]> git.meshlink.io Git - catta/blobdiff - avahi-core/browse-domain.c
forgot to pull the publish_no_reverse change to the example.
[catta] / avahi-core / browse-domain.c
index 4c78832def09ccca253067c25537b02b84b74571..9705b2a52a620ecf9088f08b42511ad9fe7ef25b 100644 (file)
@@ -1,18 +1,16 @@
-/* $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
@@ -23,6 +21,8 @@
 #include <config.h>
 #endif
 
+#include <stdlib.h>
+
 #include <avahi-common/domain.h>
 #include <avahi-common/malloc.h>
 #include <avahi-common/error.h>
@@ -32,9 +32,9 @@
 
 struct AvahiSDomainBrowser {
     int ref;
-    
+
     AvahiServer *server;
-    
+
     AvahiSRecordBrowser *record_browser;
 
     AvahiDomainBrowserType type;
@@ -44,7 +44,7 @@ struct AvahiSDomainBrowser {
     AvahiTimeEvent *defer_event;
 
     int all_for_now_scheduled;
-    
+
     AVAHI_LLIST_FIELDS(AvahiSDomainBrowser, browser);
 };
 
@@ -63,7 +63,7 @@ static void record_browser_callback(
     AvahiRecord *record,
     AvahiLookupResultFlags flags,
     void* userdata) {
-    
+
     AvahiSDomainBrowser *b = userdata;
     char *n = NULL;
 
@@ -76,7 +76,7 @@ static void record_browser_callback(
         b->all_for_now_scheduled = 1;
         return;
     }
-    
+
     /* Filter flags */
     flags &= AVAHI_LOOKUP_RESULT_CACHED | AVAHI_LOOKUP_RESULT_MULTICAST | AVAHI_LOOKUP_RESULT_WIDE_AREA;
 
@@ -88,24 +88,26 @@ static void record_browser_callback(
             AvahiStringList *l;
 
             /* Filter out entries defined statically */
-            
+
             for (l = b->server->config.browse_domains; l; l = l->next)
                 if (avahi_domain_equal((char*) l->text, n))
                     return;
         }
-        
+
     }
-        
+
     b->callback(b, interface, protocol, event, n, flags, b->userdata);
 }
 
 static void defer_callback(AvahiTimeEvent *e, void *userdata) {
     AvahiSDomainBrowser *b = userdata;
     AvahiStringList *l;
-    
+
     assert(e);
     assert(b);
 
+    assert(b->type == AVAHI_DOMAIN_BROWSER_BROWSE);
+
     avahi_time_event_free(b->defer_event);
     b->defer_event = NULL;
 
@@ -124,11 +126,11 @@ static void defer_callback(AvahiTimeEvent *e, void *userdata) {
 
     if (b->ref > 1) {
         /* If the ALL_FOR_NOW event has already been scheduled, execute it now */
-        
-        if (b->all_for_now_scheduled) 
+
+        if (b->all_for_now_scheduled)
             b->callback(b, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AVAHI_BROWSER_ALL_FOR_NOW, NULL, 0, b->userdata);
     }
-    
+
     /* Decrease ref counter */
     avahi_s_domain_browser_free(b);
 }
@@ -150,12 +152,12 @@ AvahiSDomainBrowser *avahi_s_domain_browser_new(
         "dr",
         "lb"
     };
-    
+
     AvahiSDomainBrowser *b;
     AvahiKey *k = NULL;
     char n[AVAHI_DOMAIN_NAME_MAX];
     int r;
-    
+
     assert(server);
     assert(callback);
 
@@ -172,7 +174,7 @@ AvahiSDomainBrowser *avahi_s_domain_browser_new(
         avahi_server_set_errno(server, r);
         return NULL;
     }
-    
+
     if (!(b = avahi_new(AvahiSDomainBrowser, 1))) {
         avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
         return NULL;
@@ -185,6 +187,7 @@ AvahiSDomainBrowser *avahi_s_domain_browser_new(
     b->record_browser = NULL;
     b->type = type;
     b->all_for_now_scheduled = 0;
+    b->defer_event = NULL;
 
     AVAHI_LLIST_PREPEND(AvahiSDomainBrowser, browser, server->domain_browsers, b);
 
@@ -192,23 +195,24 @@ AvahiSDomainBrowser *avahi_s_domain_browser_new(
         avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
         goto fail;
     }
-    
+
     if (!(b->record_browser = avahi_s_record_browser_new(server, interface, protocol, k, flags, record_browser_callback, b)))
         goto fail;
-    
+
     avahi_key_unref(k);
 
-    b->defer_event = avahi_time_event_new(server->time_event_queue, NULL, defer_callback, b);
-    
+    if (type == AVAHI_DOMAIN_BROWSER_BROWSE && b->server->config.browse_domains)
+        b->defer_event = avahi_time_event_new(server->time_event_queue, NULL, defer_callback, b);
+
     return b;
-    
+
 fail:
-    
+
     if (k)
         avahi_key_unref(k);
-    
+
     avahi_s_domain_browser_free(b);
-    
+
     return NULL;
 }
 
@@ -218,7 +222,7 @@ void avahi_s_domain_browser_free(AvahiSDomainBrowser *b) {
     assert(b->ref >= 1);
     if (--b->ref > 0)
         return;
-    
+
     AVAHI_LLIST_REMOVE(AvahiSDomainBrowser, browser, b->server->domain_browsers, b);
 
     if (b->record_browser)
@@ -226,6 +230,6 @@ void avahi_s_domain_browser_free(AvahiSDomainBrowser *b) {
 
     if (b->defer_event)
         avahi_time_event_free(b->defer_event);
-    
+
     avahi_free(b);
 }