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 // Initialize a CFMunge. We start out with the default CFAllocator, and
44 // we do not throw errors.
45 // CFMunge consumes the va_list, the caller should call va_copy if necessary.
46 CFMunge(const char *fmt
, va_list *args
)
47 : format(fmt
), args(args
), allocator(NULL
), error(errSecSuccess
) { }
58 CFAllocatorRef allocator
;
64 // A CFMake is a CFMunge for making CF data structures.
66 class CFMake
: public CFMunge
{
68 CFMake(const char *fmt
, va_list *args
) : CFMunge(fmt
, args
) { }
71 CFDictionaryRef
addto(CFMutableDictionaryRef dict
);
74 CFTypeRef
makedictionary();
75 CFTypeRef
makearray();
76 CFTypeRef
makenumber();
77 CFTypeRef
makestring();
78 CFTypeRef
makeformat();
79 CFTypeRef
makespecial();
81 CFDictionaryRef
add(CFMutableDictionaryRef dict
);
86 // Make a CF object following a general recipe
88 CFTypeRef
cfmake(const char *format
, ...);
89 CFTypeRef
vcfmake(const char *format
, va_list *args
);
91 template <class CFType
>
92 CFType
cfmake(const char *format
, ...)
95 va_start(args
, format
);
96 CFType result
= CFType(vcfmake(format
, &args
));
101 CFDictionaryRef
cfadd(CFMutableDictionaryRef dict
, const char *format
, ...);
105 // Parse out parts of a CF object following a general recipe.
106 // Cfscan returns false on error; cfget throws.
108 bool cfscan(CFTypeRef source
, const char *format
, ...);
109 bool vcfscan(CFTypeRef source
, const char *format
, va_list *args
);
111 CFTypeRef
cfget(CFTypeRef source
, const char *format
, ...);
112 CFTypeRef
vcfget(CFTypeRef source
, const char *format
, va_list *args
);
114 template <class CFType
>
115 CFType
cfget(CFTypeRef source
, const char *format
, ...)
118 va_start(args
, format
);
119 CFType result
= CFType(vcfget(source
, format
, &args
));
121 return (result
&& CFTraits
<CFType
>::check(result
)) ? result
: NULL
;
124 template <class CFType
>
125 class CFTemp
: public CFRef
<CFType
> {
127 CFTemp(const char *format
, ...)
130 va_start(args
, format
);
131 this->take(CFType(vcfmake(format
, &args
)));
137 } // end namespace Security