-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

> I certainly would accept such a patch. A couple of hints on implementation:

OK, I'm putting the finishing touches on the patch (work in progress
attached). A couple of questions:

1/ What exactly are the ACTION_OLD and ACTION_OLD_HOSTNAME actions?

2/ Would you rather have one signal (e.g. DhcpLeaseChanged) and pass
"add" / "del" / "old" as the first argument or would you rather have one
signal per event:

add => DhcpLeaseAdded
del => DhcpLeaseDeleted
old => DhcpLease??

3/ Do you by any chance have an svn / git / whatever repository anywhere?

Cheers,
Jeremy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkjSrcAACgkQ4mJJZqJp2SdaJACgmjyJPOVD17muUH/OLNhgGAFu
jKEAnArWllguX7ZOnphZpDgDif3WWC/b
=pV3t
-----END PGP SIGNATURE-----
diff --git a/src/dbus.c b/src/dbus.c
index 8349ff9..3fcf255 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -352,4 +352,42 @@ void check_dbus_listeners(fd_set *rset, fd_set *wset, fd_set *eset)
     }
 }
 
+void emit_dbus_signal(int action, struct dhcp_lease *lease, char *hostname)
+{
+  DBusConnection *connection = (DBusConnection *)daemon->dbus;
+  DBusMessage* message = NULL;
+  DBusMessageIter args;
+  const char *value;
+  const char *action_str;
+
+  if (!connection)
+    return;
+
+  if (action == ACTION_DEL)
+    action_str = "DhcpDel";
+  else if (action == ACTION_ADD)
+    action_str = "DhcpAdd";
+  else if (action == ACTION_OLD || action == ACTION_OLD_HOSTNAME)
+    action_str = "DhcpOld";
+  else
+    return;
+
+  if (!(message = dbus_message_new_signal(DNSMASQ_PATH, DNSMASQ_SERVICE, action_str)))
+    return;
+
+  dbus_message_iter_init_append(message, &args);
+
+  value = inet_ntoa(lease->addr);
+  dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &value);
+
+  value = print_mac(daemon->namebuff, lease->hwaddr, lease->hwaddr_len);
+  dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &value);
+
+  value = hostname ? hostname : "";
+  dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &value);
+
+  dbus_connection_send(connection, message, NULL);
+  dbus_message_unref(message);
+}
+
 #endif
diff --git a/src/dnsmasq.h b/src/dnsmasq.h
index 1c6b2a3..8eca840 100644
--- a/src/dnsmasq.h
+++ b/src/dnsmasq.h
@@ -828,6 +828,7 @@ int iface_enumerate(void *parm, int (*ipv4_callback)(), int (*ipv6_callback)());
 char *dbus_init(void);
 void check_dbus_listeners(fd_set *rset, fd_set *wset, fd_set *eset);
 void set_dbus_listeners(int *maxfdp, fd_set *rset, fd_set *wset, fd_set *eset);
+void emit_dbus_signal(int action, struct dhcp_lease *lease, char *hostname);
 #endif
 
 /* helper.c */
diff --git a/src/helper.c b/src/helper.c
index b053967..2e9fd62 100644
--- a/src/helper.c
+++ b/src/helper.c
@@ -307,6 +307,10 @@ void queue_script(int action, struct dhcp_lease *lease, char *hostname, time_t n
   size_t size;
   unsigned int i, hostname_len = 0, clid_len = 0, vclass_len = 0, uclass_len = 0;
 
+#ifdef HAVE_DBUS
+  emit_dbus_signal(action, lease, hostname);
+#endif
+
   /* no script */
   if (daemon->helperfd == -1)
     return;

Reply via email to