summaryrefslogtreecommitdiffstats
path: root/network
diff options
context:
space:
mode:
Diffstat (limited to 'network')
-rw-r--r--network/error.c8
-rw-r--r--network/error.h7
-rw-r--r--network/server.c28
3 files changed, 37 insertions, 6 deletions
diff --git a/network/error.c b/network/error.c
index 28bd54ae..ec3f9298 100644
--- a/network/error.c
+++ b/network/error.c
@@ -60,3 +60,11 @@ DBusHandlerResult err_failed(DBusConnection *conn, DBusMessage *msg,
dbus_message_new_error(msg,
NETWORK_ERROR_INTERFACE ".Failed", str));
}
+
+DBusHandlerResult err_invalid_args(DBusConnection *conn,
+ DBusMessage *msg, const char *str)
+{
+ return send_message_and_unref(conn,
+ dbus_message_new_error(msg,
+ NETWORK_ERROR_INTERFACE ".InvalidArguments", str));
+}
diff --git a/network/error.h b/network/error.h
index 63f6ffde..e28002e7 100644
--- a/network/error.h
+++ b/network/error.h
@@ -27,8 +27,9 @@ DBusHandlerResult err_unknown_connection(DBusConnection *conn,
DBusMessage *msg);
DBusHandlerResult err_generic(DBusConnection *conn, DBusMessage *msg,
const char *name, const char *str);
-DBusHandlerResult err_does_not_exist(DBusConnection *conn, DBusMessage *msg,
- const char *str);
+DBusHandlerResult err_does_not_exist(DBusConnection *conn,
+ DBusMessage *msg, const char *str);
DBusHandlerResult err_failed(DBusConnection *conn, DBusMessage *msg,
const char *str);
-
+DBusHandlerResult err_invalid_args(DBusConnection *conn,
+ DBusMessage *msg, const char *str);
diff --git a/network/server.c b/network/server.c
index bf1e45fc..98eb83b3 100644
--- a/network/server.c
+++ b/network/server.c
@@ -75,10 +75,32 @@ static DBusHandlerResult disable(DBusConnection *conn, DBusMessage *msg,
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-static DBusHandlerResult set_name(DBusConnection *conn, DBusMessage *msg,
- void *data)
+static DBusHandlerResult set_name(DBusConnection *conn,
+ DBusMessage *msg, void *data)
{
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ struct network_server *ns = data;
+ DBusMessage *reply;
+ const char *name;
+
+ reply = dbus_message_new_method_return(msg);
+ if (!reply)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+ if (!dbus_message_get_args(msg, NULL,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_INVALID))
+ return err_invalid_args(conn, msg, "Invalid name");
+
+ if (!name || (strlen(name) == 0))
+ return err_invalid_args(conn, msg, "Invalid name");
+
+ if (ns->name)
+ g_free(ns->name);
+ ns->name = g_strdup(name);
+
+ /* FIXME: Update the service record attribute */
+
+ return send_message_and_unref(conn, reply);
}
static DBusHandlerResult get_name(DBusConnection *conn,