From: Lennart Poettering Date: Mon, 3 Oct 2005 23:38:00 +0000 (+0000) Subject: * Implement DNSServiceEnumerateDomains() X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=fdb43688d8357982ab3bb9c4b2176f762727a810;p=catta * Implement DNSServiceEnumerateDomains() git-svn-id: file:///home/lennart/svn/public/avahi/trunk@692 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- diff --git a/compat-bonjour/compat.c b/compat-bonjour/compat.c index 0938842..f87a3bf 100644 --- a/compat-bonjour/compat.c +++ b/compat-bonjour/compat.c @@ -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; +} + diff --git a/compat-bonjour/funcs.txt b/compat-bonjour/funcs.txt index 85aa9e6..de8bba4 100644 --- a/compat-bonjour/funcs.txt +++ b/compat-bonjour/funcs.txt @@ -5,7 +5,7 @@ Supported: x DNSServiceRefSockFD x DNSServiceProcessResult x DNSServiceRefDeallocate -DNSServiceEnumerateDomains +x DNSServiceEnumerateDomains DNSServiceRegister x DNSServiceBrowse x DNSServiceResolve diff --git a/compat-bonjour/unsupported.c b/compat-bonjour/unsupported.c index 2afbae2..f74691d 100644 --- a/compat-bonjour/unsupported.c +++ b/compat-bonjour/unsupported.c @@ -26,18 +26,6 @@ #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,