]> git.meshlink.io Git - catta/commitdiff
DBUS: finish introspection support
authorLennart Poettering <lennart@poettering.net>
Sat, 30 Jul 2005 17:52:25 +0000 (17:52 +0000)
committerLennart Poettering <lennart@poettering.net>
Sat, 30 Jul 2005 17:52:25 +0000 (17:52 +0000)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@203 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-daemon/DBUS-API
avahi-daemon/DomainBrowser.introspect [new file with mode: 0644]
avahi-daemon/EntryGroup.introspect [new file with mode: 0644]
avahi-daemon/Makefile.am
avahi-daemon/Server.introspect
avahi-daemon/ServiceBrowser.introspect [new file with mode: 0644]
avahi-daemon/ServiceTypeBrowser.introspect [new file with mode: 0644]
avahi-daemon/dbus-protocol.c
avahi-daemon/static-services.c
todo

index 2ad5fa19d1e0f14187cac1015ef2d8607a2270d1..eb62ae399b16f021417da03db5c5aeddbd2d02f3 100644 (file)
@@ -21,7 +21,7 @@ org.freedesktop.Avahi.EntryGroup
         void Free()
         void Commit()
         int32 GetState()
-        void AddService(int32 interface, int32 protocol, string type, string name, string domain, string host, uint16 port, string txt[])
+        void AddService(int32 interface, int32 protocol, string name, string type, string domain, string host, uint16 port, string txt[])
         void AddAddress(int32 interface, int32 protocol, string name, string address)
         SIGNAL StateChanged(int32 state)
 
diff --git a/avahi-daemon/DomainBrowser.introspect b/avahi-daemon/DomainBrowser.introspect
new file mode 100644 (file)
index 0000000..dda85d0
--- /dev/null
@@ -0,0 +1,31 @@
+<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
+<!DOCTYPE node SYSTEM "introspect.dtd">
+<node>
+  
+  <!-- $Id$ -->
+
+  <interface name="org.freedesktop.DBus.Introspectable">
+    <method name="Introspect">
+      <arg name="data" type="s" direction="out" />
+    </method>
+  </interface>
+
+  <interface name="org.freedesktop.Avahi.DomainBrowser">
+
+    <method name="Free"/>
+      
+    <signal name="ItemNew">
+      <arg name="interface" type="i"/>
+      <arg name="protocol" type="i"/>
+      <arg name="domain" type="s"/>
+    </signal>
+
+    <signal name="ItemRemove">
+      <arg name="interface" type="i"/>
+      <arg name="protocol" type="i"/>
+      <arg name="domain" type="s"/>
+    </signal>
+
+  </interface> 
+</node>
+
diff --git a/avahi-daemon/EntryGroup.introspect b/avahi-daemon/EntryGroup.introspect
new file mode 100644 (file)
index 0000000..6da6973
--- /dev/null
@@ -0,0 +1,43 @@
+<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
+<!DOCTYPE node SYSTEM "introspect.dtd">
+<node>
+  
+  <!-- $Id$ -->
+
+  <interface name="org.freedesktop.DBus.Introspectable">
+    <method name="Introspect">
+      <arg name="data" type="s" direction="out"/>
+    </method>
+  </interface>
+
+  <interface name="org.freedesktop.Avahi.EntryGroup">
+    <method name="Free"/>
+    <method name="Commit"/>
+
+    <method name="GetState">
+      <arg name="state" type="i" direction="out"/>
+    </method>
+    <signal name="StateChanged">
+      <arg name="state" type="i"/>
+    </signal>
+
+    <method name="AddService">
+      <arg name="interface" type="i" direction="in"/>
+      <arg name="protocol" type="i" direction="in"/>
+      <arg name="name" type="s" direction="in"/>
+      <arg name="type" type="s" direction="in"/>
+      <arg name="domain" type="s" direction="in"/>
+      <arg name="host" type="s" direction="in"/>
+      <arg name="port" type="q" direction="in"/>
+      <arg name="txt" type="as" direction="in"/>
+    </method>
+
+    <method name="AddAddress">
+      <arg name="interface" type="i" direction="in"/>
+      <arg name="protocol" type="i" direction="in"/>
+      <arg name="name" type="s" direction="in"/>
+      <arg name="address" type="s" direction="in"/>
+    </method>
+
+  </interface>
+</node>
index f1529840adf62ea649d965c4e9d7a94a3ac45f3a..b56aa554c60716d347e4b572fc13de46801ba29d 100644 (file)
 
 pkgsysconfdir=$(sysconfdir)/avahi
 servicedir=$(pkgsysconfdir)/services
