]> git.saurik.com Git - apple/configd.git/blob - configd.tproj/_notifychanges.c
configd-963.30.1.tar.gz
[apple/configd.git] / configd.tproj / _notifychanges.c
1 /*
2 * Copyright (c) 2000-2004, 2006, 2011, 2013, 2015 Apple 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 * June 1, 2001 Allan Nathanson <ajn@apple.com>
28 * - public API conversion
29 *
30 * March 24, 2000 Allan Nathanson <ajn@apple.com>
31 * - initial revision
32 */
33
34 #include "configd.h"
35 #include "session.h"
36
37 __private_extern__
38 int
39 __SCDynamicStoreCopyNotifiedKeys(SCDynamicStoreRef store, CFArrayRef *notifierKeys)
40 {
41 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
42 CFStringRef sessionKey;
43 CFDictionaryRef info;
44 CFMutableDictionaryRef newInfo;
45
46 sessionKey = CFStringCreateWithFormat(NULL, NULL, CFSTR("%d"), storePrivate->server);
47 info = CFDictionaryGetValue(sessionData, sessionKey);
48 if ((info == NULL) ||
49 !CFDictionaryContainsKey(info, kSCDChangedKeys)) {
50 CFRelease(sessionKey);
51 *notifierKeys = CFArrayCreate(NULL, NULL, 0, &kCFTypeArrayCallBacks);
52 return kSCStatusOK;
53 }
54 newInfo = CFDictionaryCreateMutableCopy(NULL, 0, info);
55
56 *notifierKeys = CFDictionaryGetValue(newInfo, kSCDChangedKeys);
57 CFRetain(*notifierKeys);
58
59 CFDictionaryRemoveValue(newInfo, kSCDChangedKeys);
60 if (CFDictionaryGetCount(newInfo) > 0) {
61 CFDictionarySetValue(sessionData, sessionKey, newInfo);
62 } else {
63 CFDictionaryRemoveValue(sessionData, sessionKey);
64 }
65 CFRelease(newInfo);
66 CFRelease(sessionKey);
67
68 return kSCStatusOK;
69 }
70
71
72 __private_extern__
73 kern_return_t
74 _notifychanges(mach_port_t server,
75 xmlDataOut_t *listRef, /* raw XML bytes */
76 mach_msg_type_number_t *listLen,
77 int *sc_status
78 )
79 {
80 CFIndex len;
81 serverSessionRef mySession = getSession(server);
82 CFArrayRef notifierKeys; /* array of CFStringRef's */
83 Boolean ok;
84
85 *listRef = NULL;
86 *listLen = 0;
87
88 if (mySession == NULL) {
89 *sc_status = kSCStatusNoStoreSession; /* you must have an open session to play */
90 return KERN_SUCCESS;
91 }
92
93 *sc_status = __SCDynamicStoreCopyNotifiedKeys(mySession->store, &notifierKeys);
94 if (*sc_status != kSCStatusOK) {
95 return KERN_SUCCESS;
96 }
97
98 /* serialize the array of keys */
99 ok = _SCSerialize(notifierKeys, NULL, (void **)listRef, &len);
100 *listLen = (mach_msg_type_number_t)len;
101 CFRelease(notifierKeys);
102 if (!ok) {
103 *sc_status = kSCStatusFailed;
104 return KERN_SUCCESS;
105 }
106
107 return KERN_SUCCESS;
108 }