2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
27 * Modification History
29 * June 1, 2001 Allan Nathanson <ajn@apple.com>
30 * - public API conversion
32 * October 17, 2000 Allan Nathanson <ajn@apple.com>
41 __SCDynamicStoreAddTemporaryValue(SCDynamicStoreRef store
, CFStringRef key
, CFDataRef value
)
43 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
44 int sc_status
= kSCStatusOK
;
45 CFStringRef sessionKey
;
47 CFMutableDictionaryRef newDict
;
49 CFMutableArrayRef newKeys
;
51 if (_configd_verbose
) {
52 CFPropertyListRef val
;
54 (void) _SCUnserialize(&val
, value
, NULL
, NULL
);
55 SCLog(TRUE
, LOG_DEBUG
, CFSTR("__SCDynamicStoreAddTemporaryValue:"));
56 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" key = %@"), key
);
57 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" value = %@"), val
);
61 if (!store
|| (storePrivate
->server
== MACH_PORT_NULL
)) {
62 return kSCStatusNoStoreSession
; /* you must have an open session to play */
68 sc_status
= __SCDynamicStoreAddValue(store
, key
, value
);
69 if (sc_status
!= kSCStatusOK
) {
70 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" __SCDynamicStoreAddValue(): %s"), SCErrorString(sc_status
));
75 * 2. Create the session key
77 sessionKey
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%d"), storePrivate
->server
);
80 * 3. Add this key to my list of per-session keys
82 dict
= CFDictionaryGetValue(sessionData
, sessionKey
);
83 keys
= CFDictionaryGetValue(dict
, kSCDSessionKeys
);
85 (CFArrayGetFirstIndexOfValue(keys
,
86 CFRangeMake(0, CFArrayGetCount(keys
)),
89 * if no session keys defined "or" keys defined but not
93 /* this is a new session key */
94 newKeys
= CFArrayCreateMutableCopy(NULL
, 0, keys
);
96 /* this is an additional session key */
97 newKeys
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
99 CFArrayAppendValue(newKeys
, key
);
101 /* update session dictionary */
102 newDict
= CFDictionaryCreateMutableCopy(NULL
, 0, dict
);
103 CFDictionarySetValue(newDict
, kSCDSessionKeys
, newKeys
);
105 CFDictionarySetValue(sessionData
, sessionKey
, newDict
);
110 * 4. Mark the key as a "session" key and track the creator.
112 dict
= CFDictionaryGetValue(storeData
, key
);
113 newDict
= CFDictionaryCreateMutableCopy(NULL
, 0, dict
);
114 CFDictionarySetValue(newDict
, kSCDSession
, sessionKey
);
115 CFDictionarySetValue(storeData
, key
, newDict
);
118 CFRelease(sessionKey
);
125 _configadd_s(mach_port_t server
,
126 xmlData_t keyRef
, /* raw XML bytes */
127 mach_msg_type_number_t keyLen
,
128 xmlData_t dataRef
, /* raw XML bytes */
129 mach_msg_type_number_t dataLen
,
134 serverSessionRef mySession
= getSession(server
);
135 CFStringRef key
; /* key (un-serialized) */
136 CFDataRef data
; /* data (un-serialized) */
138 if (_configd_verbose
) {
139 SCLog(TRUE
, LOG_DEBUG
, CFSTR("Add (session) key to configuration database."));
140 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" server = %d"), server
);
143 *sc_status
= kSCStatusOK
;
145 /* un-serialize the key */
146 if (!_SCUnserializeString(&key
, NULL
, (void *)keyRef
, keyLen
)) {
147 *sc_status
= kSCStatusFailed
;
148 } else if (!isA_CFString(key
)) {
149 *sc_status
= kSCStatusInvalidArgument
;
152 /* un-serialize the data */
153 if (!_SCUnserializeData(&data
, (void *)dataRef
, dataLen
)) {
154 *sc_status
= kSCStatusFailed
;
158 *sc_status
= kSCStatusNoStoreSession
; /* you must have an open session to play */
161 if (*sc_status
!= kSCStatusOK
) {
162 if (key
) CFRelease(key
);
163 if (data
) CFRelease(data
);
167 *sc_status
= __SCDynamicStoreAddTemporaryValue(mySession
->store
, key
, data
);
168 if (*sc_status
== kSCStatusOK
) {