diff options
author | Stef Walter <stefw@gnome.org> | 2014-01-17 12:54:42 +0100 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2014-06-02 19:03:26 +0200 |
commit | 0a001b42869ebffdd6d82ca3a3fdbe31dc707035 (patch) | |
tree | 6eb620fa58c7536a4085e392c0d9f0367fce7383 /src/sbus/sssd_dbus_connection.c | |
parent | 4221bd76e2b631684f2dc7e8c625fd7b27947cf8 (diff) | |
download | sssd-0a001b42869ebffdd6d82ca3a3fdbe31dc707035.tar.gz sssd-0a001b42869ebffdd6d82ca3a3fdbe31dc707035.tar.xz sssd-0a001b42869ebffdd6d82ca3a3fdbe31dc707035.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>
(cherry picked from commit d9577dbd92555b0755881e37724019ef9c578404)
Conflicts:
src/sbus/sssd_dbus.h
Diffstat (limited to 'src/sbus/sssd_dbus_connection.c')
-rw-r--r-- | src/sbus/sssd_dbus_connection.c | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/src/sbus/sssd_dbus_connection.c b/src/sbus/sssd_dbus_connection.c index e3f5e163d..6535bc90e 100644 --- a/src/sbus/sssd_dbus_connection.c +++ b/src/sbus/sssd_dbus_connection.c @@ -415,7 +415,9 @@ DBusHandlerResult sbus_message_handler(DBusConnection *dbus_conn, DBusMessage *reply = NULL; const struct sbus_method_meta *method; const struct sbus_interface_meta *interface; - sbus_msg_handler_fn handler_fn; + struct sbus_request *dbus_req = NULL; + sbus_msg_handler_fn handler_fn = NULL; + DBusHandlerResult result; int ret; if (!user_data) { @@ -435,10 +437,11 @@ DBusHandlerResult sbus_message_handler(DBusConnection *dbus_conn, if (strcmp(path, intf_p->intf->path) != 0) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + /* Validate the method interface */ interface = intf_p->intf->vtable->meta; if (strcmp(msg_interface, interface->name) == 0) { - handler_fn = NULL; method = sbus_meta_find_method(interface, msg_method); if (method && method->vtable_offset) handler_fn = VTABLE_FUNC(intf_p->intf->vtable, method->vtable_offset); @@ -450,6 +453,7 @@ DBusHandlerResult sbus_message_handler(DBusConnection *dbus_conn, reply = dbus_message_new_error(message, DBUS_ERROR_UNKNOWN_METHOD, NULL); sbus_conn_send_reply(intf_p->conn, reply); dbus_message_unref(reply); + result = DBUS_HANDLER_RESULT_HANDLED; } else if (!handler_fn) { /* Reply DBUS_ERROR_NOT_SUPPORTED */ @@ -458,11 +462,7 @@ DBusHandlerResult sbus_message_handler(DBusConnection *dbus_conn, reply = dbus_message_new_error(message, DBUS_ERROR_NOT_SUPPORTED, NULL); sbus_conn_send_reply(intf_p->conn, reply); dbus_message_unref(reply); - - } else { - ret = handler_fn(message, intf_p->conn); - if (ret != EOK) - return sbus_reply_internal_error(message, intf_p->conn); + result = DBUS_HANDLER_RESULT_HANDLED; } } else { @@ -472,21 +472,28 @@ DBusHandlerResult sbus_message_handler(DBusConnection *dbus_conn, if (strcmp(msg_interface, DBUS_INTROSPECT_INTERFACE) == 0 && strcmp(msg_method, DBUS_INTROSPECT_METHOD) == 0) { - if (intf_p->intf->introspect_fn) { - /* If we have been asked for introspection data and we have - * an introspection function registered, user that. - */ - ret = intf_p->intf->introspect_fn(message, intf_p->conn); - if (ret != EOK) { - return sbus_reply_internal_error(message, intf_p->conn); - } - } + handler_fn = intf_p->intf->introspect_fn; + } + } + + if (handler_fn) { + dbus_req = sbus_new_request(intf_p->conn, intf_p->intf, message); + if (!dbus_req) { + ret = ENOMEM; + } else { + dbus_req->method = method; + ret = handler_fn(dbus_req); + } + if (ret != EOK) { + if (dbus_req) + talloc_free(dbus_req); + result = sbus_reply_internal_error(message, intf_p->conn); + } else { + result = DBUS_HANDLER_RESULT_HANDLED; } - else - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } - return DBUS_HANDLER_RESULT_HANDLED; + return result; } /* Adds a new D-BUS path message handler to the connection @@ -785,4 +792,3 @@ void sbus_conn_send_reply(struct sbus_connection *conn, DBusMessage *reply) { dbus_connection_send(conn->dbus.conn, reply, NULL); } - |