list_for_each(p, &ifs) {
const unsigned char *ipaddr;
+ int n_aliases = 0;
net = list_entry(p, struct uci_network, list);
ipaddr = net->ipaddr;
printf("\n");
}
list_for_each_entry(alias, &net->alias, list) {
+ n_aliases++;
for (i = 0; i < net->aliases->n_items; i++) {
if (alias == net->aliases->item[i].ptr)
goto next_alias;
if (set && !strcmp(net->name, "lan")) {
ucimap_free_item(&net->map, &net->ipaddr);
ucimap_set_changed(&net->map, &net->ipaddr);
+ ucimap_resize_list(&net->map, &net->aliases, n_aliases);
+ net->aliases->n_items = 0;
+ list_for_each_entry(alias, &net->alias, list) {
+ net->aliases->item[net->aliases->n_items++].ptr = alias;
+ }
+ ucimap_set_changed(&net->map, &net->aliases);
ucimap_store_section(&network_map, pkg, &net->map);
uci_save(ctx, pkg);
}
return ((char *) sd - sd->sm->smap_offset);
}
+static inline struct ucimap_section_data *
+ucimap_ptr_section(struct uci_sectionmap *sm, void *ptr) {
+ ptr = (char *) ptr + sm->smap_offset;
+ return ptr;
+}
+
static inline union ucimap_data *
ucimap_get_data(struct ucimap_section_data *sd, struct uci_optmap *om)
{
}
}
+static char *
+ucimap_data_to_string(struct ucimap_section_data *sd, struct uci_optmap *om, union ucimap_data *data)
+{
+ static char buf[32];
+ char *str = NULL;
+
+ switch(om->type & UCIMAP_SUBTYPE) {
+ case UCIMAP_STRING:
+ str = data->s;
+ break;
+ case UCIMAP_INT:
+ sprintf(buf, "%d", data->i);
+ str = buf;
+ break;
+ case UCIMAP_BOOL:
+ sprintf(buf, "%d", !!data->b);
+ str = buf;
+ break;
+ case UCIMAP_SECTION:
+ if (data->ptr)
+ str = (char *) ucimap_ptr_section(om->data.sm, data->ptr)->section_name;
+ else
+ str = "";
+ break;
+ case UCIMAP_CUSTOM:
+ break;
+ default:
+ return NULL;
+ }
+
+ if (om->format) {
+ union ucimap_data tdata;
+
+ if (ucimap_is_custom(om->type)) {
+ tdata.s = (char *)data;
+ data = &tdata;
+ }
+
+ if (om->format(ucimap_section_ptr(sd), om, data, &str) < 0)
+ return NULL;
+
+ if (!str)
+ str = "";
+ }
+ return str;
+}
+
int
ucimap_store_section(struct uci_map *map, struct uci_package *p, struct ucimap_section_data *sd)
{
ucimap_foreach_option(sm, om) {
union ucimap_data *data;
- static char buf[32];
- char *str = NULL;
i++;
- if (ucimap_is_list(om->type))
- continue;
-
data = ucimap_get_data(sd, om);
if (!TEST_BIT(sd->cmap, i - 1))
continue;
ucimap_fill_ptr(&ptr, s, om->name);
- switch(om->type & UCIMAP_SUBTYPE) {
- case UCIMAP_STRING:
- str = data->s;
- break;
- case UCIMAP_INT:
- sprintf(buf, "%d", data->i);
- str = buf;
- break;
- case UCIMAP_BOOL:
- sprintf(buf, "%d", !!data->b);
- str = buf;
- break;
- case UCIMAP_CUSTOM:
- break;
- default:
- continue;
- }
- if (om->format) {
- union ucimap_data tdata, *data;
+ if (ucimap_is_list(om->type)) {
+ struct ucimap_list *list = data->list;
+ bool first = true;
+ int j;
- data = ucimap_get_data(sd, om);
- if (ucimap_is_custom(om->type)) {
- tdata.s = (char *)data;
- data = &tdata;
- }
+ for (j = 0; j < list->n_items; j++) {
+ ptr.value = ucimap_data_to_string(sd, om, &list->item[j]);
+ if (!ptr.value)
+ continue;
- if (om->format(ucimap_section_ptr(sd), om, data, &str) < 0)
+ if (first) {
+ ret = uci_set(s->package->ctx, &ptr);
+ first = false;
+ } else {
+ ret = uci_add_list(s->package->ctx, &ptr);
+ }
+ if (ret)
+ return ret;
+ }
+ } else {
+ ptr.value = ucimap_data_to_string(sd, om, data);
+ if (!ptr.value)
continue;
- if (!str)
- str = "";
+ ret = uci_set(s->package->ctx, &ptr);
+ if (ret)
+ return ret;
}
- if (!str)
- continue;
- ptr.value = str;
-
- ret = uci_set(s->package->ctx, &ptr);
- if (ret)
- return ret;
CLR_BIT(sd->cmap, i - 1);
}