]> git.meshlink.io Git - catta/blobdiff - avahi-compat-libdns_sd/compat.c
add new utility "avahi-set-host-name" for changing the mDNS host name during runtime
[catta] / avahi-compat-libdns_sd / compat.c
index 6fec3c96b40ee8bcfbc406bf478426f5af5d83cc..e5692bbe7f66db406e3765791398547b7dded42d 100644 (file)
@@ -145,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;
 
@@ -374,8 +374,8 @@ static void sdref_unref(DNSServiceRef sdref) {
 }
 
 int DNSSD_API DNSServiceRefSockFD(DNSServiceRef sdref) {
-    assert(sdref);
-    assert(sdref->n_ref >= 1);
+    if (!sdref || sdref->n_ref <= 0)
+        return -1;
 
     AVAHI_WARN_LINKAGE;
     
@@ -481,7 +481,6 @@ static void generic_client_callback(AvahiClient *s, AvahiClientState state, void
     switch (state) {
 
         case AVAHI_CLIENT_FAILURE:
-        case AVAHI_CLIENT_DISCONNECTED:
 
             if (sdref->service_browser_callback)
                 sdref->service_browser_callback(sdref, 0, 0, error, NULL, NULL, NULL, sdref->context);
@@ -495,6 +494,7 @@ static void generic_client_callback(AvahiClient *s, AvahiClientState state, void
         case AVAHI_CLIENT_S_RUNNING:
         case AVAHI_CLIENT_S_COLLISION:
         case AVAHI_CLIENT_S_REGISTERING:
+        case AVAHI_CLIENT_CONNECTING:
             break;
     }
 }
@@ -517,7 +517,6 @@ DNSServiceErrorType DNSSD_API DNSServiceBrowse(
     
     assert(ret_sdref);
     assert(regtype);
-    assert(domain);
     assert(callback);
 
     if (interface == kDNSServiceInterfaceIndexLocalOnly || flags != 0) {
@@ -533,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;
     }
@@ -646,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;
     }
@@ -758,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;
     }
@@ -791,7 +790,8 @@ static void reg_report_error(DNSServiceRef sdref, DNSServiceErrorType error) {
     assert(sdref);
     assert(sdref->n_ref >= 1);
 
-    assert(sdref->service_register_callback);
+    if (!sdref->service_register_callback)
+        return;
 
     regtype = add_trailing_dot(sdref->service_regtype, regtype_fixed, sizeof(regtype_fixed));
     domain = add_trailing_dot(sdref->service_domain, domain_fixed, sizeof(domain_fixed));
@@ -862,7 +862,6 @@ static void reg_client_callback(AvahiClient *s, AvahiClientState state, void* us
     
     switch (state) {
         case AVAHI_CLIENT_FAILURE:
-        case AVAHI_CLIENT_DISCONNECTED:
             reg_report_error(sdref, kDNSServiceErr_Unknown);
             break;
 
@@ -898,13 +897,14 @@ static void reg_client_callback(AvahiClient *s, AvahiClientState state, void* us
         }
             
         case AVAHI_CLIENT_S_COLLISION:
+        case AVAHI_CLIENT_S_REGISTERING:
 
             /* Remove our entry */
             avahi_entry_group_reset(sdref->entry_group);
             
             break;
 
-        case AVAHI_CLIENT_S_REGISTERING:
+        case AVAHI_CLIENT_CONNECTING:
             /* Ignore */
             break;
     }
@@ -984,7 +984,6 @@ DNSServiceErrorType DNSSD_API DNSServiceRegister (
     AVAHI_WARN_LINKAGE;
 
     assert(ret_sdref);
-    assert(callback);
     assert(regtype);
 
     if (interface == kDNSServiceInterfaceIndexLocalOnly || flags) {
@@ -1016,7 +1015,7 @@ DNSServiceErrorType DNSSD_API DNSServiceRegister (
     
     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;
     }