]> git.saurik.com Git - apple/configd.git/blob - configd.tproj/_configtouch.c
configd-395.11.tar.gz
[apple/configd.git] / configd.tproj / _configtouch.c
1 /*
2 * Copyright (c) 2000-2004, 2006, 2008, 2009 Apple 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 = kSCStatusOK;
43 CFDataRef value;
44
45 if ((store == NULL) || (storePrivate->server == MACH_PORT_NULL)) {
46 return kSCStatusNoStoreSession; /* you must have an open session to play */
47 }
48
49 if (_configd_trace) {
50 SCTrace(TRUE, _configd_trace, CFSTR("touch : %5d : %@\n"), storePrivate->server, key);
51 }
52
53 /*
54 * 1. Ensure that we hold the lock.
55 */
56 sc_status = __SCDynamicStoreLock(store, TRUE);
57 if (sc_status != kSCStatusOK) {
58 return sc_status;
59 }
60
61 /*
62 * 2. Grab the current (or establish a new) store entry for this key.
63 */
64 sc_status = __SCDynamicStoreCopyValue(store, key, &value, TRUE);
65 switch (sc_status) {
66 case kSCStatusNoKey : {
67 CFDateRef now;
68
69 /* store entry does not exist, create */
70
71 now = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent());
72 (void) _SCSerialize(now, &value, NULL, NULL);
73 CFRelease(now);
74 break;
75 }
76
77 case kSCStatusOK : {
78 CFDateRef now;
79
80 /* store entry exists */
81
82 (void) _SCUnserialize((CFPropertyListRef *)&now, value, NULL, 0);
83 if (isA_CFDate(now)) {
84 /* the value is a CFDate, update the time stamp */
85 CFRelease(now);
86 CFRelease(value);
87 now = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent());
88 (void) _SCSerialize(now, &value, NULL, NULL);
89 } /* else, we'll just save the data (again) to bump the instance */
90 CFRelease(now);
91
92 break;
93 }
94 default :
95 goto done;
96 }
97
98 sc_status = __SCDynamicStoreSetValue(store, key, value, TRUE);
99 CFRelease(value);
100
101 done :
102
103 /*
104 * 8. Release our lock.
105 */
106 __SCDynamicStoreUnlock(store, TRUE);
107
108 return sc_status;
109 }
110
111
112 __private_extern__
113 kern_return_t
114 _configtouch(mach_port_t server,
115 xmlData_t keyRef, /* raw XML bytes */
116 mach_msg_type_number_t keyLen,
117 int *sc_status
118 )
119 {
120 CFStringRef key = NULL; /* key (un-serialized) */
121 serverSessionRef mySession;
122
123 /* un-serialize the key */
124 if (!_SCUnserializeString(&key, NULL, (void *)keyRef, keyLen)) {
125 *sc_status = kSCStatusFailed;
126 goto done;
127 }
128
129 if (!isA_CFString(key)) {
130 *sc_status = kSCStatusInvalidArgument;
131 goto done;
132 }
133
134 mySession = getSession(server);
135 if (mySession == NULL) {
136 *sc_status = kSCStatusNoStoreSession; /* you must have an open session to play */
137 goto done;
138 }
139
140 *sc_status = __SCDynamicStoreTouchValue(mySession->store, key);
141
142 done :
143
144 if (key) CFRelease(key);
145 return KERN_SUCCESS;
146 }