]> git.meshlink.io Git - catta/commitdiff
* DBUS: implement org.freedesktop.Avahi.GetVersionString()
authorLennart Poettering <lennart@poettering.net>
Thu, 28 Jul 2005 14:07:31 +0000 (14:07 +0000)
committerLennart Poettering <lennart@poettering.net>
Thu, 28 Jul 2005 14:07:31 +0000 (14:07 +0000)
* DBUS: implement org.freedesktop.Avahi.DomainBrowserNew()
* DBUS: Some preliminary support for missing DBUS APIs

git-svn-id: file:///home/lennart/svn/public/avahi/trunk@184 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-core/core.h
avahi-daemon/DBUS-API
avahi-daemon/dbus-protocol.c
avahi-daemon/dbus-test.py

index a41aee63bf7525f85f97c42f46d70cb04d0bdd5d..8fa30e223885b771982b5666f67b8d3aad9d22bd 100644 (file)
@@ -438,7 +438,8 @@ typedef enum {
     AVAHI_DOMAIN_BROWSER_REGISTER_DEFAULT,  /**< Browse for the default registering domain */
     AVAHI_DOMAIN_BROWSER_BROWSE,            /**< Browse for a list of available browsing domains */
     AVAHI_DOMAIN_BROWSER_BROWSE_DEFAULT,    /**< Browse for the default browsing domain */
-    AVAHI_DOMAIN_BROWSER_BROWSE_LEGACY      /**< Legacy browse domain - see DNS-SD spec for more information */
+    AVAHI_DOMAIN_BROWSER_BROWSE_LEGACY,     /**< Legacy browse domain - see DNS-SD spec for more information */
+    AVAHI_DOMAIN_BROWSER_MAX
 } AvahiDomainBrowserType;
 
 /** A local domain browsing object. May be used to enumerate domains used on the local LAN */
index fa1244487bca4096b9901f4c5c30eee289d4e67b..9e9e29395b82518a11b8e68a0b7fabdbfb317b1a 100644 (file)
@@ -4,15 +4,15 @@ org.freedesktop.Avahi.Server               -- Accessible through /org/freedeskto
         string GetHostName()
         string GetHostNameFqdn()
         string GetDomainName()
+        string GetVersionString()
         [int32 interface, int32 protocol, string host_name, int32 aprotocol, string address] ResolveHostName(int32 interface, int32 protocol, string name, int32 aprotocol)
         [int32 interface, int32 protocol, int32 aprotocol, string address, string host_name] ResolveAddress(int32 interface, int32 protocol, string address)
 TODO:   [int32 interface, int32 protocol, string name, string type, string domain, string host, int32 aprotocol, string address, uint16 port, string txt[]] ResolveService(int32 interface, int32 protocol, string name, string type, string domain, int32 aprotocol) 
         path EntryGroupNew()               -- Creates a new org.freedesktop.Avahi.EntryGroup object
-TODO:   path DomainBrowserNew(int32 interface, int32 protocol, string domain, int32 btype)
+        path DomainBrowserNew(int32 interface, int32 protocol, string domain, int32 btype)
 TODO:   path ServiceTypeBrowserNew(int32 interface, int32 protocol, string domain)
 TODO:   path ServiceBrowserNew(int32 interface, int32 protocol, string type, string domain)
-        
-       SIGNAL StateChanged(int32 state)
+        SIGNAL StateChanged(int32 state)
 
 org.freedesktop.Avahi.EntryGroup
         void Free()
@@ -20,14 +20,12 @@ org.freedesktop.Avahi.EntryGroup
         int32 GetState()
         void AddService(int32 interface, int32 protocol, string type, string name, string domain, string host, uint16 port, string txt[])
         void AddAddress(int32 interface, int32 protocol, string name, string address)
-       
         SIGNAL StateChanged(int32 state)
 
