sssd_dbus.h revision c4545b1e910857bc0dae7ce2ed6291d8bd1fc4f2
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync/*
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync SSSD
d34409ad02ea0d28e08a6c4b089a412fdb3b4c9cvboxsync
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync SSSD - D-BUS interface
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync Copyright (C) Stephen Gallagher 2008
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync This program is free software; you can redistribute it and/or modify
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync it under the terms of the GNU General Public License as published by
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync the Free Software Foundation; either version 3 of the License, or
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync (at your option) any later version.
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync This program is distributed in the hope that it will be useful,
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync but WITHOUT ANY WARRANTY; without even the implied warranty of
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync GNU General Public License for more details.
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync You should have received a copy of the GNU General Public License
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync along with this program. If not, see <http://www.gnu.org/licenses/>.
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync*/
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync#ifndef _SSSD_DBUS_H_
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync#define _SSSD_DBUS_H_
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsyncstruct sbus_connection;
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync#include "dbus/dbus.h"
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsynctypedef int (*sbus_msg_handler_fn)(DBusMessage *, struct sbus_connection *);
a9b62afc62b28da7a1a77f34259f8013892d9664vboxsync
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync/*
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync * sbus_conn_destructor_fn
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync * Function to be called when a connection is finalized
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync */
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsynctypedef int (*sbus_conn_destructor_fn)(void *);
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsynctypedef void (*sbus_conn_reconn_callback_fn)(struct sbus_connection *, int, void *);
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync/*
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync * sbus_server_conn_init_fn
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync * Set up function for connection-specific activities
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync * This function should define the sbus_conn_destructor_fn
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync * for this connection at a minimum
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync */
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsynctypedef int (*sbus_server_conn_init_fn)(struct sbus_connection *, void *);
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsyncenum {
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync SBUS_CONN_TYPE_PRIVATE = 1,
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync SBUS_CONN_TYPE_SHARED
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync};
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsyncenum {
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync SBUS_RECONNECT_SUCCESS = 1,
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync SBUS_RECONNECT_EXCEEDED_RETRIES,
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync SBUS_RECONNECT_ERROR
a6b9fb03568b86eb6be55f1db015eab0921f7ee0vboxsync};
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync/* Special interface and method for D-BUS introspection */
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync#define DBUS_INTROSPECT_INTERFACE "org.freedesktop.DBus.Introspectable"
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync#define DBUS_INTROSPECT_METHOD "Introspect"
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync#define SBUS_DEFAULT_VTABLE { NULL, sbus_message_handler, NULL, NULL, NULL, NULL }
319b6c2f1a5b5420b0a7fbef89477984cec16007vboxsync
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsyncstruct sbus_method {
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync const char *method;
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync sbus_msg_handler_fn fn;
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync};
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsyncstruct sbus_interface {
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync const char *interface;
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync const char *path;
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync DBusObjectPathVTable vtable;
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync struct sbus_method *methods;
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync sbus_msg_handler_fn introspect_fn;
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync};
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync/* Server Functions */
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsyncint sbus_new_server(TALLOC_CTX *mem_ctx,
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync struct tevent_context *ev,
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync const char *address,
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync struct sbus_interface *intf,
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync bool use_symlink,
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync struct sbus_connection **server,
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync sbus_server_conn_init_fn init_fn, void *init_pvt_data);
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync/* Connection Functions */
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync/* sbus_new_connection
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync * Use this function when connecting a new process to
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync * the standard SSSD interface.
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync * This will connect to the address specified and then
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync * call sbus_add_connection to integrate with the main
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync * loop.
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync */
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsyncint sbus_new_connection(TALLOC_CTX *ctx,
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync struct tevent_context *ev,
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync const char *address,
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync struct sbus_interface *intf,
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync struct sbus_connection **conn);
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync/* sbus_add_connection
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync * Integrates a D-BUS connection with the TEvent main
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync * loop. Use this function when you already have a
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync * DBusConnection object (for example from dbus_bus_get)
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync * Connection type can be either:
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync * SBUS_CONN_TYPE_PRIVATE: Used only from within a D-BUS
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync * server such as the Monitor in the
3b0af6c6de3509194973be62078331fc930175f7vboxsync * new_connection_callback
3b0af6c6de3509194973be62078331fc930175f7vboxsync * SBUS_CONN_TYPE_SHARED: Used for all D-BUS client
3b0af6c6de3509194973be62078331fc930175f7vboxsync * connections, including those retrieved from
3b0af6c6de3509194973be62078331fc930175f7vboxsync * dbus_bus_get
3b0af6c6de3509194973be62078331fc930175f7vboxsync */
3b0af6c6de3509194973be62078331fc930175f7vboxsyncint sbus_init_connection(TALLOC_CTX *ctx,
3b0af6c6de3509194973be62078331fc930175f7vboxsync struct tevent_context *ev,
3b0af6c6de3509194973be62078331fc930175f7vboxsync DBusConnection *dbus_conn,
3b0af6c6de3509194973be62078331fc930175f7vboxsync struct sbus_interface *intf,
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync int connection_type,
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync struct sbus_connection **_conn);
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsyncvoid sbus_conn_set_destructor(struct sbus_connection *conn,
a6b9fb03568b86eb6be55f1db015eab0921f7ee0vboxsync sbus_conn_destructor_fn destructor);
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsyncint sbus_default_connection_destructor(void *ctx);
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsyncDBusConnection *sbus_get_connection(struct sbus_connection *conn);
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsyncvoid sbus_disconnect(struct sbus_connection *conn);
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsyncvoid sbus_conn_set_private_data(struct sbus_connection *conn, void *pvt_data);
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsyncvoid *sbus_conn_get_private_data(struct sbus_connection *conn);
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsyncint sbus_conn_add_interface(struct sbus_connection *conn,
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync struct sbus_interface *intf);
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsyncbool sbus_conn_disconnecting(struct sbus_connection *conn);
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync
cdaeb34871aa28b96c0d80b474f3c8f9805d0388vboxsync/* max_retries < 0: retry forever
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync * max_retries = 0: never retry (why are you calling this function?)
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync * max_retries > 0: obvious
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync */
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsyncvoid sbus_reconnect_init(struct sbus_connection *conn,
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync int max_retries,
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync sbus_conn_reconn_callback_fn callback,
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync void *pvt);
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync/* Default message handler
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync * Should be usable for most cases */
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsyncDBusHandlerResult sbus_message_handler(DBusConnection *conn,
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync DBusMessage *message,
3b0af6c6de3509194973be62078331fc930175f7vboxsync void *user_data);
3b0af6c6de3509194973be62078331fc930175f7vboxsync
3b0af6c6de3509194973be62078331fc930175f7vboxsync/*
3b0af6c6de3509194973be62078331fc930175f7vboxsync * Send a message across the SBUS
3b0af6c6de3509194973be62078331fc930175f7vboxsync * If requested, the DBusPendingCall object will
3b0af6c6de3509194973be62078331fc930175f7vboxsync * be returned to the caller.
3b0af6c6de3509194973be62078331fc930175f7vboxsync *
3b0af6c6de3509194973be62078331fc930175f7vboxsync * This function will return EAGAIN in the event
3b0af6c6de3509194973be62078331fc930175f7vboxsync * that the connection is not open for
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync * communication.
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync */
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsyncint sbus_conn_send(struct sbus_connection *conn,
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync DBusMessage *msg,
a6b9fb03568b86eb6be55f1db015eab0921f7ee0vboxsync int timeout_ms,
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync DBusPendingCallNotifyFunction reply_handler,
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync void *pvt,
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync DBusPendingCall **pending);
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsyncvoid sbus_conn_send_reply(struct sbus_connection *conn,
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync DBusMessage *reply);
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync#endif /* _SSSD_DBUS_H_*/
3c4dd6a990d38eba0aad586bb42f72d2b10b682avboxsync