4 This file is part of avahi.
6 avahi is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 avahi is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14 Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with avahi; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 #include <dbus/dbus.h>
32 #include <avahi-client/client.h>
33 #include <avahi-common/dbus.h>
34 #include <avahi-common/llist.h>
35 #include <avahi-common/error.h>
36 #include <avahi-common/malloc.h>
37 #include <avahi-common/domain.h>
41 #include "xdg-config.h"
43 static void parse_environment(AvahiDomainBrowser *b) {
44 char buf[AVAHI_DOMAIN_NAME_MAX*3], *e, *t, *p;
48 if (!(e = getenv("AVAHI_BROWSE_DOMAINS")))
51 snprintf(buf, sizeof(buf), "%s", e);
53 for (t = strtok_r(buf, ":", &p); t; t = strtok_r(NULL, ":", &p)) {
54 char domain[AVAHI_DOMAIN_NAME_MAX];
55 if (avahi_normalize_name(t, domain, sizeof(domain)))
56 b->static_browse_domains = avahi_string_list_add(b->static_browse_domains, domain);
60 static void parse_domain_file(AvahiDomainBrowser *b) {
62 char buf[AVAHI_DOMAIN_NAME_MAX];
66 if (!(f = avahi_xdg_config_open("avahi/browse-domains")))
70 while (fgets(buf, sizeof(buf)-1, f)) {
71 char domain[AVAHI_DOMAIN_NAME_MAX];
72 buf[strcspn(buf, "\n\r")] = 0;
74 if (avahi_normalize_name(buf, domain, sizeof(domain)))
75 b->static_browse_domains = avahi_string_list_add(b->static_browse_domains, domain);
79 static void domain_browser_ref(AvahiDomainBrowser *db) {
85 static void defer_timeout_callback(AvahiTimeout *t, void *userdata) {
86 AvahiDomainBrowser *db = userdata;
90 db->client->poll_api->timeout_free(db->defer_timeout);
91 db->defer_timeout = NULL;
93 domain_browser_ref(db);
95 for (l = db->static_browse_domains; l; l = l->next) {
100 db->callback(db, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AVAHI_BROWSER_NEW, (char*) l->text, AVAHI_LOOKUP_RESULT_STATIC, db->userdata);
103 avahi_domain_browser_free(db);
106 AvahiDomainBrowser* avahi_domain_browser_new(
108 AvahiIfIndex interface,
109 AvahiProtocol protocol,
111 AvahiDomainBrowserType btype,
112 AvahiLookupFlags flags,
113 AvahiDomainBrowserCallback callback,
116 AvahiDomainBrowser *db = NULL;
117 DBusMessage *message = NULL, *reply = NULL;
120 int32_t i_interface, i_protocol, bt;
126 dbus_error_init (&error);
128 if (!avahi_client_is_connected(client)) {
129 avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE);
136 if (!(db = avahi_new (AvahiDomainBrowser, 1))) {
137 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
143 db->callback = callback;
144 db->userdata = userdata;
146 db->interface = interface;
147 db->protocol = protocol;
148 db->static_browse_domains = NULL;
149 db->defer_timeout = NULL;
151 AVAHI_LLIST_PREPEND(AvahiDomainBrowser, domain_browsers, client->domain_browsers, db);
153 if (!(client->flags & AVAHI_CLIENT_IGNORE_USER_CONFIG)) {
154 parse_environment(db);
155 parse_domain_file(db);
158 db->static_browse_domains = avahi_string_list_reverse(db->static_browse_domains);
160 if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "DomainBrowserNew"))) {
161 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
165 i_interface = (int32_t) interface;
166 i_protocol = (int32_t) protocol;
167 u_flags = (uint32_t) flags;
170 if (!(dbus_message_append_args(
172 DBUS_TYPE_INT32, &i_interface,
173 DBUS_TYPE_INT32, &i_protocol,
174 DBUS_TYPE_STRING, &domain,
175 DBUS_TYPE_INT32, &bt,
176 DBUS_TYPE_UINT32, &flags,
177 DBUS_TYPE_INVALID))) {
178 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
182 if (!(reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error)) ||
183 dbus_error_is_set(&error)) {
184 avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
188 if (!dbus_message_get_args (reply, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID) ||
189 dbus_error_is_set(&error) ||
191 avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
195 if (!(db->path = avahi_strdup(path))) {
197 /* FIXME: We don't remove the object on the server side */
199 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
203 if (db->static_browse_domains && btype == AVAHI_DOMAIN_BROWSER_BROWSE) {
204 struct timeval tv = { 0, 0 };
206 if (!(db->defer_timeout = client->poll_api->timeout_new(client->poll_api, &tv, defer_timeout_callback, db))) {
207 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
212 dbus_message_unref(message);
213 dbus_message_unref(reply);
219 if (dbus_error_is_set(&error)) {
220 avahi_client_set_dbus_error(client, &error);
221 dbus_error_free(&error);
225 avahi_domain_browser_free(db);
228 dbus_message_unref(message);
231 dbus_message_unref(reply);
236 AvahiClient* avahi_domain_browser_get_client (AvahiDomainBrowser *b) {
241 int avahi_domain_browser_free (AvahiDomainBrowser *b) {
253 if (b->path && avahi_client_is_connected(b->client))
254 r = avahi_client_simple_method_call(client, b->path, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, "Free");
256 AVAHI_LLIST_REMOVE(AvahiDomainBrowser, domain_browsers, client->domain_browsers, b);
258 if (b->defer_timeout)
259 b->client->poll_api->timeout_free(b->defer_timeout);
261 avahi_string_list_free(b->static_browse_domains);
268 DBusHandlerResult avahi_domain_browser_event (AvahiClient *client, AvahiBrowserEvent event, DBusMessage *message) {
269 AvahiDomainBrowser *db = NULL;
273 int32_t interface, protocol;
280 dbus_error_init (&error);
282 if (!(path = dbus_message_get_path(message)))
285 for (db = client->domain_browsers; db; db = db->domain_browsers_next)
286 if (strcmp (db->path, path) == 0)
292 interface = db->interface;
293 protocol = db->protocol;
296 case AVAHI_BROWSER_NEW:
297 case AVAHI_BROWSER_REMOVE:
299 if (!dbus_message_get_args(
301 DBUS_TYPE_INT32, &interface,
302 DBUS_TYPE_INT32, &protocol,
303 DBUS_TYPE_STRING, &domain,
304 DBUS_TYPE_UINT32, &flags,
305 DBUS_TYPE_INVALID) ||
306 dbus_error_is_set (&error)) {
307 fprintf(stderr, "Failed to parse browser event.\n");
313 case AVAHI_BROWSER_CACHE_EXHAUSTED:
314 case AVAHI_BROWSER_ALL_FOR_NOW:
317 case AVAHI_BROWSER_FAILURE: {
320 if (!dbus_message_get_args(
322 DBUS_TYPE_STRING, &etxt,
323 DBUS_TYPE_INVALID) ||
324 dbus_error_is_set (&error)) {
325 fprintf(stderr, "Failed to parse browser event.\n");
329 avahi_client_set_errno(db->client, avahi_error_dbus_to_number(etxt));
335 for (l = db->static_browse_domains; l; l = l->next)
336 if (avahi_domain_equal((char*) l->text, domain)) {
337 /* We had this entry already in the static entries */
338 return DBUS_HANDLER_RESULT_HANDLED;
341 db->callback(db, (AvahiIfIndex) interface, (AvahiProtocol) protocol, event, domain, (AvahiLookupResultFlags) flags, db->userdata);
343 return DBUS_HANDLER_RESULT_HANDLED;
346 dbus_error_free (&error);
347 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
350 /* AvahiServiceTypeBrowser */
352 AvahiServiceTypeBrowser* avahi_service_type_browser_new(
354 AvahiIfIndex interface,
355 AvahiProtocol protocol,
357 AvahiLookupFlags flags,
358 AvahiServiceTypeBrowserCallback callback,
361 AvahiServiceTypeBrowser *b = NULL;
362 DBusMessage *message = NULL, *reply = NULL;
365 int32_t i_interface, i_protocol;
371 dbus_error_init(&error);
373 if (!avahi_client_is_connected(client)) {
374 avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE);
381 if (!(b = avahi_new(AvahiServiceTypeBrowser, 1))) {
382 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
387 b->callback = callback;
388 b->userdata = userdata;
391 b->interface = interface;
392 b->protocol = protocol;
394 AVAHI_LLIST_PREPEND(AvahiServiceTypeBrowser, service_type_browsers, client->service_type_browsers, b);
397 if (!(b->domain = avahi_strdup(domain))) {
398 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
402 if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "ServiceTypeBrowserNew"))) {
403 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
407 i_interface = (int32_t) interface;
408 i_protocol = (int32_t) protocol;
409 u_flags = (uint32_t) flags;
411 if (!dbus_message_append_args(
413 DBUS_TYPE_INT32, &i_interface,
414 DBUS_TYPE_INT32, &i_protocol,
415 DBUS_TYPE_STRING, &domain,
416 DBUS_TYPE_UINT32, &u_flags,
417 DBUS_TYPE_INVALID)) {
418 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
422 if (!(reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error)) ||
423 dbus_error_is_set(&error)) {
424 avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
428 if (!dbus_message_get_args (reply, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID) ||
429 dbus_error_is_set(&error) ||
431 avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
435 if (!(b->path = avahi_strdup(path))) {
437 /* FIXME: We don't remove the object on the server side */
439 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
443 dbus_message_unref(message);
444 dbus_message_unref(reply);
450 if (dbus_error_is_set(&error)) {
451 avahi_client_set_dbus_error(client, &error);
452 dbus_error_free(&error);
456 avahi_service_type_browser_free(b);
459 dbus_message_unref(message);
462 dbus_message_unref(reply);
467 AvahiClient* avahi_service_type_browser_get_client (AvahiServiceTypeBrowser *b) {
472 int avahi_service_type_browser_free (AvahiServiceTypeBrowser *b) {
479 if (b->path && avahi_client_is_connected(b->client))
480 r = avahi_client_simple_method_call(client, b->path, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "Free");
482 AVAHI_LLIST_REMOVE(AvahiServiceTypeBrowser, service_type_browsers, b->client->service_type_browsers, b);
485 avahi_free(b->domain);
490 DBusHandlerResult avahi_service_type_browser_event (AvahiClient *client, AvahiBrowserEvent event, DBusMessage *message) {
491 AvahiServiceTypeBrowser *b = NULL;
494 char *domain, *type = NULL;
495 int32_t interface, protocol;
501 dbus_error_init (&error);
503 if (!(path = dbus_message_get_path(message)))
506 for (b = client->service_type_browsers; b; b = b->service_type_browsers_next)
507 if (strcmp (b->path, path) == 0)
514 interface = b->interface;
515 protocol = b->protocol;
518 case AVAHI_BROWSER_NEW:
519 case AVAHI_BROWSER_REMOVE:
520 if (!dbus_message_get_args(
522 DBUS_TYPE_INT32, &interface,
523 DBUS_TYPE_INT32, &protocol,
524 DBUS_TYPE_STRING, &type,
525 DBUS_TYPE_STRING, &domain,
526 DBUS_TYPE_UINT32, &flags,
527 DBUS_TYPE_INVALID) ||
528 dbus_error_is_set(&error)) {
529 fprintf(stderr, "Failed to parse browser event.\n");
534 case AVAHI_BROWSER_CACHE_EXHAUSTED:
535 case AVAHI_BROWSER_ALL_FOR_NOW:
538 case AVAHI_BROWSER_FAILURE: {
541 if (!dbus_message_get_args(
543 DBUS_TYPE_STRING, &etxt,
544 DBUS_TYPE_INVALID) ||
545 dbus_error_is_set (&error)) {
546 fprintf(stderr, "Failed to parse browser event.\n");
550 avahi_client_set_errno(b->client, avahi_error_dbus_to_number(etxt));
555 b->callback(b, (AvahiIfIndex) interface, (AvahiProtocol) protocol, event, type, domain, (AvahiLookupResultFlags) flags, b->userdata);
557 return DBUS_HANDLER_RESULT_HANDLED;
560 dbus_error_free (&error);
561 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
564 /* AvahiServiceBrowser */
566 AvahiServiceBrowser* avahi_service_browser_new(
568 AvahiIfIndex interface,
569 AvahiProtocol protocol,
572 AvahiLookupFlags flags,
573 AvahiServiceBrowserCallback callback,
576 AvahiServiceBrowser *b = NULL;
577 DBusMessage *message = NULL, *reply = NULL;
580 int32_t i_protocol, i_interface;
587 dbus_error_init(&error);
589 if (!avahi_client_is_connected(client)) {
590 avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE);
597 if (!(b = avahi_new(AvahiServiceBrowser, 1))) {
598 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
603 b->callback = callback;
604 b->userdata = userdata;
606 b->type = b->domain = NULL;
607 b->interface = interface;
608 b->protocol = protocol;
610 AVAHI_LLIST_PREPEND(AvahiServiceBrowser, service_browsers, client->service_browsers, b);
612 if (!(b->type = avahi_strdup(type))) {
613 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
617 if (domain && domain[0])
618 if (!(b->domain = avahi_strdup(domain))) {
619 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
623 if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "ServiceBrowserNew"))) {
624 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
628 i_interface = (int32_t) interface;
629 i_protocol = (int32_t) protocol;
630 u_flags = (uint32_t) flags;
632 if (!dbus_message_append_args(
634 DBUS_TYPE_INT32, &i_interface,
635 DBUS_TYPE_INT32, &i_protocol,
636 DBUS_TYPE_STRING, &type,
637 DBUS_TYPE_STRING, &domain,
638 DBUS_TYPE_UINT32, &u_flags,
639 DBUS_TYPE_INVALID)) {
640 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
644 if (!(reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error)) ||
645 dbus_error_is_set(&error)) {
646 avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
650 if (!dbus_message_get_args (reply, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID) ||
651 dbus_error_is_set(&error) ||
653 avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
657 if (!(b->path = avahi_strdup(path))) {
659 /* FIXME: We don't remove the object on the server side */
661 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
665 dbus_message_unref(message);
666 dbus_message_unref(reply);
671 if (dbus_error_is_set(&error)) {
672 avahi_client_set_dbus_error(client, &error);
673 dbus_error_free(&error);
677 avahi_service_browser_free(b);
680 dbus_message_unref(message);
683 dbus_message_unref(reply);
688 AvahiClient* avahi_service_browser_get_client (AvahiServiceBrowser *b) {
693 int avahi_service_browser_free (AvahiServiceBrowser *b) {
700 if (b->path && avahi_client_is_connected(b->client))
701 r = avahi_client_simple_method_call(client, b->path, AVAHI_DBUS_INTERFACE_SERVICE_BROWSER, "Free");
703 AVAHI_LLIST_REMOVE(AvahiServiceBrowser, service_browsers, b->client->service_browsers, b);
707 avahi_free(b->domain);
712 DBusHandlerResult avahi_service_browser_event(AvahiClient *client, AvahiBrowserEvent event, DBusMessage *message) {
713 AvahiServiceBrowser *b = NULL;
716 char *name = NULL, *type, *domain;
717 int32_t interface, protocol;
720 dbus_error_init (&error);
722 if (!(path = dbus_message_get_path(message)))
725 for (b = client->service_browsers; b; b = b->service_browsers_next)
726 if (strcmp (b->path, path) == 0)
734 interface = b->interface;
735 protocol = b->protocol;
738 case AVAHI_BROWSER_NEW:
739 case AVAHI_BROWSER_REMOVE:
741 if (!dbus_message_get_args (
743 DBUS_TYPE_INT32, &interface,
744 DBUS_TYPE_INT32, &protocol,
745 DBUS_TYPE_STRING, &name,
746 DBUS_TYPE_STRING, &type,
747 DBUS_TYPE_STRING, &domain,
748 DBUS_TYPE_UINT32, &flags,
749 DBUS_TYPE_INVALID) ||
750 dbus_error_is_set(&error)) {
751 fprintf(stderr, "Failed to parse browser event.\n");
756 case AVAHI_BROWSER_CACHE_EXHAUSTED:
757 case AVAHI_BROWSER_ALL_FOR_NOW:
760 case AVAHI_BROWSER_FAILURE: {
763 if (!dbus_message_get_args(
765 DBUS_TYPE_STRING, &etxt,
766 DBUS_TYPE_INVALID) ||
767 dbus_error_is_set (&error)) {
768 fprintf(stderr, "Failed to parse browser event.\n");
772 avahi_client_set_errno(b->client, avahi_error_dbus_to_number(etxt));
777 b->callback(b, (AvahiIfIndex) interface, (AvahiProtocol) protocol, event, name, type, domain, (AvahiLookupResultFlags) flags, b->userdata);
779 return DBUS_HANDLER_RESULT_HANDLED;
782 dbus_error_free (&error);
783 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
786 /* AvahiRecordBrowser */
788 AvahiRecordBrowser* avahi_record_browser_new(
790 AvahiIfIndex interface,
791 AvahiProtocol protocol,
795 AvahiLookupFlags flags,
796 AvahiRecordBrowserCallback callback,
799 AvahiRecordBrowser *b = NULL;
800 DBusMessage *message = NULL, *reply = NULL;
803 int32_t i_protocol, i_interface;
810 dbus_error_init(&error);
812 if (!avahi_client_is_connected(client)) {
813 avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE);
817 if (!(b = avahi_new(AvahiRecordBrowser, 1))) {
818 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
823 b->callback = callback;
824 b->userdata = userdata;
829 b->interface = interface;
830 b->protocol = protocol;
832 AVAHI_LLIST_PREPEND(AvahiRecordBrowser, record_browsers, client->record_browsers, b);
834 if (!(b->name = avahi_strdup(name))) {
835 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
839 if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "RecordBrowserNew"))) {
840 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
844 i_interface = (int32_t) interface;
845 i_protocol = (int32_t) protocol;
846 u_flags = (uint32_t) flags;
848 if (!dbus_message_append_args(
850 DBUS_TYPE_INT32, &i_interface,
851 DBUS_TYPE_INT32, &i_protocol,
852 DBUS_TYPE_STRING, &name,
853 DBUS_TYPE_UINT16, &clazz,
854 DBUS_TYPE_UINT16, &type,
855 DBUS_TYPE_UINT32, &u_flags,
856 DBUS_TYPE_INVALID)) {
857 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
861 if (!(reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error)) ||
862 dbus_error_is_set(&error)) {
863 avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
867 if (!dbus_message_get_args (reply, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID) ||
868 dbus_error_is_set(&error) ||
870 avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
874 if (!(b->path = avahi_strdup(path))) {
876 /* FIXME: We don't remove the object on the server side */
878 avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
882 dbus_message_unref(message);
883 dbus_message_unref(reply);
888 if (dbus_error_is_set(&error)) {
889 avahi_client_set_dbus_error(client, &error);
890 dbus_error_free(&error);
894 avahi_record_browser_free(b);
897 dbus_message_unref(message);
900 dbus_message_unref(reply);
905 AvahiClient* avahi_record_browser_get_client (AvahiRecordBrowser *b) {
910 int avahi_record_browser_free (AvahiRecordBrowser *b) {
917 if (b->path && avahi_client_is_connected(b->client))
918 r = avahi_client_simple_method_call(client, b->path, AVAHI_DBUS_INTERFACE_RECORD_BROWSER, "Free");
920 AVAHI_LLIST_REMOVE(AvahiRecordBrowser, record_browsers, b->client->record_browsers, b);
928 DBusHandlerResult avahi_record_browser_event(AvahiClient *client, AvahiBrowserEvent event, DBusMessage *message) {
929 AvahiRecordBrowser *b = NULL;
933 int32_t interface, protocol;
935 uint16_t clazz, type;
939 dbus_error_init (&error);
941 if (!(path = dbus_message_get_path(message)))
944 for (b = client->record_browsers; b; b = b->record_browsers_next)
945 if (strcmp (b->path, path) == 0)
951 interface = b->interface;
952 protocol = b->protocol;
958 case AVAHI_BROWSER_NEW:
959 case AVAHI_BROWSER_REMOVE: {
960 DBusMessageIter iter, sub;
963 if (!dbus_message_get_args (
965 DBUS_TYPE_INT32, &interface,
966 DBUS_TYPE_INT32, &protocol,
967 DBUS_TYPE_STRING, &name,
968 DBUS_TYPE_UINT16, &clazz,
969 DBUS_TYPE_UINT16, &type,
970 DBUS_TYPE_INVALID) ||
971 dbus_error_is_set(&error)) {
972 fprintf(stderr, "Failed to parse browser event.\n");
977 dbus_message_iter_init(message, &iter);
979 for (j = 0; j < 5; j++)
980 dbus_message_iter_next(&iter);
982 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
983 dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_BYTE)
986 dbus_message_iter_recurse(&iter, &sub);
987 dbus_message_iter_get_fixed_array(&sub, &rdata, &rdata_size);
989 dbus_message_iter_next(&iter);
991 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT32)
994 dbus_message_iter_get_basic(&iter, &flags);
999 case AVAHI_BROWSER_CACHE_EXHAUSTED:
1000 case AVAHI_BROWSER_ALL_FOR_NOW:
1003 case AVAHI_BROWSER_FAILURE: {
1006 if (!dbus_message_get_args(
1008 DBUS_TYPE_STRING, &etxt,
1009 DBUS_TYPE_INVALID) ||
1010 dbus_error_is_set (&error)) {
1011 fprintf(stderr, "Failed to parse browser event.\n");
1015 avahi_client_set_errno(b->client, avahi_error_dbus_to_number(etxt));
1020 b->callback(b, (AvahiIfIndex) interface, (AvahiProtocol) protocol, event, name, clazz, type, rdata, (size_t) rdata_size, (AvahiLookupResultFlags) flags, b->userdata);
1022 return DBUS_HANDLER_RESULT_HANDLED;
1025 dbus_error_free (&error);
1026 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;