]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCDNotifierSetKeys.c
configd-1061.0.2.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / SCDNotifierSetKeys.c
1 /*
2 * Copyright (c) 2000, 2001, 2003-2005, 2009-2011, 2013, 2016, 2017, 2019 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
79 retry :
80
81 /* send the keys and patterns, fetch the associated result from the server */
82 status = notifyset(storePrivate->server,
83 myKeysRef,
84 (mach_msg_type_number_t)myKeysLen,
85 myPatternsRef,
86 (mach_msg_type_number_t)myPatternsLen,
87 (int *)&sc_status);
88
89 if (__SCDynamicStoreCheckRetryAndHandleError(store,
90 status,
91 &sc_status,
92 "SCDynamicStoreSetNotificationKeys notifyset()")) {
93 goto retry;
94 }
95
96 /* clean up */
97 if (xmlKeys != NULL) CFRelease(xmlKeys);
98 if (xmlPatterns != NULL) CFRelease(xmlPatterns);
99
100 if (sc_status != kSCStatusOK) {
101 _SCErrorSet(sc_status);
102 return FALSE;
103 }
104
105 /* in case we need to re-connect, save the keys/patterns */
106 tmp = (keys != NULL) ? CFArrayCreateMutableCopy(NULL, 0, keys) : NULL;
107 if (storePrivate->keys != NULL) CFRelease(storePrivate->keys);
108 storePrivate->keys = tmp;
109
110 tmp = (patterns != NULL) ? CFArrayCreateMutableCopy(NULL, 0, patterns) : NULL;
111 if (storePrivate->patterns != NULL) CFRelease(storePrivate->patterns);
112 storePrivate->patterns = tmp;
113
114 return TRUE;
115 }