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>
36 #include <mach/mach.h>
37 #include <mach/mach_error.h>
39 #include <SystemConfiguration/SystemConfiguration.h>
40 #include <SystemConfiguration/SCPrivate.h>
41 #include "SCDynamicStoreInternal.h"
42 #include "config.h" /* MiG generated file */
46 SCDynamicStoreCopyMultiple(SCDynamicStoreRef store
,
50 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
52 CFDataRef xmlKeys
= NULL
; /* keys (XML serialized) */
53 xmlData_t myKeysRef
= NULL
; /* keys (serialized) */
54 CFIndex myKeysLen
= 0;
55 CFDataRef xmlPatterns
= NULL
; /* patterns (XML serialized) */
56 xmlData_t myPatternsRef
= NULL
; /* patterns (serialized) */
57 CFIndex myPatternsLen
= 0;
58 xmlDataOut_t xmlDictRef
; /* dict (serialized) */
60 CFDictionaryRef dict
= NULL
; /* dict (un-serialized) */
61 CFDictionaryRef expDict
= NULL
; /* dict (un-serialized / expanded) */
65 SCLog(TRUE
, LOG_DEBUG
, CFSTR("SCDynamicStoreCopyMultiple:"));
66 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" keys = %@"), keys
);
67 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" patterns = %@"), patterns
);
71 /* sorry, you must provide a session */
72 _SCErrorSet(kSCStatusNoStoreSession
);
76 if (storePrivate
->server
== MACH_PORT_NULL
) {
77 _SCErrorSet(kSCStatusNoStoreServer
);
78 return NULL
; /* you must have an open session to play */
81 /* serialize the keys */
83 if (!_SCSerialize(keys
, &xmlKeys
, (void **)&myKeysRef
, &myKeysLen
)) {
84 _SCErrorSet(kSCStatusFailed
);
89 /* serialize the patterns */
91 if (!_SCSerialize(patterns
, &xmlPatterns
, (void **)&myPatternsRef
, &myPatternsLen
)) {
93 _SCErrorSet(kSCStatusFailed
);
98 /* send the keys and patterns, fetch the associated result from the server */
99 status
= configget_m(storePrivate
->server
,
109 if (xmlKeys
) CFRelease(xmlKeys
);
110 if (xmlPatterns
) CFRelease(xmlPatterns
);
112 if (status
!= KERN_SUCCESS
) {
113 if (status
!= MACH_SEND_INVALID_DEST
)
114 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("configget_m(): %s"), mach_error_string(status
));
115 (void) mach_port_destroy(mach_task_self(), storePrivate
->server
);
116 storePrivate
->server
= MACH_PORT_NULL
;
121 if (sc_status
!= kSCStatusOK
) {
122 status
= vm_deallocate(mach_task_self(), (vm_address_t
)xmlDictRef
, xmlDictLen
);
123 if (status
!= KERN_SUCCESS
) {
124 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("vm_deallocate(): %s"), mach_error_string(status
));
125 /* non-fatal???, proceed */
127 _SCErrorSet(sc_status
);
131 /* un-serialize the dictionary */
132 if (!_SCUnserialize((CFPropertyListRef
*)&dict
, NULL
, xmlDictRef
, xmlDictLen
)) {
133 _SCErrorSet(kSCStatusFailed
);
137 expDict
= _SCUnserializeMultiple(dict
);
140 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" value = %@"), expDict
);
147 SCDynamicStoreCopyValue(SCDynamicStoreRef store
, CFStringRef key
)
149 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
150 kern_return_t status
;
151 CFDataRef utfKey
; /* key (XML serialized) */
152 xmlData_t myKeyRef
; /* key (serialized) */
154 xmlDataOut_t xmlDataRef
; /* data (serialized) */
156 CFPropertyListRef data
; /* data (un-serialized) */
161 SCLog(TRUE
, LOG_DEBUG
, CFSTR("SCDynamicStoreCopyValue:"));
162 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" key = %@"), key
);
166 /* sorry, you must provide a session */
167 _SCErrorSet(kSCStatusNoStoreSession
);
171 if (storePrivate
->server
== MACH_PORT_NULL
) {
172 _SCErrorSet(kSCStatusNoStoreServer
);
173 return NULL
; /* you must have an open session to play */
176 /* serialize the key */
177 if (!_SCSerializeString(key
, &utfKey
, (void **)&myKeyRef
, &myKeyLen
)) {
178 _SCErrorSet(kSCStatusFailed
);
182 /* send the key & fetch the associated data from the server */
183 status
= configget(storePrivate
->server
,
194 if (status
!= KERN_SUCCESS
) {
195 if (status
!= MACH_SEND_INVALID_DEST
)
196 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("configget(): %s"), mach_error_string(status
));
197 (void) mach_port_destroy(mach_task_self(), storePrivate
->server
);
198 storePrivate
->server
= MACH_PORT_NULL
;
203 if (sc_status
!= kSCStatusOK
) {
204 status
= vm_deallocate(mach_task_self(), (vm_address_t
)xmlDataRef
, xmlDataLen
);
205 if (status
!= KERN_SUCCESS
) {
206 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("vm_deallocate(): %s"), mach_error_string(status
));
207 /* non-fatal???, proceed */
209 _SCErrorSet(sc_status
);
213 /* un-serialize the data */
214 if (!_SCUnserialize(&data
, NULL
, xmlDataRef
, xmlDataLen
)) {
215 _SCErrorSet(kSCStatusFailed
);
219 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" value = %@"), data
);