2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
27 * Modification History
29 * June 1, 2001 Allan Nathanson <ajn@apple.com>
30 * - public API conversion
32 * November 9, 2000 Allan Nathanson <ajn@apple.com>
36 #include <sys/types.h>
42 static CFComparisonResult
43 sort_keys(const void *p1
, const void *p2
, void *context
) {
44 CFStringRef key1
= (CFStringRef
)p1
;
45 CFStringRef key2
= (CFStringRef
)p2
;
46 return CFStringCompare(key1
, key2
, 0);
51 do_list(int argc
, char **argv
)
57 CFMutableArrayRef sortedList
;
59 pattern
= CFStringCreateWithCString(NULL
,
60 (argc
>= 1) ? argv
[0] : ".*",
61 kCFStringEncodingMacRoman
);
63 list
= SCDynamicStoreCopyKeyList(store
, pattern
);
66 if (SCError() != kSCStatusOK
) {
67 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
69 SCPrint(TRUE
, stdout
, CFSTR(" no keys.\n"));
74 listCnt
= CFArrayGetCount(list
);
75 sortedList
= CFArrayCreateMutableCopy(NULL
, listCnt
, list
);
77 CFArraySortValues(sortedList
,
78 CFRangeMake(0, listCnt
),
83 for (i
= 0; i
< listCnt
; i
++) {
86 CFSTR(" subKey [%d] = %@\n"),
88 CFArrayGetValueAtIndex(sortedList
, i
));
91 SCPrint(TRUE
, stdout
, CFSTR(" no keys.\n"));
93 CFRelease(sortedList
);
100 do_add(int argc
, char **argv
)
104 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
107 if (!SCDynamicStoreAddValue(store
, key
, value
)) {
108 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
111 if (!SCDynamicStoreAddTemporaryValue(store
, key
, value
)) {
112 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
122 do_get(int argc
, char **argv
)
125 CFPropertyListRef newValue
;
127 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
128 newValue
= SCDynamicStoreCopyValue(store
, key
);
131 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
136 CFRelease(value
); /* we have new information, release the old */
145 do_set(int argc
, char **argv
)
149 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
150 if (!SCDynamicStoreSetValue(store
, key
, value
)) {
151 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
159 do_show(int argc
, char **argv
)
162 CFPropertyListRef newValue
;
164 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
167 newValue
= SCDynamicStoreCopyValue(store
, key
);
171 patterns
= CFArrayCreate(NULL
, (const void **)&key
, 1, &kCFTypeArrayCallBacks
);
172 newValue
= SCDynamicStoreCopyMultiple(store
, NULL
, patterns
);
178 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
182 SCPrint(TRUE
, stdout
, CFSTR("%@\n"), newValue
);
189 do_remove(int argc
, char **argv
)
193 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
194 if (!SCDynamicStoreRemoveValue(store
, key
)) {
195 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
203 do_notify(int argc
, char **argv
)
207 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
208 if (!SCDynamicStoreNotifyValue(store
, key
)) {
209 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
217 do_touch(int argc
, char **argv
)
221 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
222 if (!SCDynamicStoreTouchValue(store
, key
)) {
223 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));