]> git.meshlink.io Git - catta/commitdiff
implement sw_discovery_browse_domains()
authorLennart Poettering <lennart@poettering.net>
Sat, 15 Oct 2005 19:16:47 +0000 (19:16 +0000)
committerLennart Poettering <lennart@poettering.net>
Sat, 15 Oct 2005 19:16:47 +0000 (19:16 +0000)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@782 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-compat-howl/Makefile.am
avahi-compat-howl/address-test.c
avahi-compat-howl/browse-domain-test.c [new file with mode: 0644]
avahi-compat-howl/compat.c
avahi-compat-howl/text-test.c

index 820270318292cc12885f659ab5e05f58064a5998..5c127828a2563bb5cbb9bc03c960483c4751ab26 100644 (file)
@@ -70,7 +70,7 @@ HOWLHEADERS = \
 
 lib_LTLIBRARIES = libavahi-compat-howl.la 
 
-noinst_PROGRAMS = address-test text-test
+noinst_PROGRAMS = address-test text-test browse-domain-test
 
 libavahi_compat_howl_la_SOURCES = \
        $(HOWLHEADERS) \
@@ -98,4 +98,10 @@ text_test_SOURCES = \
 text_test_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) -I $(srcdir)/include
 text_test_LDADD = $(AM_LDADD) ../avahi-common/libavahi-common.la
 
+browse_domain_test_SOURCES = \
+       $(HOWLHEADERS) \
+       browse-domain-test.c
+browse_domain_test_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) -I $(srcdir)/include
+browse_domain_test_LDADD = $(AM_LDADD) libavahi-compat-howl.la
+
 endif
index b9c8b13d80fdf299ecba2a9c7524c031deac5deb..73c356d02d9a384cd612716dccfd9c4787039206 100644 (file)
@@ -26,7 +26,7 @@
 #include <assert.h>
 #include <stdio.h>
 
-#include <howl.h>
+#include "howl.h"
 
 #define ASSERT_SW_OKAY(t) { sw_result r; r = (t); assert(r == SW_OKAY); }
 #define ASSERT_NOT_NULL(t) { const void* r; r = (t); assert(r); }
