]> git.meshlink.io Git - catta/blobdiff - avahi-compat-libdns_sd/compat.c
* Adding the missing files for Mandriva init.d
[catta] / avahi-compat-libdns_sd / compat.c
index a06ca6826c627da13d9fdba991366e97076aee7d..052c8b2b8444858b6f7cea451819c095e63f524e 100644 (file)
@@ -33,6 +33,9 @@
 #include <netinet/in.h>
 #include <fcntl.h>
 
+#include <sys/types.h>
+#include <sys/socket.h>
+
 #include <avahi-common/simple-watch.h>
 #include <avahi-common/malloc.h>
 #include <avahi-common/error.h>
@@ -142,7 +145,7 @@ static DNSServiceErrorType map_error(int error) {
         case AVAHI_ERR_INVALID_CONFIG:
         case AVAHI_ERR_TIMEOUT:
         case AVAHI_ERR_DBUS_ERROR:
-        case AVAHI_ERR_NOT_CONNECTED:
+        case AVAHI_ERR_DISCONNECTED:
         case AVAHI_ERR_NO_DAEMON:
             break;
 
@@ -431,12 +434,12 @@ void DNSSD_API DNSServiceRefDeallocate(DNSServiceRef sdref) {
 static void service_browser_callback(
     AvahiServiceBrowser *b,
     AvahiIfIndex interface,
-    AvahiProtocol protocol,
+    AVAHI_GCC_UNUSED AvahiProtocol protocol,
     AvahiBrowserEvent event,
     const char *name,
     const char *type,
     const char *domain,
-    AvahiLookupResultFlags flags,
+    AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
     void *userdata) {
 
     DNSServiceRef sdref = userdata;
@@ -476,13 +479,8 @@ static void generic_client_callback(AvahiClient *s, AvahiClientState state, void
     assert(sdref->n_ref >= 1);
 
     switch (state) {
-        case AVAHI_CLIENT_S_FAILURE:
-
-            error = map_error(avahi_client_errno(s));
 
-            /* Fall through */
-            
-        case AVAHI_CLIENT_DISCONNECTED:
+        case AVAHI_CLIENT_FAILURE:
 
             if (sdref->service_browser_callback)
                 sdref->service_browser_callback(sdref, 0, 0, error, NULL, NULL, NULL, sdref->context);
@@ -495,8 +493,8 @@ static void generic_client_callback(AvahiClient *s, AvahiClientState state, void
 
         case AVAHI_CLIENT_S_RUNNING:
         case AVAHI_CLIENT_S_COLLISION:
-        case AVAHI_CLIENT_S_INVALID:
         case AVAHI_CLIENT_S_REGISTERING:
+        case AVAHI_CLIENT_CONNECTING:
             break;
     }
 }
@@ -519,7 +517,6 @@ DNSServiceErrorType DNSSD_API DNSServiceBrowse(
     
     assert(ret_sdref);
     assert(regtype);
-    assert(domain);
     assert(callback);
 
     if (interface == kDNSServiceInterfaceIndexLocalOnly || flags != 0) {
@@ -535,7 +532,7 @@ DNSServiceErrorType DNSSD_API DNSServiceBrowse(
 
     ASSERT_SUCCESS(pthread_mutex_lock(&sdref->mutex));
     
-    if (!(sdref->client = avahi_client_new(avahi_simple_poll_get(sdref->simple_poll), generic_client_callback, sdref, &error))) {
+    if (!(sdref->client = avahi_client_new(avahi_simple_poll_get(sdref->simple_poll), 0, generic_client_callback, sdref, &error))) {
         ret =  map_error(error);
         goto finish;
     }
@@ -563,16 +560,16 @@ finish:
 static void service_resolver_callback(
     AvahiServiceResolver *r,
     AvahiIfIndex interface,
-    AvahiProtocol protocol,
+    AVAHI_GCC_UNUSED AvahiProtocol protocol,
     AvahiResolverEvent event,
     const char *name,
     const char *type,
     const char *domain,
     const char *host_name,
-    const AvahiAddress *a,
+    AVAHI_GCC_UNUSED const AvahiAddress *a,
     uint16_t port,
     AvahiStringList *txt,
-    AvahiLookupResultFlags flags,
+    AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
     void *userdata) {
 
     DNSServiceRef sdref = userdata;
@@ -648,7 +645,7 @@ DNSServiceErrorType DNSSD_API DNSServiceResolve(
 
     ASSERT_SUCCESS(pthread_mutex_lock(&sdref->mutex));
     
-    if (!(sdref->client = avahi_client_new(avahi_simple_poll_get(sdref->simple_poll), generic_client_callback, sdref, &error))) {
+    if (!(sdref->client = avahi_client_new(avahi_simple_poll_get(sdref->simple_poll), 0, generic_client_callback, sdref, &error))) {
         ret =  map_error(error);
         goto finish;
     }
@@ -695,10 +692,10 @@ int DNSSD_API DNSServiceConstructFullName (
 static void domain_browser_callback(
     AvahiDomainBrowser *b,
     AvahiIfIndex interface,
-    AvahiProtocol protocol,
+    AVAHI_GCC_UNUSED AvahiProtocol protocol,
     AvahiBrowserEvent event,
     const char *domain,
-    AvahiLookupResultFlags flags,
+    AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
     void *userdata) {
 
     DNSServiceRef sdref = userdata;
@@ -760,7 +757,7 @@ DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains(
 
     ASSERT_SUCCESS(pthread_mutex_lock(&sdref->mutex));
     
-    if (!(sdref->client = avahi_client_new(avahi_simple_poll_get(sdref->simple_poll), generic_client_callback, sdref, &error))) {
+    if (!(sdref->client = avahi_client_new(avahi_simple_poll_get(sdref->simple_poll), 0, generic_client_callback, sdref, &error))) {
         ret =  map_error(error);
         goto finish;
     }
@@ -863,14 +860,10 @@ static void reg_client_callback(AvahiClient *s, AvahiClientState state, void* us
         return;
     
     switch (state) {
-        case AVAHI_CLIENT_DISCONNECTED:
+        case AVAHI_CLIENT_FAILURE:
             reg_report_error(sdref, kDNSServiceErr_Unknown);
             break;
 
-        case AVAHI_CLIENT_S_FAILURE:
-            reg_report_error(sdref, map_error(avahi_client_errno(s)));
-            break;
-        
         case AVAHI_CLIENT_S_RUNNING: {
             int ret;
 
@@ -909,7 +902,7 @@ static void reg_client_callback(AvahiClient *s, AvahiClientState state, void* us
             
             break;
 
-        case AVAHI_CLIENT_S_INVALID:
+        case AVAHI_CLIENT_CONNECTING:
         case AVAHI_CLIENT_S_REGISTERING:
             /* Ignore */
             break;
@@ -985,6 +978,7 @@ DNSServiceErrorType DNSSD_API DNSServiceRegister (
     DNSServiceErrorType ret = kDNSServiceErr_Unknown;
     int error;
     DNSServiceRef sdref = NULL;
+    AvahiStringList *txt = NULL;
 
     AVAHI_WARN_LINKAGE;
 
@@ -997,8 +991,14 @@ DNSServiceErrorType DNSSD_API DNSServiceRegister (
         return kDNSServiceErr_Unsupported;
     }
 
-    if (!(sdref = sdref_new()))
+    if (txtRecord && txtLen > 0) 
+        if (avahi_string_list_parse(txtRecord, txtLen, &txt) < 0)
+            return kDNSServiceErr_Invalid;
+    
+    if (!(sdref = sdref_new())) {
+        avahi_string_list_free(txt);
         return kDNSServiceErr_Unknown;
+    }
 
     sdref->context = context;
     sdref->service_register_callback = callback;
@@ -1009,13 +1009,13 @@ DNSServiceErrorType DNSSD_API DNSServiceRegister (
     sdref->service_host = host ? avahi_normalize_name_strdup(host) : NULL;
     sdref->service_interface = interface == kDNSServiceInterfaceIndexAny ? AVAHI_IF_UNSPEC : (AvahiIfIndex) interface;
     sdref->service_port = ntohs(port);
-    sdref->service_txt = txtRecord && txtLen > 0 ? avahi_string_list_parse(txtRecord, txtLen) : NULL;
+    sdref->service_txt = txt;
 
     /* Some OOM checking would be cool here */
     
     ASSERT_SUCCESS(pthread_mutex_lock(&sdref->mutex));
     
-    if (!(sdref->client = avahi_client_new(avahi_simple_poll_get(sdref->simple_poll), reg_client_callback, sdref, &error))) {
+    if (!(sdref->client = avahi_client_new(avahi_simple_poll_get(sdref->simple_poll), 0, reg_client_callback, sdref, &error))) {
         ret =  map_error(error);
         goto finish;
     }