1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
/*
* plist.h
* Main include of libplist
*
* Copyright (c) 2008 Jonathan Beck All Rights Reserved.
*
* This 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 2.1 of the License, or (at your option) any later version.
*
* This 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 this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef LIBPLIST_H
#define LIBPLIST_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _MSC_VER
typedef __int8 int8_t;
typedef __int16 int16_t;
typedef __int32 int32_t;
typedef __int64 int64_t;
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
#ifdef plist_EXPORTS
#define PLIST_API __declspec( dllexport )
#else
#define PLIST_API __declspec( dllimport )
#endif
#else
#include <stdint.h>
#define PLIST_API
#endif
#include <sys/types.h>
/**
* \mainpage libplist : A library to handle Apple Property Lists
* \defgroup PublicAPI Public libplist API
*/
/*@{*/
/**
* The basic plist abstract data type.
*/
typedef void *plist_t;
/**
* The enumeration of plist node types.
*/
typedef enum {
PLIST_BOOLEAN,
/**< Boolean, scalar type */
PLIST_UINT, /**< Unsigned integer, scalar type */
PLIST_REAL, /**< Real, scalar type */
PLIST_STRING,
/**< ASCII string, scalar type */
PLIST_ARRAY,/**< Ordered array, structured type */
PLIST_DICT, /**< Unordered dictionary (key/value pair), structured type */
PLIST_DATE, /**< Date, scalar type */
PLIST_DATA, /**< Binary data, scalar type */
PLIST_KEY, /**< Key in dictionaries (ASCII String), scalar type */
PLIST_NONE /**< No type */
} plist_type;
/********************************************
* *
* Creation & Destruction *
* *
********************************************/
/**
* Create a new root plist_t type #PLIST_DICT
*
* @return the created plist
* @sa #plist_type
*/
PLIST_API plist_t plist_new_dict(void);
/**
* Create a new root plist_t type #PLIST_ARRAY
*
* @return the created plist
* @sa #plist_type
*/
PLIST_API plist_t plist_new_array(void);
/**
* Destruct a plist_t node and all its children recursively
*
* @param plist the plist to free
*/
PLIST_API void plist_free(plist_t plist);
/********************************************
* *
* Tree navigation *
* *
********************************************/
/**
* Get the first child of a node
*
* @param node the first child
*/
PLIST_API plist_t plist_get_first_child(plist_t node);
/**
* Get the next sibling of a node
*
* @param node the next sibling
*/
PLIST_API plist_t plist_get_next_sibling(plist_t node);
/**
* Get the previous sibling of a node
*
* @param node the previous sibling
*/
PLIST_API plist_t plist_get_prev_sibling(plist_t node);
/**
* Get the nth child of a #PLIST_ARRAY node.
*
* @param node the node of type #PLIST_ARRAY
* @param n the index of the child to get. Range is [0, array_size[
* @return the nth children or NULL if node is not of type #PLIST_ARRAY
*/
PLIST_API plist_t plist_get_array_nth_el(plist_t node, uint32_t n);
/**
* Get the child of a #PLIST_DICT node from the associated key value.
*
* @param node the node of type #PLIST_DICT
* @param key the key associated to the requested value
* @return the key associated value or NULL if node is not of type #PLIST_DICT
*/
PLIST_API plist_t plist_get_dict_el_from_key(plist_t node, const char *key);
/********************************************
* *
* Setters *
* *
********************************************/
/**
* Add a subnode to a node. The node must be of a structured type
* (ie #PLIST_DICT or #PLIST_ARRAY). This function fails silently
* if subnode already has a father.
*
* @param node the node to add a children to
* @param subnode the children node
*/
PLIST_API void plist_add_sub_node(plist_t node, plist_t subnode);
/**
* Add a subnode of type #PLIST_KEY to a node. The node must be of a structured type
* (ie #PLIST_DICT or #PLIST_ARRAY).
*
* @param node the node to add a children to
* @param val the key value encoded as an ASCII string (must be null terminated)
*/
PLIST_API void plist_add_sub_key_el(plist_t node, const char *val);
/**
* Add a subnode of type #PLIST_STRING to a node. The node must be of a structured type
* (ie #PLIST_DICT or #PLIST_ARRAY).
*
* @param node the node to add a children to
* @param val the string value encoded as an ASCII or UTF-8 string (must be null terminated)
*/
PLIST_API void plist_add_sub_string_el(plist_t node, const char *val);
/**
* Add a subnode of type #PLIST_BOOLEAN to a node. The node must be of a structured type
* (ie #PLIST_DICT or #PLIST_ARRAY).
*
* @param node the node to add a children to
* @param val the boolean value (TRUE or FALSE)
*/
PLIST_API void plist_add_sub_bool_el(plist_t node, uint8_t val);
/**
* Add a subnode of type #PLIST_UINT to a node. The node must be of a structured type
* (ie #PLIST_DICT or #PLIST_ARRAY).
*
* @param node the node to add a children to
* @param val the unsigned integer value
*/
PLIST_API void plist_add_sub_uint_el(plist_t node, uint64_t val);
/**
* Add a subnode of type #PLIST_REAL to a node. The node must be of a structured type
* (ie #PLIST_DICT or #PLIST_ARRAY).
*
* @param node the node to add a children to
* @param val the real value
*/
PLIST_API void plist_add_sub_real_el(plist_t node, double val);
/**
* Add a subnode of type #PLIST_DATA to a node. The node must be of a structured type
* (ie #PLIST_DICT or #PLIST_ARRAY).
*
* @param node the node to add a children to
* @param val the binary buffer
* @param length the length of the buffer
*/
PLIST_API void plist_add_sub_data_el(plist_t node, const char *val, uint64_t length);
/**
* Add a subnode of type #PLIST_DATE to a node. The node must be of a structured type
* (ie #PLIST_DICT or #PLIST_ARRAY).
*
* @param node the node to add a children to
* @param sec the number of seconds since 01/01/2001
* @param usec the number of microseconds
*/
PLIST_API void plist_add_sub_date_el(plist_t node, int32_t sec, int32_t usec);
/********************************************
* *
* Getters *
* *
********************************************/
/**
* Get the #plist_type of a node.
*
* @param node the node
* @return the type of the node
*/
PLIST_API plist_type plist_get_node_type(plist_t node);
/**
* Get the value of a #PLIST_KEY node.
* This function does nothing if node is not of type #PLIST_KEY
*
* @param node the node
* @param val a pointer to a C-string. This function allocates the memory,
* caller is responsible for freeing it.
*/
PLIST_API void plist_get_key_val(plist_t node, char **val);
/**
* Get the value of a #PLIST_STRING node.
* This function does nothing if node is not of type #PLIST_STRING
*
* @param node the node
* @param val a pointer to a C-string. This function allocates the memory,
* caller is responsible for freeing it. Data is UTF-8 encoded.
*/
PLIST_API void plist_get_string_val(plist_t node, char **val);
/**
* Get the value of a #PLIST_BOOLEAN node.
* This function does nothing if node is not of type #PLIST_BOOLEAN
*
* @param node the node
* @param val a pointer to a uint8_t variable.
*/
PLIST_API void plist_get_bool_val(plist_t node, uint8_t * val);
/**
* Get the value of a #PLIST_UINT node.
* This function does nothing if node is not of type #PLIST_UINT
*
* @param node the node
* @param val a pointer to a uint64_t variable.
*/
PLIST_API void plist_get_uint_val(plist_t node, uint64_t * val);
/**
* Get the value of a #PLIST_REAL node.
* This function does nothing if node is not of type #PLIST_REAL
*
* @param node the node
* @param val a pointer to a double variable.
*/
PLIST_API void plist_get_real_val(plist_t node, double *val);
/**
* Get the value of a #PLIST_DATA node.
* This function does nothing if node is not of type #PLIST_DATA
*
* @param node the node
* @param val a pointer to an unallocated char buffer. This function allocates the memory,
* caller is responsible for freeing it.
*/
PLIST_API void plist_get_data_val(plist_t node, char **val, uint64_t * length);
/**
* Get the value of a #PLIST_DATE node.
* This function does nothing if node is not of type #PLIST_DATE
*
* @param node the node
* @param sec a pointer to an int32_t variable. Represents the number of seconds since 01/01/2001.
* @param usec a pointer to an int32_t variable. Represents the number of microseconds
*/
PLIST_API void plist_get_date_val(plist_t node, int32_t * sec, int32_t * usec);
/********************************************
* *
* Import & Export *
* *
********************************************/
/**
* Export the #plist_t structure to XML format.
*
* @param plist the root node to export
* @param plist_xml a pointer to a C-string. This function allocates the memory,
* caller is responsible for freeing it. Data is UTF-8 encoded.
* @param length a pointer to an uint32_t variable. Represents the length of the allocated buffer.
*/
PLIST_API void plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length);
/**
* Export the #plist_t structure to binary format.
*
* @param plist the root node to export
* @param plist_bin a pointer to a char* buffer. This function allocates the memory,
* caller is responsible for freeing it.
* @param length a pointer to an uint32_t variable. Represents the length of the allocated buffer.
*/
PLIST_API void plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length);
/**
* Import the #plist_t structure from XML format.
*
* @param plist_xml a pointer to the xml buffer.
* @param length length of the buffer to read.
* @param plist a pointer to the imported plist.
*/
PLIST_API void plist_from_xml(const char *plist_xml, uint32_t length, plist_t * plist);
/**
* Import the #plist_t structure from binary format.
*
* @param plist_bin a pointer to the xml buffer.
* @param length length of the buffer to read.
* @param plist a pointer to the imported plist.
*/
PLIST_API void plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist);
/********************************************
* *
* Utils *
* *
********************************************/
/**
* Find the first encountered #PLIST_KEY node mathing that key.
* Search is breath first order.
*
* @param plist the root node of the plist structure.
* @param value the ASCII Key to match.
*/
PLIST_API plist_t plist_find_node_by_key(plist_t plist, const char *value);
/**
* Find the first encountered #PLIST_STRING node mathing that string.
* Search is breath first order.
*
* @param plist the root node of the plist structure.
* @param value the ASCII String to match.
*/
PLIST_API plist_t plist_find_node_by_string(plist_t plist, const char *value);
/**
* Compare two node values
*
* @param node_l left node to compare
* @param node_r rigth node to compare
* @return TRUE is type and value match, FALSE otherwise.
*/
PLIST_API char plist_compare_node_value(plist_t node_l, plist_t node_r);
/*@}*/
#ifdef __cplusplus
}
#endif
#endif
|