return ((type & UCIMAP_TYPE) == UCIMAP_LIST);
}
+static inline bool
+ucimap_is_custom(enum ucimap_type type)
+{
+ return ((type & UCIMAP_SUBTYPE) == UCIMAP_CUSTOM);
+}
+
+static inline void *
+ucimap_section_ptr(struct uci_sectmap_data *sd)
+{
+ void *data = sd + 1;
+ return data;
+}
+
static inline union ucimap_data *
ucimap_get_data(struct uci_sectmap_data *sd, struct uci_optmap *om)
{
void *data;
- data = (char *) sd + sizeof(struct uci_sectmap_data) + om->offset;
+ data = (char *) ucimap_section_ptr(sd) + om->offset;
return data;
}
static void
ucimap_free_section(struct uci_map *map, struct uci_sectmap_data *sd)
{
- void *section = sd;
+ void *section;
int i;
- section = (char *) section + sizeof(struct uci_sectmap_data);
+ section = ucimap_section_ptr(sd);
if (!list_empty(&sd->list))
list_del(&sd->list);
- if (sd->sm->free_section)
- sd->sm->free_section(map, section);
+ if (sd->sm->free)
+ sd->sm->free(map, section);
for (i = 0; i < sd->allocmap_len; i++) {
ucimap_free_item(&sd->allocmap[i]);
static void
ucimap_add_value(union ucimap_data *data, struct uci_optmap *om, struct uci_sectmap_data *sd, const char *str)
{
- union ucimap_data *tdata = data;
+ union ucimap_data tdata = *data;
char *eptr = NULL;
char *s;
int val;
if (ucimap_is_list(om->type) && !ucimap_is_fixup(om->type))
- tdata = &data->list->item[data->list->n_items++];
+ data = &data->list->item[data->list->n_items++];
switch(om->type & UCIMAP_SUBTYPE) {
case UCIMAP_STRING:
return;
s = strdup(str);
- tdata->s = s;
+ tdata.s = s;
ucimap_add_alloc(sd, s);
break;
case UCIMAP_BOOL:
if (val == -1)
return;
- tdata->b = val;
+ tdata.b = val;
break;
case UCIMAP_INT:
val = strtol(str, &eptr, om->data.i.base);
if (!eptr || *eptr == '\0')
- tdata->i = val;
+ tdata.i = val;
else
return;
break;
case UCIMAP_SECTION:
ucimap_add_fixup(sd->map, data, om, str);
+ return;
+ case UCIMAP_CUSTOM:
+ tdata.s = (char *) data;
break;
}
+ if (om->parse) {
+ if (om->parse(ucimap_section_ptr(sd), om, &tdata, str) < 0)
+ return;
+ }
+ if (ucimap_is_custom(om->type))
+ return;
+ memcpy(data, &tdata, sizeof(union ucimap_data));
}
ucimap_add_alloc(sd, ucimap_get_data(sd, om)->list);
}
- section = (char *)sd + sizeof(struct uci_sectmap_data);
+ section = ucimap_section_ptr(sd);
- err = sm->init_section(map, section, s);
+ err = sm->init(map, section, s);
if (err)
goto error;
struct uci_sectmap *sm = sd->sm;
struct uci_optmap *om;
int ofs = (char *)field - (char *)section;
- int i;
+ int i = 0;
ucimap_foreach_option(sm, om) {
if (om->offset == ofs) {
SET_BIT(sd->cmap, i);
break;
}
+ i++;
}
}
static char buf[32];
const char *str = NULL;
+ if (ucimap_is_list(om->type))
+ continue;
+
data = ucimap_get_data(sd, om);
if (!TEST_BIT(sd->cmap, i))
continue;
sprintf(buf, "%d", !!data->b);
str = buf;
break;
+ default:
+ continue;
}
ptr.value = str;
list->item[list->n_items++].section = ptr;
break;
}
+ free(f);
}
list_for_each_safe(p, tmp, &map->sdata) {
struct uci_sectmap_data *sd = list_entry(p, struct uci_sectmap_data, list);
continue;
section = (char *) sd + sizeof(struct uci_sectmap_data);
- if (sd->sm->add_section(map, section) != 0)
+ if (sd->sm->add(map, section) != 0)
ucimap_free_section(map, sd);
}
}