X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-core%2Fmulticast-lookup.c;h=75988bfcd5434c154429f6664f828f7bbcd667f4;hb=abf0d60e6dd933273887c1600e0793eac2706438;hp=fa8c85951a5d0ba06289d3ff8c63a3af017ed658;hpb=6efe2615e04c6ef664fa9d49b013e261ba1e6e66;p=catta diff --git a/avahi-core/multicast-lookup.c b/avahi-core/multicast-lookup.c index fa8c859..75988bf 100644 --- a/avahi-core/multicast-lookup.c +++ b/avahi-core/multicast-lookup.c @@ -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 #endif +#include + #include #include @@ -39,17 +39,17 @@ struct AvahiMulticastLookup { 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); }; @@ -83,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)); @@ -114,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; } @@ -143,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) @@ -158,7 +159,7 @@ static void lookup_destroy(AvahiMulticastLookup *l) { if (l->cname_key) avahi_key_unref(l->cname_key); - + avahi_free(l); } @@ -176,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); } @@ -216,7 +217,7 @@ static void* scan_cache_callback(AvahiCache *c, AvahiKey *pattern, AvahiCacheEnt cbdata->userdata); cbdata->n_found ++; - + return NULL; } @@ -228,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; } @@ -244,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); @@ -261,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); @@ -272,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; @@ -288,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); @@ -310,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); @@ -323,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;