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@
23 #include <sys/types.h>
26 #include <mach/mach.h>
27 #include <mach/mach_error.h>
29 #include <SystemConfiguration/SCD.h>
30 #include "config.h" /* MiG generated file */
31 #include "SCDPrivate.h"
34 static CFComparisonResult
35 sort_keys(const void *p1
, const void *p2
, void *context
) {
36 CFStringRef key1
= (CFStringRef
)p1
;
37 CFStringRef key2
= (CFStringRef
)p2
;
38 return CFStringCompare(key1
, key2
, 0);
43 SCDList(SCDSessionRef session
, CFStringRef key
, int regexOptions
, CFArrayRef
*subKeys
)
45 SCDSessionPrivateRef sessionPrivate
= (SCDSessionPrivateRef
)session
;
47 CFDataRef xmlKey
; /* serialized key */
50 CFDataRef xmlData
; /* data (XML serialized) */
51 xmlDataOut_t xmlDataRef
; /* serialized data */
55 CFMutableArrayRef sortedKeys
;
58 SCDLog(LOG_DEBUG
, CFSTR("SCDList:"));
59 SCDLog(LOG_DEBUG
, CFSTR(" key = %@"), key
);
60 SCDLog(LOG_DEBUG
, CFSTR(" regexOptions = %0o"), regexOptions
);
63 return SCD_INVALIDARGUMENT
; /* no key specified */
66 if ((session
== NULL
) || (sessionPrivate
->server
== MACH_PORT_NULL
)) {
70 /* serialize the key */
71 xmlKey
= CFPropertyListCreateXMLData(NULL
, key
);
72 myKeyRef
= (xmlData_t
)CFDataGetBytePtr(xmlKey
);
73 myKeyLen
= CFDataGetLength(xmlKey
);
75 /* send the key & fetch the associated data from the server */
76 status
= configlist(sessionPrivate
->server
,
87 if (status
!= KERN_SUCCESS
) {
88 if (status
!= MACH_SEND_INVALID_DEST
)
89 SCDLog(LOG_DEBUG
, CFSTR("configlist(): %s"), mach_error_string(status
));
90 (void) mach_port_destroy(mach_task_self(), sessionPrivate
->server
);
91 sessionPrivate
->server
= MACH_PORT_NULL
;
95 if (scd_status
!= SCD_OK
) {
96 status
= vm_deallocate(mach_task_self(), (vm_address_t
)xmlDataRef
, xmlDataLen
);
97 if (status
!= KERN_SUCCESS
) {
98 SCDLog(LOG_DEBUG
, CFSTR("vm_deallocate(): %s"), mach_error_string(status
));
99 /* non-fatal???, proceed */
105 /* un-serialize the list of keys */
106 xmlData
= CFDataCreate(NULL
, xmlDataRef
, xmlDataLen
);
107 status
= vm_deallocate(mach_task_self(), (vm_address_t
)xmlDataRef
, xmlDataLen
);
108 if (status
!= KERN_SUCCESS
) {
109 SCDLog(LOG_DEBUG
, CFSTR("vm_deallocate(): %s"), mach_error_string(status
));
110 /* non-fatal???, proceed */
112 allKeys
= CFPropertyListCreateFromXMLData(NULL
,
114 kCFPropertyListImmutable
,
118 SCDLog(LOG_DEBUG
, CFSTR("CFPropertyListCreateFromXMLData() list: %s"), xmlError
);
122 myKeyLen
= CFArrayGetCount(allKeys
);
123 sortedKeys
= CFArrayCreateMutableCopy(NULL
, myKeyLen
, allKeys
);
125 CFArraySortValues(sortedKeys
,
126 CFRangeMake(0, myKeyLen
),
130 *subKeys
= sortedKeys
;