+introspectiondir=$(pkgdatadir)/introspection
+dbusservicedir=$(DBUS_SYS_DIR)
 
 AM_CFLAGS= \
        -I$(top_srcdir) \
        -DAVAHI_DAEMON_RUNTIME_DIR=\"$(avahi_runtime_dir)/avahi-daemon/\" \
        -DAVAHI_SOCKET=\"$(avahi_socket)\" \
-       -DAVAHI_SERVICE_DIRECTORY=\"$(servicedir)\" \
-       -DAVAHI_CONFIG_FILE=\"$(pkgsysconfdir)/avahi-daemon.conf\"
+       -DAVAHI_SERVICE_DIR=\"$(servicedir)\" \
+       -DAVAHI_CONFIG_FILE=\"$(pkgsysconfdir)/avahi-daemon.conf\" \
+       -DAVAHI_DBUS_INTROSPECTION_DIR=\"$(introspectiondir)\" 
 
 AM_LDADD=-lexpat
 
@@ -63,16 +66,30 @@ service_DATA = \
 pkgdata_DATA = \
        avahi-service.dtd
 
-EXTRA_DIST = avahi-service.dtd avahi-daemon.conf example.service dbus-test.py Server.introspect server-introspect-xml.c
-BUILT_SOURCES = server-introspect-xml.c
+EXTRA_DIST = \
+       avahi-service.dtd \
+       avahi-daemon.conf \
+       example.service \
+       dbus-test.py \
+       avahi-dbus.conf \
+       Server.introspect \
+       EntryGroup.introspect \
+       DomainBrowser.introspect \
+       ServiceTypeBrowser.introspect \
+       ServiceBrowser.introspect
 
 if ENABLE_DBUS
 avahi_daemon_SOURCES += dbus-protocol.c dbus-protocol.h
 
-dbusservicedir = $(DBUS_SYS_DIR)
 dbusservice_DATA = avahi-dbus.conf
 
-EXTRA_DIST += $(dbusservice_DATA)
+introspection_DATA = \
+       Server.introspect \
+       EntryGroup.introspect \
+       DomainBrowser.introspect \
+       ServiceTypeBrowser.introspect \
+       ServiceBrowser.introspect
+
 endif
 
 avahi_daemon_CFLAGS = $(AM_CFLAGS)
@@ -82,6 +99,6 @@ xmllint:
        xmllint --noout --valid example.service
        xmllint --noout --valid Server.introspect
        xmllint --noout --valid EntryGroup.introspect
-
-server-introspect-xml.c: Server.introspect
-       python embedd-file.py -s $< server_introspect_xml > $@
+       xmllint --noout --valid DomainBrowser.introspect
+       xmllint --noout --valid ServiceTypeBrowser.introspect
+       xmllint --noout --valid ServiceBrowser.introspect
index da7eb361e9d6e1db24498b7ebe08f4c958c70fbd..37780f1ef9c1254b121a07aafb8ff0e0faa5c778 100644 (file)
@@ -6,7 +6,7 @@
 
  <interface name="org.freedesktop.DBus.Introspectable">
     <method name="Introspect">
-      <arg name="data" direction="out" type="s"/>
+      <arg name="data" type="s" direction="out"/>
     </method>
   </interface>
 
