add a stub for testing uci_set()
[project/uci.git] / uci.h
diff --git a/uci.h b/uci.h
index a4e3f96..6a6db67 100644 (file)
--- a/uci.h
+++ b/uci.h
@@ -46,12 +46,14 @@ enum
        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;
@@ -60,14 +62,14 @@ struct uci_parse_context;
 
 
 /**
- * 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
@@ -120,6 +122,41 @@ extern int uci_unload(struct uci_context *ctx, const char *name);
 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
@@ -128,9 +165,9 @@ extern char **uci_list_configs(struct uci_context *ctx);
 
 /* 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
@@ -150,6 +187,7 @@ struct uci_context
 
        /* private: */
        int errno;
+       const char *func;
        jmp_buf trap;
        char *buf;
        int bufsz;
@@ -178,6 +216,7 @@ struct uci_package
        struct uci_context *ctx;
        /* private: */
        int n_section;
+       struct uci_list history;
 };
 
 struct uci_section
@@ -205,12 +244,9 @@ struct uci_history
 {
        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 */
@@ -274,6 +310,11 @@ struct uci_history
 /* returns true if a list is empty */
 #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[] = {