-TODO: org.freedesktop.Avahi.DomainBrowser
-TODO:   void Free()
-
-TODO:   SIGNAL ItemNew(int32 interface, int32 protocol, string domain)
-TODO:   SIGNAL ItemRemove(int32 interface, int32 protocol, string domain)
+org.freedesktop.Avahi.DomainBrowser
+        void Free()
+        SIGNAL ItemNew(int32 interface, int32 protocol, string domain)
+        SIGNAL ItemRemove(int32 interface, int32 protocol, string domain)
 
 TODO: org.freedesktop.Avahi.ServiceTypeBrowser
 TODO:   void Free()
index a1582ab86796aeafd02a4ab44174c07e4cbadc1e..14f550b226edfed7086295542162e2fbc1bfd684 100644 (file)
@@ -41,6 +41,9 @@
 #define AVAHI_DBUS_INTERFACE_SERVER AVAHI_DBUS_NAME".Server"
 #define AVAHI_DBUS_PATH_SERVER "/org/freedesktop/Avahi/Server"
 #define AVAHI_DBUS_INTERFACE_ENTRY_GROUP AVAHI_DBUS_NAME".EntryGroup"
+#define AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER AVAHI_DBUS_NAME".DomainBrowser"
+#define AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER AVAHI_DBUS_NAME".ServiceTypeBrowser"
+#define AVAHI_DBUS_INTERFACE_SERVICE_BROWSER AVAHI_DBUS_NAME".ServiceBrowser"
 
 /* Needs wrapping:
    - AvahiServiceResolver
@@ -53,6 +56,10 @@ typedef struct Client Client;
 typedef struct EntryGroupInfo EntryGroupInfo;
 typedef struct HostNameResolverInfo HostNameResolverInfo;
 typedef struct AddressResolverInfo AddressResolverInfo;
+typedef struct DomainBrowserInfo DomainBrowserInfo;
+typedef struct ServiceTypeBrowserInfo ServiceTypeBrowserInfo;
+typedef struct ServiceBrowserInfo ServiceBrowserInfo;
+typedef struct ServiceResolverInfo ServiceResolverInfo;
 
 struct EntryGroupInfo {
     guint id;
@@ -79,6 +86,41 @@ struct AddressResolverInfo {
     AVAHI_LLIST_FIELDS(AddressResolverInfo, address_resolvers);
 };
 
+struct DomainBrowserInfo {
+    guint id;
+    Client *client;
+    AvahiDomainBrowser *domain_browser;
+    gchar *path;
+
+    AVAHI_LLIST_FIELDS(DomainBrowserInfo, domain_browsers);
+};
+
+struct ServiceTypeBrowserInfo {
+    guint id;
+    Client *client;
+    AvahiServiceTypeBrowser *service_type_browser;
+    gchar *path;
+
+    AVAHI_LLIST_FIELDS(ServiceTypeBrowserInfo, service_type_browsers);
+};
+
+struct ServiceBrowserInfo {
+    guint id;
+    Client *client;
+    AvahiServiceBrowser *service_browser;
+    gchar *path;
+
+    AVAHI_LLIST_FIELDS(ServiceBrowserInfo, service_browsers);
+};
+
+struct ServiceResolverInfo {
+    Client *client;
+    AvahiServiceResolver *service_resolver;
+    DBusMessage *message;
+
+    AVAHI_LLIST_FIELDS(ServiceResolverInfo, service_resolvers);
+};
+
 struct Client {
     guint id;
     gchar *name;
@@ -88,6 +130,10 @@ struct Client {
     AVAHI_LLIST_HEAD(EntryGroupInfo, entry_groups);
     AVAHI_LLIST_HEAD(HostNameResolverInfo, host_name_resolvers);
     AVAHI_LLIST_HEAD(AddressResolverInfo, address_resolvers);
+    AVAHI_LLIST_HEAD(DomainBrowserInfo, domain_browsers);
+    AVAHI_LLIST_HEAD(ServiceTypeBrowserInfo, service_type_browsers);
+    AVAHI_LLIST_HEAD(ServiceBrowserInfo, service_browsers);
+    AVAHI_LLIST_HEAD(ServiceResolverInfo, service_resolvers);
 };
 
 struct Server {
@@ -100,8 +146,9 @@ static Server *server = NULL;
 
 static void entry_group_free(EntryGroupInfo *i) {
     g_assert(i);
-    
-    avahi_entry_group_free(i->entry_group);
+
+    if (i->entry_group)
+        avahi_entry_group_free(i->entry_group);
     dbus_connection_unregister_object_path(server->bus, i->path);
     g_free(i->path);
     AVAHI_LLIST_REMOVE(EntryGroupInfo, entry_groups, i->client->entry_groups, i);
@@ -111,7 +158,8 @@ static void entry_group_free(EntryGroupInfo *i) {
 static void host_name_resolver_free(HostNameResolverInfo *i) {
     g_assert(i);
 
-    avahi_host_name_resolver_free(i->host_name_resolver);
+    if (i->host_name_resolver)
+        avahi_host_name_resolver_free(i->host_name_resolver);
     dbus_message_unref(i->message);
     AVAHI_LLIST_REMOVE(HostNameResolverInfo, host_name_resolvers, i->client->host_name_resolvers, i);
     g_free(i);
@@ -120,12 +168,56 @@ static void host_name_resolver_free(HostNameResolverInfo *i) {
 static void address_resolver_free(AddressResolverInfo *i) {
     g_assert(i);
 
-    avahi_address_resolver_free(i->address_resolver);
+    if (i->address_resolver)
+        avahi_address_resolver_free(i->address_resolver);
     dbus_message_unref(i->message);
     AVAHI_LLIST_REMOVE(AddressResolverInfo, address_resolvers, i->client->address_resolvers, i);
     g_free(i);
 }
 
+static void domain_browser_free(DomainBrowserInfo *i) {
+    g_assert(i);
+
+    if (i->domain_browser)
+        avahi_domain_browser_free(i->domain_browser);
+    dbus_connection_unregister_object_path(server->bus, i->path);
+    g_free(i->path);
+    AVAHI_LLIST_REMOVE(DomainBrowserInfo, domain_browsers, i->client->domain_browsers, i);
+    g_free(i);
+}
+
+static void service_type_browser_free(ServiceTypeBrowserInfo *i) {
+    g_assert(i);
+
+    if (i->service_type_browser)
+        avahi_service_type_browser_free(i->service_type_browser);
+    dbus_connection_unregister_object_path(server->bus, i->path);
+    g_free(i->path);
+    AVAHI_LLIST_REMOVE(ServiceTypeBrowserInfo, service_type_browsers, i->client->service_type_browsers, i);
+    g_free(i);
+}
+
+static void service_browser_free(ServiceBrowserInfo *i) {
+    g_assert(i);
+
+    if (i->service_browser)
+        avahi_service_browser_free(i->service_browser);
+    dbus_connection_unregister_object_path(server->bus, i->path);
+    g_free(i->path);
+    AVAHI_LLIST_REMOVE(ServiceBrowserInfo, service_browsers, i->client->service_browsers, i);
+    g_free(i);
+}
+
+static void service_resolver_free(ServiceResolverInfo *i) {
+    g_assert(i);
+
+    if (i->service_resolver)
+        avahi_service_resolver_free(i->service_resolver);
+    dbus_message_unref(i->message);
+    AVAHI_LLIST_REMOVE(ServiceResolverInfo, service_resolvers, i->client->service_resolvers, i);
+    g_free(i);
+}
+
 static void client_free(Client *c) {
     
     g_assert(server);
@@ -139,7 +231,19 @@ static void client_free(Client *c) {
 
     while (c->address_resolvers)
         address_resolver_free(c->address_resolvers);
-    
+
+    while (c->domain_browsers)
+        domain_browser_free(c->domain_browsers);
+
+    while (c->service_type_browsers)
+        service_type_browser_free(c->service_type_browsers);
+
+    while (c->service_browsers)
+        service_browser_free(c->service_browsers);
+
+    while (c->service_resolvers)
+        service_resolver_free(c->service_resolvers);
+
     g_free(c->name);
     AVAHI_LLIST_REMOVE(Client, clients, server->clients, c);
     g_free(c);
@@ -166,11 +270,46 @@ static Client *client_get(const gchar *name, gboolean create) {
     AVAHI_LLIST_HEAD_INIT(EntryGroupInfo, client->entry_groups);
     AVAHI_LLIST_HEAD_INIT(HostNameResolverInfo, client->host_name_resolvers);
     AVAHI_LLIST_HEAD_INIT(AddressResolverInfo, client->address_resolvers);
+    AVAHI_LLIST_HEAD_INIT(DomainBrowserInfo, client->domain_browsers);
+    AVAHI_LLIST_HEAD_INIT(ServiceTypeBrowserInfo, client->service_type_browsers);
+    AVAHI_LLIST_HEAD_INIT(ServiceBrowserInfo, client->service_browsers);
+    AVAHI_LLIST_HEAD_INIT(ServiceResolverInfo, client->service_resolvers);
 
     AVAHI_LLIST_PREPEND(Client, clients, server->clients, client);
     return client;
 }
 
+static DBusHandlerResult respond_error(DBusConnection *c, DBusMessage *m, const gchar *error, const gchar *text) {
+    DBusMessage *reply;
+
+    reply = dbus_message_new_error(m, error, text);
+    dbus_connection_send(c, reply, NULL);
+    dbus_message_unref(reply);
+    
+    return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusHandlerResult respond_string(DBusConnection *c, DBusMessage *m, const gchar *text) {
+    DBusMessage *reply;
+
+    reply = dbus_message_new_method_return(m);
+    dbus_message_append_args(reply, DBUS_TYPE_STRING, &text, DBUS_TYPE_INVALID);
+    dbus_connection_send(c, reply, NULL);
+    dbus_message_unref(reply);
+    
+    return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusHandlerResult respond_ok(DBusConnection *c, DBusMessage *m) {
+    DBusMessage *reply;
+
+    reply = dbus_message_new_method_return(m);
+    dbus_connection_send(c, reply, NULL);
+    dbus_message_unref(reply);
+    
+    return DBUS_HANDLER_RESULT_HANDLED;
+}
+
 static DBusHandlerResult msg_signal_filter_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
     GMainLoop *loop = userdata;
     DBusError error;
@@ -197,7 +336,7 @@ static DBusHandlerResult msg_signal_filter_impl(DBusConnection *c, DBusMessage *
             goto fail;
         }
 
-        avahi_log_info("dbus: name acquired (%s)", name);
+/*         avahi_log_info("dbus: name acquired (%s)", name); */
         return DBUS_HANDLER_RESULT_HANDLED;
         
     } else if (dbus_message_is_signal(m, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
@@ -212,7 +351,7 @@ static DBusHandlerResult msg_signal_filter_impl(DBusConnection *c, DBusMessage *
             Client *client;
 
             if ((client = client_get(name, FALSE))) {
-                avahi_log_info("dbus: client %s vanished", name);
+/*                 avahi_log_info("dbus: client %s vanished", name); */
                 client_free(client);
             }
         }
@@ -225,15 +364,6 @@ fail:
     return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
-static DBusHandlerResult respond_error(DBusConnection *c, DBusMessage *m, const gchar *error, const gchar *text) {
-    DBusMessage *reply;
-
-    reply = dbus_message_new_error(m, error, text);
-    dbus_connection_send(c, reply, NULL);
-    dbus_message_unref(reply);
-    
-    return DBUS_HANDLER_RESULT_HANDLED;
-}
 
 static void entry_group_callback(AvahiServer *s, AvahiEntryGroup *g, AvahiEntryGroupState state, gpointer userdata) {
     EntryGroupInfo *i = userdata;
@@ -252,16 +382,6 @@ static void entry_group_callback(AvahiServer *s, AvahiEntryGroup *g, AvahiEntryG
     dbus_message_unref(m);
 }
 
-static DBusHandlerResult respond_ok(DBusConnection *c, DBusMessage *m) {
-    DBusMessage *reply;
-
-    reply = dbus_message_new_method_return(m);
-    dbus_connection_send(c, reply, NULL);
-    dbus_message_unref(reply);
-    
-    return DBUS_HANDLER_RESULT_HANDLED;
-}
-
 static DBusHandlerResult msg_entry_group_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
     DBusError error;
     EntryGroupInfo *i = userdata;
@@ -353,8 +473,8 @@ static DBusHandlerResult msg_entry_group_impl(DBusConnection *c, DBusMessage *m,
         if (avahi_server_add_service_strlst(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, name, type, domain, host, port, strlst) < 0) {
             avahi_log_warn("Failed to add service: %s", name);
             return respond_error(c, m, "org.freedesktop.Avahi.InvalidServiceError", NULL);
-        } else
-            avahi_log_info("Successfully added service: %s", name);
+        } /* else */
+/*             avahi_log_info("Successfully added service: %s", name); */
         
         return respond_ok(c, m);
         
@@ -382,8 +502,8 @@ static DBusHandlerResult msg_entry_group_impl(DBusConnection *c, DBusMessage *m,
         if (avahi_server_add_address(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, 0, name, &a) < 0) {
             avahi_log_warn("Failed to add service: %s", name);
             return respond_error(c, m, "org.freedesktop.Avahi.InvalidAddressError", NULL);
-        } else
-            avahi_log_info("Successfully added address: %s -> %s", name, address);
+        }/*  else */
+/*             avahi_log_info("Successfully added address: %s -> %s", name, address); */
         
         return respond_ok(c, m);
     }
@@ -477,15 +597,68 @@ static void address_resolver_callback(AvahiAddressResolver *r, AvahiIfIndex inte
     address_resolver_free(i);
 }
 
-static DBusHandlerResult respond_string(DBusConnection *c, DBusMessage *m, const gchar *text) {
-    DBusMessage *reply;
+static DBusHandlerResult msg_domain_browser_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
+    DBusError error;
+    DomainBrowserInfo *i = userdata;
 
-    reply = dbus_message_new_method_return(m);
-    dbus_message_append_args(reply, DBUS_TYPE_STRING, &text, DBUS_TYPE_INVALID);
-    dbus_connection_send(c, reply, NULL);
-    dbus_message_unref(reply);
+    g_assert(c);
+    g_assert(m);
+    g_assert(i);
     
-    return DBUS_HANDLER_RESULT_HANDLED;
+    dbus_error_init(&error);
+
+    avahi_log_debug("dbus: interface=%s, path=%s, member=%s",
+                    dbus_message_get_interface(m),
+                    dbus_message_get_path(m),
+                    dbus_message_get_member(m));
+
+    /* Access control */
+    if (strcmp(dbus_message_get_sender(m), i->client->name)) 
+        return respond_error(c, m, DBUS_ERROR_ACCESS_DENIED, NULL);
+    
+    if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, "Free")) {
+
+        if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
+            avahi_log_warn("Error parsing DomainBrowser::Free message");
+            goto fail;
+        }
+
+        domain_browser_free(i);
+        return respond_ok(c, m);
+        
+    }
+    
+    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);
+    
+    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static void domain_browser_callback(AvahiDomainBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar *domain, gpointer userdata) {
+    DomainBrowserInfo *i = userdata;
+    DBusMessage *m;
+    gint32 i_interface, i_protocol;
+    
+    g_assert(b);
+    g_assert(domain);
+    g_assert(i);
+
+    i_interface = (gint32) interface;
+    i_protocol = (gint32) protocol;
+
+    m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, event == AVAHI_BROWSER_NEW ? "ItemNew" : "ItemRemove");
+    dbus_message_append_args(
+        m,
+        DBUS_TYPE_INT32, &i_interface,
+        DBUS_TYPE_INT32, &i_protocol,
+        DBUS_TYPE_STRING, &domain,
+        DBUS_TYPE_INVALID);
+    dbus_message_set_destination(m, i->client->name);   
+    dbus_connection_send(server->bus, m, NULL);
+    dbus_message_unref(m);
 }
 
 static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
