summaryrefslogtreecommitdiffstats
path: root/common/ini/ini_valueobj.h
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2010-06-10 11:57:25 -0400
committerDmitri Pal <dpal@redhat.com>2010-08-10 12:51:32 -0400
commit85acfe3f0e53db93a741040d12642083260664f6 (patch)
treee1f62378ff562252e9cb5495baed25c45cefaa8b /common/ini/ini_valueobj.h
parent67177f82868a56a255b0eda2003b929d0bdd5f09 (diff)
downloadsssd-85acfe3f0e53db93a741040d12642083260664f6.tar.gz
sssd-85acfe3f0e53db93a741040d12642083260664f6.tar.xz
sssd-85acfe3f0e53db93a741040d12642083260664f6.zip
[INI] Introducing Value object
Value object is an object that combines a potentially multiline value comment and some statistical information regarding a configuration value. Patch includes: Source Header Unit test Makefile changes
Diffstat (limited to 'common/ini/ini_valueobj.h')
-rw-r--r--common/ini/ini_valueobj.h130
1 files changed, 130 insertions, 0 deletions
diff --git a/common/ini/ini_valueobj.h b/common/ini/ini_valueobj.h
new file mode 100644
index 0000000..d8e10de
--- /dev/null
+++ b/common/ini/ini_valueobj.h
@@ -0,0 +1,130 @@
+/*
+ INI LIBRARY
+
+ Header file for the value object.
+
+ Copyright (C) Dmitri Pal <dpal@redhat.com> 2010
+
+ INI Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ INI Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with INI Library. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+
+#ifndef INI_VALUEOBJ_H
+#define INI_VALUEOBJ_H
+
+#include "ref_array.h"
+#include "simplebuffer.h"
+#include "ini_comment.h"
+
+struct value_obj;
+
+#define INI_VALUE_READ 0 /* Value is read from the file */
+#define INI_VALUE_CREATED 1 /* Value is created in memory */
+
+/*
+ * Create value from a referenced array.
+ *
+ * NOTE: arrays and comment are NOT treated as
+ * objects that keep reference count.
+ * They are created externally and passed in
+ * as separate parts that are glued together
+ * by the value object.
+ * The caller should not free it himself
+ * (only in case of failure) since
+ * after the call the arrays and comment
+ * are owned by the value object and will
+ * be freed when it is destroyed.
+ */
+int value_create_from_refarray(struct ref_array *raw_lines,
+ struct ref_array *raw_lengths,
+ uint32_t line,
+ uint32_t origin,
+ uint32_t key_len,
+ uint32_t boundary,
+ struct ini_comment *ic,
+ struct value_obj **vo);
+
+/* Cleanup callback for lines array */
+void value_lines_cleanup_cb(void *elem,
+ ref_array_del_enum type,
+ void *data);
+
+/* Create a pair of arrays */
+int value_create_arrays(struct ref_array **raw_lines,
+ struct ref_array **raw_lengths);
+
+/* Add a raw read line to the arrays */
+int value_add_to_arrays(const char *strvalue,
+ uint32_t len,
+ struct ref_array *raw_lines,
+ struct ref_array *raw_lengths);
+
+/* Create a pair of arrays */
+void value_destroy_arrays(struct ref_array *raw_lines,
+ struct ref_array *raw_lengths);
+
+/* Create value object from string buffer.
+ * NOTE: see note above
+ * in the description of the
+ * value_create_from_refarray function.
+ */
+int value_create_new(const char *strvalue,
+ uint32_t length,
+ uint32_t origin,
+ uint32_t key_len,
+ uint32_t boundary,
+ struct ini_comment *ic,
+ struct value_obj **vo);
+
+/* Destroy a value object */
+void value_destroy(struct value_obj *vo);
+
+/* Get concatenated value */
+int value_get_concatenated(struct value_obj *vo,
+ const char **fullstr);
+
+/* Get value's origin */
+int value_get_origin(struct value_obj *vo,
+ uint32_t *origin);
+
+/* Get value's line */
+int value_get_line(struct value_obj *vo,
+ uint32_t *line);
+
+/* Update key length */
+int value_set_keylen(struct value_obj *vo,
+ uint32_t key_len);
+
+/* Update value */
+int value_update(struct value_obj *vo,
+ const char *value,
+ uint32_t length,
+ uint32_t origin,
+ uint32_t boundary);
+
+/* Get comment from the value */
+int value_extract_comment(struct value_obj *vo,
+ struct ini_comment **ic);
+
+/* Set comment into the value */
+int value_put_comment(struct value_obj *vo,
+ struct ini_comment *ic);
+
+/* Serialize value */
+int value_serialize(struct value_obj *vo,
+ const char *key,
+ struct simplebuffer **sbobj);
+
+
+#endif