2 * Copyright (c) 2000-2002 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 CFDictionaryRef dict
= NULL
; /* dict (un-serialized) */
60 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("SCDynamicStoreCopyMultiple:"));
61 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" keys = %@"), keys
);
62 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" patterns = %@"), patterns
);
65 /* sorry, you must provide a session */
66 _SCErrorSet(kSCStatusNoStoreSession
);
70 if (storePrivate
->server
== MACH_PORT_NULL
) {
71 _SCErrorSet(kSCStatusNoStoreServer
);
72 return NULL
; /* you must have an open session to play */
75 /* serialize the keys */
77 if (!_SCSerialize(keys
, &xmlKeys
, (void **)&myKeysRef
, &myKeysLen
)) {
78 _SCErrorSet(kSCStatusFailed
);
83 /* serialize the patterns */
85 if (!_SCSerialize(patterns
, &xmlPatterns
, (void **)&myPatternsRef
, &myPatternsLen
)) {
87 _SCErrorSet(kSCStatusFailed
);
92 /* send the keys and patterns, fetch the associated result from the server */
93 status
= configget_m(storePrivate
->server
,
103 if (xmlKeys
) CFRelease(xmlKeys
);
104 if (xmlPatterns
) CFRelease(xmlPatterns
);
106 if (status
!= KERN_SUCCESS
) {
107 if (status
!= MACH_SEND_INVALID_DEST
)
108 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("configget_m(): %s"), mach_error_string(status
));
109 (void) mach_port_destroy(mach_task_self(), storePrivate
->server
);
110 storePrivate
->server
= MACH_PORT_NULL
;
115 if (sc_status
!= kSCStatusOK
) {
116 status
= vm_deallocate(mach_task_self(), (vm_address_t
)xmlDictRef
, xmlDictLen
);
117 if (status
!= KERN_SUCCESS
) {
118 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("vm_deallocate(): %s"), mach_error_string(status
));
119 /* non-fatal???, proceed */
121 _SCErrorSet(sc_status
);
125 /* un-serialize the dictionary */
126 if (!_SCUnserialize((CFPropertyListRef
*)&dict
, xmlDictRef
, xmlDictLen
)) {
127 _SCErrorSet(kSCStatusFailed
);
131 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" value = %@"), dict
);
138 SCDynamicStoreCopyValue(SCDynamicStoreRef store
, CFStringRef key
)
140 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
141 kern_return_t status
;
142 CFDataRef xmlKey
; /* key (XML serialized) */
143 xmlData_t myKeyRef
; /* key (serialized) */
145 xmlDataOut_t xmlDataRef
; /* data (serialized) */
147 CFPropertyListRef data
; /* data (un-serialized) */
151 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("SCDynamicStoreCopyValue:"));
152 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" key = %@"), key
);
155 /* sorry, you must provide a session */
156 _SCErrorSet(kSCStatusNoStoreSession
);
160 if (storePrivate
->server
== MACH_PORT_NULL
) {
161 _SCErrorSet(kSCStatusNoStoreServer
);
162 return NULL
; /* you must have an open session to play */
165 /* serialize the key */
166 if (!_SCSerialize(key
, &xmlKey
, (void **)&myKeyRef
, &myKeyLen
)) {
167 _SCErrorSet(kSCStatusFailed
);
171 /* send the key & fetch the associated data from the server */
172 status
= configget(storePrivate
->server
,
183 if (status
!= KERN_SUCCESS
) {
184 if (status
!= MACH_SEND_INVALID_DEST
)
185 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("configget(): %s"), mach_error_string(status
));
186 (void) mach_port_destroy(mach_task_self(), storePrivate
->server
);
187 storePrivate
->server
= MACH_PORT_NULL
;
192 if (sc_status
!= kSCStatusOK
) {
193 status
= vm_deallocate(mach_task_self(), (vm_address_t
)xmlDataRef
, xmlDataLen
);
194 if (status
!= KERN_SUCCESS
) {
195 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR("vm_deallocate(): %s"), mach_error_string(status
));
196 /* non-fatal???, proceed */
198 _SCErrorSet(sc_status
);
202 /* un-serialize the data */
203 if (!_SCUnserialize(&data
, xmlDataRef
, xmlDataLen
)) {
204 _SCErrorSet(kSCStatusFailed
);
208 SCLog(_sc_verbose
, LOG_DEBUG
, CFSTR(" value = %@"), data
);