]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCDGet.c
configd-53.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / SCDGet.c
1 /*
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 /*
24 * Modification History
25 *
26 * June 1, 2001 Allan Nathanson <ajn@apple.com>
27 * - public API conversion
28 *
29 * March 24, 2000 Allan Nathanson <ajn@apple.com>
30 * - initial revision
31 */
32
33 #include <mach/mach.h>
34 #include <mach/mach_error.h>
35
36 #include <SystemConfiguration/SystemConfiguration.h>
37 #include <SystemConfiguration/SCPrivate.h>
38 #include "SCDynamicStoreInternal.h"
39 #include "config.h" /* MiG generated file */
40
41
42 CFDictionaryRef
43 SCDynamicStoreCopyMultiple(SCDynamicStoreRef store,
44 CFArrayRef keys,
45 CFArrayRef patterns)
46 {
47 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
48 kern_return_t status;
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) */
56 CFIndex xmlDictLen;
57 CFDictionaryRef dict = NULL; /* dict (un-serialized) */
58 int sc_status;
59
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);
63
64 if (!store) {
65 /* sorry, you must provide a session */
66 _SCErrorSet(kSCStatusNoStoreSession);
67 return NULL;
68 }
69
70 if (storePrivate->server == MACH_PORT_NULL) {
71 _SCErrorSet(kSCStatusNoStoreServer);
72 return NULL; /* you must have an open session to play */
73 }
74
75 /* serialize the keys */
76 if (keys) {
77 if (!_SCSerialize(keys, &xmlKeys, (void **)&myKeysRef, &myKeysLen)) {
78 _SCErrorSet(kSCStatusFailed);
79 return NULL;
80 }
81 }
82
83 /* serialize the patterns */
84 if (patterns) {
85 if (!_SCSerialize(patterns, &xmlPatterns, (void **)&myPatternsRef, &myPatternsLen)) {
86 CFRelease(xmlKeys);
87 _SCErrorSet(kSCStatusFailed);
88 return NULL;
89 }
90 }
91
92 /* send the keys and patterns, fetch the associated result from the server */
93 status = configget_m(storePrivate->server,
94 myKeysRef,
95 myKeysLen,
96 myPatternsRef,
97 myPatternsLen,
98 &xmlDictRef,
99 (int *)&xmlDictLen,
100 (int *)&sc_status);
101
102 /* clean up */
103 if (xmlKeys) CFRelease(xmlKeys);
104 if (xmlPatterns) CFRelease(xmlPatterns);
105
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;
111 _SCErrorSet(status);
112 return NULL;
113 }
114
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 */
120 }
121 _SCErrorSet(sc_status);
122 return NULL;
123 }
124
125 /* un-serialize the dictionary */
126 if (!_SCUnserialize((CFPropertyListRef *)&dict, xmlDictRef, xmlDictLen)) {
127 _SCErrorSet(kSCStatusFailed);
128 return NULL;
129 }
130
131 SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" value = %@"), dict);
132
133 return dict;
134 }
135
136
137 CFPropertyListRef
138 SCDynamicStoreCopyValue(SCDynamicStoreRef store, CFStringRef key)
139 {
140 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
141 kern_return_t status;
142 CFDataRef xmlKey; /* key (XML serialized) */
143 xmlData_t myKeyRef; /* key (serialized) */
144 CFIndex myKeyLen;
145 xmlDataOut_t xmlDataRef; /* data (serialized) */
146 CFIndex xmlDataLen;
147 CFPropertyListRef data; /* data (un-serialized) */
148 int newInstance;
149 int sc_status;
150
151 SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCDynamicStoreCopyValue:"));
152 SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" key = %@"), key);
153
154 if (!store) {
155 /* sorry, you must provide a session */
156 _SCErrorSet(kSCStatusNoStoreSession);
157 return NULL;
158 }
159
160 if (storePrivate->server == MACH_PORT_NULL) {
161 _SCErrorSet(kSCStatusNoStoreServer);
162 return NULL; /* you must have an open session to play */
163 }
164
165 /* serialize the key */
166 if (!_SCSerialize(key, &xmlKey, (void **)&myKeyRef, &myKeyLen)) {
167 _SCErrorSet(kSCStatusFailed);
168 return NULL;
169 }
170
171 /* send the key & fetch the associated data from the server */
172 status = configget(storePrivate->server,
173 myKeyRef,
174 myKeyLen,
175 &xmlDataRef,
176 (int *)&xmlDataLen,
177 &newInstance,
178 (int *)&sc_status);
179
180 /* clean up */
181 CFRelease(xmlKey);
182
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;
188 _SCErrorSet(status);
189 return NULL;
190 }
191
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 */
197 }
198 _SCErrorSet(sc_status);
199 return NULL;
200 }
201
202 /* un-serialize the data */
203 if (!_SCUnserialize(&data, xmlDataRef, xmlDataLen)) {
204 _SCErrorSet(kSCStatusFailed);
205 return NULL;
206 }
207
208 SCLog(_sc_verbose, LOG_DEBUG, CFSTR(" value = %@"), data);
209
210 return data;
211 }