]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCDGet.c
configd-699.1.5.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / SCDGet.c
1 /*
2 * Copyright (c) 2000-2005, 2009-2011, 2013 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 <mach/mach.h>
35 #include <mach/mach_error.h>
36
37 #include <SystemConfiguration/SystemConfiguration.h>
38 #include <SystemConfiguration/SCPrivate.h>
39 #include "SCDynamicStoreInternal.h"
40 #include "config.h" /* MiG generated file */
41
42
43 CFDictionaryRef
44 SCDynamicStoreCopyMultiple(SCDynamicStoreRef store,
45 CFArrayRef keys,
46 CFArrayRef patterns)
47 {
48 SCDynamicStorePrivateRef storePrivate;
49 kern_return_t status;
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) */
60 int sc_status;
61
62 if (store == NULL) {
63 store = __SCDynamicStoreNullSession();
64 if (store == NULL) {
65 /* sorry, you must provide a session */
66 _SCErrorSet(kSCStatusNoStoreSession);
67 return NULL;
68 }
69 }
70
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 */
75 }
76
77 /* serialize the keys */
78 if (keys != NULL) {
79 if (!_SCSerialize(keys, &xmlKeys, (void **)&myKeysRef, &myKeysLen)) {
80 _SCErrorSet(kSCStatusFailed);
81 return NULL;
82 }
83 }
84
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);
90 return NULL;
91 }
92 }
93
94 retry :
95
96 /* send the keys and patterns, fetch the associated result from the server */
97 status = configget_m(storePrivate->server,
98 myKeysRef,
99 (mach_msg_type_number_t)myKeysLen,
100 myPatternsRef,
101 (mach_msg_type_number_t)myPatternsLen,
102 &xmlDictRef,
103 &xmlDictLen,
104 (int *)&sc_status);
105
106 if (__SCDynamicStoreCheckRetryAndHandleError(store,
107 status,
108 &sc_status,
109 "SCDynamicStoreCopyMultiple configget_m()")) {
110 goto retry;
111 }
112
113 /* clean up */
114 if (xmlKeys != NULL) CFRelease(xmlKeys);
115 if (xmlPatterns != NULL) CFRelease(xmlPatterns);
116
117 if (sc_status != kSCStatusOK) {
118 if (xmlDictRef != NULL) {
119 (void) vm_deallocate(mach_task_self(), (vm_address_t)xmlDictRef, xmlDictLen);
120 }
121 _SCErrorSet(sc_status);
122 return NULL;
123 }
124
125 /* un-serialize the dictionary */
126 if (!_SCUnserialize((CFPropertyListRef *)&dict, NULL, xmlDictRef, xmlDictLen)) {
127 _SCErrorSet(kSCStatusFailed);
128 return NULL;
129 }
130
131 expDict = _SCUnserializeMultiple(dict);
132 CFRelease(dict);
133
134 return expDict;
135 }
136
137
138 CFPropertyListRef
139 SCDynamicStoreCopyValue(SCDynamicStoreRef store, CFStringRef key)
140 {
141 SCDynamicStorePrivateRef storePrivate;
142 kern_return_t status;
143 CFDataRef utfKey; /* key (XML serialized) */
144 xmlData_t myKeyRef; /* key (serialized) */
145 CFIndex myKeyLen;
146 xmlDataOut_t xmlDataRef = NULL; /* data (serialized) */
147 mach_msg_type_number_t xmlDataLen = 0;
148 CFPropertyListRef data; /* data (un-serialized) */
149 int newInstance;
150 int sc_status;
151
152 if (store == NULL) {
153 store = __SCDynamicStoreNullSession();
154 if (store == NULL) {
155 /* sorry, you must provide a session */
156 _SCErrorSet(kSCStatusNoStoreSession);
157 return NULL;
158 }
159 }
160
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 */
165 }
166
167 /* serialize the key */
168 if (!_SCSerializeString(key, &utfKey, (void **)&myKeyRef, &myKeyLen)) {
169 _SCErrorSet(kSCStatusFailed);
170 return NULL;
171 }
172
173 retry :
174
175 /* send the key & fetch the associated data from the server */
176 status = configget(storePrivate->server,
177 myKeyRef,
178 (mach_msg_type_number_t)myKeyLen,
179 &xmlDataRef,
180 &xmlDataLen,
181 &newInstance,
182 (int *)&sc_status);
183
184 if (__SCDynamicStoreCheckRetryAndHandleError(store,
185 status,
186 &sc_status,
187 "SCDynamicStoreCopyValue configget()")) {
188 goto retry;
189 }
190
191 /* clean up */
192 CFRelease(utfKey);
193
194 if (sc_status != kSCStatusOK) {
195 if (xmlDataRef != NULL) {
196 (void) vm_deallocate(mach_task_self(), (vm_address_t)xmlDataRef, xmlDataLen);
197 }
198 _SCErrorSet(sc_status);
199 return NULL;
200 }
201
202 /* un-serialize the data */
203 if (!_SCUnserialize(&data, NULL, xmlDataRef, xmlDataLen)) {
204 _SCErrorSet(kSCStatusFailed);
205 return NULL;
206 }
207
208 return data;
209 }