2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
27 * Modification History
29 * June 1, 2001 Allan Nathanson <ajn@apple.com>
30 * - public API conversion
32 * March 24, 2000 Allan Nathanson <ajn@apple.com>
41 __SCDynamicStoreCopyValue(SCDynamicStoreRef store
, CFStringRef key
, CFDataRef
*value
, Boolean internal
)
43 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
46 if (_configd_verbose
) {
47 SCLog(TRUE
, LOG_DEBUG
, CFSTR("__SCDynamicStoreCopyValue:"));
48 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" key = %@"), key
);
51 if (!store
|| (storePrivate
->server
== MACH_PORT_NULL
)) {
52 return kSCStatusNoStoreSession
; /* you must have an open session to play */
56 SCTrace(TRUE
, _configd_trace
,
57 CFSTR("%s : %5d : %@\n"),
58 internal
? "*copy " : "copy ",
63 dict
= CFDictionaryGetValue(storeData
, key
);
64 if ((dict
== NULL
) || (CFDictionaryContainsKey(dict
, kSCDData
) == FALSE
)) {
65 /* key doesn't exist (or data never defined) */
66 return kSCStatusNoKey
;
69 /* Return the data associated with the key */
70 *value
= CFRetain(CFDictionaryGetValue(dict
, kSCDData
));
72 if (_configd_verbose
) {
73 CFPropertyListRef val
;
75 (void) _SCUnserialize(&val
, *value
, NULL
, NULL
);
76 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" value = %@"), val
);
85 _configget(mach_port_t server
,
86 xmlData_t keyRef
, /* raw XML bytes */
87 mach_msg_type_number_t keyLen
,
88 xmlDataOut_t
*dataRef
, /* raw XML bytes */
89 mach_msg_type_number_t
*dataLen
,
94 CFStringRef key
; /* key (un-serialized) */
95 serverSessionRef mySession
= getSession(server
);
99 if (_configd_verbose
) {
100 SCLog(TRUE
, LOG_DEBUG
, CFSTR("Get key from configuration database."));
101 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" server = %d"), server
);
107 /* un-serialize the key */
108 if (!_SCUnserializeString(&key
, NULL
, (void *)keyRef
, keyLen
)) {
109 *sc_status
= kSCStatusFailed
;
113 if (!isA_CFString(key
)) {
114 *sc_status
= kSCStatusInvalidArgument
;
120 *sc_status
= kSCStatusNoStoreSession
; /* you must have an open session to play */
125 *sc_status
= __SCDynamicStoreCopyValue(mySession
->store
, key
, &value
, FALSE
);
127 if (*sc_status
!= kSCStatusOK
) {
131 /* serialize the data */
132 ok
= _SCSerializeData(value
, (void **)dataRef
, (CFIndex
*)dataLen
);
135 *sc_status
= kSCStatusFailed
;
140 * return the instance number associated with the returned data.
148 * "context" argument for addSpecificKey() and addSpecificPattern()
151 SCDynamicStoreRef store
;
152 CFMutableDictionaryRef dict
;
153 } addSpecific
, *addSpecificRef
;
156 addSpecificKey(const void *value
, void *context
)
159 CFStringRef key
= (CFStringRef
)value
;
160 addSpecificRef myContextRef
= (addSpecificRef
)context
;
163 if (!isA_CFString(key
)) {
167 sc_status
= __SCDynamicStoreCopyValue(myContextRef
->store
, key
, &data
, TRUE
);
168 if (sc_status
== kSCStatusOK
) {
169 CFDictionaryAddValue(myContextRef
->dict
, key
, data
);
177 addSpecificPattern(const void *value
, void *context
)
179 CFStringRef pattern
= (CFStringRef
)value
;
180 addSpecificRef myContextRef
= (addSpecificRef
)context
;
184 if (!isA_CFString(pattern
)) {
188 sc_status
= __SCDynamicStoreCopyKeyList(myContextRef
->store
, pattern
, TRUE
, &keys
);
189 if (sc_status
== kSCStatusOK
) {
190 CFArrayApplyFunction(keys
,
191 CFRangeMake(0, CFArrayGetCount(keys
)),
202 __SCDynamicStoreCopyMultiple(SCDynamicStoreRef store
, CFArrayRef keys
, CFArrayRef patterns
, CFDictionaryRef
*values
)
204 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
205 addSpecific myContext
;
207 if (_configd_verbose
) {
208 SCLog(TRUE
, LOG_DEBUG
, CFSTR("__SCDynamicStoreCopyMultiple:"));
209 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" keys = %@"), keys
);
210 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" patterns = %@"), patterns
);
213 if (!store
|| (storePrivate
->server
== MACH_PORT_NULL
)) {
214 return kSCStatusNoStoreSession
; /* you must have an open session to play */
217 if (_configd_trace
) {
218 SCTrace(TRUE
, _configd_trace
,
219 CFSTR("copy m : %5d : %d keys, %d patterns\n"),
220 storePrivate
->server
,
221 keys
? CFArrayGetCount(keys
) : 0,
222 patterns
? CFArrayGetCount(patterns
) : 0);
225 myContext
.store
= store
;
226 myContext
.dict
= CFDictionaryCreateMutable(NULL
,
228 &kCFTypeDictionaryKeyCallBacks
,
229 &kCFTypeDictionaryValueCallBacks
);
232 CFArrayApplyFunction(keys
,
233 CFRangeMake(0, CFArrayGetCount(keys
)),
239 CFArrayApplyFunction(patterns
,
240 CFRangeMake(0, CFArrayGetCount(patterns
)),
245 /* Return the keys/values associated with the key */
246 *values
= myContext
.dict
;
248 if (_configd_verbose
) {
249 CFDictionaryRef expDict
;
251 expDict
= _SCUnserializeMultiple(*values
);
252 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" values = %@"), expDict
);
261 _configget_m(mach_port_t server
,
263 mach_msg_type_number_t keysLen
,
264 xmlData_t patternsRef
,
265 mach_msg_type_number_t patternsLen
,
266 xmlDataOut_t
*dataRef
,
267 mach_msg_type_number_t
*dataLen
,
270 CFDictionaryRef dict
= NULL
; /* keys/values (un-serialized) */
271 CFArrayRef keys
= NULL
; /* keys (un-serialized) */
272 serverSessionRef mySession
= getSession(server
);
274 CFArrayRef patterns
= NULL
; /* patterns (un-serialized) */
276 if (_configd_verbose
) {
277 SCLog(TRUE
, LOG_DEBUG
, CFSTR("Get keys from configuration database."));
278 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" server = %d"), server
);
283 *sc_status
= kSCStatusOK
;
285 if (keysRef
&& (keysLen
> 0)) {
286 /* un-serialize the keys */
287 if (!_SCUnserialize((CFPropertyListRef
*)&keys
, NULL
, (void *)keysRef
, keysLen
)) {
288 *sc_status
= kSCStatusFailed
;
291 if (!isA_CFArray(keys
)) {
292 *sc_status
= kSCStatusInvalidArgument
;
296 if (patternsRef
&& (patternsLen
> 0)) {
297 /* un-serialize the patterns */
298 if (!_SCUnserialize((CFPropertyListRef
*)&patterns
, NULL
, (void *)patternsRef
, patternsLen
)) {
299 *sc_status
= kSCStatusFailed
;
302 if (!isA_CFArray(patterns
)) {
303 *sc_status
= kSCStatusInvalidArgument
;
308 *sc_status
= kSCStatusNoStoreSession
; /* you must have an open session to play */
311 if (*sc_status
!= kSCStatusOK
) {
312 if (keys
) CFRelease(keys
);
313 if (patterns
) CFRelease(patterns
);
317 *sc_status
= __SCDynamicStoreCopyMultiple(mySession
->store
, keys
, patterns
, &dict
);
318 if (keys
) CFRelease(keys
);
319 if (patterns
) CFRelease(patterns
);
321 /* serialize the dictionary of matching keys/patterns */
322 ok
= _SCSerialize(dict
, NULL
, (void **)dataRef
, (CFIndex
*)dataLen
);
325 *sc_status
= kSCStatusFailed
;