2 * Copyright (c) 2000-2005, 2009-2011, 2013 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>
34 #include <mach/mach.h>
35 #include <mach/mach_error.h>
37 #include <SystemConfiguration/SystemConfiguration.h>
38 #include <SystemConfiguration/SCPrivate.h>
39 #include "SCDynamicStoreInternal.h"
40 #include "config.h" /* MiG generated file */
44 SCDynamicStoreCopyMultiple(SCDynamicStoreRef store
,
48 SCDynamicStorePrivateRef storePrivate
;
50 CFDataRef xmlKeys
= NULL
; /* keys (XML serialized) */
51 xmlData_t myKeysRef
= NULL
; /* keys (serialized) */
52 CFIndex myKeysLen
= 0;
53 CFDataRef xmlPatterns
= NULL
; /* patterns (XML serialized) */
54 xmlData_t myPatternsRef
= NULL
; /* patterns (serialized) */
55 CFIndex myPatternsLen
= 0;
56 xmlDataOut_t xmlDictRef
= NULL
; /* dict (serialized) */
57 mach_msg_type_number_t xmlDictLen
= 0;
58 CFDictionaryRef dict
= NULL
; /* dict (un-serialized) */
59 CFDictionaryRef expDict
= NULL
; /* dict (un-serialized / expanded) */
63 store
= __SCDynamicStoreNullSession();
65 /* sorry, you must provide a session */
66 _SCErrorSet(kSCStatusNoStoreSession
);
71 storePrivate
= (SCDynamicStorePrivateRef
)store
;
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 if (!_SCSerialize(keys
, &xmlKeys
, (void **)&myKeysRef
, &myKeysLen
)) {
80 _SCErrorSet(kSCStatusFailed
);
85 /* serialize the patterns */
86 if (patterns
!= NULL
) {
87 if (!_SCSerialize(patterns
, &xmlPatterns
, (void **)&myPatternsRef
, &myPatternsLen
)) {
88 if (xmlKeys
!= NULL
) CFRelease(xmlKeys
);
89 _SCErrorSet(kSCStatusFailed
);
96 /* send the keys and patterns, fetch the associated result from the server */
97 status
= configget_m(storePrivate
->server
,
99 (mach_msg_type_number_t
)myKeysLen
,
101 (mach_msg_type_number_t
)myPatternsLen
,
106 if (__SCDynamicStoreCheckRetryAndHandleError(store
,
109 "SCDynamicStoreCopyMultiple configget_m()")) {
114 if (xmlKeys
!= NULL
) CFRelease(xmlKeys
);
115 if (xmlPatterns
!= NULL
) CFRelease(xmlPatterns
);
117 if (sc_status
!= kSCStatusOK
) {
118 if (xmlDictRef
!= NULL
) {
119 (void) vm_deallocate(mach_task_self(), (vm_address_t
)xmlDictRef
, xmlDictLen
);
121 _SCErrorSet(sc_status
);
125 /* un-serialize the dictionary */
126 if (!_SCUnserialize((CFPropertyListRef
*)&dict
, NULL
, xmlDictRef
, xmlDictLen
)) {
127 _SCErrorSet(kSCStatusFailed
);
131 expDict
= _SCUnserializeMultiple(dict
);
139 SCDynamicStoreCopyValue(SCDynamicStoreRef store
, CFStringRef key
)
141 SCDynamicStorePrivateRef storePrivate
;
142 kern_return_t status
;
143 CFDataRef utfKey
; /* key (XML serialized) */
144 xmlData_t myKeyRef
; /* key (serialized) */
146 xmlDataOut_t xmlDataRef
= NULL
; /* data (serialized) */
147 mach_msg_type_number_t xmlDataLen
= 0;
148 CFPropertyListRef data
; /* data (un-serialized) */
153 store
= __SCDynamicStoreNullSession();
155 /* sorry, you must provide a session */
156 _SCErrorSet(kSCStatusNoStoreSession
);
161 storePrivate
= (SCDynamicStorePrivateRef
)store
;
162 if (storePrivate
->server
== MACH_PORT_NULL
) {
163 _SCErrorSet(kSCStatusNoStoreServer
);
164 return NULL
; /* you must have an open session to play */
167 /* serialize the key */
168 if (!_SCSerializeString(key
, &utfKey
, (void **)&myKeyRef
, &myKeyLen
)) {
169 _SCErrorSet(kSCStatusFailed
);
175 /* send the key & fetch the associated data from the server */
176 status
= configget(storePrivate
->server
,
178 (mach_msg_type_number_t
)myKeyLen
,
184 if (__SCDynamicStoreCheckRetryAndHandleError(store
,
187 "SCDynamicStoreCopyValue configget()")) {
194 if (sc_status
!= kSCStatusOK
) {
195 if (xmlDataRef
!= NULL
) {
196 (void) vm_deallocate(mach_task_self(), (vm_address_t
)xmlDataRef
, xmlDataLen
);
198 _SCErrorSet(sc_status
);
202 /* un-serialize the data */
203 if (!_SCUnserialize(&data
, NULL
, xmlDataRef
, xmlDataLen
)) {
204 _SCErrorSet(kSCStatusFailed
);