+
+ } else if (dbus_message_is_signal(m, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
+ char *name, *old, *new;
+
+ if (!dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &old, DBUS_TYPE_STRING, &new, DBUS_TYPE_INVALID)) {
+ avahi_log_warn("Error parsing NameOwnerChanged message");
+ goto fail;
+ }
+
+ if (!*new) {
+ Client *client;
+
+ if ((client = client_get(name, FALSE))) {
+ avahi_log_debug(__FILE__": client %s vanished.", name);
+ client_free(client);
+ }
+ }
+ }
+
+fail:
+ if (dbus_error_is_set(&error))
+ dbus_error_free(&error);
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAHI_GCC_UNUSED void *userdata) {
+ DBusError error;
+
+ dbus_error_init(&error);
+
+ avahi_log_debug(__FILE__": interface=%s, path=%s, member=%s",
+ dbus_message_get_interface(m),
+ dbus_message_get_path(m),
+ dbus_message_get_member(m));
+
+ if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
+ return avahi_dbus_handle_introspect(c, m, "Server.introspect");
+
+ else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetHostName")) {
+
+ if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
+ avahi_log_warn("Error parsing Server::GetHostName message");
+ goto fail;
+ }
+
+ return avahi_dbus_respond_string(c, m, avahi_server_get_host_name(avahi_server));
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetDomainName")) {
+
+ if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
+ avahi_log_warn("Error parsing Server::GetDomainName message");
+ goto fail;
+ }
+
+ return avahi_dbus_respond_string(c, m, avahi_server_get_domain_name(avahi_server));
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetHostNameFqdn")) {
+
+ if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INVALID))) {
+ avahi_log_warn("Error parsing Server::GetHostNameFqdn message");
+ goto fail;
+ }
+
+ return avahi_dbus_respond_string(c, m, avahi_server_get_host_name_fqdn(avahi_server));
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetVersionString")) {
+
+ if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INVALID))) {
+ avahi_log_warn("Error parsing Server::GetVersionString message");
+ goto fail;
+ }
+
+ return avahi_dbus_respond_string(c, m, PACKAGE_STRING);
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetState")) {
+ AvahiServerState state;
+
+ if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INVALID))) {
+ avahi_log_warn("Error parsing Server::GetState message");
+ goto fail;
+ }
+
+ state = avahi_server_get_state(avahi_server);
+ return avahi_dbus_respond_int32(c, m, (int32_t) state);
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetLocalServiceCookie")) {
+
+ if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INVALID))) {
+ avahi_log_warn("Error parsing Server::GetLocalServiceCookie message");
+ goto fail;
+ }
+
+ return avahi_dbus_respond_uint32(c, m, avahi_server_get_local_service_cookie(avahi_server));
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetNetworkInterfaceNameByIndex")) {
+ int32_t idx;
+ int fd;
+ char name[IF_NAMESIZE];
+
+
+ if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INT32, &idx, DBUS_TYPE_INVALID))) {
+ avahi_log_warn("Error parsing Server::GetNetworkInterfaceNameByIndex message");
+ goto fail;
+ }
+
+#ifdef VALGRIND_WORKAROUND
+ return respond_string(c, m, "blah");
+#else
+
+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
+ char txt[256];
+ snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
+ return avahi_dbus_respond_error(c, m, AVAHI_ERR_OS, txt);
+ }
+
+ if ((!if_indextoname(idx, name))) {
+ char txt[256];
+ snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
+ close(fd);
+ return avahi_dbus_respond_error(c, m, AVAHI_ERR_OS, txt);
+ }
+
+ close(fd);
+
+ return avahi_dbus_respond_string(c, m, name);
+#endif
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetNetworkInterfaceIndexByName")) {
+ char *n;
+ int fd;
+ int32_t idx;
+
+ if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n) {
+ avahi_log_warn("Error parsing Server::GetNetworkInterfaceIndexByName message");
+ goto fail;
+ }
+
+#ifdef VALGRIND_WORKAROUND
+ return respond_int32(c, m, 1);
+#else
+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+ if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
+ char txt[256];
+ snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
+ return avahi_dbus_respond_error(c, m, AVAHI_ERR_OS, txt);
+ }
+
+ if (!(idx = if_nametoindex(n))) {
+ char txt[256];
+ snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
+ close(fd);
+ return avahi_dbus_respond_error(c, m, AVAHI_ERR_OS, txt);
+ }
+
+ close(fd);
+
+ return avahi_dbus_respond_int32(c, m, idx);
+#endif
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetAlternativeHostName")) {
+ char *n, * t;
+
+ if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n) {
+ avahi_log_warn("Error parsing Server::GetAlternativeHostName message");
+ goto fail;
+ }
+
+ t = avahi_alternative_host_name(n);
+ avahi_dbus_respond_string(c, m, t);
+ avahi_free(t);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetAlternativeServiceName")) {
+ char *n, *t;
+
+ if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n) {
+ avahi_log_warn("Error parsing Server::GetAlternativeServiceName message");
+ goto fail;
+ }
+
+ t = avahi_alternative_service_name(n);
+ avahi_dbus_respond_string(c, m, t);
+ avahi_free(t);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "EntryGroupNew")) {
+ Client *client;
+ EntryGroupInfo *i;
+ static const DBusObjectPathVTable vtable = {
+ NULL,
+ avahi_dbus_msg_entry_group_impl,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+ };
+
+ if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
+ avahi_log_warn("Error parsing Server::EntryGroupNew message");
+ goto fail;
+ }
+
+ if (disable_user_service_publishing)
+ return avahi_dbus_respond_error(c, m, AVAHI_ERR_NOT_PERMITTED, NULL);
+
+ if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
+ avahi_log_warn("Too many clients, client request failed.");
+ return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
+ }
+
+ if (client->n_objects >= OBJECTS_PER_CLIENT_MAX) {
+ avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
+ return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
+ }
+
+ i = avahi_new(EntryGroupInfo, 1);
+ i->id = ++client->current_id;
+ i->client = client;
+ i->path = avahi_strdup_printf("/Client%u/EntryGroup%u", client->id, i->id);
+ i->n_entries = 0;
+ AVAHI_LLIST_PREPEND(EntryGroupInfo, entry_groups, client->entry_groups, i);
+ client->n_objects++;
+
+ if (!(i->entry_group = avahi_s_entry_group_new(avahi_server, avahi_dbus_entry_group_callback, i))) {
+ avahi_dbus_entry_group_free(i);
+ return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL);
+ }
+
+ dbus_connection_register_object_path(c, i->path, &vtable, i);
+ return avahi_dbus_respond_path(c, m, i->path);
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ResolveHostName")) {
+ Client *client;
+ int32_t interface, protocol, aprotocol;
+ uint32_t flags;