]> git.saurik.com Git - apple/configd.git/blob - scutil.tproj/cache.c
configd-24.tar.gz
[apple/configd.git] / scutil.tproj / cache.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #include <sys/types.h>
24
25 #include "scutil.h"
26
27 void
28 do_list(int argc, char **argv)
29 {
30 CFStringRef key;
31 int regexOptions = 0;
32 SCDStatus status;
33 CFArrayRef list;
34 CFIndex listCnt;
35 int i;
36
37 key = CFStringCreateWithCString(NULL,
38 (argc >= 1) ? argv[0] : "",
39 kCFStringEncodingMacRoman);
40
41 if (argc == 2)
42 regexOptions = kSCDRegexKey;
43
44 status = SCDList(session, key, regexOptions, &list);
45 CFRelease(key);
46 if (status != SCD_OK) {
47 SCDLog(LOG_INFO, CFSTR("SCDList: %s"), SCDError(status));
48 return;
49 }
50
51 listCnt = CFArrayGetCount(list);
52 if (listCnt > 0) {
53 for (i=0; i<listCnt; i++) {
54 SCDLog(LOG_NOTICE, CFSTR(" subKey [%d] = %@"), i, CFArrayGetValueAtIndex(list, i));
55 }
56 } else {
57 SCDLog(LOG_NOTICE, CFSTR(" no subKey's"));
58 }
59 CFRelease(list);
60
61 return;
62 }
63
64
65 void
66 do_add(int argc, char **argv)
67 {
68 CFStringRef key;
69 SCDStatus status;
70
71 key = CFStringCreateWithCString(NULL, argv[0], kCFStringEncodingMacRoman);
72
73 if (argc < 2) {
74 status = SCDAdd(session, key, data);
75 if (status != SCD_OK) {
76 SCDLog(LOG_INFO, CFSTR("SCDAdd: %s"), SCDError(status));
77 }
78 } else {
79 status = SCDAddSession(session, key, data);
80 if (status != SCD_OK) {
81 SCDLog(LOG_INFO, CFSTR("SCDAddSession: %s"), SCDError(status));
82 }
83 }
84
85 CFRelease(key);
86 return;
87 }
88
89
90 void
91 do_get(int argc, char **argv)
92 {
93 SCDStatus status;
94 CFStringRef key;
95 SCDHandleRef newData = NULL;
96
97 key = CFStringCreateWithCString(NULL, argv[0], kCFStringEncodingMacRoman);
98 status = SCDGet(session, key, &newData);
99 CFRelease(key);
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() */
104 }
105 return;
106 }
107
108 if (data != NULL) {
109 SCDHandleRelease(data); /* we got a new handle from SCDGet() */
110 }
111 data = newData;
112
113 return;
114 }
115
116
117 void
118 do_set(int argc, char **argv)
119 {
120 SCDStatus status;
121 CFStringRef key;
122
123 key = CFStringCreateWithCString(NULL, argv[0], kCFStringEncodingMacRoman);
124 status = SCDSet(session, key, data);
125 CFRelease(key);
126 if (status != SCD_OK) {
127 SCDLog(LOG_INFO, CFSTR("SCDSet: %s"), SCDError(status));
128 }
129 return;
130 }
131
132
133 void
134 do_remove(int argc, char **argv)
135 {
136 SCDStatus status;
137 CFStringRef key;
138
139 key = CFStringCreateWithCString(NULL, argv[0], kCFStringEncodingMacRoman);
140 status = SCDRemove(session, key);
141 CFRelease(key);
142 if (status != SCD_OK) {
143 SCDLog(LOG_INFO, CFSTR("SCDRemove: %s"), SCDError(status));
144 }
145 return;
146 }
147
148
149 void
150 do_touch(int argc, char **argv)
151 {
152 SCDStatus status;
153 CFStringRef key;
154
155 key = CFStringCreateWithCString(NULL, argv[0], kCFStringEncodingMacRoman);
156 status = SCDTouch(session, key);
157 CFRelease(key);
158 if (status != SCD_OK) {
159 SCDLog(LOG_INFO, CFSTR("SCDTouch: %s"), SCDError(status));
160 }
161 return;
162 }