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 _SCDAdd(SCDSessionRef session
, CFStringRef key
, SCDHandleRef handle
)
29 SCDSessionPrivateRef sessionPrivate
= (SCDSessionPrivateRef
)session
;
30 SCDStatus scd_status
= SCD_OK
;
32 SCDHandleRef tempHandle
;
34 SCDLog(LOG_DEBUG
, CFSTR("_SCDAdd:"));
35 SCDLog(LOG_DEBUG
, CFSTR(" key = %@"), key
);
36 SCDLog(LOG_DEBUG
, CFSTR(" data = %@"), SCDHandleGetData(handle
));
38 if ((session
== NULL
) || (sessionPrivate
->server
== MACH_PORT_NULL
)) {
39 return SCD_NOSESSION
; /* you can't do anything with a closed session */
43 * 1. Determine if the cache lock is currently held
44 * and acquire the lock if necessary.
46 wasLocked
= SCDOptionGet(NULL
, kSCDOptionIsLocked
);
48 scd_status
= _SCDLock(session
);
49 if (scd_status
!= SCD_OK
) {
50 SCDLog(LOG_DEBUG
, CFSTR(" _SCDLock(): %s"), SCDError(scd_status
));
56 * 2. Ensure that this is a new key.
58 scd_status
= _SCDGet(session
, key
, &tempHandle
);
61 /* cache key does not exist, proceed */
65 /* cache key exists, sorry */
66 SCDHandleRelease(tempHandle
);
67 scd_status
= SCD_EXISTS
;
71 SCDLog(LOG_DEBUG
, CFSTR(" _SCDGet(): %s"), SCDError(scd_status
));
76 * 3. Save the new key.
78 scd_status
= _SCDSet(session
, key
, handle
);
81 * 4. Release the lock if we acquired it as part of this request.
92 _configadd(mach_port_t server
,
93 xmlData_t keyRef
, /* raw XML bytes */
94 mach_msg_type_number_t keyLen
,
95 xmlData_t dataRef
, /* raw XML bytes */
96 mach_msg_type_number_t dataLen
,
101 kern_return_t status
;
102 serverSessionRef mySession
= getSession(server
);
103 CFDataRef xmlKey
; /* key (XML serialized) */
104 CFStringRef key
; /* key (un-serialized) */
105 CFDataRef xmlData
; /* data (XML serialized) */
106 CFPropertyListRef data
; /* data (un-serialized) */
108 CFStringRef xmlError
;
110 SCDLog(LOG_DEBUG
, CFSTR("Add key to configuration database."));
111 SCDLog(LOG_DEBUG
, CFSTR(" server = %d"), server
);
113 /* un-serialize the key */
114 xmlKey
= CFDataCreate(NULL
, keyRef
, keyLen
);
115 status
= vm_deallocate(mach_task_self(), (vm_address_t
)keyRef
, keyLen
);
116 if (status
!= KERN_SUCCESS
) {
117 SCDLog(LOG_DEBUG
, CFSTR("vm_deallocate(): %s"), mach_error_string(status
));
118 /* non-fatal???, proceed */
120 key
= CFPropertyListCreateFromXMLData(NULL
,
122 kCFPropertyListImmutable
,
126 SCDLog(LOG_DEBUG
, CFSTR("CFPropertyListCreateFromXMLData() key: %s"), xmlError
);
127 *scd_status
= SCD_FAILED
;
131 /* un-serialize the data */
132 xmlData
= CFDataCreate(NULL
, dataRef
, dataLen
);
133 status
= vm_deallocate(mach_task_self(), (vm_address_t
)dataRef
, dataLen
);
134 if (status
!= KERN_SUCCESS
) {
135 SCDLog(LOG_DEBUG
, CFSTR("vm_deallocate(): %s"), mach_error_string(status
));
136 /* non-fatal???, proceed */
138 data
= CFPropertyListCreateFromXMLData(NULL
,
140 kCFPropertyListImmutable
,
144 SCDLog(LOG_DEBUG
, CFSTR("CFPropertyListCreateFromXMLData() data: %s"), xmlError
);
146 *scd_status
= SCD_FAILED
;
150 handle
= SCDHandleInit();
151 SCDHandleSetData(handle
, data
);
152 *scd_status
= _SCDAdd(mySession
->session
, key
, handle
);
153 if (*scd_status
== SCD_OK
) {
154 *newInstance
= SCDHandleGetInstance(handle
);
156 SCDHandleRelease(handle
);