]> git.meshlink.io Git - catta/commitdiff
add new API avahi_client_is_service_local()
authorLennart Poettering <lennart@poettering.net>
Sat, 10 Sep 2005 02:22:32 +0000 (02:22 +0000)
committerLennart Poettering <lennart@poettering.net>
Sat, 10 Sep 2005 02:22:32 +0000 (02:22 +0000)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@563 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-client/client.c
avahi-client/client.h

index 31bfcdcf57b41d1f4f6000ee4c49eeddc13b5835..93d768a85bef970558ccc8959fa57a1110f1991a 100644 (file)
@@ -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;
+}
index f92f4bff53df5afdf2f81f97362377da184a0e90..0cafed323459607763d99d3be1e3ab3feb7450a1 100644 (file)
@@ -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