@@ -525,6 +698,15 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void
     
         return respond_string(c, m, avahi_server_get_host_name_fqdn(avahi_server));
         
+    } if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetVersionString")) {
+
+        if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INVALID))) {
+            avahi_log_warn("Error parsing Server::GetVersionString message");
+            goto fail;
+        }
+    
+        return respond_string(c, m, PACKAGE_STRING);
+        
     } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "EntryGroupNew")) {
         Client *client;
         EntryGroupInfo *i;
@@ -548,11 +730,15 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void
         i = g_new(EntryGroupInfo, 1);
         i->id = ++client->current_id;
         i->client = client;
-        i->entry_group = avahi_entry_group_new(avahi_server, entry_group_callback, i);
         i->path = g_strdup_printf("/org/freedesktop/Avahi/Client%u/EntryGroup%u", client->id, i->id);
-
         AVAHI_LLIST_PREPEND(EntryGroupInfo, entry_groups, client->entry_groups, i);
 
+        if (!(i->entry_group = avahi_entry_group_new(avahi_server, entry_group_callback, i))) {
+            avahi_log_warn("Failed to create entry group");
+            entry_group_free(i);
+            goto fail;
+        }
+
         dbus_connection_register_object_path(c, i->path, &vtable, i);
         reply = dbus_message_new_method_return(m);
         dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &i->path, DBUS_TYPE_INVALID);
