/*
- * ucimap - library for mapping uci sections into data structures
- * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
+ * ucimap.h - Library for the Unified Configuration Interface
+ * Copyright (C) 2008-2009 Felix Fietkau <nbd@openwrt.org>
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2
+ * it under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation
*
* This program is distributed in the hope that it will be useful,
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
+
+/*
+ * This file contains ucimap, an API for mapping UCI to C data structures
+ */
+
#ifndef __UCIMAP_H
#define __UCIMAP_H
#include <stdbool.h>
-#include "uci_list.h"
#include "uci.h"
#ifndef ARRAY_SIZE
(_name[(_bit) / 8] & (1 << ((_bit) % 8)))
#ifndef __GNUC__
+
#define __optmap_gen_type(_type, _field) -1
-#else
+
+#ifndef likely
+#define likely(_expr) !!(_expr)
+#endif
+
+#ifndef unlikely
+#define unlikely(_expr) !!(_expr)
+#endif
+
+#else /* __GNUC__ */
#define __compatible(_type, _field, _newtype) \
__builtin_types_compatible_p(typeof(&(((_type *)0)->_field)), _newtype *)
__bool_compatible(_type, _field, UCIMAP_BOOL, \
-1))))
+#ifndef likely
+#define likely(x) __builtin_expect(!!(x), 1)
#endif
+#ifndef unlikely
+#define unlikely(x) __builtin_expect(!!(x), 0)
+#endif
+
+#endif /* __GNUC__ */
+
#define UCIMAP_OPTION(_type, _field) \
.type = UCIMAP_CUSTOM, \
.name = #_field, \
.offset = offsetof(_type, _field), \
- .detected_type = __optmap_gen_type(_type, _field)
+ .detected_type = __optmap_gen_type(_type, _field), \
+ .type_name = #_type
#define UCIMAP_SECTION(_name, _field) \
.alloc_len = sizeof(_name), \
- .smap_offset = offsetof(_name, _field)
+ .smap_offset = offsetof(_name, _field), \
+ .type_name = #_name
struct uci_sectionmap;
struct uci_optmap;
+
struct ucimap_list;
-struct uci_alloc;
-struct uci_alloc_custom;
+struct ucimap_fixup;
+struct ucimap_alloc;
+struct ucimap_alloc_custom;
+struct ucimap_section_data;
struct uci_map {
struct uci_sectionmap **sections;
unsigned int n_sections;
- struct list_head sdata;
- struct list_head fixup;
- struct list_head pending;
bool parsed;
-
- void *priv; /* user data */
+ void *priv;
+
+ /* private */
+ struct ucimap_fixup *fixup;
+ struct ucimap_fixup **fixup_tail;
+ struct ucimap_section_data *sdata;
+ struct ucimap_section_data *pending;
+ struct ucimap_section_data **sdata_tail;
};
enum ucimap_type {
};
struct ucimap_section_data {
- struct list_head list;
struct uci_map *map;
struct uci_sectionmap *sm;
const char *section_name;
- /* list of allocations done by ucimap */
- struct uci_alloc *allocmap;
- struct uci_alloc_custom *alloc_custom;
- unsigned int allocmap_len;
- unsigned int alloc_custom_len;
-
/* map for changed fields */
unsigned char *cmap;
bool done;
-};
-
-struct uci_listmap {
- struct list_head list;
- union ucimap_data data;
+ /* internal */
+ struct ucimap_section_data *next, **ref;
+ struct ucimap_alloc *allocmap;
+ struct ucimap_alloc_custom *alloc_custom;
+ unsigned int allocmap_len;
+ unsigned int alloc_custom_len;
};
struct uci_sectionmap {
struct uci_optmap *options;
unsigned int n_options;
unsigned int options_size;
+
+ /* internal */
+ const char *type_name;
};
struct uci_optmap {
unsigned int offset;
const char *name;
enum ucimap_type type;
- int detected_type;
int (*parse)(void *section, struct uci_optmap *om, union ucimap_data *data, const char *string);
int (*format)(void *section, struct uci_optmap *om, union ucimap_data *data, char **string);
void (*free)(void *section, struct uci_optmap *om, void *ptr);
} s;
struct uci_sectionmap *sm;
} data;
+
+ /* internal */
+ int detected_type;
+ const char *type_name;
};
struct ucimap_list {
int n_items;
+ int size;
union ucimap_data item[];
};
extern void ucimap_parse(struct uci_map *map, struct uci_package *pkg);
extern int ucimap_parse_section(struct uci_map *map, struct uci_sectionmap *sm, struct ucimap_section_data *sd, struct uci_section *s);
extern void ucimap_free_section(struct uci_map *map, struct ucimap_section_data *sd);
+extern int ucimap_resize_list(struct ucimap_section_data *sd, struct ucimap_list **list, int items);
+extern void ucimap_free_item(struct ucimap_section_data *sd, void *item);
#endif