libsoup3: update to 3.6.0; fix GTK2/3 app startup
[oi-userland.git] / components / network / avahi / patches / 11-browse-domain.patch
blob5ecea726270305161f90164b2e1666badb73cdab
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
3 @@ -26,6 +26,9 @@
4 #include <avahi-common/domain.h>
5 #include <avahi-common/malloc.h>
6 #include <avahi-common/error.h>
7 +#ifdef HAVE_BONJOUR
8 +#include <avahi-common/timeval.h>
9 +#endif
11 #include "browse.h"
12 #include "log.h"
13 @@ -45,6 +48,14 @@
15 int all_for_now_scheduled;
17 +#ifdef HAVE_BONJOUR
18 + AvahiIfIndex interface;
19 + AvahiTimeEvent *browse_error_event;
20 + AvahiTimeEvent *all_for_now_event;
21 + AvahiLookupFlags flags;
22 + AvahiWatch *watch;
23 + DNSServiceRef client;
24 +#endif
25 AVAHI_LLIST_FIELDS(AvahiSDomainBrowser, browser);
28 @@ -135,6 +146,122 @@
29 avahi_s_domain_browser_free(b);
32 +#ifdef HAVE_BONJOUR
33 +static void enumerate_reply(DNSServiceRef service,
34 + DNSServiceFlags flags,
35 + uint32_t IfIndex,
36 + DNSServiceErrorType errorCode,
37 + const char *replyDomain,
38 + void *context) {
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)
45 + return;
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;
58 + }
59 + avahi_server_set_errno(b->server, AVAHI_ERR_FAILURE);
60 + b->callback(b,
61 + b->interface,
62 + AVAHI_PROTO_UNSPEC,
63 + AVAHI_BROWSER_FAILURE,
64 + NULL,
65 + 0,
66 + b->userdata);
69 +static void all_for_now_callback(AvahiTimeEvent *e, void* userdata) {
70 + AvahiSDomainBrowser *b = userdata;
72 + assert(e);
73 + assert(b);
75 + avahi_time_event_free(b->all_for_now_event);
76 + b->all_for_now_event = NULL;
78 + b->callback(b,
79 + AVAHI_IF_UNSPEC,
80 + AVAHI_PROTO_UNSPEC,
81 + AVAHI_BROWSER_ALL_FOR_NOW,
82 + NULL,
83 + 0,
84 + b->userdata);
87 +static void enumerate_socket_event(AvahiWatch *w, int fd, AvahiWatchEvent events, void *userdata) {
88 + AvahiSDomainBrowser *b = userdata;
89 + DNSServiceErrorType ret;
91 + assert(w);
92 + assert(fd >= 0);
93 + assert(events & AVAHI_WATCH_IN);
95 + assert (fd == DNSServiceRefSockFD(b->client));
96 + ret = DNSServiceProcessResult(b->client);
97 + if (ret != kDNSServiceErr_NoError) {
98 + if (b->watch) {
99 + b->server->poll_api->watch_free(b->watch);
100 + b->watch = NULL;
102 + DNSServiceRefDeallocate(b->client);
103 + b->client = NULL;
104 + avahi_server_set_errno(b->server, AVAHI_ERR_DISCONNECTED);
105 + b->callback(b,
106 + b->interface,
107 + AVAHI_PROTO_UNSPEC,
108 + AVAHI_BROWSER_FAILURE,
109 + NULL,
110 + 0,
111 + b->userdata);
115 +static void avahi_browse_domains_start(AvahiSDomainBrowser *b) {
116 + DNSServiceErrorType ret;
117 + DNSServiceFlags flags;
118 + struct timeval tv;
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,
128 + flags,
129 + b->interface == AVAHI_IF_UNSPEC ?
130 + kDNSServiceInterfaceIndexAny :
131 + b->interface,
132 + enumerate_reply,
133 + b);
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);
137 + } else {
138 + b->watch = b->server->poll_api->watch_new(b->server->poll_api, DNSServiceRefSockFD(b->client), AVAHI_WATCH_IN, enumerate_socket_event, b);
140 + /* Add a second */
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);
146 +#endif
148 AvahiSDomainBrowser *avahi_s_domain_browser_new(
149 AvahiServer *server,
150 AvahiIfIndex interface,
151 @@ -191,6 +318,15 @@
153 AVAHI_LLIST_PREPEND(AvahiSDomainBrowser, browser, server->domain_browsers, b);
155 +#ifdef HAVE_BONJOUR
156 + b->interface = interface;
157 + b->client = NULL;
158 + b->watch = NULL;
159 + b->browse_error_event = NULL;
160 + b->all_for_now_event = NULL;
161 + b->flags = flags;
162 + avahi_browse_domains_start(b);
163 +#else
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);
166 goto fail;
167 @@ -203,6 +339,7 @@
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);
171 +#endif
173 return b;
175 @@ -225,6 +362,23 @@
177 AVAHI_LLIST_REMOVE(AvahiSDomainBrowser, browser, b->server->domain_browsers, b);
179 +#ifdef HAVE_BONJOUR
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;
189 + if (b->watch)
190 + b->server->poll_api->watch_free(b->watch);
192 + if (b->client)
193 + DNSServiceRefDeallocate(b->client);
194 +#endif
196 if (b->record_browser)
197 avahi_s_record_browser_free(b->record_browser);