X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuci.git;a=blobdiff_plain;f=blob.c;h=c8e5dc90c80a342a4bf5bdce0a11d23f0a25a71f;hp=6fdaa477346eeb092664b5ab82f5c359fcce29db;hb=471dcf63d6ed4689cfd56f2648e6d1b48f46f14c;hpb=9d8e1fe4857c1c3e8f1a2e2ae59ef9c4790adb39 diff --git a/blob.c b/blob.c index 6fdaa47..c8e5dc9 100644 --- a/blob.c +++ b/blob.c @@ -25,6 +25,7 @@ uci_attr_to_blob(struct blob_buf *b, const char *str, { char *err; int intval; + long long llval; switch (type) { case BLOBMSG_TYPE_STRING: @@ -47,6 +48,13 @@ uci_attr_to_blob(struct blob_buf *b, const char *str, blobmsg_add_u32(b, name, intval); break; + case BLOBMSG_TYPE_INT64: + llval = strtoll(str, &err, 0); + if (*err) + return false; + + blobmsg_add_u64(b, name, llval); + break; default: return false; } @@ -81,33 +89,40 @@ uci_array_to_blob(struct blob_buf *b, struct uci_option *o, } static int -__uci_to_blob(struct blob_buf *b, struct uci_section *s, - const struct uci_blob_param_list *p) +__uci_element_to_blob(struct blob_buf *b, struct uci_element *e, + const struct uci_blob_param_list *p) { const struct blobmsg_policy *attr = NULL; - struct uci_element *e; - struct uci_option *o; + struct uci_option *o = uci_to_option(e); + unsigned int types = 0; void *array; int i, ret = 0; - uci_foreach_element(&s->options, e) { - for (i = 0; i < p->n_params; i++) { - attr = &p->params[i]; - if (!strcmp(attr->name, e->name)) - break; - } + for (i = 0; i < p->n_params; i++) { + attr = &p->params[i]; + + if (strcmp(attr->name, e->name) != 0) + continue; + + if (attr->type > BLOBMSG_TYPE_LAST) + continue; - if (i == p->n_params) + if (types & (1 << attr->type)) continue; - o = uci_to_option(e); + types |= 1 << attr->type; if (attr->type == BLOBMSG_TYPE_ARRAY) { - if (!p->info) - continue; + int element_type = 0; + + if (p->info) + element_type = p->info[i].type; + + if (!element_type) + element_type = BLOBMSG_TYPE_STRING; array = blobmsg_open_array(b, attr->name); - uci_array_to_blob(b, o, p->info[i].type); + uci_array_to_blob(b, o, element_type); blobmsg_close_array(b, array); ret++; continue; @@ -118,6 +133,18 @@ __uci_to_blob(struct blob_buf *b, struct uci_section *s, ret += uci_attr_to_blob(b, o->v.string, attr->name, attr->type); } + return ret; +} + +static int +__uci_to_blob(struct blob_buf *b, struct uci_section *s, + const struct uci_blob_param_list *p) +{ + struct uci_element *e; + int ret = 0; + + uci_foreach_element(&s->options, e) + ret += __uci_element_to_blob(b, e, p); return ret; }