@@ -574,7 +760,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void
                 DBUS_TYPE_STRING, &name,
                 DBUS_TYPE_INT32, &aprotocol,
                 DBUS_TYPE_INVALID) || !name || !*name) {
-            avahi_log_warn("Error parsing EntryGroup::ResolveHostName message");
+            avahi_log_warn("Error parsing Server::ResolveHostName message");
             goto fail;
         }
 
@@ -583,9 +769,13 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void
         i = g_new(HostNameResolverInfo, 1);
         i->client = client;
         i->message = dbus_message_ref(m);
-        i->host_name_resolver = avahi_host_name_resolver_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, name, (AvahiProtocol) aprotocol, host_name_resolver_callback, i);
-
         AVAHI_LLIST_PREPEND(HostNameResolverInfo, host_name_resolvers, client->host_name_resolvers, i);
+
+        if (!(i->host_name_resolver = avahi_host_name_resolver_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, name, (AvahiProtocol) aprotocol, host_name_resolver_callback, i))) {
+            host_name_resolver_free(i);
+            avahi_log_warn("Failed to create host name resolver");
+            goto fail;
+        }
         
         return DBUS_HANDLER_RESULT_HANDLED;
         
@@ -602,7 +792,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void
                 DBUS_TYPE_INT32, &protocol,
                 DBUS_TYPE_STRING, &address,
                 DBUS_TYPE_INVALID) || !address || !*address) {
-            avahi_log_warn("Error parsing EntryGroup::ResolveAddress message");
+            avahi_log_warn("Error parsing Server::ResolveAddress message");
             goto fail;
         }
 
