blow away unnessecary errata whose functionality is covered by code from generated...
[systembsd.git] / src / interfaces / hostnamed / hostnamed.c
1 #include <unistd.h>
2 #include <limits.h>
3
4 #include <glib.h>
5 #include <gio/gio.h>
6
7 #include "hostnamed.h"
8 #include "hostnamed-gen.c"
9
10 GPtrArray *hostnamed_freeable;
11 GDBusNodeInfo *spect_data;
12
13 static void on_bus_acquired(GDBusConnection *conn,
14 const gchar *name,
15 gpointer user_data) {
16
17 GError *err;
18
19 g_print("got bus, name: %s\n", name);
20
21 /*g_dbus_connection_register_object(conn,
22 "/org/freedesktop/hostname1",
23 spect_data->interfaces[0],
24 &interface_vtable,
25 NULL, NULL, NULL);*/
26 }
27
28 static void on_name_acquired(GDBusConnection *conn,
29 const gchar *name,
30 gpointer user_data) {
31
32 g_print("got name %s\n", name);
33 }
34
35 static void on_name_lost(GDBusConnection *conn,
36 const gchar *name,
37 gpointer user_data) {
38
39 g_print("lost name %s, exiting...", name);
40
41 hostnamed_mem_clean();
42
43 //TODO exit through g_main_loop properly...
44 }
45
46 /* safe call to try and start hostnamed */
47 GError * hostnamed_init() {
48
49 guint bus_descriptor;
50 GError *err = NULL;
51 gchar **hostnamed_ispect_xml;
52 gchar *hostnamed_joined_xml;
53
54 hostnamed_freeable = g_ptr_array_new();
55
56 g_file_get_contents("conf/hostnamed-ispect.xml", hostnamed_ispect_xml, GUINT_TO_POINTER(3000), &err);
57 hostnamed_joined_xml = g_strjoinv("\n", hostnamed_ispect_xml);
58 spect_data = g_dbus_node_info_new_for_xml(hostnamed_joined_xml, NULL);
59
60 g_free(hostnamed_ispect_xml);
61 g_ptr_array_add(hostnamed_freeable, hostnamed_joined_xml);
62
63 bus_descriptor = g_bus_own_name(G_BUS_TYPE_SYSTEM,
64 "org.freedesktop.hostname1",
65 G_BUS_NAME_OWNER_FLAGS_NONE,
66 on_bus_acquired,
67 on_name_acquired,
68 on_name_lost,
69 NULL,
70 NULL);
71
72 //TODO: malloc and return reference as if a main() closed
73 return err;
74 }
75
76 //POSIX, for future ports try_hostname should be checked for null-termination
77 /*
78 gboolean init_hostname() {
79
80 gchar try_hostname[HOST_NAME_MAX];
81
82 if(!gethostname(try_hostname, HOST_NAME_MAX)) {
83 hostname = try_hostname;
84 return TRUE;
85 }
86
87 return FALSE;
88 }*/
89
90 /* free()'s */
91 void hostnamed_mem_clean() {
92
93 g_ptr_array_foreach(hostnamed_freeable, (GFunc) g_free, NULL);
94 }
95
96 //TODO figure out DMI variables on obsd
97 /*static gchar *guess_icon_name() {
98
99 gchar *filebuf = NULL;
100 gchar *ret = NULL;
101
102 //TODO vm check
103
104 #if defined(__i386__) || defined(__x86_64__)
105 /*
106 Taken with a few minor changes from systemd's hostnamed.c,
107 copyright 2011 Lennart Poettering.
108
109 See the SMBIOS Specification 2.7.1 section 7.4.1 for
110 details about the values listed here:
111
112 http://www.dmtf.org/sites/default/files/standards/documents/DSP0134_2.7.1.pdf
113 */ /*
114
115 if (g_file_get_contents ("/sys/class/dmi/id/chassis_type", &filebuf, NULL, NULL)) {
116 switch (g_ascii_strtoull (filebuf, NULL, 10)) {
117 case 0x3:
118 case 0x4:
119 case 0x5:
120 case 0x6:
121 case 0x7:
122 ret = g_strdup ("computer-desktop");
123 goto out;
124 case 0x9:
125 case 0xA:
126 case 0xE:
127 ret = g_strdup ("computer-laptop");
128 goto out;
129 case 0x11:
130 case 0x17:
131 case 0x1C:
132 case 0x1D:
133 ret = g_strdup ("computer-server");
134 goto out;
135 }
136 }
137 #endif
138 ret = g_strdup ("computer");
139 out:
140 g_free (filebuf);
141 return ret;
142 }*/