]> git.meshlink.io Git - catta/commitdiff
* Implement DNSServiceEnumerateDomains()
authorLennart Poettering <lennart@poettering.net>
Mon, 3 Oct 2005 23:38:00 +0000 (23:38 +0000)
committerLennart Poettering <lennart@poettering.net>
Mon, 3 Oct 2005 23:38:00 +0000 (23:38 +0000)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@692 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

compat-bonjour/compat.c
compat-bonjour/funcs.txt
compat-bonjour/unsupported.c

index 09388423d43ed25fc77dbbcd5bfa187b86f74168..f87a3bf401d375b61a5a5e2587e9e8c1705c44a8 100644 (file)
@@ -60,10 +60,12 @@ struct _DNSServiceRef_t {
     void *context;
     DNSServiceBrowseReply service_browser_callback;
     DNSServiceResolveReply service_resolver_callback;
+    DNSServiceDomainEnumReply domain_browser_callback;
 
     AvahiClient *client;
     AvahiServiceBrowser *service_browser;
     AvahiServiceResolver *service_resolver;
+    AvahiDomainBrowser *domain_browser;
 };
 
 #define ASSERT_SUCCESS(r) { int __ret = (r); assert(__ret == 0); }
@@ -176,6 +178,7 @@ static DNSServiceRef sdref_new(void) {
     sdref->client = NULL;
     sdref->service_browser = NULL;
     sdref->service_resolver = NULL;
+    sdref->domain_browser = NULL;
 
     ASSERT_SUCCESS(pthread_mutexattr_init(&mutex_attr));
     pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
@@ -567,3 +570,96 @@ int DNSSD_API DNSServiceConstructFullName (
     return 0;
 }
 
+static void domain_browser_callback(
+    AvahiDomainBrowser *b,
+    AvahiIfIndex interface,
+    AvahiProtocol protocol,
+    AvahiBrowserEvent event,
+    const char *domain,
+    AvahiLookupResultFlags flags,
+    void *userdata) {
+
+    DNSServiceRef sdref = userdata;
+
+    assert(b);
+    assert(sdref);
+
+    switch (event) {
+        case AVAHI_BROWSER_NEW:
+            sdref->domain_browser_callback(sdref, kDNSServiceFlagsAdd, interface, kDNSServiceErr_NoError, domain, sdref->context);
+            break;
+
+        case AVAHI_BROWSER_REMOVE:
+            sdref->domain_browser_callback(sdref, 0, interface, kDNSServiceErr_NoError, domain, sdref->context);
+            break;
+
+        case AVAHI_BROWSER_FAILURE:
+            sdref->domain_browser_callback(sdref, 0, interface, kDNSServiceErr_Unknown, domain, sdref->context);
+            break;
+            
+        case AVAHI_BROWSER_NOT_FOUND:
+            sdref->domain_browser_callback(sdref, 0, interface, kDNSServiceErr_NoSuchName, domain, sdref->context);
+            break;
+            
+        case AVAHI_BROWSER_CACHE_EXHAUSTED:
+        case AVAHI_BROWSER_ALL_FOR_NOW:
+            break;
+    }
+}
+
+DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains(
+    DNSServiceRef *ret_sdref,
+    DNSServiceFlags flags,
+    uint32_t interface,
+    DNSServiceDomainEnumReply callback,
+    void *context) {
+
+    DNSServiceErrorType ret = kDNSServiceErr_Unknown;
+    int error;
+    DNSServiceRef sdref = NULL;
+    AvahiIfIndex ifindex;
+
+    AVAHI_WARN_LINKAGE;
+
+    assert(ret_sdref);
+    assert(callback);
+
+    if (interface == kDNSServiceInterfaceIndexLocalOnly ||
+        (flags != kDNSServiceFlagsBrowseDomains &&  flags != kDNSServiceFlagsRegistrationDomains))
+        return kDNSServiceErr_Unsupported;
+
+    if (!(sdref = sdref_new()))
+        return kDNSServiceErr_Unknown;
+
+    sdref->context = context;
+    sdref->domain_browser_callback = callback;
+
+    ASSERT_SUCCESS(pthread_mutex_lock(&sdref->mutex));
+    
+    if (!(sdref->client = avahi_client_new(avahi_simple_poll_get(sdref->simple_poll), NULL, NULL, &error))) {
+        ret =  map_error(error);
+        goto finish;
+    }
+
+    ifindex = interface == kDNSServiceInterfaceIndexAny ? AVAHI_IF_UNSPEC : (AvahiIfIndex) interface;
+    
+    if (!(sdref->domain_browser = avahi_domain_browser_new(sdref->client, ifindex, AVAHI_PROTO_UNSPEC, NULL,
+                                                           flags == kDNSServiceFlagsRegistrationDomains ? AVAHI_DOMAIN_BROWSER_REGISTER : AVAHI_DOMAIN_BROWSER_BROWSE,
+                                                           0, domain_browser_callback, sdref))) {
+        ret = map_error(avahi_client_errno(sdref->client));
+        goto finish;
+    }
+    
+    ret = kDNSServiceErr_NoError;
+    *ret_sdref = sdref;
+                                                              
+finish:
+
+    ASSERT_SUCCESS(pthread_mutex_unlock(&sdref->mutex));
+    
+    if (ret != kDNSServiceErr_NoError)
+        DNSServiceRefDeallocate(sdref);
+
+    return ret;
+}
+
index 85aa9e6fff5823ca61712497071afec33f70516b..de8bba44ef8804c833ac32067ff326a2f6fe8438 100644 (file)
@@ -5,7 +5,7 @@ Supported:
 x DNSServiceRefSockFD
 x DNSServiceProcessResult
 x DNSServiceRefDeallocate
-DNSServiceEnumerateDomains
+DNSServiceEnumerateDomains
 DNSServiceRegister
 x DNSServiceBrowse
 x DNSServiceResolve
index 2afbae299549b46825fcf41bad34cb12c5f3a0e2..f74691d42cd31dcda19c385e2f9048860151509d 100644 (file)
 #include "dns_sd.h"
 #include "warn.h"
 
-DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains(
-    DNSServiceRef *sdRef,
-    DNSServiceFlags flags,
-    uint32_t interfaceIndex,
-    DNSServiceDomainEnumReply callBack,
-    void *context) {
-
-    AVAHI_WARN_UNSUPPORTED;
-    
-    return kDNSServiceErr_Unsupported;
-}
-
 DNSServiceErrorType DNSSD_API DNSServiceRegister (
     DNSServiceRef *sdRef,
     DNSServiceFlags flags,