summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/sbus/sssd_dbus_common.c264
-rw-r--r--server/sbus/sssd_dbus_connection.c203
-rw-r--r--server/sbus/sssd_dbus_private.h39
-rw-r--r--server/sbus/sssd_dbus_server.c173
4 files changed, 324 insertions, 355 deletions
diff --git a/server/sbus/sssd_dbus_common.c b/server/sbus/sssd_dbus_common.c
index 3b8a3271..6a710768 100644
--- a/server/sbus/sssd_dbus_common.c
+++ b/server/sbus/sssd_dbus_common.c
@@ -3,8 +3,179 @@
#include "dbus/dbus.h"
#include "util/util.h"
#include "util/btreemap.h"
+#include "sbus/sssd_dbus.h"
+#include "sbus/sssd_dbus_private.h"
-struct timeval _dbus_timeout_get_interval_tv(int interval) {
+/* =Watches=============================================================== */
+
+/*
+ * watch_handler
+ * Callback for D-BUS to handle messages on a file-descriptor
+ */
+static void sbus_watch_handler(struct tevent_context *ev,
+ struct tevent_fd *fde,
+ uint16_t flags, void *data)
+{
+ struct sbus_watch_ctx *watch = talloc_get_type(data,
+ struct sbus_watch_ctx);
+
+ /* Take a reference while handling watch */
+ if (watch->dbus_type == SBUS_SERVER) {
+ dbus_server_ref(watch->dbus.server);
+ } else {
+ dbus_connection_ref(watch->dbus.conn);
+ }
+
+ /* Fire if readable */
+ if (flags & TEVENT_FD_READ) {
+ dbus_watch_handle(watch->dbus_watch, DBUS_WATCH_READABLE);
+ }
+
+ /* Fire if writeable */
+ if (flags & TEVENT_FD_WRITE) {
+ dbus_watch_handle(watch->dbus_watch, DBUS_WATCH_WRITABLE);
+ }
+
+ /* Release reference once done */
+ if (watch->dbus_type == SBUS_SERVER) {
+ dbus_server_unref(watch->dbus.server);
+ } else {
+ dbus_connection_unref(watch->dbus.conn);
+ }
+}
+
+/*
+ * add_watch
+ * Set up hooks into the libevents mainloop for
+ * D-BUS to add file descriptor-based events
+ */
+dbus_bool_t sbus_add_watch(DBusWatch *dbus_watch, void *data)
+{
+ unsigned int flags;
+ uint16_t event_flags;
+ struct sbus_generic_dbus_ctx *gen_ctx;
+ struct sbus_watch_ctx *watch;
+ int fd;
+
+ gen_ctx = talloc_get_type(data, struct sbus_generic_dbus_ctx);
+
+ watch = talloc_zero(gen_ctx, struct sbus_watch_ctx);
+ if (!watch) {
+ DEBUG(0, ("Outr of Memory!\n"));
+ return FALSE;
+ }
+ watch->dbus_watch = dbus_watch;
+ watch->dbus_type = gen_ctx->type;
+ watch->dbus = gen_ctx->dbus;
+
+#ifdef HAVE_DBUS_WATCH_GET_UNIX_FD
+ fd = dbus_watch_get_unix_fd(dbus_watch);
+#else
+ fd = dbus_watch_get_fd(dbus_watch);
+#endif
+
+ flags = dbus_watch_get_flags(dbus_watch);
+ event_flags = 0;
+
+ if (dbus_watch_get_enabled(dbus_watch)) {
+ if (flags & DBUS_WATCH_READABLE) {
+ event_flags |= TEVENT_FD_READ;
+ }
+ if (flags & DBUS_WATCH_WRITABLE) {
+ event_flags |= TEVENT_FD_WRITE;
+ }
+ }
+
+ DEBUG(8, ("%p: %d, %d=%s/%s\n",
+ dbus_watch, fd, flags,
+ ((event_flags & TEVENT_FD_READ)?"R":"-"),
+ ((event_flags & TEVENT_FD_WRITE)?"W":"-")));
+
+ /* Add the file descriptor to the event loop */
+ watch->fde = tevent_add_fd(gen_ctx->ev,
+ watch, fd, event_flags,
+ sbus_watch_handler, watch);
+ if (!watch->fde) {
+ DEBUG(0, ("Failed to set up fd event!\n"));
+ return FALSE;
+ }
+
+ /* Save the event to the watch object so it can be removed later */
+ dbus_watch_set_data(dbus_watch, watch, NULL);
+
+ return TRUE;
+}
+
+/*
+ * toggle_watch
+ * Hook for D-BUS to toggle the enabled/disabled state of
+ * an event in the mainloop
+ */
+void sbus_toggle_watch(DBusWatch *dbus_watch, void *data)
+{
+ struct sbus_watch_ctx *watch;
+ uint16_t event_flags = 0;
+ unsigned int flags;
+ void *watch_data;
+
+ watch_data = dbus_watch_get_data(dbus_watch);
+ watch = talloc_get_type(watch_data, struct sbus_watch_ctx);
+ if (!watch) {
+ DEBUG(0, ("Watch does not carry watch context?!\n"));
+ /* TODO: abort ? */
+ return;
+ }
+
+ flags = dbus_watch_get_flags(dbus_watch);
+
+ if (dbus_watch_get_enabled(dbus_watch)) {
+ if (flags & DBUS_WATCH_READABLE) {
+ TEVENT_FD_READABLE(watch->fde);
+ }
+ if (flags & DBUS_WATCH_WRITABLE) {
+ TEVENT_FD_WRITEABLE(watch->fde);
+ }
+ } else {
+ if (flags & DBUS_WATCH_READABLE) {
+ TEVENT_FD_NOT_READABLE(watch->fde);
+ }
+ if (flags & DBUS_WATCH_WRITABLE) {
+ TEVENT_FD_NOT_WRITEABLE(watch->fde);
+ }
+ }
+
+ if (debug_level >= 8) {
+ event_flags = tevent_fd_get_flags(watch->fde);
+ }
+ DEBUG(8, ("%p: %p, %d=%s/%s\n",
+ dbus_watch, watch, flags,
+ ((event_flags & TEVENT_FD_READ)?"R":"-"),
+ ((event_flags & TEVENT_FD_WRITE)?"W":"-")));
+}
+
+/*
+ * sbus_remove_watch
+ * Hook for D-BUS to remove file descriptor-based events
+ * from the libevents mainloop
+ */
+void sbus_remove_watch(DBusWatch *dbus_watch, void *data)
+{
+ void *watch;
+
+ DEBUG(8, ("%p\n", dbus_watch));
+
+ watch = dbus_watch_get_data(dbus_watch);
+
+ /* remove dbus watch data */
+ dbus_watch_set_data(dbus_watch, NULL, NULL);
+
+ /* Freeing the event object will remove it from the event loop */
+ talloc_free(watch);
+}
+
+/* =Timeouts============================================================== */
+
+static struct timeval _get_interval_tv(int interval) {
struct timeval tv;
struct timeval rightnow;
@@ -16,35 +187,96 @@ struct timeval _dbus_timeout_get_interval_tv(int interval) {
}
/*
- * sbus_remove_watch
- * Hook for D-BUS to remove file descriptor-based events
- * from the libevents mainloop
+ * timeout_handler
+ * Callback for D-BUS to handle timed events
*/
-void sbus_remove_watch(DBusWatch *watch, void *data) {
- struct tevent_fd *fde;
+static void sbus_timeout_handler(struct tevent_context *ev,
+ struct tevent_timer *te,
+ struct timeval t, void *data)
+{
+ struct sbus_timeout_ctx *timeout;
+ timeout = talloc_get_type(data, struct sbus_timeout_ctx);
- DEBUG(5, ("%lX\n", watch));
- fde = talloc_get_type(dbus_watch_get_data(watch), struct tevent_fd);
+ dbus_timeout_handle(timeout->dbus_timeout);
+}
- /* Freeing the event object will remove it from the event loop */
- talloc_free(fde);
- dbus_watch_set_data(watch, NULL, NULL);
+/*
+ * add_timeout
+ * Hook for D-BUS to add time-based events to the mainloop
+ */
+dbus_bool_t sbus_add_timeout(DBusTimeout *dbus_timeout, void *data)
+{
+ struct sbus_generic_dbus_ctx *gen_ctx;
+ struct sbus_timeout_ctx *timeout;
+ struct timeval tv;
+
+ DEBUG(8, ("%p\n", dbus_timeout));
+
+ if (!dbus_timeout_get_enabled(dbus_timeout)) {
+ return TRUE;
+ }
+
+ gen_ctx = talloc_get_type(data, struct sbus_generic_dbus_ctx);
+
+ timeout = talloc_zero(gen_ctx, struct sbus_timeout_ctx);
+ if (!timeout) {
+ DEBUG(0, ("Outr of Memory!\n"));
+ return FALSE;
+ }
+ timeout->dbus_timeout = dbus_timeout;
+
+ tv = _get_interval_tv(dbus_timeout_get_interval(dbus_timeout));
+ timeout->te = tevent_add_timer(gen_ctx->ev, timeout, tv,
+ sbus_timeout_handler, timeout);
+ if (!timeout->te) {
+ DEBUG(0, ("Failed to set up timeout event!\n"));
+ return FALSE;
+ }
+
+ /* Save the event to the watch object so it can be removed later */
+ dbus_timeout_set_data(timeout->dbus_timeout, timeout, NULL);
+
+ return TRUE;
}
+/*
+ * sbus_toggle_timeout
+ * Hook for D-BUS to toggle the enabled/disabled state of a mainloop
+ * event
+ */
+void sbus_toggle_timeout(DBusTimeout *dbus_timeout, void *data)
+{
+ DEBUG(8, ("%p\n", dbus_timeout));
+
+ if (dbus_timeout_get_enabled(dbus_timeout)) {
+ sbus_add_timeout(dbus_timeout, data);
+ } else {
+ sbus_remove_timeout(dbus_timeout, data);
+ }
+}
/*
* sbus_remove_timeout
* Hook for D-BUS to remove time-based events from the mainloop
*/
-void sbus_remove_timeout(DBusTimeout *timeout, void *data) {
- struct tevent_timer *te;
- te = talloc_get_type(dbus_timeout_get_data(timeout), struct tevent_timer);
+void sbus_remove_timeout(DBusTimeout *dbus_timeout, void *data)
+{
+ void *timeout;
+
+ DEBUG(8, ("%p\n", dbus_timeout));
+
+ timeout = dbus_timeout_get_data(dbus_timeout);
+
+ /* remove dbus timeout data */
+ dbus_timeout_set_data(dbus_timeout, NULL, NULL);
/* Freeing the event object will remove it from the event loop */
- talloc_free(te);
- dbus_timeout_set_data(timeout, NULL, NULL);
+ talloc_free(timeout);
+
}
+/* =Helpers=============================================================== */
+
int sbus_is_dbus_fixed_type(int dbus_type)
{
switch (dbus_type) {
diff --git a/server/sbus/sssd_dbus_connection.c b/server/sbus/sssd_dbus_connection.c
index 3fb3f68a..3ea09ca0 100644
--- a/server/sbus/sssd_dbus_connection.c
+++ b/server/sbus/sssd_dbus_connection.c
@@ -29,19 +29,6 @@ struct sbus_message_handler_ctx {
struct sbus_method_ctx *method_ctx;
};
-struct sbus_watch_ctx {
- struct sbus_conn_ctx *conn_ctx;
- DBusWatch *watch;
- int fd;
- struct tevent_fd *fde;
-};
-
-struct sbus_timeout_ctx {
- struct sbus_conn_ctx *conn_ctx;
- DBusTimeout *timeout;
- struct tevent_timer *te;
-};
-
static int _method_list_contains_path(struct sbus_method_ctx *list,
struct sbus_method_ctx *method);
static void sbus_unreg_object_paths(struct sbus_conn_ctx *conn_ctx);
@@ -49,8 +36,8 @@ static void sbus_unreg_object_paths(struct sbus_conn_ctx *conn_ctx);
static int sbus_auto_reconnect(struct sbus_conn_ctx *conn_ctx);
static void sbus_dispatch(struct tevent_context *ev,
- struct tevent_timer *te,
- struct timeval tv, void *data)
+ struct tevent_timer *te,
+ struct timeval tv, void *data)
{
struct tevent_timer *new_event;
struct sbus_conn_ctx *conn_ctx;
@@ -126,160 +113,6 @@ static void sbus_dispatch(struct tevent_context *ev,
}
}
-/*
- * dbus_connection_read_write_handler
- * Callback for D-BUS to handle messages on a file-descriptor
- */
-static void sbus_conn_read_write_handler(struct tevent_context *ev,
- struct tevent_fd *fde,
- uint16_t flags, void *data)
-{
- struct sbus_watch_ctx *watch_ctx;
- watch_ctx = talloc_get_type(data, struct sbus_watch_ctx);
-
- DEBUG(6,("Connection is open for read/write.\n"));
- dbus_connection_ref(watch_ctx->conn_ctx->dbus_conn);
- if (flags & TEVENT_FD_READ) {
- dbus_watch_handle(watch_ctx->watch, DBUS_WATCH_READABLE);
- }
- if (flags & TEVENT_FD_WRITE) {
- dbus_watch_handle(watch_ctx->watch, DBUS_WATCH_WRITABLE);
- }
- dbus_connection_unref(watch_ctx->conn_ctx->dbus_conn);
-}
-
-/*
- * add_connection_watch
- * Set up hooks into the libevents mainloop for
- * D-BUS to add file descriptor-based events
- */
-static dbus_bool_t sbus_add_conn_watch(DBusWatch *watch, void *data)
-{
- unsigned int flags;
- unsigned int event_flags;
- struct sbus_conn_ctx *conn_ctx;
- struct sbus_watch_ctx *watch_ctx;
-
- if (!dbus_watch_get_enabled(watch)) {
- return TRUE;
- }
-
- conn_ctx = talloc_get_type(data, struct sbus_conn_ctx);
-
- watch_ctx = talloc_zero(conn_ctx, struct sbus_watch_ctx);
- watch_ctx->conn_ctx = conn_ctx;
- watch_ctx->watch = watch;
-
- flags = dbus_watch_get_flags(watch);
-#ifdef HAVE_DBUS_WATCH_GET_UNIX_FD
- watch_ctx->fd = dbus_watch_get_unix_fd(watch);
-#else
- watch_ctx->fd = dbus_watch_get_fd(watch);
-#endif
-
- event_flags = 0;
-
- if (flags & DBUS_WATCH_READABLE)
- event_flags |= TEVENT_FD_READ;
-
- if (flags & DBUS_WATCH_WRITABLE)
- event_flags |= TEVENT_FD_WRITE;
-
- if (event_flags == 0)
- return FALSE;
-
- DEBUG(5,("%lX: %d, %d=%s\n",
- watch, watch_ctx->fd, event_flags,
- event_flags==TEVENT_FD_READ?"READ":"WRITE"));
-
- /* Add the file descriptor to the event loop */
- watch_ctx->fde = tevent_add_fd(watch_ctx->conn_ctx->ev, watch_ctx,
- watch_ctx->fd, event_flags,
- sbus_conn_read_write_handler,
- watch_ctx);
-
- /* Save the event to the watch object so it can be removed later */
- dbus_watch_set_data(watch_ctx->watch, watch_ctx->fde, NULL);
-
- return TRUE;
-}
-
-/*
- * toggle_connection_watch
- * Hook for D-BUS to toggle the enabled/disabled state of
- * an event in the mainloop
- */
-static void sbus_toggle_conn_watch(DBusWatch *watch, void *data)
-{
- if (dbus_watch_get_enabled(watch)) {
- sbus_add_conn_watch(watch, data);
- } else {
- sbus_remove_watch(watch, data);
- }
-}
-
-/*
- * dbus_connection_timeout_handler
- * Callback for D-BUS to handle timed events
- */
-static void sbus_conn_timeout_handler(struct tevent_context *ev,
- struct tevent_timer *te,
- struct timeval t, void *data)
-{
- struct sbus_timeout_ctx *timeout_ctx;
- timeout_ctx = talloc_get_type(data, struct sbus_timeout_ctx);
-
- dbus_timeout_handle(timeout_ctx->timeout);
-}
-
-
-/*
- * add_connection_timeout
- * Hook for D-BUS to add time-based events to the mainloop
- */
-static dbus_bool_t sbus_add_conn_timeout(DBusTimeout *timeout, void *data)
-{
- struct sbus_conn_ctx *conn_ctx;
- struct sbus_timeout_ctx *timeout_ctx;
- struct timeval tv;
-
- if (!dbus_timeout_get_enabled(timeout))
- return TRUE;
-
- conn_ctx = talloc_get_type(data, struct sbus_conn_ctx);
-
- timeout_ctx = talloc_zero(conn_ctx,struct sbus_timeout_ctx);
- timeout_ctx->conn_ctx = conn_ctx;
- timeout_ctx->timeout = timeout;
-
- tv = _dbus_timeout_get_interval_tv(dbus_timeout_get_interval(timeout));
-
- struct timeval rightnow;
- gettimeofday(&rightnow, NULL);
-
- timeout_ctx->te = tevent_add_timer(conn_ctx->ev, timeout_ctx, tv,
- sbus_conn_timeout_handler, timeout_ctx);
-
- /* Save the event to the watch object so it can be removed later */
- dbus_timeout_set_data(timeout_ctx->timeout, timeout_ctx->te, NULL);
-
- return TRUE;
-}
-
-/*
- * sbus_toggle_conn_timeout
- * Hook for D-BUS to toggle the enabled/disabled state of a mainloop
- * event
- */
-void sbus_toggle_conn_timeout(DBusTimeout *timeout, void *data)
-{
- if (dbus_timeout_get_enabled(timeout)) {
- sbus_add_conn_timeout(timeout, data);
- } else {
- sbus_remove_timeout(timeout, data);
- }
-}
-
/* dbus_connection_wakeup_main
* D-BUS makes a callback to the wakeup_main function when
* it has data available for dispatching.
@@ -337,19 +170,20 @@ int sbus_add_connection(TALLOC_CTX *ctx,
conn_ctx->max_retries = 0;
conn_ctx->reconnect_callback = NULL;
- ret = sbus_add_connection_int(&conn_ctx);
+ *_conn_ctx = conn_ctx;
+
+ ret = sbus_add_connection_int(_conn_ctx);
if (ret != EOK) {
talloc_free(conn_ctx);
- return ret;
}
- *_conn_ctx = conn_ctx;
- return EOK;
+ return ret;
}
static int sbus_add_connection_int(struct sbus_conn_ctx **_conn_ctx)
{
- dbus_bool_t dbret;
struct sbus_conn_ctx *conn_ctx = *_conn_ctx;
+ struct sbus_generic_dbus_ctx *gen_ctx;
+ dbus_bool_t dbret;
/*
* Set the default destructor
@@ -358,12 +192,21 @@ static int sbus_add_connection_int(struct sbus_conn_ctx **_conn_ctx)
*/
sbus_conn_set_destructor(conn_ctx, NULL);
+ gen_ctx = talloc_zero(conn_ctx, struct sbus_generic_dbus_ctx);
+ if (!gen_ctx) {
+ DEBUG(0, ("Out of memory!\n"));
+ return ENOMEM;
+ }
+ gen_ctx->ev = conn_ctx->ev;
+ gen_ctx->type = SBUS_CONNECTION;
+ gen_ctx->dbus.conn = conn_ctx->dbus_conn;
+
/* Set up DBusWatch functions */
dbret = dbus_connection_set_watch_functions(conn_ctx->dbus_conn,
- sbus_add_conn_watch,
+ sbus_add_watch,
sbus_remove_watch,
- sbus_toggle_conn_watch,
- conn_ctx, NULL);
+ sbus_toggle_watch,
+ gen_ctx, NULL);
if (!dbret) {
DEBUG(2,("Error setting up D-BUS connection watch functions\n"));
return EIO;
@@ -371,10 +214,10 @@ static int sbus_add_connection_int(struct sbus_conn_ctx **_conn_ctx)
/* Set up DBusTimeout functions */
dbret = dbus_connection_set_timeout_functions(conn_ctx->dbus_conn,
- sbus_add_conn_timeout,
+ sbus_add_timeout,
sbus_remove_timeout,
- sbus_toggle_conn_timeout,
- conn_ctx, NULL);
+ sbus_toggle_timeout,
+ gen_ctx, NULL);
if (!dbret) {
DEBUG(2,("Error setting up D-BUS server timeout functions\n"));
/* FIXME: free resources ? */
diff --git a/server/sbus/sssd_dbus_private.h b/server/sbus/sssd_dbus_private.h
index bcaee62c..fdee121e 100644
--- a/server/sbus/sssd_dbus_private.h
+++ b/server/sbus/sssd_dbus_private.h
@@ -1,8 +1,43 @@
#ifndef _SSSD_DBUS_PRIVATE_H_
#define _SSSD_DBUS_PRIVATE_H_
-struct timeval _dbus_timeout_get_interval_tv(int interval);
+union dbus_pointer {
+ DBusServer *server;
+ DBusConnection *conn;
+};
+enum dbus_pointer_type {
+ SBUS_SERVER,
+ SBUS_CONNECTION
+};
+
+struct sbus_generic_dbus_ctx {
+ struct tevent_context *ev;
+ enum dbus_pointer_type type;
+ union dbus_pointer dbus;
+};
+
+/* =Watches=============================================================== */
+
+struct sbus_watch_ctx {
+ DBusWatch *dbus_watch;
+ enum dbus_pointer_type dbus_type;
+ union dbus_pointer dbus;
+ struct tevent_fd *fde;
+};
+
+dbus_bool_t sbus_add_watch(DBusWatch *watch, void *data);
+void sbus_toggle_watch(DBusWatch *watch, void *data);
void sbus_remove_watch(DBusWatch *watch, void *data);
-void sbus_remove_timeout(DBusTimeout *timeout, void *data);
+
+/* =Timeouts============================================================== */
+
+struct sbus_timeout_ctx {
+ DBusTimeout *dbus_timeout;
+ struct tevent_timer *te;
+};
+
+dbus_bool_t sbus_add_timeout(DBusTimeout *dbus_timeout, void *data);
+void sbus_toggle_timeout(DBusTimeout *dbus_timeout, void *data);
+void sbus_remove_timeout(DBusTimeout *dbus_timeout, void *data);
#endif /* _SSSD_DBUS_PRIVATE_H_ */
diff --git a/server/sbus/sssd_dbus_server.c b/server/sbus/sssd_dbus_server.c
index cf668d33..6df004d3 100644
--- a/server/sbus/sssd_dbus_server.c
+++ b/server/sbus/sssd_dbus_server.c
@@ -43,160 +43,9 @@ struct sbus_srv_ctx {
void *init_pvt_data;
};
-struct sbus_srv_watch_ctx {
- DBusWatch *watch;
- int fd;
- struct tevent_fd *fde;
- struct sbus_srv_ctx *srv_ctx;
-};
-
-struct dbus_srv_timeout_ctx {
- DBusTimeout *timeout;
- struct tevent_timer *te;
- struct sbus_srv_ctx *srv_ctx;
-};
-
static int sbus_server_destructor(void *ctx);
/*
- * dbus_server_read_write_handler
- * Callback for D-BUS to handle messages on a file-descriptor
- */
-static void sbus_srv_read_write_handler(struct tevent_context *ev,
- struct tevent_fd *fde,
- uint16_t flags, void *data)
-{
- struct sbus_srv_watch_ctx *watch_ctx;
- watch_ctx = talloc_get_type(data, struct sbus_srv_watch_ctx);
-
- dbus_server_ref(watch_ctx->srv_ctx->dbus_server);
- if (flags & TEVENT_FD_READ) {
- dbus_watch_handle(watch_ctx->watch, DBUS_WATCH_READABLE);
- }
- if (flags & TEVENT_FD_WRITE) {
- dbus_watch_handle(watch_ctx->watch, DBUS_WATCH_WRITABLE);
- }
- dbus_server_unref(watch_ctx->srv_ctx->dbus_server);
-}
-
-/*
- * add_server_watch
- * Set up hooks into the libevents mainloop for
- * D-BUS to add file descriptor-based events
- */
-static dbus_bool_t sbus_add_srv_watch(DBusWatch *watch, void *data)
-{
- unsigned int flags;
- unsigned int event_flags;
- struct sbus_srv_ctx *srv_ctx;
- struct sbus_srv_watch_ctx *watch_ctx;
-
- if (!dbus_watch_get_enabled(watch)) {
- return FALSE;
- }
-
- srv_ctx = talloc_get_type(data, struct sbus_srv_ctx);
-
- watch_ctx = talloc_zero(srv_ctx, struct sbus_srv_watch_ctx);
- watch_ctx->srv_ctx = srv_ctx;
- watch_ctx->watch = watch;
-
- flags = dbus_watch_get_flags(watch);
-#ifdef HAVE_DBUS_WATCH_GET_UNIX_FD
- watch_ctx->fd = dbus_watch_get_unix_fd(watch);
-#else
- watch_ctx->fd = dbus_watch_get_fd(watch);
-#endif
-
- event_flags = 0;
-
- if (flags & DBUS_WATCH_READABLE) {
- event_flags |= TEVENT_FD_READ;
- }
-
- if (flags & DBUS_WATCH_WRITABLE) {
- event_flags |= TEVENT_FD_WRITE;
- }
- DEBUG(5,("%lX: %d, %d=%s\n", watch, watch_ctx->fd, event_flags, event_flags==TEVENT_FD_READ?"READ":"WRITE"));
-
- watch_ctx->fde = tevent_add_fd(srv_ctx->ev, watch_ctx, watch_ctx->fd,
- event_flags, sbus_srv_read_write_handler,
- watch_ctx);
-
- /* Save the event to the watch object so it can be removed later */
- dbus_watch_set_data(watch_ctx->watch, watch_ctx->fde, NULL);
-
- return TRUE;
-}
-
-/*
- * server_watch_toggled
- * Hook for D-BUS to toggle the enabled/disabled state of
- * an event in the mainloop
- */
-static void sbus_toggle_srv_watch(DBusWatch *watch, void *data)
-{
- if (dbus_watch_get_enabled(watch)) {
- sbus_add_srv_watch(watch, data);
- } else {
- sbus_remove_watch(watch, data);
- }
-}
-
-static void sbus_srv_timeout_handler(struct tevent_context *ev,
- struct tevent_timer *te,
- struct timeval t, void *data)
-{
- struct dbus_srv_timeout_ctx *timeout_ctx;
- timeout_ctx = talloc_get_type(data, struct dbus_srv_timeout_ctx);
- dbus_timeout_handle(timeout_ctx->timeout);
-}
-
-/*
- * add_server_timeout
- * Hook for D-BUS to add time-based events to the mainloop
- */
-static dbus_bool_t sbus_add_srv_timeout(DBusTimeout *timeout, void *data)
-{
- struct sbus_srv_ctx *srv_ctx;
- struct dbus_srv_timeout_ctx *timeout_ctx;
- struct timeval tv;
-
- if (!dbus_timeout_get_enabled(timeout))
- return TRUE;
-
- srv_ctx = talloc_get_type(data, struct sbus_srv_ctx);
-
- timeout_ctx = talloc_zero(srv_ctx,struct dbus_srv_timeout_ctx);
- timeout_ctx->srv_ctx = srv_ctx;
- timeout_ctx->timeout = timeout;
-
- tv = _dbus_timeout_get_interval_tv(dbus_timeout_get_interval(timeout));
-
- timeout_ctx->te = tevent_add_timer(srv_ctx->ev, timeout_ctx, tv,
- sbus_srv_timeout_handler, timeout_ctx);
-
- /* Save the event to the watch object so it can be removed later */
- dbus_timeout_set_data(timeout_ctx->timeout, timeout_ctx->te, NULL);
-
- return TRUE;
-}
-
-/*
- * server_timeout_toggled
- * Hook for D-BUS to toggle the enabled/disabled state of a mainloop
- * event
- */
-static void sbus_toggle_srv_timeout(DBusTimeout *timeout, void *data)
-{
- if (dbus_timeout_get_enabled(timeout)) {
- sbus_add_srv_timeout(timeout, data);
- } else {
- sbus_remove_timeout(timeout, data);
- }
-}
-
-/*
* new_connection_callback
* Actions to be run upon each new client connection
* Must either perform dbus_connection_ref() on the
@@ -262,6 +111,7 @@ int sbus_new_server(TALLOC_CTX *mem_ctx,
struct sbus_srv_ctx **_srv_ctx, const char *address,
sbus_server_conn_init_fn init_fn, void *init_pvt_data)
{
+ struct sbus_generic_dbus_ctx *gen_ctx;
struct sbus_srv_ctx *srv_ctx;
DBusServer *dbus_server;
DBusError dbus_error;
@@ -295,6 +145,15 @@ int sbus_new_server(TALLOC_CTX *mem_ctx,
srv_ctx->init_fn = init_fn;
srv_ctx->init_pvt_data = init_pvt_data;
+ gen_ctx = talloc_zero(srv_ctx, struct sbus_generic_dbus_ctx);
+ if (!gen_ctx) {
+ talloc_free(srv_ctx);
+ return ENOMEM;
+ }
+ gen_ctx->ev = ev;
+ gen_ctx->type = SBUS_SERVER;
+ gen_ctx->dbus.server = dbus_server;
+
talloc_set_destructor((TALLOC_CTX *)srv_ctx, sbus_server_destructor);
/* Set up D-BUS new connection handler */
@@ -304,10 +163,10 @@ int sbus_new_server(TALLOC_CTX *mem_ctx,
/* Set up DBusWatch functions */
dbret = dbus_server_set_watch_functions(srv_ctx->dbus_server,
- sbus_add_srv_watch,
+ sbus_add_watch,
sbus_remove_watch,
- sbus_toggle_srv_watch,
- srv_ctx, NULL);
+ sbus_toggle_watch,
+ gen_ctx, NULL);
if (!dbret) {
DEBUG(4, ("Error setting up D-BUS server watch functions"));
talloc_free(srv_ctx);
@@ -316,10 +175,10 @@ int sbus_new_server(TALLOC_CTX *mem_ctx,
/* Set up DBusTimeout functions */
dbret = dbus_server_set_timeout_functions(srv_ctx->dbus_server,
- sbus_add_srv_timeout,
+ sbus_add_timeout,
sbus_remove_timeout,
- sbus_toggle_srv_timeout,
- srv_ctx, NULL);
+ sbus_toggle_timeout,
+ gen_ctx, NULL);
if (!dbret) {
DEBUG(4,("Error setting up D-BUS server timeout functions"));
dbus_server_set_watch_functions(srv_ctx->dbus_server,