~ubuntu-branches/ubuntu/jaunty/avahi/jaunty-updates

« back to all changes in this revision

Viewing changes to avahi-client/client.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-09-03 20:25:37 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20060903202537-syi99j0tijm9bldv
Tags: 0.6.13-2ubuntu1
* Merge with Debian, UVF Exception granted by Colin Watson
* debian/patches/03_foreground-console.patch:
  + Allow only foreground users access to the avahi-set-host-name utility as
    we don't use the "netdev" group anywhere. Thanks to Colin Watson for the
    hint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: client.c 1238 2006-07-18 22:25:22Z lathiat $ */
 
1
/* $Id: client.c 1261 2006-08-22 02:15:27Z lennart $ */
2
2
 
3
3
/***
4
4
  This file is part of avahi.
875
875
        dbus_connection_get_is_connected(client->bus) &&
876
876
        (client->state == AVAHI_CLIENT_S_RUNNING || client->state == AVAHI_CLIENT_S_REGISTERING || client->state == AVAHI_CLIENT_S_COLLISION);
877
877
}
 
878
 
 
879
int avahi_client_set_host_name(AvahiClient* client, const char *name) {
 
880
    DBusMessage *message = NULL, *reply = NULL;
 
881
    DBusError error;
 
882
 
 
883
    assert(client);
 
884
    
 
885
    if (!avahi_client_is_connected(client))
 
886
        return avahi_client_set_errno(client, AVAHI_ERR_BAD_STATE);
 
887
 
 
888
    dbus_error_init (&error);
 
889
 
 
890
    if (!(message = dbus_message_new_method_call (AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "SetHostName"))) {
 
891
        avahi_client_set_errno(client, AVAHI_ERR_NO_MEMORY);
 
892
        goto fail;
 
893
    }
 
894
 
 
895
    if (!dbus_message_append_args (message, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) {
 
896
        avahi_client_set_errno (client, AVAHI_ERR_NO_MEMORY);
 
897
        goto fail;
 
898
    }
 
899
    
 
900
    reply = dbus_connection_send_with_reply_and_block(client->bus, message, -1, &error);
 
901
 
 
902
    if (!reply || dbus_error_is_set (&error))
 
903
        goto fail;
 
904
 
 
905
    if (!dbus_message_get_args(reply, &error, DBUS_TYPE_INVALID) ||
 
906
        dbus_error_is_set (&error))
 
907
        goto fail;
 
908
 
 
909
    dbus_message_unref(message);
 
910
    dbus_message_unref(reply);
 
911
 
 
912
    avahi_free(client->host_name);
 
913
    client->host_name = NULL;
 
914
    avahi_free(client->host_name_fqdn);
 
915
    client->host_name_fqdn = NULL;
 
916
    
 
917
    return 0;
 
918
 
 
919
fail:
 
920
 
 
921
    if (message)
 
922
        dbus_message_unref(message);
 
923
    if (reply)
 
924
        dbus_message_unref(reply);
 
925
    
 
926
    if (dbus_error_is_set(&error)) {
 
927
        avahi_client_set_dbus_error(client, &error);
 
928
        dbus_error_free(&error);
 
929
    }
 
930
 
 
931
    return client->error;
 
932
}