2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 * Modification History
27 * June 1, 2001 Allan Nathanson <ajn@apple.com>
28 * - public API conversion
30 * October 17, 2000 Allan Nathanson <ajn@apple.com>
39 __SCDynamicStoreAddTemporaryValue(SCDynamicStoreRef store
, CFStringRef key
, CFDataRef value
)
41 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
42 int sc_status
= kSCStatusOK
;
43 CFStringRef sessionKey
;
45 CFMutableDictionaryRef newDict
;
47 CFMutableArrayRef newKeys
;
49 if (_configd_verbose
) {
50 CFPropertyListRef val
;
52 (void) _SCUnserialize(&val
, value
, NULL
, NULL
);
53 SCLog(TRUE
, LOG_DEBUG
, CFSTR("__SCDynamicStoreAddTemporaryValue:"));
54 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" key = %@"), key
);
55 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" value = %@"), val
);
59 if (!store
|| (storePrivate
->server
== MACH_PORT_NULL
)) {
60 return kSCStatusNoStoreSession
; /* you must have an open session to play */
66 sc_status
= __SCDynamicStoreAddValue(store
, key
, value
);
67 if (sc_status
!= kSCStatusOK
) {
68 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" __SCDynamicStoreAddValue(): %s"), SCErrorString(sc_status
));
73 * 2. Create the session key
75 sessionKey
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%d"), storePrivate
->server
);
78 * 3. Add this key to my list of per-session keys
80 dict
= CFDictionaryGetValue(sessionData
, sessionKey
);
81 keys
= CFDictionaryGetValue(dict
, kSCDSessionKeys
);
83 (CFArrayGetFirstIndexOfValue(keys
,
84 CFRangeMake(0, CFArrayGetCount(keys
)),
87 * if no session keys defined "or" keys defined but not
91 /* this is a new session key */
92 newKeys
= CFArrayCreateMutableCopy(NULL
, 0, keys
);
94 /* this is an additional session key */
95 newKeys
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
97 CFArrayAppendValue(newKeys
, key
);
99 /* update session dictionary */
100 newDict
= CFDictionaryCreateMutableCopy(NULL
, 0, dict
);
101 CFDictionarySetValue(newDict
, kSCDSessionKeys
, newKeys
);
103 CFDictionarySetValue(sessionData
, sessionKey
, newDict
);
108 * 4. Mark the key as a "session" key and track the creator.
110 dict
= CFDictionaryGetValue(storeData
, key
);
111 newDict
= CFDictionaryCreateMutableCopy(NULL
, 0, dict
);
112 CFDictionarySetValue(newDict
, kSCDSession
, sessionKey
);
113 CFDictionarySetValue(storeData
, key
, newDict
);
116 CFRelease(sessionKey
);
123 _configadd_s(mach_port_t server
,
124 xmlData_t keyRef
, /* raw XML bytes */
125 mach_msg_type_number_t keyLen
,
126 xmlData_t dataRef
, /* raw XML bytes */
127 mach_msg_type_number_t dataLen
,
132 serverSessionRef mySession
= getSession(server
);
133 CFStringRef key
; /* key (un-serialized) */
134 CFDataRef data
; /* data (un-serialized) */
136 if (_configd_verbose
) {
137 SCLog(TRUE
, LOG_DEBUG
, CFSTR("Add (session) key to configuration database."));
138 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" server = %d"), server
);
141 *sc_status
= kSCStatusOK
;
143 /* un-serialize the key */
144 if (!_SCUnserializeString(&key
, NULL
, (void *)keyRef
, keyLen
)) {
145 *sc_status
= kSCStatusFailed
;
146 } else if (!isA_CFString(key
)) {
147 *sc_status
= kSCStatusInvalidArgument
;
150 /* un-serialize the data */
151 if (!_SCUnserializeData(&data
, (void *)dataRef
, dataLen
)) {
152 *sc_status
= kSCStatusFailed
;
156 *sc_status
= kSCStatusNoStoreSession
; /* you must have an open session to play */
159 if (*sc_status
!= kSCStatusOK
) {
160 if (key
) CFRelease(key
);
161 if (data
) CFRelease(data
);
165 *sc_status
= __SCDynamicStoreAddTemporaryValue(mySession
->store
, key
, data
);
166 if (*sc_status
== kSCStatusOK
) {