ubus: use BLOBMSG_TYPE_UNSPEC for "params" JSON attribute
[project/uhttpd.git] / ubus.c
diff --git a/ubus.c b/ubus.c
index 97cc1e289c1f93c6fe4d216310bedee1e67f7728..ddc2f05d7d244eae01ccc56ca22bffc8eae623a5 100644 (file)
--- a/ubus.c
+++ b/ubus.c
@@ -48,7 +48,7 @@ enum {
 static const struct blobmsg_policy rpc_policy[__RPC_MAX] = {
        [RPC_JSONRPC] = { .name = "jsonrpc", .type = BLOBMSG_TYPE_STRING },
        [RPC_METHOD] = { .name = "method", .type = BLOBMSG_TYPE_STRING },
-       [RPC_PARAMS] = { .name = "params", .type = BLOBMSG_TYPE_ARRAY },
+       [RPC_PARAMS] = { .name = "params", .type = BLOBMSG_TYPE_UNSPEC },
        [RPC_ID] = { .name = "id", .type = BLOBMSG_TYPE_UNSPEC },
 };
 
@@ -288,7 +288,7 @@ static void uh_ubus_single_error(struct client *cl, enum rpc_error type)
        ops->request_done(cl);
 }
 
-static void uh_ubus_send_request(struct client *cl, json_object *obj, const char *sid, struct blob_attr *args)
+static void uh_ubus_send_request(struct client *cl, const char *sid, struct blob_attr *args)
 {
        struct dispatch *d = &cl->dispatch;
        struct dispatch_ubus *du = &d->ubus;
@@ -370,7 +370,7 @@ static void uh_ubus_list_cb(struct ubus_context *ctx, struct ubus_object_data *o
        blobmsg_close_table(data->buf, o);
 }
 
-static void uh_ubus_send_list(struct client *cl, json_object *obj, struct blob_attr *params)
+static void uh_ubus_send_list(struct client *cl, struct blob_attr *params)
 {
        struct blob_attr *cur, *dup;
        struct list_data data = { .buf = &cl->dispatch.ubus.buf, .verbose = false };
@@ -446,6 +446,9 @@ static void parse_call_params(struct rpc_data *d)
        };
        struct blob_attr *tb[4];
 
+       if (!d->params || blobmsg_type(d->params) != BLOBMSG_TYPE_ARRAY)
+               return;
+
        blobmsg_parse_array(data_policy, ARRAY_SIZE(data_policy), tb,
                            blobmsg_data(d->params), blobmsg_data_len(d->params));
 
@@ -548,11 +551,11 @@ static void uh_ubus_handle_request_object(struct client *cl, struct json_object
                        goto error;
                }
 
-               uh_ubus_send_request(cl, obj, data.sid, data.data);
+               uh_ubus_send_request(cl, data.sid, data.data);
                goto out;
        }
        else if (!strcmp(data.method, "list")) {
-               uh_ubus_send_list(cl, obj, data.params);
+               uh_ubus_send_list(cl, data.params);
                goto out;
        }
        else {