summaryrefslogtreecommitdiffstats
path: root/src/sbus/sssd_dbus_connection.c
diff options
context:
space:
mode:
authorStef Walter <stefw@redhat.com>2014-02-25 10:29:23 +0100
committerJakub Hrozek <jhrozek@redhat.com>2014-06-03 13:19:54 +0200
commite38c58d968594cb466163e64a43a7bfb959e48b0 (patch)
tree7626b1c68bb8a03713cd2eae58d3b6efbaca3997 /src/sbus/sssd_dbus_connection.c
parent8ded3b5bd988c479ede2cadac29359c65f65d0b5 (diff)
downloadsssd-e38c58d968594cb466163e64a43a7bfb959e48b0.tar.gz
sssd-e38c58d968594cb466163e64a43a7bfb959e48b0.tar.xz
sssd-e38c58d968594cb466163e64a43a7bfb959e48b0.zip
sbus: Add type-safe DBus method handlers and finish functions
Type safe method handlers allow methods not to have to do tedious unwrapping and wrapping of DBus method call messages or replies. Arguments of the following DBus types are supported in type-safe method handlers. In addition arrays of these are supported. y: uint8_t b: bool (but no arrays, yet) n: int16_t q: uint16_t i: int32_t u: uint32_t x: int64_t t: uint64_t d: double s: char * (utf8 string) o: char * (object path) As an exception, arrays of booleans are not supported, but could be added later. Other more complex types could be added later if desired. If a method has other argument types, then it must be marked as having a raw handler (see below). Internally each method can have a type specific invoker function which unpacks the incoming arguments and invokes the method handler with the correct arguments. Each method also has a finish which accepts the type-safe out arguments (ie: return values) and builds the reply message. Like other request 'finish' functions, these free the request talloc context, and are to be used in place of sbus_request_finish() or friends. Raw method handlers parse their own method arguments, and prepare their own reply (ideally using sbus_request_finish() helpers). They can also do strange things like have variable arguments. To mark a DBus method as having a raw method handler use the following annotation: <annotation name="org.freedesktop.sssd.RawHandler" value="true"/> Raw methods do not have invokers or finish functions. I've left all of the internal peer to peer communication using raw method handlers. No code changes here. (cherry picked from commit dff909d473f43a6bd0f0286fa2d279c0ebe945c6)
Diffstat (limited to 'src/sbus/sssd_dbus_connection.c')
-rw-r--r--src/sbus/sssd_dbus_connection.c33
1 files changed, 9 insertions, 24 deletions
diff --git a/src/sbus/sssd_dbus_connection.c b/src/sbus/sssd_dbus_connection.c
index 0049cf3c6..ab18049f8 100644
--- a/src/sbus/sssd_dbus_connection.c
+++ b/src/sbus/sssd_dbus_connection.c
@@ -345,18 +345,6 @@ void sbus_disconnect (struct sbus_connection *conn)
DEBUG(SSSDBG_TRACE_FUNC ,"Disconnected %p\n", conn->dbus.conn);
}
-static int sbus_reply_internal_error(DBusMessage *message,
- struct sbus_connection *conn) {
- DBusMessage *reply = dbus_message_new_error(message, DBUS_ERROR_IO_ERROR,
- "Internal Error");
- if (reply) {
- sbus_conn_send_reply(conn, reply);
- dbus_message_unref(reply);
- return DBUS_HANDLER_RESULT_HANDLED;
- }
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
/* Looks up a vtable func, in a struct derived from struct sbus_vtable */
#define VTABLE_FUNC(vtable, offset) \
(*((void **)((char *)(vtable) + (offset))))
@@ -380,7 +368,6 @@ DBusHandlerResult sbus_message_handler(DBusConnection *dbus_conn,
void *handler_data = NULL; /* Must be a talloc pointer! */
struct sbus_introspect_ctx *ictx = NULL;
DBusHandlerResult result;
- int ret;
if (!user_data) {
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@ -435,7 +422,11 @@ DBusHandlerResult sbus_message_handler(DBusConnection *dbus_conn,
DEBUG(SSSDBG_TRACE_LIBS, "Got introspection request\n");
ictx = talloc(intf_p->conn, struct sbus_introspect_ctx);
if (ictx == NULL) {
- result = sbus_reply_internal_error(message, intf_p->conn);
+ reply = dbus_message_new_error(message,
+ DBUS_ERROR_NO_MEMORY, NULL);
+ sbus_conn_send_reply(intf_p->conn, reply);
+ dbus_message_unref(reply);
+ result = DBUS_HANDLER_RESULT_HANDLED;
} else {
handler_fn = sbus_introspect;
ictx->iface = interface;
@@ -447,10 +438,7 @@ DBusHandlerResult sbus_message_handler(DBusConnection *dbus_conn,
if (handler_fn) {
dbus_req = sbus_new_request(intf_p->conn, intf_p->intf, message);
- if (!dbus_req) {
- talloc_zfree(handler_data);
- ret = ENOMEM;
- } else {
+ if (dbus_req) {
dbus_req->method = method;
if (handler_data) {
/* If the handler uses private instance data, make
@@ -463,12 +451,9 @@ DBusHandlerResult sbus_message_handler(DBusConnection *dbus_conn,
*/
handler_data = intf_p->intf->instance_data;
}
- ret = handler_fn(dbus_req, handler_data);
- }
- if (ret != EOK) {
- talloc_free(dbus_req);
- result = sbus_reply_internal_error(message, intf_p->conn);
- } else {
+
+ sbus_request_invoke_or_finish(dbus_req, handler_fn, handler_data,
+ method->invoker);
result = DBUS_HANDLER_RESULT_HANDLED;
}
}