X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fubus.git;a=blobdiff_plain;f=libubus.c;h=64190f78df2e294b7ec8389628520bc0b26d3e6e;hp=93f9bac3483b441576eaeb9f68d6319f364c279c;hb=7b262aec3843912d68e020f0750b6f96e2f7c8e3;hpb=1a871e1e89055f8683793f1ca0d629ca2fa4d3be diff --git a/libubus.c b/libubus.c index 93f9bac..64190f7 100644 --- a/libubus.c +++ b/libubus.c @@ -35,6 +35,7 @@ static const struct blob_attr_info ubus_policy[UBUS_ATTR_MAX] = { [UBUS_ATTR_STATUS] = { .type = BLOB_ATTR_INT32 }, [UBUS_ATTR_OBJID] = { .type = BLOB_ATTR_INT32 }, [UBUS_ATTR_OBJPATH] = { .type = BLOB_ATTR_STRING }, + [UBUS_ATTR_METHOD] = { .type = BLOB_ATTR_STRING }, }; static struct blob_attr *attrbuf[UBUS_ATTR_MAX]; @@ -274,12 +275,16 @@ static void ubus_process_invoke(struct ubus_context *ctx, struct ubus_msghdr *hd ubus_parse_msg(hdr->data); - if (!attrbuf[UBUS_ATTR_METHOD] || !attrbuf[UBUS_ATTR_OBJID]) { + if (!attrbuf[UBUS_ATTR_OBJID]) + return; + + objid = blob_get_int32(attrbuf[UBUS_ATTR_OBJID]); + + if (!attrbuf[UBUS_ATTR_METHOD]) { ret = UBUS_STATUS_INVALID_ARGUMENT; goto send; } - objid = blob_get_int32(attrbuf[UBUS_ATTR_OBJID]); obj = avl_find_element(&ctx->objects, &objid, obj, avl); if (!obj) { ret = UBUS_STATUS_NOT_FOUND; @@ -362,6 +367,9 @@ static void ubus_handle_data(struct uloop_fd *u, unsigned int events) while (get_next_msg(ctx, false)) ubus_process_msg(ctx, hdr); + + if (u->eof) + ctx->connection_lost(ctx); } int ubus_complete_request(struct ubus_context *ctx, struct ubus_request *req) @@ -527,6 +535,12 @@ int ubus_publish(struct ubus_context *ctx, struct ubus_object *obj) return 0; } +void ubus_default_connection_lost(struct ubus_context *ctx) +{ + if (ctx->sock.registered) + uloop_end(); +} + struct ubus_context *ubus_connect(const char *path) { struct ubus_context *ctx; @@ -578,6 +592,8 @@ struct ubus_context *ubus_connect(const char *path) ctx->local_id = hdr.hdr.peer; free(buf); + ctx->connection_lost = ubus_default_connection_lost; + INIT_LIST_HEAD(&ctx->requests); avl_init(&ctx->objects, ubus_cmp_id, false, NULL);