]> git.saurik.com Git - apple/configd.git/blob - configd.tproj/_notifychanges.c
0cb0ed8232a3d132338e3f9065f64059e49ed1a7
[apple/configd.git] / configd.tproj / _notifychanges.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 /*
24 * Modification History
25 *
26 * June 1, 2001 Allan Nathanson <ajn@apple.com>
27 * - public API conversion
28 *
29 * March 24, 2000 Allan Nathanson <ajn@apple.com>
30 * - initial revision
31 */
32
33 #include "configd.h"
34 #include "session.h"
35
36 int
37 __SCDynamicStoreCopyNotifiedKeys(SCDynamicStoreRef store, CFArrayRef *notifierKeys)
38 {
39 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
40 CFStringRef sessionKey;
41 CFDictionaryRef info;
42 CFMutableDictionaryRef newInfo;
43
44 SCLog(_configd_verbose, LOG_DEBUG, CFSTR("__SCDynamicStoreCopyNotifiedKeys:"));
45
46 if (!store || (storePrivate->server == MACH_PORT_NULL)) {
47 return kSCStatusNoStoreSession; /* you must have an open session to play */
48 }
49
50 sessionKey = CFStringCreateWithFormat(NULL, NULL, CFSTR("%d"), storePrivate->server);
51 info = CFDictionaryGetValue(sessionData, sessionKey);
52 if ((info == NULL) ||
53 (CFDictionaryContainsKey(info, kSCDChangedKeys) == FALSE)) {
54 CFRelease(sessionKey);
55 *notifierKeys = CFArrayCreate(NULL, NULL, 0, &kCFTypeArrayCallBacks);;
56 return kSCStatusOK;
57 }
58 newInfo = CFDictionaryCreateMutableCopy(NULL, 0, info);
59
60 *notifierKeys = CFDictionaryGetValue(newInfo, kSCDChangedKeys);
61 CFRetain(*notifierKeys);
62
63 CFDictionaryRemoveValue(newInfo, kSCDChangedKeys);
64 if (CFDictionaryGetCount(newInfo) > 0) {
65 CFDictionarySetValue(sessionData, sessionKey, newInfo);
66 } else {
67 CFDictionaryRemoveValue(sessionData, sessionKey);
68 }
69 CFRelease(newInfo);
70 CFRelease(sessionKey);
71
72 return kSCStatusOK;
73 }
74
75
76 kern_return_t
77 _notifychanges(mach_port_t server,
78 xmlDataOut_t *listRef, /* raw XML bytes */
79 mach_msg_type_number_t *listLen,
80 int *sc_status
81 )
82 {
83 kern_return_t status;
84 serverSessionRef mySession = getSession(server);
85 CFArrayRef notifierKeys; /* array of CFStringRef's */
86 CFDataRef xmlList; /* list (XML serialized) */
87
88 SCLog(_configd_verbose, LOG_DEBUG, CFSTR("List notification keys which have changed."));
89 SCLog(_configd_verbose, LOG_DEBUG, CFSTR(" server = %d"), server);
90
91 *sc_status = __SCDynamicStoreCopyNotifiedKeys(mySession->store, &notifierKeys);
92 if (*sc_status != kSCStatusOK) {
93 *listRef = NULL;
94 *listLen = 0;
95 return KERN_SUCCESS;
96 }
97
98 /*
99 * serialize the array, copy it into an allocated buffer which will be
100 * released when it is returned as part of a Mach message.
101 */
102 xmlList = CFPropertyListCreateXMLData(NULL, notifierKeys);
103 CFRelease(notifierKeys);
104 *listLen = CFDataGetLength(xmlList);
105 status = vm_allocate(mach_task_self(), (void *)listRef, *listLen, TRUE);
106 if (status != KERN_SUCCESS) {
107 SCLog(_configd_verbose, LOG_DEBUG, CFSTR("vm_allocate(): %s"), mach_error_string(status));
108 CFRelease(xmlList);
109 *listRef = NULL;
110 *listLen = 0;
111 *sc_status = kSCStatusFailed;
112 return KERN_SUCCESS;
113 }
114
115 bcopy((char *)CFDataGetBytePtr(xmlList), *listRef, *listLen);
116 CFRelease(xmlList);
117
118 return KERN_SUCCESS;
119 }