From 393099fb7caa2c128277e26ba3463aa7f95a0ebb Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Tue, 29 Apr 2014 23:39:45 +0200 Subject: SBUS: Split out dbus_conn_send MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Split dbus_conn_send out of sbus_conn_send to be able to call DBus messages without having a full sbus connection. This function is available to the sbus code only, consumers of sbus (responders and providers) should use sbus_conn_send. Reviewed-by: Pavel Březina Reviewed-by: Stef Walter --- src/sbus/sssd_dbus_connection.c | 56 +++++++++++++++++++++++++---------------- src/sbus/sssd_dbus_private.h | 11 ++++++++ 2 files changed, 45 insertions(+), 22 deletions(-) diff --git a/src/sbus/sssd_dbus_connection.c b/src/sbus/sssd_dbus_connection.c index f27474745..7ea70efa5 100644 --- a/src/sbus/sssd_dbus_connection.c +++ b/src/sbus/sssd_dbus_connection.c @@ -701,32 +701,16 @@ bool sbus_conn_disconnecting(struct sbus_connection *conn) return false; } -/* - * Send a message across the SBUS - * If requested, the DBusPendingCall object will - * be returned to the caller. - * - * This function will return EAGAIN in the event - * that the connection is not open for - * communication. - */ -int sbus_conn_send(struct sbus_connection *conn, - DBusMessage *msg, - int timeout_ms, - DBusPendingCallNotifyFunction reply_handler, - void *pvt, - DBusPendingCall **pending) +int sss_dbus_conn_send(DBusConnection *dbus_conn, + DBusMessage *msg, + int timeout_ms, + DBusPendingCallNotifyFunction reply_handler, + void *pvt, + DBusPendingCall **pending) { DBusPendingCall *pending_reply; - DBusConnection *dbus_conn; dbus_bool_t dbret; - dbus_conn = sbus_get_connection(conn); - if (!dbus_conn) { - DEBUG(SSSDBG_CRIT_FAILURE, "D-BUS not connected\n"); - return ENOTCONN; - } - dbret = dbus_connection_send_with_reply(dbus_conn, msg, &pending_reply, timeout_ms); @@ -770,6 +754,34 @@ int sbus_conn_send(struct sbus_connection *conn, return EAGAIN; } +/* + * Send a message across the SBUS + * If requested, the DBusPendingCall object will + * be returned to the caller. + * + * This function will return EAGAIN in the event + * that the connection is not open for + * communication. + */ +int sbus_conn_send(struct sbus_connection *conn, + DBusMessage *msg, + int timeout_ms, + DBusPendingCallNotifyFunction reply_handler, + void *pvt, + DBusPendingCall **pending) +{ + DBusConnection *dbus_conn; + + dbus_conn = sbus_get_connection(conn); + if (!dbus_conn) { + DEBUG(SSSDBG_CRIT_FAILURE, "D-BUS not connected\n"); + return ENOTCONN; + } + + return sss_dbus_conn_send(dbus_conn, msg, timeout_ms, + reply_handler, pvt, pending); +} + void sbus_conn_send_reply(struct sbus_connection *conn, DBusMessage *reply) { dbus_connection_send(conn->dbus.conn, reply, NULL); diff --git a/src/sbus/sssd_dbus_private.h b/src/sbus/sssd_dbus_private.h index 4916700b5..58b385b71 100644 --- a/src/sbus/sssd_dbus_private.h +++ b/src/sbus/sssd_dbus_private.h @@ -115,4 +115,15 @@ sbus_request_invoke_or_finish(struct sbus_request *dbus_req, void *handler_data, sbus_method_invoker_fn invoker_fn); +/* A low-level, private variant of sbus_conn_send that accepts just + * DBusConnection. It should never be used outside sbus code, responders + * and back ends should use sbus_conn_send! + */ +int sss_dbus_conn_send(DBusConnection *dbus_conn, + DBusMessage *msg, + int timeout_ms, + DBusPendingCallNotifyFunction reply_handler, + void *pvt, + DBusPendingCall **pending); + #endif /* _SSSD_DBUS_PRIVATE_H_ */ -- cgit