1 /*
2     INI LIBRARY
3 
4     Header file for the value object.
5 
6     Copyright (C) Dmitri Pal <dpal@redhat.com> 2010
7 
8     INI Library is free software: you can redistribute it and/or modify
9     it under the terms of the GNU Lesser General Public License as published by
10     the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12 
13     INI Library is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU Lesser General Public License for more details.
17 
18     You should have received a copy of the GNU Lesser General Public License
19     along with INI Library.  If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 
23 #ifndef INI_VALUEOBJ_H
24 #define INI_VALUEOBJ_H
25 
26 #include "ref_array.h"
27 #include "simplebuffer.h"
28 #include "ini_comment.h"
29 
30 struct value_obj;
31 
32 #define INI_VALUE_READ      0 /* Value is read from the file */
33 #define INI_VALUE_CREATED   1 /* Value is created in memory  */
34 
35 /*
36  * Create value from a referenced array.
37  *
38  * NOTE: arrays and comment are NOT treated as
39  * objects that keep reference count.
40  * They are created externally and passed in
41  * as separate parts that are glued together
42  * by the value object.
43  * The caller should not free it himself
44  * (only in case of failure) since
45  * after the call the arrays and comment
46  * are owned by the value object and will
47  * be freed when it is destroyed.
48  */
49 int value_create_from_refarray(struct ref_array *raw_lines,
50                                struct ref_array *raw_lengths,
51                                uint32_t line,
52                                uint32_t origin,
53                                uint32_t key_len,
54                                uint32_t boundary,
55                                struct ini_comment *ic,
56                                struct value_obj **vo);
57 
58 /* Cleanup callback for lines array */
59 void value_lines_cleanup_cb(void *elem,
60                             ref_array_del_enum type,
61                             void *data);
62 
63 /* Create a pair of arrays */
64 int value_create_arrays(struct ref_array **raw_lines,
65                         struct ref_array **raw_lengths);
66 
67 /* Add a raw read line to the arrays */
68 int value_add_to_arrays(const char *strvalue,
69                         uint32_t len,
70                         struct ref_array *raw_lines,
71                         struct ref_array *raw_lengths);
72 
73 /* Create a pair of arrays */
74 void value_destroy_arrays(struct ref_array *raw_lines,
75                           struct ref_array *raw_lengths);
76 
77 /* Create value object from string buffer.
78  * NOTE: see note above
79  * in the description of the
80  * value_create_from_refarray function.
81  */
82 int value_create_new(const char *strvalue,
83                      uint32_t length,
84                      uint32_t origin,
85                      uint32_t key_len,
86                      uint32_t boundary,
87                      struct ini_comment *ic,
88                      struct value_obj **vo);
89 
90 /* Create a copy of the value */
91 int value_copy(struct value_obj *vo,
92                struct value_obj **copy_vo);
93 
94 /* Destroy a value object */
95 void value_destroy(struct value_obj *vo);
96 
97 /* Get concatenated value */
98 int value_get_concatenated(struct value_obj *vo,
99                            const char **fullstr);
100 
101 /* Get length of the concatenated value */
102 int value_get_concatenated_len(struct value_obj *vo,
103                                uint32_t *len);
104 
105 /* Get value's origin */
106 int value_get_origin(struct value_obj *vo,
107                      uint32_t *origin);
108 
109 /* Get value's line */
110 int value_get_line(struct value_obj *vo,
111                    uint32_t *line);
112 
113 /* Update key length */
114 int value_set_keylen(struct value_obj *vo,
115                      uint32_t key_len);
116 /* Change boundary */
117 int value_set_boundary(struct value_obj *vo,
118                        uint32_t boundary);
119 
120 /* Update value */
121 int value_update(struct value_obj *vo,
122                  const char *value,
123                  uint32_t length,
124                  uint32_t origin,
125                  uint32_t boundary);
126 
127 /* Get comment from the value */
128 int value_extract_comment(struct value_obj *vo,
129                           struct ini_comment **ic);
130 
131 /* Set comment into the value */
132 int value_put_comment(struct value_obj *vo,
133                       struct ini_comment *ic);
134 
135 /* Merge comment from one value into another */
136 int value_merge_comment(struct value_obj *vo_donor,
137                         struct value_obj *vo);
138 
139 /* Serialize value */
140 int value_serialize(struct value_obj *vo,
141                     const char *key,
142                     struct simplebuffer *sbobj);
143 
144 /* Print value */
145 void value_print(const char *key, struct value_obj *vo);
146 
147 #endif
148