]> git.saurik.com Git - apple/configd.git/blob - configd.tproj/_confignotify.c
configd-53.tar.gz
[apple/configd.git] / configd.tproj / _confignotify.c
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 * May 19, 2001 Allan Nathanson <ajn@apple.com>
27 * - initial revision
28 */
29
30 #include "configd.h"
31 #include "session.h"
32
33 int
34 __SCDynamicStoreNotifyValue(SCDynamicStoreRef store, CFStringRef key)
35 {
36 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
37 int sc_status = kSCStatusOK;
38 CFDictionaryRef dict;
39 Boolean newValue = FALSE;
40 CFPropertyListRef value;
41
42 SCLog(_configd_verbose, LOG_DEBUG, CFSTR("__SCDynamicStoreNotifyValue:"));
43 SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" key = %@"), key);
44
45 if (!store || (storePrivate->server == MACH_PORT_NULL)) {
46 return kSCStatusNoStoreSession; /* you must have an open session to play */
47 }
48
49 /*
50 * 1. Ensure that we hold the lock.
51 */
52 sc_status = __SCDynamicStoreLock(store, TRUE);
53 if (sc_status != kSCStatusOK) {
54 return sc_status;
55 }
56
57 /*
58 * 2. Tickle the value in the dynamic store
59 */
60 dict = CFDictionaryGetValue(storeData, key);
61 if (!dict || !CFDictionaryGetValueIfPresent(dict, kSCDData, (const void **)&value)) {
62 /* key doesn't exist (or data never defined) */
63 value = CFDateCreate(NULL, CFAbsoluteTimeGetCurrent());
64 newValue = TRUE;
65 }
66
67 /* replace or store initial/temporary existing value */
68 __SCDynamicStoreSetValue(store, key, value);
69
70 if (newValue) {
71 /* remove the value we just created */
72 __SCDynamicStoreRemoveValue(store, key);
73 CFRelease(value);
74 }
75
76 /*
77 * 3. Release our lock.
78 */
79 __SCDynamicStoreUnlock(store, TRUE);
80
81 return sc_status;
82 }
83
84
85 kern_return_t
86 _confignotify(mach_port_t server,
87 xmlData_t keyRef, /* raw XML bytes */
88 mach_msg_type_number_t keyLen,
89 int *sc_status
90 )
91 {
92 serverSessionRef mySession = getSession(server);
93 CFStringRef key; /* key (un-serialized) */
94
95 SCLog(_configd_verbose, LOG_DEBUG, CFSTR("Notify key in configuration database."));
96 SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" server = %d"), server);
97
98 /* un-serialize the key */
99 if (!_SCUnserialize((CFPropertyListRef *)&key, (void *)keyRef, keyLen)) {
100 *sc_status = kSCStatusFailed;
101 return KERN_SUCCESS;
102 }
103
104 if (!isA_CFString(key)) {
105 CFRelease(key);
106 *sc_status = kSCStatusInvalidArgument;
107 return KERN_SUCCESS;
108 }
109
110 *sc_status = __SCDynamicStoreNotifyValue(mySession->store, key);
111 CFRelease(key);
112
113 return KERN_SUCCESS;
114 }