![]() ![]() |
![]() |
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 // Author: Heather Sterling (hsterl@us.ibm.com) 33 // 34 h.sterling 1.1 // Modified By: 35 // 36 //%///////////////////////////////////////////////////////////////////////////// 37 38 #include <Pegasus/Common/Config.h> 39 #include <Pegasus/Common/OptionManager.h> 40 #include <Pegasus/Common/FileSystem.h> 41 #include <Pegasus/Common/Tracer.h> 42 #include <Pegasus/Common/Exception.h> 43 44 #include "DynamicListenerConfig.h" 45 46 PEGASUS_NAMESPACE_BEGIN 47 PEGASUS_USING_STD; 48 49 50 const String LISTENER_HOME_DEFAULT = "."; 51 String DynamicListenerConfig::_listenerHome = LISTENER_HOME_DEFAULT; 52 53 54 static struct OptionRow optionsTable[] = 55 h.sterling 1.1 //optionname defaultvalue rqd type domain domainsize clname hlpmsg 56 { 57 58 {"listenerPort", "5999", false, Option::WHOLE_NUMBER, 0, 0, "listenerPort", "specifies system and port"}, 59 #ifdef PEGASUS_HAS_SSL 60 {"enableHttpsListenerConnection", "false", false, Option::BOOLEAN, 0, 0, "enableHttpsListenerConnection", "specifies namespace to use for operation"}, 61 62 {"sslKeyFilePath", "", false, Option::STRING, 0, 0, "sslKeyFilePath", "path to the listener's SSL private key"}, 63 64 {"sslCertificateFilePath", "", false, Option::STRING, 0, 0, "sslCertificateFilePath", "path to the listener's SSL public key certificate."}, 65 #endif 66 {"consumerDir", "", false, Option::STRING, 0, 0, "consumerDir", "path to the consumer libraries"}, 67 68 {"consumerConfigDir", "", false, Option::STRING, 0, 0, "consumerConfigDir", "path to the consumer configuration files"}, 69 70 {"enableConsumerUnload", "false", false, Option::BOOLEAN, 0, 0, "enableConsumerUnload", "specifies whether the listener should unload idle consumers"}, 71 72 {"consumerIdleTimeout", "300000", false, Option::WHOLE_NUMBER, 0, 0, "consumerIdleTimeout", "period of inactivity, in ms, before consumers are unloaded"}, 73 74 {"shutdownTimeout", "10000", false, Option::WHOLE_NUMBER, 0, 0, "shutdownTimeout", "the length of time to wait for consumer threads to complete, in ms"}, 75 76 h.sterling 1.1 {"traceFilePath", "cimlistener.trc", false, Option::STRING, 0, 0, "traceFilePath", "path to the listener's trace file"}, 77 78 {"traceLevel", "0", false, Option::WHOLE_NUMBER, 0, 0, "traceLevel", "the level of logging detail"}, 79 80 {"traceComponents", "LISTENER", false, Option::STRING, 0, 0, "traceComponents", "the components to trace"}, 81 82 }; 83 84 const Uint32 NUM_OPTIONS = sizeof(optionsTable) / sizeof(optionsTable[0]); 85 86 DynamicListenerConfig* DynamicListenerConfig::_instance = 0; 87 88 DynamicListenerConfig::DynamicListenerConfig() 89 { 90 FileSystem::getCurrentDirectory(_listenerHome); 91 FileSystem::translateSlashes(_listenerHome); 92 } 93 94 DynamicListenerConfig::~DynamicListenerConfig() 95 { 96 } 97 h.sterling 1.1 98 DynamicListenerConfig* DynamicListenerConfig::getInstance() 99 { 100 if (!_instance) 101 { 102 _instance = new DynamicListenerConfig(); | ||
103 h.sterling 1.2 } | ||
104 h.sterling 1.1 105 return _instance; 106 } 107 108 void DynamicListenerConfig::initOptions(const String& configFile) 109 { 110 _optionMgr.registerOptions(optionsTable, NUM_OPTIONS); 111 112 //do not throw an error if there's no config file; just use the defaults 113 if (FileSystem::exists(configFile)) 114 { 115 _optionMgr.mergeFile(configFile); 116 } 117 118 _optionMgr.checkRequiredOptions(); 119 } 120 121 Boolean DynamicListenerConfig::lookupValue(const String& name, String& value) const 122 { 123 String temp; 124 if (!_optionMgr.lookupValue(name, temp)) 125 h.sterling 1.1 { 126 return false; 127 } 128 129 if (String::equal(name, "consumerDir") || String::equal(name, "consumerConfigDir")) 130 { 131 value = DynamicListenerConfig::getHomedPath(temp); 132 133 if (!FileSystem::exists(value) || !FileSystem::isDirectory(value) || !FileSystem::canRead(value)) 134 { 135 throw OMInvalidOptionValue(name, value); 136 } 137 138 //must be able to write pending requests to .dat files in the config directory 139 if (String::equal(name, "consumerConfigDir") && !FileSystem::canWrite(value)) 140 { 141 throw OMInvalidOptionValue(name, value); 142 } 143 144 } else if (String::equal(name, "traceFilePath")) 145 { | ||
146 h.sterling 1.2 //a blank value is acceptable and indicates that no tracing will be done | ||
147 h.sterling 1.1 if (String::equal(temp, "")) 148 { 149 value = String::EMPTY; 150 return true; 151 } 152 | ||
153 h.sterling 1.2 value = DynamicListenerConfig::getHomedPath(temp); 154 155 //check to make sure we can create trace file 156 String path = FileSystem::extractFilePath(value); | ||
157 h.sterling 1.1 | ||
158 h.sterling 1.2 if (!FileSystem::exists(path) || !FileSystem::canWrite(path)) | ||
159 h.sterling 1.1 { | ||
160 h.sterling 1.2 throw OMInvalidOptionValue(name, value); | ||
161 h.sterling 1.1 } 162 } 163 #ifdef PEGASUS_HAS_SSL 164 else if (String::equal(name, "sslKeyFilePath") || String::equal(name, "sslCertificateFilePath")) 165 { 166 //a blank value is acceptable and is the default 167 if (String::equal(temp, "")) 168 { 169 value = String::EMPTY; 170 return true; 171 } 172 173 value = DynamicListenerConfig::getHomedPath(temp); 174 175 if (!FileSystem::exists(value) || !FileSystem::canRead(value)) 176 { 177 throw OMInvalidOptionValue(name, value); 178 } 179 } 180 #endif 181 else 182 h.sterling 1.1 { 183 value = temp; 184 } 185 186 return true; 187 } 188 189 190 Boolean DynamicListenerConfig::lookupIntegerValue(const String& name, Uint32& value) const 191 { 192 if (!_optionMgr.lookupIntegerValue(name, value)) 193 { 194 return false; 195 } 196 197 if (String::equal(name, "listenerPort")) 198 { 199 } else if (String::equal(name, "consumerIdleTimeout")) 200 { 201 } else if (String::equal(name, "shutdownTimeout")) 202 { 203 h.sterling 1.1 } else if (String::equal(name, "traceLevel")) 204 { | ||
205 h.sterling 1.3 if (value > 4) | ||
206 h.sterling 1.1 { 207 throw OMInvalidOptionValue(name, ""); 208 } 209 } 210 211 return true; 212 } 213 214 Boolean DynamicListenerConfig::valueEquals(const String& name, const String& value) const 215 { 216 //not implemented yet -- do we need this in addition to lookupValue()? 217 return _optionMgr.valueEquals(name, value); 218 } 219 220 Boolean DynamicListenerConfig::isTrue(const String& name) const 221 { 222 //no additional checking for booleans 223 return _optionMgr.isTrue(name); 224 } 225 226 String DynamicListenerConfig::getListenerHome() 227 h.sterling 1.1 { 228 return _listenerHome; 229 } 230 231 //This sets the listener home to the FULL path 232 //We do it once here so we do not have to keep doing file operations later on 233 void DynamicListenerConfig::setListenerHome(const String& home) 234 { | ||
235 h.sterling 1.2 PEG_METHOD_ENTER(TRC_LISTENER, "DynamicListenerConfig::setListenerHome"); 236 | ||
237 h.sterling 1.1 if (System::is_absolute_path((const char *)home.getCString())) 238 { 239 _listenerHome = home; 240 241 } else 242 { 243 String currentDir; 244 FileSystem::getCurrentDirectory(currentDir); 245 _listenerHome = FileSystem::getAbsolutePath((const char*)currentDir.getCString(), home); 246 } | ||
247 h.sterling 1.2 248 PEG_METHOD_EXIT(); | ||
249 h.sterling 1.1 } 250 251 String DynamicListenerConfig::getHomedPath(const String& value) 252 { | ||
253 h.sterling 1.2 PEG_METHOD_ENTER(TRC_LISTENER, "DynamicListenerConfig::getHomedPath()"); 254 | ||
255 h.sterling 1.1 String homedPath = String::EMPTY; 256 257 if (String::equal(value, String::EMPTY)) 258 { 259 homedPath = _listenerHome; 260 261 } else 262 { | ||
263 h.sterling 1.2 homedPath = FileSystem::getAbsolutePath((const char*)_listenerHome.getCString(), value); 264 } | ||
265 h.sterling 1.1 FileSystem::translateSlashes(homedPath); 266 267 PEG_METHOD_EXIT(); 268 return homedPath; 269 } 270 271 272 273 274 275 PEGASUS_NAMESPACE_END |
No CVS admin address has been configured |
Powered by ViewCVS 0.9.2 |