- Return UBUS_STATUS_NOT_FOUND if no section could be resolved for set
- Return UBUS_STATUS_INVALID_ARGUMENT if unserializable values are found
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* 3) in all other cases only emit a set operation if there is no existing
* option of if the existing options value differs from the blob value
*/
* 3) in all other cases only emit a set operation if there is no existing
* option of if the existing options value differs from the blob value
*/
rpc_uci_merge_set(struct blob_attr *opt, struct uci_ptr *ptr)
{
struct blob_attr *cur;
rpc_uci_merge_set(struct blob_attr *opt, struct uci_ptr *ptr)
{
struct blob_attr *cur;
ptr->o = NULL;
ptr->option = blobmsg_name(opt);
ptr->value = NULL;
if (!rpc_uci_verify_name(ptr->option))
ptr->o = NULL;
ptr->option = blobmsg_name(opt);
ptr->value = NULL;
if (!rpc_uci_verify_name(ptr->option))
+ return UBUS_STATUS_INVALID_ARGUMENT;
if (rpc_uci_lookup(ptr) || !ptr->s)
if (rpc_uci_lookup(ptr) || !ptr->s)
+ return UBUS_STATUS_NOT_FOUND;
if (blobmsg_type(opt) == BLOBMSG_TYPE_ARRAY)
{
if (ptr->o)
uci_delete(cursor, ptr);
if (blobmsg_type(opt) == BLOBMSG_TYPE_ARRAY)
{
if (ptr->o)
uci_delete(cursor, ptr);
+ rv = UBUS_STATUS_INVALID_ARGUMENT;
+
blobmsg_for_each_attr(cur, opt, rem)
blobmsg_for_each_attr(cur, opt, rem)
- if (rpc_uci_format_blob(cur, &ptr->value))
- uci_add_list(cursor, ptr);
+ {
+ if (!rpc_uci_format_blob(cur, &ptr->value))
+ continue;
+
+ uci_add_list(cursor, ptr);
+ rv = 0;
+ }
+
+ return rv;
}
else if (ptr->o && ptr->o->type == UCI_TYPE_LIST)
{
uci_delete(cursor, ptr);
}
else if (ptr->o && ptr->o->type == UCI_TYPE_LIST)
{
uci_delete(cursor, ptr);
- if (rpc_uci_format_blob(opt, &ptr->value))
- uci_set(cursor, ptr);
+ if (!rpc_uci_format_blob(opt, &ptr->value))
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ uci_set(cursor, ptr);
- else if (rpc_uci_format_blob(opt, &ptr->value))
+ if (!rpc_uci_format_blob(opt, &ptr->value))
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
if (!ptr->o || !ptr->o->v.string || strcmp(ptr->o->v.string, ptr->value))
uci_set(cursor, ptr);
}
if (!ptr->o || !ptr->o->v.string || strcmp(ptr->o->v.string, ptr->value))
uci_set(cursor, ptr);
}
struct uci_package *p = NULL;
struct uci_element *e;
struct uci_ptr ptr = { 0 };
struct uci_package *p = NULL;
struct uci_element *e;
struct uci_ptr ptr = { 0 };
blobmsg_parse(rpc_uci_set_policy, __RPC_S_MAX, tb,
blob_data(msg), blob_len(msg));
blobmsg_parse(rpc_uci_set_policy, __RPC_S_MAX, tb,
blob_data(msg), blob_len(msg));
{
ptr.section = blobmsg_data(tb[RPC_S_SECTION]);
blobmsg_for_each_attr(cur, tb[RPC_S_VALUES], rem)
{
ptr.section = blobmsg_data(tb[RPC_S_SECTION]);
blobmsg_for_each_attr(cur, tb[RPC_S_VALUES], rem)
- rpc_uci_merge_set(cur, &ptr);
+ {
+ rv = rpc_uci_merge_set(cur, &ptr);
+
+ if (rv)
+ err = rv;
+ }
ptr.section = e->name;
blobmsg_for_each_attr(cur, tb[RPC_S_VALUES], rem)
ptr.section = e->name;
blobmsg_for_each_attr(cur, tb[RPC_S_VALUES], rem)
- rpc_uci_merge_set(cur, &ptr);
+ {
+ rv = rpc_uci_merge_set(cur, &ptr);
+
+ if (rv)
+ err = rv;
+ }
+ if (!err && !ptr.s)
+ err = UBUS_STATUS_NOT_FOUND;
+
+ if (!err)
+ uci_save(cursor, p);
+
- return rpc_uci_status();
+ return err ? err : rpc_uci_status();