]> git.saurik.com Git - apple/configd.git/blob - scutil.tproj/session.c
configd-293.4.tar.gz
[apple/configd.git] / scutil.tproj / session.c
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, 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 __private_extern__
39 void
40 do_open(int argc, char **argv)
41 {
42 if (store) {
43 CFRelease(store);
44 CFRelease(watchedKeys);
45 CFRelease(watchedPatterns);
46 }
47
48 if (argc < 1) {
49 store = SCDynamicStoreCreate(NULL, CFSTR("scutil"), storeCallback, NULL);
50 } else {
51 CFMutableDictionaryRef options;
52
53 options = CFDictionaryCreateMutable(NULL,
54 0,
55 &kCFTypeDictionaryKeyCallBacks,
56 &kCFTypeDictionaryValueCallBacks);
57 CFDictionarySetValue(options, kSCDynamicStoreUseSessionKeys, kCFBooleanTrue);
58 store = SCDynamicStoreCreateWithOptions(NULL,
59 CFSTR("scutil"),
60 options,
61 storeCallback,
62 NULL);
63 CFRelease(options);
64 }
65 if (store == NULL) {
66 SCPrint(TRUE, stdout, CFSTR(" %s\n"), SCErrorString(SCError()));
67 return;
68 }
69
70 watchedKeys = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
71 watchedPatterns = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
72
73 return;
74 }
75
76
77 __private_extern__
78 void
79 do_close(int argc, char **argv)
80 {
81 if (notifyRls) {
82 CFRunLoopSourceInvalidate(notifyRls);
83 CFRelease(notifyRls);
84 notifyRls = NULL;
85 }
86
87 if (notifyRl) {
88 CFRunLoopStop(notifyRl);
89 notifyRl = NULL;
90 }
91
92 if (store) {
93 CFRelease(store);
94 store = NULL;
95 CFRelease(watchedKeys);
96 watchedKeys = NULL;
97 CFRelease(watchedPatterns);
98 watchedPatterns = NULL;
99 }
100 return;
101 }
102
103
104 __private_extern__
105 void
106 do_lock(int argc, char **argv)
107 {
108 if (!SCDynamicStoreLock(store)) {
109 SCPrint(TRUE, stdout, CFSTR(" %s\n"), SCErrorString(SCError()));
110 }
111 return;
112 }
113
114
115 __private_extern__
116 void
117 do_unlock(int argc, char **argv)
118 {
119 if (!SCDynamicStoreUnlock(store)) {
120 SCPrint(TRUE, stdout, CFSTR(" %s\n"), SCErrorString(SCError()));
121 }
122 return;
123 }