00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00036 #include "OW_config.h"
00037 #include "OW_Types.hpp"
00038 #include "OW_Format.hpp"
00039 #include "OW_Logger.hpp"
00040 #include "OW_CppPolledProviderIFC.hpp"
00041 #include "OW_ConfigOpts.hpp"
00042 #include "OW_CIMOMLocatorSLP.hpp"
00043 #include "OW_SocketAddress.hpp"
00044 #include "OW_CIMObjectPath.hpp"
00045 #include "OW_CIMProperty.hpp"
00046 #include "OW_CIMOMHandleIFC.hpp"
00047 #include "OW_CIMException.hpp"
00048 #include "OW_CIMValue.hpp"
00049
00050
00051 #ifdef OW_GNU_LINUX
00052 #define OW_STRPLATFORM "Linux"
00053 #endif
00054 #ifdef OW_SOLARIS
00055 #define OW_STRPLATFORM "Solaris"
00056 #endif
00057 #ifndef OW_STRPLATFORM
00058 #error "OW_STRPLATFORM is undefined"
00059 #endif
00060 extern "C"
00061 {
00062 #include <slp.h>
00063 }
00064
00065 namespace OW_NAMESPACE
00066 {
00067
00068 static const Int32 POLLING_INTERVAL = 60 * 5;
00069 static const Int32 INITIAL_POLLING_INTERVAL = 5;
00070 extern "C"
00071 {
00072 static
00073 void
00074 slpRegReport(SLPHandle hdl, SLPError errArg, void* cookie)
00075 {
00076 if (errArg < SLP_OK)
00077 {
00078 LoggerRef* pLogger = (LoggerRef*)cookie;
00079 OW_LOG_ERROR((*pLogger), Format("cimom received error durring SLP registration: %1",
00080 (int)errArg));
00081 }
00082 }
00083 }
00084
00085 namespace
00086 {
00087
00088 struct slpHandleCloser
00089 {
00090 slpHandleCloser(SLPHandle& hdl) : m_hdl(hdl) {}
00091 ~slpHandleCloser() { SLPClose(m_hdl); }
00092
00093 SLPHandle& m_hdl;
00094 };
00095
00096 const String COMPONENT_NAME("ow.provider.SLPProvider");
00097
00098 }
00099
00100 class SLPProvider : public CppPolledProviderIFC
00101 {
00102 public:
00107 virtual Int32 getInitialPollingInterval(const ProviderEnvironmentIFCRef &env)
00108 {
00109
00110 if (env->getConfigItem(ConfigOpts::SLP_ENABLE_ADVERTISEMENT_opt, OW_DEFAULT_SLP_ENABLE_ADVERTISEMENT).equalsIgnoreCase("false"))
00111 {
00112 return 0;
00113 }
00114 Int32 rval = INITIAL_POLLING_INTERVAL;
00115 OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), Format(
00116 "SLPProvider::getInitialPollingInterval returning %1",
00117 INITIAL_POLLING_INTERVAL).c_str());
00118 m_httpsPort = env->getConfigItem(ConfigOpts::HTTP_SERVER_HTTPS_PORT_opt, OW_DEFAULT_HTTP_SERVER_HTTPS_PORT);
00119 m_httpPort = env->getConfigItem(ConfigOpts::HTTP_SERVER_HTTP_PORT_opt, OW_DEFAULT_HTTP_SERVER_HTTP_PORT);
00120 Int32 httpsPort = 0, httpPort = 0;
00121 try
00122 {
00123 httpsPort = m_httpsPort.toInt32();
00124 }
00125 catch (const StringConversionException&)
00126 {
00127 }
00128 try
00129 {
00130 httpPort = m_httpPort.toInt32();
00131 }
00132 catch (const StringConversionException&)
00133 {
00134 }
00135 if (httpsPort < 1 && httpPort < 1)
00136 {
00137 return 0;
00138 }
00139 m_useDigest = env->getConfigItem(ConfigOpts::HTTP_SERVER_USE_DIGEST_opt)
00140 .equalsIgnoreCase("true");
00141 m_allowAnonymous = env->getConfigItem(ConfigOpts::ALLOW_ANONYMOUS_opt, OW_DEFAULT_ALLOW_ANONYMOUS)
00142 .equalsIgnoreCase("true");
00143
00144
00145 m_interopSchemaNamespace = env->getConfigItem(ConfigOpts::INTEROP_SCHEMA_NAMESPACE_opt, OW_DEFAULT_INTEROP_SCHEMA_NAMESPACE);
00146
00147 m_serviceId = "unknown";
00148 try
00149 {
00150 CIMObjectPathArray a = env->getCIMOMHandle()->enumInstanceNamesA(m_interopSchemaNamespace, "CIM_ObjectManager");
00151 if (a.size() == 1)
00152 {
00153 const CIMObjectPath& om = a[0];
00154 m_serviceId = om.getKeyT("Name").getValueT().toString();
00155 }
00156 }
00157 catch (CIMException& e)
00158 {
00159 OW_LOG_ERROR(env->getLogger(COMPONENT_NAME), Format("SLP provider caught (%1) when executing enumInstanceNames(%2, \"CIM_ObjectManager\")", e, m_interopSchemaNamespace));
00160 OW_LOG_ERROR(env->getLogger(COMPONENT_NAME), "SLP provider unable to determine service-id");
00161 }
00162
00163 m_queryEnabled = !env->getConfigItem(ConfigOpts::WQL_LIB_opt, OW_DEFAULT_WQL_LIB).empty();
00164 m_indicationEnabled = !env->getConfigItem(ConfigOpts::DISABLE_INDICATIONS_opt, OW_DEFAULT_DISABLE_INDICATIONS).equalsIgnoreCase("true");
00165
00166
00167
00168 return rval;
00169 }
00179 virtual Int32 poll(const ProviderEnvironmentIFCRef &env)
00180 {
00181 doSlpRegister(env);
00182 return POLLING_INTERVAL;
00183 }
00184 private:
00185 String m_httpsPort;
00186 String m_httpPort;
00187 bool m_useDigest;
00188 bool m_allowAnonymous;
00189 String m_serviceId;
00190 String m_interopSchemaNamespace;
00191 bool m_queryEnabled;
00192 bool m_indicationEnabled;
00193
00194 void doSlpRegister(const ProviderEnvironmentIFCRef& env)
00195 {
00196 SLPError err;
00197 SLPHandle slpHandle;
00198 if ((err = SLPOpen("en", SLP_FALSE, &slpHandle)) != SLP_OK)
00199 {
00200 OW_LOG_ERROR(env->getLogger(COMPONENT_NAME), Format("SLPProvider::doSlpRegister - SLPOpenFailed: %1",
00201 err).c_str());
00202 return;
00203 }
00204 slpHandleCloser closer(slpHandle);
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 StringBuffer attributes;
00224
00225
00226
00227
00228
00229
00230 attributes += "(service-id=";
00231 attributes += m_serviceId;
00232 attributes += ')';
00233
00234
00235 attributes += ",(CommunicationMechanism=cim-xml)";
00236
00237
00238
00239
00240 attributes += ",(InteropSchemaNamespace=";
00241 attributes += m_interopSchemaNamespace;
00242 attributes += ')';
00243
00244
00245 attributes += ",(ProtocolVersion=1.1)";
00246
00247
00248 attributes += ",(FunctionalProfilesSupported=";
00249 attributes +=
00250 "Basic Read"
00251 #ifndef OW_DISABLE_SCHEMA_MANIPULATION
00252 ",Schema Manipulation"
00253 #endif
00254 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00255 ",Basic Write"
00256 ",Instance Manipulation"
00257 #endif
00258 #ifndef OW_DISABLE_ASSOCIATION_TRAVERSAL
00259 ",Association Traversal"
00260 #endif
00261 #ifndef OW_DISABLE_QUALIFIER_DECLARATION
00262 ",Qualifier Declaration"
00263 #endif
00264 ;
00265 if (m_queryEnabled)
00266 {
00267 attributes += ",Query Execution";
00268 }
00269 if (m_indicationEnabled)
00270 {
00271 attributes += ",Indications";
00272 }
00273 attributes += ")";
00274
00275
00276
00277
00278 attributes += ",(MultipleOperationsSupported=true)";
00279
00280
00281 attributes += ",(AuthenticationMechanismsSupported=";
00282 if (m_allowAnonymous)
00283 {
00284 attributes += "None)";
00285 }
00286 else if (m_useDigest)
00287 {
00288 attributes += "Digest)";
00289 }
00290 else
00291 {
00292 attributes += "Basic)";
00293 }
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 String hostname = SocketAddress::getAnyLocalHost().getName();
00306 StringArray urls;
00307 try
00308 {
00309 if (m_httpPort.toInt32() > 0)
00310 {
00311 String newUrl = "http://";
00312 newUrl += hostname + ":" + m_httpPort;
00313 urls.push_back(newUrl);
00314 }
00315 }
00316 catch (const StringConversionException&)
00317 {
00318 }
00319 try
00320 {
00321 if (m_httpsPort.toInt32() > 0)
00322 {
00323 String newUrl = "https://";
00324 newUrl += hostname + ":" + m_httpsPort;
00325 urls.push_back(newUrl);
00326 }
00327 }
00328 catch (const StringConversionException&)
00329 {
00330 }
00331 for (size_t i = 0; i < urls.size(); i++)
00332 {
00333 String urlString;
00334 urlString = OW_CIMOM_SLP_URL_PREFIX;
00335 urlString += urls[i];
00336
00337 LoggerRef lgr = env->getLogger(COMPONENT_NAME);
00338 err = SLPReg(slpHandle,
00339 urlString.c_str(),
00340 POLLING_INTERVAL+60,
00341 0,
00342 attributes.c_str(),
00343 SLP_TRUE,
00344 slpRegReport,
00345 &lgr);
00346 if (err != SLP_OK)
00347 {
00348 OW_LOG_ERROR(env->getLogger(COMPONENT_NAME), Format("cimom failed to register url with SLP: %1",
00349 urlString).c_str());
00350 }
00351 else
00352 {
00353 OW_LOG_DEBUG(env->getLogger(COMPONENT_NAME), Format("cimom registered service url with SLP: %1",
00354 urlString).c_str());
00355 }
00356 }
00357 }
00358 };
00359
00360 }
00361
00362 OW_PROVIDERFACTORY(OpenWBEM::SLPProvider, owslpprovider)
00363