summaryrefslogtreecommitdiffstats
path: root/src/monitor
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2014-01-17 12:54:42 +0100
committerJakub Hrozek <jhrozek@redhat.com>2014-03-14 13:42:17 +0100
commitd9577dbd92555b0755881e37724019ef9c578404 (patch)
tree243d1ee45c7f8d0a7f30750bbb7cfd93983e6182 /src/monitor
parent5bad17538eab85ce69e0355cd25b52b4a473cc36 (diff)
downloadsssd-d9577dbd92555b0755881e37724019ef9c578404.tar.gz
sssd-d9577dbd92555b0755881e37724019ef9c578404.tar.xz
sssd-d9577dbd92555b0755881e37724019ef9c578404.zip
sbus: Add struct sbus_request to represent a DBus invocation
struct sbus_request represents a request from a dbus client being handled by a dbus server implementation. The struct contains the message, connection and method (and in the future teh property) which is being requested. In the future it will contain caller information as well. sbus_request is a talloc memory context, and is a good place to attach any allocations and memory specific to the request. Each handler accepts an sbus_request. If a handler returns EOK, it is assumed that the handler will finish the request. Any of the sbus_request_*finish() methods can be used to complete the request and send back a reply. sbus_request_return_and_finish() uses the same argument varargs syntax as dbus_message_append_args(), which isn't a great syntax. Document it a bit, but don't try to redesign: The marshalling work (will follow this patch set) will remove the need to use varargs for most DBus implementation code. This patch migrates the monitor and data provider dbus code to use sbus_request, but does not try to rework the talloc context's to use it. Reviewed-by: Jakub Hrozek <jhrozek@redhat.com> Reviewed-by: Pavel Březina <pbrezina@redhat.com> Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
Diffstat (limited to 'src/monitor')
-rw-r--r--src/monitor/monitor.c54
-rw-r--r--src/monitor/monitor_interfaces.h6
-rw-r--r--src/monitor/monitor_sbus.c26
3 files changed, 20 insertions, 66 deletions
diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
index ecfa95cfd..2e0f5230f 100644
--- a/src/monitor/monitor.c
+++ b/src/monitor/monitor.c
@@ -217,28 +217,13 @@ static void network_status_change_cb(void *cb_data)
/* dbus_get_monitor_version
* Return the monitor version over D-BUS */
-static int get_monitor_version(DBusMessage *message,
- struct sbus_connection *conn)
+static int get_monitor_version(struct sbus_request *dbus_req)
{
dbus_uint16_t version = MONITOR_VERSION;
- DBusMessage *reply;
- dbus_bool_t ret;
- reply = dbus_message_new_method_return(message);
- if (!reply) return ENOMEM;
- ret = dbus_message_append_args(reply,
- DBUS_TYPE_UINT16, &version,
- DBUS_TYPE_INVALID);
- if (!ret) {
- dbus_message_unref(reply);
- return EIO;
- }
-
- /* send reply back */
- sbus_conn_send_reply(conn, reply);
- dbus_message_unref(reply);
-
- return EOK;
+ return sbus_request_return_and_finish(dbus_req,
+ DBUS_TYPE_UINT16, &version,
+ DBUS_TYPE_INVALID);
}
struct mon_init_conn {
@@ -251,21 +236,19 @@ static int add_svc_conn_spy(struct mt_svc *svc);
/* registers a new client.
* if operation is successful also sends back the Monitor version */
-static int client_registration(DBusMessage *message,
- struct sbus_connection *conn)
+static int client_registration(struct sbus_request *dbus_req)
{
dbus_uint16_t version = MONITOR_VERSION;
struct mon_init_conn *mini;
struct mt_svc *svc;
void *data;
- DBusMessage *reply;
DBusError dbus_error;
dbus_uint16_t svc_ver;
char *svc_name;
dbus_bool_t dbret;
int ret;
- data = sbus_conn_get_private_data(conn);
+ data = sbus_conn_get_private_data(dbus_req->conn);
mini = talloc_get_type(data, struct mon_init_conn);
if (!mini) {
DEBUG(SSSDBG_FATAL_FAILURE, "Connection holds no valid init data\n");
@@ -277,7 +260,7 @@ static int client_registration(DBusMessage *message,
dbus_error_init(&dbus_error);
- dbret = dbus_message_get_args(message, &dbus_error,
+ dbret = dbus_message_get_args(dbus_req->message, &dbus_error,
DBUS_TYPE_STRING, &svc_name,
DBUS_TYPE_UINT16, &svc_ver,
DBUS_TYPE_INVALID);
@@ -285,7 +268,8 @@ static int client_registration(DBusMessage *message,
DEBUG(SSSDBG_CRIT_FAILURE,
"Failed to parse message, killing connection\n");
if (dbus_error_is_set(&dbus_error)) dbus_error_free(&dbus_error);
- sbus_disconnect(conn);
+ sbus_disconnect(dbus_req->conn);
+ sbus_request_finish(dbus_req, NULL);
/* FIXME: should we just talloc_zfree(conn) ? */
goto done;
}
@@ -306,7 +290,8 @@ static int client_registration(DBusMessage *message,
DEBUG(SSSDBG_FATAL_FAILURE,
"Unable to find peer [%s] in list of services,"
" killing connection!\n", svc_name);
- sbus_disconnect(conn);
+ sbus_disconnect(dbus_req->conn);
+ sbus_request_finish(dbus_req, NULL);
/* FIXME: should we just talloc_zfree(conn) ? */
goto done;
}
@@ -321,20 +306,9 @@ static int client_registration(DBusMessage *message,
}
/* reply that all is ok */
- reply = dbus_message_new_method_return(message);
- if (!reply) return ENOMEM;
-
- dbret = dbus_message_append_args(reply,
- DBUS_TYPE_UINT16, &version,
- DBUS_TYPE_INVALID);
- if (!dbret) {
- dbus_message_unref(reply);
- return EIO;
- }
-
- /* send reply back */
- sbus_conn_send_reply(conn, reply);
- dbus_message_unref(reply);
+ sbus_request_return_and_finish(dbus_req,
+ DBUS_TYPE_UINT16, &version,
+ DBUS_TYPE_INVALID);
done:
/* init complete, get rid of temp init context */
diff --git a/src/monitor/monitor_interfaces.h b/src/monitor/monitor_interfaces.h
index ef4254a5f..2970251df 100644
--- a/src/monitor/monitor_interfaces.h
+++ b/src/monitor/monitor_interfaces.h
@@ -38,10 +38,8 @@
int monitor_get_sbus_address(TALLOC_CTX *mem_ctx, char **address);
int monitor_common_send_id(struct sbus_connection *conn,
const char *name, uint16_t version);
-int monitor_common_pong(DBusMessage *message,
- struct sbus_connection *conn);
-int monitor_common_res_init(DBusMessage *message,
- struct sbus_connection *conn);
+int monitor_common_pong(struct sbus_request *dbus_req);
+int monitor_common_res_init(struct sbus_request *dbus_req);
int monitor_common_rotate_logs(struct confdb_ctx *confdb,
const char *conf_entry);
diff --git a/src/monitor/monitor_sbus.c b/src/monitor/monitor_sbus.c
index b1550bcdd..92d483233 100644
--- a/src/monitor/monitor_sbus.c
+++ b/src/monitor/monitor_sbus.c
@@ -144,30 +144,12 @@ int monitor_common_send_id(struct sbus_connection *conn,
return retval;
}
-int monitor_common_pong(DBusMessage *message,
- struct sbus_connection *conn)
+int monitor_common_pong(struct sbus_request *dbus_req)
{
- DBusMessage *reply;
- dbus_bool_t ret;
-
- reply = dbus_message_new_method_return(message);
- if (!reply) return ENOMEM;
-
- ret = dbus_message_append_args(reply, DBUS_TYPE_INVALID);
- if (!ret) {
- dbus_message_unref(reply);
- return EIO;
- }
-
- /* send reply back */
- sbus_conn_send_reply(conn, reply);
- dbus_message_unref(reply);
-
- return EOK;
+ return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
}
-int monitor_common_res_init(DBusMessage *message,
- struct sbus_connection *conn)
+int monitor_common_res_init(struct sbus_request *dbus_req)
{
int ret;
@@ -177,7 +159,7 @@ int monitor_common_res_init(DBusMessage *message,
}
/* Send an empty reply to acknowledge receipt */
- return monitor_common_pong(message, conn);
+ return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
}
errno_t monitor_common_rotate_logs(struct confdb_ctx *confdb,