diff --git a/avahi-compat-howl/browse-domain-test.c b/avahi-compat-howl/browse-domain-test.c
new file mode 100644 (file)
index 0000000..2eedd48
--- /dev/null
@@ -0,0 +1,75 @@
+/* $Id$ */
+
+/***
+  This file is part of avahi.
+  avahi is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as
+  published by the Free Software Foundation; either version 2.1 of the
+  License, or (at your option) any later version.
+  avahi is distributed in the hope that it will be useful, but WITHOUT
+  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+  Public License for more details.
+  You should have received a copy of the GNU Lesser General Public
+  License along with avahi; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+#include <stdio.h>
+
+#include "howl.h"
+
+#define ASSERT_SW_OKAY(t) { sw_result _r; _r = (t); assert(_r == SW_OKAY); }
+#define ASSERT_NOT_NULL(t) { const void* _r; r = (t); assert(_r); }
+
+static sw_result reply(
+    sw_discovery discovery,
+    sw_discovery_oid oid,
+    sw_discovery_browse_status status,
+    sw_uint32 interface_index,
+    sw_const_string name,
+    sw_const_string type,
+    sw_const_string domain,
+    sw_opaque extra) {
+
+    switch (status) {
+        case SW_DISCOVERY_BROWSE_ADD_DOMAIN:
+            fprintf(stderr, "new domain %s\n", domain);
+            break;
+
+        case SW_DISCOVERY_BROWSE_REMOVE_DOMAIN:
+            fprintf(stderr, "removed domain %s\n", domain);
+            break;
+
+        case SW_DISCOVERY_BROWSE_INVALID:
+            fprintf(stderr, "some kind of failure happened: %s\n", domain);
+            break;
+            
+        default:
+            abort();
+    }
+
+    return SW_OKAY;
+}
+
+int main(int argc, char *argv[]) {
+    sw_discovery discovery;
+    sw_discovery_oid oid;
+    
+    ASSERT_SW_OKAY(sw_discovery_init(&discovery));
+
+    ASSERT_SW_OKAY(sw_discovery_browse_domains(discovery, 0, reply, NULL, &oid));
+    
+    ASSERT_SW_OKAY(sw_discovery_run(discovery));
+                   
+    return 0;
+}
index f5415bf103b4dc579d8bbf2bf94c6b0c0ada1a15..d72b8828ab541242395ec3e9babccdfd076e4436 100644 (file)
@@ -524,14 +524,90 @@ sw_result sw_discovery_publish(
     return SW_E_NO_IMPL;
 }
 
+static void domain_browser_callback(
+    AvahiDomainBrowser *b,
+    AvahiIfIndex interface,
+    AvahiProtocol protocol,
+    AvahiBrowserEvent event,
+    const char *domain,
+    AvahiLookupResultFlags flags,
+    void *userdata) {
+
+    oid_data* data = userdata;
+    sw_discovery_browse_reply reply;
+    static char domain_fixed[AVAHI_DOMAIN_NAME_MAX];
+
+    assert(b);
+    assert(data);
+
+    reply = (sw_discovery_browse_reply) data->reply;
+
+    domain  = add_trailing_dot(domain, domain_fixed, sizeof(domain_fixed));
+
+    switch (event) {
+        case AVAHI_BROWSER_NEW:
+            reply(data->discovery, OID_GET_INDEX(data), SW_DISCOVERY_BROWSE_ADD_DOMAIN, interface, NULL, NULL, domain, data->extra);
+            break;
+
+        case AVAHI_BROWSER_REMOVE:
+            reply(data->discovery, OID_GET_INDEX(data), SW_DISCOVERY_BROWSE_REMOVE_DOMAIN, interface, NULL, NULL, domain, data->extra);
+            break;
+
+        case AVAHI_BROWSER_FAILURE:
+            reply(data->discovery, OID_GET_INDEX(data), SW_DISCOVERY_BROWSE_INVALID, interface, NULL, NULL, domain, data->extra);
+            break;
+            
+        case AVAHI_BROWSER_CACHE_EXHAUSTED:
+        case AVAHI_BROWSER_ALL_FOR_NOW:
+            break;
+    }
+}
+
 sw_result sw_discovery_browse_domains(
     sw_discovery self,
     sw_uint32 interface_index,
     sw_discovery_browse_reply reply,
     sw_opaque extra,
     sw_discovery_oid * oid) {
-    AVAHI_WARN_UNSUPPORTED;
-    return SW_E_NO_IMPL;
+    
+    oid_data *data;
+    AvahiIfIndex ifindex;
+    sw_result result = SW_E_UNKNOWN;
+    
+    assert(self);
+    assert(reply);
+    assert(oid);
+    
+    AVAHI_WARN_LINKAGE;
+
+    if ((*oid = oid_alloc(self, OID_DOMAIN_BROWSER)) == (sw_discovery_oid) -1)
+        return SW_E_UNKNOWN;
+
+    data = oid_get(self, *oid);
+    assert(data);
+    data->reply = (sw_result (*)(void)) reply;
+    data->extra = extra;
+    
+    ifindex = interface_index == 0 ? AVAHI_IF_UNSPEC : (AvahiIfIndex) interface_index;
+
+    ASSERT_SUCCESS(pthread_mutex_lock(&self->mutex));
+    
+    if (!(data->object = avahi_domain_browser_new(self->client, ifindex, AVAHI_PROTO_INET, NULL, AVAHI_DOMAIN_BROWSER_BROWSE, 0, domain_browser_callback, data))) {
+        result = map_error(avahi_client_errno(self->client));
+        goto finish;
+    }
+
+    result = SW_OKAY;
+
+finish:
+
+    ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
+    
+    if (result != SW_OKAY)
+        if (*oid != (sw_discovery_oid) -1)
+            oid_release(self, *oid);
+
+    return result;
 }
 
 static void service_resolver_callback(
@@ -753,6 +829,14 @@ sw_result sw_discovery_cancel(sw_discovery self, sw_discovery_oid oid) {
             avahi_service_resolver_free(data->object);
             break;
 
+        case OID_DOMAIN_BROWSER:
+            avahi_domain_browser_free(data->object);
+            break;
+
+        case OID_ENTRY_GROUP:
+            avahi_entry_group_free(data->object);
+            break;
+            
         case OID_UNUSED:
             ;
     }
index a32e1139b298133dba0a3d569ce3b621bd47ea66..995a7f54be42ca1715b3b816ef0bcad2ba2358e9 100644 (file)
@@ -26,7 +26,7 @@
 #include <assert.h>
 #include <stdio.h>
 
-#include <howl.h>
+#include "howl.h"
 
 #define ASSERT_SW_OKAY(t) { sw_result _r; _r = (t); assert(_r == SW_OKAY); }
 #define ASSERT_NOT_NULL(t) { const void* _r; r = (t); assert(_r); }