]> git.saurik.com Git - apple/configd.git/blob - configd.tproj/_configtouch.c
configd-84.6.tar.gz
[apple/configd.git] / configd.tproj / _configtouch.c
1 /*
2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /*
25 * Modification History
26 *
27 * June 1, 2001 Allan Nathanson <ajn@apple.com>
28 * - public API conversion
29 *
30 * June 20, 2000 Allan Nathanson <ajn@apple.com>
31 * - initial revision
32 */
33
34 #include "configd.h"
35 #include "session.h"
36
37 __private_extern__
38 int
39 __SCDynamicStoreTouchValue(SCDynamicStoreRef store, CFStringRef key)
40 {
41 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
42 int sc_status;
43 CFDataRef value;
44
45 if (_configd_verbose) {
46 SCLog(TRUE, LOG_DEBUG, CFSTR("__SCDynamicStoreTouchValue:"));
47 SCLog(TRUE, LOG_DEBUG, CFSTR(" key = %@"), key);
48 }
49
50 if (!store || (storePrivate->server == MACH_PORT_NULL)) {
51 return kSCStatusNoStoreSession; /* you must have an open session to play */
52 }
53
54 if (_configd_trace) {
55 SCTrace(TRUE, _configd_trace, CFSTR("touch : %5d : %@\n"), storePrivate->server, key);
56 }
57
58 /*
59 * 1. Ensure that we hold the lock.
60 */
61 sc_status = __SCDynamicStoreLock(store, TRUE);
62 if (sc_status != kSCStatusOK) {
63 return sc_status;
64 }
65
66 /*
67 * 2. Grab the current (or establish a new) store entry for this key.
68 */
69 sc_status = __SCDynamicStoreCopyValue(store, key, &value, TRUE);
70 switch (sc_status) {
71 case kSCStatusNoKey : {
72 CFDateRef now;
73
74 /* store entry does not exist, create */
75
76 now = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent());
77 SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" new time stamp = %@"), now);
78 (void) _SCSerialize(now, &value, NULL, NULL);
79 CFRelease(now);
80 break;
81 }
82
83 case kSCStatusOK : {
84 CFDateRef now;
85
86 /* store entry exists */
87
88 (void) _SCUnserialize((CFPropertyListRef *)&now, value, NULL, NULL);
89 if (isA_CFDate(now)) {
90 /* the value is a CFDate, update the time stamp */
91 CFRelease(now);
92 CFRelease(value);
93 now = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent());
94 SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" new time stamp = %@"), now);
95 (void) _SCSerialize(now, &value, NULL, NULL);
96 } /* else, we'll just save the data (again) to bump the instance */
97 CFRelease(now);
98
99 break;
100 }
101 default :
102 SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" __SCDynamicStoreCopyValue(): %s"), SCErrorString(sc_status));
103 goto done;
104 }
105
106 sc_status = __SCDynamicStoreSetValue(store, key, value, TRUE);
107 CFRelease(value);
108
109 done :
110
111 /*
112 * 8. Release our lock.
113 */
114 __SCDynamicStoreUnlock(store, TRUE);
115
116 return kSCStatusOK;
117 }
118
119
120 __private_extern__
121 kern_return_t
122 _configtouch(mach_port_t server,
123 xmlData_t keyRef, /* raw XML bytes */
124 mach_msg_type_number_t keyLen,
125 int *sc_status
126 )
127 {
128 serverSessionRef mySession = getSession(server);
129 CFStringRef key; /* key (un-serialized) */
130
131 if (_configd_verbose) {
132 SCLog(TRUE, LOG_DEBUG, CFSTR("Touch key in configuration database."));
133 SCLog(TRUE, LOG_DEBUG, CFSTR(" server = %d"), server);
134 }
135
136 /* un-serialize the key */
137 if (!_SCUnserializeString(&key, NULL, (void *)keyRef, keyLen)) {
138 *sc_status = kSCStatusFailed;
139 return KERN_SUCCESS;
140 }
141
142 if (!isA_CFString(key)) {
143 *sc_status = kSCStatusInvalidArgument;
144 CFRelease(key);
145 return KERN_SUCCESS;
146 }
147
148 if (!mySession) {
149 *sc_status = kSCStatusNoStoreSession; /* you must have an open session to play */
150 CFRelease(key);
151 return KERN_SUCCESS;
152 }
153
154 *sc_status = __SCDynamicStoreTouchValue(mySession->store, key);
155 CFRelease(key);
156
157 return KERN_SUCCESS;
158 }