]> git.saurik.com Git - apple/cf.git/blob - CFPropertyList.h
CF-550.19.tar.gz
[apple/cf.git] / CFPropertyList.h
1 /*
2 * Copyright (c) 2010 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /* CFPropertyList.h
25 Copyright (c) 1998-2009, Apple Inc. All rights reserved.
26 */
27
28 #if !defined(__COREFOUNDATION_CFPROPERTYLIST__)
29 #define __COREFOUNDATION_CFPROPERTYLIST__ 1
30
31 #include <CoreFoundation/CFBase.h>
32 #include <CoreFoundation/CFData.h>
33 #include <CoreFoundation/CFString.h>
34 #include <CoreFoundation/CFStream.h>
35
36 CF_EXTERN_C_BEGIN
37
38 enum {
39 kCFPropertyListImmutable = 0,
40 kCFPropertyListMutableContainers,
41 kCFPropertyListMutableContainersAndLeaves
42 };
43 typedef CFOptionFlags CFPropertyListMutabilityOptions;
44
45 /*
46 Creates a property list object from its XML description; xmlData should
47 be the raw bytes of that description, possibly the contents of an XML
48 file. Returns NULL if the data cannot be parsed; if the parse fails
49 and errorString is non-NULL, a human-readable description of the failure
50 is returned in errorString. It is the caller's responsibility to release
51 either the returned object or the error string, whichever is applicable.
52
53 This function is obsolete and will be deprecated soon. See CFPropertyListCreateWithData() for a replacement.
54 */
55 CF_EXPORT
56 CFPropertyListRef CFPropertyListCreateFromXMLData(CFAllocatorRef allocator, CFDataRef xmlData, CFOptionFlags mutabilityOption, CFStringRef *errorString);
57
58 /*
59 Returns the XML description of the given object; propertyList must
60 be one of the supported property list types, and (for composite types
61 like CFArray and CFDictionary) must not contain any elements that
62 are not themselves of a property list type. If a non-property list
63 type is encountered, NULL is returned. The returned data is
64 appropriate for writing out to an XML file. Note that a data, not a
65 string, is returned because the bytes contain in them a description
66 of the string encoding used.
67
68 This function is obsolete and will be deprecated soon. See CFPropertyListCreateData() for a replacement.
69 */
70 CF_EXPORT
71 CFDataRef CFPropertyListCreateXMLData(CFAllocatorRef allocator, CFPropertyListRef propertyList);
72
73 /*
74 Recursively creates a copy of the given property list (so nested arrays
75 and dictionaries are copied as well as the top-most container). The
76 resulting property list has the mutability characteristics determined
77 by mutabilityOption.
78 */
79 CF_EXPORT
80 CFPropertyListRef CFPropertyListCreateDeepCopy(CFAllocatorRef allocator, CFPropertyListRef propertyList, CFOptionFlags mutabilityOption);
81
82 #if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED
83
84 enum {
85 kCFPropertyListOpenStepFormat = 1,
86 kCFPropertyListXMLFormat_v1_0 = 100,
87 kCFPropertyListBinaryFormat_v1_0 = 200
88 };
89 typedef CFIndex CFPropertyListFormat;
90
91 /* Returns true if the object graph rooted at plist is a valid property list
92 * graph -- that is, no cycles, containing only plist objects, and dictionary
93 * keys are strings. The debugging library version spits out some messages
94 * to be helpful. The plist structure which is to be allowed is given by
95 * the format parameter. */
96 CF_EXPORT
97 Boolean CFPropertyListIsValid(CFPropertyListRef plist, CFPropertyListFormat format);
98
99 /* Writes the bytes of a plist serialization out to the stream. The
100 * stream must be opened and configured -- the function simply writes
101 * a bunch of bytes to the stream. The output plist format can be chosen.
102 * Leaves the stream open, but note that reading a plist expects the
103 * reading stream to end wherever the writing ended, so that the
104 * end of the plist data can be identified. Returns the number of bytes
105 * written, or 0 on error. Error messages are not currently localized, but
106 * may be in the future, so they are not suitable for comparison.
107 *
108 * This function is obsolete and will be deprecated soon. See CFPropertyListWrite() for a replacement. */
109 CF_EXPORT
110 CFIndex CFPropertyListWriteToStream(CFPropertyListRef propertyList, CFWriteStreamRef stream, CFPropertyListFormat format, CFStringRef *errorString);
111
112
113 /* Same as current function CFPropertyListCreateFromXMLData()
114 * but takes a stream instead of data, and works on any plist file format.
115 * CFPropertyListCreateFromXMLData() also works on any plist file format.
116 * The stream must be open and configured -- the function simply reads a bunch
117 * of bytes from it starting at the current location in the stream, to the END
118 * of the stream, which is expected to be the end of the plist, or up to the
119 * number of bytes given by the length parameter if it is not 0. Error messages
120 * are not currently localized, but may be in the future, so they are not
121 * suitable for comparison.
122 *
123 * This function is obsolete and will be deprecated soon. See CFPropertyListCreateWithStream() for a replacement. */
124 CF_EXPORT
125 CFPropertyListRef CFPropertyListCreateFromStream(CFAllocatorRef allocator, CFReadStreamRef stream, CFIndex streamLength, CFOptionFlags mutabilityOption, CFPropertyListFormat *format, CFStringRef *errorString);
126
127 #endif
128
129 #if MAC_OS_X_VERSION_10_6 <= MAC_OS_X_VERSION_MAX_ALLOWED
130 enum {
131 kCFPropertyListReadCorruptError = 3840, // Error parsing a property list
132 kCFPropertyListReadUnknownVersionError = 3841, // The version number in the property list is unknown
133 kCFPropertyListReadStreamError = 3842, // Stream error reading a property list
134 kCFPropertyListWriteStreamError = 3851, // Stream error writing a property list
135 };
136 #endif
137
138 /* Create a property list with a CFData input. If the format parameter is non-NULL, it will be set to the format of the data after parsing is complete. The options parameter is used to specify CFPropertyListMutabilityOptions. If an error occurs while parsing the data, the return value will be NULL. Additionally, if an error occurs and the error parameter is non-NULL, the error parameter will be set to a CFError describing the problem, which the caller must release. If the parse succeeds, the returned value is a reference to the new property list. It is the responsibility of the caller to release this value.
139 */
140 CF_EXPORT
141 CFPropertyListRef CFPropertyListCreateWithData(CFAllocatorRef allocator, CFDataRef data, CFOptionFlags options, CFPropertyListFormat *format, CFErrorRef *error) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
142
143 /* Create and return a property list with a CFReadStream input. TIf the format parameter is non-NULL, it will be set to the format of the data after parsing is complete. The options parameter is used to specify CFPropertyListMutabilityOptions. The streamLength parameter specifies the number of bytes to read from the stream. Set streamLength to 0 to read until the end of the stream is detected. If an error occurs while parsing the data, the return value will be NULL. Additionally, if an error occurs and the error parameter is non-NULL, the error parameter will be set to a CFError describing the problem, which the caller must release. If the parse succeeds, the returned value is a reference to the new property list. It is the responsibility of the caller to release this value.
144 */
145 CF_EXPORT
146 CFPropertyListRef CFPropertyListCreateWithStream(CFAllocatorRef allocator, CFReadStreamRef stream, CFIndex streamLength, CFOptionFlags options, CFPropertyListFormat *format, CFErrorRef *error) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
147
148 /* Write the bytes of a serialized property list out to a stream. The stream must be opened and configured. The format of the property list can be chosen with the format parameter. The options parameter is currently unused and should be set to 0. The return value is the number of bytes written or 0 in the case of an error. If an error occurs and the error parameter is non-NULL, the error parameter will be set to a CFError describing the problem, which the caller must release.
149 */
150 CF_EXPORT
151 CFIndex CFPropertyListWrite(CFPropertyListRef propertyList, CFWriteStreamRef stream, CFPropertyListFormat format, CFOptionFlags options, CFErrorRef *error) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
152
153 /* Create a CFData with the bytes of a serialized property list. The format of the property list can be chosen with the format parameter. The options parameter is currently unused and should be set to 0. If an error occurs while parsing the data, the return value will be NULL. Additionally, if an error occurs and the error parameter is non-NULL, the error parameter will be set to a CFError describing the problem, which the caller must release. If the conversion succeeds, the returned value is a reference to the created data. It is the responsibility of the caller to release this value.
154 */
155 CF_EXPORT
156 CFDataRef CFPropertyListCreateData(CFAllocatorRef allocator, CFPropertyListRef propertyList, CFPropertyListFormat format, CFOptionFlags options, CFErrorRef *error) AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER;
157
158
159 CF_EXTERN_C_END
160
161 #endif /* ! __COREFOUNDATION_CFPROPERTYLIST__ */
162