rust/cargo-c: update to 0.10.7+cargo-0.84.0
[oi-userland.git] / components / network / avahi / patches / 09-resolve-host-name.patch
blob5fcc195d35bb4beb8f703434cd7dce9eef431122
1 --- /usr/tmp/clean/avahi-0.6.28/avahi-core/resolve-host-name.c 2010-08-26 01:51:38.991153000 +0100
2 +++ avahi-0.6.28/avahi-core/resolve-host-name.c 2011-01-20 15:06:17.971781264 +0000
3 @@ -22,6 +22,7 @@
4 #endif
6 #include <stdlib.h>
7 +#include <stdio.h>
9 #include <avahi-common/domain.h>
10 #include <avahi-common/timeval.h>
11 @@ -50,6 +51,15 @@
13 AvahiTimeEvent *time_event;
15 +#ifdef HAVE_BONJOUR
16 + AvahiTimeEvent *defer_time_event;
17 + AvahiWatch *watch_a;
18 + AvahiWatch *watch_a6;
19 + AvahiLookupFlags lookup_flags;
20 + DNSServiceRef client_a;
21 + DNSServiceRef client_a6;
22 +#endif
24 AVAHI_LLIST_FIELDS(AvahiSHostNameResolver, resolver);
27 @@ -86,7 +96,7 @@
28 break;
33 case AVAHI_RESOLVER_FAILURE:
35 r->callback(r, r->interface, r->protocol, event, r->host_name, NULL, r->flags, r->userdata);
36 @@ -94,6 +104,168 @@
40 +#ifdef HAVE_BONJOUR
41 +static void resolve_socket_event(AvahiWatch *w, int fd, AvahiWatchEvent events,
42 +void *userdata) {
43 + AvahiSHostNameResolver *r = userdata;
44 + DNSServiceErrorType ret;
45 + DNSServiceRef client;
47 + assert(w);
48 + assert(fd >= 0);
49 + assert(events & AVAHI_WATCH_IN);
51 + if (fd == DNSServiceRefSockFD(r->client_a))
52 + client = r->client_a;
53 + else if (fd == DNSServiceRefSockFD(r->client_a6))
54 + client = r->client_a6;
55 + else
56 + assert (0);
58 + ret = DNSServiceProcessResult(client);
59 + if (ret != kDNSServiceErr_NoError) {
60 + if (client == r->client_a) {
61 + if (r->watch_a) {
62 + r->server->poll_api->watch_free(r->watch_a);
63 + r->watch_a = NULL;
64 + }
65 + DNSServiceRefDeallocate(r->client_a);
66 + r->client_a = NULL;
67 + } else if (client == r->client_a6) {
68 + if (r->watch_a6) {
69 + r->server->poll_api->watch_free(r->watch_a6);
70 + r->watch_a6 = NULL;
71 + }
72 + DNSServiceRefDeallocate(r->client_a6);
73 + r->client_a6 = NULL;
74 + }
75 + avahi_server_set_errno(r->server, AVAHI_ERR_DISCONNECTED);
76 + finish(r, AVAHI_RESOLVER_FAILURE);
77 + }
80 +static void resolve_reply(DNSServiceRef client, DNSServiceFlags flags, uint32_t IfIndex, DNSServiceErrorType errorCode, const char *fullname, uint16_t rrtype, uint16_t rrclass, uint16_t rdlen, const void* rdata, uint32_t ttl, void *context) {
81 + AvahiSHostNameResolver *r = context;
82 + const unsigned char *rd = rdata;
83 + AvahiAddress a;
85 + assert(rrtype == kDNSServiceType_A || rrtype == kDNSServiceType_AAAA);
86 + if (!flags & kDNSServiceFlagsAdd)
87 + /* this is a remove event so ignore*/
88 + return;
90 + if (r->interface > 0 && IfIndex != r->interface)
91 + return;
92 + if (r->interface <= 0)
93 + r->interface = IfIndex;
95 + /*
96 + * Using Bonjour we cannot determine whether result was obtained from
97 + * multicast ot unicast query
98 + */
99 + r->flags = 0;
101 + switch (rrtype) {
102 + case kDNSServiceType_A:
103 + if (r->protocol == AVAHI_PROTO_UNSPEC)
104 + r->protocol = AVAHI_PROTO_INET;
105 + else if (r->protocol != AVAHI_PROTO_INET)
106 + return;
108 + if (!r->address_record) {
109 + if (!(r->address_record = avahi_record_new_full(r->host_name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_A, ttl))) {
110 + avahi_server_set_errno(r->server, AVAHI_ERR_NO_MEMORY);
111 + finish(r, AVAHI_RESOLVER_FAILURE);
112 + return;
114 + if (avahi_rdata_parse(r->address_record, rdata, rdlen) != 0) {
115 + avahi_server_set_errno(r->server, AVAHI_ERR_INVALID_PACKET);
116 + finish(r, AVAHI_RESOLVER_FAILURE);
119 + break;
120 + case kDNSServiceType_AAAA:
121 + if (r->protocol == AVAHI_PROTO_UNSPEC)
122 + r->protocol = AVAHI_PROTO_INET6;
123 + else if (r->protocol != AVAHI_PROTO_INET6)
124 + return;
125 + if (!r->address_record) {
126 + if (!(r->address_record = avahi_record_new_full(r->host_name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_AAAA, ttl))) {
127 + avahi_server_set_errno(r->server, AVAHI_ERR_NO_MEMORY);
128 + finish(r, AVAHI_RESOLVER_FAILURE);
129 + return;
131 + if (avahi_rdata_parse(r->address_record, rdata, rdlen) != 0) {
132 + avahi_server_set_errno(r->server, AVAHI_ERR_INVALID_PACKET);
133 + finish(r, AVAHI_RESOLVER_FAILURE);
134 + return;
137 + break;
138 + default:
139 + abort();
141 + finish(r, AVAHI_RESOLVER_FOUND);
144 +static void resolve_error_callback(AvahiTimeEvent *e, void *userdata) {
145 + AvahiSHostNameResolver *r = userdata;
147 + if (r->defer_time_event) {
148 + avahi_time_event_free(r->defer_time_event);
149 + r->defer_time_event = NULL;
151 + avahi_server_set_errno(r->server, AVAHI_ERR_FAILURE);
152 + finish(r, AVAHI_RESOLVER_FAILURE);
155 +static void avahi_resolve_host_name_start(AvahiSHostNameResolver *r, AvahiProtocol aprotocol)
157 + DNSServiceErrorType ret;
158 + DNSServiceFlags flags;
160 + if (r->flags == AVAHI_LOOKUP_USE_MULTICAST)
161 + flags = kDNSServiceFlagsForceMulticast;
163 + if (aprotocol == AVAHI_PROTO_INET || aprotocol == AVAHI_PROTO_UNSPEC) {
164 + ret = DNSServiceQueryRecord(&r->client_a,
165 + flags,
166 + r->interface == AVAHI_IF_UNSPEC ?
167 + kDNSServiceInterfaceIndexAny :
168 + r->interface,
169 + r->host_name,
170 + kDNSServiceType_A,
171 + kDNSServiceClass_IN,
172 + resolve_reply,
173 + r);
174 + if (ret != kDNSServiceErr_NoError || !r->client_a) {
175 + r->defer_time_event = avahi_time_event_new(r->server->time_event_queue, NULL, resolve_error_callback, r);
176 + return;
177 + } else {
178 + r->watch_a = r->server->poll_api->watch_new(r->server->poll_api, DNSServiceRefSockFD(r->client_a), AVAHI_WATCH_IN, resolve_socket_event, r);
181 + if (aprotocol == AVAHI_PROTO_INET6 || aprotocol == AVAHI_PROTO_UNSPEC) {
182 + ret = DNSServiceQueryRecord(&r->client_a6,
183 + flags,
184 + r->interface == AVAHI_IF_UNSPEC ?
185 + kDNSServiceInterfaceIndexAny :
186 + r->interface,
187 + r->host_name,
188 + kDNSServiceType_AAAA,
189 + kDNSServiceClass_IN,
190 + resolve_reply,
191 + r);
192 + if (ret != kDNSServiceErr_NoError || !r->client_a6) {
193 + r->defer_time_event = avahi_time_event_new(r->server->time_event_queue, NULL, resolve_error_callback, r);
194 + return;
195 + } else {
196 + r->watch_a6 = r->server->poll_api->watch_new(r->server->poll_api, DNSServiceRefSockFD(r->client_a6), AVAHI_WATCH_IN, resolve_socket_event, r);
200 +#endif
202 static void time_event_callback(AvahiTimeEvent *e, void *userdata) {
203 AvahiSHostNameResolver *r = userdata;
205 @@ -116,6 +288,7 @@
206 r->time_event = avahi_time_event_new(r->server->time_event_queue, &tv, time_event_callback, r);
209 +#ifndef HAVE_BONJOUR
210 static void record_browser_callback(
211 AvahiSRecordBrowser*rr,
212 AvahiIfIndex interface,
213 @@ -200,6 +373,7 @@
214 break;
217 +#endif
219 AvahiSHostNameResolver *avahi_s_host_name_resolver_new(
220 AvahiServer *server,
221 @@ -246,6 +420,15 @@
223 r->record_browser_aaaa = r->record_browser_a = NULL;
225 +#ifdef HAVE_BONJOUR
226 + r->defer_time_event = NULL;
227 + r->watch_a = NULL;
228 + r->watch_a6 = NULL;
229 + r->client_a = NULL;
230 + r->client_a6 = NULL;
231 + r->lookup_flags = flags;
232 + avahi_resolve_host_name_start (r, aprotocol);
233 +#else
234 if (aprotocol == AVAHI_PROTO_INET || aprotocol == AVAHI_PROTO_UNSPEC) {
235 k = avahi_key_new(host_name, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_A);
236 r->record_browser_a = avahi_s_record_browser_new(server, interface, protocol, k, flags, record_browser_callback, r);
237 @@ -265,6 +448,7 @@
240 assert(r->record_browser_aaaa || r->record_browser_a);
241 +#endif
243 start_timeout(r);
245 @@ -291,6 +475,22 @@
247 if (r->address_record)
248 avahi_record_unref(r->address_record);
249 +#ifdef HAVE_BONJOUR
250 + if (r->defer_time_event) {
251 + avahi_time_event_free(r->defer_time_event);
252 + r->defer_time_event = NULL;
255 + if (r->watch_a)
256 + r->server->poll_api->watch_free(r->watch_a);
257 + if (r->watch_a6)
258 + r->server->poll_api->watch_free(r->watch_a6);
260 + if (r->client_a)
261 + DNSServiceRefDeallocate(r->client_a);
262 + if (r->client_a6)
263 + DNSServiceRefDeallocate(r->client_a6);
264 +#endif
266 avahi_free(r->host_name);
267 avahi_free(r);