2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
27 * Modification History
29 * June 1, 2001 Allan Nathanson <ajn@apple.com>
30 * - public API conversion
32 * June 20, 2000 Allan Nathanson <ajn@apple.com>
41 __SCDynamicStoreTouchValue(SCDynamicStoreRef store
, CFStringRef key
)
43 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
47 if (_configd_verbose
) {
48 SCLog(TRUE
, LOG_DEBUG
, CFSTR("__SCDynamicStoreTouchValue:"));
49 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" key = %@"), key
);
52 if (!store
|| (storePrivate
->server
== MACH_PORT_NULL
)) {
53 return kSCStatusNoStoreSession
; /* you must have an open session to play */
57 SCTrace(TRUE
, _configd_trace
, CFSTR("touch : %5d : %@\n"), storePrivate
->server
, key
);
61 * 1. Ensure that we hold the lock.
63 sc_status
= __SCDynamicStoreLock(store
, TRUE
);
64 if (sc_status
!= kSCStatusOK
) {
69 * 2. Grab the current (or establish a new) store entry for this key.
71 sc_status
= __SCDynamicStoreCopyValue(store
, key
, &value
, TRUE
);
73 case kSCStatusNoKey
: {
76 /* store entry does not exist, create */
78 now
= CFDateCreate(NULL
, CFAbsoluteTimeGetCurrent());
79 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" new time stamp = %@"), now
);
80 (void) _SCSerialize(now
, &value
, NULL
, NULL
);
88 /* store entry exists */
90 (void) _SCUnserialize((CFPropertyListRef
*)&now
, value
, NULL
, NULL
);
91 if (isA_CFDate(now
)) {
92 /* the value is a CFDate, update the time stamp */
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 */
104 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" __SCDynamicStoreCopyValue(): %s"), SCErrorString(sc_status
));
108 sc_status
= __SCDynamicStoreSetValue(store
, key
, value
, TRUE
);
114 * 8. Release our lock.
116 __SCDynamicStoreUnlock(store
, TRUE
);
124 _configtouch(mach_port_t server
,
125 xmlData_t keyRef
, /* raw XML bytes */
126 mach_msg_type_number_t keyLen
,
130 serverSessionRef mySession
= getSession(server
);
131 CFStringRef key
; /* key (un-serialized) */
133 if (_configd_verbose
) {
134 SCLog(TRUE
, LOG_DEBUG
, CFSTR("Touch key in configuration database."));
135 SCLog(TRUE
, LOG_DEBUG
, CFSTR(" server = %d"), server
);
138 /* un-serialize the key */
139 if (!_SCUnserializeString(&key
, NULL
, (void *)keyRef
, keyLen
)) {
140 *sc_status
= kSCStatusFailed
;
144 if (!isA_CFString(key
)) {
145 *sc_status
= kSCStatusInvalidArgument
;
151 *sc_status
= kSCStatusNoStoreSession
; /* you must have an open session to play */
156 *sc_status
= __SCDynamicStoreTouchValue(mySession
->store
, key
);