@@ -616,9 +806,67 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void
         i = g_new(AddressResolverInfo, 1);
         i->client = client;
         i->message = dbus_message_ref(m);
-        i->address_resolver = avahi_address_resolver_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, &a, address_resolver_callback, i);
 
         AVAHI_LLIST_PREPEND(AddressResolverInfo, address_resolvers, client->address_resolvers, i);
+
+        if (!(i->address_resolver = avahi_address_resolver_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, &a, address_resolver_callback, i))) {
+            address_resolver_free(i);
+            avahi_log_warn("Failed to create address resolver");
+            goto fail;
+        }
+        
+        return DBUS_HANDLER_RESULT_HANDLED;
+        
+     } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "DomainBrowserNew")) {
+        Client *client;
+        DomainBrowserInfo *i;
+        static const DBusObjectPathVTable vtable = {
+            NULL,
+            msg_domain_browser_impl,
+            NULL,
+            NULL,
+            NULL,
+            NULL
+        };
+        DBusMessage *reply;
+        gint32 interface, protocol, type;
+        gchar *domain;
+        
+
+        if (!dbus_message_get_args(
+                m, &error,
+                DBUS_TYPE_INT32, &interface,
+                DBUS_TYPE_INT32, &protocol,
+                DBUS_TYPE_STRING, &domain,
+                DBUS_TYPE_INT32, &type,
+                DBUS_TYPE_INVALID) || type < 0 || type >= AVAHI_DOMAIN_BROWSER_MAX) {
+            avahi_log_warn("Error parsing Server::DomainBrowserNew message");
+            goto fail;
+        }
+
+        client = client_get(dbus_message_get_sender(m), TRUE);
+
+        if (!*domain)
+            domain = NULL;
+
+        i = g_new(DomainBrowserInfo, 1);
+        i->id = ++client->current_id;
+        i->client = client;
+        i->path = g_strdup_printf("/org/freedesktop/Avahi/Client%u/DomainBrowser%u", client->id, i->id);
+
+        AVAHI_LLIST_PREPEND(DomainBrowserInfo, domain_browsers, client->domain_browsers, i);
+
+        if (!(i->domain_browser = avahi_domain_browser_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, domain, (AvahiDomainBrowserType) type, domain_browser_callback, i))) {
+            avahi_log_warn("Failed to create domain browser");
+            domain_browser_free(i);
+            goto fail;
+        }
+        
+        dbus_connection_register_object_path(c, i->path, &vtable, i);
+        reply = dbus_message_new_method_return(m);
+        dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &i->path, DBUS_TYPE_INVALID);
+        dbus_connection_send(c, reply, NULL);
+        dbus_message_unref(reply);
         
         return DBUS_HANDLER_RESULT_HANDLED;
     }