diff --git a/avahi-daemon/ServiceBrowser.introspect b/avahi-daemon/ServiceBrowser.introspect
new file mode 100644 (file)
index 0000000..e1790a1
--- /dev/null
@@ -0,0 +1,34 @@
+<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
+<!DOCTYPE node SYSTEM "introspect.dtd">
+<node>
+  
+  <!-- $Id$ -->
+
+  <interface name="org.freedesktop.DBus.Introspectable">
+    <method name="Introspect">
+      <arg name="data" type="s" direction="out" />
+    </method>
+  </interface>
+
+  <interface name="org.freedesktop.Avahi.ServiceBrowser">
+
+    <method name="Free"/>
+      
+    <signal name="ItemNew">
+      <arg name="interface" type="i"/>
+      <arg name="protocol" type="i"/>
+      <arg name="name" type="s"/>
+      <arg name="type" type="s"/>
+      <arg name="domain" type="s"/>
+    </signal>
+
+    <signal name="ItemRemove">
+      <arg name="interface" type="i"/>
+      <arg name="protocol" type="i"/>
+      <arg name="name" type="s"/>
+      <arg name="type" type="s"/>
+      <arg name="domain" type="s"/>
+    </signal>
+
+  </interface> 
+</node>
diff --git a/avahi-daemon/ServiceTypeBrowser.introspect b/avahi-daemon/ServiceTypeBrowser.introspect
new file mode 100644 (file)
index 0000000..ebb9326
--- /dev/null
@@ -0,0 +1,32 @@
+<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
+<!DOCTYPE node SYSTEM "introspect.dtd">
+<node>
+  
+  <!-- $Id$ -->
+
+  <interface name="org.freedesktop.DBus.Introspectable">
+    <method name="Introspect">
+      <arg name="data" type="s" direction="out" />
+    </method>
+  </interface>
+
+  <interface name="org.freedesktop.Avahi.ServiceTypeBrowser">
+
+    <method name="Free"/>
+      
+    <signal name="ItemNew">
+      <arg name="interface" type="i"/>
+      <arg name="protocol" type="i"/>
+      <arg name="type" type="s"/>
+      <arg name="domain" type="s"/>
+    </signal>
+
+    <signal name="ItemRemove">
+      <arg name="interface" type="i"/>
+      <arg name="protocol" type="i"/>
+      <arg name="type" type="s"/>
+      <arg name="domain" type="s"/>
+    </signal>
+
+  </interface> 
+</node>
index 626e4a066ad2fafa48a11d50a85e889db466e789..65c8e46cdc30260d413c90f20faca67e403c9794 100644 (file)
@@ -38,9 +38,6 @@
 #include "dbus-protocol.h"
 #include "main.h"
 
-/* Include generated introspection data */
-#include "server-introspect-xml.c"
-
 typedef struct Server Server;
 typedef struct Client Client;
 typedef struct EntryGroupInfo EntryGroupInfo;
@@ -311,6 +308,47 @@ static DBusHandlerResult respond_path(DBusConnection *c, DBusMessage *m, const g
     return DBUS_HANDLER_RESULT_HANDLED;
 }
 
+static DBusHandlerResult handle_introspect(DBusConnection *c, DBusMessage *m, const gchar *fname) {
+    gchar *path = NULL;
+    gchar *contents;
+    GError *gerror = NULL;
+    DBusError error;
+    
+    g_assert(c);
+    g_assert(m);
+    g_assert(fname);
+
+    dbus_error_init(&error);
+
+    if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
+        avahi_log_warn("Error parsing Introspect message: %s", error.message);
+        goto fail;
+    }
+    
+    path = g_strdup_printf("%s/%s", AVAHI_DBUS_INTROSPECTION_DIR, fname);
+
+    if (!(g_file_get_contents(path, &contents, NULL, &gerror))) {
+        avahi_log_warn("Failed to load introspection data: %s", gerror->message);
+        g_error_free(gerror);
+        g_free(path);
+        goto fail;
+    }
+
+    g_free(path);
+    
+    respond_string(c, m, contents);
+    g_free(contents);
+    
+    return DBUS_HANDLER_RESULT_HANDLED;
+
+fail:
+    if (dbus_error_is_set(&error))
+        dbus_error_free(&error);
+    
+    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+}
+
 static DBusHandlerResult msg_signal_filter_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
     GMainLoop *loop = userdata;
     DBusError error;
