rust/cargo-c: update to 0.10.7+cargo-0.84.0
[oi-userland.git] / components / network / avahi / patches / 10-resolve-address.patch
blob07591fb9d5138c1c32adab6f1b980586bb00f4f4
1 --- /usr/tmp/clean/avahi-0.6.28/avahi-core/resolve-address.c 2010-08-26 01:51:38.991153000 +0100
2 +++ avahi-0.6.28/avahi-core/resolve-address.c 2011-01-20 15:17:11.922176647 +0000
3 @@ -22,6 +22,7 @@
4 #endif
6 #include <stdlib.h>
7 +#include <stdio.h>
9 #include <avahi-common/timeval.h>
10 #include <avahi-common/malloc.h>
11 @@ -51,6 +52,13 @@
13 AvahiTimeEvent *time_event;
15 +#ifdef HAVE_BONJOUR
16 + AvahiTimeEvent *defer_time_event;
17 + AvahiLookupFlags lookup_flags;
18 + AvahiWatch *watch;
19 + DNSServiceRef client;
20 +#endif
22 AVAHI_LLIST_FIELDS(AvahiSAddressResolver, resolver);
25 @@ -74,6 +82,100 @@
29 +#ifdef HAVE_BONJOUR
30 +static void resolve_socket_event(AvahiWatch *w, int fd, AvahiWatchEvent events,
31 +void *userdata) {
32 + AvahiSAddressResolver *r = userdata;
33 + DNSServiceErrorType ret;
35 + assert(w);
36 + assert(fd >= 0);
37 + assert(events & AVAHI_WATCH_IN);
39 + assert (fd == DNSServiceRefSockFD(r->client));
41 + ret = DNSServiceProcessResult(r->client);
42 + if (ret != kDNSServiceErr_NoError) {
43 + if (r->watch) {
44 + r->server->poll_api->watch_free(r->watch);
45 + r->watch = NULL;
46 + }
47 + DNSServiceRefDeallocate(r->client);
48 + r->client = NULL;
49 + avahi_server_set_errno(r->server, AVAHI_ERR_DISCONNECTED);
50 + finish(r, AVAHI_RESOLVER_FAILURE);
51 + }
54 +static void resolve_reply(DNSServiceRef client, DNSServiceFlags flags, uint32_t
55 +IfIndex, DNSServiceErrorType errorCode, const char *fullname, uint16_t rrtype, uint16_t rrclass, uint16_t rdlen, const void* rdata, uint32_t ttl, void *context) {
56 + AvahiSAddressResolver *r = context;
58 + assert(rrtype == kDNSServiceType_PTR);
59 + if (r->interface > 0 && IfIndex != r->interface)
60 + return;
61 + if (r->interface <= 0)
62 + r->interface = IfIndex;
64 + /*
65 + * Using Bonjour we cannot determine whether result was obtained from
66 + * multicast ot unicast query
67 + */
68 + r->flags = 0;
70 + if (!(r->ptr_record = avahi_record_new(r->key, ttl))) {
71 + avahi_server_set_errno(r->server, AVAHI_ERR_NO_MEMORY);
72 + finish(r, AVAHI_RESOLVER_FAILURE);
73 + return;
74 + }
75 + if (avahi_rdata_parse(r->ptr_record, rdata, rdlen) != 0) {
76 + avahi_server_set_errno(r->server, AVAHI_ERR_INVALID_PACKET);
77 + finish(r, AVAHI_RESOLVER_FAILURE);
78 + return;
79 + }
80 + finish(r, AVAHI_RESOLVER_FOUND);
83 +static void resolve_error_callback(AvahiTimeEvent *e, void *userdata) {
84 + AvahiSAddressResolver *r = userdata;
86 + if (r->defer_time_event) {
87 + avahi_time_event_free(r->defer_time_event);
88 + r->defer_time_event = NULL;
89 + }
90 + avahi_server_set_errno(r->server, AVAHI_ERR_FAILURE);
91 + finish(r, AVAHI_RESOLVER_FAILURE);
94 +static void avahi_resolve_address_start(AvahiSAddressResolver *r)
96 + DNSServiceErrorType ret;
97 + DNSServiceFlags flags;
99 + if (r->flags != AVAHI_LOOKUP_USE_WIDE_AREA)
100 + flags = kDNSServiceFlagsForceMulticast;
101 + else
102 + flags = 0;
104 + ret = DNSServiceQueryRecord(&r->client,
105 + flags,
106 + r->interface == AVAHI_IF_UNSPEC ?
107 + kDNSServiceInterfaceIndexAny :
108 + r->interface,
109 + r->key->name,
110 + kDNSServiceType_PTR,
111 + kDNSServiceClass_IN,
112 + resolve_reply,
113 + r);
114 + if (ret != kDNSServiceErr_NoError || !r->client) {
115 + r->defer_time_event = avahi_time_event_new(r->server->time_event_queue, NULL, resolve_error_callback, r);
116 + } else {
117 + r->watch = r->server->poll_api->watch_new(r->server->poll_api, DNSServiceRefSockFD(r->client), AVAHI_WATCH_IN, resolve_socket_event, r);
120 +#endif
123 static void time_event_callback(AvahiTimeEvent *e, void *userdata) {
124 AvahiSAddressResolver *r = userdata;
126 @@ -95,6 +197,7 @@
127 r->time_event = avahi_time_event_new(r->server->time_event_queue, &tv, time_event_callback, r);
130 +#ifndef HAVE_BONJOUR
131 static void record_browser_callback(
132 AvahiSRecordBrowser*rr,
133 AvahiIfIndex interface,
134 @@ -173,6 +276,7 @@
135 break;
138 +#endif
140 AvahiSAddressResolver *avahi_s_address_resolver_new(
141 AvahiServer *server,
142 @@ -225,6 +329,13 @@
144 r->time_event = NULL;
146 +#ifdef HAVE_BONJOUR
147 + r->defer_time_event = NULL;
148 + r->watch = NULL;
149 + r->client = NULL;
150 + r->lookup_flags = flags;
151 + avahi_resolve_address_start(r);
152 +#else
153 if (!(flags & (AVAHI_LOOKUP_USE_MULTICAST|AVAHI_LOOKUP_USE_WIDE_AREA))) {
155 if (!server->wide_area_lookup_engine || !avahi_wide_area_has_servers(server->wide_area_lookup_engine))
156 @@ -241,6 +352,7 @@
157 avahi_s_address_resolver_free(r);
158 return NULL;
160 +#endif
162 start_timeout(r);
164 @@ -264,5 +376,18 @@
165 if (r->key)
166 avahi_key_unref(r->key);
168 +#ifdef HAVE_BONJOUR
169 + if (r->defer_time_event) {
170 + avahi_time_event_free(r->defer_time_event);
171 + r->defer_time_event = NULL;
174 + if (r->watch)
175 + r->server->poll_api->watch_free(r->watch);
177 + if (r->client)
178 + DNSServiceRefDeallocate(r->client);
179 +#endif
181 avahi_free(r);