+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddService")) {
+ gint32 interface, protocol;
+ gchar *type, *name, *domain, *host;
+ guint16 port;
+ gchar **txt = NULL;
+ gint txt_len;
+ AvahiStringList *strlst;
+
+ if (!dbus_message_get_args(
+ m, &error,
+ DBUS_TYPE_INT32, &interface,
+ DBUS_TYPE_INT32, &protocol,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_STRING, &type,
+ DBUS_TYPE_STRING, &domain,
+ DBUS_TYPE_STRING, &host,
+ DBUS_TYPE_UINT16, &port,
+ DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &txt, &txt_len,
+ DBUS_TYPE_INVALID) || !type || !*type || !name || !*name || !port) {
+ avahi_log_warn("Error parsing EntryGroup::AddService message");
+ goto fail;
+ }
+
+ strlst = avahi_string_list_new_from_array((const gchar**) txt, txt_len);
+ dbus_free_string_array(txt);
+
+ if (domain && !*domain)
+ domain = NULL;
+
+ if (host && !*host)
+ host = NULL;
+
+ if (avahi_server_add_service_strlst(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, name, type, domain, host, port, strlst) < 0) {
+ avahi_log_warn("Failed to add service: %s", name);
+ return respond_error(c, m, "org.freedesktop.Avahi.InvalidServiceError", NULL);
+ } /* else */
+/* avahi_log_info("Successfully added service: %s", name); */
+
+ return respond_ok(c, m);
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddAddress")) {
+ gint32 interface, protocol;
+ gchar *name, *address;
+ AvahiAddress a;
+
+ if (!dbus_message_get_args(
+ m, &error,
+ DBUS_TYPE_INT32, &interface,
+ DBUS_TYPE_INT32, &protocol,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_STRING, &address,
+ DBUS_TYPE_INVALID) || !name || !*name || !address || !*address) {
+ avahi_log_warn("Error parsing EntryGroup::AddAddress message");
+ goto fail;
+ }
+
+ if (!(avahi_address_parse(address, AVAHI_PROTO_UNSPEC, &a))) {
+ avahi_log_warn("Error parsing address data");
+ return respond_error(c, m, "org.freedesktop.Avahi.InvalidAddressError", NULL);
+ }
+
+ if (avahi_server_add_address(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, 0, name, &a) < 0) {
+ avahi_log_warn("Failed to add service: %s", name);
+ return respond_error(c, m, "org.freedesktop.Avahi.InvalidAddressError", NULL);
+ }/* else */
+/* avahi_log_info("Successfully added address: %s -> %s", name, address); */
+
+ return respond_ok(c, m);
+ }
+
+ avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
+
+fail:
+ if (dbus_error_is_set(&error))
+ dbus_error_free(&error);
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static void host_name_resolver_callback(AvahiHostNameResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const gchar *host_name, const AvahiAddress *a, gpointer userdata) {
+ HostNameResolverInfo *i = userdata;
+ DBusMessage *reply;
+
+ g_assert(r);
+ g_assert(host_name);
+ g_assert(i);
+
+ if (event == AVAHI_RESOLVER_FOUND) {
+ char t[256], *pt = t;
+ gint32 i_interface, i_protocol, i_aprotocol;
+
+ g_assert(a);
+ avahi_address_snprint(t, sizeof(t), a);
+
+ i_interface = (gint32) interface;
+ i_protocol = (gint32) protocol;
+ i_aprotocol = (gint32) a->family;
+
+ reply = dbus_message_new_method_return(i->message);
+ dbus_message_append_args(
+ reply,
+ DBUS_TYPE_INT32, &i_interface,
+ DBUS_TYPE_INT32, &i_protocol,
+ DBUS_TYPE_STRING, &host_name,
+ DBUS_TYPE_INT32, &i_aprotocol,
+ DBUS_TYPE_STRING, &pt,
+ DBUS_TYPE_INVALID);
+
+ } else {
+ g_assert(event == AVAHI_RESOLVER_TIMEOUT);
+ reply = dbus_message_new_error(i->message, "org.freedesktop.Avahi.TimeoutError", NULL);
+ }
+
+ dbus_connection_send(server->bus, reply, NULL);
+ dbus_message_unref(reply);
+
+ host_name_resolver_free(i);
+}
+
+static void address_resolver_callback(AvahiAddressResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const AvahiAddress *address, const gchar *host_name, gpointer userdata) {
+ AddressResolverInfo *i = userdata;
+ DBusMessage *reply;
+
+ g_assert(r);
+ g_assert(address);
+ g_assert(i);
+
+ if (event == AVAHI_RESOLVER_FOUND) {
+ char t[256], *pt = t;
+ gint32 i_interface, i_protocol, i_aprotocol;
+
+ g_assert(host_name);
+ avahi_address_snprint(t, sizeof(t), address);
+
+ i_interface = (gint32) interface;
+ i_protocol = (gint32) protocol;
+ i_aprotocol = (gint32) address->family;
+
+ reply = dbus_message_new_method_return(i->message);
+ dbus_message_append_args(
+ reply,
+ DBUS_TYPE_INT32, &i_interface,
+ DBUS_TYPE_INT32, &i_protocol,
+ DBUS_TYPE_INT32, &i_aprotocol,
+ DBUS_TYPE_STRING, &pt,
+ DBUS_TYPE_STRING, &host_name,
+ DBUS_TYPE_INVALID);
+
+ } else {
+ g_assert(event == AVAHI_RESOLVER_TIMEOUT);
+ reply = dbus_message_new_error(i->message, "org.freedesktop.Avahi.TimeoutError", NULL);
+ }
+
+ dbus_connection_send(server->bus, reply, NULL);
+ dbus_message_unref(reply);
+
+ address_resolver_free(i);
+}
+
+static DBusHandlerResult msg_domain_browser_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
+ DBusError error;
+ DomainBrowserInfo *i = userdata;
+
+ g_assert(c);
+ g_assert(m);
+ g_assert(i);
+
+ 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));
+
+ /* Introspection */
+ if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
+ return handle_introspect(c, m, "DomainBrowser.introspect");
+
+ /* Access control */
+ if (strcmp(dbus_message_get_sender(m), i->client->name))
+ return respond_error(c, m, DBUS_ERROR_ACCESS_DENIED, NULL);
+
+ if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, "Free")) {
+
+ if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
+ avahi_log_warn("Error parsing DomainBrowser::Free message");
+ goto fail;
+ }
+
+ domain_browser_free(i);
+ return respond_ok(c, m);
+