]> git.saurik.com Git - apple/configd.git/blob - configd.tproj/_configtouch.c
8a082b81d089d5dce47a58dd56d95f0566f80d95
[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 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25
26 /*
27 * Modification History
28 *
29 * June 1, 2001 Allan Nathanson <ajn@apple.com>
30 * - public API conversion
31 *
32 * June 20, 2000 Allan Nathanson <ajn@apple.com>
33 * - initial revision
34 */
35
36 #include "configd.h"
37 #include "session.h"
38
39 __private_extern__
40 int
41 __SCDynamicStoreTouchValue(SCDynamicStoreRef store, CFStringRef key)
42 {
43 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
44 int sc_status;
45 CFDataRef value;
46
47 if (_configd_verbose) {
48 SCLog(TRUE, LOG_DEBUG, CFSTR("__SCDynamicStoreTouchValue:"));
49 SCLog(TRUE, LOG_DEBUG, CFSTR(" key = %@"), key);
50 }
51
52 if (!store || (storePrivate->server == MACH_PORT_NULL)) {
53 return kSCStatusNoStoreSession; /* you must have an open session to play */
54 }
55
56 if (_configd_trace) {
57 SCTrace(TRUE, _configd_trace, CFSTR("touch : %5d : %@\n"), storePrivate->server, key);
58 }
59
60 /*
61 * 1. Ensure that we hold the lock.
62 */
63 sc_status = __SCDynamicStoreLock(store, TRUE);
64 if (sc_status != kSCStatusOK) {
65 return sc_status;
66 }
67
68 /*
69 * 2. Grab the current (or establish a new) store entry for this key.
70 */
71 sc_status = __SCDynamicStoreCopyValue(store, key, &value, TRUE);
72 switch (sc_status) {
73 case kSCStatusNoKey : {
74 CFDateRef now;
75
76 /* store entry does not exist, create */
77
78 now = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent());
79 SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" new time stamp = %@"), now);
80 (void) _SCSerialize(now, &value, NULL, NULL);
81 CFRelease(now);
82 break;
83 }
84
85 case kSCStatusOK : {
86 CFDateRef now;
87
88 /* store entry exists */
89
90 (void) _SCUnserialize((CFPropertyListRef *)&now, value, NULL, NULL);
91 if (isA_CFDate(now)) {
92 /* the value is a CFDate, update the time stamp */
93 CFRelease(now);
94 CFRelease(value);
95 now = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent());
96 SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" new time stamp = %@"), now);
97 (void) _SCSerialize(now, &value, NULL, NULL);
98 } /* else, we'll just save the data (again) to bump the instance */
99 CFRelease(now);
100
101 break;
102 }
103 default :
104 SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" __SCDynamicStoreCopyValue(): %s"), SCErrorString(sc_status));
105 goto done;
106 }
107
108 sc_status = __SCDynamicStoreSetValue(store, key, value, TRUE);
109 CFRelease(value);
110
111 done :
112
113 /*
114 * 8. Release our lock.
115 */
116 __SCDynamicStoreUnlock(store, TRUE);
117
118 return kSCStatusOK;
119 }
120
121
122 __private_extern__
123 kern_return_t
124 _configtouch(mach_port_t server,
125 xmlData_t keyRef, /* raw XML bytes */
126 mach_msg_type_number_t keyLen,
127 int *sc_status
128 )
129 {
130 serverSessionRef mySession = getSession(server);
131 CFStringRef key; /* key (un-serialized) */
132
133 if (_configd_verbose) {
134 SCLog(TRUE, LOG_DEBUG, CFSTR("Touch key in configuration database."));
135 SCLog(TRUE, LOG_DEBUG, CFSTR(" server = %d"), server);
136 }
137
138 /* un-serialize the key */
139 if (!_SCUnserializeString(&key, NULL, (void *)keyRef, keyLen)) {
140 *sc_status = kSCStatusFailed;
141 return KERN_SUCCESS;
142 }
143
144 if (!isA_CFString(key)) {
145 *sc_status = kSCStatusInvalidArgument;
146 CFRelease(key);
147 return KERN_SUCCESS;
148 }
149
150 if (!mySession) {
151 *sc_status = kSCStatusNoStoreSession; /* you must have an open session to play */
152 CFRelease(key);
153 return KERN_SUCCESS;
154 }
155
156 *sc_status = __SCDynamicStoreTouchValue(mySession->store, key);
157 CFRelease(key);
158
159 return KERN_SUCCESS;
160 }