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