2 * Copyright (c) 2000, 2001, 2003-2005, 2009-2011, 2013, 2016, 2017 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
25 * Modification History
27 * June 1, 2001 Allan Nathanson <ajn@apple.com>
31 #include "SCDynamicStoreInternal.h"
32 #include "config.h" /* MiG generated file */
35 SCDynamicStoreSetNotificationKeys(SCDynamicStoreRef store
,
39 SCDynamicStorePrivateRef storePrivate
= (SCDynamicStorePrivateRef
)store
;
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;
48 CFMutableArrayRef tmp
;
51 /* sorry, you must provide a session */
52 _SCErrorSet(kSCStatusNoStoreSession
);
56 if (storePrivate
->server
== MACH_PORT_NULL
) {
57 _SCErrorSet(kSCStatusNoStoreServer
);
58 return FALSE
; /* you must have an open session to play */
61 /* serialize the keys */
63 if (!_SCSerialize(keys
, &xmlKeys
, (void **)&myKeysRef
, &myKeysLen
)) {
64 _SCErrorSet(kSCStatusFailed
);
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
);
78 #ifdef VERBOSE_ACTIVITY_LOGGING
79 os_activity_scope(storePrivate
->activity
);
80 #endif // VERBOSE_ACTIVITY_LOGGING
84 /* send the keys and patterns, fetch the associated result from the server */
85 status
= notifyset(storePrivate
->server
,
87 (mach_msg_type_number_t
)myKeysLen
,
89 (mach_msg_type_number_t
)myPatternsLen
,
92 if (__SCDynamicStoreCheckRetryAndHandleError(store
,
95 "SCDynamicStoreSetNotificationKeys notifyset()")) {
100 if (xmlKeys
!= NULL
) CFRelease(xmlKeys
);
101 if (xmlPatterns
!= NULL
) CFRelease(xmlPatterns
);
103 if (sc_status
!= kSCStatusOK
) {
104 _SCErrorSet(sc_status
);
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
;
113 tmp
= (patterns
!= NULL
) ? CFArrayCreateMutableCopy(NULL
, 0, patterns
) : NULL
;
114 if (storePrivate
->patterns
!= NULL
) CFRelease(storePrivate
->patterns
);
115 storePrivate
->patterns
= tmp
;