X-Git-Url: http://git.meshlink.io/?p=catta;a=blobdiff_plain;f=src%2Fquerier.c;h=dea1aa41c4e4495a1a7532f12412592b52670fcd;hp=682d52fff3b0e3a671ac3016a67fe24c8fa5b58f;hb=2c550daf4ac6a6aab7f21047c037b4dd53c57fa6;hpb=37d19f15523b6fe4d1fef2329abe421221b3d4b3 diff --git a/src/querier.c b/src/querier.c index 682d52f..dea1aa4 100644 --- a/src/querier.c +++ b/src/querier.c @@ -1,18 +1,18 @@ /*** - This file is part of avahi. + This file is part of catta. - avahi is free software; you can redistribute it and/or modify it + catta 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 + catta 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 + License along with catta; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ***/ @@ -23,46 +23,46 @@ #include -#include -#include -#include -#include +#include +#include +#include +#include #include "querier.h" -#include +#include -struct AvahiQuerier { - AvahiInterface *interface; +struct CattaQuerier { + CattaInterface *interface; - AvahiKey *key; + CattaKey *key; int n_used; unsigned sec_delay; - AvahiTimeEvent *time_event; + CattaTimeEvent *time_event; struct timeval creation_time; unsigned post_id; int post_id_valid; - AVAHI_LLIST_FIELDS(AvahiQuerier, queriers); + CATTA_LLIST_FIELDS(CattaQuerier, queriers); }; -void avahi_querier_free(AvahiQuerier *q) { +void catta_querier_free(CattaQuerier *q) { assert(q); - AVAHI_LLIST_REMOVE(AvahiQuerier, queriers, q->interface->queriers, q); - avahi_hashmap_remove(q->interface->queriers_by_key, q->key); + CATTA_LLIST_REMOVE(CattaQuerier, queriers, q->interface->queriers, q); + catta_hashmap_remove(q->interface->queriers_by_key, q->key); - avahi_key_unref(q->key); - avahi_time_event_free(q->time_event); + catta_key_unref(q->key); + catta_time_event_free(q->time_event); - avahi_free(q); + catta_free(q); } -static void querier_elapse_callback(AVAHI_GCC_UNUSED AvahiTimeEvent *e, void *userdata) { - AvahiQuerier *q = userdata; +static void querier_elapse_callback(CATTA_GCC_UNUSED CattaTimeEvent *e, void *userdata) { + CattaQuerier *q = userdata; struct timeval tv; assert(q); @@ -73,11 +73,11 @@ static void querier_elapse_callback(AVAHI_GCC_UNUSED AvahiTimeEvent *e, void *us * ourselves. We should not send out any further queries from * this querier object anymore. */ - avahi_querier_free(q); + catta_querier_free(q); return; } - if (avahi_interface_post_query(q->interface, q->key, 0, &q->post_id)) { + if (catta_interface_post_query(q->interface, q->key, 0, &q->post_id)) { /* The queue accepted our query. We store the query id here, * that allows us to drop the query at a later point if the @@ -91,18 +91,18 @@ static void querier_elapse_callback(AVAHI_GCC_UNUSED AvahiTimeEvent *e, void *us if (q->sec_delay >= 60*60) /* 1h */ q->sec_delay = 60*60; - avahi_elapse_time(&tv, q->sec_delay*1000, 0); - avahi_time_event_update(q->time_event, &tv); + catta_elapse_time(&tv, q->sec_delay*1000, 0); + catta_time_event_update(q->time_event, &tv); } -void avahi_querier_add(AvahiInterface *i, AvahiKey *key, struct timeval *ret_ctime) { - AvahiQuerier *q; +void catta_querier_add(CattaInterface *i, CattaKey *key, struct timeval *ret_ctime) { + CattaQuerier *q; struct timeval tv; assert(i); assert(key); - if ((q = avahi_hashmap_lookup(i->queriers_by_key, key))) { + if ((q = catta_hashmap_lookup(i->queriers_by_key, key))) { /* Someone is already browsing for records of this RR key */ q->n_used++; @@ -116,10 +116,10 @@ void avahi_querier_add(AvahiInterface *i, AvahiKey *key, struct timeval *ret_cti } /* No one is browsing for this RR key, so we add a new querier */ - if (!(q = avahi_new(AvahiQuerier, 1))) + if (!(q = catta_new(CattaQuerier, 1))) return; /* OOM */ - q->key = avahi_key_ref(key); + q->key = catta_key_ref(key); q->interface = i; q->n_used = 1; q->sec_delay = 1; @@ -127,14 +127,14 @@ void avahi_querier_add(AvahiInterface *i, AvahiKey *key, struct timeval *ret_cti gettimeofday(&q->creation_time, NULL); /* Do the initial query */ - if (avahi_interface_post_query(i, key, 0, &q->post_id)) + if (catta_interface_post_query(i, key, 0, &q->post_id)) q->post_id_valid = 1; /* Schedule next queries */ - q->time_event = avahi_time_event_new(i->monitor->server->time_event_queue, avahi_elapse_time(&tv, q->sec_delay*1000, 0), querier_elapse_callback, q); + q->time_event = catta_time_event_new(i->monitor->server->time_event_queue, catta_elapse_time(&tv, q->sec_delay*1000, 0), querier_elapse_callback, q); - AVAHI_LLIST_PREPEND(AvahiQuerier, queriers, i->queriers, q); - avahi_hashmap_insert(i->queriers_by_key, q->key, q); + CATTA_LLIST_PREPEND(CattaQuerier, queriers, i->queriers, q); + catta_hashmap_insert(i->queriers_by_key, q->key, q); /* Return the creation time. This is used for generating the * ALL_FOR_NOW event one second after the querier was initially @@ -143,24 +143,24 @@ void avahi_querier_add(AvahiInterface *i, AvahiKey *key, struct timeval *ret_cti *ret_ctime = q->creation_time; } -void avahi_querier_remove(AvahiInterface *i, AvahiKey *key) { - AvahiQuerier *q; +void catta_querier_remove(CattaInterface *i, CattaKey *key) { + CattaQuerier *q; /* There was no querier for this RR key, or it wasn't referenced * by anyone. */ - if (!(q = avahi_hashmap_lookup(i->queriers_by_key, key)) || q->n_used <= 0) + if (!(q = catta_hashmap_lookup(i->queriers_by_key, key)) || q->n_used <= 0) return; if ((--q->n_used) <= 0) { /* Nobody references us anymore. */ - if (q->post_id_valid && avahi_interface_withraw_query(i, q->post_id)) { + if (q->post_id_valid && catta_interface_withraw_query(i, q->post_id)) { /* We succeeded in withdrawing our query from the queue, * so let's drop dead. */ - avahi_querier_free(q); + catta_querier_free(q); } /* If we failed to withdraw our query from the queue, we stay @@ -170,28 +170,28 @@ void avahi_querier_remove(AvahiInterface *i, AvahiKey *key) { } } -static void remove_querier_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, void* userdata) { +static void remove_querier_callback(CattaInterfaceMonitor *m, CattaInterface *i, void* userdata) { assert(m); assert(i); assert(userdata); if (i->announcing) - avahi_querier_remove(i, (AvahiKey*) userdata); + catta_querier_remove(i, (CattaKey*) userdata); } -void avahi_querier_remove_for_all(AvahiServer *s, AvahiIfIndex idx, AvahiProtocol protocol, AvahiKey *key) { +void catta_querier_remove_for_all(CattaServer *s, CattaIfIndex idx, CattaProtocol protocol, CattaKey *key) { assert(s); assert(key); - avahi_interface_monitor_walk(s->monitor, idx, protocol, remove_querier_callback, key); + catta_interface_monitor_walk(s->monitor, idx, protocol, remove_querier_callback, key); } struct cbdata { - AvahiKey *key; + CattaKey *key; struct timeval *ret_ctime; }; -static void add_querier_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, void* userdata) { +static void add_querier_callback(CattaInterfaceMonitor *m, CattaInterface *i, void* userdata) { struct cbdata *cbdata = userdata; assert(m); @@ -200,14 +200,14 @@ static void add_querier_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, vo if (i->announcing) { struct timeval tv; - avahi_querier_add(i, cbdata->key, &tv); + catta_querier_add(i, cbdata->key, &tv); - if (cbdata->ret_ctime && avahi_timeval_compare(&tv, cbdata->ret_ctime) > 0) + if (cbdata->ret_ctime && catta_timeval_compare(&tv, cbdata->ret_ctime) > 0) *cbdata->ret_ctime = tv; } } -void avahi_querier_add_for_all(AvahiServer *s, AvahiIfIndex idx, AvahiProtocol protocol, AvahiKey *key, struct timeval *ret_ctime) { +void catta_querier_add_for_all(CattaServer *s, CattaIfIndex idx, CattaProtocol protocol, CattaKey *key, struct timeval *ret_ctime) { struct cbdata cbdata; assert(s); @@ -219,18 +219,18 @@ void avahi_querier_add_for_all(AvahiServer *s, AvahiIfIndex idx, AvahiProtocol p if (ret_ctime) ret_ctime->tv_sec = ret_ctime->tv_usec = 0; - avahi_interface_monitor_walk(s->monitor, idx, protocol, add_querier_callback, &cbdata); + catta_interface_monitor_walk(s->monitor, idx, protocol, add_querier_callback, &cbdata); } -int avahi_querier_shall_refresh_cache(AvahiInterface *i, AvahiKey *key) { - AvahiQuerier *q; +int catta_querier_shall_refresh_cache(CattaInterface *i, CattaKey *key) { + CattaQuerier *q; assert(i); assert(key); /* Called by the cache maintainer */ - if (!(q = avahi_hashmap_lookup(i->queriers_by_key, key))) + if (!(q = catta_hashmap_lookup(i->queriers_by_key, key))) /* This key is currently not subscribed at all, so no cache * refresh is needed */ return 0; @@ -242,7 +242,7 @@ int avahi_querier_shall_refresh_cache(AvahiInterface *i, AvahiKey *key) { /* Remove this querier since it is referenced by nobody * and the cached data will soon be out of date */ - avahi_querier_free(q); + catta_querier_free(q); /* Tell the cache that no refresh is needed */ return 0; @@ -252,17 +252,17 @@ int avahi_querier_shall_refresh_cache(AvahiInterface *i, AvahiKey *key) { /* We can defer our query a little, since the cache will now * issue a refresh query anyway. */ - avahi_elapse_time(&tv, q->sec_delay*1000, 0); - avahi_time_event_update(q->time_event, &tv); + catta_elapse_time(&tv, q->sec_delay*1000, 0); + catta_time_event_update(q->time_event, &tv); /* Tell the cache that a refresh should be issued */ return 1; } } -void avahi_querier_free_all(AvahiInterface *i) { +void catta_querier_free_all(CattaInterface *i) { assert(i); while (i->queriers) - avahi_querier_free(i->queriers); + catta_querier_free(i->queriers); }