diff options
author | Simo Sorce <ssorce@redhat.com> | 2008-10-24 19:09:44 +0200 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2008-10-27 10:02:38 -0400 |
commit | 6fe2bfce9fb9bb1564be8257cccc52bcec589de4 (patch) | |
tree | 1b9e603f7b08f8697b443e94a0e358b4fb00f07c /server/monitor.c | |
parent | 054a931b01f98cf94b42f1ff1f48fbcb4928c869 (diff) | |
download | sssd-6fe2bfce9fb9bb1564be8257cccc52bcec589de4.tar.gz sssd-6fe2bfce9fb9bb1564be8257cccc52bcec589de4.tar.bz2 sssd-6fe2bfce9fb9bb1564be8257cccc52bcec589de4.zip |
D-BUS integration style changes.
Rework interfaces a bit to simplify and uniform function names so that they
use a well defined namespace (sssd_*).
Simplify headers file, split them into a private and a public one only.
Make static all file private functions.
Rename sssd_dbus_client.c to sssd_dbus_connection.c to reflect it's function,
as it is is used by both a server and a client.
Introduce a function table to know where to dipatch messages.
Fix coding style issues, and start pointing out where clean-up fucntions
are missing.
Diffstat (limited to 'server/monitor.c')
-rw-r--r-- | server/monitor.c | 167 |
1 files changed, 71 insertions, 96 deletions
diff --git a/server/monitor.c b/server/monitor.c index 45b21cd5..0f92eceb 100644 --- a/server/monitor.c +++ b/server/monitor.c @@ -27,9 +27,19 @@ #include "util/util.h" #include "service.h" #include "confdb/confdb.h" +#include "monitor.h" #include "dbus/dbus.h" -#include "dbus/sssd_dbus_server.h" -#include "dbus/sssd_dbus_client.h" +#include "dbus/sssd_dbus.h" + + +/* TODO: get this value from LDB */ +#define DBUS_ADDRESS "unix:path=/var/lib/sss/pipes/private/dbus" + +struct mt_ctx { + struct event_context *ev; + struct confdb_ctx *cdb; + char **services; +}; struct mt_srv { const char *name; @@ -39,6 +49,64 @@ struct mt_srv { int restarts; }; +/* dbus_get_monitor_version + * Return the monitor version over D-BUS */ +static int dbus_get_monitor_version(DBusMessage *message, + void *data, + DBusMessage **r) +{ + const char *version = MONITOR_VERSION; + DBusMessage *reply; + dbus_bool_t ret; + + reply = dbus_message_new_method_return(message); + ret = dbus_message_append_args(reply, DBUS_TYPE_STRING, + &version, DBUS_TYPE_INVALID); + + if (!ret) { + return EIO; + } + + *r = reply; + return EOK; +} + +struct sssd_dbus_method monitor_methods[] = { + { MONITOR_METHOD_VERSION, dbus_get_monitor_version}, + {NULL, NULL} +}; + +/* monitor_dbus_init + * Set up the monitor service as a D-BUS Server */ +static int monitor_dbus_init(struct mt_ctx *ctx) +{ + struct sssd_dbus_ctx *sd_ctx; + int ret; + + sd_ctx = talloc(ctx, struct sssd_dbus_ctx); + if (!sd_ctx) { + return ENOMEM; + } + + sd_ctx->ev = ctx->ev; + sd_ctx->name = talloc_strdup(sd_ctx, MONITOR_DBUS_INTERFACE); + if (!sd_ctx->name) { + talloc_free(sd_ctx); + return ENOMEM; + } + sd_ctx->path = talloc_strdup(sd_ctx, MONITOR_DBUS_PATH); + if (!sd_ctx->path) { + talloc_free(sd_ctx); + return ENOMEM; + } + sd_ctx->methods = monitor_methods; + + ret = sssd_new_dbus_server(sd_ctx, DBUS_ADDRESS); + + return ret; +} + + static void set_tasks_checker(struct mt_srv *srv); static void tasks_check_handler(struct event_context *ev, @@ -139,7 +207,7 @@ int start_monitor(TALLOC_CTX *mem_ctx, /* Initialize D-BUS Server * The monitor will act as a D-BUS server for all * SSSD processes */ - monitor_dbus_init(event_ctx); + monitor_dbus_init(ctx); for (i = 0; ctx->services[i]; i++) { @@ -163,96 +231,3 @@ int start_monitor(TALLOC_CTX *mem_ctx, return EOK; } - -/* - * monitor_dbus_init - * Set up the monitor service as a D-BUS Server - */ -int monitor_dbus_init(struct event_context *event_ctx) { - DBusError dbus_error; - DBusServer *dbus_server; - - /* Set up D-BUS server */ - dbus_error_init(&dbus_error); - dbus_server = dbus_server_listen(DBUS_ADDRESS, &dbus_error); - if (dbus_server == NULL) { - DEBUG(0,("Error: name=%s, message=%s\n", dbus_error.name, - dbus_error.message)); - } - - /* TODO: remove debug */ - DEBUG(2,("Server listening on %s\n", dbus_server_get_address(dbus_server))); - - integrate_server_with_event_loop(event_ctx, dbus_server, monitor_dbus_method_init); - - return 0; -} - -/* monitor_messsage_handler - * Receive messages and process them - */ -DBusHandlerResult monitor_message_handler(DBusConnection *conn, - DBusMessage *message, void *user_data) { - const char *method; - const char *path; - const char *msg_interface; - DBusMessage *reply = NULL; - - method = dbus_message_get_member(message); - path = dbus_message_get_path(message); - msg_interface = dbus_message_get_interface(message); - - if (!method || !path || !msg_interface) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - /* Validate the method interface */ - if (strcmp(msg_interface, MONITOR_DBUS_INTERFACE) != 0) - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - - /* Validate the D-BUS path */ - if (strcmp(path, MONITOR_DBUS_PATH) == 0) { - /* TODO Fill in methods */ - if(strcmp(method,MONITOR_METHOD_VERSION) == 0) { - reply = dbus_get_monitor_version(message); - } - } - - if(reply) { - dbus_connection_send(conn,reply, NULL); - dbus_message_unref(reply); - } - - return reply ? DBUS_HANDLER_RESULT_HANDLED : - DBUS_HANDLER_RESULT_NOT_YET_HANDLED; -} - -/* dbus_get_monitor_version - * Return the monitor version over D-BUS - */ -DBusMessage *dbus_get_monitor_version(DBusMessage *message) { - DBusMessage *reply; - const char *version = MONITOR_VERSION; - - reply = dbus_message_new_method_return(message); - dbus_message_append_args(reply,DBUS_TYPE_STRING, &version, DBUS_TYPE_INVALID); - - return reply; -} - -/* monitor_dbus_method_init - * Initialize D-BUS methods on the monitor - * Sets up a callback to monitor_message_handler - */ -void monitor_dbus_method_init(DBusConnection *conn, struct event_context *event_ctx) { - DBusObjectPathVTable *monitor_vtable; - monitor_vtable = talloc_zero(event_ctx, DBusObjectPathVTable); - - DEBUG (3,("Initializing D-BUS methods.\n")); - monitor_vtable->message_function = monitor_message_handler; - - dbus_connection_register_object_path( - conn, MONITOR_DBUS_PATH, - monitor_vtable, event_ctx); - - DEBUG(3,("D-BUS method initialization complete.\n")); -} |