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
27 #include <sys/ioctl.h>
37 #include <dbus/dbus.h>
39 #include <avahi-common/dbus.h>
40 #include <avahi-common/llist.h>
41 #include <avahi-common/malloc.h>
42 #include <avahi-common/dbus.h>
43 #include <avahi-common/dbus-watch-glue.h>
44 #include <avahi-common/alternative.h>
45 #include <avahi-common/error.h>
46 #include <avahi-core/log.h>
47 #include <avahi-core/core.h>
49 #include "dbus-protocol.h"
52 typedef struct Server Server;
53 typedef struct Client Client;
54 typedef struct EntryGroupInfo EntryGroupInfo;
55 typedef struct SyncHostNameResolverInfo SyncHostNameResolverInfo;
56 typedef struct AsyncHostNameResolverInfo AsyncHostNameResolverInfo;
57 typedef struct SyncAddressResolverInfo SyncAddressResolverInfo;
58 typedef struct AsyncAddressResolverInfo AsyncAddressResolverInfo;
59 typedef struct DomainBrowserInfo DomainBrowserInfo;
60 typedef struct ServiceTypeBrowserInfo ServiceTypeBrowserInfo;
61 typedef struct ServiceBrowserInfo ServiceBrowserInfo;
62 typedef struct SyncServiceResolverInfo SyncServiceResolverInfo;
63 typedef struct AsyncServiceResolverInfo AsyncServiceResolverInfo;
65 #define MAX_CLIENTS 20
66 #define MAX_OBJECTS_PER_CLIENT 50
67 #define MAX_ENTRIES_PER_ENTRY_GROUP 20
69 /* #define VALGRIND_WORKAROUND */
71 struct EntryGroupInfo {
74 AvahiSEntryGroup *entry_group;
79 AVAHI_LLIST_FIELDS(EntryGroupInfo, entry_groups);
82 struct SyncHostNameResolverInfo {
84 AvahiSHostNameResolver *host_name_resolver;
87 AVAHI_LLIST_FIELDS(SyncHostNameResolverInfo, sync_host_name_resolvers);
90 struct AsyncHostNameResolverInfo {
93 AvahiSHostNameResolver *host_name_resolver;
96 AVAHI_LLIST_FIELDS(AsyncHostNameResolverInfo, async_host_name_resolvers);
99 struct SyncAddressResolverInfo {
101 AvahiSAddressResolver *address_resolver;
102 DBusMessage *message;
104 AVAHI_LLIST_FIELDS(SyncAddressResolverInfo, sync_address_resolvers);
107 struct AsyncAddressResolverInfo {
110 AvahiSAddressResolver *address_resolver;
113 AVAHI_LLIST_FIELDS(AsyncAddressResolverInfo, async_address_resolvers);
116 struct DomainBrowserInfo {
119 AvahiSDomainBrowser *domain_browser;
122 AVAHI_LLIST_FIELDS(DomainBrowserInfo, domain_browsers);
125 struct ServiceTypeBrowserInfo {
128 AvahiSServiceTypeBrowser *service_type_browser;
131 AVAHI_LLIST_FIELDS(ServiceTypeBrowserInfo, service_type_browsers);
134 struct ServiceBrowserInfo {
137 AvahiSServiceBrowser *service_browser;
140 AVAHI_LLIST_FIELDS(ServiceBrowserInfo, service_browsers);
143 struct SyncServiceResolverInfo {
145 AvahiSServiceResolver *service_resolver;
146 DBusMessage *message;
148 AVAHI_LLIST_FIELDS(SyncServiceResolverInfo, sync_service_resolvers);
151 struct AsyncServiceResolverInfo {
154 AvahiSServiceResolver *service_resolver;
157 AVAHI_LLIST_FIELDS(AsyncServiceResolverInfo, async_service_resolvers);
166 AVAHI_LLIST_FIELDS(Client, clients);
167 AVAHI_LLIST_HEAD(EntryGroupInfo, entry_groups);
168 AVAHI_LLIST_HEAD(SyncHostNameResolverInfo, sync_host_name_resolvers);
169 AVAHI_LLIST_HEAD(AsyncHostNameResolverInfo, async_host_name_resolvers);
170 AVAHI_LLIST_HEAD(SyncAddressResolverInfo, sync_address_resolvers);
171 AVAHI_LLIST_HEAD(AsyncAddressResolverInfo, async_address_resolvers);
172 AVAHI_LLIST_HEAD(DomainBrowserInfo, domain_browsers);
173 AVAHI_LLIST_HEAD(ServiceTypeBrowserInfo, service_type_browsers);
174 AVAHI_LLIST_HEAD(ServiceBrowserInfo, service_browsers);
175 AVAHI_LLIST_HEAD(SyncServiceResolverInfo, sync_service_resolvers);
176 AVAHI_LLIST_HEAD(AsyncServiceResolverInfo, async_service_resolvers);
181 AVAHI_LLIST_HEAD(Client, clients);
186 static Server *server = NULL;
188 static void entry_group_free(EntryGroupInfo *i) {
192 avahi_s_entry_group_free(i->entry_group);
193 dbus_connection_unregister_object_path(server->bus, i->path);
195 AVAHI_LLIST_REMOVE(EntryGroupInfo, entry_groups, i->client->entry_groups, i);
197 i->client->n_objects--;
198 assert(i->client->n_objects >= 0);
203 static void sync_host_name_resolver_free(SyncHostNameResolverInfo *i) {
206 if (i->host_name_resolver)
207 avahi_s_host_name_resolver_free(i->host_name_resolver);
208 dbus_message_unref(i->message);
209 AVAHI_LLIST_REMOVE(SyncHostNameResolverInfo, sync_host_name_resolvers, i->client->sync_host_name_resolvers, i);
211 i->client->n_objects--;
212 assert(i->client->n_objects >= 0);
217 static void async_host_name_resolver_free(AsyncHostNameResolverInfo *i) {
220 if (i->host_name_resolver)
221 avahi_s_host_name_resolver_free(i->host_name_resolver);
222 dbus_connection_unregister_object_path(server->bus, i->path);
223 AVAHI_LLIST_REMOVE(AsyncHostNameResolverInfo, async_host_name_resolvers, i->client->async_host_name_resolvers, i);
225 i->client->n_objects--;
226 assert(i->client->n_objects >= 0);
231 static void sync_address_resolver_free(SyncAddressResolverInfo *i) {
234 if (i->address_resolver)
235 avahi_s_address_resolver_free(i->address_resolver);
236 dbus_message_unref(i->message);
237 AVAHI_LLIST_REMOVE(SyncAddressResolverInfo, sync_address_resolvers, i->client->sync_address_resolvers, i);
239 i->client->n_objects--;
240 assert(i->client->n_objects >= 0);
245 static void async_address_resolver_free(AsyncAddressResolverInfo *i) {
248 if (i->address_resolver)
249 avahi_s_address_resolver_free(i->address_resolver);
250 dbus_connection_unregister_object_path(server->bus, i->path);
251 AVAHI_LLIST_REMOVE(AsyncAddressResolverInfo, async_address_resolvers, i->client->async_address_resolvers, i);
253 i->client->n_objects--;
254 assert(i->client->n_objects >= 0);
259 static void domain_browser_free(DomainBrowserInfo *i) {
262 if (i->domain_browser)
263 avahi_s_domain_browser_free(i->domain_browser);
264 dbus_connection_unregister_object_path(server->bus, i->path);
266 AVAHI_LLIST_REMOVE(DomainBrowserInfo, domain_browsers, i->client->domain_browsers, i);
268 i->client->n_objects--;
269 assert(i->client->n_objects >= 0);
274 static void service_type_browser_free(ServiceTypeBrowserInfo *i) {
277 if (i->service_type_browser)
278 avahi_s_service_type_browser_free(i->service_type_browser);
279 dbus_connection_unregister_object_path(server->bus, i->path);
281 AVAHI_LLIST_REMOVE(ServiceTypeBrowserInfo, service_type_browsers, i->client->service_type_browsers, i);
283 i->client->n_objects--;
284 assert(i->client->n_objects >= 0);
289 static void service_browser_free(ServiceBrowserInfo *i) {
292 if (i->service_browser)
293 avahi_s_service_browser_free(i->service_browser);
294 dbus_connection_unregister_object_path(server->bus, i->path);
296 AVAHI_LLIST_REMOVE(ServiceBrowserInfo, service_browsers, i->client->service_browsers, i);
298 i->client->n_objects--;
299 assert(i->client->n_objects >= 0);
304 static void sync_service_resolver_free(SyncServiceResolverInfo *i) {
307 if (i->service_resolver)
308 avahi_s_service_resolver_free(i->service_resolver);
309 dbus_message_unref(i->message);
310 AVAHI_LLIST_REMOVE(SyncServiceResolverInfo, sync_service_resolvers, i->client->sync_service_resolvers, i);
312 i->client->n_objects--;
313 assert(i->client->n_objects >= 0);
318 static void async_service_resolver_free(AsyncServiceResolverInfo *i) {
321 if (i->service_resolver)
322 avahi_s_service_resolver_free(i->service_resolver);
324 dbus_connection_unregister_object_path(server->bus, i->path);
325 AVAHI_LLIST_REMOVE(AsyncServiceResolverInfo, async_service_resolvers, i->client->async_service_resolvers, i);
327 i->client->n_objects--;
328 assert(i->client->n_objects >= 0);
333 static void client_free(Client *c) {
338 while (c->entry_groups)
339 entry_group_free(c->entry_groups);
341 while (c->sync_host_name_resolvers)
342 sync_host_name_resolver_free(c->sync_host_name_resolvers);
344 while (c->async_host_name_resolvers)
345 async_host_name_resolver_free(c->async_host_name_resolvers);
347 while (c->sync_address_resolvers)
348 sync_address_resolver_free(c->sync_address_resolvers);
350 while (c->async_address_resolvers)
351 async_address_resolver_free(c->async_address_resolvers);
353 while (c->domain_browsers)
354 domain_browser_free(c->domain_browsers);
356 while (c->service_type_browsers)
357 service_type_browser_free(c->service_type_browsers);
359 while (c->service_browsers)
360 service_browser_free(c->service_browsers);
362 while (c->sync_service_resolvers)
363 sync_service_resolver_free(c->sync_service_resolvers);
365 while (c->async_service_resolvers)
366 async_service_resolver_free(c->async_service_resolvers);
368 assert(c->n_objects == 0);
371 AVAHI_LLIST_REMOVE(Client, clients, server->clients, c);
374 server->n_clients --;
375 assert(server->n_clients >= 0);
378 static Client *client_get(const char *name, int create) {
384 for (client = server->clients; client; client = client->clients_next)
385 if (!strcmp(name, client->name))
391 if (server->n_clients >= MAX_CLIENTS)
394 /* If not existant yet, create a new entry */
395 client = avahi_new(Client, 1);
396 client->id = server->current_id++;
397 client->name = avahi_strdup(name);
398 client->current_id = 0;
399 client->n_objects = 0;
401 AVAHI_LLIST_HEAD_INIT(EntryGroupInfo, client->entry_groups);
402 AVAHI_LLIST_HEAD_INIT(SyncHostNameResolverInfo, client->sync_host_name_resolvers);
403 AVAHI_LLIST_HEAD_INIT(AsyncHostNameResolverInfo, client->async_host_name_resolvers);
404 AVAHI_LLIST_HEAD_INIT(SyncAddressResolverInfo, client->sync_address_resolvers);
405 AVAHI_LLIST_HEAD_INIT(AsyncAddressResolverInfo, client->async_address_resolvers);
406 AVAHI_LLIST_HEAD_INIT(DomainBrowserInfo, client->domain_browsers);
407 AVAHI_LLIST_HEAD_INIT(ServiceTypeBrowserInfo, client->service_type_browsers);
408 AVAHI_LLIST_HEAD_INIT(ServiceBrowserInfo, client->service_browsers);
409 AVAHI_LLIST_HEAD_INIT(SyncServiceResolverInfo, client->sync_service_resolvers);
410 AVAHI_LLIST_HEAD_INIT(AsyncServiceResolverInfo, client->async_service_resolvers);
412 AVAHI_LLIST_PREPEND(Client, clients, server->clients, client);
415 assert(server->n_clients > 0);
420 static DBusHandlerResult respond_error(DBusConnection *c, DBusMessage *m, int error, const char *text) {
423 assert(-error > -AVAHI_OK);
424 assert(-error < -AVAHI_ERR_MAX);
426 reply = dbus_message_new_error(m, avahi_error_number_to_dbus (error), text ? text : avahi_strerror(error));
427 dbus_connection_send(c, reply, NULL);
428 dbus_message_unref(reply);
430 return DBUS_HANDLER_RESULT_HANDLED;
433 static DBusHandlerResult respond_string(DBusConnection *c, DBusMessage *m, const char *text) {
436 reply = dbus_message_new_method_return(m);
437 dbus_message_append_args(reply, DBUS_TYPE_STRING, &text, DBUS_TYPE_INVALID);
438 dbus_connection_send(c, reply, NULL);
439 dbus_message_unref(reply);
441 return DBUS_HANDLER_RESULT_HANDLED;
444 static DBusHandlerResult respond_int32(DBusConnection *c, DBusMessage *m, int32_t i) {
447 reply = dbus_message_new_method_return(m);
448 dbus_message_append_args(reply, DBUS_TYPE_INT32, &i, DBUS_TYPE_INVALID);
449 dbus_connection_send(c, reply, NULL);
450 dbus_message_unref(reply);
452 return DBUS_HANDLER_RESULT_HANDLED;
455 static DBusHandlerResult respond_ok(DBusConnection *c, DBusMessage *m) {
458 reply = dbus_message_new_method_return(m);
459 dbus_connection_send(c, reply, NULL);
460 dbus_message_unref(reply);
462 return DBUS_HANDLER_RESULT_HANDLED;
465 static DBusHandlerResult respond_path(DBusConnection *c, DBusMessage *m, const char *path) {
468 reply = dbus_message_new_method_return(m);
469 dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID);
470 dbus_connection_send(c, reply, NULL);
471 dbus_message_unref(reply);
473 return DBUS_HANDLER_RESULT_HANDLED;
476 static char *file_get_contents(char *fname) {
484 if (!(fd = open(fname, O_RDONLY))) {
485 avahi_log_error("Failed to open %s: %s", fname, strerror(errno));
489 if (fstat(fd, &st) < 0) {
490 avahi_log_error("stat(%s) failed: %s", fname, strerror(errno));
494 if (!(S_ISREG(st.st_mode))) {
495 avahi_log_error("Invalid file %s", fname);
499 if (st.st_size > 1024*1024) { /** 1MB */
500 avahi_log_error("File too large %s", fname);
504 buf = avahi_new(char, st.st_size+1);
506 if ((size = read(fd, buf, st.st_size)) < 0) {
507 avahi_log_error("read() failed: %s\n", strerror(errno));
527 static DBusHandlerResult handle_introspect(DBusConnection *c, DBusMessage *m, const char *fname) {
528 char *path, *contents;
535 dbus_error_init(&error);
537 if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
538 avahi_log_error("Error parsing Introspect message: %s", error.message);
542 path = avahi_strdup_printf("%s/%s", AVAHI_DBUS_INTROSPECTION_DIR, fname);
543 contents = file_get_contents(path);
547 avahi_log_error("Failed to load introspection data.");
551 respond_string(c, m, contents);
552 avahi_free(contents);
554 return DBUS_HANDLER_RESULT_HANDLED;
557 if (dbus_error_is_set(&error))
558 dbus_error_free(&error);
560 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
564 static DBusHandlerResult msg_signal_filter_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
567 dbus_error_init(&error);
569 /* avahi_log_debug("dbus: interface=%s, path=%s, member=%s", */
570 /* dbus_message_get_interface(m), */
571 /* dbus_message_get_path(m), */
572 /* dbus_message_get_member(m)); */
574 if (dbus_message_is_signal(m, DBUS_INTERFACE_LOCAL, "Disconnected")) {
575 /* No, we shouldn't quit, but until we get somewhere
576 * usefull such that we can restore our state, we will */
577 avahi_log_warn("Disconnnected from d-bus, terminating...");
579 raise(SIGQUIT); /* The signal handler will catch this and terminate the process cleanly*/
581 return DBUS_HANDLER_RESULT_HANDLED;
583 } else if (dbus_message_is_signal(m, DBUS_INTERFACE_DBUS, "NameAcquired")) {
586 if (!dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) {
587 avahi_log_warn("Error parsing NameAcquired message");
591 /* avahi_log_info("dbus: name acquired (%s)", name); */
592 return DBUS_HANDLER_RESULT_HANDLED;
594 } else if (dbus_message_is_signal(m, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
595 char *name, *old, *new;
597 if (!dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &old, DBUS_TYPE_STRING, &new, DBUS_TYPE_INVALID)) {
598 avahi_log_warn("Error parsing NameOwnerChanged message");
605 if ((client = client_get(name, FALSE))) {
606 /* avahi_log_info("dbus: client %s vanished", name); */
613 if (dbus_error_is_set(&error))
614 dbus_error_free(&error);
616 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
619 static void entry_group_callback(AvahiServer *s, AvahiSEntryGroup *g, AvahiEntryGroupState state, void* userdata) {
620 EntryGroupInfo *i = userdata;
628 m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "StateChanged");
630 dbus_message_append_args(m, DBUS_TYPE_INT32, &t, DBUS_TYPE_INVALID);
631 dbus_message_set_destination(m, i->client->name);
632 dbus_connection_send(server->bus, m, NULL);
633 dbus_message_unref(m);
636 static DBusHandlerResult msg_entry_group_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
638 EntryGroupInfo *i = userdata;
644 dbus_error_init(&error);
646 avahi_log_debug("dbus: interface=%s, path=%s, member=%s",
647 dbus_message_get_interface(m),
648 dbus_message_get_path(m),
649 dbus_message_get_member(m));
652 if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
653 return handle_introspect(c, m, "EntryGroup.introspect");
656 if (strcmp(dbus_message_get_sender(m), i->client->name))
657 return respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL);
659 if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "Free")) {
661 if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
662 avahi_log_warn("Error parsing EntryGroup::Free message");
667 return respond_ok(c, m);
669 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "Commit")) {
671 if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
672 avahi_log_warn("Error parsing EntryGroup::Commit message");
676 avahi_s_entry_group_commit(i->entry_group);
677 return respond_ok(c, m);
680 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "Reset")) {
682 if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
683 avahi_log_warn("Error parsing EntryGroup::Reset message");
687 avahi_s_entry_group_reset(i->entry_group);
688 return respond_ok(c, m);
690 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "IsEmpty")) {
694 if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
695 avahi_log_warn("Error parsing EntryGroup::IsEmpty message");
699 b = !!avahi_s_entry_group_is_empty(i->entry_group);
701 reply = dbus_message_new_method_return(m);
702 dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &b, DBUS_TYPE_INVALID);
703 dbus_connection_send(c, reply, NULL);
704 dbus_message_unref(reply);
706 return DBUS_HANDLER_RESULT_HANDLED;
708 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "GetState")) {
709 AvahiEntryGroupState state;
711 if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
712 avahi_log_warn("Error parsing EntryGroup::GetState message");
716 state = avahi_s_entry_group_get_state(i->entry_group);
717 return respond_int32(c, m, (int32_t) state);
719 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddService")) {
720 int32_t interface, protocol;
721 char *type, *name, *domain, *host;
723 AvahiStringList *strlst;
724 DBusMessageIter iter, sub;
727 if (!dbus_message_get_args(
729 DBUS_TYPE_INT32, &interface,
730 DBUS_TYPE_INT32, &protocol,
731 DBUS_TYPE_STRING, &name,
732 DBUS_TYPE_STRING, &type,
733 DBUS_TYPE_STRING, &domain,
734 DBUS_TYPE_STRING, &host,
735 DBUS_TYPE_UINT16, &port,
736 DBUS_TYPE_INVALID) || !type || !name) {
737 avahi_log_warn("Error parsing EntryGroup::AddService message");
741 dbus_message_iter_init(m, &iter);
743 for (j = 0; j < 7; j++)
744 dbus_message_iter_next(&iter);
746 if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
747 dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_ARRAY) {
748 avahi_log_warn("Error parsing EntryGroup::AddService message 2");
753 dbus_message_iter_recurse(&iter, &sub);
756 DBusMessageIter sub2;
760 if ((at = dbus_message_iter_get_arg_type(&sub)) == DBUS_TYPE_INVALID)
763 assert(at == DBUS_TYPE_ARRAY);
765 if (dbus_message_iter_get_element_type(&sub) != DBUS_TYPE_BYTE) {
766 avahi_log_warn("Error parsing EntryGroup::AddService message");
770 dbus_message_iter_recurse(&sub, &sub2);
771 dbus_message_iter_get_fixed_array(&sub2, &k, &n);
772 strlst = avahi_string_list_add_arbitrary(strlst, k, n);
774 dbus_message_iter_next(&sub);
777 if (i->n_entries >= MAX_ENTRIES_PER_ENTRY_GROUP) {
778 avahi_string_list_free(strlst);
779 avahi_log_warn("Too many entries per entry group, client request failed.");
780 return respond_error(c, m, AVAHI_ERR_TOO_MANY_ENTRIES, NULL);
783 if (domain && !*domain)
789 if (avahi_server_add_service_strlst(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, name, type, domain, host, port, strlst) < 0) {
790 avahi_string_list_free(strlst);
791 return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
795 avahi_string_list_free(strlst);
797 return respond_ok(c, m);
799 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddAddress")) {
800 int32_t interface, protocol;
801 char *name, *address;
804 if (!dbus_message_get_args(
806 DBUS_TYPE_INT32, &interface,
807 DBUS_TYPE_INT32, &protocol,
808 DBUS_TYPE_STRING, &name,
809 DBUS_TYPE_STRING, &address,
810 DBUS_TYPE_INVALID) || !name || !address) {
811 avahi_log_warn("Error parsing EntryGroup::AddAddress message");
815 if (i->n_entries >= MAX_ENTRIES_PER_ENTRY_GROUP) {
816 avahi_log_warn("Too many entries per entry group, client request failed.");
817 return respond_error(c, m, AVAHI_ERR_TOO_MANY_ENTRIES, NULL);
820 if (!(avahi_address_parse(address, AVAHI_PROTO_UNSPEC, &a))) {
821 return respond_error(c, m, AVAHI_ERR_INVALID_ADDRESS, NULL);
824 if (avahi_server_add_address(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, 0, name, &a) < 0)
825 return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
829 return respond_ok(c, m);
832 avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
835 if (dbus_error_is_set(&error))
836 dbus_error_free(&error);
838 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
841 static void sync_host_name_resolver_callback(AvahiSHostNameResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const char *host_name, const AvahiAddress *a, void* userdata) {
842 SyncHostNameResolverInfo *i = userdata;
848 if (event == AVAHI_RESOLVER_FOUND) {
849 char t[256], *pt = t;
850 int32_t i_interface, i_protocol, i_aprotocol;
854 avahi_address_snprint(t, sizeof(t), a);
856 i_interface = (int32_t) interface;
857 i_protocol = (int32_t) protocol;
858 i_aprotocol = (int32_t) a->family;
860 reply = dbus_message_new_method_return(i->message);
861 dbus_message_append_args(
863 DBUS_TYPE_INT32, &i_interface,
864 DBUS_TYPE_INT32, &i_protocol,
865 DBUS_TYPE_STRING, &host_name,
866 DBUS_TYPE_INT32, &i_aprotocol,
867 DBUS_TYPE_STRING, &pt,
870 dbus_connection_send(server->bus, reply, NULL);
871 dbus_message_unref(reply);
873 assert(event == AVAHI_RESOLVER_TIMEOUT);
875 respond_error(server->bus, i->message, AVAHI_ERR_TIMEOUT, NULL);
878 sync_host_name_resolver_free(i);
881 static void sync_address_resolver_callback(AvahiSAddressResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const AvahiAddress *address, const char *host_name, void* userdata) {
882 SyncAddressResolverInfo *i = userdata;
888 if (event == AVAHI_RESOLVER_FOUND) {
889 char t[256], *pt = t;
890 int32_t i_interface, i_protocol, i_aprotocol;
894 avahi_address_snprint(t, sizeof(t), address);
896 i_interface = (int32_t) interface;
897 i_protocol = (int32_t) protocol;
898 i_aprotocol = (int32_t) address->family;
900 reply = dbus_message_new_method_return(i->message);
901 dbus_message_append_args(
903 DBUS_TYPE_INT32, &i_interface,
904 DBUS_TYPE_INT32, &i_protocol,
905 DBUS_TYPE_INT32, &i_aprotocol,
906 DBUS_TYPE_STRING, &pt,
907 DBUS_TYPE_STRING, &host_name,
910 dbus_connection_send(server->bus, reply, NULL);
911 dbus_message_unref(reply);
913 assert(event == AVAHI_RESOLVER_TIMEOUT);
914 respond_error(server->bus, i->message, AVAHI_ERR_TIMEOUT, NULL);
917 sync_address_resolver_free(i);
920 static DBusHandlerResult msg_domain_browser_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
922 DomainBrowserInfo *i = userdata;
928 dbus_error_init(&error);
930 avahi_log_debug("dbus: interface=%s, path=%s, member=%s",
931 dbus_message_get_interface(m),
932 dbus_message_get_path(m),
933 dbus_message_get_member(m));
936 if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
937 return handle_introspect(c, m, "DomainBrowser.introspect");
940 if (strcmp(dbus_message_get_sender(m), i->client->name))
941 return respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL);
943 if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, "Free")) {
945 if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
946 avahi_log_warn("Error parsing DomainBrowser::Free message");
950 domain_browser_free(i);
951 return respond_ok(c, m);
955 avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
958 if (dbus_error_is_set(&error))
959 dbus_error_free(&error);
961 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
964 static void domain_browser_callback(AvahiSDomainBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *domain, void* userdata) {
965 DomainBrowserInfo *i = userdata;
967 int32_t i_interface, i_protocol;
973 i_interface = (int32_t) interface;
974 i_protocol = (int32_t) protocol;
976 m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, event == AVAHI_BROWSER_NEW ? "ItemNew" : "ItemRemove");
977 dbus_message_append_args(
979 DBUS_TYPE_INT32, &i_interface,
980 DBUS_TYPE_INT32, &i_protocol,
981 DBUS_TYPE_STRING, &domain,
983 dbus_message_set_destination(m, i->client->name);
984 dbus_connection_send(server->bus, m, NULL);
985 dbus_message_unref(m);
988 static DBusHandlerResult msg_service_type_browser_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
990 ServiceTypeBrowserInfo *i = userdata;
996 dbus_error_init(&error);
998 avahi_log_debug("dbus: interface=%s, path=%s, member=%s",
999 dbus_message_get_interface(m),
1000 dbus_message_get_path(m),
1001 dbus_message_get_member(m));
1004 if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
1005 return handle_introspect(c, m, "ServiceTypeBrowser.introspect");
1007 /* Access control */
1008 if (strcmp(dbus_message_get_sender(m), i->client->name))
1009 return respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL);
1011 if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "Free")) {
1013 if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
1014 avahi_log_warn("Error parsing ServiceTypeBrowser::Free message");
1018 service_type_browser_free(i);
1019 return respond_ok(c, m);
1023 avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
1026 if (dbus_error_is_set(&error))
1027 dbus_error_free(&error);
1029 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1032 static void service_type_browser_callback(AvahiSServiceTypeBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *type, const char *domain, void* userdata) {
1033 ServiceTypeBrowserInfo *i = userdata;
1035 int32_t i_interface, i_protocol;
1042 i_interface = (int32_t) interface;
1043 i_protocol = (int32_t) protocol;
1045 m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, event == AVAHI_BROWSER_NEW ? "ItemNew" : "ItemRemove");
1046 dbus_message_append_args(
1048 DBUS_TYPE_INT32, &i_interface,
1049 DBUS_TYPE_INT32, &i_protocol,
1050 DBUS_TYPE_STRING, &type,
1051 DBUS_TYPE_STRING, &domain,
1053 dbus_message_set_destination(m, i->client->name);
1054 dbus_connection_send(server->bus, m, NULL);
1055 dbus_message_unref(m);
1058 static DBusHandlerResult msg_service_browser_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
1060 ServiceBrowserInfo *i = userdata;
1066 dbus_error_init(&error);
1068 avahi_log_debug("dbus: interface=%s, path=%s, member=%s",
1069 dbus_message_get_interface(m),
1070 dbus_message_get_path(m),
1071 dbus_message_get_member(m));
1074 if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
1075 return handle_introspect(c, m, "ServiceBrowser.Introspect");
1077 /* Access control */
1078 if (strcmp(dbus_message_get_sender(m), i->client->name))
1079 return respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL);
1081 if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVICE_BROWSER, "Free")) {
1083 if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
1084 avahi_log_warn("Error parsing ServiceBrowser::Free message");
1088 service_browser_free(i);
1089 return respond_ok(c, m);
1093 avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
1096 if (dbus_error_is_set(&error))
1097 dbus_error_free(&error);
1099 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1102 static void service_browser_callback(AvahiSServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, void* userdata) {
1103 ServiceBrowserInfo *i = userdata;
1105 int32_t i_interface, i_protocol;
1113 i_interface = (int32_t) interface;
1114 i_protocol = (int32_t) protocol;
1116 m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_SERVICE_BROWSER, event == AVAHI_BROWSER_NEW ? "ItemNew" : "ItemRemove");
1117 dbus_message_append_args(
1119 DBUS_TYPE_INT32, &i_interface,
1120 DBUS_TYPE_INT32, &i_protocol,
1121 DBUS_TYPE_STRING, &name,
1122 DBUS_TYPE_STRING, &type,
1123 DBUS_TYPE_STRING, &domain,
1125 dbus_message_set_destination(m, i->client->name);
1126 dbus_connection_send(server->bus, m, NULL);
1127 dbus_message_unref(m);
1130 static void append_string_list(DBusMessage *reply, AvahiStringList *txt) {
1132 DBusMessageIter iter, sub;
1136 dbus_message_iter_init_append(reply, &iter);
1137 dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "ay", &sub);
1139 for (p = txt; p; p = p->next) {
1140 DBusMessageIter sub2;
1141 const uint8_t *data = p->text;
1143 dbus_message_iter_open_container(&sub, DBUS_TYPE_ARRAY, "y", &sub2);
1144 dbus_message_iter_append_fixed_array(&sub2, DBUS_TYPE_BYTE, &data, p->size);
1145 dbus_message_iter_close_container(&sub, &sub2);
1148 dbus_message_iter_close_container(&iter, &sub);
1151 static void sync_service_resolver_callback(
1152 AvahiSServiceResolver *r,
1153 AvahiIfIndex interface,
1154 AvahiProtocol protocol,
1155 AvahiResolverEvent event,
1159 const char *host_name,
1160 const AvahiAddress *a,
1162 AvahiStringList *txt,
1165 SyncServiceResolverInfo *i = userdata;
1170 if (event == AVAHI_RESOLVER_FOUND) {
1171 char t[256], *pt = t;
1172 int32_t i_interface, i_protocol, i_aprotocol;
1178 avahi_address_snprint(t, sizeof(t), a);
1180 i_interface = (int32_t) interface;
1181 i_protocol = (int32_t) protocol;
1182 i_aprotocol = (int32_t) a->family;
1184 reply = dbus_message_new_method_return(i->message);
1185 dbus_message_append_args(
1187 DBUS_TYPE_INT32, &i_interface,
1188 DBUS_TYPE_INT32, &i_protocol,
1189 DBUS_TYPE_STRING, &name,
1190 DBUS_TYPE_STRING, &type,
1191 DBUS_TYPE_STRING, &domain,
1192 DBUS_TYPE_STRING, &host_name,
1193 DBUS_TYPE_INT32, &i_aprotocol,
1194 DBUS_TYPE_STRING, &pt,
1195 DBUS_TYPE_UINT16, &port,
1198 append_string_list(reply, txt);
1200 dbus_connection_send(server->bus, reply, NULL);
1201 dbus_message_unref(reply);
1203 assert(event == AVAHI_RESOLVER_TIMEOUT);
1205 respond_error(server->bus, i->message, AVAHI_ERR_TIMEOUT, NULL);
1208 sync_service_resolver_free(i);
1211 static void async_address_resolver_callback(AvahiSAddressResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const AvahiAddress *address, const char *host_name, void* userdata) {
1212 AsyncAddressResolverInfo *i = userdata;
1219 if (event == AVAHI_RESOLVER_FOUND) {
1220 char t[256], *pt = t;
1221 int32_t i_interface, i_protocol, i_aprotocol;
1224 avahi_address_snprint(t, sizeof(t), address);
1226 i_interface = (int32_t) interface;
1227 i_protocol = (int32_t) protocol;
1228 i_aprotocol = (int32_t) address->family;
1230 reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_ADDRESS_RESOLVER, "Found");
1231 dbus_message_append_args(
1233 DBUS_TYPE_INT32, &i_interface,
1234 DBUS_TYPE_INT32, &i_protocol,
1235 DBUS_TYPE_INT32, &i_aprotocol,
1236 DBUS_TYPE_STRING, &pt,
1237 DBUS_TYPE_STRING, &host_name,
1241 assert(event == AVAHI_RESOLVER_TIMEOUT);
1243 reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_ADDRESS_RESOLVER, "Timeout");
1246 dbus_connection_send(server->bus, reply, NULL);
1247 dbus_message_unref(reply);
1250 static DBusHandlerResult msg_async_address_resolver_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
1252 AsyncAddressResolverInfo *i = userdata;
1258 dbus_error_init(&error);
1260 avahi_log_debug("dbus: interface=%s, path=%s, member=%s",
1261 dbus_message_get_interface(m),
1262 dbus_message_get_path(m),
1263 dbus_message_get_member(m));
1266 if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
1267 return handle_introspect(c, m, "AddressResolver.Introspect");
1269 /* Access control */
1270 if (strcmp(dbus_message_get_sender(m), i->client->name))
1271 return respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL);
1273 if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ADDRESS_RESOLVER, "Free")) {
1275 if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
1276 avahi_log_warn("Error parsing AddressResolver::Free message");
1280 async_address_resolver_free(i);
1281 return respond_ok(c, m);
1285 avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
1288 if (dbus_error_is_set(&error))
1289 dbus_error_free(&error);
1291 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1294 static void async_host_name_resolver_callback(AvahiSHostNameResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const char *host_name, const AvahiAddress *a, void* userdata) {
1295 AsyncHostNameResolverInfo *i = userdata;
1302 if (event == AVAHI_RESOLVER_FOUND) {
1303 char t[256], *pt = t;
1304 int32_t i_interface, i_protocol, i_aprotocol;
1307 avahi_address_snprint(t, sizeof(t), a);
1309 i_interface = (int32_t) interface;
1310 i_protocol = (int32_t) protocol;
1311 i_aprotocol = (int32_t) a->family;
1313 reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_HOST_NAME_RESOLVER, "Found");
1314 dbus_message_append_args(
1316 DBUS_TYPE_INT32, &i_interface,
1317 DBUS_TYPE_INT32, &i_protocol,
1318 DBUS_TYPE_STRING, &host_name,
1319 DBUS_TYPE_INT32, &i_aprotocol,
1320 DBUS_TYPE_STRING, &pt,
1323 assert(event == AVAHI_RESOLVER_TIMEOUT);
1325 reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_HOST_NAME_RESOLVER, "Timeout");
1328 dbus_connection_send(server->bus, reply, NULL);
1329 dbus_message_unref(reply);
1332 static DBusHandlerResult msg_async_host_name_resolver_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
1334 AsyncHostNameResolverInfo *i = userdata;
1340 dbus_error_init(&error);
1342 avahi_log_debug("dbus: interface=%s, path=%s, member=%s",
1343 dbus_message_get_interface(m),
1344 dbus_message_get_path(m),
1345 dbus_message_get_member(m));
1348 if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
1349 return handle_introspect(c, m, "HostNameResolver.Introspect");
1351 /* Access control */
1352 if (strcmp(dbus_message_get_sender(m), i->client->name))
1353 return respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL);
1355 if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_HOST_NAME_RESOLVER, "Free")) {
1357 if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
1358 avahi_log_warn("Error parsing HostNameResolver::Free message");
1362 async_host_name_resolver_free(i);
1363 return respond_ok(c, m);
1366 avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
1369 if (dbus_error_is_set(&error))
1370 dbus_error_free(&error);
1372 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1375 static void async_service_resolver_callback(
1376 AvahiSServiceResolver *r,
1377 AvahiIfIndex interface,
1378 AvahiProtocol protocol,
1379 AvahiResolverEvent event,
1383 const char *host_name,
1384 const AvahiAddress *a,
1386 AvahiStringList *txt,
1389 AsyncServiceResolverInfo *i = userdata;
1396 if (event == AVAHI_RESOLVER_FOUND) {
1397 char t[256], *pt = t;
1398 int32_t i_interface, i_protocol, i_aprotocol;
1403 avahi_address_snprint(t, sizeof(t), a);
1405 i_interface = (int32_t) interface;
1406 i_protocol = (int32_t) protocol;
1407 i_aprotocol = (int32_t) a->family;
1409 reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_SERVICE_RESOLVER, "Found");
1410 dbus_message_append_args(
1412 DBUS_TYPE_INT32, &i_interface,
1413 DBUS_TYPE_INT32, &i_protocol,
1414 DBUS_TYPE_STRING, &name,
1415 DBUS_TYPE_STRING, &type,
1416 DBUS_TYPE_STRING, &domain,
1417 DBUS_TYPE_STRING, &host_name,
1418 DBUS_TYPE_INT32, &i_aprotocol,
1419 DBUS_TYPE_STRING, &pt,
1420 DBUS_TYPE_UINT16, &port,
1423 append_string_list(reply, txt);
1426 assert(event == AVAHI_RESOLVER_TIMEOUT);
1428 reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_SERVICE_RESOLVER, "Timeout");
1431 dbus_connection_send(server->bus, reply, NULL);
1432 dbus_message_unref(reply);
1435 static DBusHandlerResult msg_async_service_resolver_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
1437 AsyncServiceResolverInfo *i = userdata;
1443 dbus_error_init(&error);
1445 avahi_log_debug("dbus: interface=%s, path=%s, member=%s",
1446 dbus_message_get_interface(m),
1447 dbus_message_get_path(m),
1448 dbus_message_get_member(m));
1451 if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
1452 return handle_introspect(c, m, "ServiceResolver.Introspect");
1454 /* Access control */
1455 if (strcmp(dbus_message_get_sender(m), i->client->name))
1456 return respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL);
1458 if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVICE_RESOLVER, "Free")) {
1460 if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
1461 avahi_log_warn("Error parsing ServiceResolver::Free message");
1465 async_service_resolver_free(i);
1466 return respond_ok(c, m);
1469 avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
1472 if (dbus_error_is_set(&error))
1473 dbus_error_free(&error);
1475 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
1478 static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
1481 dbus_error_init(&error);
1483 avahi_log_debug("dbus: interface=%s, path=%s, member=%s",
1484 dbus_message_get_interface(m),
1485 dbus_message_get_path(m),
1486 dbus_message_get_member(m));
1488 if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
1489 return handle_introspect(c, m, "Server.introspect");
1491 else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetHostName")) {
1493 if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
1494 avahi_log_warn("Error parsing Server::GetHostName message");
1498 return respond_string(c, m, avahi_server_get_host_name(avahi_server));
1500 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetDomainName")) {
1502 if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
1503 avahi_log_warn("Error parsing Server::GetDomainName message");
1507 return respond_string(c, m, avahi_server_get_domain_name(avahi_server));
1509 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetHostNameFqdn")) {
1511 if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INVALID))) {
1512 avahi_log_warn("Error parsing Server::GetHostNameFqdn message");
1516 return respond_string(c, m, avahi_server_get_host_name_fqdn(avahi_server));
1518 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetVersionString")) {
1520 if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INVALID))) {
1521 avahi_log_warn("Error parsing Server::GetVersionString message");
1525 return respond_string(c, m, PACKAGE_STRING);
1527 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetState")) {
1528 AvahiServerState state;
1530 if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INVALID))) {
1531 avahi_log_warn("Error parsing Server::GetState message");
1535 state = avahi_server_get_state(avahi_server);
1536 return respond_int32(c, m, (int32_t) state);
1538 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetNetworkInterfaceNameByIndex")) {
1543 if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INT32, &idx, DBUS_TYPE_INVALID))) {
1544 avahi_log_warn("Error parsing Server::GetNetworkInterfaceNameByIndex message");
1548 #ifdef VALGRIND_WORKAROUND
1549 return respond_string(c, m, "blah");
1552 if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
1553 if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
1555 snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
1556 return respond_error(c, m, AVAHI_ERR_OS, txt);
1559 memset(&ifr, 0, sizeof(ifr));
1560 ifr.ifr_ifindex = idx;
1562 if (ioctl(fd, SIOCGIFNAME, &ifr) < 0) {
1564 snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
1566 return respond_error(c, m, AVAHI_ERR_OS, txt);
1571 return respond_string(c, m, ifr.ifr_name);
1574 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetNetworkInterfaceIndexByName")) {
1579 if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n) {
1580 avahi_log_warn("Error parsing Server::GetNetworkInterfaceIndexByName message");
1584 #ifdef VALGRIND_WORKAROUND
1585 return respond_int32(c, m, 1);
1587 if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
1588 if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
1590 snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
1591 return respond_error(c, m, AVAHI_ERR_OS, txt);
1594 memset(&ifr, 0, sizeof(ifr));
1595 snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", n);
1597 if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
1599 snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
1601 return respond_error(c, m, AVAHI_ERR_OS, txt);
1606 return respond_int32(c, m, ifr.ifr_ifindex);
1609 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetAlternativeHostName")) {
1612 if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n) {
1613 avahi_log_warn("Error parsing Server::GetAlternativeHostName message");
1617 t = avahi_alternative_host_name(n);
1618 respond_string(c, m, t);
1621 return DBUS_HANDLER_RESULT_HANDLED;
1623 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetAlternativeServiceName")) {
1626 if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n) {
1627 avahi_log_warn("Error parsing Server::GetAlternativeServiceName message");
1631 t = avahi_alternative_service_name(n);
1632 respond_string(c, m, t);
1635 return DBUS_HANDLER_RESULT_HANDLED;
1637 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "EntryGroupNew")) {
1640 static const DBusObjectPathVTable vtable = {
1642 msg_entry_group_impl,
1649 if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
1650 avahi_log_warn("Error parsing Server::EntryGroupNew message");
1654 if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
1655 avahi_log_warn("Too many clients, client request failed.");
1656 return respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
1659 if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
1660 avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
1661 return respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
1664 i = avahi_new(EntryGroupInfo, 1);
1665 i->id = ++client->current_id;
1667 i->path = avahi_strdup_printf("/Client%u/EntryGroup%u", client->id, i->id);
1669 AVAHI_LLIST_PREPEND(EntryGroupInfo, entry_groups, client->entry_groups, i);
1670 client->n_objects++;
1672 if (!(i->entry_group = avahi_s_entry_group_new(avahi_server, entry_group_callback, i))) {
1673 entry_group_free(i);
1674 return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
1677 dbus_connection_register_object_path(c, i->path, &vtable, i);
1678 return respond_path(c, m, i->path);
1680 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ResolveHostName")) {
1682 int32_t interface, protocol, aprotocol;
1684 SyncHostNameResolverInfo *i;
1686 if (!dbus_message_get_args(
1688 DBUS_TYPE_INT32, &interface,
1689 DBUS_TYPE_INT32, &protocol,
1690 DBUS_TYPE_STRING, &name,
1691 DBUS_TYPE_INT32, &aprotocol,
1692 DBUS_TYPE_INVALID) || !name) {
1693 avahi_log_warn("Error parsing Server::ResolveHostName message");
1697 if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
1698 avahi_log_warn("Too many clients, client request failed.");
1699 return respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
1702 if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
1703 avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
1704 return respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
1707 i = avahi_new(SyncHostNameResolverInfo, 1);
1709 i->message = dbus_message_ref(m);
1710 AVAHI_LLIST_PREPEND(SyncHostNameResolverInfo, sync_host_name_resolvers, client->sync_host_name_resolvers, i);
1711 client->n_objects++;
1713 if (!(i->host_name_resolver = avahi_s_host_name_resolver_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, name, (AvahiProtocol) aprotocol, sync_host_name_resolver_callback, i))) {
1714 sync_host_name_resolver_free(i);
1715 return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
1718 return DBUS_HANDLER_RESULT_HANDLED;
1720 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ResolveAddress")) {
1722 int32_t interface, protocol;
1724 SyncAddressResolverInfo *i;
1727 if (!dbus_message_get_args(
1729 DBUS_TYPE_INT32, &interface,
1730 DBUS_TYPE_INT32, &protocol,
1731 DBUS_TYPE_STRING, &address,
1732 DBUS_TYPE_INVALID) || !address) {
1733 avahi_log_warn("Error parsing Server::ResolveAddress message");
1737 if (!avahi_address_parse(address, AVAHI_PROTO_UNSPEC, &a))
1738 return respond_error(c, m, AVAHI_ERR_INVALID_ADDRESS, NULL);
1740 if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
1741 avahi_log_warn("Too many clients, client request failed.");
1742 return respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
1745 if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
1746 avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
1747 return respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
1750 i = avahi_new(SyncAddressResolverInfo, 1);
1752 i->message = dbus_message_ref(m);
1753 AVAHI_LLIST_PREPEND(SyncAddressResolverInfo, sync_address_resolvers, client->sync_address_resolvers, i);
1754 client->n_objects++;
1756 if (!(i->address_resolver = avahi_s_address_resolver_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, &a, sync_address_resolver_callback, i))) {
1757 sync_address_resolver_free(i);
1758 return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
1761 return DBUS_HANDLER_RESULT_HANDLED;
1763 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "DomainBrowserNew")) {
1765 DomainBrowserInfo *i;
1766 static const DBusObjectPathVTable vtable = {
1768 msg_domain_browser_impl,
1774 int32_t interface, protocol, type;
1777 if (!dbus_message_get_args(
1779 DBUS_TYPE_INT32, &interface,
1780 DBUS_TYPE_INT32, &protocol,
1781 DBUS_TYPE_STRING, &domain,
1782 DBUS_TYPE_INT32, &type,
1783 DBUS_TYPE_INVALID) || type < 0 || type >= AVAHI_DOMAIN_BROWSER_MAX) {
1784 avahi_log_warn("Error parsing Server::DomainBrowserNew message");
1788 if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
1789 avahi_log_warn("Too many clients, client request failed.");
1790 return respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
1793 if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
1794 avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
1795 return respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
1801 i = avahi_new(DomainBrowserInfo, 1);
1802 i->id = ++client->current_id;
1804 i->path = avahi_strdup_printf("/Client%u/DomainBrowser%u", client->id, i->id);
1805 AVAHI_LLIST_PREPEND(DomainBrowserInfo, domain_browsers, client->domain_browsers, i);
1806 client->n_objects++;
1808 if (!(i->domain_browser = avahi_s_domain_browser_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, domain, (AvahiDomainBrowserType) type, domain_browser_callback, i))) {
1809 domain_browser_free(i);
1810 return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
1813 dbus_connection_register_object_path(c, i->path, &vtable, i);
1814 return respond_path(c, m, i->path);
1816 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ServiceTypeBrowserNew")) {
1818 ServiceTypeBrowserInfo *i;
1819 static const DBusObjectPathVTable vtable = {
1821 msg_service_type_browser_impl,
1827 int32_t interface, protocol;
1830 if (!dbus_message_get_args(
1832 DBUS_TYPE_INT32, &interface,
1833 DBUS_TYPE_INT32, &protocol,
1834 DBUS_TYPE_STRING, &domain,
1835 DBUS_TYPE_INVALID)) {
1836 avahi_log_warn("Error parsing Server::ServiceTypeBrowserNew message");
1840 if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
1841 avahi_log_warn("Too many clients, client request failed.");
1842 return respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
1846 if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
1847 avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
1848 return respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
1854 i = avahi_new(ServiceTypeBrowserInfo, 1);
1855 i->id = ++client->current_id;
1857 i->path = avahi_strdup_printf("/Client%u/ServiceTypeBrowser%u", client->id, i->id);
1858 AVAHI_LLIST_PREPEND(ServiceTypeBrowserInfo, service_type_browsers, client->service_type_browsers, i);
1859 client->n_objects++;
1861 if (!(i->service_type_browser = avahi_s_service_type_browser_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, domain, service_type_browser_callback, i))) {
1862 service_type_browser_free(i);
1863 return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
1866 dbus_connection_register_object_path(c, i->path, &vtable, i);
1867 return respond_path(c, m, i->path);
1869 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ServiceBrowserNew")) {
1871 ServiceBrowserInfo *i;
1872 static const DBusObjectPathVTable vtable = {
1874 msg_service_browser_impl,
1880 int32_t interface, protocol;
1881 char *domain, *type;
1883 if (!dbus_message_get_args(
1885 DBUS_TYPE_INT32, &interface,
1886 DBUS_TYPE_INT32, &protocol,
1887 DBUS_TYPE_STRING, &type,
1888 DBUS_TYPE_STRING, &domain,
1889 DBUS_TYPE_INVALID) || !type) {
1890 avahi_log_warn("Error parsing Server::ServiceBrowserNew message");
1894 if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
1895 avahi_log_warn("Too many clients, client request failed.");
1896 return respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
1900 if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
1901 avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
1902 return respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
1908 i = avahi_new(ServiceBrowserInfo, 1);
1909 i->id = ++client->current_id;
1911 i->path = avahi_strdup_printf("/Client%u/ServiceBrowser%u", client->id, i->id);
1912 AVAHI_LLIST_PREPEND(ServiceBrowserInfo, service_browsers, client->service_browsers, i);
1913 client->n_objects++;
1915 if (!(i->service_browser = avahi_s_service_browser_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, type, domain, service_browser_callback, i))) {
1916 service_browser_free(i);
1917 return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
1920 dbus_connection_register_object_path(c, i->path, &vtable, i);
1921 return respond_path(c, m, i->path);
1923 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ResolveService")) {
1925 int32_t interface, protocol, aprotocol;
1926 char *name, *type, *domain;
1927 SyncServiceResolverInfo *i;
1929 if (!dbus_message_get_args(
1931 DBUS_TYPE_INT32, &interface,
1932 DBUS_TYPE_INT32, &protocol,
1933 DBUS_TYPE_STRING, &name,
1934 DBUS_TYPE_STRING, &type,
1935 DBUS_TYPE_STRING, &domain,
1936 DBUS_TYPE_INT32, &aprotocol,
1937 DBUS_TYPE_INVALID) || !name || !type) {
1938 avahi_log_warn("Error parsing Server::ResolveService message");
1942 if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
1943 avahi_log_warn("Too many clients, client request failed.");
1944 return respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
1947 if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
1948 avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
1949 return respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
1955 i = avahi_new(SyncServiceResolverInfo, 1);
1957 i->message = dbus_message_ref(m);
1958 AVAHI_LLIST_PREPEND(SyncServiceResolverInfo, sync_service_resolvers, client->sync_service_resolvers, i);
1959 client->n_objects++;
1961 if (!(i->service_resolver = avahi_s_service_resolver_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, name, type, domain, (AvahiProtocol) aprotocol, sync_service_resolver_callback, i))) {
1962 sync_service_resolver_free(i);
1963 return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
1966 return DBUS_HANDLER_RESULT_HANDLED;
1968 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ServiceResolverNew")) {
1970 int32_t interface, protocol, aprotocol;
1971 char *name, *type, *domain;
1972 AsyncServiceResolverInfo *i;
1973 static const DBusObjectPathVTable vtable = {
1975 msg_async_service_resolver_impl,
1982 if (!dbus_message_get_args(
1984 DBUS_TYPE_INT32, &interface,
1985 DBUS_TYPE_INT32, &protocol,
1986 DBUS_TYPE_STRING, &name,
1987 DBUS_TYPE_STRING, &type,
1988 DBUS_TYPE_STRING, &domain,
1989 DBUS_TYPE_INT32, &aprotocol,
1990 DBUS_TYPE_INVALID) || !name || !type) {
1991 avahi_log_warn("Error parsing Server::ServiceResolverNew message");
1995 if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
1996 avahi_log_warn(__FILE__": Too many clients, client request failed.");
1997 return respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
2000 if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
2001 avahi_log_warn(__FILE__": Too many objects for client '%s', client request failed.", client->name);
2002 return respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
2005 i = avahi_new(AsyncServiceResolverInfo, 1);
2006 i->id = ++client->current_id;
2008 i->path = avahi_strdup_printf("/Client%u/ServiceResolver%u", client->id, i->id);
2009 AVAHI_LLIST_PREPEND(AsyncServiceResolverInfo, async_service_resolvers, client->async_service_resolvers, i);
2010 client->n_objects++;
2012 if (!(i->service_resolver = avahi_s_service_resolver_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, name, type, domain, (AvahiProtocol) aprotocol, async_service_resolver_callback, i))) {
2013 async_service_resolver_free(i);
2014 return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
2017 dbus_connection_register_object_path(c, i->path, &vtable, i);
2018 return respond_path(c, m, i->path);
2020 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "HostNameResolverNew")) {
2022 int32_t interface, protocol, aprotocol;
2024 AsyncHostNameResolverInfo *i;
2025 static const DBusObjectPathVTable vtable = {
2027 msg_async_host_name_resolver_impl,
2034 if (!dbus_message_get_args(
2036 DBUS_TYPE_INT32, &interface,
2037 DBUS_TYPE_INT32, &protocol,
2038 DBUS_TYPE_STRING, &name,
2039 DBUS_TYPE_INT32, &aprotocol,
2040 DBUS_TYPE_INVALID) || !name) {
2041 avahi_log_warn("Error parsing Server::HostNameResolverNew message");
2045 if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
2046 avahi_log_warn(__FILE__": Too many clients, client request failed.");
2047 return respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
2050 if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
2051 avahi_log_warn(__FILE__": Too many objects for client '%s', client request failed.", client->name);
2052 return respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
2055 i = avahi_new(AsyncHostNameResolverInfo, 1);
2056 i->id = ++client->current_id;
2058 i->path = avahi_strdup_printf("/Client%u/HostNameResolver%u", client->id, i->id);
2059 AVAHI_LLIST_PREPEND(AsyncHostNameResolverInfo, async_host_name_resolvers, client->async_host_name_resolvers, i);
2060 client->n_objects++;
2062 if (!(i->host_name_resolver = avahi_s_host_name_resolver_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, name, aprotocol, async_host_name_resolver_callback, i))) {
2063 async_host_name_resolver_free(i);
2064 return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
2067 dbus_connection_register_object_path(c, i->path, &vtable, i);
2068 return respond_path(c, m, i->path);
2070 } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "AddressResolverNew")) {
2072 int32_t interface, protocol;
2074 AsyncAddressResolverInfo *i;
2076 static const DBusObjectPathVTable vtable = {
2078 msg_async_address_resolver_impl,
2085 if (!dbus_message_get_args(
2087 DBUS_TYPE_INT32, &interface,
2088 DBUS_TYPE_INT32, &protocol,
2089 DBUS_TYPE_STRING, &address,
2090 DBUS_TYPE_INVALID) || !address) {
2091 avahi_log_warn("Error parsing Server::AddressResolverNew message");
2095 if (!avahi_address_parse(address, AVAHI_PROTO_UNSPEC, &a))
2096 return respond_error(c, m, AVAHI_ERR_INVALID_ADDRESS, NULL);
2098 if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
2099 avahi_log_warn(__FILE__": Too many clients, client request failed.");
2100 return respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
2103 if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
2104 avahi_log_warn(__FILE__": Too many objects for client '%s', client request failed.", client->name);
2105 return respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
2108 i = avahi_new(AsyncAddressResolverInfo, 1);
2109 i->id = ++client->current_id;
2111 i->path = avahi_strdup_printf("/Client%u/AddressResolver%u", client->id, i->id);
2112 AVAHI_LLIST_PREPEND(AsyncAddressResolverInfo, async_address_resolvers, client->async_address_resolvers, i);
2113 client->n_objects++;
2115 if (!(i->address_resolver = avahi_s_address_resolver_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, &a, async_address_resolver_callback, i))) {
2116 async_address_resolver_free(i);
2117 return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
2120 dbus_connection_register_object_path(c, i->path, &vtable, i);
2121 return respond_path(c, m, i->path);
2124 avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
2127 if (dbus_error_is_set(&error))
2128 dbus_error_free(&error);
2130 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
2133 void dbus_protocol_server_state_changed(AvahiServerState state) {
2140 m = dbus_message_new_signal(AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "StateChanged");
2141 t = (int32_t) state;
2142 dbus_message_append_args(m, DBUS_TYPE_INT32, &t, DBUS_TYPE_INVALID);
2143 dbus_connection_send(server->bus, m, NULL);
2144 dbus_message_unref(m);
2147 int dbus_protocol_setup(const AvahiPoll *poll_api) {
2150 static const DBusObjectPathVTable server_vtable = {
2159 dbus_error_init(&error);
2161 server = avahi_new(Server, 1);
2162 AVAHI_LLIST_HEAD_INIT(Clients, server->clients);
2163 server->current_id = 0;
2164 server->n_clients = 0;
2166 if (!(server->bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error))) {
2167 assert(dbus_error_is_set(&error));
2168 avahi_log_error("dbus_bus_get(): %s", error.message);
2172 if (avahi_dbus_connection_glue(server->bus, poll_api) < 0) {
2173 avahi_log_error("avahi_dbus_connection_glue() failed");
2177 if (dbus_bus_request_name(server->bus, AVAHI_DBUS_NAME, DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT, &error) != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
2178 if (dbus_error_is_set(&error)) {
2179 avahi_log_error("dbus_bus_request_name(): %s", error.message);
2183 avahi_log_error("Failed to acquire DBUS name '"AVAHI_DBUS_NAME"'");
2187 if (!(dbus_connection_add_filter(server->bus, msg_signal_filter_impl, (void*) poll_api, NULL))) {
2188 avahi_log_error("dbus_connection_add_filter() failed");
2192 dbus_bus_add_match(server->bus, "type='signal',""interface='" DBUS_INTERFACE_DBUS "'", &error);
2194 if (dbus_error_is_set(&error)) {
2195 avahi_log_error("dbus_bus_add_match(): %s", error.message);
2199 if (!(dbus_connection_register_object_path(server->bus, AVAHI_DBUS_PATH_SERVER, &server_vtable, NULL))) {
2200 avahi_log_error("dbus_connection_register_object_path() failed");
2208 dbus_connection_disconnect(server->bus);
2209 dbus_connection_unref(server->bus);
2212 if (dbus_error_is_set(&error))
2213 dbus_error_free(&error);
2220 void dbus_protocol_shutdown(void) {
2224 while (server->clients)
2225 client_free(server->clients);
2227 assert(server->n_clients == 0);
2230 dbus_connection_disconnect(server->bus);
2231 dbus_connection_unref(server->bus);