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 | |
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.
-rw-r--r-- | server/monitor.c | 2 | ||||
-rw-r--r-- | server/nss/nsssrv.c | 1 | ||||
-rw-r--r-- | server/sbus/sssd_dbus.h | 18 | ||||
-rw-r--r-- | server/sbus/sssd_dbus_connection.c | 44 | ||||
-rw-r--r-- | server/sbus/tests/test_client.c | 1 |
5 files changed, 44 insertions, 22 deletions
diff --git a/server/monitor.c b/server/monitor.c index 9eccb0b9..b85b7d60 100644 --- a/server/monitor.c +++ b/server/monitor.c @@ -138,7 +138,7 @@ static int monitor_dbus_init(struct mt_ctx *ctx) return ENOMEM; } sd_ctx->methods = monitor_methods; - sd_ctx->message_handler = NULL; /* Use the default message_handler */ + sd_ctx->message_handler = sbus_message_handler; /* Use the default message_handler */ ret = sbus_new_server(ctx->ev, sd_ctx, sbus_address, dbus_service_init, ctx); diff --git a/server/nss/nsssrv.c b/server/nss/nsssrv.c index 93f8d223..4ce00ffc 100644 --- a/server/nss/nsssrv.c +++ b/server/nss/nsssrv.c @@ -288,6 +288,7 @@ static int nss_sbus_init(struct nss_ctx *nctx) return ENOMEM; } srv_sm_ctx->methods = nss_sbus_methods; + srv_sm_ctx->message_handler = sbus_message_handler; sbus_conn_add_method_ctx(ns_ctx->scon_ctx, srv_sm_ctx); /* set up client stuff */ diff --git a/server/sbus/sssd_dbus.h b/server/sbus/sssd_dbus.h index 5510b6e4..321bd603 100644 --- a/server/sbus/sssd_dbus.h +++ b/server/sbus/sssd_dbus.h @@ -52,19 +52,17 @@ struct sbus_method { struct sbus_method_ctx { struct sbus_method_ctx *prev, *next; - /*struct event_context *ev;*/ char *interface; char *path; - - /* If a non-default message_handler is desired, set it in this - * object before calling sbus_conn_add_method_ctx() - * Otherwise it will default to message_handler() in - * sssd_dbus_connection.c - */ DBusObjectPathMessageFunction message_handler; struct sbus_method *methods; }; +struct sbus_message_handler_ctx { + struct sbus_conn_ctx *conn_ctx; + struct sbus_method_ctx *method_ctx; +}; + /* Server Functions */ int sbus_new_server(struct event_context *ev, struct sbus_method_ctx *ctx, const char *address, @@ -87,4 +85,10 @@ void sbus_conn_set_private_data(struct sbus_conn_ctx *conn_ctx, void *pvt_data); int sbus_conn_add_method_ctx(struct sbus_conn_ctx *conn_ctx, struct sbus_method_ctx *method_ctx); +/* Default message handler + * Should be usable for most cases */ +DBusHandlerResult sbus_message_handler(DBusConnection *conn, + DBusMessage *message, + void *user_data); + #endif /* _SSSD_DBUS_H_*/ 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; } diff --git a/server/sbus/tests/test_client.c b/server/sbus/tests/test_client.c index 06cd1133..b2dce426 100644 --- a/server/sbus/tests/test_client.c +++ b/server/sbus/tests/test_client.c @@ -182,6 +182,7 @@ int main (int argc, const char *argv[]) service_methods->interface = talloc_strdup(service_methods, SERVICE_INTERFACE); service_methods->path = talloc_strdup(service_methods, SERVICE_PATH); service_methods->methods = monitor_service_methods; + service_methods->message_handler = sbus_message_handler; sbus_conn_add_method_ctx(test_ctx->dct_ctx, service_methods); /* Enter the main loop (and hopefully never return) */ |