2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
24 * Modification History
26 * June 1, 2001 Allan Nathanson <ajn@apple.com>
27 * - public API conversion
29 * June 20, 2000 Allan Nathanson <ajn@apple.com>
37 __SCDynamicStoreTouchValue(SCDynamicStoreRef store
, CFStringRef key
)
39 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
41 Boolean newValue
= FALSE
;
42 CFPropertyListRef value
;
44 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("__SCDynamicStoreTouchValue:"));
45 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" key = %@"), key
);
47 if (!store
|| (storePrivate
->server
== MACH_PORT_NULL
)) {
48 return kSCStatusNoStoreSession
; /* you must have an open session to play */
52 * 1. Ensure that we hold the lock.
54 sc_status
= __SCDynamicStoreLock(store
, TRUE
);
55 if (sc_status
!= kSCStatusOK
) {
60 * 2. Grab the current (or establish a new) store entry for this key.
62 sc_status
= __SCDynamicStoreCopyValue(store
, key
, &value
);
65 /* store entry does not exist, create */
66 value
= CFDateCreate(NULL
, CFAbsoluteTimeGetCurrent());
68 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" new time stamp = %@"), value
);
72 /* store entry exists */
73 if (CFGetTypeID(value
) == CFDateGetTypeID()) {
74 /* the value is a CFDate, update the time stamp */
76 value
= CFDateCreate(NULL
, CFAbsoluteTimeGetCurrent());
78 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" new time stamp = %@"), value
);
79 } /* else, we'll just save the data (again) to bump the instance */
83 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" __SCDynamicStoreCopyValue(): %s"), SCErrorString(sc_status
));
87 sc_status
= __SCDynamicStoreSetValue(store
, key
, value
);
96 * 8. Release our lock.
98 __SCDynamicStoreUnlock(store
, TRUE
);
105 _configtouch(mach_port_t server
,
106 xmlData_t keyRef
, /* raw XML bytes */
107 mach_msg_type_number_t keyLen
,
111 kern_return_t status
;
112 serverSessionRef mySession
= getSession(server
);
113 CFDataRef xmlKey
; /* key (XML serialized) */
114 CFStringRef key
; /* key (un-serialized) */
115 CFStringRef xmlError
;
117 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("Touch key in configuration database."));
118 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR(" server = %d"), server
);
120 /* un-serialize the key */
121 xmlKey
= CFDataCreate(NULL
, keyRef
, keyLen
);
122 status
= vm_deallocate(mach_task_self(), (vm_address_t
)keyRef
, keyLen
);
123 if (status
!= KERN_SUCCESS
) {
124 SCLog(_configd_verbose
, LOG_DEBUG
, CFSTR("vm_deallocate(): %s"), mach_error_string(status
));
125 /* non-fatal???, proceed */
127 key
= CFPropertyListCreateFromXMLData(NULL
,
129 kCFPropertyListImmutable
,
134 SCLog(_configd_verbose
, LOG_DEBUG
,
135 CFSTR("CFPropertyListCreateFromXMLData() key: %@"),
139 *sc_status
= kSCStatusFailed
;
141 } else if (!isA_CFString(key
)) {
142 *sc_status
= kSCStatusInvalidArgument
;
146 *sc_status
= __SCDynamicStoreTouchValue(mySession
->store
, key
);