1 --- /usr/tmp/clean/avahi-0.6.28/avahi-core/browse-domain.c 2010-08-26 01:51:38.982153000 +0100
2 +++ avahi-0.6.28/avahi-core/browse-domain.c 2011-01-20 15:24:22.639202717 +0000
4 #include <avahi-common/domain.h>
5 #include <avahi-common/malloc.h>
6 #include <avahi-common/error.h>
8 +#include <avahi-common/timeval.h>
15 int all_for_now_scheduled;
18 + AvahiIfIndex interface;
19 + AvahiTimeEvent *browse_error_event;
20 + AvahiTimeEvent *all_for_now_event;
21 + AvahiLookupFlags flags;
23 + DNSServiceRef client;
25 AVAHI_LLIST_FIELDS(AvahiSDomainBrowser, browser);
29 avahi_s_domain_browser_free(b);
33 +static void enumerate_reply(DNSServiceRef service,
34 + DNSServiceFlags flags,
36 + DNSServiceErrorType errorCode,
37 + const char *replyDomain,
39 + AvahiSDomainBrowser *b = context;
40 + AvahiIfIndex interface;
42 + if (flags & kDNSServiceFlagsDefault)
43 + if (b->flags != AVAHI_DOMAIN_BROWSER_BROWSE_DEFAULT &&
44 + b->flags != AVAHI_DOMAIN_BROWSER_REGISTER_DEFAULT)
47 + interface = (IfIndex == kDNSServiceInterfaceIndexAny) ? AVAHI_IF_UNSPEC : IfIndex;
49 + b->callback(b, interface, AVAHI_PROTO_UNSPEC, AVAHI_BROWSER_NEW, replyDomain, 0 /* flags */, b->userdata);
52 +static void enumerate_error_callback(AvahiTimeEvent *e, void *userdata) {
53 + AvahiSDomainBrowser *b = userdata;
55 + if (b->browse_error_event) {
56 + avahi_time_event_free(b->browse_error_event);
57 + b->browse_error_event = NULL;
59 + avahi_server_set_errno(b->server, AVAHI_ERR_FAILURE);
63 + AVAHI_BROWSER_FAILURE,
69 +static void all_for_now_callback(AvahiTimeEvent *e, void* userdata) {
70 + AvahiSDomainBrowser *b = userdata;
75 + avahi_time_event_free(b->all_for_now_event);
76 + b->all_for_now_event = NULL;
81 + AVAHI_BROWSER_ALL_FOR_NOW,
87 +static void enumerate_socket_event(AvahiWatch *w, int fd, AvahiWatchEvent events, void *userdata) {
88 + AvahiSDomainBrowser *b = userdata;
89 + DNSServiceErrorType ret;
93 + assert(events & AVAHI_WATCH_IN);
95 + assert (fd == DNSServiceRefSockFD(b->client));
96 + ret = DNSServiceProcessResult(b->client);
97 + if (ret != kDNSServiceErr_NoError) {
99 + b->server->poll_api->watch_free(b->watch);
102 + DNSServiceRefDeallocate(b->client);
104 + avahi_server_set_errno(b->server, AVAHI_ERR_DISCONNECTED);
107 + AVAHI_PROTO_UNSPEC,
108 + AVAHI_BROWSER_FAILURE,
115 +static void avahi_browse_domains_start(AvahiSDomainBrowser *b) {
116 + DNSServiceErrorType ret;
117 + DNSServiceFlags flags;
120 + if (b->flags == AVAHI_DOMAIN_BROWSER_BROWSE ||
121 + b->flags == AVAHI_DOMAIN_BROWSER_BROWSE_DEFAULT)
122 + flags = kDNSServiceFlagsBrowseDomains;
123 + else if (b->flags == AVAHI_DOMAIN_BROWSER_REGISTER ||
124 + b->flags == AVAHI_DOMAIN_BROWSER_REGISTER_DEFAULT)
125 + flags = kDNSServiceFlagsRegistrationDomains;
127 + ret = DNSServiceEnumerateDomains(&b->client,
129 + b->interface == AVAHI_IF_UNSPEC ?
130 + kDNSServiceInterfaceIndexAny :
134 + if (ret != kDNSServiceErr_NoError || !b->client) {
135 + b->browse_error_event = avahi_time_event_new(b->server->time_event_queue,
136 +NULL, enumerate_error_callback, b);
138 + b->watch = b->server->poll_api->watch_new(b->server->poll_api, DNSServiceRefSockFD(b->client), AVAHI_WATCH_IN, enumerate_socket_event, b);
141 + gettimeofday(&tv, NULL);
142 + avahi_timeval_add(&tv, 1000000);
143 + b->all_for_now_event = avahi_time_event_new(b->server->time_event_queue, &tv, all_for_now_callback, b);
148 AvahiSDomainBrowser *avahi_s_domain_browser_new(
150 AvahiIfIndex interface,
153 AVAHI_LLIST_PREPEND(AvahiSDomainBrowser, browser, server->domain_browsers, b);
156 + b->interface = interface;
159 + b->browse_error_event = NULL;
160 + b->all_for_now_event = NULL;
162 + avahi_browse_domains_start(b);
164 if (!(k = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR))) {
165 avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
169 if (type == AVAHI_DOMAIN_BROWSER_BROWSE && b->server->config.browse_domains)
170 b->defer_event = avahi_time_event_new(server->time_event_queue, NULL, defer_callback, b);
177 AVAHI_LLIST_REMOVE(AvahiSDomainBrowser, browser, b->server->domain_browsers, b);
180 + if (b->browse_error_event) {
181 + avahi_time_event_free(b->browse_error_event);
182 + b->browse_error_event = NULL;
184 + if (b->all_for_now_event) {
185 + avahi_time_event_free(b->all_for_now_event);
186 + b->all_for_now_event = NULL;
190 + b->server->poll_api->watch_free(b->watch);
193 + DNSServiceRefDeallocate(b->client);
196 if (b->record_browser)
197 avahi_s_record_browser_free(b->record_browser);