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