summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Jonathan Beck2009-01-29 22:08:44 +0100
committerGravatar Jonathan Beck2009-01-29 22:08:44 +0100
commit7bb672f801c3a245b38535f5a33f9fffa88c683c (patch)
treee536996d360fcb4438a95a6899708f6a917b17d7
parentf1d587b73eb3d8a7379e7c44f03257e6e553ca1b (diff)
downloadlibplist-7bb672f801c3a245b38535f5a33f9fffa88c683c.tar.gz
libplist-7bb672f801c3a245b38535f5a33f9fffa88c683c.tar.bz2
Add documentation to the public API.
-rw-r--r--include/plist/plist.h332
1 files changed, 306 insertions, 26 deletions
diff --git a/include/plist/plist.h b/include/plist/plist.h
index 76ce0ec..2c0df11 100644
--- a/include/plist/plist.h
+++ b/include/plist/plist.h
@@ -29,72 +29,352 @@ extern "C" {
29#include <stdint.h> 29#include <stdint.h>
30#include <sys/types.h> 30#include <sys/types.h>
31 31
32/**
33 * \mainpage libplist : A library to handle Apple Property Lists
34 * \defgroup PublicAPI Public libplist API
35 */
36/*@{*/
37
38
39/**
40 * The basic plist abstract data type.
41 */
32typedef void* plist_t; 42typedef void* plist_t;
33 43
44/**
45 * The enumeration of plist node types.
46 */
34typedef enum { 47typedef enum {
35 PLIST_BOOLEAN, 48 PLIST_BOOLEAN, /**< Boolean, scalar type */
36 PLIST_UINT, 49 PLIST_UINT, /**< Unsigned integer, scalar type */
37 PLIST_REAL, 50 PLIST_REAL, /**< Real, scalar type */
38 PLIST_STRING, 51 PLIST_STRING, /**< ASCII string, scalar type */
39 PLIST_UNICODE, 52 PLIST_UNICODE, /**< Unicode strin, scalar type */
40 PLIST_ARRAY, 53 PLIST_ARRAY, /**< Ordered array, structured type */
41 PLIST_DICT, 54 PLIST_DICT, /**< Unordered dictionary (key/value pair), structured type */
42 PLIST_DATE, 55 PLIST_DATE, /**< Date, scalar type */
43 PLIST_DATA, 56 PLIST_DATA, /**< Binary data, scalar type */
44 PLIST_KEY, 57 PLIST_KEY, /**< Key in dictionaries (ASCII String), scalar type */
45 PLIST_NONE 58 PLIST_NONE /**< No type */
46} plist_type; 59} plist_type;
47 60
48//Plist creation and edition 61
49//utilitary functions to create root nodes (supposed to be dict or array) 62/********************************************
63 * *
64 * Creation & Destruction *
65 * *
66 ********************************************/
67
68/**
69 * Create a new root plist_t type #PLIST_DICT
70 *
71 * @return the created plist
72 * @sa #plist_type
73 */
50plist_t plist_new_dict(); 74plist_t plist_new_dict();
75
76/**
77 * Create a new root plist_t type #PLIST_ARRAY
78 *
79 * @return the created plist
80 * @sa #plist_type
81 */
51plist_t plist_new_array(); 82plist_t plist_new_array();
52 83
84/**
85 * Destruct a plist_t node and all its children recursively
86 *
87 * @param plist the plist to free
88 */
89void plist_free(plist_t plist);
53 90
54//Plist edition, only work for dict and array node 91/********************************************
92 * *
93 * Tree navigation *
94 * *
95 ********************************************/
96
97/**
98 * Get the first child of a node
99 *
100 * @param node the first child
101 */
102plist_t plist_get_first_child(plist_t node);
103
104
105/**
106 * Get the next sibling of a node
107 *
108 * @param node the next sibling
109 */
110plist_t plist_get_next_sibling(plist_t node);
111
112
113/**
114 * Get the previous sibling of a node
115 *
116 * @param node the previous sibling
117 */
118plist_t plist_get_prev_sibling(plist_t node);
119
120/********************************************
121 * *
122 * Setters *
123 * *
124 ********************************************/
125
126/**
127 * Add a subnode to a node. The node must be of a structured type
128 * (ie #PLIST_DICT or #PLIST_ARRAY). This function fails silently
129 * if subnode already has a father.
130 *
131 * @param node the node to add a children to
132 * @param subnode the children node
133 */
55void plist_add_sub_node(plist_t node, plist_t subnode); 134void plist_add_sub_node(plist_t node, plist_t subnode);
56 135
136/**
137 * Add a subnode of type #PLIST_KEY to a node. The node must be of a structured type
138 * (ie #PLIST_DICT or #PLIST_ARRAY).
139 *
140 * @param node the node to add a children to
141 * @param val the key value encoded as an ASCII string (must be null terminated)
142 */
57void plist_add_sub_key_el(plist_t node, const char* val); 143void plist_add_sub_key_el(plist_t node, const char* val);
144
145/**
146 * Add a subnode of type #PLIST_STRING to a node. The node must be of a structured type
147 * (ie #PLIST_DICT or #PLIST_ARRAY).
148 *
149 * @param node the node to add a children to
150 * @param val the string value encoded as an ASCII string (must be null terminated)
151 */
58void plist_add_sub_string_el(plist_t node, const char* val); 152void plist_add_sub_string_el(plist_t node, const char* val);
153
154/**
155 * Add a subnode of type #PLIST_BOOLEAN to a node. The node must be of a structured type
156 * (ie #PLIST_DICT or #PLIST_ARRAY).
157 *
158 * @param node the node to add a children to
159 * @param val the boolean value (TRUE or FALSE)
160 */
59void plist_add_sub_bool_el(plist_t node, uint8_t val); 161void plist_add_sub_bool_el(plist_t node, uint8_t val);
162
163/**
164 * Add a subnode of type #PLIST_UINT to a node. The node must be of a structured type
165 * (ie #PLIST_DICT or #PLIST_ARRAY).
166 *
167 * @param node the node to add a children to
168 * @param val the unsigned integer value
169 */
60void plist_add_sub_uint_el(plist_t node, uint64_t val); 170void plist_add_sub_uint_el(plist_t node, uint64_t val);
171
172/**
173 * Add a subnode of type #PLIST_REAL to a node. The node must be of a structured type
174 * (ie #PLIST_DICT or #PLIST_ARRAY).
175 *
176 * @param node the node to add a children to
177 * @param val the real value
178 */
61void plist_add_sub_real_el(plist_t node, double val); 179void plist_add_sub_real_el(plist_t node, double val);
180
181/**
182 * Add a subnode of type #PLIST_DATA to a node. The node must be of a structured type
183 * (ie #PLIST_DICT or #PLIST_ARRAY).
184 *
185 * @param node the node to add a children to
186 * @param val the binary buffer
187 * @param length the length of the buffer
188 */
62void plist_add_sub_data_el(plist_t node, const char* val, uint64_t length); 189void plist_add_sub_data_el(plist_t node, const char* val, uint64_t length);
190
191/**
192 * Add a subnode of type #PLIST_UNICODE to a node. The node must be of a structured type
193 * (ie #PLIST_DICT or #PLIST_ARRAY).
194 *
195 * @param node the node to add a children to
196 * @param val the unicode string encoded in UTF-8 (must be null terminated)
197 */
63void plist_add_sub_unicode_el(plist_t node, const char* val); 198void plist_add_sub_unicode_el(plist_t node, const char* val);
64void plist_add_sub_date_el(plist_t node, int32_t sec, int32_t usec);
65 199
66//plist free 200/**
67void plist_free(plist_t plist); 201 * Add a subnode of type #PLIST_DATE to a node. The node must be of a structured type
202 * (ie #PLIST_DICT or #PLIST_ARRAY).
203 *
204 * @param node the node to add a children to
205 * @param sec the number of seconds since 01/01/2001
206 * @param usec the number of microseconds
207 */
208void plist_add_sub_date_el(plist_t node, int32_t sec, int32_t usec);
68 209
69//plist navigation
70plist_t plist_get_first_child(plist_t node);
71plist_t plist_get_next_sibling(plist_t node);
72plist_t plist_get_prev_sibling(plist_t node);
73 210
74//utili function to find first (and only the first encountred) corresponding node 211/********************************************
75plist_t plist_find_node_by_key(plist_t plist, const char *value); 212 * *
76plist_t plist_find_node_by_string(plist_t plist, const char *value); 213 * Getters *
214 * *
215 ********************************************/
77 216
78//Plist reading 217/**
218 * Get the #plist_type of a node.
219 *
220 * @param node the node
221 * @return the type of the node
222 */
79plist_type plist_get_node_type(plist_t node); 223plist_type plist_get_node_type(plist_t node);
80 224
225/**
226 * Get the value of a #PLIST_KEY node.
227 * This function does nothing if node is not of type #PLIST_KEY
228 *
229 * @param node the node
230 * @param val a pointer to a C-string. This function allocates the memory,
231 * caller is responsible for freeing it.
232 */
81void plist_get_key_val(plist_t node, char** val); 233void plist_get_key_val(plist_t node, char** val);
234
235/**
236 * Get the value of a #PLIST_STRING node.
237 * This function does nothing if node is not of type #PLIST_STRING
238 *
239 * @param node the node
240 * @param val a pointer to a C-string. This function allocates the memory,
241 * caller is responsible for freeing it.
242 */
82void plist_get_string_val(plist_t node, char** val); 243void plist_get_string_val(plist_t node, char** val);
244
245/**
246 * Get the value of a #PLIST_BOOLEAN node.
247 * This function does nothing if node is not of type #PLIST_BOOLEAN
248 *
249 * @param node the node
250 * @param val a pointer to a uint8_t variable.
251 */
83void plist_get_bool_val(plist_t node, uint8_t* val); 252void plist_get_bool_val(plist_t node, uint8_t* val);
253
254/**
255 * Get the value of a #PLIST_UINT node.
256 * This function does nothing if node is not of type #PLIST_UINT
257 *
258 * @param node the node
259 * @param val a pointer to a uint64_t variable.
260 */
84void plist_get_uint_val(plist_t node, uint64_t* val); 261void plist_get_uint_val(plist_t node, uint64_t* val);
262
263/**
264 * Get the value of a #PLIST_REAL node.
265 * This function does nothing if node is not of type #PLIST_REAL
266 *
267 * @param node the node
268 * @param val a pointer to a double variable.
269 */
85void plist_get_real_val(plist_t node, double* val); 270void plist_get_real_val(plist_t node, double* val);
271
272/**
273 * Get the value of a #PLIST_DATA node.
274 * This function does nothing if node is not of type #PLIST_DATA
275 *
276 * @param node the node
277 * @param val a pointer to an unallocated char buffer. This function allocates the memory,
278 * caller is responsible for freeing it.
279 */
86void plist_get_data_val(plist_t node, char** val, uint64_t* length); 280void plist_get_data_val(plist_t node, char** val, uint64_t* length);
281
282/**
283 * Get the value of a #PLIST_UNICODE node.
284 * This function does nothing if node is not of type #PLIST_UNICODE
285 *
286 * @param node the node
287 * @param val a pointer to a C-string. This function allocates the memory,
288 * caller is responsible for freeing it. Data is UTF-8 encoded.
289 */
87void plist_get_unicode_val(plist_t node, char** val); 290void plist_get_unicode_val(plist_t node, char** val);
291
292/**
293 * Get the value of a #PLIST_DATE node.
294 * This function does nothing if node is not of type #PLIST_DATE
295 *
296 * @param node the node
297 * @param sec a pointer to an int32_t variable. Represents the number of seconds since 01/01/2001.
298 * @param usec a pointer to an int32_t variable. Represents the number of microseconds
299 */
88void plist_get_date_val(plist_t node, int32_t* sec, int32_t* usec); 300void plist_get_date_val(plist_t node, int32_t* sec, int32_t* usec);
89 301
90 302
91//import and export functions 303
304/********************************************
305 * *
306 * Import & Export *
307 * *
308 ********************************************/
309
310/**
311 * Export the #plist_t structure to XML format.
312 *
313 * @param plist the root node to export
314 * @param plist_xml a pointer to a C-string. This function allocates the memory,
315 * caller is responsible for freeing it. Data is UTF-8 encoded.
316 * @param length a pointer to an uint32_t variable. Represents the length of the allocated buffer.
317 */
92void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length); 318void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length);
319
320/**
321 * Export the #plist_t structure to binary format.
322 *
323 * @param plist the root node to export
324 * @param plist_bin a pointer to a char* buffer. This function allocates the memory,
325 * caller is responsible for freeing it.
326 * @param length a pointer to an uint32_t variable. Represents the length of the allocated buffer.
327 */
93void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length); 328void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length);
94 329
330/**
331 * Import the #plist_t structure from XML format.
332 *
333 * @param plist_xml a pointer to the xml buffer.
334 * @param length length of the buffer to read.
335 * @param plist a pointer to the imported plist.
336 */
95void plist_from_xml(const char *plist_xml, uint32_t length, plist_t * plist); 337void plist_from_xml(const char *plist_xml, uint32_t length, plist_t * plist);
338
339/**
340 * Import the #plist_t structure from binary format.
341 *
342 * @param plist_bin a pointer to the xml buffer.
343 * @param length length of the buffer to read.
344 * @param plist a pointer to the imported plist.
345 */
96void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist); 346void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist);
97 347
348
349
350/********************************************
351 * *
352 * Utils *
353 * *
354 ********************************************/
355
356/**
357 * Find the first encountered #PLIST_KEY node mathing that key.
358 * Search is breath first order.
359 *
360 * @param plist the root node of the plist structure.
361 * @param value the ASCII Key to match.
362 */
363plist_t plist_find_node_by_key(plist_t plist, const char *value);
364
365/**
366 * Find the first encountered #PLIST_STRING node mathing that string.
367 * Search is breath first order.
368 *
369 * @param plist the root node of the plist structure.
370 * @param value the ASCII String to match.
371 */
372plist_t plist_find_node_by_string(plist_t plist, const char *value);
373
374
375/*@}*/
376
377
98#ifdef __cplusplus 378#ifdef __cplusplus
99} 379}
100#endif 380#endif