2 * Copyright (c) 2000-2002 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 serverSessionRef mySession
= getSession(server
);
124 CFStringRef key
; /* key (un-serialized) */
125 CFPropertyListRef data
; /* data (un-serialized) */
127 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("Add (session) key to configuration database."));
128 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" server = %d"), server
);
130 *sc_status
= kSCStatusOK
;
132 /* un-serialize the key */
133 if (!_SCUnserialize((CFPropertyListRef
*)&key
, (void *)keyRef
, keyLen
)) {
134 *sc_status
= kSCStatusFailed
;
137 if (!isA_CFString(key
)) {
138 *sc_status
= kSCStatusInvalidArgument
;
141 /* un-serialize the data */
142 if (!_SCUnserialize((CFPropertyListRef
*)&data
, (void *)dataRef
, dataLen
)) {
143 *sc_status
= kSCStatusFailed
;
146 if (!isA_CFPropertyList(data
)) {
147 *sc_status
= kSCStatusInvalidArgument
;
150 if (*sc_status
!= kSCStatusOK
) {
151 if (key
) CFRelease(key
);
152 if (data
) CFRelease(data
);
156 *sc_status
= __SCDynamicStoreAddTemporaryValue(mySession
->store
, key
, data
);
157 if (*sc_status
== kSCStatusOK
) {