1
/* dnsmasq is Copyright (c) 2000-2007 Simon Kelley
1
/* dnsmasq is Copyright (c) 2000-2009 Simon Kelley
3
3
This program is free software; you can redistribute it and/or modify
4
4
it under the terms of the GNU General Public License as published by
10
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License
14
along with this program. If not, see <http://www.gnu.org/licenses/>.
13
You should have received a copy of the GNU General Public License
14
along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
#include "dnsmasq.h"
21
21
#define DBUS_API_SUBJECT_TO_CHANGE
22
22
#include <dbus/dbus.h>
24
const char* introspection_xml =
25
"<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
26
"\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
27
"<node name=\"" DNSMASQ_PATH "\">\n"
28
" <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
29
" <method name=\"Introspect\">\n"
30
" <arg name=\"data\" direction=\"out\" type=\"s\"/>\n"
33
" <interface name=\"" DNSMASQ_SERVICE "\">\n"
34
" <method name=\"ClearCache\">\n"
36
" <method name=\"GetVersion\">\n"
37
" <arg name=\"version\" direction=\"out\" type=\"s\"/>\n"
39
" <method name=\"SetServers\">\n"
40
" <arg name=\"servers\" direction=\"in\" type=\"av\"/>\n"
42
" <signal name=\"DhcpLeaseAdded\">\n"
43
" <arg name=\"ipaddr\" type=\"s\"/>\n"
44
" <arg name=\"hwaddr\" type=\"s\"/>\n"
45
" <arg name=\"hostname\" type=\"s\"/>\n"
47
" <signal name=\"DhcpLeaseDeleted\">\n"
48
" <arg name=\"ipaddr\" type=\"s\"/>\n"
49
" <arg name=\"hwaddr\" type=\"s\"/>\n"
50
" <arg name=\"hostname\" type=\"s\"/>\n"
52
" <signal name=\"DhcpLeaseUpdated\">\n"
53
" <arg name=\"ipaddr\" type=\"s\"/>\n"
54
" <arg name=\"hwaddr\" type=\"s\"/>\n"
55
" <arg name=\"hostname\" type=\"s\"/>\n"
26
62
struct watch *next;
230
266
char *method = (char *)dbus_message_get_member(message);
232
if (strcmp(method, "GetVersion") == 0)
268
if (dbus_message_is_method_call(message, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
270
DBusMessage *reply = dbus_message_new_method_return(message);
272
dbus_message_append_args(reply, DBUS_TYPE_STRING, &introspection_xml, DBUS_TYPE_INVALID);
273
dbus_connection_send (connection, reply, NULL);
274
dbus_message_unref (reply);
276
else if (strcmp(method, "GetVersion") == 0)
234
278
char *v = VERSION;
235
279
DBusMessage *reply = dbus_message_new_method_return(message);
283
327
daemon->dbus = connection;
285
329
if ((message = dbus_message_new_signal(DNSMASQ_PATH, DNSMASQ_SERVICE, "Up")))
286
dbus_connection_send(connection, message, NULL);
331
dbus_connection_send(connection, message, NULL);
332
dbus_message_unref(message);
402
void emit_dbus_signal(int action, char *mac, char *hostname, char *addr)
404
DBusConnection *connection = (DBusConnection *)daemon->dbus;
405
DBusMessage* message = NULL;
406
DBusMessageIter args;
407
const char *action_str;
412
if (action == ACTION_DEL)
413
action_str = "DhcpLeaseDeleted";
414
else if (action == ACTION_ADD)
415
action_str = "DhcpLeaseAdded";
416
else if (action == ACTION_OLD)
417
action_str = "DhcpLeaseUpdated";
421
if (!(message = dbus_message_new_signal(DNSMASQ_PATH, DNSMASQ_SERVICE, action_str)))
424
dbus_message_iter_init_append(message, &args);
426
if (dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &addr) &&
427
dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &mac) &&
428
dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &hostname))
429
dbus_connection_send(connection, message, NULL);
431
dbus_message_unref(message);