diff options
| author | 2026-02-21 10:39:24 -0300 | |
|---|---|---|
| committer | 2026-03-20 17:12:47 +0100 | |
| commit | 3edac28498d883f1f768699ee15ce85a82bb2a7b (patch) | |
| tree | b350517a84a671fc500d943168f973e7c97aa93e /include | |
| parent | 6e03a1df6d1aa87c8f9e2b35f1a2ca60feca1c0e (diff) | |
| download | libplist-3edac28498d883f1f768699ee15ce85a82bb2a7b.tar.gz libplist-3edac28498d883f1f768699ee15ce85a82bb2a7b.tar.bz2 | |
- Add PLIST_OPT_COERCE option to coerce PLIST_DATE, PLIST_DATA, and PLIST_UID to JSON-compatible types (ISO 8601 strings, Base64 strings, and integers)
- Add plist_to_json_with_options() function to allow passing coercion options (and others)
- Update plist_write_to_string() and plist_write_to_stream() to support coercion option
- Add --coerce flag to plistutil for JSON output
- Create plist2json symlink that automatically enables coercion when invoked
Diffstat (limited to 'include')
| -rw-r--r-- | include/plist/plist.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/include/plist/plist.h b/include/plist/plist.h index b46b9a9..bd35c53 100644 --- a/include/plist/plist.h +++ b/include/plist/plist.h @@ -175,6 +175,11 @@ extern "C" 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. */ 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. */ 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. */ + PLIST_OPT_COERCE = 1 << 4, /**< Coerce plist types that have no native JSON representation into JSON-compatible types. + #PLIST_DATE is converted to an ISO 8601 date string, + #PLIST_DATA is converted to a Base64-encoded string, and + #PLIST_UID is converted to an integer. + Only valid for #PLIST_FORMAT_JSON. Without this option, these types cause #PLIST_ERR_FORMAT. */ } plist_write_options_t; /** To be used with #PLIST_OPT_INDENT - encodes the level of indentation for OR'ing it into the #plist_write_options_t bitfield. */ @@ -938,6 +943,29 @@ extern "C" PLIST_API plist_err_t plist_to_json(plist_t plist, char **plist_json, uint32_t* length, int prettify); /** + * Export the #plist_t structure to JSON format with extended options. + * + * When \a PLIST_OPT_COMPACT is set in \a options, the resulting JSON + * will be non-prettified. + * + * When \a PLIST_OPT_COERCE is set in \a options, plist types that have + * no native JSON representation are converted to JSON-compatible types + * instead of returning #PLIST_ERR_FORMAT: + * - #PLIST_DATE is serialized as an ISO 8601 date string + * - #PLIST_DATA is serialized as a Base64-encoded string + * - #PLIST_UID is serialized as an integer + * + * @param plist the root node to export + * @param plist_json 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. + * @param options One or more bitwise ORed values of #plist_write_options_t. + * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure + * @note Use plist_mem_free() to free the allocated memory. + */ + PLIST_API plist_err_t plist_to_json_with_options(plist_t plist, char **plist_json, uint32_t* length, plist_write_options_t options); + + /** * Export the #plist_t structure to OpenStep format. * * @param plist the root node to export |
