]>
Commit | Line | Data |
---|---|---|
5958d7c0 | 1 | /* |
edebe297 | 2 | * Copyright (c) 2000-2004, 2006, 2007 Apple Inc. All rights reserved. |
5958d7c0 A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
009ee3c6 | 5 | * |
009ee3c6 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
12 | * | |
13 | * The Original Code and all software distributed under the License are | |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
5958d7c0 A |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
009ee3c6 A |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
20 | * | |
5958d7c0 A |
21 | * @APPLE_LICENSE_HEADER_END@ |
22 | */ | |
23 | ||
0fae82ee A |
24 | /* |
25 | * Modification History | |
26 | * | |
27 | * June 1, 2001 Allan Nathanson <ajn@apple.com> | |
28 | * - public API conversion | |
29 | * | |
30 | * March 24, 2000 Allan Nathanson <ajn@apple.com> | |
31 | * - initial revision | |
32 | */ | |
33 | ||
5958d7c0 A |
34 | #include "configd.h" |
35 | #include "session.h" | |
009ee3c6 A |
36 | #include "pattern.h" |
37 | ||
38 | #define N_QUICK 64 | |
5958d7c0 | 39 | |
009ee3c6 | 40 | __private_extern__ |
0fae82ee A |
41 | int |
42 | __SCDynamicStoreCopyKeyList(SCDynamicStoreRef store, CFStringRef key, Boolean isRegex, CFArrayRef *subKeys) | |
5958d7c0 | 43 | { |
009ee3c6 | 44 | SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store; |
0fae82ee | 45 | CFMutableArrayRef keyArray; |
009ee3c6 | 46 | CFIndex storeCnt; |
0fae82ee A |
47 | CFStringRef storeStr; |
48 | CFDictionaryRef storeValue; | |
0fae82ee | 49 | |
edebe297 | 50 | if ((store == NULL) || (storePrivate->server == MACH_PORT_NULL)) { |
0fae82ee | 51 | return kSCStatusNoStoreSession; /* you must have an open session to play */ |
5958d7c0 A |
52 | } |
53 | ||
0fae82ee | 54 | if (isRegex) { |
edebe297 A |
55 | *subKeys = patternCopyMatches(key); |
56 | return (*subKeys != NULL) ? kSCStatusOK : kSCStatusFailed; | |
5958d7c0 A |
57 | } |
58 | ||
dbf6a266 A |
59 | storeCnt = CFDictionaryGetCount(storeData); |
60 | keyArray = CFArrayCreateMutable(NULL, storeCnt, &kCFTypeArrayCallBacks); | |
a5f60add | 61 | if (storeCnt > 0) { |
009ee3c6 A |
62 | int i; |
63 | const void * storeKeys_q[N_QUICK]; | |
64 | const void ** storeKeys = storeKeys_q; | |
65 | const void * storeValues_q[N_QUICK]; | |
66 | const void ** storeValues = storeValues_q; | |
67 | ||
68 | if (storeCnt > (CFIndex)(sizeof(storeKeys_q) / sizeof(CFStringRef))) { | |
69 | storeKeys = CFAllocatorAllocate(NULL, storeCnt * sizeof(CFStringRef), 0); | |
70 | storeValues = CFAllocatorAllocate(NULL, storeCnt * sizeof(CFStringRef), 0); | |
71 | } | |
72 | ||
a5f60add | 73 | CFDictionaryGetKeysAndValues(storeData, storeKeys, storeValues); |
009ee3c6 | 74 | for (i = 0; i < storeCnt; i++) { |
a5f60add A |
75 | storeStr = (CFStringRef)storeKeys[i]; |
76 | storeValue = (CFDictionaryRef)storeValues[i]; | |
edebe297 A |
77 | /* |
78 | * only return those keys which are prefixed by the | |
79 | * provided key string and have data. | |
80 | */ | |
81 | if (((CFStringGetLength(key) == 0) || CFStringHasPrefix(storeStr, key)) && | |
82 | CFDictionaryContainsKey(storeValue, kSCDData)) { | |
83 | CFArrayAppendValue(keyArray, storeStr); | |
5958d7c0 A |
84 | } |
85 | } | |
009ee3c6 A |
86 | |
87 | if (storeKeys != storeKeys_q) { | |
88 | CFAllocatorDeallocate(NULL, storeKeys); | |
89 | CFAllocatorDeallocate(NULL, storeValues); | |
90 | } | |
5958d7c0 | 91 | } |
5958d7c0 | 92 | |
dbf6a266 A |
93 | *subKeys = CFArrayCreateCopy(NULL, keyArray); |
94 | CFRelease(keyArray); | |
0fae82ee | 95 | return kSCStatusOK; |
5958d7c0 A |
96 | } |
97 | ||
98 | ||
009ee3c6 | 99 | __private_extern__ |
5958d7c0 A |
100 | kern_return_t |
101 | _configlist(mach_port_t server, | |
102 | xmlData_t keyRef, /* raw XML bytes */ | |
103 | mach_msg_type_number_t keyLen, | |
0fae82ee | 104 | int isRegex, |
5958d7c0 A |
105 | xmlDataOut_t *listRef, /* raw XML bytes */ |
106 | mach_msg_type_number_t *listLen, | |
0fae82ee | 107 | int *sc_status |
5958d7c0 A |
108 | ) |
109 | { | |
dbf6a266 A |
110 | CFStringRef key = NULL; /* key (un-serialized) */ |
111 | serverSessionRef mySession = getSession(server); | |
a5f60add | 112 | Boolean ok; |
dbf6a266 | 113 | CFArrayRef subKeys; /* array of CFStringRef's */ |
0fae82ee A |
114 | |
115 | *listRef = NULL; | |
116 | *listLen = 0; | |
5958d7c0 A |
117 | |
118 | /* un-serialize the key */ | |
009ee3c6 | 119 | if (!_SCUnserializeString(&key, NULL, (void *)keyRef, keyLen)) { |
0fae82ee | 120 | *sc_status = kSCStatusFailed; |
dbf6a266 | 121 | goto done; |
a5f60add A |
122 | } |
123 | ||
124 | if (!isA_CFString(key)) { | |
0fae82ee | 125 | *sc_status = kSCStatusInvalidArgument; |
dbf6a266 | 126 | goto done; |
009ee3c6 A |
127 | } |
128 | ||
edebe297 | 129 | if (mySession == NULL) { |
009ee3c6 | 130 | *sc_status = kSCStatusNoStoreSession; /* you must have an open session to play */ |
dbf6a266 | 131 | goto done; |
5958d7c0 A |
132 | } |
133 | ||
009ee3c6 | 134 | *sc_status = __SCDynamicStoreCopyKeyList(mySession->store, key, isRegex != 0, &subKeys); |
0fae82ee | 135 | if (*sc_status != kSCStatusOK) { |
dbf6a266 | 136 | goto done; |
5958d7c0 A |
137 | } |
138 | ||
a5f60add A |
139 | /* serialize the list of keys */ |
140 | ok = _SCSerialize(subKeys, NULL, (void **)listRef, (CFIndex *)listLen); | |
5958d7c0 | 141 | CFRelease(subKeys); |
a5f60add | 142 | if (!ok) { |
0fae82ee | 143 | *sc_status = kSCStatusFailed; |
dbf6a266 | 144 | goto done; |
5958d7c0 | 145 | } |
5958d7c0 | 146 | |
dbf6a266 A |
147 | done : |
148 | ||
149 | if (key) CFRelease(key); | |
5958d7c0 A |
150 | return KERN_SUCCESS; |
151 | } |