]> git.saurik.com Git - apple/configd.git/blob - configd.tproj/_notifychanges.c
configd-24.1.tar.gz
[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 #include "configd.h"
24 #include "session.h"
25
26 SCDStatus
27 _SCDNotifierGetChanges(SCDSessionRef session, CFArrayRef *notifierKeys)
28 {
29 SCDSessionPrivateRef sessionPrivate = (SCDSessionPrivateRef)session;
30 CFStringRef sessionKey;
31 CFDictionaryRef info;
32 CFMutableDictionaryRef newInfo;
33
34 SCDLog(LOG_DEBUG, CFSTR("_SCDNotifierGetChanges:"));
35
36 if ((session == NULL) || (sessionPrivate->server == MACH_PORT_NULL)) {
37 return SCD_NOSESSION;
38 }
39
40 sessionKey = CFStringCreateWithFormat(NULL, NULL, CFSTR("%d"), sessionPrivate->server);
41 info = CFDictionaryGetValue(sessionData, sessionKey);
42 if ((info == NULL) ||
43 (CFDictionaryContainsKey(info, kSCDChangedKeys) == FALSE)) {
44 CFRelease(sessionKey);
45 *notifierKeys = CFArrayCreate(NULL, NULL, 0, &kCFTypeArrayCallBacks);;
46 return SCD_OK;
47 }
48 newInfo = CFDictionaryCreateMutableCopy(NULL, 0, info);
49
50 *notifierKeys = CFDictionaryGetValue(newInfo, kSCDChangedKeys);
51 CFRetain(*notifierKeys);
52
53 CFDictionaryRemoveValue(newInfo, kSCDChangedKeys);
54 if (CFDictionaryGetCount(newInfo) > 0) {
55 CFDictionarySetValue(sessionData, sessionKey, newInfo);
56 } else {
57 CFDictionaryRemoveValue(sessionData, sessionKey);
58 }
59 CFRelease(newInfo);
60 CFRelease(sessionKey);
61
62 return SCD_OK;
63 }
64
65
66 kern_return_t
67 _notifychanges(mach_port_t server,
68 xmlDataOut_t *listRef, /* raw XML bytes */
69 mach_msg_type_number_t *listLen,
70 int *scd_status
71 )
72 {
73 kern_return_t status;
74 serverSessionRef mySession = getSession(server);
75 CFArrayRef notifierKeys; /* array of CFStringRef's */
76 CFDataRef xmlList; /* list (XML serialized) */
77
78 SCDLog(LOG_DEBUG, CFSTR("List notification keys which have changed."));
79 SCDLog(LOG_DEBUG, CFSTR(" server = %d"), server);
80
81 *scd_status = _SCDNotifierGetChanges(mySession->session, &notifierKeys);
82 if (*scd_status != SCD_OK) {
83 *listRef = NULL;
84 *listLen = 0;
85 return KERN_SUCCESS;
86 }
87
88 /*
89 * serialize the array, copy it into an allocated buffer which will be
90 * released when it is returned as part of a Mach message.
91 */
92 xmlList = CFPropertyListCreateXMLData(NULL, notifierKeys);
93 CFRelease(notifierKeys);
94 *listLen = CFDataGetLength(xmlList);
95 status = vm_allocate(mach_task_self(), (void *)listRef, *listLen, TRUE);
96 if (status != KERN_SUCCESS) {
97 SCDLog(LOG_DEBUG, CFSTR("vm_allocate(): %s"), mach_error_string(status));
98 CFRelease(xmlList);
99 *listRef = NULL;
100 *listLen = 0;
101 *scd_status = SCD_FAILED;
102 return KERN_SUCCESS;
103 }
104
105 bcopy((char *)CFDataGetBytePtr(xmlList), *listRef, *listLen);
106 CFRelease(xmlList);
107
108 return KERN_SUCCESS;
109 }