]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCDNotifierSetKeys.c
configd-963.260.1.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / SCDNotifierSetKeys.c
1 /*
2 * Copyright (c) 2000, 2001, 2003-2005, 2009-2011, 2013, 2016, 2017 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 * - initial revision
29 */
30
31 #include "SCDynamicStoreInternal.h"
32 #include "config.h" /* MiG generated file */
33
34 Boolean
35 SCDynamicStoreSetNotificationKeys(SCDynamicStoreRef store,
36 CFArrayRef keys,
37 CFArrayRef patterns)
38 {
39 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
40 kern_return_t status;
41 CFDataRef xmlKeys = NULL; /* keys (XML serialized) */
42 xmlData_t myKeysRef = NULL; /* keys (serialized) */
43 CFIndex myKeysLen = 0;
44 CFDataRef xmlPatterns = NULL; /* patterns (XML serialized) */
45 xmlData_t myPatternsRef = NULL; /* patterns (serialized) */
46 CFIndex myPatternsLen = 0;
47 int sc_status;
48 CFMutableArrayRef tmp;
49
50 if (store == NULL) {
51 /* sorry, you must provide a session */
52 _SCErrorSet(kSCStatusNoStoreSession);
53 return FALSE;
54 }
55
56 if (storePrivate->server == MACH_PORT_NULL) {
57 _SCErrorSet(kSCStatusNoStoreServer);
58 return FALSE; /* you must have an open session to play */
59 }
60
61 /* serialize the keys */
62 if (keys != NULL) {
63 if (!_SCSerialize(keys, &xmlKeys, (void **)&myKeysRef, &myKeysLen)) {
64 _SCErrorSet(kSCStatusFailed);
65 return FALSE;
66 }
67 }
68
69 /* serialize the patterns */
70 if (patterns != NULL) {
71 if (!_SCSerialize(patterns, &xmlPatterns, (void **)&myPatternsRef, &myPatternsLen)) {
72 if (xmlKeys != NULL) CFRelease(xmlKeys);
73 _SCErrorSet(kSCStatusFailed);
74 return FALSE;
75 }
76 }
77
78 #ifdef VERBOSE_ACTIVITY_LOGGING
79 os_activity_scope(storePrivate->activity);
80 #endif // VERBOSE_ACTIVITY_LOGGING
81
82 retry :
83
84 /* send the keys and patterns, fetch the associated result from the server */
85 status = notifyset(storePrivate->server,
86 myKeysRef,
87 (mach_msg_type_number_t)myKeysLen,
88 myPatternsRef,
89 (mach_msg_type_number_t)myPatternsLen,
90 (int *)&sc_status);
91
92 if (__SCDynamicStoreCheckRetryAndHandleError(store,
93 status,
94 &sc_status,
95 "SCDynamicStoreSetNotificationKeys notifyset()")) {
96 goto retry;
97 }
98
99 /* clean up */
100 if (xmlKeys != NULL) CFRelease(xmlKeys);
101 if (xmlPatterns != NULL) CFRelease(xmlPatterns);
102
103 if (sc_status != kSCStatusOK) {
104 _SCErrorSet(sc_status);
105 return FALSE;
106 }
107
108 /* in case we need to re-connect, save the keys/patterns */
109 tmp = (keys != NULL) ? CFArrayCreateMutableCopy(NULL, 0, keys) : NULL;
110 if (storePrivate->keys != NULL) CFRelease(storePrivate->keys);
111 storePrivate->keys = tmp;
112
113 tmp = (patterns != NULL) ? CFArrayCreateMutableCopy(NULL, 0, patterns) : NULL;
114 if (storePrivate->patterns != NULL) CFRelease(storePrivate->patterns);
115 storePrivate->patterns = tmp;
116
117 return TRUE;
118 }