]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCDCache.c
configd-1109.40.9.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / SCDCache.c
1 /*
2 * Copyright (c) 2018 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 * Oct 1, 2018 Allan Nathanson <ajn@apple.com>
28 * - initial revision
29 */
30
31
32 #ifdef SC_LOG_HANDLE
33 #include <os/log.h>
34 os_log_t SC_LOG_HANDLE(void);
35 #endif //SC_LOG_HANDLE
36
37 #include "SCDynamicStoreInternal.h"
38
39
40 Boolean
41 _SCDynamicStoreCacheIsActive(SCDynamicStoreRef store)
42 {
43 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
44
45 if (store == NULL) {
46 // sorry, you must provide a session
47 _SCErrorSet(kSCStatusNoStoreSession);
48 return FALSE;
49 }
50
51 return storePrivate->cache_active;
52 }
53
54
55 static void
56 __SCDynamicStoreCacheRelease(SCDynamicStoreRef store)
57 {
58 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
59
60 if (storePrivate->cached_keys != NULL) {
61 CFRelease(storePrivate->cached_keys);
62 storePrivate->cached_keys = NULL;
63 }
64 if (storePrivate->cached_set != NULL) {
65 CFRelease(storePrivate->cached_set);
66 storePrivate->cached_set = NULL;
67 }
68 if (storePrivate->cached_removals != NULL) {
69 CFRelease(storePrivate->cached_removals);
70 storePrivate->cached_removals = NULL;
71 }
72 if (storePrivate->cached_notifys != NULL) {
73 CFRelease(storePrivate->cached_notifys);
74 storePrivate->cached_notifys = NULL;
75 }
76
77 return;
78 }
79
80
81 Boolean
82 _SCDynamicStoreCacheOpen(SCDynamicStoreRef store)
83 {
84 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
85
86 if (store == NULL) {
87 // sorry, you must provide a session
88 _SCErrorSet(kSCStatusNoStoreSession);
89 return FALSE;
90 }
91
92 __SCDynamicStoreCacheRelease(store); // if we are already using the cache, start clean
93 storePrivate->cache_active = TRUE;
94
95 return TRUE;
96 }
97
98
99 Boolean
100 _SCDynamicStoreCacheCommitChanges(SCDynamicStoreRef store)
101 {
102 Boolean ok = TRUE;
103 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
104
105 if (store == NULL) {
106 // sorry, you must provide a session
107 _SCErrorSet(kSCStatusNoStoreSession);
108 return FALSE;
109 }
110
111 if (!storePrivate->cache_active) {
112 // if not using the cache
113 _SCErrorSet(kSCStatusFailed);
114 return FALSE;
115 }
116
117 if ((storePrivate->cached_set != NULL) ||
118 (storePrivate->cached_removals != NULL) ||
119 (storePrivate->cached_notifys != NULL)) {
120 ok = SCDynamicStoreSetMultiple(store,
121 storePrivate->cached_set,
122 storePrivate->cached_removals,
123 storePrivate->cached_notifys);
124 __SCDynamicStoreCacheRelease(store);
125 }
126
127 return ok;
128 }
129
130
131 Boolean
132 _SCDynamicStoreCacheClose(SCDynamicStoreRef store)
133 {
134 SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store;
135
136 if (store == NULL) {
137 // sorry, you must provide a session
138 _SCErrorSet(kSCStatusNoStoreSession);
139 return FALSE;
140 }
141
142 if (!storePrivate->cache_active) {
143 // if not using the cache
144 _SCErrorSet(kSCStatusFailed);
145 return FALSE;
146 }
147
148 __SCDynamicStoreCacheRelease(store);
149 storePrivate->cache_active = FALSE;
150
151 return TRUE;
152 }