]> git.saurik.com Git - apple/configd.git/blob - configd.tproj/_confignotify.c
configd-212.2.tar.gz
[apple/configd.git] / configd.tproj / _confignotify.c
1 /*
2 * Copyright (c) 2000-2004, 2006 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 ((store == NULL) || (storePrivate->server == MACH_PORT_NULL)) {
45 return kSCStatusNoStoreSession; /* you must have an open session to play */
46 }
47
48 if (_configd_trace) {
49 SCTrace(TRUE, _configd_trace,
50 CFSTR("%s : %5d : %@\n"),
51 internal ? "*notify" : "notify ",
52 storePrivate->server,
53 key);
54 }
55
56 /*
57 * 1. Ensure that we hold the lock.
58 */
59 sc_status = __SCDynamicStoreLock(store, TRUE);
60 if (sc_status != kSCStatusOK) {
61 return sc_status;
62 }
63
64 /*
65 * 2. Tickle the value in the dynamic store
66 */
67 dict = CFDictionaryGetValue(storeData, key);
68 if (!dict || !CFDictionaryGetValueIfPresent(dict, kSCDData, (const void **)&value)) {
69 /* key doesn't exist (or data never defined) */
70 (void)_SCSerialize(kCFBooleanTrue, &value, NULL, NULL);
71 newValue = TRUE;
72 }
73
74 /* replace or store initial/temporary existing value */
75 __SCDynamicStoreSetValue(store, key, value, TRUE);
76
77 if (newValue) {
78 /* remove the value we just created */
79 __SCDynamicStoreRemoveValue(store, key, TRUE);
80 CFRelease(value);
81 }
82
83 /*
84 * 3. Release our lock.
85 */
86 __SCDynamicStoreUnlock(store, TRUE);
87
88 return sc_status;
89 }
90
91
92 __private_extern__
93 kern_return_t
94 _confignotify(mach_port_t server,
95 xmlData_t keyRef, /* raw XML bytes */
96 mach_msg_type_number_t keyLen,
97 int *sc_status
98 )
99 {
100 CFStringRef key = NULL; /* key (un-serialized) */
101 serverSessionRef mySession = getSession(server);
102
103 /* un-serialize the key */
104 if (!_SCUnserializeString(&key, NULL, (void *)keyRef, keyLen)) {
105 *sc_status = kSCStatusFailed;
106 goto done;
107 }
108
109 if (!isA_CFString(key)) {
110 *sc_status = kSCStatusInvalidArgument;
111 goto done;
112 }
113
114 if (mySession == NULL) {
115 *sc_status = kSCStatusNoStoreSession; /* you must have an open session to play */
116 goto done;
117 }
118
119 *sc_status = __SCDynamicStoreNotifyValue(mySession->store, key, FALSE);
120
121 done :
122
123 if (key) CFRelease(key);
124 return KERN_SUCCESS;
125 }