2 * Copyright (c) 2000-2002 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 if (SCError() != kSCStatusOK
) {
63 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
65 SCPrint(TRUE
, stdout
, CFSTR(" no keys.\n"));
70 listCnt
= CFArrayGetCount(list
);
71 sortedList
= CFArrayCreateMutableCopy(NULL
, listCnt
, list
);
73 CFArraySortValues(sortedList
,
74 CFRangeMake(0, listCnt
),
79 for (i
=0; i
<listCnt
; i
++) {
82 CFSTR(" subKey [%d] = %@\n"),
84 CFArrayGetValueAtIndex(sortedList
, i
));
87 SCPrint(TRUE
, stdout
, CFSTR(" no keys.\n"));
89 CFRelease(sortedList
);
96 do_add(int argc
, char **argv
)
100 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
103 if (!SCDynamicStoreAddValue(store
, key
, value
)) {
104 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
107 if (!SCDynamicStoreAddTemporaryValue(store
, key
, value
)) {
108 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
118 do_get(int argc
, char **argv
)
121 CFPropertyListRef newValue
;
123 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
124 newValue
= SCDynamicStoreCopyValue(store
, key
);
127 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
132 CFRelease(value
); /* we have new information, release the old */
141 do_set(int argc
, char **argv
)
145 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
146 if (!SCDynamicStoreSetValue(store
, key
, value
)) {
147 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
155 do_show(int argc
, char **argv
)
158 CFPropertyListRef newValue
;
160 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
161 newValue
= SCDynamicStoreCopyValue(store
, key
);
164 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
168 SCPrint(TRUE
, stdout
, CFSTR("%@\n"), newValue
);
175 do_remove(int argc
, char **argv
)
179 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
180 if (!SCDynamicStoreRemoveValue(store
, key
)) {
181 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
189 do_notify(int argc
, char **argv
)
193 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
194 if (!SCDynamicStoreNotifyValue(store
, key
)) {
195 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
203 do_touch(int argc
, char **argv
)
207 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
208 if (!SCDynamicStoreTouchValue(store
, key
)) {
209 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));