]> git.meshlink.io Git - catta/commitdiff
* remove AVAHI_PUBLISH_IS_PROXY, it was a bad idea
authorLennart Poettering <lennart@poettering.net>
Tue, 18 Oct 2005 19:52:03 +0000 (19:52 +0000)
committerLennart Poettering <lennart@poettering.net>
Tue, 18 Oct 2005 19:52:03 +0000 (19:52 +0000)
* drop avahi_service_is_service_local(), avahi_client_is_service_local()
* add new lookup result flags AVAHI_LOOKUP_RESULT_OUR_OWN and AVAHI_LOOKUP_RESULT_LOCAL
* remove avahi_address_resolver_new() and replace it by avahi_address_resolver_new_a()
* avahi-client: save query data in browse/resolve objects so that we can return it on failure
* other cleanups

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

27 files changed:
avahi-client/browser.c
avahi-client/client-test.c
avahi-client/client.c
avahi-client/client.h
avahi-client/entrygroup.c
avahi-client/internal.h
avahi-client/lookup.h
avahi-client/resolver.c
avahi-common/defs.h
avahi-core/browse-dns-server.c
avahi-core/browse-domain.c
avahi-core/browse-service-type.c
avahi-core/browse-service.c
avahi-core/browse.c
avahi-core/core.h
avahi-core/entry.c
avahi-core/internal.h
avahi-core/publish.h
avahi-core/resolve-address.c
avahi-core/server.c
avahi-daemon/Server.introspect
avahi-daemon/dbus-protocol.c
avahi-daemon/static-services.c
examples/client-browse-services.c
examples/client-publish-service.c
examples/core-browse-services.c
examples/core-publish-service.c

index bdbd8c5c58da6b79731bde7a5372426f4aa99216..122d6f2f74b02676f0b4573dcdcb3f0ee431b4fd 100644 (file)
@@ -77,6 +77,8 @@ AvahiDomainBrowser* avahi_domain_browser_new(
     db->callback = callback;
     db->userdata = userdata;
     db->path = NULL;
+    db->interface = interface;
+    db->protocol = protocol;
 
     AVAHI_LLIST_PREPEND(AvahiDomainBrowser, domain_browsers, client->domain_browsers, db);
 
@@ -147,8 +149,7 @@ fail:
     return NULL;
 }
 
