]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCDGet.c
19d67c5094dfac04ce3fa125ebfa4b41d3c18135
[apple/configd.git] / SystemConfiguration.fproj / SCDGet.c
1 /*
2 * Copyright (c) 2000-2005, 2009-2011, 2013, 2016 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /*
25 * Modification History
26 *
27 * June 1, 2001 Allan Nathanson <ajn@apple.com>
28 * - public API conversion
29 *
30 * March 24, 2000 Allan Nathanson <ajn@apple.com>
31 * - initial revision
32 */
33
34 #include "SCDynamicStoreInternal.h"
35 #include "config.h" /* MiG generated file */
36
37
38 CFDictionaryRef
39 SCDynamicStoreCopyMultiple(SCDynamicStoreRef store,
40 CFArrayRef keys,
41 CFArrayRef patterns)
42 {
43 SCDynamicStorePrivateRef storePrivate;
44 kern_return_t status;
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) */
55 int sc_status;
56
57 if (store == NULL) {
58 store = __SCDynamicStoreNullSession();
59 if (store == NULL) {
60 /* sorry, you must provide a session */
61 _SCErrorSet(kSCStatusNoStoreSession);
62 return NULL;
63 }
64 }
65
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 */
70 }
71
72 /* serialize the keys */
73 if (keys != NULL) {
74 if (!_SCSerialize(keys, &xmlKeys, (void **)&myKeysRef, &myKeysLen)) {
75 _SCErrorSet(kSCStatusFailed);
76 return NULL;
77 }
78 }
79
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);
85 return NULL;
86 }
87 }
88
89 os_activity_scope(storePrivate->activity);
90
91 retry :
92
93 /* send the keys and patterns, fetch the associated result from the server */
94 status = configget_m(storePrivate->server,
95 myKeysRef,
96 (mach_msg_type_number_t)myKeysLen,
97 myPatternsRef,
98 (mach_msg_type_number_t)myPatternsLen,
99 &xmlDictRef,
100 &xmlDictLen,
101 (int *)&sc_status);
102
103 if (__SCDynamicStoreCheckRetryAndHandleError(store,
104 status,
105 &sc_status,
106 "SCDynamicStoreCopyMultiple configget_m()")) {
107 goto retry;
108 }
109
110 /* clean up */
111 if (xmlKeys != NULL) CFRelease(xmlKeys);
112 if (xmlPatterns != NULL) CFRelease(xmlPatterns);
113
114 if (sc_status != kSCStatusOK) {
115 if (xmlDictRef != NULL) {
116 (void) vm_deallocate(mach_task_self(), (vm_address_t)xmlDictRef, xmlDictLen);
117 }
118 _SCErrorSet(sc_status);
119 return NULL;
120 }
121
122 /* un-serialize the dictionary */
123 if (!_SCUnserialize((CFPropertyListRef *)&dict, NULL, xmlDictRef, xmlDictLen)) {
124 _SCErrorSet(kSCStatusFailed);
125 return NULL;
126 }
127
128 expDict = _SCUnserializeMultiple(dict);
129 CFRelease(dict);
130
131 return expDict;
132 }
133
134
135 CFPropertyListRef
136 SCDynamicStoreCopyValue(SCDynamicStoreRef store, CFStringRef key)
137 {
138 SCDynamicStorePrivateRef storePrivate;
139 kern_return_t status;
140 CFDataRef utfKey; /* key (XML serialized) */
141 xmlData_t myKeyRef; /* key (serialized) */
142 CFIndex myKeyLen;
143 xmlDataOut_t xmlDataRef = NULL; /* data (serialized) */
144 mach_msg_type_number_t xmlDataLen = 0;
145 CFPropertyListRef data; /* data (un-serialized) */
146 int newInstance;
147 int sc_status;
148
149 if (store == NULL) {
150 store = __SCDynamicStoreNullSession();
151 if (store == NULL) {
152 /* sorry, you must provide a session */
153 _SCErrorSet(kSCStatusNoStoreSession);
154 return NULL;
155 }
156 }
157
158 storePrivate = (SCDynamicStorePrivateRef)store;
159 if (storePrivate->server == MACH_PORT_NULL) {
160 _SCErrorSet(kSCStatusNoStoreServer);
161 return NULL; /* you must have an open session to play */
162 }
163
164 /* serialize the key */
165 if (!_SCSerializeString(key, &utfKey, (void **)&myKeyRef, &myKeyLen)) {
166 _SCErrorSet(kSCStatusFailed);
167 return NULL;
168 }
169
170 os_activity_scope(storePrivate->activity);
171
172 retry :
173
174 /* send the key & fetch the associated data from the server */
175 status = configget(storePrivate->server,
176 myKeyRef,
177 (mach_msg_type_number_t)myKeyLen,
178 &xmlDataRef,
179 &xmlDataLen,
180 &newInstance,
181 (int *)&sc_status);
182
183 if (__SCDynamicStoreCheckRetryAndHandleError(store,
184 status,
185 &sc_status,
186 "SCDynamicStoreCopyValue configget()")) {
187 goto retry;
188 }
189
190 /* clean up */
191 CFRelease(utfKey);
192
193 if (sc_status != kSCStatusOK) {
194 if (xmlDataRef != NULL) {
195 (void) vm_deallocate(mach_task_self(), (vm_address_t)xmlDataRef, xmlDataLen);
196 }
197 _SCErrorSet(sc_status);
198 return NULL;
199 }
200
201 /* un-serialize the data */
202 if (!_SCUnserialize(&data, NULL, xmlDataRef, xmlDataLen)) {
203 _SCErrorSet(kSCStatusFailed);
204 return NULL;
205 }
206
207 return data;
208 }