index c75faf3ed543fe8625fd94589d0b74f354737013..11dd5ae0ff5a942f0ab989eb78ccbe994dec2c41 100755 (executable)
@@ -16,6 +16,8 @@ def server_state_changed_callback(t):
 
 server.connect_to_signal("StateChanged", server_state_changed_callback)
 
+print "Version String: ", server.GetVersionString()
+
 print server.ResolveHostName(0, 0, "ecstasy.local", 0)
 print server.ResolveAddress(0, 0, "192.168.50.4")
 
@@ -23,26 +25,32 @@ print "Host name: %s" % server.GetHostName()
 print "Domain name: %s" % server.GetDomainName()
 print "FQDN: %s" % server.GetHostNameFqdn()
 
-g = dbus.Interface(bus.get_object("org.freedesktop.Avahi", server.EntryGroupNew()), 'org.freedesktop.Avahi.EntryGroup')
-
 def entry_group_state_changed_callback(t):
     print "EntryGroup::StateChanged: ", t
 
     if t == 1:
         print server.ResolveHostName(0, 0, "foo.local", 0)
         
-
+g = dbus.Interface(bus.get_object("org.freedesktop.Avahi", server.EntryGroupNew()), 'org.freedesktop.Avahi.EntryGroup')
 g.connect_to_signal('StateChanged', entry_group_state_changed_callback)
-
 g.AddService(0, 0, "Test Web Site", "_http._tcp", "", "", dbus.UInt16(4712), ["fuck=hallo", "gurke=mega"])
 g.AddAddress(0, 0, "foo.local", "47.11.8.15")
 g.Commit()
 
+def domain_browser_callback(a, interface, protocol, domain):
+    print "DOMAIN_BROWSER: %s %i %i %s" % (a, interface, protocol, domain)
+
+db = dbus.Interface(bus.get_object("org.freedesktop.Avahi", server.DomainBrowserNew(0, 0, "", 2)), 'org.freedesktop.Avahi.DomainBrowser')
+
+db.connect_to_signal('ItemNew', lambda interface, protocol, domain: domain_browser_callback("NEW", interface, protocol, domain))
+db.connect_to_signal('ItemRemove', lambda interface, protocol, domain: domain_browser_callback("REMOVE", interface, protocol, domain))
+
 try:
     gobject.MainLoop().run()
 except KeyboardInterrupt, k:
     pass
 
 g.Free()
+db.Free()
 
 print "Quit"