CMakeLists.txt: bump minimum cmake version
[project/ubus.git] / libubus.c
index b405891416c22856729ae2193cde60231bd52ad3..c9c3c6e5c2484b23b06ffc2407f2cbc476b6eb62 100644 (file)
--- a/libubus.c
+++ b/libubus.c
@@ -34,6 +34,9 @@ const char *__ubus_strerror[__UBUS_STATUS_LAST] = {
        [UBUS_STATUS_NOT_SUPPORTED] = "Operation not supported",
        [UBUS_STATUS_UNKNOWN_ERROR] = "Unknown error",
        [UBUS_STATUS_CONNECTION_FAILED] = "Connection failed",
+       [UBUS_STATUS_NO_MEMORY] = "Out of memory",
+       [UBUS_STATUS_PARSE_ERROR] = "Parsing message data failed",
+       [UBUS_STATUS_SYSTEM_ERROR] = "System error",
 };
 
 struct blob_buf b __hidden = {};
@@ -103,7 +106,9 @@ ubus_process_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf, int fd)
                        break;
                }
 
+               ctx->stack_depth++;
                ubus_process_obj_msg(ctx, buf, fd);
+               ctx->stack_depth--;
                break;
        case UBUS_MSG_MONITOR:
                if (ctx->monitor_cb)
@@ -115,12 +120,13 @@ ubus_process_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf, int fd)
 static void ubus_process_pending_msg(struct uloop_timeout *timeout)
 {
        struct ubus_context *ctx = container_of(timeout, struct ubus_context, pending_timer);
-       struct ubus_pending_msg *pending, *tmp;
+       struct ubus_pending_msg *pending;
 
-       list_for_each_entry_safe(pending, tmp, &ctx->pending, list) {
+       while (!list_empty(&ctx->pending)) {
                if (ctx->stack_depth)
                        break;
 
+               pending = list_first_entry(&ctx->pending, struct ubus_pending_msg, list);
                list_del(&pending->list);
                ubus_process_msg(ctx, &pending->hdr, -1);
                free(pending);
@@ -139,7 +145,7 @@ static void ubus_lookup_cb(struct ubus_request *ureq, int type, struct blob_attr
        struct blob_attr **attr;
 
        req = container_of(ureq, struct ubus_lookup_request, req);
-       attr = ubus_parse_msg(msg);
+       attr = ubus_parse_msg(msg, blob_raw_len(msg));
 
        if (!attr[UBUS_ATTR_OBJID] || !attr[UBUS_ATTR_OBJPATH] ||
            !attr[UBUS_ATTR_OBJTYPE])
@@ -175,7 +181,7 @@ static void ubus_lookup_id_cb(struct ubus_request *req, int type, struct blob_at
        struct blob_attr **attr;
        uint32_t *id = req->priv;
 
-       attr = ubus_parse_msg(msg);
+       attr = ubus_parse_msg(msg, blob_raw_len(msg));
 
        if (!attr[UBUS_ATTR_OBJID])
                return;
@@ -292,6 +298,7 @@ int ubus_connect_ctx(struct ubus_context *ctx, const char *path)
 
        INIT_LIST_HEAD(&ctx->requests);
        INIT_LIST_HEAD(&ctx->pending);
+       INIT_LIST_HEAD(&ctx->auto_subscribers);
        avl_init(&ctx->objects, ubus_cmp_id, false, NULL);
        if (ubus_reconnect(ctx, path)) {
                free(ctx->msgbuf.data);
@@ -362,6 +369,7 @@ void ubus_shutdown(struct ubus_context *ctx)
        blob_buf_free(&b);
        if (!ctx)
                return;
+       uloop_fd_delete(&ctx->sock);
        close(ctx->sock.fd);
        uloop_timeout_cancel(&ctx->pending_timer);
        free(ctx->msgbuf.data);