]> git.meshlink.io Git - catta/blobdiff - avahi-core/multicast-lookup.c
forgot to pull the publish_no_reverse change to the example.
[catta] / avahi-core / multicast-lookup.c
index 4ba48b4e752525b928c106277c23030921244c91..75988bfcd5434c154429f6664f828f7bbcd667f4 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
 #include <config.h>
 #endif
 
+#include <stdlib.h>
+
 #include <avahi-common/malloc.h>
+#include <avahi-common/timeval.h>
 
-#include "server.h"
+#include "internal.h"
 #include "browse.h"
 #include "socket.h"
 #include "log.h"
 #include "hashmap.h"
 #include "multicast-lookup.h"
+#include "rr-util.h"
 
 struct AvahiMulticastLookup {
     AvahiMulticastLookupEngine *engine;
     int dead;
 
     AvahiKey *key, *cname_key;
-    
+
     AvahiMulticastLookupCallback callback;
     void *userdata;
 
     AvahiIfIndex interface;
     AvahiProtocol protocol;
-    
+
     int queriers_added;
 
     AvahiTimeEvent *all_for_now_event;
-    
+
     AVAHI_LLIST_FIELDS(AvahiMulticastLookup, lookups);
     AVAHI_LLIST_FIELDS(AvahiMulticastLookup, by_key);
 };
@@ -81,10 +83,10 @@ AvahiMulticastLookup *avahi_multicast_lookup_new(
     AvahiKey *key,
     AvahiMulticastLookupCallback callback,
     void *userdata) {
-    
+
     AvahiMulticastLookup *l, *t;
     struct timeval tv;
-        
+
     assert(e);
     assert(AVAHI_IF_VALID(interface));
     assert(AVAHI_PROTO_VALID(protocol));
@@ -112,11 +114,12 @@ AvahiMulticastLookup *avahi_multicast_lookup_new(
     avahi_querier_add_for_all(e->server, interface, protocol, l->key, &tv);
     l->queriers_added = 1;
 
-    /* add a second */
+    /* Add a second */
     avahi_timeval_add(&tv, 1000000);
 
+    /* Issue the ALL_FOR_NOW event one second after the querier was initially created */
     l->all_for_now_event = avahi_time_event_new(e->server->time_event_queue, &tv, all_for_now_callback, l);
-    
+
     return l;
 }
 
@@ -141,7 +144,7 @@ static void lookup_destroy(AvahiMulticastLookup *l) {
     assert(l);
 
     lookup_stop(l);
-    
+
     t = avahi_hashmap_lookup(l->engine->lookups_by_key, l->key);
     AVAHI_LLIST_REMOVE(AvahiMulticastLookup, by_key, t, l);
     if (t)
@@ -156,7 +159,7 @@ static void lookup_destroy(AvahiMulticastLookup *l) {
 
     if (l->cname_key)
         avahi_key_unref(l->cname_key);
-    
+
     avahi_free(l);
 }
 
@@ -174,13 +177,13 @@ void avahi_multicast_lookup_free(AvahiMulticastLookup *l) {
 void avahi_multicast_lookup_engine_cleanup(AvahiMulticastLookupEngine *e) {
     AvahiMulticastLookup *l, *n;
     assert(e);
-    
+
     while (e->cleanup_dead) {
         e->cleanup_dead = 0;
-        
+
         for (l = e->lookups; l; l = n) {
             n = l->lookups_next;
-            
+
             if (l->dead)
                 lookup_destroy(l);
         }
@@ -214,7 +217,7 @@ static void* scan_cache_callback(AvahiCache *c, AvahiKey *pattern, AvahiCacheEnt
         cbdata->userdata);
 
     cbdata->n_found ++;
-    
+
     return NULL;
 }
 
@@ -226,12 +229,12 @@ static void scan_interface_callback(AvahiInterfaceMonitor *m, AvahiInterface *i,
     assert(cbdata);
 
     cbdata->interface = i;
-    
+
     avahi_cache_walk(i->cache, cbdata->key, scan_cache_callback, cbdata);
 
     if (cbdata->cname_key)
         avahi_cache_walk(i->cache, cbdata->cname_key, scan_cache_callback, cbdata);
-    
+
     cbdata->interface = NULL;
 }
 
@@ -242,9 +245,9 @@ unsigned avahi_multicast_lookup_engine_scan_cache(
     AvahiKey *key,
     AvahiMulticastLookupCallback callback,
     void *userdata) {
-    
+
     struct cbdata cbdata;
-    
+
     assert(e);
     assert(key);
     assert(callback);
@@ -259,9 +262,9 @@ unsigned avahi_multicast_lookup_engine_scan_cache(
     cbdata.userdata = userdata;
     cbdata.interface = NULL;
     cbdata.n_found = 0;
-    
+
     avahi_interface_monitor_walk(e->server->monitor, interface, protocol, scan_interface_callback, &cbdata);
-    
+
     if (cbdata.cname_key)
         avahi_key_unref(cbdata.cname_key);
 
@@ -270,12 +273,12 @@ unsigned avahi_multicast_lookup_engine_scan_cache(
 
 void avahi_multicast_lookup_engine_new_interface(AvahiMulticastLookupEngine *e, AvahiInterface *i) {
     AvahiMulticastLookup *l;
-    
+
     assert(e);
     assert(i);
 
     for (l = e->lookups; l; l = l->lookups_next) {
-        
+
         if (l->dead || !l->callback)
             continue;
 
@@ -286,7 +289,7 @@ void avahi_multicast_lookup_engine_new_interface(AvahiMulticastLookupEngine *e,
 
 void avahi_multicast_lookup_engine_notify(AvahiMulticastLookupEngine *e, AvahiInterface *i, AvahiRecord *record, AvahiBrowserEvent event) {
     AvahiMulticastLookup *l;
-    
+
     assert(e);
     assert(record);
     assert(i);
@@ -308,7 +311,7 @@ void avahi_multicast_lookup_engine_notify(AvahiMulticastLookupEngine *e, AvahiIn
 
             if (l->dead || !l->callback)
                 continue;
-            
+
             if ((key = avahi_key_new_cname(l->key))) {
                 if (avahi_key_equal(record->key, key))
                     l->callback(e, i->hardware->index, i->protocol, event, AVAHI_LOOKUP_RESULT_MULTICAST, record, l->userdata);
@@ -321,9 +324,9 @@ void avahi_multicast_lookup_engine_notify(AvahiMulticastLookupEngine *e, AvahiIn
 
 AvahiMulticastLookupEngine *avahi_multicast_lookup_engine_new(AvahiServer *s) {
     AvahiMulticastLookupEngine *e;
-    
+
     assert(s);
-    
+
     e = avahi_new(AvahiMulticastLookupEngine, 1);
     e->server = s;
     e->cleanup_dead = 0;