]> git.saurik.com Git - apple/configd.git/blob - configd.tproj/_confignotify.c
configd-84.6.tar.gz
[apple/configd.git] / configd.tproj / _confignotify.c
1 /*
2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /*
25 * Modification History
26 *
27 * May 19, 2001 Allan Nathanson <ajn@apple.com>
28 * - initial revision
29 */
30
31 #include "configd.h"
32 #include "session.h"
33
34 __private_extern__
35 int
36 __SCDynamicStoreNotifyValue(SCDynamicStoreRef store, CFStringRef key, Boolean internal)
37 {
38 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
39 int sc_status = kSCStatusOK;
40 CFDictionaryRef dict;
41 Boolean newValue = FALSE;
42 CFDataRef value;
43
44 if (_configd_verbose) {
45 SCLog(TRUE, LOG_DEBUG, CFSTR("__SCDynamicStoreNotifyValue:"));
46 SCLog(TRUE, LOG_DEBUG, CFSTR(" key = %@"), key);
47 }
48
49 if (!store || (storePrivate->server == MACH_PORT_NULL)) {
50 return kSCStatusNoStoreSession; /* you must have an open session to play */
51 }
52
53 if (_configd_trace) {
54 SCTrace(TRUE, _configd_trace,
55 CFSTR("%s : %5d : %@\n"),
56 internal ? "*notify" : "notify ",
57 storePrivate->server,
58 key);
59 }
60
61 /*
62 * 1. Ensure that we hold the lock.
63 */
64 sc_status = __SCDynamicStoreLock(store, TRUE);
65 if (sc_status != kSCStatusOK) {
66 return sc_status;
67 }
68
69 /*
70 * 2. Tickle the value in the dynamic store
71 */
72 dict = CFDictionaryGetValue(storeData, key);
73 if (!dict || !CFDictionaryGetValueIfPresent(dict, kSCDData, (const void **)&value)) {
74 /* key doesn't exist (or data never defined) */
75 (void)_SCSerialize(kCFBooleanTrue, &value, NULL, NULL);
76 newValue = TRUE;
77 }
78
79 /* replace or store initial/temporary existing value */
80 __SCDynamicStoreSetValue(store, key, value, TRUE);
81
82 if (newValue) {
83 /* remove the value we just created */
84 __SCDynamicStoreRemoveValue(store, key, TRUE);
85 CFRelease(value);
86 }
87
88 /*
89 * 3. Release our lock.
90 */
91 __SCDynamicStoreUnlock(store, TRUE);
92
93 return sc_status;
94 }
95
96
97 __private_extern__
98 kern_return_t
99 _confignotify(mach_port_t server,
100 xmlData_t keyRef, /* raw XML bytes */
101 mach_msg_type_number_t keyLen,
102 int *sc_status
103 )
104 {
105 serverSessionRef mySession = getSession(server);
106 CFStringRef key; /* key (un-serialized) */
107
108 if (_configd_verbose) {
109 SCLog(TRUE, LOG_DEBUG, CFSTR("Notify key in configuration database."));
110 SCLog(TRUE, LOG_DEBUG, CFSTR(" server = %d"), server);
111 }
112
113 /* un-serialize the key */
114 if (!_SCUnserializeString(&key, NULL, (void *)keyRef, keyLen)) {
115 *sc_status = kSCStatusFailed;
116 return KERN_SUCCESS;
117 }
118
119 if (!isA_CFString(key)) {
120 *sc_status = kSCStatusInvalidArgument;
121 CFRelease(key);
122 return KERN_SUCCESS;
123 }
124
125 if (!mySession) {
126 *sc_status = kSCStatusNoStoreSession; /* you must have an open session to play */
127 CFRelease(key);
128 return KERN_SUCCESS;
129 }
130
131 *sc_status = __SCDynamicStoreNotifyValue(mySession->store, key, FALSE);
132 CFRelease(key);
133
134 return KERN_SUCCESS;
135 }