]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCDAdd.c
3142f6686d904d9fc7e6b90c9633f9d2aebd0482
[apple/configd.git] / SystemConfiguration.fproj / SCDAdd.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 Boolean
38 SCDynamicStoreAddTemporaryValue(SCDynamicStoreRef store, CFStringRef key, CFPropertyListRef value)
39 {
40 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
41 kern_return_t status;
42 CFDataRef utfKey; /* serialized key */
43 xmlData_t myKeyRef;
44 CFIndex myKeyLen;
45 CFDataRef xmlData; /* serialized data */
46 xmlData_t myDataRef;
47 CFIndex myDataLen;
48 int newInstance;
49 int sc_status;
50
51 if (store == NULL) {
52 /* sorry, you must provide a session */
53 _SCErrorSet(kSCStatusNoStoreSession);
54 return FALSE;
55 }
56
57 if (storePrivate->server == MACH_PORT_NULL) {
58 /* sorry, you must have an open session to play */
59 _SCErrorSet(kSCStatusNoStoreServer);
60 return FALSE;
61 }
62
63 /* serialize the key */
64 if (!_SCSerializeString(key, &utfKey, (void **)&myKeyRef, &myKeyLen)) {
65 _SCErrorSet(kSCStatusFailed);
66 return FALSE;
67 }
68
69 /* serialize the data */
70 if (!_SCSerialize(value, &xmlData, (void **)&myDataRef, &myDataLen)) {
71 CFRelease(utfKey);
72 _SCErrorSet(kSCStatusFailed);
73 return FALSE;
74 }
75
76 os_activity_scope(storePrivate->activity);
77
78 retry :
79
80 /* send the key & data to the server */
81 status = configadd_s(storePrivate->server,
82 myKeyRef,
83 (mach_msg_type_number_t)myKeyLen,
84 myDataRef,
85 (mach_msg_type_number_t)myDataLen,
86 &newInstance,
87 (int *)&sc_status);
88
89 if (__SCDynamicStoreCheckRetryAndHandleError(store,
90 status,
91 &sc_status,
92 "SCDynamicStoreAddTemporaryValue configadd_s()")) {
93 goto retry;
94 }
95
96 /* clean up */
97 CFRelease(utfKey);
98 CFRelease(xmlData);
99
100 if (sc_status != kSCStatusOK) {
101 _SCErrorSet(sc_status);
102 return FALSE;
103 }
104
105 return TRUE;
106 }
107
108 Boolean
109 SCDynamicStoreAddValue(SCDynamicStoreRef store, CFStringRef key, CFPropertyListRef value)
110 {
111 SCDynamicStorePrivateRef storePrivate;
112 kern_return_t status;
113 CFDataRef utfKey; /* serialized key */
114 xmlData_t myKeyRef;
115 CFIndex myKeyLen;
116 CFDataRef xmlData; /* serialized data */
117 xmlData_t myDataRef;
118 CFIndex myDataLen;
119 int newInstance;
120 int sc_status;
121
122 if (store == NULL) {
123 store = __SCDynamicStoreNullSession();
124 if (store == NULL) {
125 /* sorry, you must provide a session */
126 _SCErrorSet(kSCStatusNoStoreSession);
127 return FALSE;
128 }
129 }
130
131 storePrivate = (SCDynamicStorePrivateRef)store;
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 os_activity_scope(storePrivate->activity);
152
153 retry :
154
155 /* send the key & data to the server */
156 status = configadd(storePrivate->server,
157 myKeyRef,
158 (mach_msg_type_number_t)myKeyLen,
159 myDataRef,
160 (mach_msg_type_number_t)myDataLen,
161 &newInstance,
162 (int *)&sc_status);
163
164 if (__SCDynamicStoreCheckRetryAndHandleError(store,
165 status,
166 &sc_status,
167 "SCDynamicStoreAddValue configadd()")) {
168 goto retry;
169 }
170
171 /* clean up */
172 CFRelease(utfKey);
173 CFRelease(xmlData);
174
175 if (sc_status != kSCStatusOK) {
176 _SCErrorSet(sc_status);
177 return FALSE;
178 }
179
180 return TRUE;
181 }