1 karl 1.4 //%2006////////////////////////////////////////////////////////////////////////
|
2 h.sterling 1.1 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.4 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 h.sterling 1.1 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
20 //
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34 h.sterling 1.1 #include <Pegasus/Common/Config.h>
35 #include <Pegasus/Common/OptionManager.h>
36 #include <Pegasus/Common/FileSystem.h>
37 #include <Pegasus/Common/Tracer.h>
38 #include <Pegasus/Common/Exception.h>
39
40 #include "DynamicListenerConfig.h"
41
42 PEGASUS_NAMESPACE_BEGIN
43 PEGASUS_USING_STD;
44
45
46 const String LISTENER_HOME_DEFAULT = ".";
47 String DynamicListenerConfig::_listenerHome = LISTENER_HOME_DEFAULT;
48
49
50 static struct OptionRow optionsTable[] =
51 //optionname defaultvalue rqd type domain domainsize clname hlpmsg
52 {
53
|
54 marek 1.6 {"listenerPort", "5999", false, Option::WHOLE_NUMBER, 0, 0,
55 "listenerPort", "specifies system and port"},
|
56 h.sterling 1.1 #ifdef PEGASUS_HAS_SSL
|
57 marek 1.6 {"enableHttpsListenerConnection", "false", false, Option::BOOLEAN, 0, 0,
58 "enableHttpsListenerConnection", "specifies namespace to use for operation"},
|
59 h.sterling 1.1
|
60 marek 1.6 {"sslKeyFilePath", "", false, Option::STRING, 0, 0,
61 "sslKeyFilePath", "path to the listener's SSL private key"},
|
62 h.sterling 1.1
|
63 marek 1.6 {"sslCertificateFilePath", "", false, Option::STRING, 0, 0,
64 "sslCertificateFilePath",
65 "path to the listener's SSL public key certificate."},
|
66 h.sterling 1.1 #endif
|
67 marek 1.6 {"consumerDir", "", false, Option::STRING, 0, 0,
68 "consumerDir", "path to the consumer libraries"},
|
69 h.sterling 1.1
|
70 marek 1.6 {"consumerConfigDir", "", false, Option::STRING, 0, 0,
71 "consumerConfigDir", "path to the consumer configuration files"},
|
72 h.sterling 1.1
|
73 marek 1.6 {"enableConsumerUnload", "false", false, Option::BOOLEAN, 0, 0,
74 "enableConsumerUnload",
75 "specifies whether the listener should unload idle consumers"},
|
76 h.sterling 1.1
|
77 marek 1.6 {"consumerIdleTimeout", "300000", false, Option::WHOLE_NUMBER, 0, 0,
78 "consumerIdleTimeout",
79 "period of inactivity, in ms, before consumers are unloaded"},
|
80 h.sterling 1.1
|
81 marek 1.6 {"shutdownTimeout", "10000", false, Option::WHOLE_NUMBER, 0, 0,
82 "shutdownTimeout",
83 "the length of time to wait for consumer threads to complete, in ms"},
|
84 h.sterling 1.1
|
85 marek 1.6 {"traceFilePath", "cimlistener.trc", false, Option::STRING, 0, 0,
86 "traceFilePath", "path to the listener's trace file"},
|
87 h.sterling 1.1
|
88 marek 1.6 {"traceLevel", "0", false, Option::WHOLE_NUMBER, 0, 0,
89 "traceLevel", "the level of logging detail"},
|
90 h.sterling 1.1
|
91 marek 1.6 {"traceComponents", "LISTENER", false, Option::STRING, 0, 0,
92 "traceComponents", "the components to trace"},
|
93 h.sterling 1.1
94 };
95
96 const Uint32 NUM_OPTIONS = sizeof(optionsTable) / sizeof(optionsTable[0]);
97
98 DynamicListenerConfig* DynamicListenerConfig::_instance = 0;
99
100 DynamicListenerConfig::DynamicListenerConfig()
101 {
102 FileSystem::getCurrentDirectory(_listenerHome);
103 FileSystem::translateSlashes(_listenerHome);
104 }
105
106 DynamicListenerConfig::~DynamicListenerConfig()
107 {
108 }
109
110 DynamicListenerConfig* DynamicListenerConfig::getInstance()
111 {
112 if (!_instance)
113 {
114 h.sterling 1.1 _instance = new DynamicListenerConfig();
|
115 h.sterling 1.2 }
|
116 h.sterling 1.1
117 return _instance;
118 }
119
120 void DynamicListenerConfig::initOptions(const String& configFile)
121 {
122 _optionMgr.registerOptions(optionsTable, NUM_OPTIONS);
123
124 //do not throw an error if there's no config file; just use the defaults
125 if (FileSystem::exists(configFile))
126 {
127 _optionMgr.mergeFile(configFile);
128 }
129
130 _optionMgr.checkRequiredOptions();
131 }
132
|
133 marek 1.6 Boolean DynamicListenerConfig::lookupValue(
134 const String& name,
135 String& value) const
|
136 h.sterling 1.1 {
137 String temp;
138 if (!_optionMgr.lookupValue(name, temp))
139 {
140 return false;
141 }
142
|
143 marek 1.6 if (String::equal(name, "consumerDir") ||
144 String::equal(name, "consumerConfigDir"))
|
145 h.sterling 1.1 {
146 value = DynamicListenerConfig::getHomedPath(temp);
147
|
148 marek 1.6 if (!FileSystem::exists(value) ||
149 !FileSystem::isDirectory(value) ||
150 !FileSystem::canRead(value))
|
151 h.sterling 1.1 {
152 throw OMInvalidOptionValue(name, value);
153 }
154
|
155 marek 1.6 // must be able to write pending requests to
156 // .dat files in the config directory
157 if (String::equal(name, "consumerConfigDir") &&
158 !FileSystem::canWrite(value))
|
159 h.sterling 1.1 {
160 throw OMInvalidOptionValue(name, value);
161 }
162
163 } else if (String::equal(name, "traceFilePath"))
164 {
|
165 marek 1.6 //a blank value is acceptable and indicates
166 // that no tracing will be done
|
167 h.sterling 1.1 if (String::equal(temp, ""))
168 {
169 value = String::EMPTY;
170 return true;
171 }
172
|
173 marek 1.6 value = DynamicListenerConfig::getHomedPath(temp);
|
174 h.sterling 1.2
|
175 marek 1.6 //check to make sure we can create trace file
176 String path = FileSystem::extractFilePath(value);
|
177 h.sterling 1.1
|
178 h.sterling 1.2 if (!FileSystem::exists(path) || !FileSystem::canWrite(path))
|
179 h.sterling 1.1 {
|
180 h.sterling 1.2 throw OMInvalidOptionValue(name, value);
|
181 h.sterling 1.1 }
182 }
183 #ifdef PEGASUS_HAS_SSL
|
184 marek 1.6 else if (String::equal(name, "sslKeyFilePath") ||
185 String::equal(name, "sslCertificateFilePath"))
|
186 h.sterling 1.1 {
187 //a blank value is acceptable and is the default
188 if (String::equal(temp, ""))
189 {
190 value = String::EMPTY;
191 return true;
192 }
193
194 value = DynamicListenerConfig::getHomedPath(temp);
195
196 if (!FileSystem::exists(value) || !FileSystem::canRead(value))
197 {
198 throw OMInvalidOptionValue(name, value);
199 }
200 }
201 #endif
202 else
203 {
204 value = temp;
205 }
206
207 h.sterling 1.1 return true;
208 }
209
210
|
211 marek 1.6 Boolean DynamicListenerConfig::lookupIntegerValue(
212 const String& name,
213 Uint32& value) const
|
214 h.sterling 1.1 {
215 if (!_optionMgr.lookupIntegerValue(name, value))
216 {
217 return false;
218 }
219
220 if (String::equal(name, "listenerPort"))
221 {
222 } else if (String::equal(name, "consumerIdleTimeout"))
223 {
224 } else if (String::equal(name, "shutdownTimeout"))
225 {
226 } else if (String::equal(name, "traceLevel"))
227 {
|
228 h.sterling 1.3 if (value > 4)
|
229 h.sterling 1.1 {
230 throw OMInvalidOptionValue(name, "");
231 }
232 }
233
234 return true;
235 }
236
|
237 marek 1.6 Boolean DynamicListenerConfig::valueEquals(
238 const String& name,
239 const String& value) const
|
240 h.sterling 1.1 {
241 //not implemented yet -- do we need this in addition to lookupValue()?
242 return _optionMgr.valueEquals(name, value);
243 }
244
245 Boolean DynamicListenerConfig::isTrue(const String& name) const
246 {
247 //no additional checking for booleans
248 return _optionMgr.isTrue(name);
249 }
250
251 String DynamicListenerConfig::getListenerHome()
252 {
253 return _listenerHome;
254 }
255
256 //This sets the listener home to the FULL path
257 //We do it once here so we do not have to keep doing file operations later on
258 void DynamicListenerConfig::setListenerHome(const String& home)
259 {
|
260 marek 1.6 PEG_METHOD_ENTER(TRC_LISTENER, "DynamicListenerConfig::setListenerHome");
|
261 h.sterling 1.2
|
262 h.sterling 1.1 if (System::is_absolute_path((const char *)home.getCString()))
263 {
264 _listenerHome = home;
265
266 } else
267 {
268 String currentDir;
269 FileSystem::getCurrentDirectory(currentDir);
|
270 marek 1.6 _listenerHome = FileSystem::getAbsolutePath(
271 (const char*)currentDir.getCString(),
272 home);
|
273 h.sterling 1.1 }
|
274 h.sterling 1.2
|
275 marek 1.6 PEG_METHOD_EXIT();
|
276 h.sterling 1.1 }
277
278 String DynamicListenerConfig::getHomedPath(const String& value)
279 {
|
280 h.sterling 1.2 PEG_METHOD_ENTER(TRC_LISTENER, "DynamicListenerConfig::getHomedPath()");
281
|
282 kumpf 1.5 String homedPath;
|
283 h.sterling 1.1
284 if (String::equal(value, String::EMPTY))
285 {
286 homedPath = _listenerHome;
287
288 } else
289 {
|
290 marek 1.6 homedPath = FileSystem::getAbsolutePath(
291 (const char*)_listenerHome.getCString(),
292 value);
293 }
|
294 h.sterling 1.1 FileSystem::translateSlashes(homedPath);
295
296 PEG_METHOD_EXIT();
297 return homedPath;
298 }
299
300
301
302
303
304 PEGASUS_NAMESPACE_END
|