rrlist.c rrlist.h \
alternative.c alternative.h \
resolve-host-name.c \
- resolve-address.c
+ resolve-address.c \
+ browse-domain.c
prioq_test_SOURCES = \
prioq-test.c \
return TRUE;
}
-static void record_resolver_callback(AvahiRecordResolver *r, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
+static void record_browser_callback(AvahiRecordBrowser *r, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
gchar *t;
g_assert(r);
g_assert(protocol != AF_UNSPEC);
g_message("SUBSCRIPTION: record [%s] on %i.%i is %s", t = avahi_record_to_string(record), interface, protocol,
- event == AVAHI_BROWSER_NEW ? "new" : "removed");
+ event == AVAHI_BROWSER_NEW ? "new" : "remove");
g_free(t);
}
-
static void remove_entries(void);
static void create_entries(gboolean new_name);
static void hnr_callback(AvahiHostNameResolver *r, gint iface, guchar protocol, AvahiBrowserEvent event, const gchar *hostname, const AvahiAddress *a, gpointer userdata) {
gchar t[64];
+ if (a)
+ avahi_address_snprint(t, sizeof(t), a);
+
+ g_message("HNR: (%i.%i) %s -> %s [%s]", iface, protocol, hostname, a ? t : "n/a", event == AVAHI_BROWSER_NEW ? "found" : "timeout");
+}
+
+static void ar_callback(AvahiAddressResolver *r, gint iface, guchar protocol, AvahiBrowserEvent event, const AvahiAddress *a, const gchar *hostname, gpointer userdata) {
+ gchar t[64];
+
avahi_address_snprint(t, sizeof(t), a);
- g_message("HNR: (%i.%i) %s -> %s [%s]", iface, protocol, hostname, t, event == AVAHI_BROWSER_NEW ? "new" : "remove");
+ g_message("AR: (%i.%i) %s -> %s [%s]", iface, protocol, t, hostname ? hostname : "n/a", event == AVAHI_BROWSER_NEW ? "found" : "timeout");
+}
+
+static void db_callback(AvahiDomainBrowser *b, gint iface, guchar protocol, AvahiBrowserEvent event, const gchar *domain, gpointer userdata) {
+
+ g_message("DB: (%i.%i) %s [%s]", iface, protocol, domain, event == AVAHI_BROWSER_NEW ? "new" : "remove");
}
int main(int argc, char *argv[]) {
GMainLoop *loop = NULL;
- AvahiRecordResolver *r;
+ AvahiRecordBrowser *r;
AvahiHostNameResolver *hnr;
+ AvahiAddressResolver *ar;
AvahiKey *k;
AvahiServerConfig config;
+ AvahiAddress a;
+ AvahiDomainBrowser *db;
avahi_server_config_init(&config);
/* config.host_name = g_strdup("test"); */
avahi_server_config_free(&config);
k = avahi_key_new("_http._tcp.local", AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR);
- r = avahi_record_resolver_new(server, 0, AF_UNSPEC, k, record_resolver_callback, NULL);
+ r = avahi_record_browser_new(server, 0, AF_UNSPEC, k, record_browser_callback, NULL);
avahi_key_unref(k);
- hnr = avahi_host_name_resolver_new(server, 0, AF_UNSPEC, "ecstasy.local", hnr_callback, NULL);
+ hnr = avahi_host_name_resolver_new(server, 0, AF_UNSPEC, "codes-CompUTER.local", AF_UNSPEC, hnr_callback, NULL);
+ ar = avahi_address_resolver_new(server, 0, AF_UNSPEC, avahi_address_parse("192.168.50.15", AF_INET, &a), ar_callback, NULL);
+
+ db = avahi_domain_browser_new(server, 0, AF_UNSPEC, NULL, AVAHI_DOMAIN_BROWSER_BROWSE, db_callback, NULL);
+
loop = g_main_loop_new(NULL, FALSE);
/* g_timeout_add(1000*5, dump_timeout, server); */
- g_timeout_add(1000*30, quit_timeout, loop);
+/* g_timeout_add(1000*30, quit_timeout, loop); */
g_main_loop_run(loop);
g_main_loop_unref(loop);
- avahi_record_resolver_free(r);
+ avahi_record_browser_free(r);
avahi_host_name_resolver_free(hnr);
+ avahi_address_resolver_free(ar);
if (group)
avahi_entry_group_free(group);
if (e->time_event)
avahi_time_event_queue_remove(c->server->time_event_queue, e->time_event);
- avahi_resolver_notify(c->server, c->interface, e->record, AVAHI_BROWSER_REMOVE);
+ avahi_browser_notify(c->server, c->interface, e->record, AVAHI_BROWSER_REMOVE);
avahi_record_unref(e->record);
g_assert(percent > 0);
/* Request a cache update, if we are subscribed to this entry */
- if (avahi_is_subscribed(e->cache->server, e->record->key)) {
+ if (avahi_is_subscribed(e->cache->server, e->cache->interface, e->record->key)) {
/* g_message("Requesting cache entry update at %i%%.", percent); */
avahi_interface_post_query(e->cache->interface, e->record->key, TRUE);
}
AVAHI_LLIST_PREPEND(AvahiCacheEntry, entry, c->entries, e);
/* Notify subscribers */
- avahi_resolver_notify(c->server, c->interface, e->record, AVAHI_BROWSER_NEW);
+ avahi_browser_notify(c->server, c->interface, e->record, AVAHI_BROWSER_NEW);
}
e->origin = *a;
gpointer avahi_server_get_data(AvahiServer *s);
void avahi_server_set_data(AvahiServer *s, gpointer userdata);
-AvahiServerState avhai_server_get_state(AvahiServer *s);
+AvahiServerState avahi_server_get_state(AvahiServer *s);
const AvahiRecord *avahi_server_iterate(AvahiServer *s, AvahiEntryGroup *g, void **state);
void avahi_server_dump(AvahiServer *s, FILE *f);
AvahiStringList *strlst);
typedef enum {
- AVAHI_BROWSER_NEW,
- AVAHI_BROWSER_REMOVE,
+ AVAHI_BROWSER_NEW = 0,
+ AVAHI_BROWSER_REMOVE = -1
} AvahiBrowserEvent;
-typedef struct AvahiRecordResolver AvahiRecordResolver;
-typedef void (*AvahiRecordResolverCallback)(AvahiRecordResolver *r, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata);
-AvahiRecordResolver *avahi_record_resolver_new(AvahiServer *server, gint interface, guchar protocol, AvahiKey *key, AvahiRecordResolverCallback callback, gpointer userdata);
-void avahi_record_resolver_free(AvahiRecordResolver *r);
+typedef enum {
+ AVAHI_RESOLVER_FOUND = 0,
+ AVAHI_RESOLVER_TIMEOUT = -1
+} AvahiResolverEvent;
+
+
+typedef struct AvahiRecordBrowser AvahiRecordBrowser;
+typedef void (*AvahiRecordBrowserCallback)(AvahiRecordBrowser *b, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata);
+AvahiRecordBrowser *avahi_record_browser_new(AvahiServer *server, gint interface, guchar protocol, AvahiKey *key, AvahiRecordBrowserCallback callback, gpointer userdata);
+void avahi_record_browser_free(AvahiRecordBrowser *b);
typedef struct AvahiHostNameResolver AvahiHostNameResolver;
-typedef void (*AvahiHostNameResolverCallback)(AvahiHostNameResolver *r, gint interface, guchar protocol, AvahiBrowserEvent event, const gchar *host_name, const AvahiAddress *a, gpointer userdata);
-AvahiHostNameResolver *avahi_host_name_resolver_new(AvahiServer *server, gint interface, guchar protocol, const gchar *host_name, AvahiHostNameResolverCallback calback, gpointer userdata);
+typedef void (*AvahiHostNameResolverCallback)(AvahiHostNameResolver *r, gint interface, guchar protocol, AvahiResolverEvent event, const gchar *host_name, const AvahiAddress *a, gpointer userdata);
+AvahiHostNameResolver *avahi_host_name_resolver_new(AvahiServer *server, gint interface, guchar protocol, const gchar *host_name, guchar aprotocol, AvahiHostNameResolverCallback calback, gpointer userdata);
void avahi_host_name_resolver_free(AvahiHostNameResolver *r);
typedef struct AvahiAddressResolver AvahiAddressResolver;
-typedef void (*AvahiAddressResolverCallback)(AvahiAddressResolver *r, gint interface, guchar protocol, AvahiBrowserEvent event, const AvahiAddress *a, const gchar *host_name, gpointer userdata);
+typedef void (*AvahiAddressResolverCallback)(AvahiAddressResolver *r, gint interface, guchar protocol, AvahiResolverEvent event, const AvahiAddress *a, const gchar *host_name, gpointer userdata);
AvahiAddressResolver *avahi_address_resolver_new(AvahiServer *server, gint interface, guchar protocol, const AvahiAddress *address, AvahiAddressResolverCallback calback, gpointer userdata);
void avahi_address_resolver_free(AvahiAddressResolver *r);
-/* not yet implemented */
+typedef enum {
+ AVAHI_DOMAIN_BROWSER_REGISTER,
+ AVAHI_DOMAIN_BROWSER_REGISTER_DEFAULT,
+ AVAHI_DOMAIN_BROWSER_BROWSE,
+ AVAHI_DOMAIN_BROWSER_BROWSE_DEFAULT
+} AvahiDomainBrowserType;
typedef struct AvahiDomainBrowser AvahiDomainBrowser;
+typedef void (*AvahiDomainBrowserCallback)(AvahiDomainBrowser *b, gint interface, guchar protocol, AvahiBrowserEvent event, const gchar *domain, gpointer userdata);
+AvahiDomainBrowser *avahi_domain_browser_new(AvahiServer *server, gint interface, guchar protocol, const gchar *domain, AvahiDomainBrowserType type, AvahiDomainBrowserCallback callback, gpointer userdata);
+void avahi_domain_browser_free(AvahiDomainBrowser *b);
+
+/* not yet implemented */
typedef struct AvahiServiceTypeBrowser AvahiServiceTypeBrowser;
typedef struct AvahiServiceBrowser AvahiServiceBrowser;
typedef struct AvahiServiceResolver AvahiServiceResolver;
AvahiServer *server;
AvahiAddress address;
- AvahiRecordResolver *record_resolver;
+ AvahiRecordBrowser *record_browser;
AvahiAddressResolverCallback callback;
gpointer userdata;
+ AvahiTimeEvent *time_event;
+
AVAHI_LLIST_FIELDS(AvahiAddressResolver, resolver);
};
-static void record_resolver_callback(AvahiRecordResolver*rr, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
+static void finish(AvahiAddressResolver *r, gint interface, guchar protocol, AvahiResolverEvent event, AvahiRecord *record) {
+ g_assert(r);
+
+ avahi_record_browser_free(r->record_browser);
+ r->record_browser = NULL;
+
+ avahi_time_event_queue_remove(r->server->time_event_queue, r->time_event);
+ r->time_event = NULL;
+
+ r->callback(r, interface, protocol, event, &r->address, record ? record->data.ptr.name : NULL, r->userdata);
+}
+
+static void record_browser_callback(AvahiRecordBrowser*rr, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
AvahiAddressResolver *r = userdata;
g_assert(rr);
g_assert(record);
g_assert(r);
- r->callback(r, interface, protocol, event, &r->address, record->data.ptr.name, r->userdata);
+ if (!(event == AVAHI_BROWSER_NEW))
+ return;
+
+ g_assert(record->key->type == AVAHI_DNS_TYPE_PTR);
+
+ finish(r, interface, protocol, AVAHI_RESOLVER_FOUND, record);
+}
+
+static void time_event_callback(AvahiTimeEvent *e, void *userdata) {
+ AvahiAddressResolver *r = userdata;
+
+ g_assert(e);
+ g_assert(r);
+
+ finish(r, -1, AF_UNSPEC, AVAHI_RESOLVER_TIMEOUT, NULL);
}
AvahiAddressResolver *avahi_address_resolver_new(AvahiServer *server, gint interface, guchar protocol, const AvahiAddress *address, AvahiAddressResolverCallback callback, gpointer userdata) {
AvahiAddressResolver *r;
AvahiKey *k;
gchar *n;
+ GTimeVal tv;
g_assert(server);
g_assert(address);
k = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR);
g_free(n);
- r->record_resolver = avahi_record_resolver_new(server, interface, protocol, k, record_resolver_callback, r);
+ r->record_browser = avahi_record_browser_new(server, interface, protocol, k, record_browser_callback, r);
avahi_key_unref(k);
+ avahi_elapse_time(&tv, 1000, 0);
+ r->time_event = avahi_time_event_queue_add(server->time_event_queue, &tv, time_event_callback, r);
+
AVAHI_LLIST_PREPEND(AvahiAddressResolver, resolver, server->address_resolvers, r);
return r;
g_assert(r);
AVAHI_LLIST_REMOVE(AvahiAddressResolver, resolver, r->server->address_resolvers, r);
- avahi_record_resolver_free(r->record_resolver);
+
+ if (r->record_browser)
+ avahi_record_browser_free(r->record_browser);
+
+ if (r->time_event)
+ avahi_time_event_queue_remove(r->server->time_event_queue, r->time_event);
+
g_free(r);
}
AvahiServer *server;
gchar *host_name;
- AvahiRecordResolver *record_resolver_a;
- AvahiRecordResolver *record_resolver_aaaa;
+ AvahiRecordBrowser *record_browser_a;
+ AvahiRecordBrowser *record_browser_aaaa;
AvahiHostNameResolverCallback callback;
gpointer userdata;
+ AvahiTimeEvent *time_event;
+
AVAHI_LLIST_FIELDS(AvahiHostNameResolver, resolver);
};
-static void record_resolver_callback(AvahiRecordResolver*rr, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
- AvahiHostNameResolver *r = userdata;
+static void finish(AvahiHostNameResolver *r, gint interface, guchar protocol, AvahiResolverEvent event, AvahiRecord *record) {
AvahiAddress a;
+
+ g_assert(r);
+
+ if (r->record_browser_a) {
+ avahi_record_browser_free(r->record_browser_a);
+ r->record_browser_a = NULL;
+ }
+
+ if (r->record_browser_aaaa) {
+ avahi_record_browser_free(r->record_browser_aaaa);
+ r->record_browser_aaaa = NULL;
+ }
+
+ avahi_time_event_queue_remove(r->server->time_event_queue, r->time_event);
+ r->time_event = NULL;
+
+ if (record) {
+ switch (record->key->type) {
+ case AVAHI_DNS_TYPE_A:
+ a.family = AF_INET;
+ a.data.ipv4 = record->data.a.address;
+ break;
+
+ case AVAHI_DNS_TYPE_AAAA:
+ a.family = AF_INET6;
+ a.data.ipv6 = record->data.aaaa.address;
+ break;
+
+ default:
+ g_assert(FALSE);
+ }
+ }
+
+ r->callback(r, interface, protocol, event, record ? record->key->name : r->host_name, record ? &a : NULL, r->userdata);
+}
+
+static void record_browser_callback(AvahiRecordBrowser*rr, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
+ AvahiHostNameResolver *r = userdata;
g_assert(rr);
g_assert(record);
g_assert(r);
- switch (record->key->type) {
- case AVAHI_DNS_TYPE_A:
- a.family = AF_INET;
- a.data.ipv4 = record->data.a.address;
- break;
-
- case AVAHI_DNS_TYPE_AAAA:
- a.family = AF_INET6;
- a.data.ipv6 = record->data.aaaa.address;
- break;
+ if (!(event == AVAHI_BROWSER_NEW))
+ return;
+
+ g_assert(record->key->type == AVAHI_DNS_TYPE_A || record->key->type == AVAHI_DNS_TYPE_AAAA);
+ finish(r, interface, protocol, AVAHI_RESOLVER_FOUND, record);
+}
- default:
- g_assert(FALSE);
- }
+static void time_event_callback(AvahiTimeEvent *e, void *userdata) {
+ AvahiHostNameResolver *r = userdata;
+
+ g_assert(e);
+ g_assert(r);
- r->callback(r, interface, protocol, event, record->key->name, &a, r->userdata);
+ finish(r, -1, AF_UNSPEC, AVAHI_RESOLVER_TIMEOUT, NULL);
}
-AvahiHostNameResolver *avahi_host_name_resolver_new(AvahiServer *s, gint interface, guchar protocol, const gchar *host_name, AvahiHostNameResolverCallback callback, gpointer userdata) {
+AvahiHostNameResolver *avahi_host_name_resolver_new(AvahiServer *server, gint interface, guchar protocol, const gchar *host_name, guchar aprotocol, AvahiHostNameResolverCallback callback, gpointer userdata) {
AvahiHostNameResolver *r;
AvahiKey *k;
-
- g_assert(s);
+ GTimeVal tv;
+
+ g_assert(server);
g_assert(host_name);
g_assert(callback);
+ g_assert(aprotocol == AF_UNSPEC || aprotocol == AF_INET || aprotocol == AF_INET6);
+
r = g_new(AvahiHostNameResolver, 1);
- r->server = s;
+ r->server = server;
r->host_name = avahi_normalize_name(host_name);
r->callback = callback;
r->userdata = userdata;
- k = avahi_key_new(host_name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_A);
- r->record_resolver_a = avahi_record_resolver_new(s, interface, protocol, k, record_resolver_callback, r);
- avahi_key_unref(k);
-
- k = avahi_key_new(host_name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_AAAA);
- r->record_resolver_aaaa = avahi_record_resolver_new(s, interface, protocol, k, record_resolver_callback, r);
- avahi_key_unref(k);
-
- AVAHI_LLIST_PREPEND(AvahiHostNameResolver, resolver, s->host_name_resolvers, r);
+ if (aprotocol == AF_INET || aprotocol == AF_UNSPEC) {
+ k = avahi_key_new(host_name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_A);
+ r->record_browser_a = avahi_record_browser_new(server, interface, protocol, k, record_browser_callback, r);
+ avahi_key_unref(k);
+ } else
+ r->record_browser_a = NULL;
+
+ if (aprotocol == AF_INET6 || aprotocol == AF_UNSPEC) {
+ k = avahi_key_new(host_name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_AAAA);
+ r->record_browser_aaaa = avahi_record_browser_new(server, interface, protocol, k, record_browser_callback, r);
+ avahi_key_unref(k);
+ } else
+ r->record_browser_aaaa = NULL;
+
+ avahi_elapse_time(&tv, 1000, 0);
+ r->time_event = avahi_time_event_queue_add(server->time_event_queue, &tv, time_event_callback, r);
+
+ AVAHI_LLIST_PREPEND(AvahiHostNameResolver, resolver, server->host_name_resolvers, r);
return r;
}
AVAHI_LLIST_REMOVE(AvahiHostNameResolver, resolver, r->server->host_name_resolvers, r);
- avahi_record_resolver_free(r->record_resolver_a);
- avahi_record_resolver_free(r->record_resolver_aaaa);
+ if (r->record_browser_a)
+ avahi_record_browser_free(r->record_browser_a);
+ if (r->record_browser_aaaa)
+ avahi_record_browser_free(r->record_browser_aaaa);
+
g_free(r->host_name);
g_free(r);
}
#include "resolve.h"
#include "util.h"
+struct AvahiRecordBrowser {
+ gboolean dead;
+
+ AvahiServer *server;
+ AvahiKey *key;
+ gint interface;
+ guchar protocol;
+ gint n_query;
+ guint sec_delay;
+
+ AvahiTimeEvent *time_event;
+
+ AvahiRecordBrowserCallback callback;
+ gpointer userdata;
+
+ AVAHI_LLIST_FIELDS(AvahiRecordBrowser, resolver);
+ AVAHI_LLIST_FIELDS(AvahiRecordBrowser, by_key);
+};
+
static void elapse(AvahiTimeEvent *e, void *userdata) {
- AvahiRecordResolver *s = userdata;
+ AvahiRecordBrowser *s = userdata;
GTimeVal tv;
/* gchar *t; */
}
struct cbdata {
- AvahiRecordResolver *record_resolver;
+ AvahiRecordBrowser *record_browser;
AvahiInterface *interface;
};
g_assert(e);
g_assert(cbdata);
- cbdata->record_resolver->callback(
- cbdata->record_resolver,
+ if (cbdata->record_browser->dead)
+ return NULL;
+
+ cbdata->record_browser->callback(
+ cbdata->record_browser,
cbdata->interface->hardware->index,
cbdata->interface->protocol,
AVAHI_BROWSER_NEW,
e->record,
- cbdata->record_resolver->userdata);
+ cbdata->record_browser->userdata);
return NULL;
}
static void scan_interface_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, gpointer userdata) {
- AvahiRecordResolver *s = userdata;
+ AvahiRecordBrowser *s = userdata;
struct cbdata cbdata = { s, i };
g_assert(m);
avahi_cache_walk(i->cache, s->key, scan_cache_callback, &cbdata);
}
-AvahiRecordResolver *avahi_record_resolver_new(AvahiServer *server, gint interface, guchar protocol, AvahiKey *key, AvahiRecordResolverCallback callback, gpointer userdata) {
- AvahiRecordResolver *s, *t;
+AvahiRecordBrowser *avahi_record_browser_new(AvahiServer *server, gint interface, guchar protocol, AvahiKey *key, AvahiRecordBrowserCallback callback, gpointer userdata) {
+ AvahiRecordBrowser *b, *t;
GTimeVal tv;
g_assert(server);
g_assert(!avahi_key_is_pattern(key));
- s = g_new(AvahiRecordResolver, 1);
- s->server = server;
- s->key = avahi_key_ref(key);
- s->interface = interface;
- s->protocol = protocol;
- s->callback = callback;
- s->userdata = userdata;
- s->n_query = 1;
- s->sec_delay = 1;
-
- avahi_server_post_query(s->server, s->interface, s->protocol, s->key);
+ b = g_new(AvahiRecordBrowser, 1);
+ b->dead = FALSE;
+ b->server = server;
+ b->key = avahi_key_ref(key);
+ b->interface = interface;
+ b->protocol = protocol;
+ b->callback = callback;
+ b->userdata = userdata;
+ b->n_query = 1;
+ b->sec_delay = 1;
+
+ avahi_server_post_query(b->server, b->interface, b->protocol, b->key);
- avahi_elapse_time(&tv, s->sec_delay*1000, 0);
- s->time_event = avahi_time_event_queue_add(server->time_event_queue, &tv, elapse, s);
+ avahi_elapse_time(&tv, b->sec_delay*1000, 0);
+ b->time_event = avahi_time_event_queue_add(server->time_event_queue, &tv, elapse, b);
- AVAHI_LLIST_PREPEND(AvahiRecordResolver, resolver, server->record_resolvers, s);
+ AVAHI_LLIST_PREPEND(AvahiRecordBrowser, resolver, server->record_browsers, b);
- /* Add the new entry to the record_resolver hash table */
- t = g_hash_table_lookup(server->record_resolver_hashtable, key);
- AVAHI_LLIST_PREPEND(AvahiRecordResolver, by_key, t, s);
- g_hash_table_replace(server->record_resolver_hashtable, key, t);
+ /* Add the new entry to the record_browser hash table */
+ t = g_hash_table_lookup(server->record_browser_hashtable, key);
+ AVAHI_LLIST_PREPEND(AvahiRecordBrowser, by_key, t, b);
+ g_hash_table_replace(server->record_browser_hashtable, key, t);
/* Scan the caches */
- avahi_interface_monitor_walk(s->server->monitor, s->interface, s->protocol, scan_interface_callback, s);
+ avahi_interface_monitor_walk(b->server->monitor, b->interface, b->protocol, scan_interface_callback, b);
- return s;
+ return b;
}
-void avahi_record_resolver_free(AvahiRecordResolver *s) {
- AvahiRecordResolver *t;
-
- g_assert(s);
+void avahi_record_browser_free(AvahiRecordBrowser *b) {
+ g_assert(b);
+ g_assert(!b->dead);
- AVAHI_LLIST_REMOVE(AvahiRecordResolver, resolver, s->server->record_resolvers, s);
+ b->dead = TRUE;
+ b->server->need_browser_cleanup = TRUE;
- t = g_hash_table_lookup(s->server->record_resolver_hashtable, s->key);
- AVAHI_LLIST_REMOVE(AvahiRecordResolver, by_key, t, s);
+ if (b->time_event) {
+ avahi_time_event_queue_remove(b->server->time_event_queue, b->time_event);
+ b->time_event = NULL;
+ }
+}
+
+void avahi_record_browser_destroy(AvahiRecordBrowser *b) {
+ AvahiRecordBrowser *t;
+
+ g_assert(b);
+
+ AVAHI_LLIST_REMOVE(AvahiRecordBrowser, resolver, b->server->record_browsers, b);
+
+ t = g_hash_table_lookup(b->server->record_browser_hashtable, b->key);
+ AVAHI_LLIST_REMOVE(AvahiRecordBrowser, by_key, t, b);
if (t)
- g_hash_table_replace(s->server->record_resolver_hashtable, t->key, t);
+ g_hash_table_replace(b->server->record_browser_hashtable, t->key, t);
else
- g_hash_table_remove(s->server->record_resolver_hashtable, s->key);
+ g_hash_table_remove(b->server->record_browser_hashtable, b->key);
+
+ if (b->time_event)
+ avahi_time_event_queue_remove(b->server->time_event_queue, b->time_event);
+ avahi_key_unref(b->key);
- avahi_time_event_queue_remove(s->server->time_event_queue, s->time_event);
- avahi_key_unref(s->key);
+ g_free(b);
+}
+void avahi_browser_cleanup(AvahiServer *server) {
+ AvahiRecordBrowser *b;
+ AvahiRecordBrowser *n;
- g_free(s);
+ g_assert(server);
+
+ for (b = server->record_browsers; b; b = n) {
+ n = b->resolver_next;
+
+ if (b->dead)
+ avahi_record_browser_destroy(b);
+ }
+
+ server->need_browser_cleanup = FALSE;
}
-void avahi_resolver_notify(AvahiServer *server, AvahiInterface *i, AvahiRecord *record, AvahiBrowserEvent event) {
- AvahiRecordResolver *s;
+void avahi_browser_notify(AvahiServer *server, AvahiInterface *i, AvahiRecord *record, AvahiBrowserEvent event) {
+ AvahiRecordBrowser *b;
g_assert(server);
g_assert(record);
- for (s = g_hash_table_lookup(server->record_resolver_hashtable, record->key); s; s = s->by_key_next)
- if (avahi_interface_match(i, s->interface, s->protocol))
- s->callback(s, i->hardware->index, i->protocol, event, record, s->userdata);
+ for (b = g_hash_table_lookup(server->record_browser_hashtable, record->key); b; b = b->by_key_next)
+ if (!b->dead && avahi_interface_match(i, b->interface, b->protocol))
+ b->callback(b, i->hardware->index, i->protocol, event, record, b->userdata);
}
-gboolean avahi_is_subscribed(AvahiServer *server, AvahiKey *k) {
+gboolean avahi_is_subscribed(AvahiServer *server, AvahiInterface *i, AvahiKey *k) {
+ AvahiRecordBrowser *b;
g_assert(server);
g_assert(k);
- return !!g_hash_table_lookup(server->record_resolver_hashtable, k);
+ for (b = g_hash_table_lookup(server->record_browser_hashtable, k); b; b = b->by_key_next)
+ if (!b->dead && avahi_interface_match(i, b->interface, b->protocol))
+ return TRUE;
+
+ return FALSE;
}
#include "timeeventq.h"
#include "server.h"
-struct AvahiRecordResolver {
- AvahiServer *server;
- AvahiKey *key;
- gint interface;
- guchar protocol;
- gint n_query;
- guint sec_delay;
+void avahi_browser_cleanup(AvahiServer *server);
+void avahi_browser_notify(AvahiServer *s, AvahiInterface *i, AvahiRecord *record, AvahiBrowserEvent event);
- AvahiTimeEvent *time_event;
+gboolean avahi_is_subscribed(AvahiServer *s, AvahiInterface *i, AvahiKey *k);
- AvahiRecordResolverCallback callback;
- gpointer userdata;
-
- AVAHI_LLIST_FIELDS(AvahiRecordResolver, resolver);
- AVAHI_LLIST_FIELDS(AvahiRecordResolver, by_key);
-};
-
-void avahi_resolver_notify(AvahiServer *s, AvahiInterface *i, AvahiRecord *record, AvahiBrowserEvent event);
-
-gboolean avahi_is_subscribed(AvahiServer *s, AvahiKey *k);
+void avahi_record_browser_destroy(AvahiRecordBrowser *b);
#endif
gchar *avahi_key_to_string(const AvahiKey *k) {
+ g_assert(k);
+ g_assert(k->ref >= 1);
+
return g_strdup_printf("%s\t%s\t%s",
k->name,
avahi_dns_class_to_string(k->class),
gchar *p, *s;
char buf[257], *t = NULL, *d = NULL;
+ g_assert(r);
+ g_assert(r->ref >= 1);
+
switch (r->key->type) {
case AVAHI_DNS_TYPE_A:
inet_ntop(AF_INET, &r->data.a.address.address, t = buf, sizeof(buf));
s->need_entry_cleanup = FALSE;
}
+
+ if (s->need_browser_cleanup)
+ avahi_browser_cleanup(s);
}
static void enum_aux_records(AvahiServer *s, AvahiInterface *i, const gchar *name, guint16 type, void (*callback)(AvahiServer *s, AvahiRecord *r, gboolean flush_cache, gpointer userdata), gpointer userdata) {
static gboolean handle_conflict(AvahiServer *s, AvahiInterface *i, AvahiRecord *record, gboolean unique, const AvahiAddress *a) {
gboolean valid = TRUE, ours = FALSE, conflict = FALSE, withdraw_immediately = FALSE;
AvahiEntry *e, *n, *conflicting_entry = NULL;
- gchar *t;
g_assert(s);
g_assert(i);
g_assert(record);
- t = avahi_record_to_string(record);
/* g_message("CHECKING FOR CONFLICT: [%s]", t); */
/* Check wheter there is a TTL conflict */
if (record->ttl <= e->record->ttl/2) {
+ gchar *t;
/* Refresh */
+ t = avahi_record_to_string(record);
+
g_message("Recieved record with bad TTL [%s]. Refreshing.", t);
- avahi_interface_post_response(i, e->record, FALSE, NULL, TRUE);
+ avahi_server_prepare_matching_responses(s, i, e->record->key, FALSE);
valid = FALSE;
+
+ g_free(t);
}
/* There's no need to check the other entries of this RRset */
/* g_message("ours=%i conflict=%i", ours, conflict); */
if (!ours && conflict) {
+ gchar *t;
+
valid = FALSE;
+ t = avahi_record_to_string(record);
+
if (withdraw_immediately) {
g_message("Recieved conflicting record [%s] with local record to be. Withdrawing.", t);
withdraw_rrset(s, record->key);
/* Local unique records are returned to probin
* state. Local shared records are reannounced. */
}
- }
- g_free(t);
+ g_free(t);
+ }
return valid;
}
s = g_new(AvahiServer, 1);
s->n_host_rr_pending = 0;
- s->need_entry_cleanup = s->need_group_cleanup = FALSE;
+ s->need_entry_cleanup = s->need_group_cleanup = s->need_browser_cleanup = FALSE;
if (sc)
avahi_server_config_copy(&s->config, sc);
s->entries_by_key = g_hash_table_new((GHashFunc) avahi_key_hash, (GEqualFunc) avahi_key_equal);
AVAHI_LLIST_HEAD_INIT(AvahiGroup, s->groups);
- AVAHI_LLIST_HEAD_INIT(AvahiRecordResolver, s->record_resolvers);
- s->record_resolver_hashtable = g_hash_table_new((GHashFunc) avahi_key_hash, (GEqualFunc) avahi_key_equal);
+ AVAHI_LLIST_HEAD_INIT(AvahiRecordBrowser, s->record_browsers);
+ s->record_browser_hashtable = g_hash_table_new((GHashFunc) avahi_key_hash, (GEqualFunc) avahi_key_equal);
AVAHI_LLIST_HEAD_INIT(AvahiHostNameResolver, s->host_name_resolvers);
AVAHI_LLIST_HEAD_INIT(AvahiAddressResolver, s->address_resolvers);
+ AVAHI_LLIST_HEAD_INIT(AvahiDomainBrowser, s->domain_browsers);
/* Get host name */
s->host_name = s->config.host_name ? avahi_normalize_name(s->config.host_name) : avahi_get_host_name();
avahi_host_name_resolver_free(s->host_name_resolvers);
while (s->address_resolvers)
avahi_address_resolver_free(s->address_resolvers);
- while (s->record_resolvers)
- avahi_record_resolver_free(s->record_resolvers);
- g_hash_table_destroy(s->record_resolver_hashtable);
+ while (s->domain_browsers)
+ avahi_domain_browser_free(s->domain_browsers);
+ while (s->record_browsers)
+ avahi_record_browser_destroy(s->record_browsers);
+ g_hash_table_destroy(s->record_browser_hashtable);
g_hash_table_destroy(s->entries_by_key);
s->userdata = userdata;
}
-AvahiServerState avhai_server_get_state(AvahiServer *s) {
+AvahiServerState avahi_server_get_state(AvahiServer *s) {
g_assert(s);
return s->state;
AVAHI_LLIST_HEAD(AvahiEntryGroup, groups);
- AVAHI_LLIST_HEAD(AvahiRecordResolver, record_resolvers);
- GHashTable *record_resolver_hashtable;
+ AVAHI_LLIST_HEAD(AvahiRecordBrowser, record_browsers);
+ GHashTable *record_browser_hashtable;
AVAHI_LLIST_HEAD(AvahiHostNameResolver, host_name_resolvers);
AVAHI_LLIST_HEAD(AvahiAddressResolver, address_resolvers);
+ AVAHI_LLIST_HEAD(AvahiDomainBrowser, domain_browsers);
- gboolean need_entry_cleanup, need_group_cleanup;
+ gboolean need_entry_cleanup, need_group_cleanup, need_browser_cleanup;
AvahiTimeEventQueue *time_event_queue;
if (n != l)
s ++;
- s += n->size+3;
+ s += n->size+2;
}
- t = e = g_new(gchar, s);
+ t = e = g_new(gchar, s+1);
for (n = l; n; n = n->next) {
if (n != l)
e[n->size] = 0;
e = strchr(e, 0);
*(e++) = '"';
+
+ g_assert(e);
}
l = string_list_reverse(l);
-
+
*e = 0;
return t;
AvahiTimeEvent* avahi_time_event_queue_root(AvahiTimeEventQueue *q);
AvahiTimeEvent* avahi_time_event_next(AvahiTimeEvent *e);
-
-
-
#endif
*(ret_dest++) = '\\';
*(ret_dest++) = *src;
-
escaped = FALSE;
} else {
if (--size <= 1) break;