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@
27 _SCDAddSession(SCDSessionRef session
, CFStringRef key
, SCDHandleRef handle
)
29 SCDSessionPrivateRef sessionPrivate
= (SCDSessionPrivateRef
)session
;
30 SCDStatus scd_status
= SCD_OK
;
31 CFStringRef sessionKey
;
33 CFMutableDictionaryRef newDict
;
35 CFMutableArrayRef newKeys
;
37 SCDLog(LOG_DEBUG
, CFSTR("_SCDAddSession:"));
38 SCDLog(LOG_DEBUG
, CFSTR(" key = %@"), key
);
39 SCDLog(LOG_DEBUG
, CFSTR(" data = %@"), SCDHandleGetData(handle
));
41 if ((session
== NULL
) || (sessionPrivate
->server
== MACH_PORT_NULL
)) {
42 return SCD_NOSESSION
; /* you can't do anything with a closed session */
48 scd_status
= _SCDAdd(session
, key
, handle
);
49 if (scd_status
!= SCD_OK
) {
50 SCDLog(LOG_DEBUG
, CFSTR(" _SCDAdd(): %s"), SCDError(scd_status
));
55 * 2. Create the session key
57 sessionKey
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("%d"), sessionPrivate
->server
);
60 * 3. Add this key to my list of per-session keys
62 dict
= CFDictionaryGetValue(sessionData
, sessionKey
);
63 keys
= CFDictionaryGetValue(dict
, kSCDSessionKeys
);
65 (CFArrayGetFirstIndexOfValue(keys
,
66 CFRangeMake(0, CFArrayGetCount(keys
)),
69 * if no session keys defined "or" keys defined but not
73 /* this is a new session key */
74 newKeys
= CFArrayCreateMutableCopy(NULL
, 0, keys
);
76 /* this is an additional session key */
77 newKeys
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
79 CFArrayAppendValue(newKeys
, key
);
81 /* update session dictionary */
82 newDict
= CFDictionaryCreateMutableCopy(NULL
, 0, dict
);
83 CFDictionarySetValue(newDict
, kSCDSessionKeys
, newKeys
);
85 CFDictionarySetValue(sessionData
, sessionKey
, newDict
);
90 * 4. Mark the key as a "session" key and track the creator.
92 dict
= CFDictionaryGetValue(cacheData
, key
);
93 newDict
= CFDictionaryCreateMutableCopy(NULL
, 0, dict
);
94 CFDictionarySetValue(newDict
, kSCDSession
, sessionKey
);
95 CFDictionarySetValue(cacheData
, key
, newDict
);
98 CFRelease(sessionKey
);
104 _configadd_s(mach_port_t server
,
105 xmlData_t keyRef
, /* raw XML bytes */
106 mach_msg_type_number_t keyLen
,
107 xmlData_t dataRef
, /* raw XML bytes */
108 mach_msg_type_number_t dataLen
,
113 kern_return_t status
;
114 serverSessionRef mySession
= getSession(server
);
115 CFDataRef xmlKey
; /* key (XML serialized) */
116 CFStringRef key
; /* key (un-serialized) */
117 CFDataRef xmlData
; /* data (XML serialized) */
118 CFPropertyListRef data
; /* data (un-serialized) */
120 CFStringRef xmlError
;
122 SCDLog(LOG_DEBUG
, CFSTR("Add (session) key to configuration database."));
123 SCDLog(LOG_DEBUG
, CFSTR(" server = %d"), server
);
125 /* un-serialize the key */
126 xmlKey
= CFDataCreate(NULL
, keyRef
, keyLen
);
127 status
= vm_deallocate(mach_task_self(), (vm_address_t
)keyRef
, keyLen
);
128 if (status
!= KERN_SUCCESS
) {
129 SCDLog(LOG_DEBUG
, CFSTR("vm_deallocate(): %s"), mach_error_string(status
));
130 /* non-fatal???, proceed */
132 key
= CFPropertyListCreateFromXMLData(NULL
,
134 kCFPropertyListImmutable
,
138 SCDLog(LOG_DEBUG
, CFSTR("CFPropertyListCreateFromXMLData() key: %s"), xmlError
);
139 *scd_status
= SCD_FAILED
;
143 /* un-serialize the data */
144 xmlData
= CFDataCreate(NULL
, dataRef
, dataLen
);
145 status
= vm_deallocate(mach_task_self(), (vm_address_t
)dataRef
, dataLen
);
146 if (status
!= KERN_SUCCESS
) {
147 SCDLog(LOG_DEBUG
, CFSTR("vm_deallocate(): %s"), mach_error_string(status
));
148 /* non-fatal???, proceed */
150 data
= CFPropertyListCreateFromXMLData(NULL
,
152 kCFPropertyListImmutable
,
156 SCDLog(LOG_DEBUG
, CFSTR("CFPropertyListCreateFromXMLData() data: %s"), xmlError
);
158 *scd_status
= SCD_FAILED
;
162 handle
= SCDHandleInit();
163 SCDHandleSetData(handle
, data
);
164 *scd_status
= _SCDAddSession(mySession
->session
, key
, handle
);
165 if (*scd_status
== SCD_OK
) {
166 *newInstance
= SCDHandleGetInstance(handle
);
168 SCDHandleRelease(handle
);