fix wrong buffer allocation
[project/uci.git] / uci.h
diff --git a/uci.h b/uci.h
index 16c69665f6eabfe5bb6e6f2296b1ce1fbca6eeb6..198ae2a5888a3da88cf69e72b19eb1a54df5cc77 100644 (file)
--- a/uci.h
+++ b/uci.h
@@ -186,6 +186,14 @@ extern int uci_add_section(struct uci_context *ctx, struct uci_package *p, const
  */
 extern int uci_set_element_value(struct uci_context *ctx, struct uci_element **element, const char *value);
 
+/**
+ * uci_add_element_list: Append a string to a list option
+ * @ctx: uci context
+ * @option: pointer to the uci option element
+ * @value: string to append
+ */
+extern int uci_add_element_list(struct uci_context *ctx, struct uci_option *o, const char *value);
+
 /**
  * uci_set: Set an element's value; create the element if necessary
  * @ctx: uci context
@@ -197,6 +205,20 @@ extern int uci_set_element_value(struct uci_context *ctx, struct uci_element **e
  */
 extern int uci_set(struct uci_context *ctx, struct uci_package *p, const char *section, const char *option, const char *value, struct uci_element **result);
 
+/**
+ * uci_add_list: Append a string to an element list
+ * @ctx: uci context
+ * @package: package name
+ * @section: section name
+ * @option: option name
+ * @value: string value
+ * @result: store the updated element in this variable (optional)
+ *
+ * Note: if the given option already contains a string, convert it to an 1-element-list
+ * before appending the next element
+ */
+extern int uci_add_list(struct uci_context *ctx, struct uci_package *p, const char *section, const char *option, const char *value, struct uci_option **result);
+
 /**
  * uci_rename: Rename an element
  * @ctx: uci context
@@ -317,6 +339,12 @@ enum uci_type {
        UCI_TYPE_OPTION = 3,
        UCI_TYPE_PATH = 4,
        UCI_TYPE_BACKEND = 5,
+       UCI_TYPE_ITEM = 6,
+};
+
+enum uci_option_type {
+       UCI_TYPE_STRING = 0,
+       UCI_TYPE_LIST = 1,
 };
 
 enum uci_flags {
@@ -404,14 +432,19 @@ struct uci_option
 {
        struct uci_element e;
        struct uci_section *section;
-       char *value;
+       enum uci_option_type type;
+       union {
+               struct uci_list list;
+               char *string;
+       } v;
 };
 
 enum uci_command {
        UCI_CMD_ADD,
        UCI_CMD_REMOVE,
        UCI_CMD_CHANGE,
-       UCI_CMD_RENAME
+       UCI_CMD_RENAME,
+       UCI_CMD_LIST_ADD,
 };
 
 struct uci_history