]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCDAdd.c
configd-1109.40.9.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / SCDAdd.c
1 /*
2 * Copyright (c) 2000-2005, 2009-2011, 2013, 2016, 2017, 2019 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 retry :
77
78 /* send the key & data to the server */
79 status = configadd_s(storePrivate->server,
80 myKeyRef,
81 (mach_msg_type_number_t)myKeyLen,
82 myDataRef,
83 (mach_msg_type_number_t)myDataLen,
84 &newInstance,
85 (int *)&sc_status);
86
87 if (__SCDynamicStoreCheckRetryAndHandleError(store,
88 status,
89 &sc_status,
90 "SCDynamicStoreAddTemporaryValue configadd_s()")) {
91 goto retry;
92 }
93
94 /* clean up */
95 CFRelease(utfKey);
96 CFRelease(xmlData);
97
98 if (sc_status != kSCStatusOK) {
99 _SCErrorSet(sc_status);
100 return FALSE;
101 }
102
103 return TRUE;
104 }
105
106 Boolean
107 SCDynamicStoreAddValue(SCDynamicStoreRef store, CFStringRef key, CFPropertyListRef value)
108 {
109 SCDynamicStorePrivateRef storePrivate;
110 kern_return_t status;
111 CFDataRef utfKey; /* serialized key */
112 xmlData_t myKeyRef;
113 CFIndex myKeyLen;
114 CFDataRef xmlData; /* serialized data */
115 xmlData_t myDataRef;
116 CFIndex myDataLen;
117 int newInstance;
118 int sc_status;
119
120 if (store == NULL) {
121 store = __SCDynamicStoreNullSession();
122 if (store == NULL) {
123 /* sorry, you must provide a session */
124 _SCErrorSet(kSCStatusNoStoreSession);
125 return FALSE;
126 }
127 }
128
129 storePrivate = (SCDynamicStorePrivateRef)store;
130 if (storePrivate->server == MACH_PORT_NULL) {
131 /* sorry, you must have an open session to play */
132 _SCErrorSet(kSCStatusNoStoreServer);
133 return FALSE;
134 }
135
136 /* serialize the key */
137 if (!_SCSerializeString(key, &utfKey, (void **)&myKeyRef, &myKeyLen)) {
138 _SCErrorSet(kSCStatusFailed);
139 return FALSE;
140 }
141
142 /* serialize the data */
143 if (!_SCSerialize(value, &xmlData, (void **)&myDataRef, &myDataLen)) {
144 CFRelease(utfKey);
145 _SCErrorSet(kSCStatusFailed);
146 return FALSE;
147 }
148
149 retry :
150
151 /* send the key & data to the server */
152 status = configadd(storePrivate->server,
153 myKeyRef,
154 (mach_msg_type_number_t)myKeyLen,
155 myDataRef,
156 (mach_msg_type_number_t)myDataLen,
157 &newInstance,
158 (int *)&sc_status);
159
160 if (__SCDynamicStoreCheckRetryAndHandleError(store,
161 status,
162 &sc_status,
163 "SCDynamicStoreAddValue configadd()")) {
164 goto retry;
165 }
166
167 /* clean up */
168 CFRelease(utfKey);
169 CFRelease(xmlData);
170
171 if (sc_status != kSCStatusOK) {
172 _SCErrorSet(sc_status);
173 return FALSE;
174 }
175
176 return TRUE;
177 }