1 --- avahi-0.6.28/avahi-core/browse-service.c.orig 2010-08-26 01:51:38.983153000 +0100
2 +++ avahi-0.6.28/avahi-core/browse-service.c 2011-01-20 09:22:41.808471289 +0000
10 #include <avahi-common/domain.h>
11 #include <avahi-common/malloc.h>
13 +#include <avahi-common/timeval.h>
15 #include <avahi-common/error.h>
19 AvahiSServiceBrowserCallback callback;
23 + AvahiProtocol protocol;
24 + AvahiIfIndex interface;
25 + AvahiTimeEvent *browse_error_event;
26 + AvahiTimeEvent *all_for_now_event;
27 + AvahiLookupFlags flags;
29 + DNSServiceRef client;
32 AVAHI_LLIST_FIELDS(AvahiSServiceBrowser, browser);
36 +static void browse_reply(DNSServiceRef client, const DNSServiceFlags flags, uint32_t IfIndex, DNSServiceErrorType errorCode,
37 + const char *name, const char *type, const char *domain, void *context) {
38 + AvahiSServiceBrowser *b = context;
39 + char *op = (flags &kDNSServiceFlagsAdd) ? "Add" : "Rmv";
40 + AvahiBrowserEvent event;
41 + AvahiIfIndex interface;
43 + interface = (IfIndex == kDNSServiceInterfaceIndexAny) ? AVAHI_IF_UNSPEC : IfIndex;
45 + event = (flags &kDNSServiceFlagsAdd) ? AVAHI_BROWSER_NEW : AVAHI_BROWSER_REMOVE;
47 + b->callback(b, interface, AVAHI_PROTO_UNSPEC, event, name, type, domain, 0, b->userdata);
51 +static void browse_socket_event(AvahiWatch *w, int fd, AvahiWatchEvent events, void *userdata) {
52 + AvahiSServiceBrowser *b = userdata;
53 + DNSServiceErrorType ret;
57 + assert(events & AVAHI_WATCH_IN);
59 + assert (fd == DNSServiceRefSockFD(b->client));
60 + ret = DNSServiceProcessResult(b->client);
61 + if (ret != kDNSServiceErr_NoError) {
63 + b->server->poll_api->watch_free(b->watch);
66 + DNSServiceRefDeallocate(b->client);
68 + avahi_server_set_errno(b->server, AVAHI_ERR_DISCONNECTED);
72 + AVAHI_BROWSER_FAILURE,
81 +static void all_for_now_callback(AvahiTimeEvent *e, void* userdata) {
82 + AvahiSServiceBrowser *b = userdata;
87 + avahi_time_event_free(b->all_for_now_event);
88 + b->all_for_now_event = NULL;
93 + AVAHI_BROWSER_ALL_FOR_NOW,
101 +static void browse_error_callback(AvahiTimeEvent *e, void *userdata) {
102 + AvahiSServiceBrowser *b = userdata;
104 + if (b->browse_error_event) {
105 + avahi_time_event_free(b->browse_error_event);
106 + b->browse_error_event = NULL;
108 + avahi_server_set_errno(b->server, AVAHI_ERR_FAILURE);
112 + AVAHI_BROWSER_FAILURE,
120 +static void avahi_browse_service_start(AvahiSServiceBrowser *b) {
121 + DNSServiceErrorType ret;
124 + ret = DNSServiceBrowse(&b->client,
126 + b->interface == AVAHI_IF_UNSPEC ?
127 + kDNSServiceInterfaceIndexAny :
133 + if (ret != kDNSServiceErr_NoError || !b->client) {
134 + b->browse_error_event = avahi_time_event_new(b->server->time_event_queue,
135 +NULL, browse_error_callback, b);
137 + b->watch = b->server->poll_api->watch_new(b->server->poll_api, DNSServiceRefSockFD(b->client), AVAHI_WATCH_IN, browse_socket_event, b);
140 + gettimeofday(&tv, NULL);
141 + avahi_timeval_add(&tv, 1000000);
142 + b->all_for_now_event = avahi_time_event_new(b->server->time_event_queue, &tv, all_for_now_callback, b);
147 static void record_browser_callback(
148 AvahiSRecordBrowser*rr,
149 AvahiIfIndex interface,
151 AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_IF_VALID(interface), AVAHI_ERR_INVALID_INTERFACE);
152 AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_PROTO_VALID(protocol), AVAHI_ERR_INVALID_PROTOCOL);
153 AVAHI_CHECK_VALIDITY_RETURN_NULL(server, !domain || avahi_is_valid_domain_name(domain), AVAHI_ERR_INVALID_DOMAIN_NAME);
155 + AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_FLAGS_VALID(flags, AVAHI_LOOKUP_USE_MULTICAST), AVAHI_ERR_INVALID_FLAGS);
157 AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_FLAGS_VALID(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST), AVAHI_ERR_INVALID_FLAGS);
159 AVAHI_CHECK_VALIDITY_RETURN_NULL(server, avahi_is_valid_service_type_generic(service_type), AVAHI_ERR_INVALID_SERVICE_TYPE);
167 + b->protocol = protocol;
168 + b->interface = interface;
170 + b->browse_error_event = NULL;
171 + b->all_for_now_event = NULL;
174 + avahi_browse_service_start(b);
176 if (!(k = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR))) {
177 avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
189 avahi_free(b->domain_name);
190 avahi_free(b->service_type);
192 + if (b->browse_error_event) {
193 + avahi_time_event_free(b->browse_error_event);
194 + b->browse_error_event = NULL;
196 + if (b->all_for_now_event) {
197 + avahi_time_event_free(b->all_for_now_event);
198 + b->all_for_now_event = NULL;
202 + b->server->poll_api->watch_free(b->watch);
205 + DNSServiceRefDeallocate (b->client);