summaryrefslogtreecommitdiffstats
path: root/src/sbus/sssd_dbus.h
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/sbus/sssd_dbus.h
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/sbus/sssd_dbus.h')
-rw-r--r--src/sbus/sssd_dbus.h78
1 files changed, 77 insertions, 1 deletions
diff --git a/src/sbus/sssd_dbus.h b/src/sbus/sssd_dbus.h
index 7d00b94d0..dcb669079 100644
--- a/src/sbus/sssd_dbus.h
+++ b/src/sbus/sssd_dbus.h
@@ -24,9 +24,11 @@
struct sbus_connection;
+struct sbus_request;
+
#include <dbus/dbus.h>
-typedef int (*sbus_msg_handler_fn)(DBusMessage *, struct sbus_connection *);
+typedef int (*sbus_msg_handler_fn)(struct sbus_request *dbus_req);
/*
* sbus_conn_destructor_fn
@@ -170,4 +172,78 @@ int sbus_conn_send(struct sbus_connection *conn,
void sbus_conn_send_reply(struct sbus_connection *conn,
DBusMessage *reply);
+/*
+ * This structure is passed to all dbus method and property
+ * handlers. It is a talloc context which will be valid until
+ * the request is completed with either the sbus_request_complete()
+ * or sbus_request_fail() functions.
+ */
+struct sbus_request {
+ struct sbus_connection *conn;
+ DBusMessage *message;
+ struct sbus_interface *intf;
+ const struct sbus_method_meta *method;
+};
+
+/*
+ * Complete a DBus request, and free the @dbus_req context. The @dbus_req
+ * and associated talloc context are no longer valid after this function
+ * returns.
+ *
+ * If @reply is non-NULL then the reply is sent to the caller. Not sending
+ * a reply when the caller is expecting one is fairly rude behavior.
+ *
+ * The return value is useful for logging, but not much else. In particular
+ * even if this function return !EOK, @dbus_req is still unusable after this
+ * function returns.
+ */
+int sbus_request_finish(struct sbus_request *dbus_req,
+ DBusMessage *reply);
+
+/*
+ * Return a reply for a DBus method call request. The variable
+ * arguments are (unfortunately) formatted exactly the same as those of the
+ * dbus_message_append_args() function. Documented here:
+ *
+ * http://dbus.freedesktop.org/doc/api/html/group__DBusMessage.html
+ *
+ * Important: don't pass int or bool or such types as
+ * values to this function. That's not portable. Use actual dbus types.
+ * You must also pass pointers as the values:
+ *
+ * dbus_bool_t val1 = TRUE;
+ * dbus_int32_t val2 = 5;
+ * ret = sbus_request_finish(dbus_req,
+ * DBUS_TYPE_BOOLEAN, &val1,
+ * DBUS_TYPE_INT32, &val2,
+ * DBUS_TYPE_INVALID);
+ *
+ * To pass arrays to this function, use the following syntax. Never
+ * pass actual C arrays with [] syntax to this function. The C standard is
+ * rather vague with C arrays and varargs, and it just plain doesn't work.
+ *
+ * const char *array[] = { "one", "two", "three" };
+ * int count = 3; // yes, a plain int
+ * const char **ptr = array;
+ * ret = sbus_request_finish(dbus_req,
+ * DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &ptr, 3,
+ * DBUS_TYPE_INVALID);
+ *
+ * The @dbus_req and associated talloc context are no longer valid after this
+ * function returns, even if this function returns an error code.
+ */
+int sbus_request_return_and_finish(struct sbus_request *dbus_req,
+ int first_arg_type,
+ ...);
+
+/*
+ * Return an error for a DBus method call request. The @error is a normal
+ * DBusError.
+ *
+ * The @dbus_req and associated talloc context are no longer valid after this
+ * function returns, even if this function returns an error code.
+ */
+int sbus_request_fail_and_finish(struct sbus_request *dbus_req,
+ const DBusError *error);
+
#endif /* _SSSD_DBUS_H_*/