]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCDAdd.c
configd-130.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / SCDAdd.c
1 /*
2 * Copyright (c) 2000-2003 Apple Computer, 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 Boolean
43 SCDynamicStoreAddTemporaryValue(SCDynamicStoreRef store, CFStringRef key, CFPropertyListRef value)
44 {
45 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
46 kern_return_t status;
47 CFDataRef utfKey; /* serialized key */
48 xmlData_t myKeyRef;
49 CFIndex myKeyLen;
50 CFDataRef xmlData; /* serialized data */
51 xmlData_t myDataRef;
52 CFIndex myDataLen;
53 int newInstance;
54 int sc_status;
55
56 if (store == NULL) {
57 /* sorry, you must provide a session */
58 _SCErrorSet(kSCStatusNoStoreSession);
59 }
60
61 if (storePrivate->server == MACH_PORT_NULL) {
62 /* sorry, you must have an open session to play */
63 _SCErrorSet(kSCStatusNoStoreServer);
64 return FALSE;
65 }
66
67 /* serialize the key */
68 if (!_SCSerializeString(key, &utfKey, (void **)&myKeyRef, &myKeyLen)) {
69 _SCErrorSet(kSCStatusFailed);
70 return FALSE;
71 }
72
73 /* serialize the data */
74 if (!_SCSerialize(value, &xmlData, (void **)&myDataRef, &myDataLen)) {
75 CFRelease(utfKey);
76 _SCErrorSet(kSCStatusFailed);
77 return FALSE;
78 }
79
80 /* send the key & data to the server */
81 status = configadd_s(storePrivate->server,
82 myKeyRef,
83 myKeyLen,
84 myDataRef,
85 myDataLen,
86 &newInstance,
87 (int *)&sc_status);
88
89 /* clean up */
90 CFRelease(utfKey);
91 CFRelease(xmlData);
92
93 if (status != KERN_SUCCESS) {
94 #ifdef DEBUG
95 if (status != MACH_SEND_INVALID_DEST)
96 SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCDynamicStoreAddTemporaryValue configadd_s(): %s"), mach_error_string(status));
97 #endif /* DEBUG */
98 (void) mach_port_destroy(mach_task_self(), storePrivate->server);
99 storePrivate->server = MACH_PORT_NULL;
100 _SCErrorSet(status);
101 return FALSE;
102 }
103
104 if (sc_status != kSCStatusOK) {
105 _SCErrorSet(sc_status);
106 return FALSE;
107 }
108
109 return TRUE;
110 }
111
112 Boolean
113 SCDynamicStoreAddValue(SCDynamicStoreRef store, CFStringRef key, CFPropertyListRef value)
114 {
115 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
116 kern_return_t status;
117 CFDataRef utfKey; /* serialized key */
118 xmlData_t myKeyRef;
119 CFIndex myKeyLen;
120 CFDataRef xmlData; /* serialized data */
121 xmlData_t myDataRef;
122 CFIndex myDataLen;
123 int newInstance;
124 int sc_status;
125
126 if (store == NULL) {
127 /* sorry, you must provide a session */
128 _SCErrorSet(kSCStatusNoStoreSession);
129 return FALSE;
130 }
131
132 if (storePrivate->server == MACH_PORT_NULL) {
133 /* sorry, you must have an open session to play */
134 _SCErrorSet(kSCStatusNoStoreServer);
135 return FALSE;
136 }
137
138 /* serialize the key */
139 if (!_SCSerializeString(key, &utfKey, (void **)&myKeyRef, &myKeyLen)) {
140 _SCErrorSet(kSCStatusFailed);
141 return FALSE;
142 }
143
144 /* serialize the data */
145 if (!_SCSerialize(value, &xmlData, (void **)&myDataRef, &myDataLen)) {
146 CFRelease(utfKey);
147 _SCErrorSet(kSCStatusFailed);
148 return FALSE;
149 }
150
151 /* send the key & data to the server */
152 status = configadd(storePrivate->server,
153 myKeyRef,
154 myKeyLen,
155 myDataRef,
156 myDataLen,
157 &newInstance,
158 (int *)&sc_status);
159
160 /* clean up */
161 CFRelease(utfKey);
162 CFRelease(xmlData);
163
164 if (status != KERN_SUCCESS) {
165 #ifdef DEBUG
166 if (status != MACH_SEND_INVALID_DEST)
167 SCLog(_sc_verbose, LOG_DEBUG, CFSTR("SCDynamicStoreAddValue configadd(): %s"), mach_error_string(status));
168 #endif /* DEBUG */
169 (void) mach_port_destroy(mach_task_self(), storePrivate->server);
170 storePrivate->server = MACH_PORT_NULL;
171 _SCErrorSet(status);
172 return FALSE;
173 }
174
175 if (sc_status != kSCStatusOK) {
176 _SCErrorSet(sc_status);
177 return FALSE;
178 }
179
180 return TRUE;
181 }