]> git.saurik.com Git - apple/configd.git/blame - configd.tproj/_configtouch.c
configd-53.1.tar.gz
[apple/configd.git] / configd.tproj / _configtouch.c
CommitLineData
5958d7c0 1/*
a5f60add 2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
5958d7c0
A
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
0fae82ee
A
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
5958d7c0
A
33#include "configd.h"
34#include "session.h"
35
0fae82ee
A
36int
37__SCDynamicStoreTouchValue(SCDynamicStoreRef store, CFStringRef key)
5958d7c0 38{
0fae82ee
A
39 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
40 int sc_status;
41 Boolean newValue = FALSE;
42 CFPropertyListRef value;
5958d7c0 43
0fae82ee
A
44 SCLog(_configd_verbose, LOG_DEBUG, CFSTR("__SCDynamicStoreTouchValue:"));
45 SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" key = %@"), key);
5958d7c0 46
0fae82ee
A
47 if (!store || (storePrivate->server == MACH_PORT_NULL)) {
48 return kSCStatusNoStoreSession; /* you must have an open session to play */
5958d7c0
A
49 }
50
51 /*
0fae82ee 52 * 1. Ensure that we hold the lock.
5958d7c0 53 */
0fae82ee
A
54 sc_status = __SCDynamicStoreLock(store, TRUE);
55 if (sc_status != kSCStatusOK) {
56 return sc_status;
5958d7c0
A
57 }
58
59 /*
0fae82ee 60 * 2. Grab the current (or establish a new) store entry for this key.
5958d7c0 61 */
0fae82ee
A
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);
5958d7c0
A
69 break;
70
0fae82ee
A
71 case kSCStatusOK :
72 /* store entry exists */
a5f60add 73 if (isA_CFDate(value)) {
0fae82ee 74 /* the value is a CFDate, update the time stamp */
5958d7c0 75 CFRelease(value);
0fae82ee
A
76 value = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent());
77 newValue = TRUE;
78 SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" new time stamp = %@"), value);
5958d7c0
A
79 } /* else, we'll just save the data (again) to bump the instance */
80 break;
81
82 default :
0fae82ee 83 SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" __SCDynamicStoreCopyValue(): %s"), SCErrorString(sc_status));
5958d7c0
A
84 goto done;
85 }
86
0fae82ee
A
87 sc_status = __SCDynamicStoreSetValue(store, key, value);
88
89 if (newValue) {
90 CFRelease(value);
91 }
5958d7c0
A
92
93 done :
94
95 /*
0fae82ee 96 * 8. Release our lock.
5958d7c0 97 */
0fae82ee 98 __SCDynamicStoreUnlock(store, TRUE);
5958d7c0 99
0fae82ee 100 return kSCStatusOK;
5958d7c0
A
101}
102
103
104kern_return_t
0fae82ee 105_configtouch(mach_port_t server,
5958d7c0
A
106 xmlData_t keyRef, /* raw XML bytes */
107 mach_msg_type_number_t keyLen,
0fae82ee 108 int *sc_status
5958d7c0
A
109)
110{
5958d7c0 111 serverSessionRef mySession = getSession(server);
5958d7c0 112 CFStringRef key; /* key (un-serialized) */
5958d7c0 113
0fae82ee
A
114 SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Touch key in configuration database."));
115 SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" server = %d"), server);
5958d7c0
A
116
117 /* un-serialize the key */
a5f60add 118 if (!_SCUnserialize((CFPropertyListRef *)&key, (void *)keyRef, keyLen)) {
0fae82ee
A
119 *sc_status = kSCStatusFailed;
120 return KERN_SUCCESS;
a5f60add
A
121 }
122
123 if (!isA_CFString(key)) {
124 CFRelease(key);
0fae82ee 125 *sc_status = kSCStatusInvalidArgument;
5958d7c0
A
126 return KERN_SUCCESS;
127 }
128
0fae82ee 129 *sc_status = __SCDynamicStoreTouchValue(mySession->store, key);
5958d7c0
A
130 CFRelease(key);
131
132 return KERN_SUCCESS;
133}