diff options
author | Stephen Gallagher <sgallagh@redhat.com> | 2008-11-17 09:41:06 -0500 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2008-11-17 10:02:34 -0500 |
commit | 977a6d0035dc1add3f490fcb31376271450ebfac (patch) | |
tree | 02d0eee222ce472f0ed71d29d68fb7129cb18976 /server/sbus/sssd_dbus_connection.c | |
parent | 12136300b98a87169964dfe72adc442b6d91a47a (diff) | |
download | sssd-977a6d0035dc1add3f490fcb31376271450ebfac.tar.gz sssd-977a6d0035dc1add3f490fcb31376271450ebfac.tar.bz2 sssd-977a6d0035dc1add3f490fcb31376271450ebfac.zip |
The default message handler will now pass both the method_ctx and the
sbus_conn_ctx to all message handling functions.
This will allow connection-specific data to be passed in by taking advantage
of the sbus_conn_set_private_data() function on the sbus_conn_ctx struct.
Presently this private data is global to all methods of the connection context.
Diffstat (limited to 'server/sbus/sssd_dbus_connection.c')
-rw-r--r-- | server/sbus/sssd_dbus_connection.c | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/server/sbus/sssd_dbus_connection.c b/server/sbus/sssd_dbus_connection.c index d84dd218..15086f3b 100644 --- a/server/sbus/sssd_dbus_connection.c +++ b/server/sbus/sssd_dbus_connection.c @@ -466,18 +466,21 @@ void sbus_disconnect (struct sbus_conn_ctx *dct_ctx) /* messsage_handler * Receive messages and process them */ -static DBusHandlerResult message_handler(DBusConnection *conn, +DBusHandlerResult sbus_message_handler(DBusConnection *conn, DBusMessage *message, void *user_data) { - struct sbus_method_ctx *ctx; + struct sbus_message_handler_ctx *ctx; const char *method; const char *path; const char *msg_interface; DBusMessage *reply = NULL; int i, ret; - ctx = talloc_get_type(user_data, struct sbus_method_ctx); + if (!user_data) { + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } + ctx = talloc_get_type(user_data, struct sbus_message_handler_ctx); method = dbus_message_get_member(message); path = dbus_message_get_path(message); @@ -487,14 +490,14 @@ static DBusHandlerResult message_handler(DBusConnection *conn, return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; /* Validate the method interface */ - if (strcmp(msg_interface, ctx->interface) != 0) + if (strcmp(msg_interface, ctx->method_ctx->interface) != 0) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; /* Validate the D-BUS path */ - if (strcmp(path, ctx->path) == 0) { - for (i = 0; ctx->methods[i].method != NULL; i++) { - if (strcmp(method, ctx->methods[i].method) == 0) { - ret = ctx->methods[i].fn(message, ctx, &reply); + if (strcmp(path, ctx->method_ctx->path) == 0) { + for (i = 0; ctx->method_ctx->methods[i].method != NULL; i++) { + if (strcmp(method, ctx->method_ctx->methods[i].method) == 0) { + ret = ctx->method_ctx->methods[i].fn(message, ctx, &reply); /* FIXME: check error */ break; } @@ -520,8 +523,10 @@ int sbus_conn_add_method_ctx(struct sbus_conn_ctx *dct_ctx, struct sbus_method_ctx *method_ctx) { DBusObjectPathVTable *connection_vtable; + struct sbus_message_handler_ctx *msg_handler_ctx; + dbus_bool_t dbret; - if (!method_ctx) { + if (!dct_ctx||!method_ctx) { return EINVAL; } @@ -529,18 +534,29 @@ int sbus_conn_add_method_ctx(struct sbus_conn_ctx *dct_ctx, return EINVAL; } + if (method_ctx->message_handler == NULL) { + return EINVAL; + } + DLIST_ADD(dct_ctx->method_ctx_list, method_ctx); /* Set up the vtable for the object path */ connection_vtable = talloc_zero(dct_ctx, DBusObjectPathVTable); - if (method_ctx->message_handler) { - connection_vtable->message_function = method_ctx->message_handler; - } else { - connection_vtable->message_function = message_handler; + if (!connection_vtable) { + return ENOMEM; + } + connection_vtable->message_function = method_ctx->message_handler; + + msg_handler_ctx = talloc_zero(dct_ctx, struct sbus_message_handler_ctx); + if (!msg_handler_ctx) { + talloc_free(connection_vtable); + return ENOMEM; } + msg_handler_ctx->conn_ctx = dct_ctx; + msg_handler_ctx->method_ctx = method_ctx; dbret = dbus_connection_register_object_path(dct_ctx->conn, method_ctx->path, - connection_vtable, method_ctx); + connection_vtable, msg_handler_ctx); if (!dbret) { return ENOMEM; } |