summaryrefslogtreecommitdiffstats
path: root/server/sbus/sssd_dbus_connection.c
diff options
context:
space:
mode:
Diffstat (limited to 'server/sbus/sssd_dbus_connection.c')
-rw-r--r--server/sbus/sssd_dbus_connection.c294
1 files changed, 147 insertions, 147 deletions
diff --git a/server/sbus/sssd_dbus_connection.c b/server/sbus/sssd_dbus_connection.c
index 70ddefd9f..8e4c3048b 100644
--- a/server/sbus/sssd_dbus_connection.c
+++ b/server/sbus/sssd_dbus_connection.c
@@ -7,7 +7,7 @@
/* Types */
struct dbus_ctx_list;
-struct sbus_conn_ctx {
+struct sbus_connection {
struct tevent_context *ev;
DBusConnection *dbus_conn;
char *address;
@@ -25,36 +25,36 @@ struct sbus_conn_ctx {
};
struct sbus_message_handler_ctx {
- struct sbus_conn_ctx *conn_ctx;
+ struct sbus_connection *conn;
struct sbus_method_ctx *method_ctx;
};
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);
+static void sbus_unreg_object_paths(struct sbus_connection *conn);
-static int sbus_auto_reconnect(struct sbus_conn_ctx *conn_ctx);
+static int sbus_auto_reconnect(struct sbus_connection *conn);
static void sbus_dispatch(struct tevent_context *ev,
struct tevent_timer *te,
struct timeval tv, void *data)
{
struct tevent_timer *new_event;
- struct sbus_conn_ctx *conn_ctx;
+ struct sbus_connection *conn;
DBusConnection *dbus_conn;
int ret;
if (data == NULL) return;
- conn_ctx = talloc_get_type(data, struct sbus_conn_ctx);
+ conn = talloc_get_type(data, struct sbus_connection);
- dbus_conn = conn_ctx->dbus_conn;
+ dbus_conn = conn->dbus_conn;
DEBUG(6, ("dbus conn: %lX\n", dbus_conn));
- if (conn_ctx->retries > 0) {
+ if (conn->retries > 0) {
DEBUG(6, ("SBUS is reconnecting. Deferring.\n"));
/* Currently trying to reconnect, defer dispatch */
- new_event = tevent_add_timer(ev, conn_ctx, tv, sbus_dispatch, conn_ctx);
+ new_event = tevent_add_timer(ev, conn, tv, sbus_dispatch, conn);
if (new_event == NULL) {
DEBUG(0,("Could not defer dispatch!\n"));
}
@@ -62,30 +62,30 @@ static void sbus_dispatch(struct tevent_context *ev,
}
if ((!dbus_connection_get_is_connected(dbus_conn)) &&
- (conn_ctx->max_retries != 0)) {
+ (conn->max_retries != 0)) {
/* Attempt to reconnect automatically */
- ret = sbus_auto_reconnect(conn_ctx);
+ ret = sbus_auto_reconnect(conn);
if (ret == EOK) {
DEBUG(1, ("Performing auto-reconnect\n"));
return;
}
DEBUG(0, ("Cannot start auto-reconnection.\n"));
- conn_ctx->reconnect_callback(conn_ctx,
+ conn->reconnect_callback(conn,
SBUS_RECONNECT_ERROR,
- conn_ctx->reconnect_pvt);
+ conn->reconnect_pvt);
return;
}
- if ((conn_ctx->disconnect) ||
+ if ((conn->disconnect) ||
(!dbus_connection_get_is_connected(dbus_conn))) {
DEBUG(3,("Connection is not open for dispatching.\n"));
/*
* Free the connection object.
* This will invoke the destructor for the connection
*/
- talloc_free(conn_ctx);
- conn_ctx = NULL;
+ talloc_free(conn);
+ conn = NULL;
return;
}
@@ -103,7 +103,7 @@ static void sbus_dispatch(struct tevent_context *ev,
*/
ret = dbus_connection_get_dispatch_status(dbus_conn);
if (ret != DBUS_DISPATCH_COMPLETE) {
- new_event = tevent_add_timer(ev, conn_ctx, tv, sbus_dispatch, conn_ctx);
+ new_event = tevent_add_timer(ev, conn, tv, sbus_dispatch, conn);
if (new_event == NULL) {
DEBUG(2,("Could not add dispatch event!\n"));
@@ -122,15 +122,15 @@ static void sbus_dispatch(struct tevent_context *ev,
*/
static void sbus_conn_wakeup_main(void *data)
{
- struct sbus_conn_ctx *conn_ctx;
+ struct sbus_connection *conn;
struct timeval tv;
struct tevent_timer *te;
- conn_ctx = talloc_get_type(data, struct sbus_conn_ctx);
+ conn = talloc_get_type(data, struct sbus_connection);
gettimeofday(&tv, NULL);
/* D-BUS calls this function when it is time to do a dispatch */
- te = tevent_add_timer(conn_ctx->ev, conn_ctx, tv, sbus_dispatch, conn_ctx);
+ te = tevent_add_timer(conn->ev, conn, tv, sbus_dispatch, conn);
if (te == NULL) {
DEBUG(2,("Could not add dispatch event!\n"));
/* TODO: Calling exit here is bad */
@@ -138,7 +138,7 @@ static void sbus_conn_wakeup_main(void *data)
}
}
-static int sbus_add_connection_int(struct sbus_conn_ctx **conn_ctx);
+static int sbus_add_connection_int(struct sbus_connection **conn);
/*
* integrate_connection_with_event_loop
@@ -148,40 +148,40 @@ static int sbus_add_connection_int(struct sbus_conn_ctx **conn_ctx);
int sbus_add_connection(TALLOC_CTX *ctx,
struct tevent_context *ev,
DBusConnection *dbus_conn,
- struct sbus_conn_ctx **_conn_ctx,
+ struct sbus_connection **_conn,
int connection_type)
{
- struct sbus_conn_ctx *conn_ctx;
+ struct sbus_connection *conn;
int ret;
DEBUG(5,("Adding connection %lX\n", dbus_conn));
- conn_ctx = talloc_zero(ctx, struct sbus_conn_ctx);
+ conn = talloc_zero(ctx, struct sbus_connection);
- conn_ctx->ev = ev;
- conn_ctx->dbus_conn = dbus_conn;
- conn_ctx->connection_type = connection_type;
- conn_ctx->disconnect = 0;
+ conn->ev = ev;
+ conn->dbus_conn = dbus_conn;
+ conn->connection_type = connection_type;
+ conn->disconnect = 0;
/* This will be replaced on the first call to sbus_conn_add_method_ctx() */
- conn_ctx->method_ctx_list = NULL;
+ conn->method_ctx_list = NULL;
/* This can be overridden by a call to sbus_reconnect_init() */
- conn_ctx->retries = 0;
- conn_ctx->max_retries = 0;
- conn_ctx->reconnect_callback = NULL;
+ conn->retries = 0;
+ conn->max_retries = 0;
+ conn->reconnect_callback = NULL;
- *_conn_ctx = conn_ctx;
+ *_conn = conn;
- ret = sbus_add_connection_int(_conn_ctx);
+ ret = sbus_add_connection_int(_conn);
if (ret != EOK) {
- talloc_free(conn_ctx);
+ talloc_free(conn);
}
return ret;
}
-static int sbus_add_connection_int(struct sbus_conn_ctx **_conn_ctx)
+static int sbus_add_connection_int(struct sbus_connection **_conn)
{
- struct sbus_conn_ctx *conn_ctx = *_conn_ctx;
+ struct sbus_connection *conn = *_conn;
struct sbus_generic_dbus_ctx *gen_ctx;
dbus_bool_t dbret;
@@ -190,19 +190,19 @@ static int sbus_add_connection_int(struct sbus_conn_ctx **_conn_ctx)
* Connections can override this with
* sbus_conn_set_destructor
*/
- sbus_conn_set_destructor(conn_ctx, NULL);
+ sbus_conn_set_destructor(conn, NULL);
- gen_ctx = talloc_zero(conn_ctx, struct sbus_generic_dbus_ctx);
+ gen_ctx = talloc_zero(conn, struct sbus_generic_dbus_ctx);
if (!gen_ctx) {
DEBUG(0, ("Out of memory!\n"));
return ENOMEM;
}
- gen_ctx->ev = conn_ctx->ev;
+ gen_ctx->ev = conn->ev;
gen_ctx->type = SBUS_CONNECTION;
- gen_ctx->dbus.conn = conn_ctx->dbus_conn;
+ gen_ctx->dbus.conn = conn->dbus_conn;
/* Set up DBusWatch functions */
- dbret = dbus_connection_set_watch_functions(conn_ctx->dbus_conn,
+ dbret = dbus_connection_set_watch_functions(conn->dbus_conn,
sbus_add_watch,
sbus_remove_watch,
sbus_toggle_watch,
@@ -213,7 +213,7 @@ 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,
+ dbret = dbus_connection_set_timeout_functions(conn->dbus_conn,
sbus_add_timeout,
sbus_remove_timeout,
sbus_toggle_timeout,
@@ -225,9 +225,9 @@ static int sbus_add_connection_int(struct sbus_conn_ctx **_conn_ctx)
}
/* Set up dispatch handler */
- dbus_connection_set_wakeup_main_function(conn_ctx->dbus_conn,
+ dbus_connection_set_wakeup_main_function(conn->dbus_conn,
sbus_conn_wakeup_main,
- conn_ctx, NULL);
+ conn, NULL);
/* Set up any method_contexts passed in */
@@ -236,17 +236,17 @@ static int sbus_add_connection_int(struct sbus_conn_ctx **_conn_ctx)
* If there are no messages to be dispatched, this will do
* nothing.
*/
- sbus_conn_wakeup_main(conn_ctx);
+ sbus_conn_wakeup_main(conn);
/* Return the new toplevel object */
- *_conn_ctx = conn_ctx;
+ *_conn = conn;
return EOK;
}
int sbus_new_connection(TALLOC_CTX *ctx, struct tevent_context *ev,
const char *address,
- struct sbus_conn_ctx **conn_ctx)
+ struct sbus_connection **conn)
{
DBusConnection *dbus_conn;
DBusError dbus_error;
@@ -264,15 +264,15 @@ int sbus_new_connection(TALLOC_CTX *ctx, struct tevent_context *ev,
}
ret = sbus_add_connection(ctx, ev, dbus_conn,
- conn_ctx, SBUS_CONN_TYPE_SHARED);
+ conn, SBUS_CONN_TYPE_SHARED);
if (ret != EOK) {
/* FIXME: release resources */
}
/* Store the address for later reconnection */
- (*conn_ctx)->address = talloc_strdup((*conn_ctx), address);
+ (*conn)->address = talloc_strdup((*conn), address);
- dbus_connection_set_exit_on_disconnect((*conn_ctx)->dbus_conn, FALSE);
+ dbus_connection_set_exit_on_disconnect((*conn)->dbus_conn, FALSE);
return ret;
}
@@ -281,33 +281,33 @@ int sbus_new_connection(TALLOC_CTX *ctx, struct tevent_context *ev,
* sbus_conn_set_destructor
* Configures a callback to clean up this connection when it
* is finalized.
- * @param conn_ctx The sbus_conn_ctx created
+ * @param conn The sbus_connection created
* when this connection was established
* @param destructor The destructor function that should be
* called when the connection is finalized. If passed NULL,
* this will reset the connection to the default destructor.
*/
-void sbus_conn_set_destructor(struct sbus_conn_ctx *conn_ctx,
+void sbus_conn_set_destructor(struct sbus_connection *conn,
sbus_conn_destructor_fn destructor)
{
- if (!conn_ctx) return;
+ if (!conn) return;
- conn_ctx->destructor = destructor;
+ conn->destructor = destructor;
/* TODO: Should we try to handle the talloc_destructor too? */
}
int sbus_default_connection_destructor(void *ctx)
{
- struct sbus_conn_ctx *conn_ctx;
- conn_ctx = talloc_get_type(ctx, struct sbus_conn_ctx);
+ struct sbus_connection *conn;
+ conn = talloc_get_type(ctx, struct sbus_connection);
DEBUG(5, ("Invoking default destructor on connection %lX\n",
- conn_ctx->dbus_conn));
- if (conn_ctx->connection_type == SBUS_CONN_TYPE_PRIVATE) {
+ conn->dbus_conn));
+ if (conn->connection_type == SBUS_CONN_TYPE_PRIVATE) {
/* Private connections must be closed explicitly */
- dbus_connection_close(conn_ctx->dbus_conn);
+ dbus_connection_close(conn->dbus_conn);
}
- else if (conn_ctx->connection_type == SBUS_CONN_TYPE_SHARED) {
+ else if (conn->connection_type == SBUS_CONN_TYPE_SHARED) {
/* Shared connections are destroyed when their last reference is removed */
}
else {
@@ -319,75 +319,75 @@ int sbus_default_connection_destructor(void *ctx)
/* Remove object path */
/* TODO: Remove object paths */
- dbus_connection_unref(conn_ctx->dbus_conn);
+ dbus_connection_unref(conn->dbus_conn);
return 0;
}
/*
* sbus_get_connection
* Utility function to retreive the DBusConnection object
- * from a sbus_conn_ctx
+ * from a sbus_connection
*/
-DBusConnection *sbus_get_connection(struct sbus_conn_ctx *conn_ctx)
+DBusConnection *sbus_get_connection(struct sbus_connection *conn)
{
- return conn_ctx->dbus_conn;
+ return conn->dbus_conn;
}
-void sbus_disconnect (struct sbus_conn_ctx *conn_ctx)
+void sbus_disconnect (struct sbus_connection *conn)
{
- if (conn_ctx == NULL) {
+ if (conn == NULL) {
return;
}
- DEBUG(5,("Disconnecting %lX\n", conn_ctx->dbus_conn));
+ DEBUG(5,("Disconnecting %lX\n", conn->dbus_conn));
/*******************************
- * Referencing conn_ctx->dbus_conn */
- dbus_connection_ref(conn_ctx->dbus_conn);
+ * Referencing conn->dbus_conn */
+ dbus_connection_ref(conn->dbus_conn);
- conn_ctx->disconnect = 1;
+ conn->disconnect = 1;
/* Invoke the custom destructor, if it exists */
- if (conn_ctx->destructor) {
- conn_ctx->destructor(conn_ctx);
+ if (conn->destructor) {
+ conn->destructor(conn);
}
/* Unregister object paths */
- sbus_unreg_object_paths(conn_ctx);
+ sbus_unreg_object_paths(conn);
/* Disable watch functions */
- dbus_connection_set_watch_functions(conn_ctx->dbus_conn,
+ dbus_connection_set_watch_functions(conn->dbus_conn,
NULL, NULL, NULL,
NULL, NULL);
/* Disable timeout functions */
- dbus_connection_set_timeout_functions(conn_ctx->dbus_conn,
+ dbus_connection_set_timeout_functions(conn->dbus_conn,
NULL, NULL, NULL,
NULL, NULL);
/* Disable dispatch status function */
- dbus_connection_set_dispatch_status_function(conn_ctx->dbus_conn,
+ dbus_connection_set_dispatch_status_function(conn->dbus_conn,
NULL, NULL, NULL);
/* Disable wakeup main function */
- dbus_connection_set_wakeup_main_function(conn_ctx->dbus_conn,
+ dbus_connection_set_wakeup_main_function(conn->dbus_conn,
NULL, NULL, NULL);
/* Finalize the connection */
- sbus_default_connection_destructor(conn_ctx);
+ sbus_default_connection_destructor(conn);
- dbus_connection_unref(conn_ctx->dbus_conn);
- /* Unreferenced conn_ctx->dbus_conn *
+ dbus_connection_unref(conn->dbus_conn);
+ /* Unreferenced conn->dbus_conn *
******************************/
- DEBUG(5,("Disconnected %lX\n", conn_ctx->dbus_conn));
+ DEBUG(5,("Disconnected %lX\n", conn->dbus_conn));
}
static int sbus_reply_internal_error(DBusMessage *message,
- struct sbus_conn_ctx *conn_ctx) {
+ struct sbus_connection *conn) {
DBusMessage *reply = dbus_message_new_error(message, DBUS_ERROR_IO_ERROR,
"Internal Error");
if (reply) {
- sbus_conn_send_reply(conn_ctx, reply);
+ sbus_conn_send_reply(conn, reply);
dbus_message_unref(reply);
return DBUS_HANDLER_RESULT_HANDLED;
}
@@ -397,7 +397,7 @@ static int sbus_reply_internal_error(DBusMessage *message,
/* messsage_handler
* Receive messages and process them
*/
-DBusHandlerResult sbus_message_handler(DBusConnection *conn,
+DBusHandlerResult sbus_message_handler(DBusConnection *dbus_conn,
DBusMessage *message,
void *user_data)
{
@@ -432,9 +432,9 @@ DBusHandlerResult sbus_message_handler(DBusConnection *conn,
for (i = 0; ctx->method_ctx->methods[i].method != NULL; i++) {
if (strcmp(method, ctx->method_ctx->methods[i].method) == 0) {
found = 1;
- ret = ctx->method_ctx->methods[i].fn(message, ctx->conn_ctx);
+ ret = ctx->method_ctx->methods[i].fn(message, ctx->conn);
if (ret != EOK) return sbus_reply_internal_error(message,
- ctx->conn_ctx);
+ ctx->conn);
break;
}
}
@@ -443,7 +443,7 @@ DBusHandlerResult sbus_message_handler(DBusConnection *conn,
/* Reply DBUS_ERROR_UNKNOWN_METHOD */
DEBUG(1, ("No matching method found for %s.\n", method));
reply = dbus_message_new_error(message, DBUS_ERROR_UNKNOWN_METHOD, NULL);
- sbus_conn_send_reply(ctx->conn_ctx, reply);
+ sbus_conn_send_reply(ctx->conn, reply);
dbus_message_unref(reply);
}
}
@@ -458,9 +458,9 @@ DBusHandlerResult sbus_message_handler(DBusConnection *conn,
/* If we have been asked for introspection data and we have
* an introspection function registered, user that.
*/
- ret = ctx->method_ctx->introspect_fn(message, ctx->conn_ctx);
+ ret = ctx->method_ctx->introspect_fn(message, ctx->conn);
if (ret != EOK) return sbus_reply_internal_error(message,
- ctx->conn_ctx);
+ ctx->conn);
}
}
else
@@ -473,7 +473,7 @@ DBusHandlerResult sbus_message_handler(DBusConnection *conn,
/* Adds a new D-BUS path message handler to the connection
* Note: this must be a unique path.
*/
-int sbus_conn_add_method_ctx(struct sbus_conn_ctx *conn_ctx,
+int sbus_conn_add_method_ctx(struct sbus_connection *conn,
struct sbus_method_ctx *method_ctx)
{
DBusObjectPathVTable *connection_vtable;
@@ -481,11 +481,11 @@ int sbus_conn_add_method_ctx(struct sbus_conn_ctx *conn_ctx,
TALLOC_CTX *tmp_ctx;
dbus_bool_t dbret;
- if (!conn_ctx || !method_ctx) {
+ if (!conn || !method_ctx) {
return EINVAL;
}
- if (_method_list_contains_path(conn_ctx->method_ctx_list, method_ctx)) {
+ if (_method_list_contains_path(conn->method_ctx_list, method_ctx)) {
DEBUG(0, ("Cannot add method context with identical path.\n"));
return EINVAL;
}
@@ -494,29 +494,29 @@ int sbus_conn_add_method_ctx(struct sbus_conn_ctx *conn_ctx,
return EINVAL;
}
- DLIST_ADD(conn_ctx->method_ctx_list, method_ctx);
- tmp_ctx = talloc_reference(conn_ctx, method_ctx);
+ DLIST_ADD(conn->method_ctx_list, method_ctx);
+ tmp_ctx = talloc_reference(conn, method_ctx);
if (tmp_ctx != method_ctx) {
/* talloc_reference only fails on insufficient memory */
return ENOMEM;
}
/* Set up the vtable for the object path */
- connection_vtable = talloc_zero(conn_ctx, DBusObjectPathVTable);
+ connection_vtable = talloc_zero(conn, DBusObjectPathVTable);
if (!connection_vtable) {
return ENOMEM;
}
connection_vtable->message_function = method_ctx->message_handler;
- msg_handler_ctx = talloc_zero(conn_ctx, struct sbus_message_handler_ctx);
+ msg_handler_ctx = talloc_zero(conn, struct sbus_message_handler_ctx);
if (!msg_handler_ctx) {
talloc_free(connection_vtable);
return ENOMEM;
}
- msg_handler_ctx->conn_ctx = conn_ctx;
+ msg_handler_ctx->conn = conn;
msg_handler_ctx->method_ctx = method_ctx;
- dbret = dbus_connection_register_object_path(conn_ctx->dbus_conn,
+ dbret = dbus_connection_register_object_path(conn->dbus_conn,
method_ctx->path,
connection_vtable,
msg_handler_ctx);
@@ -548,36 +548,36 @@ static int _method_list_contains_path(struct sbus_method_ctx *list,
return 0; /* FALSE */
}
-static void sbus_unreg_object_paths(struct sbus_conn_ctx *conn_ctx)
+static void sbus_unreg_object_paths(struct sbus_connection *conn)
{
- struct sbus_method_ctx *iter = conn_ctx->method_ctx_list;
+ struct sbus_method_ctx *iter = conn->method_ctx_list;
struct sbus_method_ctx *purge;
while (iter != NULL) {
- dbus_connection_unregister_object_path(conn_ctx->dbus_conn,
+ dbus_connection_unregister_object_path(conn->dbus_conn,
iter->path);
- DLIST_REMOVE(conn_ctx->method_ctx_list, iter);
+ DLIST_REMOVE(conn->method_ctx_list, iter);
purge = iter;
iter = iter->next;
- talloc_unlink(conn_ctx, purge);
+ talloc_unlink(conn, purge);
}
}
-void sbus_conn_set_private_data(struct sbus_conn_ctx *conn_ctx, void *pvt_data)
+void sbus_conn_set_private_data(struct sbus_connection *conn, void *pvt_data)
{
- conn_ctx->pvt_data = pvt_data;
+ conn->pvt_data = pvt_data;
}
-void *sbus_conn_get_private_data(struct sbus_conn_ctx *conn_ctx)
+void *sbus_conn_get_private_data(struct sbus_connection *conn)
{
- return conn_ctx->pvt_data;
+ return conn->pvt_data;
}
static void sbus_reconnect(struct tevent_context *ev,
struct tevent_timer *te,
struct timeval tv, void *data)
{
- struct sbus_conn_ctx *conn_ctx = talloc_get_type(data, struct sbus_conn_ctx);
+ struct sbus_connection *conn = talloc_get_type(data, struct sbus_connection);
DBusConnection *dbus_conn;
DBusError dbus_error;
struct tevent_timer *event;
@@ -586,40 +586,40 @@ static void sbus_reconnect(struct tevent_context *ev,
int ret;
DEBUG(3, ("Making reconnection attempt %d to [%s]\n",
- conn_ctx->retries, conn_ctx->address));
+ conn->retries, conn->address));
/* Make a new connection to the D-BUS address */
dbus_error_init(&dbus_error);
- dbus_conn = dbus_connection_open(conn_ctx->address, &dbus_error);
+ dbus_conn = dbus_connection_open(conn->address, &dbus_error);
if (dbus_conn) {
/* We successfully reconnected. Set up mainloop
* integration.
*/
- DEBUG(3, ("Reconnected to [%s]\n", conn_ctx->address));
- conn_ctx->dbus_conn = dbus_conn;
- ret = sbus_add_connection_int(&conn_ctx);
+ DEBUG(3, ("Reconnected to [%s]\n", conn->address));
+ conn->dbus_conn = dbus_conn;
+ ret = sbus_add_connection_int(&conn);
if (ret != EOK) {
dbus_connection_unref(dbus_conn);
goto failed;
}
/* Remove object paths (the reconnection callback must re-add these */
- iter = conn_ctx->method_ctx_list;
+ iter = conn->method_ctx_list;
while (iter != NULL) {
- DLIST_REMOVE(conn_ctx->method_ctx_list, iter);
+ DLIST_REMOVE(conn->method_ctx_list, iter);
purge = iter;
iter = iter->next;
- talloc_unlink(conn_ctx, purge);
+ talloc_unlink(conn, purge);
}
/* Reset retries to 0 to resume dispatch processing */
- conn_ctx->retries = 0;
+ conn->retries = 0;
/* Notify the owner of this connection that the
* reconnection was successful
*/
- conn_ctx->reconnect_callback(conn_ctx,
+ conn->reconnect_callback(conn,
SBUS_RECONNECT_SUCCESS,
- conn_ctx->reconnect_pvt);
+ conn->reconnect_pvt);
return;
}
@@ -629,49 +629,49 @@ failed:
dbus_error.name, dbus_error.message));
if (dbus_error_is_set(&dbus_error)) dbus_error_free(&dbus_error);
- conn_ctx->retries++;
+ conn->retries++;
/* Check if we've passed our last chance or if we've lost track of
* our retry count somehow
*/
- if (((conn_ctx->max_retries > 0) &&
- (conn_ctx->retries > conn_ctx->max_retries)) ||
- conn_ctx->retries <= 0) {
- conn_ctx->reconnect_callback(conn_ctx,
+ if (((conn->max_retries > 0) &&
+ (conn->retries > conn->max_retries)) ||
+ conn->retries <= 0) {
+ conn->reconnect_callback(conn,
SBUS_RECONNECT_EXCEEDED_RETRIES,
- conn_ctx->reconnect_pvt);
+ conn->reconnect_pvt);
}
- if (conn_ctx->retries == 2) {
+ if (conn->retries == 2) {
tv.tv_sec += 3; /* Wait 3 seconds before the second reconnect attempt */
}
- else if (conn_ctx->retries == 3) {
+ else if (conn->retries == 3) {
tv.tv_sec += 10; /* Wait 10 seconds before the third reconnect attempt */
}
else {
tv.tv_sec += 30; /* Wait 30 seconds before all subsequent reconnect attempts */
}
- event = tevent_add_timer(conn_ctx->ev, conn_ctx, tv, sbus_reconnect, conn_ctx);
+ event = tevent_add_timer(conn->ev, conn, tv, sbus_reconnect, conn);
if (event == NULL) {
- conn_ctx->reconnect_callback(conn_ctx,
+ conn->reconnect_callback(conn,
SBUS_RECONNECT_ERROR,
- conn_ctx->reconnect_pvt);
+ conn->reconnect_pvt);
}
}
-/* This function will free and recreate the sbus_conn_ctx,
+/* This function will free and recreate the sbus_connection,
* calling functions need to be aware of this (and whether
* they have attached a talloc destructor to the
- * sbus_conn_ctx.
+ * sbus_connection.
*/
-static int sbus_auto_reconnect(struct sbus_conn_ctx *conn_ctx)
+static int sbus_auto_reconnect(struct sbus_connection *conn)
{
struct tevent_timer *te = NULL;
struct timeval tv;
- conn_ctx->retries++;
- if ((conn_ctx->max_retries > 0) &&
- (conn_ctx->retries >= conn_ctx->max_retries)) {
+ conn->retries++;
+ if ((conn->max_retries > 0) &&
+ (conn->retries >= conn->max_retries)) {
/* Return EAGAIN (to tell the calling process it
* needs to create a new connection from scratch
*/
@@ -680,34 +680,34 @@ static int sbus_auto_reconnect(struct sbus_conn_ctx *conn_ctx)
gettimeofday(&tv, NULL);
tv.tv_sec += 1; /* Wait 1 second before the first reconnect attempt */
- te = tevent_add_timer(conn_ctx->ev, conn_ctx, tv, sbus_reconnect, conn_ctx);
+ te = tevent_add_timer(conn->ev, conn, tv, sbus_reconnect, conn);
if (te == NULL) return EAGAIN;
return EOK;
}
/* Max retries */
-void sbus_reconnect_init(struct sbus_conn_ctx *conn_ctx,
+void sbus_reconnect_init(struct sbus_connection *conn,
int max_retries,
sbus_conn_reconn_callback_fn callback,
void *pvt)
{
if(max_retries == 0 || callback == NULL) return;
- conn_ctx->retries = 0;
- conn_ctx->max_retries = max_retries;
- conn_ctx->reconnect_callback = callback;
- conn_ctx->reconnect_pvt = pvt;
+ conn->retries = 0;
+ conn->max_retries = max_retries;
+ conn->reconnect_callback = callback;
+ conn->reconnect_pvt = pvt;
}
-bool sbus_conn_disconnecting(struct sbus_conn_ctx *conn_ctx)
+bool sbus_conn_disconnecting(struct sbus_connection *conn)
{
- if (conn_ctx->disconnect == 1) return true;
+ if (conn->disconnect == 1) return true;
return false;
}
-void sbus_conn_send_reply(struct sbus_conn_ctx *conn_ctx, DBusMessage *reply)
+void sbus_conn_send_reply(struct sbus_connection *conn, DBusMessage *reply)
{
- dbus_connection_send(conn_ctx->dbus_conn, reply, NULL);
+ dbus_connection_send(conn->dbus_conn, reply, NULL);
}