+ return DBUS_HANDLER_RESULT_HANDLED;
+
+fail:
+ dbus_error_free (&error);
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+/* AvahiServiceTypeBrowser */
+AvahiServiceTypeBrowser* avahi_service_type_browser_new(
+ AvahiClient *client,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ const char *domain,
+ AvahiServiceTypeBrowserCallback callback,
+ void *userdata) {
+
+ AvahiServiceTypeBrowser *b = NULL;
+ DBusMessage *message = NULL, *reply = NULL;
+ DBusError error;
+ char *path;
+ int32_t i_interface, i_protocol;
+
+ assert(client);
+ assert(callback);
+
+ dbus_error_init(&error);
+
+ if (client->state == AVAHI_CLIENT_DISCONNECTED) {
+ avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE);
+ goto fail;
+ }
+
+ if (!domain)
+ domain = "";
+
+ if (!(b = avahi_new(AvahiServiceTypeBrowser, 1))) {
+ avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
+ goto fail;
+ }
+
+ b->client = client;
+ b->callback = callback;
+ b->userdata = userdata;
+ b->path = NULL;
+
+ AVAHI_LLIST_PREPEND(AvahiServiceTypeBrowser, service_type_browsers, client->service_type_browsers, b);
+
+ if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "ServiceTypeBrowserNew"))) {
+ avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
+ goto fail;
+ }
+
+ i_interface = interface;
+ i_protocol = protocol;
+
+ if (!dbus_message_append_args(
+ message,
+ DBUS_TYPE_INT32, &interface,
+ DBUS_TYPE_INT32, &protocol,
+ DBUS_TYPE_STRING, &domain,
+ DBUS_TYPE_INVALID)) {
+ avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
+ goto fail;
+ }
+
+ if (!(reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error)) ||
+ dbus_error_is_set(&error)) {
+ avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
+ goto fail;
+ }
+
+ if (!dbus_message_get_args (reply, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID) ||
+ dbus_error_is_set(&error) ||
+ !path) {
+ avahi_client_set_errno(client, AVAHI_ERR_DBUS_ERROR);
+ goto fail;
+ }
+
+ if (!(b->path = avahi_strdup(path))) {
+
+ /* FIXME: We don't remove the object on the server side */
+
+ avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
+ goto fail;
+ }
+
+ dbus_message_unref(message);
+ dbus_message_unref(reply);
+
+ return b;
+
+fail:
+
+ if (dbus_error_is_set(&error)) {
+ avahi_client_set_dbus_error(client, &error);
+ dbus_error_free(&error);
+ }
+
+ if (b)
+ avahi_service_type_browser_free(b);
+
+ if (message)
+ dbus_message_unref(message);
+
+ if (reply)
+ dbus_message_unref(reply);
+
+ return NULL;
+}
+
+AvahiClient* avahi_service_type_browser_get_client (AvahiServiceTypeBrowser *b)
+{
+ assert(b);
+ return b->client;
+}
+
+int avahi_service_type_browser_free (AvahiServiceTypeBrowser *b) {
+ AvahiClient *client;
+ int r = AVAHI_OK;
+
+ assert(b);
+ client = b->client;
+
+ if (b->path && client->state != AVAHI_CLIENT_DISCONNECTED)
+ r = avahi_client_simple_method_call(client, b->path, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "Free");
+
+ AVAHI_LLIST_REMOVE(AvahiServiceTypeBrowser, service_type_browsers, b->client->service_type_browsers, b);
+
+ avahi_free(b->path);
+ avahi_free(b);
+ return r;
+}
+
+DBusHandlerResult avahi_service_type_browser_event (AvahiClient *client, AvahiBrowserEvent event, DBusMessage *message) {
+ AvahiServiceTypeBrowser *b = NULL;
+ DBusError error;
+ const char *path;
+ char *domain, *type;
+ int32_t interface, protocol;
+
+ assert(client);
+ assert(message);
+
+ dbus_error_init (&error);
+
+ if (!(path = dbus_message_get_path(message)))
+ goto fail;
+
+ for (b = client->service_type_browsers; b; b = b->service_type_browsers_next)
+ if (strcmp (b->path, path) == 0)