~davewalker/ubuntu/oneiric/dnsmasq/add_dnsmasq-utils_package

« back to all changes in this revision

Viewing changes to src/dbus.c

  • Committer: Bazaar Package Importer
  • Author(s): Simon Kelley
  • Date: 2009-02-07 19:25:23 UTC
  • mfrom: (10.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090207192523-zut5qet639v1httx
 * Fix bashism in init script. (closes: #514397)
 * Tweak logging in init script.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* dnsmasq is Copyright (c) 2000-2007 Simon Kelley
 
1
/* dnsmasq is Copyright (c) 2000-2009 Simon Kelley
2
2
 
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.
12
12
     
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/>.
15
15
*/
16
16
 
17
17
#include "dnsmasq.h"
21
21
#define DBUS_API_SUBJECT_TO_CHANGE
22
22
#include <dbus/dbus.h>
23
23
 
 
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"
 
31
"    </method>\n"
 
32
"  </interface>\n"
 
33
"  <interface name=\"" DNSMASQ_SERVICE "\">\n"
 
34
"    <method name=\"ClearCache\">\n"
 
35
"    </method>\n"
 
36
"    <method name=\"GetVersion\">\n"
 
37
"      <arg name=\"version\" direction=\"out\" type=\"s\"/>\n"
 
38
"    </method>\n"
 
39
"    <method name=\"SetServers\">\n"
 
40
"      <arg name=\"servers\" direction=\"in\" type=\"av\"/>\n"
 
41
"    </method>\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"
 
46
"    </signal>\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"
 
51
"    </signal>\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"
 
56
"    </signal>\n"
 
57
"  </interface>\n"
 
58
"</node>\n";
 
59
 
24
60
struct watch {
25
61
  DBusWatch *watch;      
26
62
  struct watch *next;
229
265
{
230
266
  char *method = (char *)dbus_message_get_member(message);
231
267
   
232
 
  if (strcmp(method, "GetVersion") == 0)
 
268
  if (dbus_message_is_method_call(message, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
 
269
    {
 
270
      DBusMessage *reply = dbus_message_new_method_return(message);
 
271
 
 
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);
 
275
    }
 
276
  else if (strcmp(method, "GetVersion") == 0)
233
277
    {
234
278
      char *v = VERSION;
235
279
      DBusMessage *reply = dbus_message_new_method_return(message);
283
327
  daemon->dbus = connection; 
284
328
  
285
329
  if ((message = dbus_message_new_signal(DNSMASQ_PATH, DNSMASQ_SERVICE, "Up")))
286
 
    dbus_connection_send(connection, message, NULL);
 
330
    {
 
331
      dbus_connection_send(connection, message, NULL);
 
332
      dbus_message_unref(message);
 
333
    }
287
334
 
288
335
  return NULL;
289
336
}
352
399
    }
353
400
}
354
401
 
 
402
void emit_dbus_signal(int action, char *mac, char *hostname, char *addr)
 
403
{
 
404
  DBusConnection *connection = (DBusConnection *)daemon->dbus;
 
405
  DBusMessage* message = NULL;
 
406
  DBusMessageIter args;
 
407
  const char *action_str;
 
408
 
 
409
  if (!connection)
 
410
    return;
 
411
 
 
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";
 
418
  else
 
419
    return;
 
420
 
 
421
  if (!(message = dbus_message_new_signal(DNSMASQ_PATH, DNSMASQ_SERVICE, action_str)))
 
422
    return;
 
423
  
 
424
  dbus_message_iter_init_append(message, &args);
 
425
 
 
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);
 
430
  
 
431
  dbus_message_unref(message);
 
432
}
 
433
 
355
434
#endif