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
9 #include <avahi-common/timeval.h>
10 #include <avahi-common/malloc.h>
13 AvahiTimeEvent *time_event;
16 + AvahiTimeEvent *defer_time_event;
17 + AvahiLookupFlags lookup_flags;
19 + DNSServiceRef client;
22 AVAHI_LLIST_FIELDS(AvahiSAddressResolver, resolver);
30 +static void resolve_socket_event(AvahiWatch *w, int fd, AvahiWatchEvent events,
32 + AvahiSAddressResolver *r = userdata;
33 + DNSServiceErrorType ret;
37 + assert(events & AVAHI_WATCH_IN);
39 + assert (fd == DNSServiceRefSockFD(r->client));
41 + ret = DNSServiceProcessResult(r->client);
42 + if (ret != kDNSServiceErr_NoError) {
44 + r->server->poll_api->watch_free(r->watch);
47 + DNSServiceRefDeallocate(r->client);
49 + avahi_server_set_errno(r->server, AVAHI_ERR_DISCONNECTED);
50 + finish(r, AVAHI_RESOLVER_FAILURE);
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)
61 + if (r->interface <= 0)
62 + r->interface = IfIndex;
65 + * Using Bonjour we cannot determine whether result was obtained from
66 + * multicast ot unicast query
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);
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);
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;
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;
104 + ret = DNSServiceQueryRecord(&r->client,
106 + r->interface == AVAHI_IF_UNSPEC ?
107 + kDNSServiceInterfaceIndexAny :
110 + kDNSServiceType_PTR,
111 + kDNSServiceClass_IN,
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);
117 + r->watch = r->server->poll_api->watch_new(r->server->poll_api, DNSServiceRefSockFD(r->client), AVAHI_WATCH_IN, resolve_socket_event, r);
123 static void time_event_callback(AvahiTimeEvent *e, void *userdata) {
124 AvahiSAddressResolver *r = userdata;
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,
140 AvahiSAddressResolver *avahi_s_address_resolver_new(
144 r->time_event = NULL;
147 + r->defer_time_event = NULL;
150 + r->lookup_flags = flags;
151 + avahi_resolve_address_start(r);
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))
157 avahi_s_address_resolver_free(r);
166 avahi_key_unref(r->key);
169 + if (r->defer_time_event) {
170 + avahi_time_event_free(r->defer_time_event);
171 + r->defer_time_event = NULL;
175 + r->server->poll_api->watch_free(r->watch);
178 + DNSServiceRefDeallocate(r->client);