2 * Copyright (c) 2000-2004,2011,2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
24 // CoreFoundation building and parsing functions
29 #include <security_utilities/cfutilities.h>
30 #include <CoreFoundation/CoreFoundation.h>
37 // Common interface to Mungers.
38 // A CFMunge provides a one-pass, non-resettable scan through a format string,
39 // performing various actions on the way.
43 CFMunge(const char *fmt
, va_list arg
);
55 CFAllocatorRef allocator
;
61 // A CFMake is a CFMunge for making CF data structures.
63 class CFMake
: public CFMunge
{
65 CFMake(const char *fmt
, va_list arg
) : CFMunge(fmt
, arg
) { }
68 CFDictionaryRef
addto(CFMutableDictionaryRef dict
);
71 CFTypeRef
makedictionary();
72 CFTypeRef
makearray();
73 CFTypeRef
makenumber();
74 CFTypeRef
makestring();
75 CFTypeRef
makeformat();
76 CFTypeRef
makespecial();
78 CFDictionaryRef
add(CFMutableDictionaryRef dict
);
83 // Make a CF object following a general recipe
85 CFTypeRef
cfmake(const char *format
, ...);
86 CFTypeRef
vcfmake(const char *format
, va_list args
);
88 template <class CFType
>
89 CFType
cfmake(const char *format
, ...)
92 va_start(args
, format
);
93 CFType result
= CFType(vcfmake(format
, args
));
98 CFDictionaryRef
cfadd(CFMutableDictionaryRef dict
, const char *format
, ...);
102 // Parse out parts of a CF object following a general recipe.
103 // Cfscan returns false on error; cfget throws.
105 bool cfscan(CFTypeRef source
, const char *format
, ...);
106 bool vcfscan(CFTypeRef source
, const char *format
, va_list args
);
108 CFTypeRef
cfget(CFTypeRef source
, const char *format
, ...);
109 CFTypeRef
vcfget(CFTypeRef source
, const char *format
, va_list args
);
111 template <class CFType
>
112 CFType
cfget(CFTypeRef source
, const char *format
, ...)
115 va_start(args
, format
);
116 CFType result
= CFType(vcfget(source
, format
, args
));
118 return (result
&& CFTraits
<CFType
>::check(result
)) ? result
: NULL
;
121 template <class CFType
>
122 class CFTemp
: public CFRef
<CFType
> {
124 CFTemp(const char *format
, ...)
127 va_start(args
, format
);
128 this->take(CFType(vcfmake(format
, args
)));
134 } // end namespace Security