UCI_ERR_LAST
};
+struct uci_list;
struct uci_list
{
- void *next;
- void *prev;
+ struct uci_list *next;
+ struct uci_list *prev;
};
+struct uci_element;
struct uci_package;
struct uci_section;
struct uci_option;
/**
- * uci_alloc: Allocate a new uci context
+ * uci_alloc_context: Allocate a new uci context
*/
-extern struct uci_context *uci_alloc(void);
+extern struct uci_context *uci_alloc_context(void);
/**
- * uci_free: Free the uci context including all of its data
+ * uci_free_context: Free the uci context including all of its data
*/
-extern void uci_free(struct uci_context *ctx);
+extern void uci_free_context(struct uci_context *ctx);
/**
* uci_perror: Print the last uci error that occured
extern int uci_cleanup(struct uci_context *ctx);
/**
+ * uci_lookup: Look up an uci element
+ *
+ * @ctx: uci context
+ * @res: where to store the result
+ * @package: config package
+ * @section: config section (optional)
+ * @option: option to search for (optional)
+ *
+ * If section is omitted, then a pointer to the config package is returned
+ * If option is omitted, then a pointer to the config section is returned
+ */
+extern int uci_lookup(struct uci_context *ctx, struct uci_element **res, char *package, char *section, char *option);
+
+/**
+ * uci_set_element_value: Replace an element's value with a new one
+ * @ctx: uci context
+ * @element: pointer to an uci_element struct pointer
+ * @value: new value
+ *
+ * Only valid for uci_option and uci_section. Will replace the type string
+ * when used with an uci_section
+ */
+extern int uci_set_element_value(struct uci_context *ctx, struct uci_element **element, char *value);
+
+/**
+ * uci_set: Set an element's value; create the element if necessary
+ * @ctx: uci context
+ * @package: package name
+ * @section: section name
+ * @option: option name
+ * @value: value (option) or type (section)
+ */
+extern int uci_set(struct uci_context *ctx, char *package, char *section, char *option, char *value);
+
+/**
* uci_list_configs: List available uci config files
*
* @ctx: uci context
/* UCI data structures */
enum uci_type {
- uci_type_package = 0,
- uci_type_section = 1,
- uci_type_option = 2
+ UCI_TYPE_PACKAGE = 0,
+ UCI_TYPE_SECTION = 1,
+ UCI_TYPE_OPTION = 2
};
struct uci_element
/* private: */
int errno;
+ const char *func;
jmp_buf trap;
char *buf;
int bufsz;
struct uci_context *ctx;
/* private: */
int n_section;
+ struct uci_list history;
};
struct uci_section
{
struct uci_list list;
enum uci_command cmd;
- union {
- struct uci_element element;
- struct uci_package package;
- struct uci_section section;
- struct uci_option option;
- } data;
+ char *section;
+ char *option;
+ char *value;
};
/* linked list handling */
&_ptr->list != (_list); \
_ptr = _tmp, _tmp = list_to_element(_ptr->list.next))
-/* returns true if a list is empty */
+/**
+ * uci_list_empty: returns true if a list is empty
+ * @list: list head
+ */
#define uci_list_empty(list) ((list)->next == (list))
+/* wrappers for dynamic type handling */
+#define uci_type_package UCI_TYPE_PACKAGE
+#define uci_type_section UCI_TYPE_SECTION
+#define uci_type_option UCI_TYPE_OPTION
+
/* element typecasting */
#ifdef UCI_DEBUG_TYPECAST
static const char *uci_typestr[] = {