2 * Copyright (c) 2013 Frank Lahm <franklahm@gmail.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
17 #endif /* HAVE_CONFIG_H */
22 #include <glib-object.h>
24 #include <glib/gprintf.h>
26 #include <atalk/logger.h>
27 #include <atalk/dsi.h>
30 #include "afpstats_obj.h"
37 struct AFPStatsObjClass
42 static void afpstats_obj_init(AFPStatsObj *obj)
46 static void afpstats_obj_class_init(AFPStatsObjClass *klass)
50 static gpointer afpstats_obj_parent_class = NULL;
52 static void afpstats_obj_class_intern_init(gpointer klass)
54 afpstats_obj_parent_class = g_type_class_peek_parent(klass);
55 afpstats_obj_class_init((AFPStatsObjClass *)klass);
58 GType afpstats_obj_get_type(void)
60 static volatile gsize g_define_type_id__volatile = 0;
61 if (g_once_init_enter(&g_define_type_id__volatile)) {
62 GType g_define_type_id = g_type_register_static_simple(
64 g_intern_static_string("AFPStatsObj"),
65 sizeof(AFPStatsObjClass),
66 (GClassInitFunc)afpstats_obj_class_intern_init,
68 (GInstanceInitFunc)afpstats_obj_init,
70 g_once_init_leave(&g_define_type_id__volatile, g_define_type_id);
72 return g_define_type_id__volatile;
75 gboolean afpstats_obj_get_users(AFPStatsObj *obj, gchar ***ret, GError **error)
78 server_child_t *childs = afpstats_get_and_lock_childs();
84 names = g_new(char *, childs->servch_count + 1);
86 for (j = 0; j < CHILD_HASHSIZE && i < childs->servch_count; j++) {
87 child = childs->servch_table[j];
89 if (child->afpch_valid && (pw = getpwuid(child->afpch_uid))) {
90 time_t time = child->afpch_logintime;
91 strftime(buf, sizeof(buf), "%b %d %H:%M:%S", localtime(&time));
92 names[i++] = g_strdup_printf("name: %s, pid: %d, logintime: %s, state: %s, volumes: %s",
93 pw->pw_name, child->afpch_pid, buf,
94 child->afpch_state == DSI_RUNNING ? "active" :
95 child->afpch_state == DSI_SLEEPING ? "sleeping" :
96 child->afpch_state == DSI_EXTSLEEP ? "sleeping" :
97 child->afpch_state == DSI_DISCONNECTED ? "disconnected" :
99 child->afpch_volumes ? child->afpch_volumes : "-");
101 child = child->afpch_next;
107 afpstats_unlock_childs();