]> git.saurik.com Git - apple/configd.git/blob - scutil.tproj/session.c
configd-395.6.tar.gz
[apple/configd.git] / scutil.tproj / session.c
1 /*
2 * Copyright (c) 2000-2004, 2010 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 * - public API conversion
29 *
30 * November 9, 2000 Allan Nathanson <ajn@apple.com>
31 * - initial revision
32 */
33
34 #include "scutil.h"
35 #include "session.h"
36 #include "notifications.h"
37
38
39 static void
40 reconnected(SCDynamicStoreRef store, void *info)
41 {
42 SCPrint(TRUE, stdout, CFSTR("SCDynamicStore server restarted, session reconnected\n"));
43 return;
44 }
45
46
47 __private_extern__
48 void
49 do_open(int argc, char **argv)
50 {
51 if (store) {
52 CFRelease(store);
53 CFRelease(watchedKeys);
54 CFRelease(watchedPatterns);
55 }
56
57 if (argc < 1) {
58 store = SCDynamicStoreCreate(NULL, CFSTR("scutil"), storeCallback, NULL);
59 } else {
60 CFMutableDictionaryRef options;
61
62 options = CFDictionaryCreateMutable(NULL,
63 0,
64 &kCFTypeDictionaryKeyCallBacks,
65 &kCFTypeDictionaryValueCallBacks);
66 CFDictionarySetValue(options, kSCDynamicStoreUseSessionKeys, kCFBooleanTrue);
67 store = SCDynamicStoreCreateWithOptions(NULL,
68 CFSTR("scutil"),
69 options,
70 storeCallback,
71 NULL);
72 CFRelease(options);
73 }
74 if (store == NULL) {
75 SCPrint(TRUE, stdout, CFSTR(" %s\n"), SCErrorString(SCError()));
76 return;
77 }
78
79 (void) SCDynamicStoreSetDisconnectCallBack(store, reconnected);
80
81 watchedKeys = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
82 watchedPatterns = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
83
84 return;
85 }
86
87
88 __private_extern__
89 void
90 do_close(int argc, char **argv)
91 {
92 if (notifyRls != NULL) {
93 if (doDispatch) {
94 (void) SCDynamicStoreSetDispatchQueue(store, NULL);
95 } else {
96 CFRunLoopSourceInvalidate(notifyRls);
97 CFRelease(notifyRls);
98 }
99 notifyRls = NULL;
100 }
101
102 if (notifyRl != NULL) {
103 CFRunLoopStop(notifyRl);
104 notifyRl = NULL;
105 }
106
107 if (store != NULL) {
108 CFRelease(store);
109 store = NULL;
110 CFRelease(watchedKeys);
111 watchedKeys = NULL;
112 CFRelease(watchedPatterns);
113 watchedPatterns = NULL;
114 }
115 return;
116 }
117
118
119 __private_extern__
120 void
121 do_lock(int argc, char **argv)
122 {
123 if (!SCDynamicStoreLock(store)) {
124 SCPrint(TRUE, stdout, CFSTR(" %s\n"), SCErrorString(SCError()));
125 }
126 return;
127 }
128
129
130 __private_extern__
131 void
132 do_unlock(int argc, char **argv)
133 {
134 if (!SCDynamicStoreUnlock(store)) {
135 SCPrint(TRUE, stdout, CFSTR(" %s\n"), SCErrorString(SCError()));
136 }
137 return;
138 }