@@ -398,6 +436,10 @@ static DBusHandlerResult msg_entry_group_impl(DBusConnection *c, DBusMessage *m,
                     dbus_message_get_path(m),
                     dbus_message_get_member(m));
 
+    /* Introspection */
+    if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
+        return handle_introspect(c, m, "EntryGroup.introspect");
+    
     /* Access control */
     if (strcmp(dbus_message_get_sender(m), i->client->name)) 
         return respond_error(c, m, DBUS_ERROR_ACCESS_DENIED, NULL);
@@ -613,6 +655,10 @@ static DBusHandlerResult msg_domain_browser_impl(DBusConnection *c, DBusMessage
                     dbus_message_get_path(m),
                     dbus_message_get_member(m));
 
+    /* Introspection */
+    if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
+        return handle_introspect(c, m, "DomainBrowser.introspect");
+    
     /* Access control */
     if (strcmp(dbus_message_get_sender(m), i->client->name)) 
         return respond_error(c, m, DBUS_ERROR_ACCESS_DENIED, NULL);
@@ -677,6 +723,10 @@ static DBusHandlerResult msg_service_type_browser_impl(DBusConnection *c, DBusMe
                     dbus_message_get_path(m),
                     dbus_message_get_member(m));
 
+    /* Introspection */
+    if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
+        return handle_introspect(c, m, "ServiceTypeBrowser.introspect");
+    
     /* Access control */
     if (strcmp(dbus_message_get_sender(m), i->client->name)) 
         return respond_error(c, m, DBUS_ERROR_ACCESS_DENIED, NULL);
@@ -743,6 +793,10 @@ static DBusHandlerResult msg_service_browser_impl(DBusConnection *c, DBusMessage
                     dbus_message_get_path(m),
                     dbus_message_get_member(m));
 
+    /* Introspection */
+    if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
+        return handle_introspect(c, m, "ServiceBrowser.introspect");
+    
     /* Access control */
     if (strcmp(dbus_message_get_sender(m), i->client->name)) 
         return respond_error(c, m, DBUS_ERROR_ACCESS_DENIED, NULL);
@@ -866,6 +920,7 @@ static void service_resolver_callback(
     service_resolver_free(i);
 }
 
+
 static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
     DBusError error;
 
@@ -876,16 +931,10 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void
                     dbus_message_get_path(m),
                     dbus_message_get_member(m));
 
-    if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect")) {
-
-        if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
-            avahi_log_warn("Error parsing Introspect message");
-            goto fail;
-        }
-
-        return respond_string(c, m, server_introspect_xml);
+    if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
+        return handle_introspect(c, m, "Server.introspect");
         
-    else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetHostName")) {
+    else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetHostName")) {
 
         if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
             avahi_log_warn("Error parsing Server::GetHostName message");
@@ -1249,7 +1298,6 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void
 
     avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
 
-
 fail:
     if (dbus_error_is_set(&error))
         dbus_error_free(&error);
index 59ef7aa9826275a1d7401b5a15dbcdf52a1af44c..56345fd87e02afeddc9e75469be8c766d6d70f7f 100644 (file)
@@ -590,7 +590,7 @@ void static_service_load(void) {
     }
 
     memset(&globbuf, 0, sizeof(globbuf));
-    if (glob(AVAHI_SERVICE_DIRECTORY "/*.service", GLOB_ERR, NULL, &globbuf) != 0)
+    if (glob(AVAHI_SERVICE_DIR "/*.service", GLOB_ERR, NULL, &globbuf) != 0)
         avahi_log_error("Failed to read service directory.");
     else {
         for (p = globbuf.gl_pathv; *p; p++)
diff --git a/todo b/todo
index 6860e94c5c310859ee04ab456643ebdecce4759b..beae6e875e13931daff2e4056a08a39f547636c5 100644 (file)
--- a/todo
+++ b/todo
@@ -1,6 +1,5 @@
 todo:
 * finish DBUS stuff:
-       - introspection
        - enforce limits
     - allow NUL bytes in TXT records
 * release!