+ dbus_connection_send(server->bus, reply, NULL);
+ dbus_message_unref(reply);
+
+ service_resolver_free(i);
+}
+
+
+static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
+ DBusError error;
+
+ dbus_error_init(&error);
+
+ avahi_log_debug("dbus: 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 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 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 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 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 respond_string(c, m, PACKAGE_STRING);
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetState")) {
+ DBusMessage *reply;
+ gint32 s;
+
+ if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INVALID))) {
+ avahi_log_warn("Error parsing Server::GetState message");
+ goto fail;
+ }
+
+ s = (gint32) avahi_server_get_state(avahi_server);
+
+ reply = dbus_message_new_method_return(m);
+ dbus_message_append_args(reply, DBUS_TYPE_INT32, &s, DBUS_TYPE_INVALID);
+ dbus_connection_send(c, reply, NULL);
+ dbus_message_unref(reply);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetAlternativeHostName")) {
+ gchar *n, * t;
+
+ if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n || !*n) {
+ avahi_log_warn("Error parsing Server::GetAlternativeHostName message");
+ goto fail;
+ }
+
+ t = avahi_alternative_host_name(n);
+ respond_string(c, m, t);
+ g_free(t);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetAlternativeServiceName")) {
+ gchar *n, *t;
+
+ if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n || !*n) {
+ avahi_log_warn("Error parsing Server::GetAlternativeServiceName message");
+ goto fail;
+ }
+
+ t = avahi_alternative_service_name(n);
+ respond_string(c, m, t);
+ g_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,
+ 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 (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
+ avahi_log_warn("Too many clients, client request failed.");
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_CLIENTS, NULL);
+ }
+
+ if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
+ avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_OBJECTS, NULL);
+ }
+
+ i = g_new(EntryGroupInfo, 1);
+ i->id = ++client->current_id;
+ i->client = client;
+ i->path = g_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_entry_group_new(avahi_server, entry_group_callback, i))) {
+ avahi_log_warn("Failed to create entry group");
+ entry_group_free(i);
+ goto fail;
+ }
+
+ dbus_connection_register_object_path(c, i->path, &vtable, i);
+ return respond_path(c, m, i->path);
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ResolveHostName")) {
+ Client *client;
+ gint32 interface, protocol, aprotocol;
+ gchar *name;
+ HostNameResolverInfo *i;
+
+ if (!dbus_message_get_args(
+ m, &error,
+ DBUS_TYPE_INT32, &interface,
+ DBUS_TYPE_INT32, &protocol,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_INT32, &aprotocol,
+ DBUS_TYPE_INVALID) || !name || !*name) {
+ avahi_log_warn("Error parsing Server::ResolveHostName message");
+ goto fail;
+ }
+
+ if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
+ avahi_log_warn("Too many clients, client request failed.");
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_CLIENTS, NULL);
+ }
+
+ if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
+ avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_OBJECTS, NULL);
+ }
+
+ i = g_new(HostNameResolverInfo, 1);
+ i->client = client;
+ i->message = dbus_message_ref(m);
+ AVAHI_LLIST_PREPEND(HostNameResolverInfo, host_name_resolvers, client->host_name_resolvers, i);
+ client->n_objects++;
+
+ if (!(i->host_name_resolver = avahi_host_name_resolver_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, name, (AvahiProtocol) aprotocol, host_name_resolver_callback, i))) {
+ host_name_resolver_free(i);
+ avahi_log_warn("Failed to create host name resolver");
+ goto fail;
+ }
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ResolveAddress")) {
+ Client *client;
+ gint32 interface, protocol;
+ gchar *address;
+ AddressResolverInfo *i;
+ AvahiAddress a;
+
+ if (!dbus_message_get_args(
+ m, &error,
+ DBUS_TYPE_INT32, &interface,
+ DBUS_TYPE_INT32, &protocol,
+ DBUS_TYPE_STRING, &address,
+ DBUS_TYPE_INVALID) || !address || !*address) {
+ avahi_log_warn("Error parsing Server::ResolveAddress message");
+ goto fail;
+ }
+
+ if (!avahi_address_parse(address, AVAHI_PROTO_UNSPEC, &a)) {
+ avahi_log_warn("Error parsing address data");
+ return respond_error(c, m, AVAHI_DBUS_ERROR_INVALID_ADDRESS, NULL);
+ }
+
+ if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
+ avahi_log_warn("Too many clients, client request failed.");
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_CLIENTS, NULL);
+ }
+
+ if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
+ avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_OBJECTS, NULL);
+ }
+
+ i = g_new(AddressResolverInfo, 1);
+ i->client = client;
+ i->message = dbus_message_ref(m);
+ AVAHI_LLIST_PREPEND(AddressResolverInfo, address_resolvers, client->address_resolvers, i);
+ client->n_objects++;
+
+ if (!(i->address_resolver = avahi_address_resolver_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, &a, address_resolver_callback, i))) {
+ address_resolver_free(i);
+ avahi_log_warn("Failed to create address resolver");
+ goto fail;
+ }
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "DomainBrowserNew")) {
+ Client *client;
+ DomainBrowserInfo *i;
+ static const DBusObjectPathVTable vtable = {
+ NULL,
+ msg_domain_browser_impl,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+ };
+ gint32 interface, protocol, type;
+ gchar *domain;
+
+
+ if (!dbus_message_get_args(
+ m, &error,
+ DBUS_TYPE_INT32, &interface,
+ DBUS_TYPE_INT32, &protocol,
+ DBUS_TYPE_STRING, &domain,
+ DBUS_TYPE_INT32, &type,
+ DBUS_TYPE_INVALID) || type < 0 || type >= AVAHI_DOMAIN_BROWSER_MAX) {
+ avahi_log_warn("Error parsing Server::DomainBrowserNew message");
+ goto fail;
+ }
+
+ if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
+ avahi_log_warn("Too many clients, client request failed.");
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_CLIENTS, NULL);
+ }
+
+ if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
+ avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
+ return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_OBJECTS, NULL);
+ }
+
+ if (!*domain)
+ domain = NULL;