2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
24 * Modification History
26 * June 1, 2001 Allan Nathanson <ajn@apple.com>
27 * - public API conversion
29 * October 17, 2000 Allan Nathanson <ajn@apple.com>
37 __SCDynamicStoreAddTemporaryValue(SCDynamicStoreRef store
, CFStringRef key
, CFPropertyListRef value
)
39 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
40 int sc_status
= kSCStatusOK
;
41 CFStringRef sessionKey
;
43 CFMutableDictionaryRef newDict
;
45 CFMutableArrayRef newKeys
;
47 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("__SCDynamicStoreAddTemporaryValue:"));
48 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" key = %@"), key
);
49 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" value = %@"), value
);
51 if (!store
|| (storePrivate
->server
== MACH_PORT_NULL
)) {
52 return kSCStatusNoStoreSession
; /* you must have an open session to play */
58 sc_status
= __SCDynamicStoreAddValue(store
, key
, value
);
59 if (sc_status
!= kSCStatusOK
) {
60 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" __SCDynamicStoreAddValue(): %s"), SCErrorString(sc_status
));
65 * 2. Create the session key
67 sessionKey
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%d"), storePrivate
->server
);
70 * 3. Add this key to my list of per-session keys
72 dict
= CFDictionaryGetValue(sessionData
, sessionKey
);
73 keys
= CFDictionaryGetValue(dict
, kSCDSessionKeys
);
75 (CFArrayGetFirstIndexOfValue(keys
,
76 CFRangeMake(0, CFArrayGetCount(keys
)),
79 * if no session keys defined "or" keys defined but not
83 /* this is a new session key */
84 newKeys
= CFArrayCreateMutableCopy(NULL
, 0, keys
);
86 /* this is an additional session key */
87 newKeys
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
89 CFArrayAppendValue(newKeys
, key
);
91 /* update session dictionary */
92 newDict
= CFDictionaryCreateMutableCopy(NULL
, 0, dict
);
93 CFDictionarySetValue(newDict
, kSCDSessionKeys
, newKeys
);
95 CFDictionarySetValue(sessionData
, sessionKey
, newDict
);
100 * 4. Mark the key as a "session" key and track the creator.
102 dict
= CFDictionaryGetValue(storeData
, key
);
103 newDict
= CFDictionaryCreateMutableCopy(NULL
, 0, dict
);
104 CFDictionarySetValue(newDict
, kSCDSession
, sessionKey
);
105 CFDictionarySetValue(storeData
, key
, newDict
);
108 CFRelease(sessionKey
);
114 _configadd_s(mach_port_t server
,
115 xmlData_t keyRef
, /* raw XML bytes */
116 mach_msg_type_number_t keyLen
,
117 xmlData_t dataRef
, /* raw XML bytes */
118 mach_msg_type_number_t dataLen
,
123 kern_return_t status
;
124 serverSessionRef mySession
= getSession(server
);
125 CFDataRef xmlKey
; /* key (XML serialized) */
126 CFStringRef key
; /* key (un-serialized) */
127 CFDataRef xmlData
; /* data (XML serialized) */
128 CFPropertyListRef data
; /* data (un-serialized) */
129 CFStringRef xmlError
;
131 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("Add (session) key to configuration database."));
132 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" server = %d"), server
);
134 *sc_status
= kSCStatusOK
;
136 /* un-serialize the key */
137 xmlKey
= CFDataCreate(NULL
, keyRef
, keyLen
);
138 status
= vm_deallocate(mach_task_self(), (vm_address_t
)keyRef
, keyLen
);
139 if (status
!= KERN_SUCCESS
) {
140 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("vm_deallocate(): %s"), mach_error_string(status
));
141 /* non-fatal???, proceed */
143 key
= CFPropertyListCreateFromXMLData(NULL
,
145 kCFPropertyListImmutable
,
150 SCLog(_configd_verbose
, LOG_DEBUG
,
151 CFSTR("CFPropertyListCreateFromXMLData() key: %@"),
155 *sc_status
= kSCStatusFailed
;
156 } else if (!isA_CFString(key
)) {
157 *sc_status
= kSCStatusInvalidArgument
;
160 /* un-serialize the data */
161 xmlData
= CFDataCreate(NULL
, dataRef
, dataLen
);
162 status
= vm_deallocate(mach_task_self(), (vm_address_t
)dataRef
, dataLen
);
163 if (status
!= KERN_SUCCESS
) {
164 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("vm_deallocate(): %s"), mach_error_string(status
));
165 /* non-fatal???, proceed */
167 data
= CFPropertyListCreateFromXMLData(NULL
,
169 kCFPropertyListImmutable
,
174 SCLog(_configd_verbose
, LOG_DEBUG
,
175 CFSTR("CFPropertyListCreateFromXMLData() data: %@"),
179 *sc_status
= kSCStatusFailed
;
180 } else if (!isA_CFPropertyList(data
)) {
181 *sc_status
= kSCStatusInvalidArgument
;
184 if (*sc_status
!= kSCStatusOK
) {
185 if (key
) CFRelease(key
);
186 if (data
) CFRelease(data
);
190 *sc_status
= __SCDynamicStoreAddTemporaryValue(mySession
->store
, key
, data
);
191 if (*sc_status
== kSCStatusOK
) {