2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
24 * Modification History
26 * June 1, 2001 Allan Nathanson <ajn@apple.com>
27 * - public API conversion
29 * March 24, 2000 Allan Nathanson <ajn@apple.com>
33 #include <mach/mach.h>
34 #include <mach/mach_error.h>
36 #include <SystemConfiguration/SystemConfiguration.h>
37 #include <SystemConfiguration/SCPrivate.h>
38 #include "SCDynamicStoreInternal.h"
39 #include "config.h" /* MiG generated file */
43 SCDynamicStoreCopyMultiple(SCDynamicStoreRef store
,
47 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
49 CFDataRef xmlKeys
= NULL
; /* keys (XML serialized) */
50 xmlData_t myKeysRef
= NULL
; /* keys (serialized) */
51 CFIndex myKeysLen
= 0;
52 CFDataRef xmlPatterns
= NULL
; /* patterns (XML serialized) */
53 xmlData_t myPatternsRef
= NULL
; /* patterns (serialized) */
54 CFIndex myPatternsLen
= 0;
55 xmlDataOut_t xmlDictRef
; /* dict (serialized) */
57 CFDataRef xmlDict
; /* dict (XML serialized) */
58 CFDictionaryRef dict
; /* dict (un-serialized) */
62 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("SCDynamicStoreCopyMultiple:"));
63 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" keys = %@"), keys
);
64 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" patterns = %@"), patterns
);
67 /* sorry, you must provide a session */
68 _SCErrorSet(kSCStatusNoStoreSession
);
72 if (storePrivate
->server
== MACH_PORT_NULL
) {
73 _SCErrorSet(kSCStatusNoStoreServer
);
74 return NULL
; /* you must have an open session to play */
77 /* serialize the keys */
79 xmlKeys
= CFPropertyListCreateXMLData(NULL
, keys
);
80 myKeysRef
= (xmlData_t
)CFDataGetBytePtr(xmlKeys
);
81 myKeysLen
= CFDataGetLength(xmlKeys
);
84 /* serialize the patterns */
86 xmlPatterns
= CFPropertyListCreateXMLData(NULL
, patterns
);
87 myPatternsRef
= (xmlData_t
)CFDataGetBytePtr(xmlPatterns
);
88 myPatternsLen
= CFDataGetLength(xmlPatterns
);
91 /* send the keys and patterns, fetch the associated result from the server */
92 status
= configget_m(storePrivate
->server
,
102 if (xmlKeys
) CFRelease(xmlKeys
);
103 if (xmlPatterns
) CFRelease(xmlPatterns
);
105 if (status
!= KERN_SUCCESS
) {
106 if (status
!= MACH_SEND_INVALID_DEST
)
107 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("configget_m(): %s"), mach_error_string(status
));
108 (void) mach_port_destroy(mach_task_self(), storePrivate
->server
);
109 storePrivate
->server
= MACH_PORT_NULL
;
114 if (sc_status
!= kSCStatusOK
) {
115 status
= vm_deallocate(mach_task_self(), (vm_address_t
)xmlDictRef
, xmlDictLen
);
116 if (status
!= KERN_SUCCESS
) {
117 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("vm_deallocate(): %s"), mach_error_string(status
));
118 /* non-fatal???, proceed */
120 _SCErrorSet(sc_status
);
124 /* un-serialize the dict, return a value associated with the key */
125 xmlDict
= CFDataCreate(NULL
, xmlDictRef
, xmlDictLen
);
126 status
= vm_deallocate(mach_task_self(), (vm_address_t
)xmlDictRef
, xmlDictLen
);
127 if (status
!= KERN_SUCCESS
) {
128 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("vm_deallocate(): %s"), mach_error_string(status
));
129 /* non-fatal???, proceed */
131 dict
= CFPropertyListCreateFromXMLData(NULL
,
133 kCFPropertyListImmutable
,
138 SCLog(_sc_verbose
, LOG_DEBUG
,
139 CFSTR("CFPropertyListCreateFromXMLData() dict: %@"),
143 _SCErrorSet(kSCStatusFailed
);
147 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" value = %@"), dict
);
154 SCDynamicStoreCopyValue(SCDynamicStoreRef store
, CFStringRef key
)
156 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
157 kern_return_t status
;
158 CFDataRef xmlKey
; /* key (XML serialized) */
159 xmlData_t myKeyRef
; /* key (serialized) */
161 xmlDataOut_t xmlDataRef
; /* data (serialized) */
163 CFDataRef xmlData
; /* data (XML serialized) */
164 CFPropertyListRef data
; /* data (un-serialized) */
167 CFStringRef xmlError
;
169 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("SCDynamicStoreCopyValue:"));
170 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" key = %@"), key
);
173 /* sorry, you must provide a session */
174 _SCErrorSet(kSCStatusNoStoreSession
);
178 if (storePrivate
->server
== MACH_PORT_NULL
) {
179 _SCErrorSet(kSCStatusNoStoreServer
);
180 return NULL
; /* you must have an open session to play */
183 /* serialize the key */
184 xmlKey
= CFPropertyListCreateXMLData(NULL
, key
);
185 myKeyRef
= (xmlData_t
)CFDataGetBytePtr(xmlKey
);
186 myKeyLen
= CFDataGetLength(xmlKey
);
188 /* send the key & fetch the associated data from the server */
189 status
= configget(storePrivate
->server
,
200 if (status
!= KERN_SUCCESS
) {
201 if (status
!= MACH_SEND_INVALID_DEST
)
202 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("configget(): %s"), mach_error_string(status
));
203 (void) mach_port_destroy(mach_task_self(), storePrivate
->server
);
204 storePrivate
->server
= MACH_PORT_NULL
;
209 if (sc_status
!= kSCStatusOK
) {
210 status
= vm_deallocate(mach_task_self(), (vm_address_t
)xmlDataRef
, xmlDataLen
);
211 if (status
!= KERN_SUCCESS
) {
212 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("vm_deallocate(): %s"), mach_error_string(status
));
213 /* non-fatal???, proceed */
215 _SCErrorSet(sc_status
);
219 /* un-serialize the data, return a value associated with the key */
220 xmlData
= CFDataCreate(NULL
, xmlDataRef
, xmlDataLen
);
221 status
= vm_deallocate(mach_task_self(), (vm_address_t
)xmlDataRef
, xmlDataLen
);
222 if (status
!= KERN_SUCCESS
) {
223 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("vm_deallocate(): %s"), mach_error_string(status
));
224 /* non-fatal???, proceed */
226 data
= CFPropertyListCreateFromXMLData(NULL
,
228 kCFPropertyListImmutable
,
233 SCLog(_sc_verbose
, LOG_DEBUG
,
234 CFSTR("CFPropertyListCreateFromXMLData() data: %@"),
238 _SCErrorSet(kSCStatusFailed
);
242 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" value = %@"), data
);