/*
+ * Copyright (C) 2023 Tobias Brunner
* Copyright (C) 2014 Martin Willi
*
* Copyright (C) secunet Security Networks AG
int error;
/** wait state */
wait_state_t wait;
+ /** callback if connection closed */
+ vici_close_cb_t on_close;
+ /** user data for above callback */
+ void *on_close_user;
};
/**
static bool read_error(vici_conn_t *conn, int err)
{
conn->error = err;
+ if (err == ECONNRESET && conn->on_close)
+ {
+ conn->on_close(conn->on_close_user);
+ }
return wait_result(conn, WAIT_READ_ERROR);
}
{
return TRUE;
}
+ if (!hlen)
+ {
+ errno = ECONNRESET;
+ }
return read_error(conn, errno);
}
if (hlen < sizeof(len))
return ret;
}
+void vici_on_close(vici_conn_t *conn, vici_close_cb_t cb, void *user)
+{
+ conn->on_close = cb;
+ conn->on_close_user = user;
+}
+
void vici_init()
{
library_init(NULL, "vici");
/*
+ * Copyright (C) 2023 Tobias Brunner
* Copyright (C) 2014 Martin Willi
*
* libvici.h is MIT-licensed to simplify reuse, but please note that libvici.c
* To register or unregister for asynchronous event messages vici_register() is
* used. The registered callback gets invoked by an asynchronous thread. To
* parse the event message, the vici_parse*() functions can be used.
+ * To get notified if the connection is closed by the vici service while waiting
+ * for event messages, vici_on_close() may be used.
*/
#ifndef LIBVICI_H_
*/
typedef int (*vici_parse_section_cb_t)(void *user, vici_res_t *res, char *name);
+/**
+ * Callback function invoked if the connection is closed by the vici service.
+ *
+ * @param user user data, as passed to vici_on_close()
+ */
+typedef void (*vici_close_cb_t)(void *user);
+
/**
* Open a new vici connection.
*
*/
int vici_register(vici_conn_t *conn, char *name, vici_event_cb_t cb, void *user);
+/**
+ * (Un-)Register a callback that's invoked if the connection is closed by the
+ * vici service.
+ *
+ * Primarily useful when listening for events via vici_register(). The callback
+ * gets invoked by a different thread from the libstrongswan thread pool.
+ *
+ * @param cb callback function to register, NULL to unregister
+ * @param user user data passed to callback invocation
+ */
+void vici_on_close(vici_conn_t *conn, vici_close_cb_t cb, void *user);
+
/**
* Initialize libvici before first time use.
*/