Commit | Line | Data |
---|---|---|
5958d7c0 | 1 | /* |
a40a14f8 | 2 | * Copyright (c) 2000-2004, 2006, 2008 Apple Inc. All rights reserved. |
5958d7c0 A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
009ee3c6 | 5 | * |
009ee3c6 A |
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 | |
5958d7c0 A |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
009ee3c6 A |
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 | * | |
5958d7c0 A |
21 | * @APPLE_LICENSE_HEADER_END@ |
22 | */ | |
23 | ||
0fae82ee A |
24 | /* |
25 | * Modification History | |
26 | * | |
27 | * June 1, 2001 Allan Nathanson <ajn@apple.com> | |
28 | * - public API conversion | |
29 | * | |
30 | * March 24, 2000 Allan Nathanson <ajn@apple.com> | |
31 | * - initial revision | |
32 | */ | |
33 | ||
009ee3c6 | 34 | |
5958d7c0 A |
35 | #include "configd.h" |
36 | #include "session.h" | |
009ee3c6 | 37 | #include "pattern.h" |
5958d7c0 | 38 | |
0fae82ee | 39 | |
009ee3c6 | 40 | __private_extern__ |
0fae82ee | 41 | int |
009ee3c6 | 42 | __SCDynamicStoreRemoveWatchedKey(SCDynamicStoreRef store, CFStringRef key, Boolean isRegex, Boolean internal) |
0fae82ee | 43 | { |
009ee3c6 | 44 | CFNumberRef sessionNum; |
0fae82ee | 45 | SCDynamicStorePrivateRef storePrivate = (SCDynamicStorePrivateRef)store; |
5958d7c0 | 46 | |
edebe297 | 47 | if ((store == NULL) || (storePrivate->server == MACH_PORT_NULL)) { |
0fae82ee | 48 | return kSCStatusNoStoreSession; /* you must have an open session to play */ |
5958d7c0 A |
49 | } |
50 | ||
009ee3c6 A |
51 | if (_configd_trace) { |
52 | SCTrace(TRUE, _configd_trace, | |
53 | CFSTR("%s : %5d : %s : %@\n"), | |
54 | internal ? "*watch-" : "watch- ", | |
55 | storePrivate->server, | |
56 | isRegex ? "pattern" : "key", | |
57 | key); | |
58 | } | |
59 | ||
5958d7c0 A |
60 | /* |
61 | * remove key from this sessions notifier list after checking that | |
62 | * it was previously defined. | |
63 | */ | |
0fae82ee | 64 | if (isRegex) { |
009ee3c6 | 65 | if (!CFSetContainsValue(storePrivate->patterns, key)) |
0fae82ee | 66 | return kSCStatusNoKey; /* sorry, key does not exist in notifier list */ |
009ee3c6 A |
67 | |
68 | /* remove key from this sessions notifier list */ | |
69 | CFSetRemoveValue(storePrivate->patterns, key); | |
70 | ||
71 | /* remove this session as a pattern watcher */ | |
72 | sessionNum = CFNumberCreate(NULL, kCFNumberIntType, &storePrivate->server); | |
73 | patternRemoveSession(key, sessionNum); | |
74 | CFRelease(sessionNum); | |
5958d7c0 | 75 | } else { |
0fae82ee A |
76 | if (!CFSetContainsValue(storePrivate->keys, key)) |
77 | return kSCStatusNoKey; /* sorry, key does not exist in notifier list */ | |
5958d7c0 | 78 | |
009ee3c6 A |
79 | /* remove key from this sessions notifier list */ |
80 | CFSetRemoveValue(storePrivate->keys, key); | |
5958d7c0 A |
81 | |
82 | /* | |
83 | * We are watching a specific key. As such, update the | |
0fae82ee | 84 | * store to mark our interest in any changes. |
5958d7c0 | 85 | */ |
0fae82ee | 86 | sessionNum = CFNumberCreate(NULL, kCFNumberIntType, &storePrivate->server); |
5958d7c0 A |
87 | _removeWatcher(sessionNum, key); |
88 | CFRelease(sessionNum); | |
89 | } | |
90 | ||
0fae82ee | 91 | return kSCStatusOK; |
5958d7c0 A |
92 | } |
93 | ||
94 | ||
009ee3c6 | 95 | __private_extern__ |
5958d7c0 A |
96 | kern_return_t |
97 | _notifyremove(mach_port_t server, | |
98 | xmlData_t keyRef, /* raw XML bytes */ | |
99 | mach_msg_type_number_t keyLen, | |
0fae82ee A |
100 | int isRegex, |
101 | int *sc_status | |
5958d7c0 A |
102 | ) |
103 | { | |
dbf6a266 | 104 | CFStringRef key = NULL; /* key (un-serialized) */ |
a40a14f8 | 105 | serverSessionRef mySession; |
5958d7c0 A |
106 | |
107 | /* un-serialize the key */ | |
009ee3c6 | 108 | if (!_SCUnserializeString(&key, NULL, (void *)keyRef, keyLen)) { |
0fae82ee | 109 | *sc_status = kSCStatusFailed; |
dbf6a266 | 110 | goto done; |
a5f60add A |
111 | } |
112 | ||
113 | if (!isA_CFString(key)) { | |
0fae82ee | 114 | *sc_status = kSCStatusInvalidArgument; |
dbf6a266 | 115 | goto done; |
009ee3c6 A |
116 | } |
117 | ||
a40a14f8 | 118 | mySession = getSession(server); |
edebe297 | 119 | if (mySession == NULL) { |
009ee3c6 | 120 | *sc_status = kSCStatusNoStoreSession; /* you must have an open session to play */ |
dbf6a266 | 121 | goto done; |
5958d7c0 A |
122 | } |
123 | ||
009ee3c6 A |
124 | *sc_status = __SCDynamicStoreRemoveWatchedKey(mySession->store, |
125 | key, | |
126 | isRegex != 0, | |
127 | FALSE); | |
5958d7c0 | 128 | |
dbf6a266 A |
129 | done : |
130 | ||
131 | if (key) CFRelease(key); | |
5958d7c0 A |
132 | return KERN_SUCCESS; |
133 | } | |
134 |