2 * Copyright (c) 2000-2006, 2008, 2011, 2013-2016 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 * Modification History
27 * June 1, 2001 Allan Nathanson <ajn@apple.com>
28 * - public API conversion
30 * March 24, 2000 Allan Nathanson <ajn@apple.com>
39 __SCDynamicStoreCopyValue(SCDynamicStoreRef store
, CFStringRef key
, CFDataRef
*value
, Boolean internal
)
41 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
44 SC_trace("%s : %5d : %@",
45 internal
? "*copy " : "copy ",
49 dict
= CFDictionaryGetValue(storeData
, key
);
50 if ((dict
== NULL
) || !CFDictionaryContainsKey(dict
, kSCDData
)) {
51 /* key doesn't exist (or data never defined) */
52 return kSCStatusNoKey
;
55 /* Return the data associated with the key */
56 *value
= CFRetain(CFDictionaryGetValue(dict
, kSCDData
));
63 _configget(mach_port_t server
,
64 xmlData_t keyRef
, /* raw XML bytes */
65 mach_msg_type_number_t keyLen
,
66 xmlDataOut_t
*dataRef
, /* raw XML bytes */
67 mach_msg_type_number_t
*dataLen
,
70 audit_token_t audit_token
)
72 CFStringRef key
= NULL
; /* key (un-serialized) */
74 serverSessionRef mySession
;
81 /* un-serialize the key */
82 if (!_SCUnserializeString(&key
, NULL
, (void *)keyRef
, keyLen
)) {
83 *sc_status
= kSCStatusFailed
;
87 if (!isA_CFString(key
)) {
88 *sc_status
= kSCStatusInvalidArgument
;
92 mySession
= getSession(server
);
93 if (mySession
== NULL
) {
94 mySession
= tempSession(server
, CFSTR("SCDynamicStoreCopyValue"), audit_token
);
95 if (mySession
== NULL
) {
96 /* you must have an open session to play */
97 *sc_status
= kSCStatusNoStoreSession
;
102 *sc_status
= __SCDynamicStoreCopyValue(mySession
->store
, key
, &value
, FALSE
);
103 if (*sc_status
!= kSCStatusOK
) {
107 /* serialize the data */
108 ok
= _SCSerializeData(value
, (void **)dataRef
, &len
);
109 *dataLen
= (mach_msg_type_number_t
)len
;
112 *sc_status
= kSCStatusFailed
;
117 * return the instance number associated with the returned data.
123 if (key
!= NULL
) CFRelease(key
);
128 * "context" argument for addSpecificKey() and addSpecificPattern()
131 SCDynamicStoreRef store
;
132 CFMutableDictionaryRef dict
;
133 } addSpecific
, *addSpecificRef
;
136 addSpecificKey(const void *value
, void *context
)
139 CFStringRef key
= (CFStringRef
)value
;
140 addSpecificRef myContextRef
= (addSpecificRef
)context
;
143 if (!isA_CFString(key
)) {
147 sc_status
= __SCDynamicStoreCopyValue(myContextRef
->store
, key
, &data
, TRUE
);
148 if (sc_status
== kSCStatusOK
) {
149 CFDictionaryAddValue(myContextRef
->dict
, key
, data
);
157 addSpecificPattern(const void *value
, void *context
)
159 CFStringRef pattern
= (CFStringRef
)value
;
160 addSpecificRef myContextRef
= (addSpecificRef
)context
;
164 if (!isA_CFString(pattern
)) {
168 sc_status
= __SCDynamicStoreCopyKeyList(myContextRef
->store
, pattern
, TRUE
, &keys
);
169 if (sc_status
== kSCStatusOK
) {
170 CFArrayApplyFunction(keys
,
171 CFRangeMake(0, CFArrayGetCount(keys
)),
182 __SCDynamicStoreCopyMultiple(SCDynamicStoreRef store
, CFArrayRef keys
, CFArrayRef patterns
, CFDictionaryRef
*values
)
184 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
185 addSpecific myContext
;
187 SC_trace("copy m : %5d : %ld keys, %ld patterns",
188 storePrivate
->server
,
189 keys
? CFArrayGetCount(keys
) : 0,
190 patterns
? CFArrayGetCount(patterns
) : 0);
192 myContext
.store
= store
;
193 myContext
.dict
= CFDictionaryCreateMutable(NULL
,
195 &kCFTypeDictionaryKeyCallBacks
,
196 &kCFTypeDictionaryValueCallBacks
);
199 CFArrayApplyFunction(keys
,
200 CFRangeMake(0, CFArrayGetCount(keys
)),
206 CFArrayApplyFunction(patterns
,
207 CFRangeMake(0, CFArrayGetCount(patterns
)),
212 /* Return the keys/values associated with the key */
213 *values
= myContext
.dict
;
220 _configget_m(mach_port_t server
,
222 mach_msg_type_number_t keysLen
,
223 xmlData_t patternsRef
,
224 mach_msg_type_number_t patternsLen
,
225 xmlDataOut_t
*dataRef
,
226 mach_msg_type_number_t
*dataLen
,
228 audit_token_t audit_token
)
230 CFDictionaryRef dict
= NULL
; /* keys/values (un-serialized) */
231 CFArrayRef keys
= NULL
; /* keys (un-serialized) */
233 serverSessionRef mySession
;
235 CFArrayRef patterns
= NULL
; /* patterns (un-serialized) */
240 *sc_status
= kSCStatusOK
;
242 if (keysRef
&& (keysLen
> 0)) {
243 /* un-serialize the keys */
244 if (!_SCUnserialize((CFPropertyListRef
*)&keys
, NULL
, (void *)keysRef
, keysLen
)) {
245 *sc_status
= kSCStatusFailed
;
249 if (patternsRef
&& (patternsLen
> 0)) {
250 /* un-serialize the patterns */
251 if (!_SCUnserialize((CFPropertyListRef
*)&patterns
, NULL
, (void *)patternsRef
, patternsLen
)) {
252 *sc_status
= kSCStatusFailed
;
256 if (*sc_status
!= kSCStatusOK
) {
260 if ((keys
!= NULL
) && !isA_CFArray(keys
)) {
261 *sc_status
= kSCStatusInvalidArgument
;
265 if ((patterns
!= NULL
) && !isA_CFArray(patterns
)) {
266 *sc_status
= kSCStatusInvalidArgument
;
270 mySession
= getSession(server
);
271 if (mySession
== NULL
) {
272 mySession
= tempSession(server
, CFSTR("SCDynamicStoreCopyMultiple"), audit_token
);
273 if (mySession
== NULL
) {
274 /* you must have an open session to play */
275 *sc_status
= kSCStatusNoStoreSession
;
280 /* fetch the requested information */
281 *sc_status
= __SCDynamicStoreCopyMultiple(mySession
->store
, keys
, patterns
, &dict
);
283 /* serialize the dictionary of matching keys/patterns */
284 ok
= _SCSerialize(dict
, NULL
, (void **)dataRef
, &len
);
285 *dataLen
= (mach_msg_type_number_t
)len
;
288 *sc_status
= kSCStatusFailed
;
293 if (keys
) CFRelease(keys
);
294 if (patterns
) CFRelease(patterns
);