2 * Copyright (c) 2000-2005, 2009-2011, 2013, 2016, 2017 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 "SCDynamicStoreInternal.h"
35 #include "config.h" /* MiG generated file */
39 SCDynamicStoreCopyMultiple(SCDynamicStoreRef store
,
43 SCDynamicStorePrivateRef storePrivate
;
45 CFDataRef xmlKeys
= NULL
; /* keys (XML serialized) */
46 xmlData_t myKeysRef
= NULL
; /* keys (serialized) */
47 CFIndex myKeysLen
= 0;
48 CFDataRef xmlPatterns
= NULL
; /* patterns (XML serialized) */
49 xmlData_t myPatternsRef
= NULL
; /* patterns (serialized) */
50 CFIndex myPatternsLen
= 0;
51 xmlDataOut_t xmlDictRef
= NULL
; /* dict (serialized) */
52 mach_msg_type_number_t xmlDictLen
= 0;
53 CFDictionaryRef dict
= NULL
; /* dict (un-serialized) */
54 CFDictionaryRef expDict
= NULL
; /* dict (un-serialized / expanded) */
58 store
= __SCDynamicStoreNullSession();
60 /* sorry, you must provide a session */
61 _SCErrorSet(kSCStatusNoStoreSession
);
66 storePrivate
= (SCDynamicStorePrivateRef
)store
;
67 if (storePrivate
->server
== MACH_PORT_NULL
) {
68 _SCErrorSet(kSCStatusNoStoreServer
);
69 return NULL
; /* you must have an open session to play */
72 /* serialize the keys */
74 if (!_SCSerialize(keys
, &xmlKeys
, (void **)&myKeysRef
, &myKeysLen
)) {
75 _SCErrorSet(kSCStatusFailed
);
80 /* serialize the patterns */
81 if (patterns
!= NULL
) {
82 if (!_SCSerialize(patterns
, &xmlPatterns
, (void **)&myPatternsRef
, &myPatternsLen
)) {
83 if (xmlKeys
!= NULL
) CFRelease(xmlKeys
);
84 _SCErrorSet(kSCStatusFailed
);
89 #ifdef VERBOSE_ACTIVITY_LOGGING
90 os_activity_scope(storePrivate
->activity
);
91 #endif // VERBOSE_ACTIVITY_LOGGING
95 /* send the keys and patterns, fetch the associated result from the server */
96 status
= configget_m(storePrivate
->server
,
98 (mach_msg_type_number_t
)myKeysLen
,
100 (mach_msg_type_number_t
)myPatternsLen
,
105 if (__SCDynamicStoreCheckRetryAndHandleError(store
,
108 "SCDynamicStoreCopyMultiple configget_m()")) {
113 if (xmlKeys
!= NULL
) CFRelease(xmlKeys
);
114 if (xmlPatterns
!= NULL
) CFRelease(xmlPatterns
);
116 if (sc_status
!= kSCStatusOK
) {
117 if (xmlDictRef
!= NULL
) {
118 (void) vm_deallocate(mach_task_self(), (vm_address_t
)xmlDictRef
, xmlDictLen
);
120 _SCErrorSet(sc_status
);
124 /* un-serialize the dictionary */
125 if (!_SCUnserialize((CFPropertyListRef
*)&dict
, NULL
, xmlDictRef
, xmlDictLen
)) {
126 _SCErrorSet(kSCStatusFailed
);
130 expDict
= _SCUnserializeMultiple(dict
);
138 SCDynamicStoreCopyValue(SCDynamicStoreRef store
, CFStringRef key
)
140 SCDynamicStorePrivateRef storePrivate
;
141 kern_return_t status
;
142 CFDataRef utfKey
; /* key (XML serialized) */
143 xmlData_t myKeyRef
; /* key (serialized) */
145 xmlDataOut_t xmlDataRef
= NULL
; /* data (serialized) */
146 mach_msg_type_number_t xmlDataLen
= 0;
147 CFPropertyListRef data
; /* data (un-serialized) */
152 store
= __SCDynamicStoreNullSession();
154 /* sorry, you must provide a session */
155 _SCErrorSet(kSCStatusNoStoreSession
);
160 storePrivate
= (SCDynamicStorePrivateRef
)store
;
161 if (storePrivate
->server
== MACH_PORT_NULL
) {
162 _SCErrorSet(kSCStatusNoStoreServer
);
163 return NULL
; /* you must have an open session to play */
166 /* serialize the key */
167 if (!_SCSerializeString(key
, &utfKey
, (void **)&myKeyRef
, &myKeyLen
)) {
168 _SCErrorSet(kSCStatusFailed
);
172 #ifdef VERBOSE_ACTIVITY_LOGGING
173 os_activity_scope(storePrivate
->activity
);
174 #endif // VERBOSE_ACTIVITY_LOGGING
178 /* send the key & fetch the associated data from the server */
179 status
= configget(storePrivate
->server
,
181 (mach_msg_type_number_t
)myKeyLen
,
187 if (__SCDynamicStoreCheckRetryAndHandleError(store
,
190 "SCDynamicStoreCopyValue configget()")) {
197 if (sc_status
!= kSCStatusOK
) {
198 if (xmlDataRef
!= NULL
) {
199 (void) vm_deallocate(mach_task_self(), (vm_address_t
)xmlDataRef
, xmlDataLen
);
201 _SCErrorSet(sc_status
);
205 /* un-serialize the data */
206 if (!_SCUnserialize(&data
, NULL
, xmlDataRef
, xmlDataLen
)) {
207 _SCErrorSet(kSCStatusFailed
);