From bb14e0a8aa3173c8a6d80b1a9c8b300a452ee9f1 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 12 Oct 2005 02:37:08 +0000 Subject: [PATCH] * drop AVAHI_RESOLVER_TIMEOUT, AVAHI_RESOLVER_NOT_FOUND and AVAHI_BROWSER_NOT_FOUND, use AVAHI_xxx_FAILURE instead * set the client/server errno variable when AVAHI_xxx_FAILURE happens * update DBUS interface accordingly, pass errno value with Failure events * Pass DNS return codes to the app by wrapping them in avahi error codes git-svn-id: file:///home/lennart/svn/public/avahi/trunk@732 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-client/browser.c | 145 +++++++--- avahi-client/client-test.c | 9 +- avahi-client/client.c | 18 -- avahi-client/resolver.c | 305 ++++++++++++--------- avahi-common/dbus.c | 14 +- avahi-common/dbus.h | 12 + avahi-common/defs.h | 9 +- avahi-common/error.c | 18 +- avahi-common/error.h | 18 +- avahi-compat-libdns_sd/compat.c | 19 +- avahi-core/avahi-test.c | 3 - avahi-core/browse-dns-server.c | 3 - avahi-core/browse.c | 4 +- avahi-core/querier-test.c | 1 - avahi-core/resolve-address.c | 14 +- avahi-core/resolve-host-name.c | 8 +- avahi-core/resolve-service.c | 12 +- avahi-core/wide-area.c | 32 ++- avahi-daemon/AddressResolver.introspect | 8 +- avahi-daemon/DomainBrowser.introspect | 6 +- avahi-daemon/HostNameResolver.introspect | 8 +- avahi-daemon/ServiceBrowser.introspect | 7 +- avahi-daemon/ServiceResolver.introspect | 8 +- avahi-daemon/ServiceTypeBrowser.introspect | 6 +- avahi-daemon/dbus-protocol.c | 67 +++-- avahi-daemon/simple-protocol.c | 23 +- avahi-discover-standalone/main.c | 16 +- examples/client-browse-services.c | 8 +- examples/core-browse-services.c | 10 +- 29 files changed, 479 insertions(+), 332 deletions(-) diff --git a/avahi-client/browser.c b/avahi-client/browser.c index a83aa69..bdbd8c5 100644 --- a/avahi-client/browser.c +++ b/avahi-client/browser.c @@ -194,17 +194,42 @@ DBusHandlerResult avahi_domain_browser_event (AvahiClient *client, AvahiBrowserE if (!db) goto fail; - if (event == AVAHI_BROWSER_NEW || event == AVAHI_BROWSER_REMOVE) { - if (!dbus_message_get_args( - message, &error, - DBUS_TYPE_INT32, &interface, - DBUS_TYPE_INT32, &protocol, - DBUS_TYPE_STRING, &domain, - DBUS_TYPE_UINT32, &flags, - DBUS_TYPE_INVALID) || - dbus_error_is_set (&error)) { - fprintf(stderr, "Failed to parse browser event.\n"); - goto fail; + switch (event) { + case AVAHI_BROWSER_NEW: + case AVAHI_BROWSER_REMOVE: + + if (!dbus_message_get_args( + message, &error, + DBUS_TYPE_INT32, &interface, + DBUS_TYPE_INT32, &protocol, + DBUS_TYPE_STRING, &domain, + DBUS_TYPE_UINT32, &flags, + DBUS_TYPE_INVALID) || + dbus_error_is_set (&error)) { + fprintf(stderr, "Failed to parse browser event.\n"); + goto fail; + } + + break; + + case AVAHI_BROWSER_CACHE_EXHAUSTED: + case AVAHI_BROWSER_ALL_FOR_NOW: + break; + + case AVAHI_BROWSER_FAILURE: { + char *etxt; + + if (!dbus_message_get_args( + message, &error, + DBUS_TYPE_STRING, &etxt, + DBUS_TYPE_INVALID) || + dbus_error_is_set (&error)) { + fprintf(stderr, "Failed to parse browser event.\n"); + goto fail; + } + + avahi_client_set_errno(db->client, avahi_error_dbus_to_number(etxt)); + break; } } @@ -369,19 +394,41 @@ DBusHandlerResult avahi_service_type_browser_event (AvahiClient *client, AvahiBr if (!b) goto fail; + switch (event) { + case AVAHI_BROWSER_NEW: + case AVAHI_BROWSER_REMOVE: + if (!dbus_message_get_args( + message, &error, + DBUS_TYPE_INT32, &interface, + DBUS_TYPE_INT32, &protocol, + DBUS_TYPE_STRING, &type, + DBUS_TYPE_STRING, &domain, + DBUS_TYPE_UINT32, &flags, + DBUS_TYPE_INVALID) || + dbus_error_is_set(&error)) { + fprintf(stderr, "Failed to parse browser event.\n"); + goto fail; + } + break; + + case AVAHI_BROWSER_CACHE_EXHAUSTED: + case AVAHI_BROWSER_ALL_FOR_NOW: + break; - if (event == AVAHI_BROWSER_NEW || event == AVAHI_BROWSER_REMOVE) { - if (!dbus_message_get_args( - message, &error, - DBUS_TYPE_INT32, &interface, - DBUS_TYPE_INT32, &protocol, - DBUS_TYPE_STRING, &type, - DBUS_TYPE_STRING, &domain, - DBUS_TYPE_UINT32, &flags, - DBUS_TYPE_INVALID) || - dbus_error_is_set(&error)) { - fprintf(stderr, "Failed to parse browser event.\n"); - goto fail; + case AVAHI_BROWSER_FAILURE: { + char *etxt; + + if (!dbus_message_get_args( + message, &error, + DBUS_TYPE_STRING, &etxt, + DBUS_TYPE_INVALID) || + dbus_error_is_set (&error)) { + fprintf(stderr, "Failed to parse browser event.\n"); + goto fail; + } + + avahi_client_set_errno(b->client, avahi_error_dbus_to_number(etxt)); + break; } } @@ -528,7 +575,7 @@ int avahi_service_browser_free (AvahiServiceBrowser *b) { } -DBusHandlerResult avahi_service_browser_event (AvahiClient *client, AvahiBrowserEvent event, DBusMessage *message) { +DBusHandlerResult avahi_service_browser_event(AvahiClient *client, AvahiBrowserEvent event, DBusMessage *message) { AvahiServiceBrowser *b = NULL; DBusError error; const char *path; @@ -548,19 +595,43 @@ DBusHandlerResult avahi_service_browser_event (AvahiClient *client, AvahiBrowser if (!b) goto fail; - if (event == AVAHI_BROWSER_NEW || event == AVAHI_BROWSER_REMOVE) { - if (!dbus_message_get_args ( - message, &error, - DBUS_TYPE_INT32, &interface, - DBUS_TYPE_INT32, &protocol, - DBUS_TYPE_STRING, &name, - DBUS_TYPE_STRING, &type, - DBUS_TYPE_STRING, &domain, - DBUS_TYPE_UINT32, &flags, - DBUS_TYPE_INVALID) || - dbus_error_is_set(&error)) { - fprintf(stderr, "Failed to parse browser event.\n"); - goto fail; + switch (event) { + case AVAHI_BROWSER_NEW: + case AVAHI_BROWSER_REMOVE: + + if (!dbus_message_get_args ( + message, &error, + DBUS_TYPE_INT32, &interface, + DBUS_TYPE_INT32, &protocol, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_STRING, &type, + DBUS_TYPE_STRING, &domain, + DBUS_TYPE_UINT32, &flags, + DBUS_TYPE_INVALID) || + dbus_error_is_set(&error)) { + fprintf(stderr, "Failed to parse browser event.\n"); + goto fail; + } + break; + + case AVAHI_BROWSER_CACHE_EXHAUSTED: + case AVAHI_BROWSER_ALL_FOR_NOW: + break; + + case AVAHI_BROWSER_FAILURE: { + char *etxt; + + if (!dbus_message_get_args( + message, &error, + DBUS_TYPE_STRING, &etxt, + DBUS_TYPE_INVALID) || + dbus_error_is_set (&error)) { + fprintf(stderr, "Failed to parse browser event.\n"); + goto fail; + } + + avahi_client_set_errno(b->client, avahi_error_dbus_to_number(etxt)); + break; } } diff --git a/avahi-client/client-test.c b/avahi-client/client-test.c index 15af93f..c7789ba 100644 --- a/avahi-client/client-test.c +++ b/avahi-client/client-test.c @@ -71,8 +71,7 @@ static void avahi_service_resolver_callback( char addr[64]; char *txtr; - if (event == AVAHI_RESOLVER_TIMEOUT) - { + if (event == AVAHI_RESOLVER_FAILURE) { printf ("SERVICE-RESOLVER: ServiceResolver %p timed out (%s %s)\n", (void*) r, name, type); return; } @@ -129,8 +128,7 @@ static void avahi_address_resolver_callback ( void *userdata) { char addr[64]; - if (event == AVAHI_RESOLVER_TIMEOUT) - { + if (event == AVAHI_RESOLVER_FAILURE) { printf ("ADDRESS-RESOLVER: Callback on AddressResolver, timed out.\n"); return; } @@ -152,8 +150,7 @@ static void avahi_host_name_resolver_callback ( AvahiAddressResolver *ar; char addr[64]; - if (event == AVAHI_RESOLVER_TIMEOUT) - { + if (event == AVAHI_RESOLVER_FAILURE) { printf ("HOST-NAME-RESOLVER: Callback on HostNameResolver, timed out.\n"); return; } diff --git a/avahi-client/client.c b/avahi-client/client.c index be52cc9..8b0d957 100644 --- a/avahi-client/client.c +++ b/avahi-client/client.c @@ -178,8 +178,6 @@ static DBusHandlerResult filter_func(DBusConnection *bus, DBusMessage *message, return avahi_domain_browser_event(client, AVAHI_BROWSER_CACHE_EXHAUSTED, message); else if (dbus_message_is_signal (message, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, "AllForNow")) return avahi_domain_browser_event(client, AVAHI_BROWSER_ALL_FOR_NOW, message); - else if (dbus_message_is_signal (message, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, "NotFound")) - return avahi_domain_browser_event(client, AVAHI_BROWSER_NOT_FOUND, message); else if (dbus_message_is_signal (message, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, "Failure")) return avahi_domain_browser_event(client, AVAHI_BROWSER_FAILURE, message); @@ -191,8 +189,6 @@ static DBusHandlerResult filter_func(DBusConnection *bus, DBusMessage *message, return avahi_service_type_browser_event (client, AVAHI_BROWSER_CACHE_EXHAUSTED, message); else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "AllForNow")) return avahi_service_type_browser_event (client, AVAHI_BROWSER_ALL_FOR_NOW, message); - else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "NotFound")) - return avahi_service_type_browser_event (client, AVAHI_BROWSER_NOT_FOUND, message); else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "Failure")) return avahi_service_type_browser_event (client, AVAHI_BROWSER_FAILURE, message); @@ -204,35 +200,21 @@ static DBusHandlerResult filter_func(DBusConnection *bus, DBusMessage *message, return avahi_service_browser_event (client, AVAHI_BROWSER_CACHE_EXHAUSTED, message); else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_BROWSER, "AllForNow")) return avahi_service_browser_event (client, AVAHI_BROWSER_ALL_FOR_NOW, message); - else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_BROWSER, "NotFound")) - return avahi_service_browser_event (client, AVAHI_BROWSER_NOT_FOUND, message); else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_BROWSER, "Failure")) return avahi_service_browser_event (client, AVAHI_BROWSER_FAILURE, message); else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_RESOLVER, "Found")) return avahi_service_resolver_event (client, AVAHI_RESOLVER_FOUND, message); - else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_RESOLVER, "Timeout")) - return avahi_service_resolver_event (client, AVAHI_RESOLVER_TIMEOUT, message); - else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_RESOLVER, "NotFound")) - return avahi_service_resolver_event (client, AVAHI_RESOLVER_NOT_FOUND, message); else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_SERVICE_RESOLVER, "Failure")) return avahi_service_resolver_event (client, AVAHI_RESOLVER_FAILURE, message); else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_HOST_NAME_RESOLVER, "Found")) return avahi_host_name_resolver_event (client, AVAHI_RESOLVER_FOUND, message); - else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_HOST_NAME_RESOLVER, "Timeout")) - return avahi_host_name_resolver_event (client, AVAHI_RESOLVER_TIMEOUT, message); - else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_HOST_NAME_RESOLVER, "NotFound")) - return avahi_host_name_resolver_event (client, AVAHI_RESOLVER_NOT_FOUND, message); else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_HOST_NAME_RESOLVER, "Failure")) return avahi_host_name_resolver_event (client, AVAHI_RESOLVER_FAILURE, message); else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_ADDRESS_RESOLVER, "Found")) return avahi_address_resolver_event (client, AVAHI_RESOLVER_FOUND, message); - else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_ADDRESS_RESOLVER, "Timeout")) - return avahi_address_resolver_event (client, AVAHI_RESOLVER_TIMEOUT, message); - else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_ADDRESS_RESOLVER, "NotFound")) - return avahi_address_resolver_event (client, AVAHI_RESOLVER_NOT_FOUND, message); else if (dbus_message_is_signal(message, AVAHI_DBUS_INTERFACE_ADDRESS_RESOLVER, "Failure")) return avahi_address_resolver_event (client, AVAHI_RESOLVER_FAILURE, message); diff --git a/avahi-client/resolver.c b/avahi-client/resolver.c index 494d3cc..889088f 100644 --- a/avahi-client/resolver.c +++ b/avahi-client/resolver.c @@ -61,95 +61,113 @@ DBusHandlerResult avahi_service_resolver_event (AvahiClient *client, AvahiResolv if (!r) goto fail; - if (event == AVAHI_RESOLVER_FOUND) { - int j; - int32_t interface, protocol, aprotocol; - uint32_t flags; - char *name, *type, *domain, *host, *address; - uint16_t port; - DBusMessageIter iter, sub; - AvahiAddress a; - - if (!dbus_message_get_args( - message, &error, - DBUS_TYPE_INT32, &interface, - DBUS_TYPE_INT32, &protocol, - DBUS_TYPE_STRING, &name, - DBUS_TYPE_STRING, &type, - DBUS_TYPE_STRING, &domain, - DBUS_TYPE_STRING, &host, - DBUS_TYPE_INT32, &aprotocol, - DBUS_TYPE_STRING, &address, - DBUS_TYPE_UINT16, &port, - DBUS_TYPE_INVALID) || - dbus_error_is_set (&error)) { + switch (event) { + case AVAHI_RESOLVER_FOUND: { + int j; + int32_t interface, protocol, aprotocol; + uint32_t flags; + char *name, *type, *domain, *host, *address; + uint16_t port; + DBusMessageIter iter, sub; + AvahiAddress a; - fprintf(stderr, "Failed to parse resolver event.\n"); - goto fail; - } + if (!dbus_message_get_args( + message, &error, + DBUS_TYPE_INT32, &interface, + DBUS_TYPE_INT32, &protocol, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_STRING, &type, + DBUS_TYPE_STRING, &domain, + DBUS_TYPE_STRING, &host, + DBUS_TYPE_INT32, &aprotocol, + DBUS_TYPE_STRING, &address, + DBUS_TYPE_UINT16, &port, + DBUS_TYPE_INVALID) || + dbus_error_is_set (&error)) { + + fprintf(stderr, "Failed to parse resolver event.\n"); + goto fail; + } - dbus_message_iter_init(message, &iter); + dbus_message_iter_init(message, &iter); - for (j = 0; j < 9; j++) - dbus_message_iter_next(&iter); + for (j = 0; j < 9; j++) + dbus_message_iter_next(&iter); - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY || - dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_ARRAY) { - fprintf(stderr, "Error parsing service resolving message\n"); - goto fail; - } + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY || + dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_ARRAY) { + fprintf(stderr, "Error parsing service resolving message\n"); + goto fail; + } - strlst = NULL; - dbus_message_iter_recurse(&iter, &sub); + strlst = NULL; + dbus_message_iter_recurse(&iter, &sub); - for (;;) { - DBusMessageIter sub2; - int at; + for (;;) { + DBusMessageIter sub2; + int at; - if ((at = dbus_message_iter_get_arg_type(&sub)) == DBUS_TYPE_INVALID) - break; + if ((at = dbus_message_iter_get_arg_type(&sub)) == DBUS_TYPE_INVALID) + break; - assert(at == DBUS_TYPE_ARRAY); + assert(at == DBUS_TYPE_ARRAY); - if (dbus_message_iter_get_element_type(&sub) != DBUS_TYPE_BYTE) { - fprintf(stderr, "Error parsing service resolving message\n"); - goto fail; - } + if (dbus_message_iter_get_element_type(&sub) != DBUS_TYPE_BYTE) { + fprintf(stderr, "Error parsing service resolving message\n"); + goto fail; + } - dbus_message_iter_recurse(&sub, &sub2); + dbus_message_iter_recurse(&sub, &sub2); - if (dbus_message_iter_get_array_len(&sub2) > 0) { - uint8_t *k; - int n; + if (dbus_message_iter_get_array_len(&sub2) > 0) { + uint8_t *k; + int n; - dbus_message_iter_get_fixed_array(&sub2, &k, &n); - strlst = avahi_string_list_add_arbitrary(strlst, k, n); - } + dbus_message_iter_get_fixed_array(&sub2, &k, &n); + strlst = avahi_string_list_add_arbitrary(strlst, k, n); + } - dbus_message_iter_next(&sub); - } + dbus_message_iter_next(&sub); + } - dbus_message_iter_next(&iter); + dbus_message_iter_next(&iter); - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32) { - fprintf(stderr, "Failed to parse resolver event.\n"); - goto fail; - } + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32) { + fprintf(stderr, "Failed to parse resolver event.\n"); + goto fail; + } - dbus_message_iter_get_basic(&iter, &flags); + dbus_message_iter_get_basic(&iter, &flags); - assert(address); - if (!avahi_address_parse(address, (AvahiProtocol) aprotocol, &a)) { - fprintf(stderr, "Failed to parse address\n"); - goto fail; - } + assert(address); + if (!avahi_address_parse(address, (AvahiProtocol) aprotocol, &a)) { + fprintf(stderr, "Failed to parse address\n"); + goto fail; + } - r->callback(r, (AvahiIfIndex) interface, (AvahiProtocol) protocol, AVAHI_RESOLVER_FOUND, name, type, domain, host, &a, port, strlst, (AvahiLookupResultFlags) flags, r->userdata); + r->callback(r, (AvahiIfIndex) interface, (AvahiProtocol) protocol, AVAHI_RESOLVER_FOUND, name, type, domain, host, &a, port, strlst, (AvahiLookupResultFlags) flags, r->userdata); - avahi_string_list_free(strlst); - - } else - r->callback(r, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, event, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, r->userdata); + avahi_string_list_free(strlst); + break; + } + + case AVAHI_RESOLVER_FAILURE: { + char *etxt; + + if (!dbus_message_get_args( + message, &error, + DBUS_TYPE_STRING, &etxt, + DBUS_TYPE_INVALID) || + dbus_error_is_set (&error)) { + fprintf(stderr, "Failed to parse resolver event.\n"); + goto fail; + } + + avahi_client_set_errno(r->client, avahi_error_dbus_to_number(etxt)); + r->callback(r, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, event, NULL, NULL, NULL, NULL, NULL, 0, NULL, 0, r->userdata); + break; + } + } return DBUS_HANDLER_RESULT_HANDLED; @@ -324,36 +342,54 @@ DBusHandlerResult avahi_host_name_resolver_event (AvahiClient *client, AvahiReso if (!r) goto fail; - if (event == AVAHI_RESOLVER_FOUND) { - int32_t interface, protocol, aprotocol; - uint32_t flags; - char *name, *address; - AvahiAddress a; - - if (!dbus_message_get_args( - message, &error, - DBUS_TYPE_INT32, &interface, - DBUS_TYPE_INT32, &protocol, - DBUS_TYPE_STRING, &name, - DBUS_TYPE_INT32, &aprotocol, - DBUS_TYPE_STRING, &address, - DBUS_TYPE_UINT32, &flags, - DBUS_TYPE_INVALID) || - dbus_error_is_set (&error)) { - fprintf(stderr, "Failed to parse resolver event.\n"); - goto fail; + switch (event) { + case AVAHI_RESOLVER_FOUND: { + int32_t interface, protocol, aprotocol; + uint32_t flags; + char *name, *address; + AvahiAddress a; + + if (!dbus_message_get_args( + message, &error, + DBUS_TYPE_INT32, &interface, + DBUS_TYPE_INT32, &protocol, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_INT32, &aprotocol, + DBUS_TYPE_STRING, &address, + DBUS_TYPE_UINT32, &flags, + DBUS_TYPE_INVALID) || + dbus_error_is_set (&error)) { + fprintf(stderr, "Failed to parse resolver event.\n"); + goto fail; + } + + assert(address); + if (!avahi_address_parse(address, (AvahiProtocol) aprotocol, &a)) { + fprintf(stderr, "Failed to parse address\n"); + goto fail; + } + + r->callback(r, (AvahiIfIndex) interface, (AvahiProtocol) protocol, AVAHI_RESOLVER_FOUND, name, &a, (AvahiLookupResultFlags) flags, r->userdata); + break; } - - assert(address); - if (!avahi_address_parse(address, (AvahiProtocol) aprotocol, &a)) { - fprintf(stderr, "Failed to parse address\n"); - goto fail; + + case AVAHI_RESOLVER_FAILURE: { + char *etxt; + + if (!dbus_message_get_args( + message, &error, + DBUS_TYPE_STRING, &etxt, + DBUS_TYPE_INVALID) || + dbus_error_is_set (&error)) { + fprintf(stderr, "Failed to parse resolver event.\n"); + goto fail; + } + + avahi_client_set_errno(r->client, avahi_error_dbus_to_number(etxt)); + r->callback(r, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, event, NULL, NULL, 0, r->userdata); + break; } - - r->callback(r, (AvahiIfIndex) interface, (AvahiProtocol) protocol, AVAHI_RESOLVER_FOUND, name, &a, (AvahiLookupResultFlags) flags, r->userdata); - - } else - r->callback(r, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, event, NULL, NULL, 0, r->userdata); + } return DBUS_HANDLER_RESULT_HANDLED; @@ -516,35 +552,54 @@ DBusHandlerResult avahi_address_resolver_event (AvahiClient *client, AvahiResolv if (!r) goto fail; - if (event == AVAHI_RESOLVER_FOUND) { - int32_t interface, protocol, aprotocol; - uint32_t flags; - char *name, *address; - AvahiAddress a; - - if (!dbus_message_get_args( - message, &error, - DBUS_TYPE_INT32, &interface, - DBUS_TYPE_INT32, &protocol, - DBUS_TYPE_INT32, &aprotocol, - DBUS_TYPE_STRING, &address, - DBUS_TYPE_STRING, &name, - DBUS_TYPE_UINT32, &flags, - DBUS_TYPE_INVALID) || - dbus_error_is_set (&error)) { - fprintf(stderr, "Failed to parse resolver event.\n"); - goto fail; + switch (event) { + case AVAHI_RESOLVER_FOUND: { + int32_t interface, protocol, aprotocol; + uint32_t flags; + char *name, *address; + AvahiAddress a; + + if (!dbus_message_get_args( + message, &error, + DBUS_TYPE_INT32, &interface, + DBUS_TYPE_INT32, &protocol, + DBUS_TYPE_INT32, &aprotocol, + DBUS_TYPE_STRING, &address, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_UINT32, &flags, + DBUS_TYPE_INVALID) || + dbus_error_is_set (&error)) { + fprintf(stderr, "Failed to parse resolver event.\n"); + goto fail; + } + + assert(address); + if (!avahi_address_parse(address, (AvahiProtocol) aprotocol, &a)) { + fprintf(stderr, "Failed to parse address\n"); + goto fail; + } + + r->callback(r, (AvahiIfIndex) interface, (AvahiProtocol) protocol, AVAHI_RESOLVER_FOUND, (AvahiProtocol) aprotocol, &a, name, (AvahiLookupResultFlags) flags, r->userdata); + break; } - - assert(address); - if (!avahi_address_parse(address, (AvahiProtocol) aprotocol, &a)) { - fprintf(stderr, "Failed to parse address\n"); - goto fail; + + case AVAHI_RESOLVER_FAILURE: { + char *etxt; + + if (!dbus_message_get_args( + message, &error, + DBUS_TYPE_STRING, &etxt, + DBUS_TYPE_INVALID) || + dbus_error_is_set (&error)) { + fprintf(stderr, "Failed to parse resolver event.\n"); + goto fail; + } + + avahi_client_set_errno(r->client, avahi_error_dbus_to_number(etxt)); + r->callback(r, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, event, AVAHI_PROTO_UNSPEC, NULL, NULL, 0, r->userdata); + break; } - - r->callback(r, (AvahiIfIndex) interface, (AvahiProtocol) protocol, AVAHI_RESOLVER_FOUND, (AvahiProtocol) aprotocol, &a, name, (AvahiLookupResultFlags) flags, r->userdata); - } else - r->callback(r, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, event, AVAHI_PROTO_UNSPEC, NULL, NULL, 0, r->userdata); + } return DBUS_HANDLER_RESULT_HANDLED; diff --git a/avahi-common/dbus.c b/avahi-common/dbus.c index d658868..179b1ed 100644 --- a/avahi-common/dbus.c +++ b/avahi-common/dbus.c @@ -64,7 +64,19 @@ static const char * const table[- AVAHI_ERR_MAX] = { AVAHI_DBUS_ERR_NOT_FOUND, AVAHI_DBUS_ERR_INVALID_CONFIG, AVAHI_DBUS_ERR_VERSION_MISMATCH, - AVAHI_DBUS_ERR_INVALID_SERVICE_SUBTYPE + AVAHI_DBUS_ERR_INVALID_SERVICE_SUBTYPE, + AVAHI_DBUS_ERR_INVALID_PACKET, + AVAHI_DBUS_ERR_INVALID_DNS_ERROR, + AVAHI_DBUS_ERR_DNS_FORMERR, + AVAHI_DBUS_ERR_DNS_SERVFAIL, + AVAHI_DBUS_ERR_DNS_NXDOMAIN, + AVAHI_DBUS_ERR_DNS_NOTIMP, + AVAHI_DBUS_ERR_DNS_REFUSED, + AVAHI_DBUS_ERR_DNS_YXDOMAIN, + AVAHI_DBUS_ERR_DNS_YXRRSET, + AVAHI_DBUS_ERR_DNS_NXRRSET, + AVAHI_DBUS_ERR_DNS_NOTAUTH, + AVAHI_DBUS_ERR_DNS_NOTZONE, }; int avahi_error_dbus_to_number(const char *s) { diff --git a/avahi-common/dbus.h b/avahi-common/dbus.h index cb7ba19..9806f58 100644 --- a/avahi-common/dbus.h +++ b/avahi-common/dbus.h @@ -75,6 +75,18 @@ AVAHI_C_DECL_BEGIN #define AVAHI_DBUS_ERR_INVALID_CONFIG "org.freedesktop.Avahi.InvalidConfigurationError" #define AVAHI_DBUS_ERR_VERSION_MISMATCH "org.freedesktop.Avahi.VersionMismatchError" #define AVAHI_DBUS_ERR_INVALID_SERVICE_SUBTYPE "org.freedesktop.Avahi.InvalidServiceSubtypeError" +#define AVAHI_DBUS_ERR_INVALID_PACKET "org.freedesktop.Avahi.InvalidPacketError" +#define AVAHI_DBUS_ERR_INVALID_DNS_ERROR "org.freedesktop.Avahi.InvalidDNSError" +#define AVAHI_DBUS_ERR_DNS_FORMERR "org.freedesktop.Avahi.DNSFORMERR" +#define AVAHI_DBUS_ERR_DNS_SERVFAIL "org.freedesktop.Avahi.DNSSERVFAIL" +#define AVAHI_DBUS_ERR_DNS_NXDOMAIN "org.freedesktop.Avahi.DNSNXDOMAIN" +#define AVAHI_DBUS_ERR_DNS_NOTIMP "org.freedesktop.Avahi.DNSNOTIMP" +#define AVAHI_DBUS_ERR_DNS_REFUSED "org.freedesktop.Avahi.DNSREFUSED" +#define AVAHI_DBUS_ERR_DNS_YXDOMAIN "org.freedesktop.Avahi.DNSYXDOMAIN" +#define AVAHI_DBUS_ERR_DNS_YXRRSET "org.freedesktop.Avahi.DNSYXRRSET" +#define AVAHI_DBUS_ERR_DNS_NXRRSET "org.freedesktop.Avahi.DNSNXRRSET" +#define AVAHI_DBUS_ERR_DNS_NOTAUTH "org.freedesktop.Avahi.DNSNOTAUTH" +#define AVAHI_DBUS_ERR_DNS_NOTZONE "org.freedesktop.Avahi.DNSNOTZONE" /** Convert a DBus error string into an Avahi error number */ int avahi_error_dbus_to_number(const char *s); diff --git a/avahi-common/defs.h b/avahi-common/defs.h index be8022e..4d9c40f 100644 --- a/avahi-common/defs.h +++ b/avahi-common/defs.h @@ -139,7 +139,7 @@ typedef enum { AVAHI_ENTRY_GROUP_UNCOMMITED, /**< The group has not yet been commited, the user must still call avahi_entry_group_commit() */ AVAHI_ENTRY_GROUP_REGISTERING, /**< The entries of the group are currently being registered */ AVAHI_ENTRY_GROUP_ESTABLISHED, /**< The entries have successfully been established */ - AVAHI_ENTRY_GROUP_COLLISION /**< A name collision for one of the entries in the group has been detected, the entries have been withdrawn */ + AVAHI_ENTRY_GROUP_COLLISION, /**< A name collision for one of the entries in the group has been detected, the entries have been withdrawn */ } AvahiEntryGroupState; /** The type of domain to browse for */ @@ -187,16 +187,13 @@ typedef enum { AVAHI_BROWSER_REMOVE, /**< The object has been removed from the network */ AVAHI_BROWSER_CACHE_EXHAUSTED, /**< One-time event, to notify the user that all entries from the caches have been send */ AVAHI_BROWSER_ALL_FOR_NOW, /**< One-time event, to notify the user that more records will probably not show up in the near future, i.e. all cache entries have been read and all static servers been queried */ - AVAHI_BROWSER_NOT_FOUND, /**< Issued when using wide area DNS-SD to inform that a record is not existing */ - AVAHI_BROWSER_FAILURE /**< Issued when using wide area DNS-SD to inform about server failures */ + AVAHI_BROWSER_FAILURE /**< Browsing failed due to some reason which can be retrieved using avahi_server_errno()/avahi_client_errno() */ } AvahiBrowserEvent; /** Type of callback event when resolving */ typedef enum { AVAHI_RESOLVER_FOUND, /**< RR found, resolving successful */ - AVAHI_RESOLVER_TIMEOUT, /**< Noone responded within the timeout, resolving failed */ - AVAHI_RESOLVER_NOT_FOUND, /**< Query was done using wide area DNS-SD and the server told us that the entry is nto available */ - AVAHI_RESOLVER_FAILURE /**< Query was done using wide area DNS-SD and the server failed */ + AVAHI_RESOLVER_FAILURE /**< Resolving failed due to some reason which can be retrieved using avahi_server_errno()/avahi_client_errno() */ } AvahiResolverEvent; /** States of a server object */ diff --git a/avahi-common/error.c b/avahi-common/error.c index 76a05fd..af10422 100644 --- a/avahi-common/error.c +++ b/avahi-common/error.c @@ -38,6 +38,7 @@ const char *avahi_strerror(int error) { "Resource record key is pattern", "Local name collision", "Invalid record", + "Invalid service name", "Invalid service type", "Invalid port number", @@ -48,6 +49,7 @@ const char *avahi_strerror(int error) { "Too many objects", "Too many entries", "OS Error", + "Access denied", "Invalid operation", "An unexpected DBUS error occured", @@ -58,10 +60,24 @@ const char *avahi_strerror(int error) { "Invalid interface index", "Invalid protocol specification", "Invalid flags", + "Not found", "Invalid configuration", "Version mismatch", - "Invalid service subtype" + "Invalid service subtype", + "Invalid packet", + "Invalid DNS return code", + "DNS failure: FORMERR", + "DNS failure: SERVFAIL", + "DNS failure: NXDOMAIN", + "DNS failure: NOTIMP", + + "DNS failure: REFUSED", + "DNS failure: YXDOMAIN", + "DNS failure: YXRRSET", + "DNS failure: NXRRSET", + "DNS failure: NOTAUTH", + "DNS failure: NOTZONE" }; if (-error < 0 || -error >= -AVAHI_ERR_MAX) diff --git a/avahi-common/error.h b/avahi-common/error.h index 623620a..55c388b 100644 --- a/avahi-common/error.h +++ b/avahi-common/error.h @@ -42,6 +42,7 @@ enum { AVAHI_ERR_IS_PATTERN = -7, /**< RR key is pattern */ AVAHI_ERR_LOCAL_COLLISION = -8, /**< Local name collision */ AVAHI_ERR_INVALID_RECORD = -9, /**< Invalid RR */ + AVAHI_ERR_INVALID_SERVICE_NAME = -10, /**< Invalid service name */ AVAHI_ERR_INVALID_SERVICE_TYPE = -11, /**< Invalid service type */ AVAHI_ERR_INVALID_PORT = -12, /**< Invalid port number */ @@ -52,6 +53,7 @@ enum { AVAHI_ERR_TOO_MANY_OBJECTS = -17, /**< Too many objects */ AVAHI_ERR_TOO_MANY_ENTRIES = -18, /**< Too many entries */ AVAHI_ERR_OS = -19, /**< OS error */ + AVAHI_ERR_ACCESS_DENIED = -20, /**< Access denied */ AVAHI_ERR_INVALID_OPERATION = -21, /**< Invalid operation */ AVAHI_ERR_DBUS_ERROR = -22, /**< An unexpected DBUS error occured */ @@ -62,11 +64,25 @@ enum { AVAHI_ERR_INVALID_INTERFACE = -27, /**< Invalid interface */ AVAHI_ERR_INVALID_PROTOCOL = -28, /**< Invalid protocol */ AVAHI_ERR_INVALID_FLAGS = -29, /**< Invalid flags */ + AVAHI_ERR_NOT_FOUND = -30, /**< Not found */ AVAHI_ERR_INVALID_CONFIG = -31, /**< Configuration error */ AVAHI_ERR_VERSION_MISMATCH = -32, /**< Verson mismatch */ AVAHI_ERR_INVALID_SERVICE_SUBTYPE = -33, /**< Invalid service subtype */ + AVAHI_ERR_INVALID_PACKET = -34, /**< Invalid packet */ + AVAHI_ERR_INVALID_DNS_ERROR = -35, /**< Invlaid DNS return code */ + AVAHI_ERR_DNS_FORMERR = -36, + AVAHI_ERR_DNS_SERVFAIL = -37, + AVAHI_ERR_DNS_NXDOMAIN = -38, + AVAHI_ERR_DNS_NOTIMP = -39, + AVAHI_ERR_DNS_REFUSED = -40, + AVAHI_ERR_DNS_YXDOMAIN = -41, + AVAHI_ERR_DNS_YXRRSET = -42, + AVAHI_ERR_DNS_NXRRSET = -43, + AVAHI_ERR_DNS_NOTAUTH = -44, + AVAHI_ERR_DNS_NOTZONE = -45, + /**** **** IF YOU ADD A NEW ERROR CODE HERE, PLEASE DON'T FORGET TO ADD **** IT TO THE STRING ARRAY IN avahi_strerror() IN error.c AND @@ -75,7 +91,7 @@ enum { **** Also remember to update the MAX value below. ****/ - AVAHI_ERR_MAX = -34 + AVAHI_ERR_MAX = -46 }; /** Return a human readable error string for the specified error code */ diff --git a/avahi-compat-libdns_sd/compat.c b/avahi-compat-libdns_sd/compat.c index 02c04ee..fda5b59 100644 --- a/avahi-compat-libdns_sd/compat.c +++ b/avahi-compat-libdns_sd/compat.c @@ -448,11 +448,7 @@ static void service_browser_callback( break; case AVAHI_BROWSER_FAILURE: - sdref->service_browser_callback(sdref, 0, interface, kDNSServiceErr_Unknown, NULL, NULL, NULL, sdref->context); - break; - - case AVAHI_BROWSER_NOT_FOUND: - sdref->service_browser_callback(sdref, 0, interface, kDNSServiceErr_NoSuchName, NULL, NULL, NULL, sdref->context); + sdref->service_browser_callback(sdref, 0, interface, map_error(avahi_client_errno(sdref->client)), NULL, NULL, NULL, sdref->context); break; case AVAHI_BROWSER_CACHE_EXHAUSTED: @@ -594,13 +590,8 @@ static void service_resolver_callback( break; } - case AVAHI_RESOLVER_TIMEOUT: - case AVAHI_RESOLVER_NOT_FOUND: - sdref->service_resolver_callback(sdref, 0, interface, kDNSServiceErr_NoSuchName, NULL, NULL, 0, 0, NULL, sdref->context); - break; - case AVAHI_RESOLVER_FAILURE: - sdref->service_resolver_callback(sdref, 0, interface, kDNSServiceErr_Unknown, NULL, NULL, 0, 0, NULL, sdref->context); + sdref->service_resolver_callback(sdref, 0, interface, map_error(avahi_client_errno(sdref->client)), NULL, NULL, 0, 0, NULL, sdref->context); } } @@ -713,11 +704,7 @@ static void domain_browser_callback( break; case AVAHI_BROWSER_FAILURE: - sdref->domain_browser_callback(sdref, 0, interface, kDNSServiceErr_Unknown, domain, sdref->context); - break; - - case AVAHI_BROWSER_NOT_FOUND: - sdref->domain_browser_callback(sdref, 0, interface, kDNSServiceErr_NoSuchName, domain, sdref->context); + sdref->domain_browser_callback(sdref, 0, interface, map_error(avahi_client_errno(sdref->client)), domain, sdref->context); break; case AVAHI_BROWSER_CACHE_EXHAUSTED: diff --git a/avahi-core/avahi-test.c b/avahi-core/avahi-test.c index 7ed5991..46e68d5 100644 --- a/avahi-core/avahi-test.c +++ b/avahi-core/avahi-test.c @@ -71,7 +71,6 @@ static const char *browser_event_to_string(AvahiBrowserEvent event) { case AVAHI_BROWSER_CACHE_EXHAUSTED : return "CACHE_EXHAUSTED"; case AVAHI_BROWSER_ALL_FOR_NOW : return "ALL_FOR_NOW"; case AVAHI_BROWSER_FAILURE : return "FAILURE"; - case AVAHI_BROWSER_NOT_FOUND : return "NOT_FOUND"; } abort(); @@ -80,8 +79,6 @@ static const char *browser_event_to_string(AvahiBrowserEvent event) { static const char *resolver_event_to_string(AvahiResolverEvent event) { switch (event) { case AVAHI_RESOLVER_FOUND: return "FOUND"; - case AVAHI_RESOLVER_TIMEOUT: return "TIMEOUT"; - case AVAHI_RESOLVER_NOT_FOUND: return "NOT_FOUND"; case AVAHI_RESOLVER_FAILURE: return "FAILURE"; } abort(); diff --git a/avahi-core/browse-dns-server.c b/avahi-core/browse-dns-server.c index 52dafc2..2c907c3 100644 --- a/avahi-core/browse-dns-server.c +++ b/avahi-core/browse-dns-server.c @@ -128,9 +128,7 @@ static void host_name_resolver_callback( break; } - case AVAHI_RESOLVER_NOT_FOUND: case AVAHI_RESOLVER_FAILURE: - case AVAHI_RESOLVER_TIMEOUT: /* Ignore */ break; } @@ -215,7 +213,6 @@ static void record_browser_callback( } case AVAHI_BROWSER_FAILURE: - case AVAHI_BROWSER_NOT_FOUND: case AVAHI_BROWSER_ALL_FOR_NOW: case AVAHI_BROWSER_CACHE_EXHAUSTED: diff --git a/avahi-core/browse.c b/avahi-core/browse.c index 5617395..a133c62 100644 --- a/avahi-core/browse.c +++ b/avahi-core/browse.c @@ -222,7 +222,6 @@ static void lookup_wide_area_callback( abort(); case AVAHI_BROWSER_ALL_FOR_NOW: - case AVAHI_BROWSER_NOT_FOUND: case AVAHI_BROWSER_FAILURE: b->callback(b, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, event, NULL, flags, b->userdata); @@ -292,7 +291,6 @@ static void lookup_multicast_callback( break; case AVAHI_BROWSER_CACHE_EXHAUSTED: - case AVAHI_BROWSER_NOT_FOUND: case AVAHI_BROWSER_FAILURE: /* Not defined for multicast DNS */ abort(); @@ -464,6 +462,8 @@ static void defer_callback(AvahiTimeEvent *e, void *userdata) { if (n < 0) { /* sending of the initial query failed */ + avahi_server_set_errno(b->server, AVAHI_ERR_FAILURE); + b->callback( b, b->interface, b->protocol, AVAHI_BROWSER_FAILURE, NULL, b->flags & AVAHI_LOOKUP_USE_WIDE_AREA ? AVAHI_LOOKUP_RESULT_WIDE_AREA : AVAHI_LOOKUP_RESULT_MULTICAST, diff --git a/avahi-core/querier-test.c b/avahi-core/querier-test.c index 254ecbb..41efc2c 100644 --- a/avahi-core/querier-test.c +++ b/avahi-core/querier-test.c @@ -49,7 +49,6 @@ static const char *browser_event_to_string(AvahiBrowserEvent event) { case AVAHI_BROWSER_CACHE_EXHAUSTED : return "CACHE_EXHAUSTED"; case AVAHI_BROWSER_ALL_FOR_NOW : return "ALL_FOR_NOW"; case AVAHI_BROWSER_FAILURE : return "FAILURE"; - case AVAHI_BROWSER_NOT_FOUND : return "NOT_FOUND"; } abort(); diff --git a/avahi-core/resolve-address.c b/avahi-core/resolve-address.c index 704dab4..661982d 100644 --- a/avahi-core/resolve-address.c +++ b/avahi-core/resolve-address.c @@ -62,8 +62,6 @@ static void finish(AvahiSAddressResolver *r, AvahiResolverEvent event) { } switch (event) { - case AVAHI_RESOLVER_NOT_FOUND: - case AVAHI_RESOLVER_TIMEOUT: case AVAHI_RESOLVER_FAILURE: r->callback(r, r->interface, r->protocol, event, &r->address, NULL, r->flags, r->userdata); break; @@ -81,7 +79,8 @@ static void time_event_callback(AvahiTimeEvent *e, void *userdata) { assert(e); assert(r); - finish(r, AVAHI_RESOLVER_TIMEOUT); + avahi_server_set_errno(r->server, AVAHI_ERR_TIMEOUT); + finish(r, AVAHI_RESOLVER_FAILURE); } static void start_timeout(AvahiSAddressResolver *r) { @@ -155,7 +154,7 @@ static void record_browser_callback( case AVAHI_BROWSER_ALL_FOR_NOW: break; - case AVAHI_BROWSER_NOT_FOUND: + case AVAHI_BROWSER_FAILURE: if (r->retry_with_multicast) { r->retry_with_multicast = 0; @@ -169,12 +168,9 @@ static void record_browser_callback( } } - /* Fallthrough */ - - case AVAHI_BROWSER_FAILURE: r->flags = flags; - finish(r, event == AVAHI_BROWSER_NOT_FOUND ? AVAHI_RESOLVER_NOT_FOUND : AVAHI_RESOLVER_FAILURE); - + finish(r, AVAHI_RESOLVER_FAILURE); + break; } } diff --git a/avahi-core/resolve-host-name.c b/avahi-core/resolve-host-name.c index 6315dbb..a38c001 100644 --- a/avahi-core/resolve-host-name.c +++ b/avahi-core/resolve-host-name.c @@ -89,8 +89,6 @@ static void finish(AvahiSHostNameResolver *r, AvahiResolverEvent event) { } - case AVAHI_RESOLVER_TIMEOUT: - case AVAHI_RESOLVER_NOT_FOUND: case AVAHI_RESOLVER_FAILURE: r->callback(r, r->interface, r->protocol, event, r->host_name, NULL, r->flags, r->userdata); @@ -104,7 +102,8 @@ static void time_event_callback(AvahiTimeEvent *e, void *userdata) { assert(e); assert(r); - finish(r, AVAHI_RESOLVER_TIMEOUT); + avahi_server_set_errno(r->server, AVAHI_ERR_TIMEOUT); + finish(r, AVAHI_RESOLVER_FAILURE); } static void start_timeout(AvahiSHostNameResolver *r) { @@ -188,7 +187,6 @@ static void record_browser_callback( break; case AVAHI_BROWSER_FAILURE: - case AVAHI_BROWSER_NOT_FOUND: /* Stop browsers */ @@ -200,7 +198,7 @@ static void record_browser_callback( r->record_browser_a = r->record_browser_aaaa = NULL; r->flags = flags; - finish(r, event == AVAHI_BROWSER_FAILURE ? AVAHI_RESOLVER_FAILURE : AVAHI_RESOLVER_NOT_FOUND); + finish(r, AVAHI_RESOLVER_FAILURE); break; } } diff --git a/avahi-core/resolve-service.c b/avahi-core/resolve-service.c index 85ac3d5..a897546 100644 --- a/avahi-core/resolve-service.c +++ b/avahi-core/resolve-service.c @@ -81,8 +81,6 @@ static void finish(AvahiSServiceResolver *r, AvahiResolverEvent event) { switch (event) { case AVAHI_RESOLVER_FAILURE: - case AVAHI_RESOLVER_NOT_FOUND: - case AVAHI_RESOLVER_TIMEOUT: r->callback( r, @@ -151,9 +149,8 @@ static void time_event_callback(AvahiTimeEvent *e, void *userdata) { assert(e); assert(r); - avahi_log_debug("timeout"); - - finish(r, AVAHI_RESOLVER_TIMEOUT); + avahi_server_set_errno(r->server, AVAHI_ERR_TIMEOUT); + finish(r, AVAHI_RESOLVER_FAILURE); } static void start_timeout(AvahiSServiceResolver *r) { @@ -346,9 +343,7 @@ static void record_browser_callback( case AVAHI_BROWSER_ALL_FOR_NOW: break; - case AVAHI_BROWSER_NOT_FOUND: case AVAHI_BROWSER_FAILURE: - if (rr == r->record_browser_a && r->record_browser_aaaa) { /* We were looking for both AAAA and A, and the other query is still living, so we'll not die */ @@ -364,7 +359,6 @@ static void record_browser_callback( break; } - /* Hmm, everything's lost, tell the user */ if (r->record_browser_srv) @@ -378,7 +372,7 @@ static void record_browser_callback( r->record_browser_srv = r->record_browser_txt = r->record_browser_a = r->record_browser_aaaa = NULL; - finish(r, event == AVAHI_BROWSER_FAILURE ? AVAHI_RESOLVER_FAILURE : AVAHI_RESOLVER_NOT_FOUND); + finish(r, AVAHI_RESOLVER_FAILURE); break; } } diff --git a/avahi-core/wide-area.c b/avahi-core/wide-area.c index 8c8b962..1075084 100644 --- a/avahi-core/wide-area.c +++ b/avahi-core/wide-area.c @@ -29,6 +29,7 @@ #include #include +#include #include "server.h" #include "browse.h" @@ -173,6 +174,7 @@ static void sender_timeout_callback(AvahiTimeEvent *e, void *userdata) { if (l->n_send >= 6) { avahi_log_warn(__FILE__": Query timed out."); + avahi_server_set_errno(l->engine->server, AVAHI_ERR_TIMEOUT); l->callback(l->engine, AVAHI_BROWSER_FAILURE, AVAHI_LOOKUP_RESULT_WIDE_AREA, NULL, l->userdata); avahi_wide_area_lookup_free(l); return; @@ -447,6 +449,31 @@ finish: run_callbacks(e, r); } +static int map_dns_error(uint16_t error) { + static const int table[16] = { + AVAHI_OK, + AVAHI_ERR_DNS_FORMERR, + AVAHI_ERR_DNS_SERVFAIL, + AVAHI_ERR_DNS_NXDOMAIN, + AVAHI_ERR_DNS_NOTIMP, + AVAHI_ERR_DNS_REFUSED, + AVAHI_ERR_DNS_YXDOMAIN, + AVAHI_ERR_DNS_YXRRSET, + AVAHI_ERR_DNS_NXRRSET, + AVAHI_ERR_DNS_NOTAUTH, + AVAHI_ERR_DNS_NOTZONE, + AVAHI_ERR_INVALID_DNS_ERROR, + AVAHI_ERR_INVALID_DNS_ERROR, + AVAHI_ERR_INVALID_DNS_ERROR, + AVAHI_ERR_INVALID_DNS_ERROR, + AVAHI_ERR_INVALID_DNS_ERROR + }; + + assert(error <= 15); + + return table[error]; +} + static void handle_packet(AvahiWideAreaLookupEngine *e, AvahiDnsPacket *p, AvahiAddress *a) { AvahiWideAreaLookup *l = NULL; int i, r; @@ -470,8 +497,9 @@ static void handle_packet(AvahiWideAreaLookupEngine *e, AvahiDnsPacket *p, Avahi if ((r = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_FLAGS) & 15) != 0 || avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ANCOUNT) == 0) { + avahi_server_set_errno(e->server, r == 0 ? AVAHI_ERR_NOT_FOUND : map_dns_error(r)); /* Tell the user about the failure */ - final_event = r == 3 ? AVAHI_BROWSER_NOT_FOUND : AVAHI_BROWSER_FAILURE; + final_event = AVAHI_BROWSER_FAILURE; /* We go on here, since some of the records contained in the reply might be interesting in some way */ @@ -483,6 +511,7 @@ static void handle_packet(AvahiWideAreaLookupEngine *e, AvahiDnsPacket *p, Avahi if (!(k = avahi_dns_packet_consume_key(p, NULL))) { avahi_log_warn(__FILE__": Wide area response packet too short."); + avahi_server_set_errno(e->server, AVAHI_ERR_INVALID_PACKET); final_event = AVAHI_BROWSER_FAILURE; goto finish; } @@ -499,6 +528,7 @@ static void handle_packet(AvahiWideAreaLookupEngine *e, AvahiDnsPacket *p, Avahi if (!(rr = avahi_dns_packet_consume_record(p, NULL))) { avahi_log_warn(__FILE__": Wide area response packet too short (2)."); + avahi_server_set_errno(e->server, AVAHI_ERR_INVALID_PACKET); final_event = AVAHI_BROWSER_FAILURE; goto finish; } diff --git a/avahi-daemon/AddressResolver.introspect b/avahi-daemon/AddressResolver.introspect index 61a6e9c..273ce8f 100644 --- a/avahi-daemon/AddressResolver.introspect +++ b/avahi-daemon/AddressResolver.introspect @@ -24,11 +24,9 @@ - - - - - + + + diff --git a/avahi-daemon/DomainBrowser.introspect b/avahi-daemon/DomainBrowser.introspect index 85e7e73..daabdb8 100644 --- a/avahi-daemon/DomainBrowser.introspect +++ b/avahi-daemon/DomainBrowser.introspect @@ -29,9 +29,9 @@ - - - + + + diff --git a/avahi-daemon/HostNameResolver.introspect b/avahi-daemon/HostNameResolver.introspect index d3337f9..d71ed8a 100644 --- a/avahi-daemon/HostNameResolver.introspect +++ b/avahi-daemon/HostNameResolver.introspect @@ -24,11 +24,9 @@ - - - - - + + + diff --git a/avahi-daemon/ServiceBrowser.introspect b/avahi-daemon/ServiceBrowser.introspect index 350026d..9638eaa 100644 --- a/avahi-daemon/ServiceBrowser.introspect +++ b/avahi-daemon/ServiceBrowser.introspect @@ -33,14 +33,13 @@ - - - + + + - diff --git a/avahi-daemon/ServiceResolver.introspect b/avahi-daemon/ServiceResolver.introspect index 7b752e3..771f179 100644 --- a/avahi-daemon/ServiceResolver.introspect +++ b/avahi-daemon/ServiceResolver.introspect @@ -29,11 +29,9 @@ - - - - - + + + diff --git a/avahi-daemon/ServiceTypeBrowser.introspect b/avahi-daemon/ServiceTypeBrowser.introspect index 1540a8f..04e7db9 100644 --- a/avahi-daemon/ServiceTypeBrowser.introspect +++ b/avahi-daemon/ServiceTypeBrowser.introspect @@ -31,9 +31,9 @@ - - - + + + diff --git a/avahi-daemon/dbus-protocol.c b/avahi-daemon/dbus-protocol.c index 96d0118..25a9e8e 100644 --- a/avahi-daemon/dbus-protocol.c +++ b/avahi-daemon/dbus-protocol.c @@ -430,7 +430,7 @@ static DBusHandlerResult respond_error(DBusConnection *c, DBusMessage *m, int er if (!text) text = avahi_strerror(error); - reply = dbus_message_new_error(m, avahi_error_number_to_dbus (error), text); + reply = dbus_message_new_error(m, avahi_error_number_to_dbus(error), text); dbus_connection_send(c, reply, NULL); dbus_message_unref(reply); @@ -504,6 +504,17 @@ static DBusHandlerResult respond_path(DBusConnection *c, DBusMessage *m, const c return DBUS_HANDLER_RESULT_HANDLED; } +static void append_server_error(DBusMessage *reply) { + const char *t; + + t = avahi_error_number_to_dbus(avahi_server_errno(avahi_server)); + + dbus_message_append_args( + reply, + DBUS_TYPE_STRING, &t, + DBUS_TYPE_INVALID); +} + static char *file_get_contents(char *fname) { int fd = -1; struct stat st; @@ -560,7 +571,6 @@ static const char *map_browse_signal_name(AvahiBrowserEvent e) { case AVAHI_BROWSER_NEW : return "ItemNew"; case AVAHI_BROWSER_REMOVE : return "ItemRemove"; case AVAHI_BROWSER_FAILURE : return "Failure"; - case AVAHI_BROWSER_NOT_FOUND : return "NotFound"; case AVAHI_BROWSER_CACHE_EXHAUSTED : return "CacheExhausted"; case AVAHI_BROWSER_ALL_FOR_NOW : return "AllForNow"; } @@ -571,25 +581,12 @@ static const char *map_browse_signal_name(AvahiBrowserEvent e) { static const char *map_resolve_signal_name(AvahiResolverEvent e) { switch (e) { case AVAHI_RESOLVER_FOUND : return "Found"; - case AVAHI_RESOLVER_TIMEOUT : return "Timeout"; case AVAHI_RESOLVER_FAILURE : return "Failure"; - case AVAHI_RESOLVER_NOT_FOUND : return "NotFound"; } abort(); } -static int map_resolve_error(AvahiResolverEvent e) { - - switch(e) { - case AVAHI_RESOLVER_FOUND : abort(); - case AVAHI_RESOLVER_TIMEOUT : return AVAHI_ERR_TIMEOUT; - case AVAHI_RESOLVER_FAILURE : return AVAHI_ERR_FAILURE; - case AVAHI_RESOLVER_NOT_FOUND : return AVAHI_ERR_NOT_FOUND; - } - - abort(); -} static DBusHandlerResult handle_introspect(DBusConnection *c, DBusMessage *m, const char *fname) { char *path, *contents; @@ -979,8 +976,10 @@ static void sync_host_name_resolver_callback(AvahiSHostNameResolver *r, AvahiIfI dbus_connection_send(server->bus, reply, NULL); dbus_message_unref(reply); - } else - respond_error(server->bus, i->message, map_resolve_error(event), NULL); + } else { + assert(event == AVAHI_RESOLVER_FAILURE); + respond_error(server->bus, i->message, avahi_server_errno(avahi_server), NULL); + } sync_host_name_resolver_free(i); } @@ -1019,8 +1018,10 @@ static void sync_address_resolver_callback(AvahiSAddressResolver *r, AvahiIfInde dbus_connection_send(server->bus, reply, NULL); dbus_message_unref(reply); - } else - respond_error(server->bus, i->message, map_resolve_error(event), NULL); + } else { + assert(event == AVAHI_RESOLVER_FAILURE); + respond_error(server->bus, i->message, avahi_server_errno(avahi_server), NULL); + } sync_address_resolver_free(i); } @@ -1093,7 +1094,8 @@ static void domain_browser_callback(AvahiSDomainBrowser *b, AvahiIfIndex interfa DBUS_TYPE_STRING, &domain, DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID); - } + } else if (event == AVAHI_BROWSER_FAILURE) + append_server_error(m); dbus_message_set_destination(m, i->client->name); dbus_connection_send(server->bus, m, NULL); @@ -1170,7 +1172,8 @@ static void service_type_browser_callback(AvahiSServiceTypeBrowser *b, AvahiIfIn DBUS_TYPE_STRING, &domain, DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID); - } + } else if (event == AVAHI_BROWSER_FAILURE) + append_server_error(m); dbus_message_set_destination(m, i->client->name); dbus_connection_send(server->bus, m, NULL); @@ -1250,7 +1253,8 @@ static void service_browser_callback(AvahiSServiceBrowser *b, AvahiIfIndex inter DBUS_TYPE_STRING, &domain, DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID); - } + } else if (event == AVAHI_BROWSER_FAILURE) + append_server_error(m); dbus_message_set_destination(m, i->client->name); dbus_connection_send(server->bus, m, NULL); @@ -1340,8 +1344,12 @@ static void sync_service_resolver_callback( dbus_connection_send(server->bus, reply, NULL); dbus_message_unref(reply); - } else - respond_error(server->bus, i->message, map_resolve_error(event), NULL); + + } else { + assert(event == AVAHI_RESOLVER_FAILURE); + + respond_error(server->bus, i->message, avahi_server_errno(avahi_server), NULL); + } sync_service_resolver_free(i); } @@ -1353,7 +1361,7 @@ static void async_address_resolver_callback(AvahiSAddressResolver *r, AvahiIfInd assert(r); assert(i); - reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_ADDRESS_RESOLVER, map_browse_signal_name(event)); + reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_ADDRESS_RESOLVER, map_resolve_signal_name(event)); if (event == AVAHI_RESOLVER_FOUND) { char t[256], *pt = t; @@ -1379,6 +1387,9 @@ static void async_address_resolver_callback(AvahiSAddressResolver *r, AvahiIfInd DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID); + } else { + assert(event == AVAHI_RESOLVER_FAILURE); + append_server_error(reply); } dbus_message_set_destination(reply, i->client->name); @@ -1462,6 +1473,9 @@ static void async_host_name_resolver_callback(AvahiSHostNameResolver *r, AvahiIf DBUS_TYPE_STRING, &pt, DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID); + } else { + assert(event == AVAHI_RESOLVER_FAILURE); + append_server_error(reply); } dbus_message_set_destination(reply, i->client->name); @@ -1574,6 +1588,9 @@ static void async_service_resolver_callback( reply, DBUS_TYPE_UINT32, &u_flags, DBUS_TYPE_INVALID); + } else { + assert(event == AVAHI_RESOLVER_FAILURE); + append_server_error(reply); } dbus_message_set_destination(reply, i->client->name); diff --git a/avahi-daemon/simple-protocol.c b/avahi-daemon/simple-protocol.c index 0c9989a..d53987d 100644 --- a/avahi-daemon/simple-protocol.c +++ b/avahi-daemon/simple-protocol.c @@ -178,12 +178,8 @@ static void host_name_resolver_callback( assert(c); - if (event == AVAHI_RESOLVER_TIMEOUT) - client_output_printf(c, "%+i Query timed out\n", AVAHI_ERR_TIMEOUT); - else if (event == AVAHI_RESOLVER_FAILURE) - client_output_printf(c, "%+i Query failed\n", AVAHI_ERR_FAILURE); - else if (event == AVAHI_RESOLVER_NOT_FOUND) - client_output_printf(c, "%+i Query timed out\n", AVAHI_ERR_NOT_FOUND); + if (event == AVAHI_RESOLVER_FAILURE) + client_output_printf(c, "%+i %s\n", avahi_server_errno(avahi_server), avahi_strerror(avahi_server_errno(avahi_server))); else if (event == AVAHI_RESOLVER_FOUND) { char t[64]; avahi_address_snprint(t, sizeof(t), a); @@ -207,12 +203,8 @@ static void address_resolver_callback( assert(c); - if (event == AVAHI_RESOLVER_TIMEOUT) - client_output_printf(c, "%+i Query timed out\n", AVAHI_ERR_TIMEOUT); - else if (event == AVAHI_RESOLVER_FAILURE) - client_output_printf(c, "%+i Query failed\n", AVAHI_ERR_FAILURE); - else if (event == AVAHI_RESOLVER_NOT_FOUND) - client_output_printf(c, "%+i Not found\n", AVAHI_ERR_NOT_FOUND); + if (event == AVAHI_RESOLVER_FAILURE) + client_output_printf(c, "%+i %s\n", avahi_server_errno(avahi_server), avahi_strerror(avahi_server_errno(avahi_server))); else if (event == AVAHI_RESOLVER_FOUND) client_output_printf(c, "+ %i %u %s\n", iface, protocol, hostname); @@ -240,12 +232,7 @@ static void dns_server_browser_callback( switch (event) { case AVAHI_BROWSER_FAILURE: - client_output_printf(c, "%+i Query failed\n", AVAHI_ERR_FAILURE); - c->state = CLIENT_DEAD; - break; - - case AVAHI_BROWSER_NOT_FOUND: - client_output_printf(c, "%+i Not found\n", AVAHI_ERR_FAILURE); + client_output_printf(c, "%+i %s\n", avahi_server_errno(avahi_server), avahi_strerror(avahi_server_errno(avahi_server))); c->state = CLIENT_DEAD; break; diff --git a/avahi-discover-standalone/main.c b/avahi-discover-standalone/main.c index c6e9cc4..296b56d 100644 --- a/avahi-discover-standalone/main.c +++ b/avahi-discover-standalone/main.c @@ -30,10 +30,14 @@ #include #include + #include #include + #include #include +#include + #include #include @@ -312,13 +316,11 @@ static void service_resolver_callback( return; } - if (event == AVAHI_RESOLVER_TIMEOUT) - gtk_label_set_markup(info_label, "Failed to resolve: Timeout."); - else if (event == AVAHI_RESOLVER_FAILURE) - gtk_label_set_markup(info_label, "Failed to resolve: Failure."); - else if (event == AVAHI_RESOLVER_NOT_FOUND) - gtk_label_set_markup(info_label, "Failed to resolve: Not found."); - else if (event == AVAHI_RESOLVER_FOUND) + if (event == AVAHI_RESOLVER_FAILURE) { + char t[256]; + snprintf(t, sizeof(t), "Failed to resolve: %s.", avahi_strerror(avahi_server_errno(server))); + gtk_label_set_markup(info_label, t); + } else if (event == AVAHI_RESOLVER_FOUND) update_label(s, host_name, a, port, txt); } diff --git a/examples/client-browse-services.c b/examples/client-browse-services.c index ac65ac4..7a6940b 100644 --- a/examples/client-browse-services.c +++ b/examples/client-browse-services.c @@ -55,11 +55,8 @@ static void resolve_callback( /* Called whenever a service has been resolved successfully or timed out */ switch (event) { - case AVAHI_RESOLVER_TIMEOUT: - case AVAHI_RESOLVER_NOT_FOUND: case AVAHI_RESOLVER_FAILURE: - fprintf(stderr, "(Resolver) Failed to resolve service '%s' of type '%s' in domain '%s': %s\n", name, type, domain, - event == AVAHI_RESOLVER_TIMEOUT ? "TIMEOUT" : (event == AVAHI_RESOLVER_NOT_FOUND ? "NOT_FOUND" : "FAILURE")); + fprintf(stderr, "(Resolver) Failed to resolve service '%s' of type '%s' in domain '%s': %s\n", name, type, domain, avahi_strerror(avahi_client_errno(avahi_service_resolver_get_client(r)))); break; case AVAHI_RESOLVER_FOUND: { @@ -110,9 +107,8 @@ static void browse_callback( switch (event) { case AVAHI_BROWSER_FAILURE: - case AVAHI_BROWSER_NOT_FOUND: - fprintf(stderr, "(Browser) %s\n", event == AVAHI_BROWSER_FAILURE ? "FAILURE" : "NOT_FOUND"); + fprintf(stderr, "(Browser) %s\n", avahi_strerror(avahi_client_errno(avahi_service_browser_get_client(b)))); avahi_simple_poll_quit(simple_poll); return; diff --git a/examples/core-browse-services.c b/examples/core-browse-services.c index d2a5e98..5de47b3 100644 --- a/examples/core-browse-services.c +++ b/examples/core-browse-services.c @@ -68,17 +68,14 @@ static void resolve_callback( /* Called whenever a service has been resolved successfully or timed out */ switch (event) { - case AVAHI_RESOLVER_TIMEOUT: - case AVAHI_RESOLVER_NOT_FOUND: case AVAHI_RESOLVER_FAILURE: - fprintf(stderr, "Failed to resolve service '%s' of type '%s' in domain '%s': %s\n", name, type, domain, - event == AVAHI_RESOLVER_TIMEOUT ? "TIMEOUT" : (event == AVAHI_RESOLVER_NOT_FOUND ? "NOT_FOUND" : "FAILURE")); + fprintf(stderr, "(Resolver) Failed to resolve service '%s' of type '%s' in domain '%s': %s\n", name, type, domain, avahi_strerror(avahi_server_errno(server))); break; case AVAHI_RESOLVER_FOUND: { char a[128], *t; - fprintf(stderr, "Service '%s' of type '%s' in domain '%s':\n", name, type, domain); + fprintf(stderr, "(Resolver) Service '%s' of type '%s' in domain '%s':\n", name, type, domain); avahi_address_snprint(a, sizeof(a), address); t = avahi_string_list_to_string(txt); @@ -123,9 +120,8 @@ static void browse_callback( switch (event) { case AVAHI_BROWSER_FAILURE: - case AVAHI_BROWSER_NOT_FOUND: - fprintf(stderr, "(Browser) %s\n", event == AVAHI_BROWSER_FAILURE ? "FAILURE" : "NOT_FOUND"); + fprintf(stderr, "(Browser) %s\n", avahi_strerror(avahi_server_errno(server))); avahi_simple_poll_quit(simple_poll); return; -- 2.39.5