summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2023-04-16 16:06:11 +0200
committerGravatar Nikias Bassen2023-04-16 16:06:11 +0200
commit3aa5f6a3a663a5f2694ec6fc8cdf9744b616e15e (patch)
tree9b071b9f041f80ab36a240b226af642cc0c19031 /include
parentbfc97788f081584ced9cd35d85b69b3fec6b907c (diff)
downloadlibplist-3aa5f6a3a663a5f2694ec6fc8cdf9744b616e15e.tar.gz
libplist-3aa5f6a3a663a5f2694ec6fc8cdf9744b616e15e.tar.bz2
Add new output-only formats and Define constants for the different plist formats
This commit introduces constants for the different plist formats, and adds 3 new human-readable output-only formats: - PLIST_FORMAT_PRINT: the default human-readable format - PLIST_FORMAT_LIMD: "libimobiledevice" format (used in ideviceinfo) - PLIST_FORMAT_PLUTIL: plutil-style format Also, a new set of write functions has been added: - plist_write_to_string - plist_write_to_stream - plist_write_to_file Plus a simple "dump" function: - plist_print See documentation for details.
Diffstat (limited to 'include')
-rw-r--r--include/plist/plist.h99
1 files changed, 91 insertions, 8 deletions
diff --git a/include/plist/plist.h b/include/plist/plist.h
index 2e04b1d..b635996 100644
--- a/include/plist/plist.h
+++ b/include/plist/plist.h
@@ -75,6 +75,7 @@ extern "C"
75 75
76#include <sys/types.h> 76#include <sys/types.h>
77#include <stdarg.h> 77#include <stdarg.h>
78#include <stdio.h>
78 79
79 /** 80 /**
80 * \mainpage libplist : A library to handle Apple Property Lists 81 * \mainpage libplist : A library to handle Apple Property Lists
@@ -103,6 +104,7 @@ extern "C"
103 */ 104 */
104 typedef enum 105 typedef enum
105 { 106 {
107 PLIST_NONE =-1, /**< No type */
106 PLIST_BOOLEAN, /**< Boolean, scalar type */ 108 PLIST_BOOLEAN, /**< Boolean, scalar type */
107 PLIST_INT, /**< Integer, scalar type */ 109 PLIST_INT, /**< Integer, scalar type */
108 PLIST_REAL, /**< Real, scalar type */ 110 PLIST_REAL, /**< Real, scalar type */
@@ -114,7 +116,6 @@ extern "C"
114 PLIST_KEY, /**< Key in dictionaries (ASCII String), scalar type */ 116 PLIST_KEY, /**< Key in dictionaries (ASCII String), scalar type */
115 PLIST_UID, /**< Special type used for 'keyed encoding' */ 117 PLIST_UID, /**< Special type used for 'keyed encoding' */
116 PLIST_NULL, /**< NULL type */ 118 PLIST_NULL, /**< NULL type */
117 PLIST_NONE /**< No type */
118 } plist_type; 119 } plist_type;
119 120
120 /* for backwards compatibility */ 121 /* for backwards compatibility */
@@ -130,9 +131,40 @@ extern "C"
130 PLIST_ERR_FORMAT = -2, /**< the plist contains nodes not compatible with the output format */ 131 PLIST_ERR_FORMAT = -2, /**< the plist contains nodes not compatible with the output format */
131 PLIST_ERR_PARSE = -3, /**< parsing of the input format failed */ 132 PLIST_ERR_PARSE = -3, /**< parsing of the input format failed */
132 PLIST_ERR_NO_MEM = -4, /**< not enough memory to handle the operation */ 133 PLIST_ERR_NO_MEM = -4, /**< not enough memory to handle the operation */
134 PLIST_ERR_IO = -5, /**< I/O error */
133 PLIST_ERR_UNKNOWN = -255 /**< an unspecified error occurred */ 135 PLIST_ERR_UNKNOWN = -255 /**< an unspecified error occurred */
134 } plist_err_t; 136 } plist_err_t;
135 137
138 /**
139 * libplist format types
140 */
141 typedef enum
142 {
143 PLIST_FORMAT_XML = 1, /**< XML format */
144 PLIST_FORMAT_BINARY = 2, /**< bplist00 format */
145 PLIST_FORMAT_JSON = 3, /**< JSON format */
146 PLIST_FORMAT_OSTEP = 4, /**< OpenStep "old-style" plist format */
147 /* 5-9 are reserved for possible future use */
148 PLIST_FORMAT_PRINT = 10, /**< human-readable output-only format */
149 PLIST_FORMAT_LIMD = 11, /**< "libimobiledevice" output-only format (ideviceinfo) */
150 PLIST_FORMAT_PLUTIL = 12, /**< plutil-style output-only format */
151 } plist_format_t;
152
153 /**
154 * libplist write options
155 */
156 typedef enum
157 {
158 PLIST_OPT_COMPACT = 1 << 0, /**< Use a compact representation (non-prettified). Only valid for #PLIST_FORMAT_JSON and #PLIST_FORMAT_OSTEP. */
159 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. */
160 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. */
161 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. */
162 } plist_write_options_t;
163
164 /** To be used with #PLIST_OPT_INDENT. Encodes the level of indentation for OR'ing it into the #plist_write_options_t bitfield. */
165 #define PLIST_OPT_INDENT_BY(x) ((x & 0xFF) << 24)
166
167
136 /******************************************** 168 /********************************************
137 * * 169 * *
138 * Creation & Destruction * 170 * Creation & Destruction *
@@ -788,22 +820,73 @@ extern "C"
788 /** 820 /**
789 * Import the #plist_t structure from memory data. 821 * Import the #plist_t structure from memory data.
790 * This method will look at the first bytes of plist_data 822 * This method will look at the first bytes of plist_data
791 * to determine if plist_data contains a binary, JSON, or XML plist 823 * to determine if plist_data contains a binary, JSON, OpenStep, or XML plist
792 * and tries to parse the data in the appropriate format. 824 * and tries to parse the data in the appropriate format.
793 * @note This is just a convenience function and the format detection is 825 * @note This is just a convenience function and the format detection is
794 * very basic. It checks with plist_is_binary() if the data supposedly 826 * very basic. It checks with plist_is_binary() if the data supposedly
795 * contains binary plist data, if not it checks if the first byte is 827 * contains binary plist data, if not it checks if the first bytes have
796 * either '{' or '[' and assumes JSON format, otherwise it will try 828 * either '{' or '[' and assumes JSON format, and XML tags will result
797 * to parse the data as XML. 829 * in parsing as XML, otherwise it will try to parse as OpenStep.
798 * 830 *
799 * @param plist_data a pointer to the memory buffer containing plist data. 831 * @param plist_data A pointer to the memory buffer containing plist data.
800 * @param length length of the buffer to read. 832 * @param length Length of the buffer to read.
801 * @param plist a pointer to the imported plist. 833 * @param plist A pointer to the imported plist.
802 * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure 834 * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure
803 */ 835 */
804 plist_err_t plist_from_memory(const char *plist_data, uint32_t length, plist_t * plist); 836 plist_err_t plist_from_memory(const char *plist_data, uint32_t length, plist_t * plist);
805 837
806 /** 838 /**
839 * Write the #plist_t structure to a NULL-terminated string using the given format and options.
840 *
841 * @param plist The input plist structure
842 * @param output Pointer to a char* buffer. This function allocates the memory,
843 * caller is responsible for freeing it.
844 * @param length A pointer to a uint32_t value that will receive the lenght of the allocated buffer.
845 * @param format A #plist_format_t value that specifies the output format to use.
846 * @param options One or more bitwise ORed values of #plist_write_options_t.
847 * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure.
848 * @note Use plist_mem_free() to free the allocated memory.
849 * @note #PLIST_FORMAT_BINARY is not supported by this function.
850 */
851 plist_err_t plist_write_to_string(plist_t plist, char **output, uint32_t* length, plist_format_t format, plist_write_options_t options);
852
853 /**
854 * Write the #plist_t structure to a FILE* stream using the given format and options.
855 *
856 * @param plist The input plist structure
857 * @param stream A writeable FILE* stream that the data will be written to.
858 * @param format A #plist_format_t value that specifies the output format to use.
859 * @param options One or more bitwise ORed values of #plist_write_options_t.
860 * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure.
861 * @note While this function allows all formats to be written to the given stream,
862 * only the formats #PLIST_FORMAT_PRINT, #PLIST_FORMAT_LIMD, and #PLIST_FORMAT_PLUTIL
863 * (basically all output-only formats) are directly and efficiently written to the stream;
864 * the other formats are written to a memory buffer first.
865 */
866 plist_err_t plist_write_to_stream(plist_t plist, FILE* stream, plist_format_t format, plist_write_options_t options);
867
868 /**
869 * Write the #plist_t structure to a file at given path using the given format and options.
870 *
871 * @param plist The input plist structure
872 * @param filename The file name of the file to write to. Existing files will be overwritten.
873 * @param format A #plist_format_t value that specifies the output format to use.
874 * @param options One or more bitwise ORed values of #plist_write_options_t.
875 * @return PLIST_ERR_SUCCESS on success or a #plist_err_t on failure.
876 * @note Use plist_mem_free() to free the allocated memory.
877 */
878 plist_err_t plist_write_to_file(plist_t plist, const char *filename, plist_format_t format, plist_write_options_t options);
879
880 /**
881 * Print the given plist in human-readable format to standard output.
882 * This is equivalent to
883 * <code>plist_write_to_stream(plist, stdout, PLIST_FORMAT_PRINT, PLIST_OPT_PARTIAL_DATA);</code>
884 * @param plist The #plist_t structure to print
885 * @note For #PLIST_DATA nodes, only a maximum of 24 bytes (first 16 and last 8) are written.
886 */
887 void plist_print(plist_t plist);
888
889 /**
807 * Test if in-memory plist data is in binary format. 890 * Test if in-memory plist data is in binary format.
808 * This function will look at the first bytes of plist_data to determine 891 * This function will look at the first bytes of plist_data to determine
809 * if it supposedly contains a binary plist. 892 * if it supposedly contains a binary plist.