]> git.meshlink.io Git - catta/blobdiff - avahi-core/browse.c
* avahi-utils: replace python avahi-browse with a version written in C.
[catta] / avahi-core / browse.c
index a133c62bdcc5603b39a2c5814115cbd0c4af0c99..dd4fe3c214e7c7b589b24dc8e30327deb5072538 100644 (file)
 #include "browse.h"
 #include "log.h"
 #include "querier.h"
+#include "domain-util.h"
+#include "rr-util.h"
 
-#define AVAHI_MAX_LOOKUPS_PER_BROWSER 15
+#define AVAHI_LOOKUPS_PER_BROWSER_MAX 15
 
 struct AvahiSRBLookup {
     AvahiSRecordBrowser *record_browser;
@@ -79,7 +81,6 @@ static void transport_flags_from_domain(AvahiServer *s, AvahiLookupFlags *flags,
         *flags |= AVAHI_LOOKUP_USE_WIDE_AREA;
 }
 
-
 static AvahiSRBLookup* lookup_new(
     AvahiSRecordBrowser *b,
     AvahiIfIndex interface,
@@ -93,7 +94,7 @@ static AvahiSRBLookup* lookup_new(
     assert(AVAHI_IF_VALID(interface));
     assert(AVAHI_PROTO_VALID(protocol));
 
-    if (b->n_lookups >= AVAHI_MAX_LOOKUPS_PER_BROWSER)
+    if (b->n_lookups >= AVAHI_LOOKUPS_PER_BROWSER_MAX)
         /* We don't like cyclic CNAMEs */
         return NULL;
     
@@ -180,6 +181,21 @@ static AvahiSRBLookup *lookup_find(
     return NULL;
 }
 
+static void browser_cancel(AvahiSRecordBrowser *b) {
+    assert(b);
+
+    if (b->root_lookup) {
+        lookup_unref(b->root_lookup);
+        b->root_lookup = NULL;
+    }
+
+    if (b->defer_time_event) {
+        avahi_time_event_free(b->defer_time_event);
+        b->defer_time_event = NULL;
+    }
+}
+
+
 static void lookup_wide_area_callback(
     AvahiWideAreaLookupEngine *e,
     AvahiBrowserEvent event,
@@ -264,8 +280,10 @@ static void lookup_multicast_callback(
                 lookup_handle_cname(l, interface, protocol, b->flags, r);
             else {
                 /* It's a normal record, so let's call the user callback */
-                assert(avahi_key_equal(b->key, l->key));
 
+                if (avahi_server_is_record_local(b->server, interface, protocol, r))
+                    flags |= AVAHI_LOOKUP_RESULT_LOCAL;
+                
                 b->callback(b, interface, protocol, event, r, flags, b->userdata);
             }
             break;
@@ -408,7 +426,7 @@ static void lookup_handle_cname(AvahiSRBLookup *l, AvahiIfIndex interface, Avahi
 
 static void lookup_drop_cname(AvahiSRBLookup *l, AvahiIfIndex interface, AvahiProtocol protocol, AvahiLookupFlags flags, AvahiRecord *r) {
     AvahiKey *k;
-    AvahiSRBLookup *n;
+    AvahiSRBLookup *n = NULL;
     AvahiRList *rl;
 
     assert(r->key->clazz == AVAHI_DNS_CLASS_IN);
@@ -436,7 +454,7 @@ static void lookup_drop_cname(AvahiSRBLookup *l, AvahiIfIndex interface, AvahiPr
     }
 }
 
-static void defer_callback(AvahiTimeEvent *e, void *userdata) {
+static void defer_callback(AVAHI_GCC_UNUSED AvahiTimeEvent *e, void *userdata) {
     AvahiSRecordBrowser *b = userdata;
     int n;
 
@@ -469,7 +487,7 @@ static void defer_callback(AvahiTimeEvent *e, void *userdata) {
             b->flags & AVAHI_LOOKUP_USE_WIDE_AREA ? AVAHI_LOOKUP_RESULT_WIDE_AREA : AVAHI_LOOKUP_RESULT_MULTICAST,
             b->userdata);
         
-        avahi_s_record_browser_cancel(b);
+        browser_cancel(b);
         return;
     }
     
@@ -493,7 +511,7 @@ void avahi_s_record_browser_restart(AvahiSRecordBrowser *b) {
     assert(b);
     assert(!b->dead);
 
-    avahi_s_record_browser_cancel(b);
+    browser_cancel(b);
 
     /* Request a new iteration of the cache scanning */
     if (!b->defer_time_event) {
@@ -550,20 +568,6 @@ AvahiSRecordBrowser *avahi_s_record_browser_new(
     return b;
 }
 
-void avahi_s_record_browser_cancel(AvahiSRecordBrowser *b) {
-    assert(b);
-
-    if (b->root_lookup) {
-        lookup_unref(b->root_lookup);
-        b->root_lookup = NULL;
-    }
-
-    if (b->defer_time_event) {
-        avahi_time_event_free(b->defer_time_event);
-        b->defer_time_event = NULL;
-    }
-}
-
 void avahi_s_record_browser_free(AvahiSRecordBrowser *b) {
     assert(b);
     assert(!b->dead);
@@ -571,13 +575,13 @@ void avahi_s_record_browser_free(AvahiSRecordBrowser *b) {
     b->dead = 1;
     b->server->need_browser_cleanup = 1;
 
-    avahi_s_record_browser_cancel(b);
+    browser_cancel(b);
 }
 
 void avahi_s_record_browser_destroy(AvahiSRecordBrowser *b) {
     assert(b);
 
-    avahi_s_record_browser_cancel(b);
+    browser_cancel(b);
     
     AVAHI_LLIST_REMOVE(AvahiSRecordBrowser, browser, b->server->record_browsers, b);