summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2021-12-23 03:09:07 +0100
committerGravatar Nikias Bassen2021-12-23 03:09:07 +0100
commit429cbc660ae14d4998715803b44c71abf0e4a339 (patch)
tree12fe08f5dcb00a380536198bac3fffd4eb7dd19b /include
parent70002721443dabaa99b56301b537980e137b6249 (diff)
downloadlibplist-429cbc660ae14d4998715803b44c71abf0e4a339.tar.gz
libplist-429cbc660ae14d4998715803b44c71abf0e4a339.tar.bz2
Add support for JSON format
Diffstat (limited to 'include')
-rw-r--r--include/plist/plist.h43
1 files changed, 36 insertions, 7 deletions
diff --git a/include/plist/plist.h b/include/plist/plist.h
index 21fd8bd..ac15568 100644
--- a/include/plist/plist.h
+++ b/include/plist/plist.h
@@ -682,6 +682,19 @@ extern "C"
682 plist_err_t plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length); 682 plist_err_t plist_to_bin(plist_t plist, char **plist_bin, uint32_t * length);
683 683
684 /** 684 /**
685 * Export the #plist_t structure to JSON format.
686 *
687 * @param plist the root node to export
688 * @param json a pointer to a char* buffer. This function allocates the memory,
689 * caller is responsible for freeing it.
690 * @param length a pointer to an uint32_t variable. Represents the length of the allocated buffer.
691 * @param prettify pretty print the output if != 0
692 * @return PLIST_ERR_SUCCESS on success or a #plist_error on failure
693 * @note Use plist_mem_free() to free the allocated memory.
694 */
695 plist_err_t plist_to_json(plist_t plist, char **plist_json, uint32_t* length, int prettify);
696
697 /**
685 * Import the #plist_t structure from XML format. 698 * Import the #plist_t structure from XML format.
686 * 699 *
687 * @param plist_xml a pointer to the xml buffer. 700 * @param plist_xml a pointer to the xml buffer.
@@ -702,9 +715,25 @@ extern "C"
702 plist_err_t plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist); 715 plist_err_t plist_from_bin(const char *plist_bin, uint32_t length, plist_t * plist);
703 716
704 /** 717 /**
718 * Import the #plist_t structure from JSON format.
719 *
720 * @param json a pointer to the JSON buffer.
721 * @param length length of the buffer to read.
722 * @param plist a pointer to the imported plist.
723 * @return PLIST_ERR_SUCCESS on success or a #plist_error on failure
724 */
725 plist_err_t plist_from_json(const char *json, uint32_t length, plist_t * plist);
726
727 /**
705 * Import the #plist_t structure from memory data. 728 * Import the #plist_t structure from memory data.
706 * This method will look at the first bytes of plist_data 729 * This method will look at the first bytes of plist_data
707 * to determine if plist_data contains a binary or XML plist. 730 * to determine if plist_data contains a binary, JSON, or XML plist
731 * and tries to parse the data in the appropriate format.
732 * @note This is just a convenience function and the format detection is
733 * very basic. It checks with plist_is_binary() if the data supposedly
734 * contains binary plist data, if not it checks if the first byte is
735 * either '{' or '[' and assumes JSON format, otherwise it will try
736 * to parse the data as XML.
708 * 737 *
709 * @param plist_data a pointer to the memory buffer containing plist data. 738 * @param plist_data a pointer to the memory buffer containing plist data.
710 * @param length length of the buffer to read. 739 * @param length length of the buffer to read.
@@ -714,12 +743,12 @@ extern "C"
714 plist_err_t plist_from_memory(const char *plist_data, uint32_t length, plist_t * plist); 743 plist_err_t plist_from_memory(const char *plist_data, uint32_t length, plist_t * plist);
715 744
716 /** 745 /**
717 * Test if in-memory plist data is binary or XML 746 * Test if in-memory plist data is in binary format.
718 * This method will look at the first bytes of plist_data 747 * This function will look at the first bytes of plist_data to determine
719 * to determine if plist_data contains a binary or XML plist. 748 * if it supposedly contains a binary plist.
720 * This method is not validating the whole memory buffer to check if the 749 * @note The function is not validating the whole memory buffer to check
721 * content is truly a plist, it's only using some heuristic on the first few 750 * if the content is truly a plist, it is only using some heuristic on
722 * bytes of plist_data. 751 * the first few bytes of plist_data.
723 * 752 *
724 * @param plist_data a pointer to the memory buffer containing plist data. 753 * @param plist_data a pointer to the memory buffer containing plist data.
725 * @param length length of the buffer to read. 754 * @param length length of the buffer to read.