summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafał Miłecki <rafal@milecki.pl>2020-07-23 07:38:07 +0200
committerRafał Miłecki <rafal@milecki.pl>2020-07-25 10:24:39 +0200
commit8d9e1fce9f89d07c41e8c4984c6583babfc9709f (patch)
tree94ae80be631beedcc28ea8a4fe7d4eb2a01109c4
parent939c281c70ef82929ffcb3cb383fd6fdc40f341b (diff)
ubus: parse "call" method params only for relevant call
There is no point in parsing "call" specific params for other ("list") method calls. This is a minor cleanup that doesn't change uhttpd ubus behaviour. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--ubus.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/ubus.c b/ubus.c
index 8578631..97cc1e2 100644
--- a/ubus.c
+++ b/ubus.c
@@ -409,14 +409,7 @@ static void uh_ubus_send_list(struct client *cl, json_object *obj, struct blob_a
static bool parse_json_rpc(struct rpc_data *d, struct blob_attr *data)
{
- const struct blobmsg_policy data_policy[] = {
- { .type = BLOBMSG_TYPE_STRING },
- { .type = BLOBMSG_TYPE_STRING },
- { .type = BLOBMSG_TYPE_STRING },
- { .type = BLOBMSG_TYPE_TABLE },
- };
struct blob_attr *tb[__RPC_MAX];
- struct blob_attr *tb2[4];
struct blob_attr *cur;
blobmsg_parse(rpc_policy, __RPC_MAX, tb, blob_data(data), blob_len(data));
@@ -440,24 +433,35 @@ static bool parse_json_rpc(struct rpc_data *d, struct blob_attr *data)
if (!d->params)
return false;
- blobmsg_parse_array(data_policy, ARRAY_SIZE(data_policy), tb2,
+ return true;
+}
+
+static void parse_call_params(struct rpc_data *d)
+{
+ const struct blobmsg_policy data_policy[] = {
+ { .type = BLOBMSG_TYPE_STRING },
+ { .type = BLOBMSG_TYPE_STRING },
+ { .type = BLOBMSG_TYPE_STRING },
+ { .type = BLOBMSG_TYPE_TABLE },
+ };
+ struct blob_attr *tb[4];
+
+ blobmsg_parse_array(data_policy, ARRAY_SIZE(data_policy), tb,
blobmsg_data(d->params), blobmsg_data_len(d->params));
- if (tb2[0])
- d->sid = blobmsg_data(tb2[0]);
+ if (tb[0])
+ d->sid = blobmsg_data(tb[0]);
if (conf.ubus_noauth && (!d->sid || !*d->sid))
d->sid = UH_UBUS_DEFAULT_SID;
- if (tb2[1])
- d->object = blobmsg_data(tb2[1]);
-
- if (tb2[2])
- d->function = blobmsg_data(tb2[2]);
+ if (tb[1])
+ d->object = blobmsg_data(tb[1]);
- d->data = tb2[3];
+ if (tb[2])
+ d->function = blobmsg_data(tb[2]);
- return true;
+ d->data = tb[3];
}
static void uh_ubus_init_batch(struct client *cl)
@@ -528,6 +532,8 @@ static void uh_ubus_handle_request_object(struct client *cl, struct json_object
goto error;
if (!strcmp(data.method, "call")) {
+ parse_call_params(&data);
+
if (!data.sid || !data.object || !data.function || !data.data)
goto error;