plist.h 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  1. /**
  2. * @file plist/plist.h
  3. * @brief Main include of libplist
  4. * \internal
  5. *
  6. * Copyright (c) 2012-2023 Nikias Bassen, All Rights Reserved.
  7. * Copyright (c) 2008-2009 Jonathan Beck, All Rights Reserved.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #ifndef LIBPLIST_H
  24. #define LIBPLIST_H
  25. #ifdef __cplusplus
  26. extern "C"
  27. {
  28. #endif
  29. #if _MSC_VER && _MSC_VER < 1700
  30. typedef __int8 int8_t;
  31. typedef __int16 int16_t;
  32. typedef __int32 int32_t;
  33. typedef __int64 int64_t;
  34. typedef unsigned __int8 uint8_t;
  35. typedef unsigned __int16 uint16_t;
  36. typedef unsigned __int32 uint32_t;
  37. typedef unsigned __int64 uint64_t;
  38. #else
  39. #include <stdint.h>
  40. #endif
  41. /*{{{ deprecation macros */
  42. #ifdef __llvm__
  43. #if defined(__has_extension)
  44. #if (__has_extension(attribute_deprecated_with_message))
  45. #ifndef PLIST_WARN_DEPRECATED
  46. #define PLIST_WARN_DEPRECATED(x) __attribute__((deprecated(x)))
  47. #endif
  48. #else
  49. #ifndef PLIST_WARN_DEPRECATED
  50. #define PLIST_WARN_DEPRECATED(x) __attribute__((deprecated))
  51. #endif
  52. #endif
  53. #else
  54. #ifndef PLIST_WARN_DEPRECATED
  55. #define PLIST_WARN_DEPRECATED(x) __attribute__((deprecated))
  56. #endif
  57. #endif
  58. #elif (__GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ >= 5)))
  59. #ifndef PLIST_WARN_DEPRECATED
  60. #define PLIST_WARN_DEPRECATED(x) __attribute__((deprecated(x)))
  61. #endif
  62. #elif defined(_MSC_VER)
  63. #ifndef PLIST_WARN_DEPRECATED
  64. #define PLIST_WARN_DEPRECATED(x) __declspec(deprecated(x))
  65. #endif
  66. #else
  67. #define PLIST_WARN_DEPRECATED(x)
  68. #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
  69. #endif
  70. /*}}}*/
  71. #ifndef PLIST_API
  72. #ifdef LIBPLIST_STATIC
  73. #define PLIST_API
  74. #elif defined(_WIN32)
  75. #define PLIST_API __declspec(dllimport)
  76. #else
  77. #define PLIST_API
  78. #endif
  79. #endif
  80. #include <sys/types.h>
  81. #include <stdarg.h>
  82. #include <stdio.h>
  83. /**
  84. * libplist : A library to handle Apple Property Lists
  85. * \defgroup PublicAPI Public libplist API
  86. */
  87. /*@{*/
  88. /**
  89. * The basic plist abstract data type.
  90. */
  91. typedef void *plist_t;
  92. /**
  93. * The plist dictionary iterator.
  94. */
  95. typedef void* plist_dict_iter;
  96. /**
  97. * The plist array iterator.
  98. */
  99. typedef void* plist_array_iter;
  100. /**
  101. * The enumeration of plist node types.
  102. */
  103. typedef enum
  104. {
  105. PLIST_NONE =-1, /**< No type */
  106. PLIST_BOOLEAN, /**< Boolean, scalar type */
  107. PLIST_INT, /**< Integer, scalar type */
  108. PLIST_REAL, /**< Real, scalar type */
  109. PLIST_STRING, /**< ASCII string, scalar type */
  110. PLIST_ARRAY, /**< Ordered array, structured type */
  111. PLIST_DICT, /**< Unordered dictionary (key/value pair), structured type */
  112. PLIST_DATE, /**< Date, scalar type */
  113. PLIST_DATA, /**< Binary data, scalar type */
  114. PLIST_KEY, /**< Key in dictionaries (ASCII String), scalar type */
  115. PLIST_UID, /**< Special type used for 'keyed encoding' */
  116. PLIST_NULL, /**< NULL type */
  117. } plist_type;
  118. /* for backwards compatibility */
  119. #define PLIST_UINT PLIST_INT
  120. /**
  121. * libplist error values
  122. */
  123. typedef enum
  124. {
  125. PLIST_ERR_SUCCESS = 0, /**< operation successful */
  126. PLIST_ERR_INVALID_ARG = -1, /**< one or more of the parameters are invalid */
  127. PLIST_ERR_FORMAT = -2, /**< the plist contains nodes not compatible with the output format */
  128. PLIST_ERR_PARSE = -3, /**< parsing of the input format failed */
  129. PLIST_ERR_NO_MEM = -4, /**< not enough memory to handle the operation */
  130. PLIST_ERR_IO = -5, /**< I/O error */
  131. PLIST_ERR_UNKNOWN = -255 /**< an unspecified error occurred */
  132. } plist_err_t;
  133. /**
  134. * libplist format types
  135. */
  136. typedef enum
  137. {
  138. PLIST_FORMAT_NONE = 0, /**< No format */
  139. PLIST_FORMAT_XML = 1, /**< XML format */
  140. PLIST_FORMAT_BINARY = 2, /**< bplist00 format */
  141. PLIST_FORMAT_JSON = 3, /**< JSON format */
  142. PLIST_FORMAT_OSTEP = 4, /**< OpenStep "old-style" plist format */
  143. /* 5-9 are reserved for possible future use */
  144. PLIST_FORMAT_PRINT = 10, /**< human-readable output-only format */
  145. PLIST_FORMAT_LIMD = 11, /**< "libimobiledevice" output-only format (ideviceinfo) */
  146. PLIST_FORMAT_PLUTIL = 12, /**< plutil-style output-only format */
  147. } plist_format_t;
  148. /**
  149. * libplist write options
  150. */
  151. typedef enum
  152. {
  153. PLIST_OPT_NONE = 0, /**< Default value to use when none of the options is needed. */
  154. PLIST_OPT_COMPACT = 1 << 0, /**< Use a compact representation (non-prettified). Only valid for #PLIST_FORMAT_JSON and #PLIST_FORMAT_OSTEP. */
  155. PLIST_OPT_PARTIAL_DATA = 1 << 1, /**< Print 24 bytes maximum of #PLIST_DATA values. If the data is longer than 24 bytes, the first 16 and last 8 bytes will be written. Only valid for #PLIST_FORMAT_PRINT. */
  156. PLIST_OPT_NO_NEWLINE = 1 << 2, /**< Do not print a final newline character. Only valid for #PLIST_FORMAT_PRINT, #PLIST_FORMAT_LIMD, and #PLIST_FORMAT_PLUTIL. */
  157. PLIST_OPT_INDENT = 1 << 3, /**< Indent each line of output. Currently only #PLIST_FORMAT_PRINT and #PLIST_FORMAT_LIMD are supported. Use #PLIST_OPT_INDENT_BY() macro to specify the level of indentation. */
  158. } plist_write_options_t;
  159. /** To be used with #PLIST_OPT_INDENT - encodes the level of indentation for OR'ing it into the #plist_write_options_t bitfield. */
  160. #define PLIST_OPT_INDENT_BY(x) ((x & 0xFF) << 24)
  161. /********************************************
  162. * *
  163. * Creation & Destruction *
  164. * *
  165. ********************************************/
  166. /**
  167. * Create a new root plist_t type #PLIST_DICT
  168. *
  169. * @return the created plist
  170. * @sa #plist_type
  171. */
  172. PLIST_API plist_t plist_new_dict(void);
  173. /**
  174. * Create a new root plist_t type #PLIST_ARRAY
  175. *
  176. * @return the created plist
  177. * @sa #plist_type
  178. */
  179. PLIST_API plist_t plist_new_array(void);
  180. /**
  181. * Create a new plist_t type #PLIST_STRING
  182. *
  183. * @param val the sting value, encoded in UTF8.
  184. * @return the created item
  185. * @sa #plist_type
  186. */
  187. PLIST_API plist_t plist_new_string(const char *val);
  188. /**
  189. * Create a new plist_t type #PLIST_BOOLEAN
  190. *
  191. * @param val the boolean value, 0 is false, other values are true.
  192. * @return the created item
  193. * @sa #plist_type
  194. */
  195. PLIST_API plist_t plist_new_bool(uint8_t val);
  196. /**
  197. * Create a new plist_t type #PLIST_INT with an unsigned integer value
  198. *
  199. * @param val the unsigned integer value
  200. * @return the created item
  201. * @sa #plist_type
  202. * @note The value is always stored as uint64_t internally.
  203. * Use #plist_get_uint_val or #plist_get_int_val to get the unsigned or signed value.
  204. */
  205. PLIST_API plist_t plist_new_uint(uint64_t val);
  206. /**
  207. * Create a new plist_t type #PLIST_INT with a signed integer value
  208. *
  209. * @param val the signed integer value
  210. * @return the created item
  211. * @sa #plist_type
  212. * @note The value is always stored as uint64_t internally.
  213. * Use #plist_get_uint_val or #plist_get_int_val to get the unsigned or signed value.
  214. */
  215. PLIST_API plist_t plist_new_int(int64_t val);
  216. /**
  217. * Create a new plist_t type #PLIST_REAL
  218. *
  219. * @param val the real value
  220. * @return the created item
  221. * @sa #plist_type
  222. */
  223. PLIST_API plist_t plist_new_real(double val);
  224. /**
  225. * Create a new plist_t type #PLIST_DATA
  226. *
  227. * @param val the binary buffer
  228. * @param length the length of the buffer
  229. * @return the created item
  230. * @sa #plist_type
  231. */
  232. PLIST_API plist_t plist_new_data(const char *val, uint64_t length);
  233. /**
  234. * Create a new plist_t type #PLIST_DATE
  235. *
  236. * @param sec the number of seconds since 01/01/2001
  237. * @param usec the number of microseconds
  238. * @return the created item
  239. * @sa #plist_type
  240. */
  241. PLIST_API plist_t plist_new_date(int32_t sec, int32_t usec);
  242. /**
  243. * Create a new plist_t type #PLIST_UID
  244. *
  245. * @param val the unsigned integer value
  246. * @return the created item
  247. * @sa #plist_type
  248. */
  249. PLIST_API plist_t plist_new_uid(uint64_t val);
  250. /**
  251. * Create a new plist_t type #PLIST_NULL
  252. * @return the created item
  253. * @sa #plist_type
  254. * @note This type is not valid for all formats, e.g. the XML format
  255. * does not support it.
  256. */
  257. PLIST_API plist_t plist_new_null(void);
  258. /**
  259. * Destruct a plist_t node and all its children recursively
  260. *
  261. * @param plist the plist to free
  262. */
  263. PLIST_API void plist_free(plist_t plist);
  264. /**
  265. * Return a copy of passed node and it's children
  266. *
  267. * @param node the plist to copy
  268. * @return copied plist
  269. */
  270. PLIST_API plist_t plist_copy(plist_t node);
  271. /********************************************
  272. * *
  273. * Array functions *
  274. * *
  275. ********************************************/
  276. /**
  277. * Get size of a #PLIST_ARRAY node.
  278. *
  279. * @param node the node of type #PLIST_ARRAY
  280. * @return size of the #PLIST_ARRAY node
  281. */
  282. PLIST_API uint32_t plist_array_get_size(plist_t node);
  283. /**
  284. * Get the nth item in a #PLIST_ARRAY node.
  285. *
  286. * @param node the node of type #PLIST_ARRAY
  287. * @param n the index of the item to get. Range is [0, array_size[
  288. * @return the nth item or NULL if node is not of type #PLIST_ARRAY
  289. */
  290. PLIST_API plist_t plist_array_get_item(plist_t node, uint32_t n);
  291. /**
  292. * Get the index of an item. item must be a member of a #PLIST_ARRAY node.
  293. *
  294. * @param node the node
  295. * @return the node index or UINT_MAX if node index can't be determined
  296. */
  297. PLIST_API uint32_t plist_array_get_item_index(plist_t node);
  298. /**
  299. * Set the nth item in a #PLIST_ARRAY node.
  300. * The previous item at index n will be freed using #plist_free
  301. *
  302. * @param node the node of type #PLIST_ARRAY
  303. * @param item the new item at index n. The array is responsible for freeing item when it is no longer needed.
  304. * @param n the index of the item to get. Range is [0, array_size[. Assert if n is not in range.
  305. */
  306. PLIST_API void plist_array_set_item(plist_t node, plist_t item, uint32_t n);
  307. /**
  308. * Append a new item at the end of a #PLIST_ARRAY node.
  309. *
  310. * @param node the node of type #PLIST_ARRAY
  311. * @param item the new item. The array is responsible for freeing item when it is no longer needed.
  312. */
  313. PLIST_API void plist_array_append_item(plist_t node, plist_t item);
  314. /**
  315. * Insert a new item at position n in a #PLIST_ARRAY node.
  316. *
  317. * @param node the node of type #PLIST_ARRAY
  318. * @param item the new item to insert. The array is responsible for freeing item when it is no longer needed.
  319. * @param n The position at which the node will be stored. Range is [0, array_size[. Assert if n is not in range.
  320. */
  321. PLIST_API void plist_array_insert_item(plist_t node, plist_t item, uint32_t n);
  322. /**
  323. * Remove an existing position in a #PLIST_ARRAY node.
  324. * Removed position will be freed using #plist_free.
  325. *
  326. * @param node the node of type #PLIST_ARRAY
  327. * @param n The position to remove. Range is [0, array_size[. Assert if n is not in range.
  328. */
  329. PLIST_API void plist_array_remove_item(plist_t node, uint32_t n);
  330. /**
  331. * Remove a node that is a child node of a #PLIST_ARRAY node.
  332. * node will be freed using #plist_free.
  333. *
  334. * @param node The node to be removed from its #PLIST_ARRAY parent.
  335. */
  336. PLIST_API void plist_array_item_remove(plist_t node);
  337. /**
  338. * Create an iterator of a #PLIST_ARRAY node.
  339. * The allocated iterator should be freed with the standard free function.
  340. *
  341. * @param node The node of type #PLIST_ARRAY
  342. * @param iter Location to store the iterator for the array.
  343. */
  344. PLIST_API void plist_array_new_iter(plist_t node, plist_array_iter *iter);
  345. /**
  346. * Increment iterator of a #PLIST_ARRAY node.
  347. *
  348. * @param node The node of type #PLIST_ARRAY.
  349. * @param iter Iterator of the array
  350. * @param item Location to store the item. The caller must *not* free the
  351. * returned item. Will be set to NULL when no more items are left
  352. * to iterate.
  353. */
  354. PLIST_API void plist_array_next_item(plist_t node, plist_array_iter iter, plist_t *item);
  355. /********************************************
  356. * *
  357. * Dictionary functions *
  358. * *
  359. ********************************************/
  360. /**
  361. * Get size of a #PLIST_DICT node.
  362. *
  363. * @param node the node of type #PLIST_DICT
  364. * @return size of the #PLIST_DICT node
  365. */
  366. PLIST_API uint32_t plist_dict_get_size(plist_t node);
  367. /**
  368. * Create an iterator of a #PLIST_DICT node.
  369. * The allocated iterator should be freed with the standard free function.
  370. *
  371. * @param node The node of type #PLIST_DICT.
  372. * @param iter Location to store the iterator for the dictionary.
  373. */
  374. PLIST_API void plist_dict_new_iter(plist_t node, plist_dict_iter *iter);
  375. /**
  376. * Increment iterator of a #PLIST_DICT node.
  377. *
  378. * @param node The node of type #PLIST_DICT
  379. * @param iter Iterator of the dictionary
  380. * @param key Location to store the key, or NULL. The caller is responsible
  381. * for freeing the the returned string.
  382. * @param val Location to store the value, or NULL. The caller must *not*
  383. * free the returned value. Will be set to NULL when no more
  384. * key/value pairs are left to iterate.
  385. */
  386. PLIST_API void plist_dict_next_item(plist_t node, plist_dict_iter iter, char **key, plist_t *val);
  387. /**
  388. * Get key associated key to an item. Item must be member of a dictionary.
  389. *
  390. * @param node the item
  391. * @param key a location to store the key. The caller is responsible for freeing the returned string.
  392. */
  393. PLIST_API void plist_dict_get_item_key(plist_t node, char **key);
  394. /**
  395. * Get the nth item in a #PLIST_DICT node.
  396. *
  397. * @param node the node of type #PLIST_DICT
  398. * @param key the identifier of the item to get.
  399. * @return the item or NULL if node is not of type #PLIST_DICT. The caller should not free
  400. * the returned node.
  401. */
  402. PLIST_API plist_t plist_dict_get_item(plist_t node, const char* key);
  403. /**
  404. * Get key node associated to an item. Item must be member of a dictionary.
  405. *
  406. * @param node the item
  407. * @return the key node of the given item, or NULL.
  408. */
  409. PLIST_API plist_t plist_dict_item_get_key(plist_t node);
  410. /**
  411. * Set item identified by key in a #PLIST_DICT node.
  412. * The previous item identified by key will be freed using #plist_free.
  413. * If there is no item for the given key a new item will be inserted.
  414. *
  415. * @param node the node of type #PLIST_DICT
  416. * @param item the new item associated to key
  417. * @param key the identifier of the item to set.
  418. */
  419. PLIST_API void plist_dict_set_item(plist_t node, const char* key, plist_t item);
  420. /**
  421. * Remove an existing position in a #PLIST_DICT node.
  422. * Removed position will be freed using #plist_free
  423. *
  424. * @param node the node of type #PLIST_DICT
  425. * @param key The identifier of the item to remove. Assert if identifier is not present.
  426. */
  427. PLIST_API void plist_dict_remove_item(plist_t node, const char* key);
  428. /**
  429. * Merge a dictionary into another. This will add all key/value pairs
  430. * from the source dictionary to the target dictionary, overwriting
  431. * any existing key/value pairs that are already present in target.
  432. *
  433. * @param target pointer to an existing node of type #PLIST_DICT
  434. * @param source node of type #PLIST_DICT that should be merged into target
  435. */
  436. PLIST_API void plist_dict_merge(plist_t *target, plist_t source);
  437. /********************************************
  438. * *
  439. * Getters *
  440. * *
  441. ********************************************/
  442. /**
  443. * Get the parent of a node
  444. *
  445. * @param node the parent (NULL if node is root)
  446. */
  447. PLIST_API plist_t plist_get_parent(plist_t node);
  448. /**
  449. * Get the #plist_type of a node.
  450. *
  451. * @param node the node
  452. * @return the type of the node
  453. */
  454. PLIST_API plist_type plist_get_node_type(plist_t node);
  455. /**
  456. * Get the value of a #PLIST_KEY node.
  457. * This function does nothing if node is not of type #PLIST_KEY
  458. *
  459. * @param node the node
  460. * @param val a pointer to a C-string. This function allocates the memory,
  461. * caller is responsible for freeing it.
  462. * @note Use plist_mem_free() to free the allocated memory.
  463. */
  464. PLIST_API void plist_get_key_val(plist_t node, char **val);
  465. /**
  466. * Get the value of a #PLIST_STRING node.
  467. * This function does nothing if node is not of type #PLIST_STRING
  468. *
  469. * @param node the node
  470. * @param val a pointer to a C-string. This function allocates the memory,
  471. * caller is responsible for freeing it. Data is UTF-8 encoded.
  472. * @note Use plist_mem_free() to free the allocated memory.
  473. */
  474. PLIST_API void plist_get_string_val(plist_t node, char **val);
  475. /**
  476. * Get a pointer to the buffer of a #PLIST_STRING node.
  477. *
  478. * @note DO NOT MODIFY the buffer. Mind that the buffer is only available
  479. * until the plist node gets freed. Make a copy if needed.
  480. *
  481. * @param node The node
  482. * @param length If non-NULL, will be set to the length of the string
  483. *
  484. * @return Pointer to the NULL-terminated buffer.
  485. */
  486. PLIST_API const char* plist_get_string_ptr(plist_t node, uint64_t* length);
  487. /**
  488. * Get the value of a #PLIST_BOOLEAN node.
  489. * This function does nothing if node is not of type #PLIST_BOOLEAN
  490. *
  491. * @param node the node
  492. * @param val a pointer to a uint8_t variable.
  493. */
  494. PLIST_API void plist_get_bool_val(plist_t node, uint8_t * val);
  495. /**
  496. * Get the unsigned integer value of a #PLIST_INT node.
  497. * This function does nothing if node is not of type #PLIST_INT
  498. *
  499. * @param node the node
  500. * @param val a pointer to a uint64_t variable.
  501. */
  502. PLIST_API void plist_get_uint_val(plist_t node, uint64_t * val);
  503. /**
  504. * Get the signed integer value of a #PLIST_INT node.
  505. * This function does nothing if node is not of type #PLIST_INT
  506. *
  507. * @param node the node
  508. * @param val a pointer to a int64_t variable.
  509. */
  510. PLIST_API void plist_get_int_val(plist_t node, int64_t * val);
  511. /**
  512. * Get the value of a #PLIST_REAL node.
  513. * This function does nothing if node is not of type #PLIST_REAL
  514. *
  515. * @param node the node
  516. * @param val a pointer to a double variable.
  517. */
  518. PLIST_API void plist_get_real_val(plist_t node, double *val);
  519. /**
  520. * Get the value of a #PLIST_DATA node.
  521. * This function does nothing if node is not of type #PLIST_DATA
  522. *
  523. * @param node the node
  524. * @param val a pointer to an unallocated char buffer. This function allocates the memory,
  525. * caller is responsible for freeing it.
  526. * @param length the length of the buffer
  527. * @note Use plist_mem_free() to free the allocated memory.
  528. */
  529. PLIST_API void plist_get_data_val(plist_t node, char **val, uint64_t * length);
  530. /**
  531. * Get a pointer to the data buffer of a #PLIST_DATA node.
  532. *
  533. * @note DO NOT MODIFY the buffer. Mind that the buffer is only available
  534. * until the plist node gets freed. Make a copy if needed.
  535. *
  536. * @param node The node
  537. * @param length Pointer to a uint64_t that will be set to the length of the buffer
  538. *
  539. * @return Pointer to the buffer
  540. */
  541. PLIST_API const char* plist_get_data_ptr(plist_t node, uint64_t* length);
  542. /**
  543. * Get the value of a #PLIST_DATE node.
  544. * This function does nothing if node is not of type #PLIST_DATE
  545. *
  546. * @param node the node
  547. * @param sec a pointer to an int32_t variable. Represents the number of seconds since 01/01/2001.
  548. * @param usec a pointer to an int32_t variable. Represents the number of microseconds
  549. */
  550. PLIST_API void plist_get_date_val(plist_t node, int32_t * sec, int32_t * usec);
  551. /**
  552. * Get the value of a #PLIST_UID node.
  553. * This function does nothing if node is not of type #PLIST_UID
  554. *
  555. * @param node the node
  556. * @param val a pointer to a uint64_t variable.
  557. */
  558. PLIST_API void plist_get_uid_val(plist_t node, uint64_t * val);
  559. /********************************************
  560. * *
  561. * Setters *
  562. * *
  563. ********************************************/
  564. /**
  565. * Set the value of a node.
  566. * Forces type of node to #PLIST_KEY
  567. *
  568. * @param node the node
  569. * @param val the key value
  570. */
  571. PLIST_API void plist_set_key_val(plist_t node, const char *val);
  572. /**
  573. * Set the value of a node.
  574. * Forces type of node to #PLIST_STRING
  575. *
  576. * @param node the node
  577. * @param val the string value. The string is copied when set and will be
  578. * freed by the node.
  579. */
  580. PLIST_API void plist_set_string_val(plist_t node, const char *val);
  581. /**
  582. * Set the value of a node.
  583. * Forces type of node to #PLIST_BOOLEAN
  584. *
  585. * @param node the node
  586. * @param val the boolean value
  587. */
  588. PLIST_API void plist_set_bool_val(plist_t node, uint8_t val);
  589. /**
  590. * Set the value of a node.
  591. * Forces type of node to #PLIST_INT
  592. *
  593. * @param node the node
  594. * @param val the unsigned integer value
  595. */
  596. PLIST_API void plist_set_uint_val(plist_t node, uint64_t val);
  597. /**
  598. * Set the value of a node.
  599. * Forces type of node to #PLIST_INT
  600. *
  601. * @param node the node
  602. * @param val the signed integer value
  603. */
  604. PLIST_API void plist_set_int_val(plist_t node, int64_t val);
  605. /**
  606. * Set the value of a node.
  607. * Forces type of node to #PLIST_REAL
  608. *
  609. * @param node the node
  610. * @param val the real value
  611. */
  612. PLIST_API void plist_set_real_val(plist_t node, double val);
  613. /**
  614. * Set the value of a node.
  615. * Forces type of node to #PLIST_DATA
  616. *
  617. * @param node the node
  618. * @param val the binary buffer. The buffer is copied when set and will
  619. * be freed by the node.
  620. * @param length the length of the buffer
  621. */
  622. PLIST_API void plist_set_data_val(plist_t node, const char *val, uint64_t length);
  623. /**
  624. * Set the value of a node.
  625. * Forces type of node to #PLIST_DATE
  626. *
  627. * @param node the node
  628. * @param sec the number of seconds since 01/01/2001
  629. * @param usec the number of microseconds
  630. */
  631. PLIST_API void plist_set_date_val(plist_t node, int32_t sec, int32_t usec);
  632. /**
  633. * Set the value of a node.
  634. * Forces type of node to #PLIST_UID
  635. *
  636. * @param node the node
  637. * @param val the unsigned integer value
  638. */
  639. PLIST_API void plist_set_uid_val(plist_t node, uint64_t val);
  640. /********************************************
  641. * *
  642. * Import & Export *
  643. * *
  644. ********************************************/
  645. /**
  646. * Export the #plist_t structure to XML format.
  647. *
  648. * @param plist the root node to export
  649. * @param plist_xml a pointer to a C-string. This function allocates the memory,
  650. * caller is responsible for freeing it. Data is UTF-8 encoded.
  651. * @param length a pointer to an uint32_t variable. Represents the length of the allocated buffer.
  652. * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure
  653. * @note Use plist_mem_free() to free the allocated memory.
  654. */
  655. PLIST_API plist_err_t plist_to_xml(plist_t plist, char **plist_xml, uint32_t * length);
  656. /**
  657. * Export the #plist_t structure to binary format.
  658. *
  659. * @param plist the root node to export
  660. * @param plist_bin a pointer to a char* buffer. This function allocates the memory,
  661. * caller is responsible for freeing it.
  662. * @param length a pointer to an uint32_t variable. Represents the length of the allocated buffer.
  663. * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure
  664. * @note Use plist_mem_free() to free the allocated memory.
  665. */
  666. PLIST_API plist_err_t plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length);
  667. /**
  668. * Export the #plist_t structure to JSON format.
  669. *
  670. * @param plist the root node to export
  671. * @param plist_json a pointer to a char* buffer. This function allocates the memory,
  672. * caller is responsible for freeing it.
  673. * @param length a pointer to an uint32_t variable. Represents the length of the allocated buffer.
  674. * @param prettify pretty print the output if != 0
  675. * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure
  676. * @note Use plist_mem_free() to free the allocated memory.
  677. */
  678. PLIST_API plist_err_t plist_to_json(plist_t plist, char **plist_json, uint32_t* length, int prettify);
  679. /**
  680. * Export the #plist_t structure to OpenStep format.
  681. *
  682. * @param plist the root node to export
  683. * @param plist_openstep a pointer to a char* buffer. This function allocates the memory,
  684. * caller is responsible for freeing it.
  685. * @param length a pointer to an uint32_t variable. Represents the length of the allocated buffer.
  686. * @param prettify pretty print the output if != 0
  687. * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure
  688. * @note Use plist_mem_free() to free the allocated memory.
  689. */
  690. PLIST_API plist_err_t plist_to_openstep(plist_t plist, char **plist_openstep, uint32_t* length, int prettify);
  691. /**
  692. * Import the #plist_t structure from XML format.
  693. *
  694. * @param plist_xml a pointer to the xml buffer.
  695. * @param length length of the buffer to read.
  696. * @param plist a pointer to the imported plist.
  697. * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure
  698. */
  699. PLIST_API plist_err_t plist_from_xml(const char *plist_xml, uint32_t length, plist_t * plist);
  700. /**
  701. * Import the #plist_t structure from binary format.
  702. *
  703. * @param plist_bin a pointer to the xml buffer.
  704. * @param length length of the buffer to read.
  705. * @param plist a pointer to the imported plist.
  706. * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure
  707. */
  708. PLIST_API plist_err_t plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist);
  709. /**
  710. * Import the #plist_t structure from JSON format.
  711. *
  712. * @param json a pointer to the JSON buffer.
  713. * @param length length of the buffer to read.
  714. * @param plist a pointer to the imported plist.
  715. * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure
  716. */
  717. PLIST_API plist_err_t plist_from_json(const char *json, uint32_t length, plist_t * plist);
  718. /**
  719. * Import the #plist_t structure from OpenStep plist format.
  720. *
  721. * @param openstep a pointer to the OpenStep plist buffer.
  722. * @param length length of the buffer to read.
  723. * @param plist a pointer to the imported plist.
  724. * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure
  725. */
  726. PLIST_API plist_err_t plist_from_openstep(const char *openstep, uint32_t length, plist_t * plist);
  727. /**
  728. * Import the #plist_t structure from memory data.
  729. *
  730. * This function will look at the first bytes of plist_data
  731. * to determine if plist_data contains a binary, JSON, OpenStep, or XML plist
  732. * and tries to parse the data in the appropriate format.
  733. * @note This is just a convenience function and the format detection is
  734. * very basic. It checks with plist_is_binary() if the data supposedly
  735. * contains binary plist data, if not it checks if the first bytes have
  736. * either '{' or '[' and assumes JSON format, and XML tags will result
  737. * in parsing as XML, otherwise it will try to parse as OpenStep.
  738. *
  739. * @param plist_data A pointer to the memory buffer containing plist data.
  740. * @param length Length of the buffer to read.
  741. * @param plist A pointer to the imported plist.
  742. * @param format If non-NULL, the #plist_format_t value pointed to will be set to the parsed format.
  743. * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure
  744. */
  745. PLIST_API plist_err_t plist_from_memory(const char *plist_data, uint32_t length, plist_t *plist, plist_format_t *format);
  746. /**
  747. * Import the #plist_t structure directly from file.
  748. *
  749. * This function will look at the first bytes of the file data
  750. * to determine if it contains a binary, JSON, OpenStep, or XML plist
  751. * and tries to parse the data in the appropriate format.
  752. * Uses plist_from_memory() internally.
  753. *
  754. * @param filename The name of the file to parse.
  755. * @param plist A pointer to the imported plist.
  756. * @param format If non-NULL, the #plist_format_t value pointed to will be set to the parsed format.
  757. * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure
  758. */
  759. PLIST_API plist_err_t plist_read_from_file(const char *filename, plist_t *plist, plist_format_t *format);
  760. /**
  761. * Write the #plist_t structure to a NULL-terminated string using the given format and options.
  762. *
  763. * @param plist The input plist structure
  764. * @param output Pointer to a char* buffer. This function allocates the memory,
  765. * caller is responsible for freeing it.
  766. * @param length A pointer to a uint32_t value that will receive the lenght of the allocated buffer.
  767. * @param format A #plist_format_t value that specifies the output format to use.
  768. * @param options One or more bitwise ORed values of #plist_write_options_t.
  769. * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure.
  770. * @note Use plist_mem_free() to free the allocated memory.
  771. * @note #PLIST_FORMAT_BINARY is not supported by this function.
  772. */
  773. PLIST_API plist_err_t plist_write_to_string(plist_t plist, char **output, uint32_t* length, plist_format_t format, plist_write_options_t options);
  774. /**
  775. * Write the #plist_t structure to a FILE* stream using the given format and options.
  776. *
  777. * @param plist The input plist structure
  778. * @param stream A writeable FILE* stream that the data will be written to.
  779. * @param format A #plist_format_t value that specifies the output format to use.
  780. * @param options One or more bitwise ORed values of #plist_write_options_t.
  781. * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure.
  782. * @note While this function allows all formats to be written to the given stream,
  783. * only the formats #PLIST_FORMAT_PRINT, #PLIST_FORMAT_LIMD, and #PLIST_FORMAT_PLUTIL
  784. * (basically all output-only formats) are directly and efficiently written to the stream;
  785. * the other formats are written to a memory buffer first.
  786. */
  787. PLIST_API plist_err_t plist_write_to_stream(plist_t plist, FILE* stream, plist_format_t format, plist_write_options_t options);
  788. /**
  789. * Write the #plist_t structure to a file at given path using the given format and options.
  790. *
  791. * @param plist The input plist structure
  792. * @param filename The file name of the file to write to. Existing files will be overwritten.
  793. * @param format A #plist_format_t value that specifies the output format to use.
  794. * @param options One or more bitwise ORed values of #plist_write_options_t.
  795. * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure.
  796. * @note Use plist_mem_free() to free the allocated memory.
  797. */
  798. PLIST_API plist_err_t plist_write_to_file(plist_t plist, const char *filename, plist_format_t format, plist_write_options_t options);
  799. /**
  800. * Print the given plist in human-readable format to standard output.
  801. * This is equivalent to
  802. * <code>plist_write_to_stream(plist, stdout, PLIST_FORMAT_PRINT, PLIST_OPT_PARTIAL_DATA);</code>
  803. * @param plist The #plist_t structure to print
  804. * @note For #PLIST_DATA nodes, only a maximum of 24 bytes (first 16 and last 8) are written.
  805. */
  806. PLIST_API void plist_print(plist_t plist);
  807. /**
  808. * Test if in-memory plist data is in binary format.
  809. * This function will look at the first bytes of plist_data to determine
  810. * if it supposedly contains a binary plist.
  811. * @note The function is not validating the whole memory buffer to check
  812. * if the content is truly a plist, it is only using some heuristic on
  813. * the first few bytes of plist_data.
  814. *
  815. * @param plist_data a pointer to the memory buffer containing plist data.
  816. * @param length length of the buffer to read.
  817. * @return 1 if the buffer is a binary plist, 0 otherwise.
  818. */
  819. PLIST_API int plist_is_binary(const char *plist_data, uint32_t length);
  820. /********************************************
  821. * *
  822. * Utils *
  823. * *
  824. ********************************************/
  825. /**
  826. * Get a node from its path. Each path element depends on the associated father node type.
  827. * For Dictionaries, var args are casted to const char*, for arrays, var args are caster to uint32_t
  828. * Search is breath first order.
  829. *
  830. * @param plist the node to access result from.
  831. * @param length length of the path to access
  832. * @return the value to access.
  833. */
  834. PLIST_API plist_t plist_access_path(plist_t plist, uint32_t length, ...);
  835. /**
  836. * Variadic version of #plist_access_path.
  837. *
  838. * @param plist the node to access result from.
  839. * @param length length of the path to access
  840. * @param v list of array's index and dic'st key
  841. * @return the value to access.
  842. */
  843. PLIST_API plist_t plist_access_pathv(plist_t plist, uint32_t length, va_list v);
  844. /**
  845. * Compare two node values
  846. *
  847. * @param node_l left node to compare
  848. * @param node_r rigth node to compare
  849. * @return TRUE is type and value match, FALSE otherwise.
  850. */
  851. PLIST_API char plist_compare_node_value(plist_t node_l, plist_t node_r);
  852. /** Helper macro used by PLIST_IS_* macros that will evaluate the type of a plist node. */
  853. #define _PLIST_IS_TYPE(__plist, __plist_type) (__plist && (plist_get_node_type(__plist) == PLIST_##__plist_type))
  854. /* Helper macros for the different plist types */
  855. /** Evaluates to true if the given plist node is of type PLIST_BOOLEAN */
  856. #define PLIST_IS_BOOLEAN(__plist) _PLIST_IS_TYPE(__plist, BOOLEAN)
  857. /** Evaluates to true if the given plist node is of type PLIST_INT */
  858. #define PLIST_IS_INT(__plist) _PLIST_IS_TYPE(__plist, INT)
  859. /** Evaluates to true if the given plist node is of type PLIST_REAL */
  860. #define PLIST_IS_REAL(__plist) _PLIST_IS_TYPE(__plist, REAL)
  861. /** Evaluates to true if the given plist node is of type PLIST_STRING */
  862. #define PLIST_IS_STRING(__plist) _PLIST_IS_TYPE(__plist, STRING)
  863. /** Evaluates to true if the given plist node is of type PLIST_ARRAY */
  864. #define PLIST_IS_ARRAY(__plist) _PLIST_IS_TYPE(__plist, ARRAY)
  865. /** Evaluates to true if the given plist node is of type PLIST_DICT */
  866. #define PLIST_IS_DICT(__plist) _PLIST_IS_TYPE(__plist, DICT)
  867. /** Evaluates to true if the given plist node is of type PLIST_DATE */
  868. #define PLIST_IS_DATE(__plist) _PLIST_IS_TYPE(__plist, DATE)
  869. /** Evaluates to true if the given plist node is of type PLIST_DATA */
  870. #define PLIST_IS_DATA(__plist) _PLIST_IS_TYPE(__plist, DATA)
  871. /** Evaluates to true if the given plist node is of type PLIST_KEY */
  872. #define PLIST_IS_KEY(__plist) _PLIST_IS_TYPE(__plist, KEY)
  873. /** Evaluates to true if the given plist node is of type PLIST_UID */
  874. #define PLIST_IS_UID(__plist) _PLIST_IS_TYPE(__plist, UID)
  875. /* for backwards compatibility */
  876. #define PLIST_IS_UINT PLIST_IS_INT
  877. /**
  878. * Helper function to check the value of a PLIST_BOOL node.
  879. *
  880. * @param boolnode node of type PLIST_BOOL
  881. * @return 1 if the boolean node has a value of TRUE or 0 if FALSE.
  882. */
  883. PLIST_API int plist_bool_val_is_true(plist_t boolnode);
  884. /**
  885. * Helper function to test if a given #PLIST_INT node's value is negative
  886. *
  887. * @param intnode node of type PLIST_INT
  888. * @return 1 if the node's value is negative, or 0 if positive.
  889. */
  890. PLIST_API int plist_int_val_is_negative(plist_t intnode);
  891. /**
  892. * Helper function to compare the value of a PLIST_INT node against
  893. * a given signed integer value.
  894. *
  895. * @param uintnode node of type PLIST_INT
  896. * @param cmpval value to compare against
  897. * @return 0 if the node's value and cmpval are equal,
  898. * 1 if the node's value is greater than cmpval,
  899. * or -1 if the node's value is less than cmpval.
  900. */
  901. PLIST_API int plist_int_val_compare(plist_t uintnode, int64_t cmpval);
  902. /**
  903. * Helper function to compare the value of a PLIST_INT node against
  904. * a given unsigned integer value.
  905. *
  906. * @param uintnode node of type PLIST_INT
  907. * @param cmpval value to compare against
  908. * @return 0 if the node's value and cmpval are equal,
  909. * 1 if the node's value is greater than cmpval,
  910. * or -1 if the node's value is less than cmpval.
  911. */
  912. PLIST_API int plist_uint_val_compare(plist_t uintnode, uint64_t cmpval);
  913. /**
  914. * Helper function to compare the value of a PLIST_UID node against
  915. * a given value.
  916. *
  917. * @param uidnode node of type PLIST_UID
  918. * @param cmpval value to compare against
  919. * @return 0 if the node's value and cmpval are equal,
  920. * 1 if the node's value is greater than cmpval,
  921. * or -1 if the node's value is less than cmpval.
  922. */
  923. PLIST_API int plist_uid_val_compare(plist_t uidnode, uint64_t cmpval);
  924. /**
  925. * Helper function to compare the value of a PLIST_REAL node against
  926. * a given value.
  927. *
  928. * @note WARNING: Comparing floating point values can give inaccurate
  929. * results because of the nature of floating point values on computer
  930. * systems. While this function is designed to be as accurate as
  931. * possible, please don't rely on it too much.
  932. *
  933. * @param realnode node of type PLIST_REAL
  934. * @param cmpval value to compare against
  935. * @return 0 if the node's value and cmpval are (almost) equal,
  936. * 1 if the node's value is greater than cmpval,
  937. * or -1 if the node's value is less than cmpval.
  938. */
  939. PLIST_API int plist_real_val_compare(plist_t realnode, double cmpval);
  940. /**
  941. * Helper function to compare the value of a PLIST_DATE node against
  942. * a given set of seconds and fraction of a second since epoch.
  943. *
  944. * @param datenode node of type PLIST_DATE
  945. * @param cmpsec number of seconds since epoch to compare against
  946. * @param cmpusec fraction of a second in microseconds to compare against
  947. * @return 0 if the node's date is equal to the supplied values,
  948. * 1 if the node's date is greater than the supplied values,
  949. * or -1 if the node's date is less than the supplied values.
  950. */
  951. PLIST_API int plist_date_val_compare(plist_t datenode, int32_t cmpsec, int32_t cmpusec);
  952. /**
  953. * Helper function to compare the value of a PLIST_STRING node against
  954. * a given value.
  955. * This function basically behaves like strcmp.
  956. *
  957. * @param strnode node of type PLIST_STRING
  958. * @param cmpval value to compare against
  959. * @return 0 if the node's value and cmpval are equal,
  960. * > 0 if the node's value is lexicographically greater than cmpval,
  961. * or < 0 if the node's value is lexicographically less than cmpval.
  962. */
  963. PLIST_API int plist_string_val_compare(plist_t strnode, const char* cmpval);
  964. /**
  965. * Helper function to compare the value of a PLIST_STRING node against
  966. * a given value, while not comparing more than n characters.
  967. * This function basically behaves like strncmp.
  968. *
  969. * @param strnode node of type PLIST_STRING
  970. * @param cmpval value to compare against
  971. * @param n maximum number of characters to compare
  972. * @return 0 if the node's value and cmpval are equal,
  973. * > 0 if the node's value is lexicographically greater than cmpval,
  974. * or < 0 if the node's value is lexicographically less than cmpval.
  975. */
  976. PLIST_API int plist_string_val_compare_with_size(plist_t strnode, const char* cmpval, size_t n);
  977. /**
  978. * Helper function to match a given substring in the value of a
  979. * PLIST_STRING node.
  980. *
  981. * @param strnode node of type PLIST_STRING
  982. * @param substr value to match
  983. * @return 1 if the node's value contains the given substring,
  984. * or 0 if not.
  985. */
  986. PLIST_API int plist_string_val_contains(plist_t strnode, const char* substr);
  987. /**
  988. * Helper function to compare the value of a PLIST_KEY node against
  989. * a given value.
  990. * This function basically behaves like strcmp.
  991. *
  992. * @param keynode node of type PLIST_KEY
  993. * @param cmpval value to compare against
  994. * @return 0 if the node's value and cmpval are equal,
  995. * > 0 if the node's value is lexicographically greater than cmpval,
  996. * or < 0 if the node's value is lexicographically less than cmpval.
  997. */
  998. PLIST_API int plist_key_val_compare(plist_t keynode, const char* cmpval);
  999. /**
  1000. * Helper function to compare the value of a PLIST_KEY node against
  1001. * a given value, while not comparing more than n characters.
  1002. * This function basically behaves like strncmp.
  1003. *
  1004. * @param keynode node of type PLIST_KEY
  1005. * @param cmpval value to compare against
  1006. * @param n maximum number of characters to compare
  1007. * @return 0 if the node's value and cmpval are equal,
  1008. * > 0 if the node's value is lexicographically greater than cmpval,
  1009. * or < 0 if the node's value is lexicographically less than cmpval.
  1010. */
  1011. PLIST_API int plist_key_val_compare_with_size(plist_t keynode, const char* cmpval, size_t n);
  1012. /**
  1013. * Helper function to match a given substring in the value of a
  1014. * PLIST_KEY node.
  1015. *
  1016. * @param keynode node of type PLIST_KEY
  1017. * @param substr value to match
  1018. * @return 1 if the node's value contains the given substring,
  1019. * or 0 if not.
  1020. */
  1021. PLIST_API int plist_key_val_contains(plist_t keynode, const char* substr);
  1022. /**
  1023. * Helper function to compare the data of a PLIST_DATA node against
  1024. * a given blob and size.
  1025. * This function basically behaves like memcmp after making sure the
  1026. * size of the node's data value is equal to the size of cmpval (n),
  1027. * making this a "full match" comparison.
  1028. *
  1029. * @param datanode node of type PLIST_DATA
  1030. * @param cmpval data blob to compare against
  1031. * @param n size of data blob passed in cmpval
  1032. * @return 0 if the node's data blob and cmpval are equal,
  1033. * > 0 if the node's value is lexicographically greater than cmpval,
  1034. * or < 0 if the node's value is lexicographically less than cmpval.
  1035. */
  1036. PLIST_API int plist_data_val_compare(plist_t datanode, const uint8_t* cmpval, size_t n);
  1037. /**
  1038. * Helper function to compare the data of a PLIST_DATA node against
  1039. * a given blob and size, while no more than n bytes are compared.
  1040. * This function basically behaves like memcmp after making sure the
  1041. * size of the node's data value is at least n, making this a
  1042. * "starts with" comparison.
  1043. *
  1044. * @param datanode node of type PLIST_DATA
  1045. * @param cmpval data blob to compare against
  1046. * @param n size of data blob passed in cmpval
  1047. * @return 0 if the node's value and cmpval are equal,
  1048. * > 0 if the node's value is lexicographically greater than cmpval,
  1049. * or < 0 if the node's value is lexicographically less than cmpval.
  1050. */
  1051. PLIST_API int plist_data_val_compare_with_size(plist_t datanode, const uint8_t* cmpval, size_t n);
  1052. /**
  1053. * Helper function to match a given data blob within the value of a
  1054. * PLIST_DATA node.
  1055. *
  1056. * @param datanode node of type PLIST_KEY
  1057. * @param cmpval data blob to match
  1058. * @param n size of data blob passed in cmpval
  1059. * @return 1 if the node's value contains the given data blob
  1060. * or 0 if not.
  1061. */
  1062. PLIST_API int plist_data_val_contains(plist_t datanode, const uint8_t* cmpval, size_t n);
  1063. /**
  1064. * Sort all PLIST_DICT key/value pairs in a property list lexicographically
  1065. * by key. Recurses into the child nodes if necessary.
  1066. *
  1067. * @param plist The property list to perform the sorting operation on.
  1068. */
  1069. PLIST_API void plist_sort(plist_t plist);
  1070. /**
  1071. * Free memory allocated by relevant libplist API calls:
  1072. * - plist_to_xml()
  1073. * - plist_to_bin()
  1074. * - plist_get_key_val()
  1075. * - plist_get_string_val()
  1076. * - plist_get_data_val()
  1077. *
  1078. * @param ptr pointer to the memory to free
  1079. *
  1080. * @note Do not use this function to free plist_t nodes, use plist_free()
  1081. * instead.
  1082. */
  1083. PLIST_API void plist_mem_free(void* ptr);
  1084. /**
  1085. * Set debug level for the format parsers.
  1086. * @note This function does nothing if libplist was not configured with --enable-debug .
  1087. *
  1088. * @param debug Debug level. Currently, only 0 (off) and 1 (enabled) are supported.
  1089. */
  1090. PLIST_API void plist_set_debug(int debug);
  1091. /**
  1092. * Returns a static string of the libplist version.
  1093. *
  1094. * @return The libplist version as static ascii string
  1095. */
  1096. PLIST_API const char* libplist_version();
  1097. /*@}*/
  1098. #ifdef __cplusplus
  1099. }
  1100. #endif
  1101. #endif