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@
24 * Modification History
26 * June 1, 2001 Allan Nathanson <ajn@apple.com>
27 * - public API conversion
29 * November 9, 2000 Allan Nathanson <ajn@apple.com>
33 #include <sys/types.h>
38 static CFComparisonResult
39 sort_keys(const void *p1
, const void *p2
, void *context
) {
40 CFStringRef key1
= (CFStringRef
)p1
;
41 CFStringRef key2
= (CFStringRef
)p2
;
42 return CFStringCompare(key1
, key2
, 0);
47 do_list(int argc
, char **argv
)
53 CFMutableArrayRef sortedList
;
55 pattern
= CFStringCreateWithCString(NULL
,
56 (argc
>= 1) ? argv
[0] : ".*",
57 kCFStringEncodingMacRoman
);
59 list
= SCDynamicStoreCopyKeyList(store
, pattern
);
62 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
66 listCnt
= CFArrayGetCount(list
);
67 sortedList
= CFArrayCreateMutableCopy(NULL
, listCnt
, list
);
69 CFArraySortValues(sortedList
,
70 CFRangeMake(0, listCnt
),
75 for (i
=0; i
<listCnt
; i
++) {
78 CFSTR(" subKey [%d] = %@\n"),
80 CFArrayGetValueAtIndex(sortedList
, i
));
83 SCPrint(TRUE
, stdout
, CFSTR(" no subKey's.\n"));
85 CFRelease(sortedList
);
92 do_add(int argc
, char **argv
)
96 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
99 if (!SCDynamicStoreAddValue(store
, key
, value
)) {
100 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
103 if (!SCDynamicStoreAddTemporaryValue(store
, key
, value
)) {
104 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
114 do_get(int argc
, char **argv
)
117 CFPropertyListRef newValue
;
119 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
120 newValue
= SCDynamicStoreCopyValue(store
, key
);
123 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
128 CFRelease(value
); /* we have new information, release the old */
137 do_set(int argc
, char **argv
)
141 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
142 if (!SCDynamicStoreSetValue(store
, key
, value
)) {
143 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
151 do_show(int argc
, char **argv
)
154 CFPropertyListRef newValue
;
156 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
157 newValue
= SCDynamicStoreCopyValue(store
, key
);
160 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
164 SCPrint(TRUE
, stdout
, CFSTR("%@\n"), newValue
);
171 do_remove(int argc
, char **argv
)
175 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
176 if (!SCDynamicStoreRemoveValue(store
, key
)) {
177 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
185 do_notify(int argc
, char **argv
)
189 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
190 if (!SCDynamicStoreNotifyValue(store
, key
)) {
191 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
199 do_touch(int argc
, char **argv
)
203 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
204 if (!SCDynamicStoreTouchValue(store
, key
)) {
205 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));