]> git.meshlink.io Git - catta/commitdiff
implement avahi_client_set_host_name() as wrapper around the new DBUS function o...
authorLennart Poettering <lennart@poettering.net>
Tue, 22 Aug 2006 02:15:27 +0000 (02:15 +0000)
committerLennart Poettering <lennart@poettering.net>
Tue, 22 Aug 2006 02:15:27 +0000 (02:15 +0000)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1261 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

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

index 0913847b7abe6b6f1c5fa9a7efb6f8cf6e1f8759..825e88f301e53fd82b2f8b8d849d46bfffa68ed3 100644 (file)
@@ -875,3 +875,58 @@ int avahi_client_is_connected(AvahiClient *client) {
         dbus_connection_get_is_connected(client->bus) &&
         (client->state == AVAHI_CLIENT_S_RUNNING || client->state == AVAHI_CLIENT_S_REGISTERING || client->state == AVAHI_CLIENT_S_COLLISION);
 }
+
+int avahi_client_set_host_name(AvahiClient* client, const char *name) {
+    DBusMessage *message = NULL, *reply = NULL;
+    DBusError error;
+
+    assert(client);
+    
+    if (!avahi_client_is_connected(client))
+        return avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE);
+
+    dbus_error_init (&error);
+
+    if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "SetHostName"))) {
+        avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
+        goto fail;
+    }
+
+    if (!dbus_message_append_args (message, DBUS_TYPE_STRING, &name, 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_INVALID) ||
+        dbus_error_is_set (&error))
+        goto fail;
+
+    dbus_message_unref(message);
+    dbus_message_unref(reply);
+
+    avahi_free(client->host_name);
+    client->host_name = NULL;
+    avahi_free(client->host_name_fqdn);
+    client->host_name_fqdn = NULL;
+    
+    return 0;
+
+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 client->error;
+}
index e15c1303be94d1c695a63cb0062477f9f93e75b5..f102f05934b3d55f32aebb85b7728ae41767b003 100644 (file)
@@ -77,6 +77,9 @@ const char* avahi_client_get_version_string (AvahiClient*);
 /** Get host name */
 const char* avahi_client_get_host_name (AvahiClient*);
 
+/** Set host name. \since 0.6.13 */
+int avahi_client_set_host_name(AvahiClient*, const char *name);
+
 /** Get domain name */
 const char* avahi_client_get_domain_name (AvahiClient*);