summaryrefslogtreecommitdiff
path: root/libubus.c
diff options
context:
space:
mode:
authorDelio Brignoli <dbrignoli@audioscience.com>2014-10-01 19:57:56 +0200
committerFelix Fietkau <nbd@openwrt.org>2014-10-14 09:57:11 +0200
commit7b79b6226e737e28aafb4e9b668b86b5f180314b (patch)
tree319c5f2fcc73de64431d17141525bd06f791b733 /libubus.c
parent4c4f35cf2230d70b9ddd87638ca911e8a563f2f3 (diff)
downloadubus-7b79b6226e737e28aafb4e9b668b86b5f180314b.tar.gz
libubus: expose ubus_connect_ctx() in public API
ubus_connect_ctx() is equivalent to ubus_connect() but accepts a pointer to a previously allocated ubus_context struct. ubus_shutdown() is made available as an alternative to ubus_free() to clean up contexts initialised by ubus_connect_ctx(). Signed-off-by: Delio Brignoli <dbrignoli@audioscience.com>
Diffstat (limited to 'libubus.c')
-rw-r--r--libubus.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/libubus.c b/libubus.c
index 18267bb..ccaa069 100644
--- a/libubus.c
+++ b/libubus.c
@@ -271,8 +271,10 @@ static void ubus_default_connection_lost(struct ubus_context *ctx)
uloop_end();
}
-static int _ubus_connect(struct ubus_context *ctx, const char *path)
+int ubus_connect_ctx(struct ubus_context *ctx, const char *path)
{
+ memset(ctx, 0, sizeof(*ctx));
+
ctx->sock.fd = -1;
ctx->sock.cb = ubus_handle_data;
ctx->connection_lost = ubus_default_connection_lost;
@@ -316,7 +318,7 @@ static void ubus_auto_connect_cb(struct uloop_timeout *timeout)
{
struct ubus_auto_conn *conn = container_of(timeout, struct ubus_auto_conn, timer);
- if (_ubus_connect(&conn->ctx, conn->path)) {
+ if (ubus_connect_ctx(&conn->ctx, conn->path)) {
uloop_timeout_set(timeout, 1000);
fprintf(stderr, "failed to connect to ubus\n");
return;
@@ -341,7 +343,7 @@ struct ubus_context *ubus_connect(const char *path)
if (!ctx)
return NULL;
- if (_ubus_connect(ctx, path)) {
+ if (ubus_connect_ctx(ctx, path)) {
free(ctx);
ctx = NULL;
}
@@ -349,10 +351,15 @@ struct ubus_context *ubus_connect(const char *path)
return ctx;
}
-void ubus_free(struct ubus_context *ctx)
+void ubus_shutdown(struct ubus_context *ctx)
{
blob_buf_free(&b);
close(ctx->sock.fd);
free(ctx->msgbuf.data);
+}
+
+void ubus_free(struct ubus_context *ctx)
+{
+ ubus_shutdown(ctx);
free(ctx);
}