2 * Copyright (c) 2000-2004, 2006, 2008 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 if ((store
== NULL
) || (storePrivate
->server
== MACH_PORT_NULL
)) {
45 return kSCStatusNoStoreSession
; /* you must have an open session to play */
49 SCTrace(TRUE
, _configd_trace
,
50 CFSTR("%s : %5d : %@\n"),
51 internal
? "*copy " : "copy ",
56 dict
= CFDictionaryGetValue(storeData
, key
);
57 if ((dict
== NULL
) || (CFDictionaryContainsKey(dict
, kSCDData
) == FALSE
)) {
58 /* key doesn't exist (or data never defined) */
59 return kSCStatusNoKey
;
62 /* Return the data associated with the key */
63 *value
= CFRetain(CFDictionaryGetValue(dict
, kSCDData
));
70 _configget(mach_port_t server
,
71 xmlData_t keyRef
, /* raw XML bytes */
72 mach_msg_type_number_t keyLen
,
73 xmlDataOut_t
*dataRef
, /* raw XML bytes */
74 mach_msg_type_number_t
*dataLen
,
79 CFStringRef key
= NULL
; /* key (un-serialized) */
80 serverSessionRef mySession
;
87 /* un-serialize the key */
88 if (!_SCUnserializeString(&key
, NULL
, (void *)keyRef
, keyLen
)) {
89 *sc_status
= kSCStatusFailed
;
93 if (!isA_CFString(key
)) {
94 *sc_status
= kSCStatusInvalidArgument
;
98 mySession
= getSession(server
);
99 if (mySession
== NULL
) {
100 *sc_status
= kSCStatusNoStoreSession
; /* you must have an open session to play */
104 *sc_status
= __SCDynamicStoreCopyValue(mySession
->store
, key
, &value
, FALSE
);
105 if (*sc_status
!= kSCStatusOK
) {
109 /* serialize the data */
110 ok
= _SCSerializeData(value
, (void **)dataRef
, (CFIndex
*)dataLen
);
113 *sc_status
= kSCStatusFailed
;
118 * return the instance number associated with the returned data.
124 if (key
!= NULL
) CFRelease(key
);
129 * "context" argument for addSpecificKey() and addSpecificPattern()
132 SCDynamicStoreRef store
;
133 CFMutableDictionaryRef dict
;
134 } addSpecific
, *addSpecificRef
;
137 addSpecificKey(const void *value
, void *context
)
140 CFStringRef key
= (CFStringRef
)value
;
141 addSpecificRef myContextRef
= (addSpecificRef
)context
;
144 if (!isA_CFString(key
)) {
148 sc_status
= __SCDynamicStoreCopyValue(myContextRef
->store
, key
, &data
, TRUE
);
149 if (sc_status
== kSCStatusOK
) {
150 CFDictionaryAddValue(myContextRef
->dict
, key
, data
);
158 addSpecificPattern(const void *value
, void *context
)
160 CFStringRef pattern
= (CFStringRef
)value
;
161 addSpecificRef myContextRef
= (addSpecificRef
)context
;
165 if (!isA_CFString(pattern
)) {
169 sc_status
= __SCDynamicStoreCopyKeyList(myContextRef
->store
, pattern
, TRUE
, &keys
);
170 if (sc_status
== kSCStatusOK
) {
171 CFArrayApplyFunction(keys
,
172 CFRangeMake(0, CFArrayGetCount(keys
)),
183 __SCDynamicStoreCopyMultiple(SCDynamicStoreRef store
, CFArrayRef keys
, CFArrayRef patterns
, CFDictionaryRef
*values
)
185 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
186 addSpecific myContext
;
188 if ((store
== NULL
) || (storePrivate
->server
== MACH_PORT_NULL
)) {
189 return kSCStatusNoStoreSession
; /* you must have an open session to play */
192 if (_configd_trace
) {
193 SCTrace(TRUE
, _configd_trace
,
194 CFSTR("copy m : %5d : %d keys, %d patterns\n"),
195 storePrivate
->server
,
196 keys
? CFArrayGetCount(keys
) : 0,
197 patterns
? CFArrayGetCount(patterns
) : 0);
200 myContext
.store
= store
;
201 myContext
.dict
= CFDictionaryCreateMutable(NULL
,
203 &kCFTypeDictionaryKeyCallBacks
,
204 &kCFTypeDictionaryValueCallBacks
);
207 CFArrayApplyFunction(keys
,
208 CFRangeMake(0, CFArrayGetCount(keys
)),
214 CFArrayApplyFunction(patterns
,
215 CFRangeMake(0, CFArrayGetCount(patterns
)),
220 /* Return the keys/values associated with the key */
221 *values
= myContext
.dict
;
228 _configget_m(mach_port_t server
,
230 mach_msg_type_number_t keysLen
,
231 xmlData_t patternsRef
,
232 mach_msg_type_number_t patternsLen
,
233 xmlDataOut_t
*dataRef
,
234 mach_msg_type_number_t
*dataLen
,
237 CFDictionaryRef dict
= NULL
; /* keys/values (un-serialized) */
238 CFArrayRef keys
= NULL
; /* keys (un-serialized) */
239 serverSessionRef mySession
;
241 CFArrayRef patterns
= NULL
; /* patterns (un-serialized) */
246 *sc_status
= kSCStatusOK
;
248 if (keysRef
&& (keysLen
> 0)) {
249 /* un-serialize the keys */
250 if (!_SCUnserialize((CFPropertyListRef
*)&keys
, NULL
, (void *)keysRef
, keysLen
)) {
251 *sc_status
= kSCStatusFailed
;
255 if (patternsRef
&& (patternsLen
> 0)) {
256 /* un-serialize the patterns */
257 if (!_SCUnserialize((CFPropertyListRef
*)&patterns
, NULL
, (void *)patternsRef
, patternsLen
)) {
258 *sc_status
= kSCStatusFailed
;
262 if (*sc_status
!= kSCStatusOK
) {
266 if ((keys
!= NULL
) && !isA_CFArray(keys
)) {
267 *sc_status
= kSCStatusInvalidArgument
;
271 if ((patterns
!= NULL
) && !isA_CFArray(patterns
)) {
272 *sc_status
= kSCStatusInvalidArgument
;
276 mySession
= getSession(server
);
277 if (mySession
== NULL
) {
278 *sc_status
= kSCStatusNoStoreSession
; /* you must have an open session to play */
282 /* fetch the requested information */
283 *sc_status
= __SCDynamicStoreCopyMultiple(mySession
->store
, keys
, patterns
, &dict
);
285 /* serialize the dictionary of matching keys/patterns */
286 ok
= _SCSerialize(dict
, NULL
, (void **)dataRef
, (CFIndex
*)dataLen
);
289 *sc_status
= kSCStatusFailed
;
294 if (keys
) CFRelease(keys
);
295 if (patterns
) CFRelease(patterns
);