2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
21 * @APPLE_LICENSE_HEADER_END@
25 * Modification History
27 * June 1, 2001 Allan Nathanson <ajn@apple.com>
28 * - public API conversion
30 * November 9, 2000 Allan Nathanson <ajn@apple.com>
34 #include <sys/types.h>
40 static CFComparisonResult
41 sort_keys(const void *p1
, const void *p2
, void *context
) {
42 CFStringRef key1
= (CFStringRef
)p1
;
43 CFStringRef key2
= (CFStringRef
)p2
;
44 return CFStringCompare(key1
, key2
, 0);
49 do_list(int argc
, char **argv
)
55 CFMutableArrayRef sortedList
;
57 pattern
= CFStringCreateWithCString(NULL
,
58 (argc
>= 1) ? argv
[0] : ".*",
59 kCFStringEncodingMacRoman
);
61 list
= SCDynamicStoreCopyKeyList(store
, pattern
);
64 if (SCError() != kSCStatusOK
) {
65 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
67 SCPrint(TRUE
, stdout
, CFSTR(" no keys.\n"));
72 listCnt
= CFArrayGetCount(list
);
73 sortedList
= CFArrayCreateMutableCopy(NULL
, listCnt
, list
);
75 CFArraySortValues(sortedList
,
76 CFRangeMake(0, listCnt
),
81 for (i
= 0; i
< listCnt
; i
++) {
84 CFSTR(" subKey [%d] = %@\n"),
86 CFArrayGetValueAtIndex(sortedList
, i
));
89 SCPrint(TRUE
, stdout
, CFSTR(" no keys.\n"));
91 CFRelease(sortedList
);
98 do_add(int argc
, char **argv
)
102 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
105 if (!SCDynamicStoreAddValue(store
, key
, value
)) {
106 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
109 if (!SCDynamicStoreAddTemporaryValue(store
, key
, value
)) {
110 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
120 do_get(int argc
, char **argv
)
123 CFPropertyListRef newValue
;
125 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
126 newValue
= SCDynamicStoreCopyValue(store
, key
);
129 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
134 CFRelease(value
); /* we have new information, release the old */
143 do_set(int argc
, char **argv
)
147 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
148 if (!SCDynamicStoreSetValue(store
, key
, value
)) {
149 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
157 do_show(int argc
, char **argv
)
160 CFPropertyListRef newValue
;
162 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
165 newValue
= SCDynamicStoreCopyValue(store
, key
);
169 patterns
= CFArrayCreate(NULL
, (const void **)&key
, 1, &kCFTypeArrayCallBacks
);
170 newValue
= SCDynamicStoreCopyMultiple(store
, NULL
, patterns
);
176 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
180 SCPrint(TRUE
, stdout
, CFSTR("%@\n"), newValue
);
187 do_remove(int argc
, char **argv
)
191 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
192 if (!SCDynamicStoreRemoveValue(store
, key
)) {
193 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
201 do_notify(int argc
, char **argv
)
205 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
206 if (!SCDynamicStoreNotifyValue(store
, key
)) {
207 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));
215 do_touch(int argc
, char **argv
)
219 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
220 if (!SCDynamicStoreTouchValue(store
, key
)) {
221 SCPrint(TRUE
, stdout
, CFSTR(" %s\n"), SCErrorString(SCError()));