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