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 _SCDGet(SCDSessionRef session
, CFStringRef key
, SCDHandleRef
*handle
)
29 SCDSessionPrivateRef sessionPrivate
= (SCDSessionPrivateRef
)session
;
34 SCDLog(LOG_DEBUG
, CFSTR("_SCDGet:"));
35 SCDLog(LOG_DEBUG
, CFSTR(" key = %@"), key
);
37 if ((session
== NULL
) || (sessionPrivate
->server
== MACH_PORT_NULL
)) {
41 dict
= CFDictionaryGetValue(cacheData
, key
);
42 if ((dict
== NULL
) || (CFDictionaryContainsKey(dict
, kSCDData
) == FALSE
)) {
43 /* key doesn't exist (or data never defined) */
47 /* Create a new handle associated with the cached data */
48 *handle
= SCDHandleInit();
50 /* Return the data associated with the key */
51 SCDHandleSetData(*handle
, CFDictionaryGetValue(dict
, kSCDData
));
53 /* Return the instance number associated with the key */
54 num
= CFDictionaryGetValue(dict
, kSCDInstance
);
55 (void) CFNumberGetValue(num
, kCFNumberIntType
, &dictInstance
);
56 _SCDHandleSetInstance(*handle
, dictInstance
);
58 SCDLog(LOG_DEBUG
, CFSTR(" data = %@"), SCDHandleGetData(*handle
));
59 SCDLog(LOG_DEBUG
, CFSTR(" instance = %d"), SCDHandleGetInstance(*handle
));
66 _configget(mach_port_t server
,
67 xmlData_t keyRef
, /* raw XML bytes */
68 mach_msg_type_number_t keyLen
,
69 xmlDataOut_t
*dataRef
, /* raw XML bytes */
70 mach_msg_type_number_t
*dataLen
,
76 serverSessionRef mySession
= getSession(server
);
77 CFDataRef xmlKey
; /* key (XML serialized) */
78 CFStringRef key
; /* key (un-serialized) */
79 CFDataRef xmlData
; /* data (XML serialized) */
83 SCDLog(LOG_DEBUG
, CFSTR("Get key from configuration database."));
84 SCDLog(LOG_DEBUG
, CFSTR(" server = %d"), server
);
86 /* un-serialize the key */
87 xmlKey
= CFDataCreate(NULL
, keyRef
, keyLen
);
88 status
= vm_deallocate(mach_task_self(), (vm_address_t
)keyRef
, keyLen
);
89 if (status
!= KERN_SUCCESS
) {
90 SCDLog(LOG_DEBUG
, CFSTR("vm_deallocate(): %s"), mach_error_string(status
));
91 /* non-fatal???, proceed */
93 key
= CFPropertyListCreateFromXMLData(NULL
,
95 kCFPropertyListImmutable
,
99 SCDLog(LOG_DEBUG
, CFSTR("CFPropertyListCreateFromXMLData() key: %s"), xmlError
);
100 *scd_status
= SCD_FAILED
;
104 *scd_status
= _SCDGet(mySession
->session
, key
, &handle
);
106 if (*scd_status
!= SCD_OK
) {
113 * serialize the data, copy it into an allocated buffer which will be
114 * released when it is returned as part of a Mach message.
116 xmlData
= CFPropertyListCreateXMLData(NULL
, SCDHandleGetData(handle
));
117 *dataLen
= CFDataGetLength(xmlData
);
118 status
= vm_allocate(mach_task_self(), (void *)dataRef
, *dataLen
, TRUE
);
119 if (status
!= KERN_SUCCESS
) {
120 SCDLog(LOG_DEBUG
, CFSTR("vm_allocate(): %s"), mach_error_string(status
));
121 *scd_status
= SCD_FAILED
;
128 bcopy((char *)CFDataGetBytePtr(xmlData
), *dataRef
, *dataLen
);
132 * return the instance number associated with the returned data.
134 *newInstance
= SCDHandleGetInstance(handle
);
136 SCDHandleRelease(handle
);