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@
23 #include <sys/types.h>
28 do_list(int argc
, char **argv
)
37 key
= CFStringCreateWithCString(NULL
,
38 (argc
>= 1) ? argv
[0] : "",
39 kCFStringEncodingMacRoman
);
42 regexOptions
= kSCDRegexKey
;
44 status
= SCDList(session
, key
, regexOptions
, &list
);
46 if (status
!= SCD_OK
) {
47 SCDLog(LOG_INFO
, CFSTR("SCDList: %s"), SCDError(status
));
51 listCnt
= CFArrayGetCount(list
);
53 for (i
=0; i
<listCnt
; i
++) {
54 SCDLog(LOG_NOTICE
, CFSTR(" subKey [%d] = %@"), i
, CFArrayGetValueAtIndex(list
, i
));
57 SCDLog(LOG_NOTICE
, CFSTR(" no subKey's"));
66 do_add(int argc
, char **argv
)
71 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
74 status
= SCDAdd(session
, key
, data
);
75 if (status
!= SCD_OK
) {
76 SCDLog(LOG_INFO
, CFSTR("SCDAdd: %s"), SCDError(status
));
79 status
= SCDAddSession(session
, key
, data
);
80 if (status
!= SCD_OK
) {
81 SCDLog(LOG_INFO
, CFSTR("SCDAddSession: %s"), SCDError(status
));
91 do_get(int argc
, char **argv
)
95 SCDHandleRef newData
= NULL
;
97 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
98 status
= SCDGet(session
, key
, &newData
);
100 if (status
!= SCD_OK
) {
101 SCDLog(LOG_INFO
, CFSTR("SCDGet: %s"), SCDError(status
));
102 if (newData
!= NULL
) {
103 SCDHandleRelease(newData
); /* toss the handle from SCDGet() */
109 SCDHandleRelease(data
); /* we got a new handle from SCDGet() */
118 do_set(int argc
, char **argv
)
123 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
124 status
= SCDSet(session
, key
, data
);
126 if (status
!= SCD_OK
) {
127 SCDLog(LOG_INFO
, CFSTR("SCDSet: %s"), SCDError(status
));
134 do_remove(int argc
, char **argv
)
139 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
140 status
= SCDRemove(session
, key
);
142 if (status
!= SCD_OK
) {
143 SCDLog(LOG_INFO
, CFSTR("SCDRemove: %s"), SCDError(status
));
150 do_touch(int argc
, char **argv
)
155 key
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingMacRoman
);
156 status
= SCDTouch(session
, key
);
158 if (status
!= SCD_OK
) {
159 SCDLog(LOG_INFO
, CFSTR("SCDTouch: %s"), SCDError(status
));