]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_utilities/lib/simpleprefs.h
2 * Copyright (c) 2002-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@
25 * simpleprefs.h - plist support for a bare bones Preferences implementation,
26 * using only Darwin-avaialble CoreFoundation classes.
29 #ifndef _SECURITY_UTILITIES_SIMPLE_PREFS_H_
30 #define _SECURITY_UTILITIES_SIMPLE_PREFS_H_
32 #include <CoreFoundation/CFDictionary.h>
33 #include <CoreFoundation/CFString.h>
34 #include <security_utilities/utilities.h>
40 * PropertyList compatible CFDictionary, nonmutable. All keys are CFStringRefs;
41 * all values are CF objects.
49 /* create from preferences file */
56 /* make blank dictionary */
59 /* create from arbitrary file */
64 // factory functions for the dictionaries
65 static Dictionary
* CreateDictionary(const char* path
);
66 static Dictionary
* CreateDictionary(const char* domain
, UserOrSystem userSys
, bool loose
= false);
70 /* create from existing CFDictionary */
72 CFDictionaryRef dict
);
74 virtual ~Dictionary();
80 /* lookup, value must be CFString (we check) */
81 CFStringRef
getStringValue(
84 /* lookup, value must be CFData (we check) */
85 CFDataRef
getDataValue(
88 /* lookup, value must be CFDictionary (we check) */
89 CFDictionaryRef
getDictValue(
93 * Lookup, value is a dictionary, we return value as Dictionary
94 * if found, else return NULL.
96 Dictionary
*copyDictValue(
100 * boolean lookup, tolerate many different forms of value.
101 * Default if value not present is false.
106 /* basic CF level accessors */
107 CFDictionaryRef
dict() { return mDict
; }
112 CFDictionaryRef newDict
);
117 /* this might be a CFMutableDictionary...use accessors for proper typing */
118 CFDictionaryRef mDict
;
122 * PropertyList compatible CFDictionary, mutable.
124 class MutableDictionary
: public Dictionary
126 NOCOPY(MutableDictionary
)
128 /* Create an empty mutable dictionary */
132 /* create from arbitrary file */
134 const char *filename
);
138 static MutableDictionary
* CreateMutableDictionary(const char* fileName
);
139 static MutableDictionary
* CreateMutableDictionary(const char *domain
, UserOrSystem userSys
);
142 * Create from existing CFDictionary (OR CFMutableDictionary).
143 * I don't see anyway the CF runtime will let us differentiate an
144 * immutable from a mutable dictionary here, so caller has to tell us.
147 CFDictionaryRef dict
,
150 virtual ~MutableDictionary();
153 * Lookup, value must be CFDictionary (we check). We return a
154 * mutable copy, or if key not found, we return a new mutable dictionary.
155 * If you want a NULL return if it's not there, use getDictValue().
157 CFMutableDictionaryRef
getMutableDictValue(
161 * Lookup, value is a dictionary, we return a MutableDictionary, even if
164 MutableDictionary
*copyMutableDictValue(
168 * Basic setter. Does a "replace if present, add if not present" op.
175 * Set key/value pair, data as CFData in the dictionary but passed
176 * to us as CSSM_DATA.
183 /* remove key/value, if present; not an error if it's not */
187 /* write as XML property list, both return true on success */
188 bool writePlistToFile(
191 /* write XML property list to preferences file */
192 bool writePlistToPrefs(
193 const char *domain
, // e.g., com.apple.security
194 UserOrSystem userSys
); // US_User : ~/Library/Preferences/domain.plist
195 // US_System: /Library/Preferences/domain.plist
197 CFMutableDictionaryRef
mutableDict() { return (CFMutableDictionaryRef
)dict(); }
200 /* replace mDict with a mutable copy */
204 } /* end namespace Security */
206 #endif /* _SECURITY_UTILITIES_SIMPLE_PREFS_H_ */