From 2137c8a1904f4dd738c07b8373ef1e9fce519207 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sat, 10 Sep 2005 02:22:32 +0000 Subject: [PATCH] add new API avahi_client_is_service_local() git-svn-id: file:///home/lennart/svn/public/avahi/trunk@563 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-client/client.c | 67 +++++++++++++++++++++++++++++++++++++++++++ avahi-client/client.h | 3 ++ 2 files changed, 70 insertions(+) diff --git a/avahi-client/client.c b/avahi-client/client.c index 31bfcdc..93d768a 100644 --- a/avahi-client/client.c +++ b/avahi-client/client.c @@ -644,3 +644,70 @@ fail: return AVAHI_SERVICE_COOKIE_INVALID; } + +int avahi_client_is_service_local(AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain) { + DBusMessage *message = NULL, *reply = NULL; + DBusError error; + int32_t i_interface, i_protocol; + int b; + + assert(client); + assert(name); + assert(type); + assert(domain); + + if (client->state == AVAHI_CLIENT_DISCONNECTED) { + avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE); + return AVAHI_SERVICE_COOKIE_INVALID; + } + + dbus_error_init (&error); + + if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "IsServiceLocal"))) { + avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY); + goto fail; + } + + i_interface = (int32_t) interface; + i_protocol = (int32_t) protocol; + + if (!dbus_message_append_args( + message, + DBUS_TYPE_INT32, &i_interface, + DBUS_TYPE_INT32, &i_protocol, + DBUS_TYPE_STRING, &name, + DBUS_TYPE_STRING, &type, + DBUS_TYPE_STRING, &domain, + DBUS_TYPE_INVALID)) { + avahi_client_set_errno (client, AVAHI_ERR_NO_MEMORY); + goto fail; + } + + reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error); + + if (!reply || dbus_error_is_set (&error)) + goto fail; + + if (!dbus_message_get_args (reply, &error, DBUS_TYPE_BOOLEAN, &b, DBUS_TYPE_INVALID) || + dbus_error_is_set (&error)) + goto fail; + + dbus_message_unref(message); + dbus_message_unref(reply); + + return b; + +fail: + + if (message) + dbus_message_unref(message); + if (reply) + dbus_message_unref(reply); + + if (dbus_error_is_set(&error)) { + avahi_client_set_dbus_error(client, &error); + dbus_error_free(&error); + } + + return AVAHI_SERVICE_COOKIE_INVALID; +} diff --git a/avahi-client/client.h b/avahi-client/client.h index f92f4bf..0cafed3 100644 --- a/avahi-client/client.h +++ b/avahi-client/client.h @@ -320,6 +320,9 @@ int avahi_address_resolver_free(AvahiAddressResolver *r); /** Return the local service cookie. returns AVAHI_SERVICE_COOKIE_INVALID on failure. */ uint32_t avahi_client_get_local_service_cookie(AvahiClient *client); +/** Return 1 if the specified service is a registered locally, negative on failure, 0 otherwise. */ +int avahi_client_is_service_local(AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, const char *name, const char *type, const char *domain); + #ifndef DOXYGEN_SHOULD_SKIP_THIS AVAHI_C_DECL_END #endif -- 2.39.5