X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuci.git;a=blobdiff_plain;f=list.c;h=b4f4da8faf0b6194e490be9f8bb4b2e74171dcd7;hp=0cb6daded734eb2a85c04ebc535308616c02ec99;hb=93de031b1b9bb5d2a55a692fbd1a07cd15ebc9b2;hpb=4fb6a564b8eebe01f46766b8238a64d6414ed3ba diff --git a/list.c b/list.c index 0cb6dad..b4f4da8 100644 --- a/list.c +++ b/list.c @@ -322,7 +322,7 @@ uci_lookup_ext_section(struct uci_context *ctx, struct uci_ptr *ptr) if (!*name) name = NULL; - else if (!uci_validate_str(name, false)) + else if (!uci_validate_type(name)) goto error; /* if the given index is negative, it specifies the section number from @@ -358,7 +358,8 @@ error: UCI_THROW(ctx, UCI_ERR_INVAL); done: free(section); - ptr->section = e->name; + if (e) + ptr->section = e->name; return e; } @@ -466,7 +467,7 @@ expand_ptr(struct uci_context *ctx, struct uci_ptr *ptr, bool complete) UCI_ASSERT(ctx, ptr != NULL); if (!(ptr->flags & UCI_LOOKUP_DONE)) - uci_lookup_ptr(ctx, ptr, NULL, 1); + UCI_INTERNAL(uci_lookup_ptr, ctx, ptr, NULL, 1); if (complete && !(ptr->flags & UCI_LOOKUP_COMPLETE)) UCI_THROW(ctx, UCI_ERR_NOTFOUND); UCI_ASSERT(ctx, ptr->p != NULL); @@ -617,9 +618,15 @@ int uci_set(struct uci_context *ctx, struct uci_ptr *ptr) UCI_ASSERT(ctx, ptr->value); UCI_ASSERT(ctx, ptr->s || (!ptr->option && ptr->section)); if (!ptr->option) { - UCI_ASSERT(ctx, uci_validate_str(ptr->value, false)); + UCI_ASSERT(ctx, uci_validate_type(ptr->value)); } + if (!ptr->o && ptr->s && ptr->option) { + struct uci_element *e; + e = uci_lookup_list(&ptr->s->options, ptr->option); + if (e) + ptr->o = uci_to_option(e); + } if (!ptr->o && ptr->option) { /* new option */ ptr->o = uci_alloc_option(ptr->s, ptr->option, ptr->value); ptr->last = &ptr->o->e; @@ -627,6 +634,9 @@ int uci_set(struct uci_context *ctx, struct uci_ptr *ptr) ptr->s = uci_alloc_section(ptr->p, ptr->value, ptr->section); ptr->last = &ptr->s->e; } else if (ptr->o && ptr->option) { /* update option */ + if ((ptr->o->type == UCI_TYPE_STRING) && + !strcmp(ptr->o->v.string, ptr->value)) + return 0; uci_free_option(ptr->o); ptr->o = uci_alloc_option(ptr->s, ptr->option, ptr->value); ptr->last = &ptr->o->e;