-AvahiClient* avahi_domain_browser_get_client (AvahiDomainBrowser *b)
-{
+AvahiClient* avahi_domain_browser_get_client (AvahiDomainBrowser *b) {
     assert(b);
     return b->client;
 }
@@ -176,7 +177,7 @@ DBusHandlerResult avahi_domain_browser_event (AvahiClient *client, AvahiBrowserE
     DBusError error;
     const char *path;
     char *domain = NULL;
-    int32_t interface = AVAHI_IF_UNSPEC, protocol = AVAHI_PROTO_UNSPEC;
+    int32_t interface, protocol;
     uint32_t flags = 0;
 
     assert(client);
@@ -194,6 +195,9 @@ DBusHandlerResult avahi_domain_browser_event (AvahiClient *client, AvahiBrowserE
     if (!db)
         goto fail;
 
+    interface = db->interface;
+    protocol = db->protocol;
+
     switch (event) {
         case AVAHI_BROWSER_NEW:
         case AVAHI_BROWSER_REMOVE:
@@ -281,9 +285,18 @@ AvahiServiceTypeBrowser* avahi_service_type_browser_new(
     b->callback = callback;
     b->userdata = userdata;
     b->path = NULL;
+    b->domain = NULL;
+    b->interface = interface;
+    b->protocol = protocol;
 
     AVAHI_LLIST_PREPEND(AvahiServiceTypeBrowser, service_type_browsers, client->service_type_browsers, b);
 
+    if (domain[0])
+        if (!(b->domain = avahi_strdup(domain))) {
+            avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
+            goto fail;
+        }
+          
     if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "ServiceTypeBrowserNew"))) {
         avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
         goto fail;
@@ -349,8 +362,7 @@ fail:
     return NULL;
 }
 
-AvahiClient* avahi_service_type_browser_get_client (AvahiServiceTypeBrowser *b)
-{
+AvahiClient* avahi_service_type_browser_get_client (AvahiServiceTypeBrowser *b) {
     assert(b);
     return b->client;
 }
@@ -368,6 +380,7 @@ int avahi_service_type_browser_free (AvahiServiceTypeBrowser *b) {
     AVAHI_LLIST_REMOVE(AvahiServiceTypeBrowser, service_type_browsers, b->client->service_type_browsers, b);
 
     avahi_free(b->path);
+    avahi_free(b->domain);
     avahi_free(b);
     return r;
 }
@@ -376,8 +389,8 @@ DBusHandlerResult avahi_service_type_browser_event (AvahiClient *client, AvahiBr
     AvahiServiceTypeBrowser *b = NULL;
     DBusError error;
     const char *path;
-    char *domain = NULL, *type = NULL;
-    int32_t interface = AVAHI_IF_UNSPEC, protocol = AVAHI_PROTO_UNSPEC;
+    char *domain, *type = NULL;
+    int32_t interface, protocol;
     uint32_t flags = 0;
 
     assert(client);
@@ -394,6 +407,11 @@ DBusHandlerResult avahi_service_type_browser_event (AvahiClient *client, AvahiBr
 
     if (!b)
         goto fail;
+
+    domain = b->domain;
+    interface = b->interface;
+    protocol = b->protocol;
+    
     switch (event) {
         case AVAHI_BROWSER_NEW:
         case AVAHI_BROWSER_REMOVE:
@@ -483,9 +501,23 @@ AvahiServiceBrowser* avahi_service_browser_new(
     b->callback = callback;
     b->userdata = userdata;
     b->path = NULL;
+    b->type = b->domain = NULL;
+    b->interface = interface;
+    b->protocol = protocol;
 
     AVAHI_LLIST_PREPEND(AvahiServiceBrowser, service_browsers, client->service_browsers, b);
 
+    if (!(b->type = avahi_strdup(type))) {
+        avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
+        goto fail;
+    }
+    
+    if (domain && domain[0])
+        if (!(b->domain = avahi_strdup(domain))) {
+            avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
+            goto fail;
+        }
+    
     if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "ServiceBrowserNew"))) {
         avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
         goto fail;
@@ -551,8 +583,7 @@ fail:
     return NULL;
 }
 
-AvahiClient* avahi_service_browser_get_client (AvahiServiceBrowser *b)
-{
+AvahiClient* avahi_service_browser_get_client (AvahiServiceBrowser *b) {
     assert(b);
     return b->client;
 }
@@ -570,17 +601,18 @@ int avahi_service_browser_free (AvahiServiceBrowser *b) {
     AVAHI_LLIST_REMOVE(AvahiServiceBrowser, service_browsers, b->client->service_browsers, b);
 
     avahi_free(b->path);
+    avahi_free(b->type);
+    avahi_free(b->domain);
     avahi_free(b);
     return r;
 }
 
-
 DBusHandlerResult avahi_service_browser_event(AvahiClient *client, AvahiBrowserEvent event, DBusMessage *message) {
     AvahiServiceBrowser *b = NULL;
     DBusError error;
     const char *path;
-    char *name = NULL, *type = NULL, *domain = NULL;
-    int32_t interface = AVAHI_IF_UNSPEC, protocol = AVAHI_PROTO_UNSPEC;
+    char *name = NULL, *type, *domain;
+    int32_t interface, protocol;
     uint32_t flags = 0;
 
     dbus_error_init (&error);
@@ -595,6 +627,11 @@ DBusHandlerResult avahi_service_browser_event(AvahiClient *client, AvahiBrowserE
     if (!b)
         goto fail;
 
+    type = b->type;
+    domain = b->domain;
+    interface = b->interface;
+    protocol = b->protocol;
+
     switch (event) {
         case AVAHI_BROWSER_NEW:
         case AVAHI_BROWSER_REMOVE:
index 076fb3b4f7e36df85a6aaf25e67cef87db5715e0..f9913e624f276a86d8d45085a6eccc5ed7f87ab0 100644 (file)
@@ -33,6 +33,7 @@
 #include <avahi-common/error.h>
 #include <avahi-common/simple-watch.h>
 #include <avahi-common/malloc.h>
+#include <avahi-common/timeval.h>
 
 static const AvahiPoll *poll_api = NULL;
 static AvahiSimplePoll *simple_poll = NULL;
@@ -129,7 +130,6 @@ static void avahi_address_resolver_callback (
     AvahiIfIndex interface,
     AvahiProtocol protocol,
     AvahiResolverEvent event,
-    AvahiProtocol aprotocol,
     const AvahiAddress *address,
     const char *name,
     AvahiLookupResultFlags flags,
@@ -141,7 +141,7 @@ static void avahi_address_resolver_callback (
         return;
     }
     avahi_address_snprint (addr, sizeof (addr), address);
-    printf ("ADDRESS-RESOLVER: Callback on AddressResolver, interface (%d), protocol (%d), even (%d), aprotocol (%d), address (%s), name (%s), data(%s)\n", interface, protocol, event, aprotocol, addr, name, (char*) userdata);
+    printf ("ADDRESS-RESOLVER: Callback on AddressResolver, interface (%d), protocol (%d), even (%d), address (%s), name (%s), data(%s)\n", interface, protocol, event, addr, name, (char*) userdata);
 }
 
 static void avahi_host_name_resolver_callback (
@@ -163,7 +163,7 @@ static void avahi_host_name_resolver_callback (
         return;
     }
     client = avahi_host_name_resolver_get_client (r);
-    ar = avahi_address_resolver_new_a (client, interface, protocol, a, 0, avahi_address_resolver_callback, "omghai6u");
+    ar = avahi_address_resolver_new(client, interface, protocol, a, 0, avahi_address_resolver_callback, "omghai6u");
     if (ar)
     {
         printf ("Succesfully created address resolver object\n");
@@ -293,7 +293,7 @@ int main (int argc, char *argv[]) {
         group2 = avahi_entry_group_new (avahi, avahi_entry_group2_callback, "omghai222");
         if ((error = avahi_entry_group_add_address (group2, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, "test-mdns.local.", aar)) < 0)
         {
-            printf ("*** failed to add address to entry group: %s\n", avahi_strerror (ret));
+            printf ("*** failed to add address to entry group: %s\n", avahi_strerror (error));
             avahi_entry_group_free (group2);
         } else {
             printf ("*** success, added address\n");
index 8b0d9579acff8fa666fba35dadc9ddc759958c95..8bc515ee5aa42ff38f99fc5dccca25cda6c920f5 100644 (file)
@@ -725,70 +725,3 @@ fail:
 
     return AVAHI_SERVICE_COOKIE_INVALID;
 }
-
-int avahi_client_is_service_local(AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain) {
-    DBusMessage *message = NULL, *reply = NULL;
-    DBusError error;
-    int32_t i_interface, i_protocol;
-    int b;
-
-    assert(client);
-    assert(name);
-    assert(type);
-    assert(domain);
-
-    if (client->state == AVAHI_CLIENT_DISCONNECTED) {
-        avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE);
-        return AVAHI_SERVICE_COOKIE_INVALID;
-    }
-
-    dbus_error_init (&error);
-
-    if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "IsServiceLocal"))) {
-        avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
-        goto fail;
-    }
-
-    i_interface = (int32_t) interface;
-    i_protocol = (int32_t) protocol;
-    
-    if (!dbus_message_append_args(
-            message,
-            DBUS_TYPE_INT32, &i_interface,
-            DBUS_TYPE_INT32, &i_protocol,
-            DBUS_TYPE_STRING, &name,
-            DBUS_TYPE_STRING, &type,
-            DBUS_TYPE_STRING, &domain,
-            DBUS_TYPE_INVALID)) {
-        avahi_client_set_errno (client, AVAHI_ERR_NO_MEMORY);
-        goto fail;
-    }
-
-    reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error);
-
-    if (!reply || dbus_error_is_set (&error))
-        goto fail;
-
-    if (!dbus_message_get_args (reply, &error, DBUS_TYPE_BOOLEAN, &b, DBUS_TYPE_INVALID) ||
-        dbus_error_is_set (&error))
-        goto fail;
-    
-    dbus_message_unref(message);
-    dbus_message_unref(reply);
-
-    return b;
-
-fail:
-
-    if (message)
-        dbus_message_unref(message);
-    if (reply)
-        dbus_message_unref(reply);
-    
-    if (dbus_error_is_set(&error)) {
-        avahi_client_set_dbus_error(client, &error);
-        dbus_error_free(&error);
-    }
-
-    return AVAHI_SERVICE_COOKIE_INVALID;
-}
index 8a59ca111c2eb740ecf234d77bd2d97005b9760e..d00cc8b39f25acee2d07b1ab32ef0df7f96554f0 100644 (file)
@@ -82,9 +82,6 @@ int avahi_client_errno (AvahiClient*);
 /** Return the local service cookie. returns AVAHI_SERVICE_COOKIE_INVALID on failure. */
 uint32_t avahi_client_get_local_service_cookie(AvahiClient *client);
 
-/** Return 1 if the specified service is a registered locally, negative on failure, 0 otherwise. */
-int avahi_client_is_service_local(AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain);
-
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
 AVAHI_C_DECL_END
 #endif
index 0b7d2176874efbc19facda0e89224441161f6a0a..9d58afbeddf34ae18edf050fa76b08f9c3ebd5cf 100644 (file)
@@ -336,7 +336,6 @@ static int append_string_list(DBusMessage *message, AvahiStringList *txt) {
     AvahiStringList *p;
 
     assert(message);
-    assert(txt);
 
     dbus_message_iter_init_append(message, &iter);
 
index 56aaaae94ef6cb4aeab7b829968b3eb17a891e9b..c9c9dc7497f0642cba064c691dca765c9b61d767 100644 (file)
@@ -66,6 +66,9 @@ struct AvahiDomainBrowser {
     AvahiDomainBrowserCallback callback;
     void *userdata;
     AVAHI_LLIST_FIELDS(AvahiDomainBrowser, domain_browsers);
+
+    AvahiIfIndex interface;
+    AvahiProtocol protocol;
 };
 
 struct AvahiServiceBrowser {
@@ -74,6 +77,10 @@ struct AvahiServiceBrowser {
     AvahiServiceBrowserCallback callback;
     void *userdata;
     AVAHI_LLIST_FIELDS(AvahiServiceBrowser, service_browsers);
+
+    char *type, *domain;
+    AvahiIfIndex interface;
+    AvahiProtocol protocol;
 };
 
 struct AvahiServiceTypeBrowser {
@@ -82,6 +89,10 @@ struct AvahiServiceTypeBrowser {
     AvahiServiceTypeBrowserCallback callback;
     void *userdata;
     AVAHI_LLIST_FIELDS(AvahiServiceTypeBrowser, service_type_browsers);
+
+    char *domain;
+    AvahiIfIndex interface;
+    AvahiProtocol protocol;
 };
 
 struct AvahiServiceResolver {
@@ -90,6 +101,10 @@ struct AvahiServiceResolver {
     AvahiServiceResolverCallback callback;
     void *userdata;
     AVAHI_LLIST_FIELDS(AvahiServiceResolver, service_resolvers);
+
+    char *name, *type, *domain;
+    AvahiIfIndex interface;
+    AvahiProtocol protocol;
 };
 
 struct AvahiHostNameResolver {
@@ -98,6 +113,10 @@ struct AvahiHostNameResolver {
     AvahiHostNameResolverCallback callback;
     void *userdata;
     AVAHI_LLIST_FIELDS(AvahiHostNameResolver, host_name_resolvers);
+
+    char *host_name;
+    AvahiIfIndex interface;
+    AvahiProtocol protocol;
 };
 
 struct AvahiAddressResolver {
@@ -106,6 +125,10 @@ struct AvahiAddressResolver {
     AvahiAddressResolverCallback callback;
     void *userdata;
     AVAHI_LLIST_FIELDS(AvahiAddressResolver, address_resolvers);
+
+    AvahiAddress address;
+    AvahiIfIndex interface;
+    AvahiProtocol protocol;
 };
 
 int avahi_client_set_errno (AvahiClient *client, int error);
index 659700eb107ab34662e6f29e3d161a7198fe663d..bf19479f8e817a78c0f97c8824c22e22862b2e3c 100644 (file)
@@ -102,13 +102,11 @@ typedef void (*AvahiAddressResolverCallback) (
     AvahiIfIndex interface,
     AvahiProtocol protocol,
     AvahiResolverEvent event,
-    AvahiProtocol aprotocol,
     const AvahiAddress *a,
     const char *name,
     AvahiLookupResultFlags flags, 
     void *userdata);
 
-
 /** Browse for domains on the local network */
 AvahiDomainBrowser* avahi_domain_browser_new (
     AvahiClient *client,
@@ -195,18 +193,8 @@ AvahiClient* avahi_host_name_resolver_get_client (AvahiHostNameResolver *);
 /** Free a hostname resolver object */
 int avahi_host_name_resolver_free(AvahiHostNameResolver *r);
 
-/** Create a new address resolver object from an address string.  Set aprotocol to AF_UNSPEC for protocol detection. */
-AvahiAddressResolver * avahi_address_resolver_new(
-    AvahiClient *client,
-    AvahiIfIndex interface,
-    AvahiProtocol protocol,
-    const char *address,
-    AvahiLookupFlags flags,
-    AvahiAddressResolverCallback callback,
-    void *userdata);
-
 /** Create a new address resolver object from an AvahiAddress object */
-AvahiAddressResolver* avahi_address_resolver_new_a(
+AvahiAddressResolver* avahi_address_resolver_new(
     AvahiClient *client,
     AvahiIfIndex interface,
     AvahiProtocol protocol,
index 14d6acadee4d1178f2b57394880ccf2b16811510..d06c43c7ba3cd808a0a4addcfda19974a3f455f8 100644 (file)
@@ -165,7 +165,7 @@ DBusHandlerResult avahi_service_resolver_event (AvahiClient *client, AvahiResolv
             }
             
             avahi_client_set_errno(r->client, avahi_error_dbus_to_number(etxt));
-            r->callback(r, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, event, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, r->userdata);
+            r->callback(r, r->interface, r->protocol, event, r->name, r->type, r->domain, NULL, NULL, 0, NULL, 0, r->userdata);
             break;
         }
     }
@@ -223,9 +223,30 @@ AvahiServiceResolver * avahi_service_resolver_new(
     r->callback = callback;
     r->userdata = userdata;
     r->path = NULL;
+    r->name = r->type = r->domain = NULL;
+    r->interface = interface;
+    r->protocol = protocol;
     
     AVAHI_LLIST_PREPEND(AvahiServiceResolver, service_resolvers, client->service_resolvers, r);
 
+    if (name && name[0])
+        if (!(r->name = avahi_strdup(name))) {
+            avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
+            goto fail;
+        }
+
+    if (!(r->type = avahi_strdup(type))) {
+        avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
+        goto fail;
+    }
+
+    if (domain && domain[0])
+        if (!(r->domain = avahi_strdup(domain))) {
+            avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
+            goto fail;
+        }
+    
+    
     if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "ServiceResolverNew"))) {
         avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
         goto fail;
@@ -316,6 +337,9 @@ int avahi_service_resolver_free(AvahiServiceResolver *r) {
     AVAHI_LLIST_REMOVE(AvahiServiceResolver, service_resolvers, client->service_resolvers, r);
 
     avahi_free(r->path);
+    avahi_free(r->name);
+    avahi_free(r->type);
+    avahi_free(r->domain);
     avahi_free(r);
 
     return ret;
@@ -387,7 +411,7 @@ DBusHandlerResult avahi_host_name_resolver_event (AvahiClient *client, AvahiReso
             }
             
             avahi_client_set_errno(r->client, avahi_error_dbus_to_number(etxt));
-            r->callback(r, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, event, NULL, NULL, 0, r->userdata);
+            r->callback(r, r->interface, r->protocol, event, r->host_name, NULL, 0, r->userdata);
             break;
         }
     }
@@ -436,9 +460,17 @@ AvahiHostNameResolver * avahi_host_name_resolver_new(
     r->callback = callback;
     r->userdata = userdata;
     r->path = NULL;
+    r->interface = interface;
+    r->protocol = protocol;
+    r->host_name = NULL;
     
     AVAHI_LLIST_PREPEND(AvahiHostNameResolver, host_name_resolvers, client->host_name_resolvers, r);
 
+    if (!(r->host_name = avahi_strdup(name))) {
+        avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
+        goto fail;
+    }
+
     if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "HostNameResolverNew"))) {
         avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
         goto fail;
@@ -520,6 +552,7 @@ int avahi_host_name_resolver_free(AvahiHostNameResolver *r) {
     AVAHI_LLIST_REMOVE(AvahiHostNameResolver, host_name_resolvers, client->host_name_resolvers, r);
 
     avahi_free(r->path);
+    avahi_free(r->host_name);
     avahi_free(r);
 
     return ret;
@@ -580,7 +613,7 @@ DBusHandlerResult avahi_address_resolver_event (AvahiClient *client, AvahiResolv
                 goto fail;
             }
             
-            r->callback(r, (AvahiIfIndex) interface, (AvahiProtocol) protocol, AVAHI_RESOLVER_FOUND, (AvahiProtocol) aprotocol, &a, name, (AvahiLookupResultFlags) flags, r->userdata);
+            r->callback(r, (AvahiIfIndex) interface, (AvahiProtocol) protocol, AVAHI_RESOLVER_FOUND, &a, name, (AvahiLookupResultFlags) flags, r->userdata);
             break;
         }
 
@@ -597,7 +630,7 @@ DBusHandlerResult avahi_address_resolver_event (AvahiClient *client, AvahiResolv
             }
             
             avahi_client_set_errno(r->client, avahi_error_dbus_to_number(etxt));
-            r->callback(r, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, event, AVAHI_PROTO_UNSPEC, NULL, NULL, 0, r->userdata);
+            r->callback(r, r->interface, r->protocol, event, &r->address, NULL, 0, r->userdata);
             break;
         }
     }
@@ -609,35 +642,11 @@ fail:
     return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
-AvahiAddressResolver * avahi_address_resolver_new_a(
-    AvahiClient *client,
-    AvahiIfIndex interface,
-    AvahiProtocol protocol,
-    const AvahiAddress *a,
-    AvahiLookupFlags flags,
-    AvahiAddressResolverCallback callback,
-    void *userdata) {
-
-    char addr[AVAHI_ADDRESS_STR_MAX];
-
-    assert (a);
-
-    if (!avahi_address_snprint (addr, sizeof (addr), a)) {
-        avahi_client_set_errno(client, AVAHI_ERR_INVALID_ADDRESS);
-        return NULL;
-    }
-
-    return avahi_address_resolver_new(
-        client, interface, protocol,
-        addr, flags,
-        callback, userdata);
-}
-
 AvahiAddressResolver * avahi_address_resolver_new(
     AvahiClient *client,
     AvahiIfIndex interface,
     AvahiProtocol protocol,
-    const char *address,
+    const AvahiAddress *a,
     AvahiLookupFlags flags, 
     AvahiAddressResolverCallback callback,
     void *userdata) {
@@ -648,11 +657,18 @@ AvahiAddressResolver * avahi_address_resolver_new(
     int32_t i_interface, i_protocol;
     uint32_t u_flags;
     char *path;
-    
+    char addr[AVAHI_ADDRESS_STR_MAX], *address = addr;
+
     assert(client);
+    assert(a);
 
     dbus_error_init (&error);
 
+    if (!avahi_address_snprint (addr, sizeof(addr), a)) {
+        avahi_client_set_errno(client, AVAHI_ERR_INVALID_ADDRESS);
+        return NULL;
+    }
+
     if (client->state == AVAHI_CLIENT_DISCONNECTED) {
         avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE);
         goto fail;
@@ -667,6 +683,9 @@ AvahiAddressResolver * avahi_address_resolver_new(
     r->callback = callback;
     r->userdata = userdata;
     r->path = NULL;
+    r->interface = interface;
+    r->protocol = protocol;
+    r->address = *a;
     
     AVAHI_LLIST_PREPEND(AvahiAddressResolver, address_resolvers, client->address_resolvers, r);
 
index 41e4daafbbaf1af093cd37d92a98c4d29de31218..67bdddc485dbfe9fed3522b89a174db501ee1907 100644 (file)
@@ -161,8 +161,7 @@ typedef enum {
     AVAHI_PUBLISH_ALLOW_MULTIPLE = 8,   /**< For raw records: Allow multiple local records of this type, even if they are intended to be unique */
     AVAHI_PUBLISH_NO_REVERSE = 16,      /**< For address records: don't create a reverse (PTR) entry */
     AVAHI_PUBLISH_NO_COOKIE = 32,       /**< For service records: do not implicitly add the local service cookie to TXT data */
-    AVAHI_PUBLISH_IS_PROXY = 64,        /**< For service records: this is a proxy for another host. This modifies behaviour of avahi_server_is_service_local() */
-    AVAHI_PUBLISH_UPDATE = 128          /**< Update existing records instead of adding new ones */
+    AVAHI_PUBLISH_UPDATE = 64           /**< Update existing records instead of adding new ones */
 } AvahiPublishFlags;
 
 /** Some flags for lookup functions */
@@ -177,9 +176,11 @@ typedef enum {
 /** Some flags for lookup callback functions */
 typedef enum {
     AVAHI_LOOKUP_RESULT_NULL = 0,
-    AVAHI_LOOKUP_RESULT_CACHED = 1,      /**< This response originates from the cache */
-    AVAHI_LOOKUP_RESULT_WIDE_AREA = 2,   /**< This response originates from wide area DNS */
-    AVAHI_LOOKUP_RESULT_MULTICAST = 4    /**< This response originates from multicast DNS */
+    AVAHI_LOOKUP_RESULT_CACHED = 1,         /**< This response originates from the cache */
+    AVAHI_LOOKUP_RESULT_WIDE_AREA = 2,      /**< This response originates from wide area DNS */
+    AVAHI_LOOKUP_RESULT_MULTICAST = 4,      /**< This response originates from multicast DNS */
+    AVAHI_LOOKUP_RESULT_LOCAL = 8,          /**< This record/service resides on and was announced by the local host. Only available in service and record browsers and only on AVAHI_BROWSER_NEW. */
+    AVAHI_LOOKUP_RESULT_OUR_OWN = 16        /**< This service belongs to the same local client as the browser object. Only available in avahi-client, and only for service browsers and only on AVAHI_BROWSER_NEW. */
 } AvahiLookupResultFlags;
 
 /** Type of callback event when browsing */
index 2c907c3fef31acf9b44f288216f9e2d24834a98f..ba0aeaa145dc81a177e05a042cc451aaef75885d 100644 (file)
@@ -151,6 +151,8 @@ static void record_browser_callback(
     assert(rr);
     assert(b);
 
+    /* Filter flags */
+    flags &= AVAHI_LOOKUP_RESULT_CACHED | AVAHI_LOOKUP_RESULT_MULTICAST | AVAHI_LOOKUP_RESULT_WIDE_AREA;
 
     switch (event) {
         case AVAHI_BROWSER_NEW: {
index e2eab44bafc79ad9fcf032c10ecf86b3660d2aca..507446970b13e39140eb0c0adb897b1a1fc53003 100644 (file)
@@ -54,6 +54,9 @@ static void record_browser_callback(
 
     assert(rr);
     assert(b);
+
+    /* Filter flags */
+    flags &= AVAHI_LOOKUP_RESULT_CACHED | AVAHI_LOOKUP_RESULT_MULTICAST | AVAHI_LOOKUP_RESULT_WIDE_AREA;
     
     if (record) {
         assert(record->key->type == AVAHI_DNS_TYPE_PTR);
@@ -63,7 +66,6 @@ static void record_browser_callback(
     b->callback(b, interface, protocol, event, n, flags, b->userdata);
 }
 
-
 AvahiSDomainBrowser *avahi_s_domain_browser_new(
     AvahiServer *server,
     AvahiIfIndex interface,
index 39bf4712cdfa090466d9f22b4e802d853cdbc043..252e3cb0f1d2fe389f4ba8f6dee36dff500e8e66 100644 (file)
@@ -58,6 +58,9 @@ static void record_browser_callback(
     assert(rr);
     assert(b);
 
+    /* Filter flags */
+    flags &= AVAHI_LOOKUP_RESULT_CACHED | AVAHI_LOOKUP_RESULT_MULTICAST | AVAHI_LOOKUP_RESULT_WIDE_AREA;
+
     if (record) {
         char type[AVAHI_DOMAIN_NAME_MAX], domain[AVAHI_DOMAIN_NAME_MAX];
         
index 170a64fde88b5ee6b0e391f12b04edb6ef7378b9..43778ddc6f0c49f7f12cf0f3860be2dbe63aab07 100644 (file)
@@ -59,11 +59,17 @@ static void record_browser_callback(
     assert(rr);
     assert(b);
 
+    /* Filter flags */
+    flags &= AVAHI_LOOKUP_RESULT_CACHED | AVAHI_LOOKUP_RESULT_MULTICAST | AVAHI_LOOKUP_RESULT_WIDE_AREA;
+    
     if (record) {
         char service[AVAHI_LABEL_MAX], type[AVAHI_DOMAIN_NAME_MAX], domain[AVAHI_DOMAIN_NAME_MAX];
 
         assert(record->key->type == AVAHI_DNS_TYPE_PTR);
 
+        if (event == AVAHI_BROWSER_NEW && avahi_server_is_service_local(b->server, interface, protocol, record->data.ptr.name))
+            flags |= AVAHI_LOOKUP_RESULT_LOCAL;
+
         if (avahi_service_name_split(record->data.ptr.name, service, sizeof(service), type, sizeof(type), domain, sizeof(domain)) < 0) {
             avahi_log_warn("Failed to split '%s'", record->key->name);
             return;
index 09bc0fa1f869b92aae244dc88b1dbac8b922f85b..e7e01d1ef790ba35595c881f629461fa3c3e93ae 100644 (file)
@@ -280,6 +280,9 @@ static void lookup_multicast_callback(
                 /* It's a normal record, so let's call the user callback */
                 assert(avahi_key_equal(b->key, l->key));
 
+                if (avahi_server_is_record_local(b->server, interface, protocol, r))
+                    flags |= AVAHI_LOOKUP_RESULT_LOCAL;
+                
                 b->callback(b, interface, protocol, event, r, flags, b->userdata);
             }
             break;
index e3bf8a3af8e705272f2f47e9c92101c3856189df..4223bf7695aa36b74614fb47b7828aef28fca081 100644 (file)
@@ -154,9 +154,6 @@ int avahi_server_errno(AvahiServer *s);
 /** Return the local service cookie */
 uint32_t avahi_server_get_local_service_cookie(AvahiServer *s);
 
-/** Return 1 if there is a local service with the specified credentials registeresd. Return 0 if not, negative on failure */
-int avahi_server_is_service_local(AvahiServer *s, AvahiIfIndex, AvahiProtocol protocol, const char *name, const char *type,  const char*domain);
-
 /** Set the wide area DNS servers */
 int avahi_server_set_wide_area_servers(AvahiServer *s, const AvahiAddress *a, unsigned n);
 
index fe7702e01693df42298da09426fa84b54f6ee424..3b73ff3f7fac1732b67780ea78413ee1eac95a28 100644 (file)
@@ -172,7 +172,6 @@ int avahi_server_add(
             AVAHI_PUBLISH_NO_PROBE|
             AVAHI_PUBLISH_UNIQUE|
             AVAHI_PUBLISH_ALLOW_MULTIPLE|
-            AVAHI_PUBLISH_IS_PROXY|
             AVAHI_PUBLISH_UPDATE))
         return avahi_server_set_errno(s, AVAHI_ERR_INVALID_FLAGS);
     
@@ -523,7 +522,7 @@ static int server_add_service_strlst_nocopy(
 
     AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, AVAHI_IF_VALID(interface), AVAHI_ERR_INVALID_INTERFACE);
     AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, AVAHI_PROTO_VALID(protocol), AVAHI_ERR_INVALID_PROTOCOL);
-    AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, AVAHI_FLAGS_VALID(flags, AVAHI_PUBLISH_NO_COOKIE|AVAHI_PUBLISH_IS_PROXY|AVAHI_PUBLISH_UPDATE), AVAHI_ERR_INVALID_FLAGS);
+    AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, AVAHI_FLAGS_VALID(flags, AVAHI_PUBLISH_NO_COOKIE|AVAHI_PUBLISH_UPDATE), AVAHI_ERR_INVALID_FLAGS);
     AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, avahi_is_valid_service_name(name), AVAHI_ERR_INVALID_SERVICE_NAME);
     AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, avahi_is_valid_service_type_strict(type), AVAHI_ERR_INVALID_SERVICE_TYPE);
     AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, !domain || avahi_is_valid_domain_name(domain), AVAHI_ERR_INVALID_DOMAIN_NAME);
@@ -549,7 +548,7 @@ static int server_add_service_strlst_nocopy(
 
     /* Add service enumeration PTR record */
     
-    if ((ret = avahi_server_add_ptr(s, g, interface, protocol, flags & AVAHI_PUBLISH_IS_PROXY, AVAHI_DEFAULT_TTL, ptr_name, svc_name)) < 0)
+    if ((ret = avahi_server_add_ptr(s, g, interface, protocol, 0, AVAHI_DEFAULT_TTL, ptr_name, svc_name)) < 0)
         goto fail;
 
     /* Add SRV record */
@@ -564,7 +563,7 @@ static int server_add_service_strlst_nocopy(
     r->data.srv.port = port;
     r->data.srv.name = h;
     h = NULL;
-    ret = avahi_server_add(s, g, interface, protocol, (flags & AVAHI_PUBLISH_IS_PROXY) | AVAHI_PUBLISH_UNIQUE, r);
+    ret = avahi_server_add(s, g, interface, protocol, AVAHI_PUBLISH_UNIQUE, r);
     avahi_record_unref(r);
 
     if (ret < 0)
@@ -575,7 +574,7 @@ static int server_add_service_strlst_nocopy(
     if (!(flags & AVAHI_PUBLISH_NO_COOKIE))
         strlst = add_magic_cookie(s, strlst);
     
-    ret = server_add_txt_strlst_nocopy(s, g, interface, protocol, (flags & AVAHI_PUBLISH_IS_PROXY) | AVAHI_PUBLISH_UNIQUE, AVAHI_DEFAULT_TTL, svc_name, strlst);
+    ret = server_add_txt_strlst_nocopy(s, g, interface, protocol, AVAHI_PUBLISH_UNIQUE, AVAHI_DEFAULT_TTL, svc_name, strlst);
     strlst = NULL;
 
     if (ret < 0)
@@ -583,7 +582,7 @@ static int server_add_service_strlst_nocopy(
 
     /* Add service type enumeration record */
     
-    ret = avahi_server_add_ptr(s, g, interface, protocol, (flags & AVAHI_PUBLISH_IS_PROXY), AVAHI_DEFAULT_TTL, enum_ptr, ptr_name);
+    ret = avahi_server_add_ptr(s, g, interface, protocol, 0, AVAHI_DEFAULT_TTL, enum_ptr, ptr_name);
 
 fail:
     
@@ -676,7 +675,7 @@ static int server_update_service_txt_strlst_nocopy(
 
     AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, AVAHI_IF_VALID(interface), AVAHI_ERR_INVALID_INTERFACE);
     AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, AVAHI_PROTO_VALID(protocol), AVAHI_ERR_INVALID_PROTOCOL);
-    AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, AVAHI_FLAGS_VALID(flags, AVAHI_PUBLISH_IS_PROXY|AVAHI_PUBLISH_NO_COOKIE), AVAHI_ERR_INVALID_FLAGS);
+    AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, AVAHI_FLAGS_VALID(flags, AVAHI_PUBLISH_NO_COOKIE), AVAHI_ERR_INVALID_FLAGS);
     AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, avahi_is_valid_service_name(name), AVAHI_ERR_INVALID_SERVICE_NAME);
     AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, avahi_is_valid_service_type_strict(type), AVAHI_ERR_INVALID_SERVICE_TYPE);
     AVAHI_CHECK_VALIDITY_SET_RET_GOTO_FAIL(s, !domain || avahi_is_valid_domain_name(domain), AVAHI_ERR_INVALID_DOMAIN_NAME);
@@ -693,7 +692,7 @@ static int server_update_service_txt_strlst_nocopy(
     if (!(flags & AVAHI_PUBLISH_NO_COOKIE))
         strlst = add_magic_cookie(s, strlst);
     
-    ret = server_add_txt_strlst_nocopy(s, g, interface, protocol, (flags & AVAHI_PUBLISH_IS_PROXY) | AVAHI_PUBLISH_UNIQUE | AVAHI_PUBLISH_UPDATE, AVAHI_DEFAULT_TTL, svc_name, strlst);
+    ret = server_add_txt_strlst_nocopy(s, g, interface, protocol, AVAHI_PUBLISH_UNIQUE | AVAHI_PUBLISH_UPDATE, AVAHI_DEFAULT_TTL, svc_name, strlst);
     strlst = NULL;
 
 fail:
@@ -789,7 +788,7 @@ int avahi_server_add_service_subtype(
         goto fail;
     }
 
-    if ((ret = avahi_server_add_ptr(s, g, interface, protocol, flags & AVAHI_PUBLISH_IS_PROXY, AVAHI_DEFAULT_TTL, ptr_name, svc_name)) < 0)
+    if ((ret = avahi_server_add_ptr(s, g, interface, protocol, 0, AVAHI_DEFAULT_TTL, ptr_name, svc_name)) < 0)
         goto fail;
 
 fail:
index 47a9c8465ad2a43e80c1a6e4b4acb7b9e4ce5c84..27edde8cc5aa3cc1f6fbbcfc2ab236fbf8bbaee6 100644 (file)
@@ -180,6 +180,9 @@ void avahi_server_decrease_host_rr_pending(AvahiServer *s);
 
 int avahi_server_set_errno(AvahiServer *s, int error);
 
+int avahi_server_is_service_local(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, const char *name);
+int avahi_server_is_record_local(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, AvahiRecord *record);
+
 int avahi_server_add_ptr(
     AvahiServer *s,
     AvahiSEntryGroup *g,
@@ -191,6 +194,8 @@ int avahi_server_add_ptr(
     const char *dest);
 
 
+
+
 #define AVAHI_CHECK_VALIDITY_RETURN_NULL(server, expression, error) { \
         if (!(expression)) { \
             avahi_server_set_errno((server), (error)); \
index a059a4b802ea0326f78562b7be6352c5668866a4..38e5116b4a852143c154dcec10c91e3ed249ecc1 100644 (file)
@@ -197,6 +197,9 @@ int avahi_server_update_service_txt(
     const char *domain,   
     ...) AVAHI_GCC_SENTINEL;
 
+/** Check if there is a service locally defined and return the entry group it is attached to. Returns NULL if the service isn't local*/
+int avahi_server_get_group_of_service(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain, AvahiSEntryGroup** ret_group);
+
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
 AVAHI_C_DECL_END
 #endif
index 661982d4989c267e37e3e3ab23272c58647b0536..94e07f5356929ca75fca1ad575c593b3357ae2c2 100644 (file)
@@ -108,7 +108,6 @@ static void record_browser_callback(
     assert(rr);
     assert(r);
 
-
     switch (event) {
         case AVAHI_BROWSER_NEW: 
             assert(record);
index 5651bc16c906ae0866e2a5ef01c4dd7836fd4ba1..a1486f88935e52148d65d7c70fab7ebe6b9461e2 100644 (file)
@@ -1566,17 +1566,40 @@ uint32_t avahi_server_get_local_service_cookie(AvahiServer *s) {
     return s->local_service_cookie;
 }
 
-int avahi_server_is_service_local(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char*domain) {
+static AvahiEntry *find_entry(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, AvahiKey *key) {
+    AvahiEntry *e;
+    
+    assert(s);
+    assert(key);
+
+    for (e = avahi_hashmap_lookup(s->entries_by_key, key); e; e = e->by_key_next)
+
+        if ((e->interface == interface || e->interface <= 0 || interface <= 0) &&
+            (e->protocol == protocol || e->protocol == AVAHI_PROTO_UNSPEC || protocol == AVAHI_PROTO_UNSPEC) &&
+            (!e->group || e->group->state == AVAHI_ENTRY_GROUP_ESTABLISHED || e->group->state == AVAHI_ENTRY_GROUP_REGISTERING))
+
+            return e;
+
+    return NULL;
+}
+
+int avahi_server_get_group_of_service(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain, AvahiSEntryGroup** ret_group) {
     AvahiKey *key = NULL;
-    char n[256];
-    int ret;
     AvahiEntry *e;
+    int ret;
+    char n[AVAHI_DOMAIN_NAME_MAX];
     
     assert(s);
     assert(name);
     assert(type);
-    assert(domain);
+    assert(ret_group);
+
+    if (!AVAHI_IF_VALID(interface))
+        return avahi_server_set_errno(s, AVAHI_ERR_INVALID_INTERFACE);
 
+    if (!AVAHI_IF_VALID(protocol))
+        return avahi_server_set_errno(s, AVAHI_ERR_INVALID_PROTOCOL);
+    
     if (!avahi_is_valid_service_name(name))
         return avahi_server_set_errno(s, AVAHI_ERR_INVALID_SERVICE_NAME);
 
@@ -1592,21 +1615,54 @@ int avahi_server_is_service_local(AvahiServer *s, AvahiIfIndex interface, AvahiP
     if (!(key = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV)))
         return avahi_server_set_errno(s, AVAHI_ERR_NO_MEMORY);
 
-    ret = 0;
-    
-    for (e = avahi_hashmap_lookup(s->entries_by_key, key); e; e = e->by_key_next) {
+    e = find_entry(s, interface, protocol, key);
+    avahi_key_unref(key);
 
-        if ((e->interface == interface || e->interface <= 0 || interface <= 0) &&
-            (e->protocol == protocol || e->protocol == AVAHI_PROTO_UNSPEC || protocol == AVAHI_PROTO_UNSPEC) &&
-            !(e->flags & AVAHI_PUBLISH_IS_PROXY)) {
-            ret = 1;
-            break;
-        }
+    if (e) {
+        *ret_group = e->group;
+        return AVAHI_OK;
     }
+
+    return avahi_server_set_errno(s, AVAHI_ERR_NOT_FOUND);
+}
+
+int avahi_server_is_service_local(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, const char *name) {
+    AvahiKey *key = NULL;
+    AvahiEntry *e;
+
+    assert(s);
+    assert(name);
+
+    if (!s->host_name_fqdn)
+        return 0;
     
+    if (!(key = avahi_key_new(name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_SRV)))
+        return 0;
+
+    e = find_entry(s, interface, protocol, key);
     avahi_key_unref(key);
+
+    if (!e)
+        return 0;
     
-    return ret;
+    return avahi_domain_equal(s->host_name_fqdn, e->record->data.srv.name);
+}
+
+int avahi_server_is_record_local(AvahiServer *s, AvahiIfIndex interface, AvahiProtocol protocol, AvahiRecord *record) {
+    AvahiEntry *e;
+
+    assert(s);
+    assert(record);
+    
+    for (e = avahi_hashmap_lookup(s->entries_by_key, record->key); e; e = e->by_key_next)
+
+        if ((e->interface == interface || e->interface <= 0 || interface <= 0) &&
+            (e->protocol == protocol || e->protocol == AVAHI_PROTO_UNSPEC || protocol == AVAHI_PROTO_UNSPEC) &&
+            (!e->group || e->group->state == AVAHI_ENTRY_GROUP_ESTABLISHED || e->group->state == AVAHI_ENTRY_GROUP_REGISTERING) &&
+            avahi_record_equal_no_ttl(record, e->record))
+            return 1;
+
+    return 0;
 }
 
 /** Set the wide area DNS servers */
index 5d5e8623ba1b78ce0f03f65134717f0898a43409..2e36a21301289e02073354def776404406a89804 100644 (file)
       <arg name="flags" type="u" direction="out"/>
     </method>
 
-    <method name="IsServiceLocal">
-      <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="is_local" type="b" direction="out"/>
-    </method>
-
     <method name="EntryGroupNew">
       <arg name="path" type="o" direction="out"/>
     </method>
index d2d2d8ff5385cc3ddabf8cc1a34ec8bd0f975766..76111562d217d6864e4ab74bd72e5aada480ac06 100644 (file)
@@ -805,22 +805,13 @@ static DBusHandlerResult msg_entry_group_impl(DBusConnection *c, DBusMessage *m,
         return respond_ok(c, m);
         
     } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "IsEmpty")) {
-        DBusMessage *reply;
-        int b;
-        
+
         if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
             avahi_log_warn("Error parsing EntryGroup::IsEmpty message");
             goto fail;
         }
 
-        b = !!avahi_s_entry_group_is_empty(i->entry_group);
-
-        reply = dbus_message_new_method_return(m);
-        dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &b, DBUS_TYPE_INVALID);
-        dbus_connection_send(c, reply, NULL);
-        dbus_message_unref(reply);
-        
-        return DBUS_HANDLER_RESULT_HANDLED;
+        return respond_boolean(c, m, !!avahi_s_entry_group_is_empty(i->entry_group));
         
     } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "GetState")) {
         AvahiEntryGroupState state;
@@ -1271,6 +1262,21 @@ fail:
     return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
+static int is_our_own_service(Client *c, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain) {
+    AvahiSEntryGroup *g;
+        
+
+    if (avahi_server_get_group_of_service(avahi_server, interface, protocol, name, type, domain, &g) == AVAHI_OK) {
+        EntryGroupInfo *egi;
+
+        for (egi = c->entry_groups; egi; egi = egi->entry_groups_next)
+            if (egi->entry_group == g)
+                return 1;
+    }
+
+    return 0;
+}
+
 static void service_browser_callback(AvahiSServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, AvahiLookupResultFlags flags, void* userdata) {
     ServiceBrowserInfo *i = userdata;
     DBusMessage *m;
@@ -1286,6 +1292,13 @@ static void service_browser_callback(AvahiSServiceBrowser *b, AvahiIfIndex inter
 
     m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_SERVICE_BROWSER, map_browse_signal_name(event));
 
+    if (event == AVAHI_BROWSER_NEW) {
+        /* Patch in AVAHI_LOOKUP_RESULT_OUR_OWN */
+
+        if (is_our_own_service(i->client, interface, protocol, name, type, domain) > 0)
+            flags |= AVAHI_LOOKUP_RESULT_OUR_OWN;
+    }
+    
     if (event == AVAHI_BROWSER_NEW || event == AVAHI_BROWSER_REMOVE) {
         assert(name);
         assert(type);
@@ -1359,13 +1372,23 @@ static void sync_service_resolver_callback(
 
         if (!name)
             name = "";
-        
-        assert(a);
-        avahi_address_snprint(t, sizeof(t), a);
 
+        if (a) 
+            avahi_address_snprint(t, sizeof(t), a);
+        else
+            t[0] = 0;
+
+        /* Patch in AVAHI_LOOKUP_RESULT_OUR_OWN */
+
+        if (is_our_own_service(i->client, interface, protocol, name, type, domain) > 0)
+            flags |= AVAHI_LOOKUP_RESULT_OUR_OWN;
+        
         i_interface = (int32_t) interface;
         i_protocol = (int32_t) protocol;
-        i_aprotocol = (int32_t) a->proto;
+        if (a) 
+           i_aprotocol = (int32_t) a->proto;
+       else 
+           i_aprotocol = AVAHI_PROTO_UNSPEC;
         u_flags = (uint32_t) flags;
 
         reply = dbus_message_new_method_return(i->message);
@@ -1391,7 +1414,6 @@ static void sync_service_resolver_callback(
 
         dbus_connection_send(server->bus, reply, NULL);
         dbus_message_unref(reply);
-        
     } else {
         assert(event == AVAHI_RESOLVER_FAILURE);
         
@@ -1613,6 +1635,9 @@ static void async_service_resolver_callback(
         if (!name)
             name = "";
 
+        if (is_our_own_service(i->client, interface, protocol, name, type, domain) > 0)
+            flags |= AVAHI_LOOKUP_RESULT_OUR_OWN;
+
         i_interface = (int32_t) interface;
         i_protocol = (int32_t) protocol;
         if (a) 
@@ -1762,28 +1787,6 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void
         
         return respond_uint32(c, m, avahi_server_get_local_service_cookie(avahi_server));
 
-    } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "IsServiceLocal")) {
-        int32_t interface, protocol;
-        char *name, *type, *domain;
-        int b;
-        
-        if (!dbus_message_get_args(
-                m, &error,
-                DBUS_TYPE_INT32, &interface,
-                DBUS_TYPE_INT32, &protocol,
-                DBUS_TYPE_STRING, &name,
-                DBUS_TYPE_STRING, &type,
-                DBUS_TYPE_STRING, &domain,
-                DBUS_TYPE_INVALID) || !name || !type || !domain) {
-            avahi_log_warn("Error parsing Server::IsServiceLocal message");
-            goto fail;
-        }
-
-        if ((b = avahi_server_is_service_local(avahi_server, interface, protocol, name, type, domain)) < 0)
-            return respond_error(c, m, avahi_server_errno(avahi_server), NULL);            
-        
-        return respond_boolean(c, m, b);
-
     } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetNetworkInterfaceNameByIndex")) {
         int32_t idx;
         int fd;
index 36f1608b7556accffe72f4dd9ca860a3a12ad3db..09777cca847224808f06e21f021a7a8f6161a5d0 100644 (file)
@@ -222,7 +222,7 @@ static void add_static_service_group_to_server(StaticServiceGroup *g) {
                 avahi_server,
                 g->entry_group,
                 AVAHI_IF_UNSPEC, s->protocol,
-                s->host_name ? AVAHI_PUBLISH_IS_PROXY : 0, 
+                0, 
                 g->chosen_name, s->type, 
                 s->domain_name, s->host_name, s->port,
                 s->txt_records) < 0) {
index 3bbed112fa9d56ce30a0c0d16fdec6cf4c978438..5ebbf2d89dc5981fe3dd72d50dcaf2fc1f20521d 100644 (file)
@@ -73,13 +73,15 @@ static void resolve_callback(
                     "\tTXT=%s\n"
                     "\tcookie is %u\n"
                     "\tis_local: %i\n"
+                    "\tour_own: %i\n"
                     "\twide_area: %i\n"
                     "\tmulticast: %i\n"
                     "\tcached: %i\n",
                     host_name, port, a,
                     t,
                     avahi_string_list_get_service_cookie(txt),
-                    avahi_client_is_service_local(avahi_service_resolver_get_client(r), interface, protocol, name, type, domain),
+                    !!(flags & AVAHI_LOOKUP_RESULT_LOCAL),
+                    !!(flags & AVAHI_LOOKUP_RESULT_OUR_OWN),
                     !!(flags & AVAHI_LOOKUP_RESULT_WIDE_AREA),
                     !!(flags & AVAHI_LOOKUP_RESULT_MULTICAST),
                     !!(flags & AVAHI_LOOKUP_RESULT_CACHED));
@@ -176,11 +178,9 @@ int main(int argc, char*argv[]) {
         fprintf(stderr, "Failed to create service browser: %s\n", avahi_strerror(avahi_client_errno(client)));
         goto fail;
     }
-    
+
     /* Run the main loop */
-    for (;;)
-        if (avahi_simple_poll_iterate(simple_poll, -1) != 0)
-            break;
+    avahi_simple_poll_loop(simple_poll);
     
     ret = 0;
     
index e9dcffca8a6aa522db36d55e380ddbf649bcd69f..bb895ce66cc9c6ba10ed56a4f125b9f460d89fad 100644 (file)
@@ -72,15 +72,14 @@ static void create_services(AvahiClient *c) {
     assert(c);
 
     /* If this is the first time we're called, let's create a new entry group */
-    if (!group) {
+    if (!group)
         if (!(group = avahi_entry_group_new(c, entry_group_callback, NULL))) {
             fprintf(stderr, "avahi_entry_group_new() failed: %s\n", avahi_strerror(avahi_client_errno(c)));
             goto fail;
         }
-    }
     
     fprintf(stderr, "Adding service '%s'\n", name);
-
+    
     /* Create some random TXT data */
     snprintf(r, sizeof(r), "random=%i", rand());
 
@@ -120,12 +119,15 @@ static void client_callback(AvahiClient *c, AvahiClientState state, void * userd
 
     /* Called whenever the client or server state changes */
 
-    if (state == AVAHI_CLIENT_S_RUNNING)
-        /* The serve has startup successfully and registered its host
+    if (state == AVAHI_CLIENT_S_RUNNING) {
+        
+        /* The server has startup successfully and registered its host
          * name on the network, so it's time to create our services */
-        create_services(c);
+        if (group)
+            create_services(c);
     
-    else if (state == AVAHI_CLIENT_S_COLLISION) {
+    } else if (state == AVAHI_CLIENT_S_COLLISION) {
+        
         /* Let's drop our registered services. When the server is back
          * in AVAHI_SERVER_RUNNING state we will register them
          * again with the new host name. */
@@ -160,19 +162,15 @@ int main(int argc, char*argv[]) {
         fprintf(stderr, "Failed to create client: %s\n", avahi_strerror(error));
         goto fail;
     }
-    
+
     /* Run the main loop */
-    for (;;)
-        if (avahi_simple_poll_iterate(simple_poll, -1) != 0)
-            break;
+    avahi_simple_poll_loop(simple_poll);
     
     ret = 0;
     
 fail:
     
     /* Cleanup things */
-    if (group)
-        avahi_entry_group_free(group);
 
     if (client)
         avahi_client_free(client);
index 57fafe46f3263f6b4aff3cfdefa4437ee02e8a2f..db2dcb9b19e67a3059bcb29d5324d1c7b8c8409d 100644 (file)
@@ -90,7 +90,7 @@ static void resolve_callback(
                     host_name, port, a,
                     t,
                     avahi_string_list_get_service_cookie(txt),
-                    avahi_server_is_service_local(server, interface, protocol, name, type, domain),
+                    !!(flags & AVAHI_LOOKUP_RESULT_LOCAL),
                     !!(flags & AVAHI_LOOKUP_RESULT_WIDE_AREA),
                     !!(flags & AVAHI_LOOKUP_RESULT_MULTICAST),
                     !!(flags & AVAHI_LOOKUP_RESULT_CACHED));
@@ -195,9 +195,7 @@ int main(int argc, char*argv[]) {
     }
     
     /* Run the main loop */
-    for (;;)
-        if (avahi_simple_poll_iterate(simple_poll, -1) != 0)
-            break;
+    avahi_simple_poll_loop(simple_poll);
     
     ret = 0;
     
index f826a5f4e7a43e88d6e6f0057a3c0036b6964800..0d8c04caaeb8e35ee3601c384fc27f9004fa8c4a 100644 (file)
@@ -72,12 +72,11 @@ static void create_services(AvahiServer *s) {
     assert(s);
 
     /* If this is the first time we're called, let's create a new entry group */
-    if (!group) {
+    if (!group)
         if (!(group = avahi_s_entry_group_new(s, entry_group_callback, NULL))) {
             fprintf(stderr, "avahi_entry_group_new() failed: %s\n", avahi_strerror(avahi_server_errno(s)));
             goto fail;
         }
-    }
     
     fprintf(stderr, "Adding service '%s'\n", name);
 
@@ -120,12 +119,14 @@ static void server_callback(AvahiServer *s, AvahiServerState state, void * userd
 
     /* Called whenever the server state changes */
 
-    if (state == AVAHI_SERVER_RUNNING)
+    if (state == AVAHI_SERVER_RUNNING) {
         /* The serve has startup successfully and registered its host
          * name on the network, so it's time to create our services */
-        create_services(s);
+
+        if (group)
+            create_services(s);
     
-    else if (state == AVAHI_SERVER_COLLISION) {
+    else if (state == AVAHI_SERVER_COLLISION) {
         char *n;
         int r;
         
@@ -183,19 +184,15 @@ int main(int argc, char*argv[]) {
         fprintf(stderr, "Failed to create server: %s\n", avahi_strerror(error));
         goto fail;
     }
-    
+
     /* Run the main loop */
-    for (;;)
-        if (avahi_simple_poll_iterate(simple_poll, -1) != 0)
-            break;
+    avahi_simple_poll_loop(simple_poll);
     
     ret = 0;
     
 fail:
     
     /* Cleanup things */
-    if (group)
-        avahi_s_entry_group_free(group);
 
     if (server)
         avahi_server_free(server);