📄 cimserver.cpp
字号:
//%2006//////////////////////////////////////////////////////////////////////////// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.// Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation, The Open Group.// Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; VERITAS Software Corporation; The Open Group.// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;// EMC Corporation; Symantec Corporation; The Open Group.//// Permission is hereby granted, free of charge, to any person obtaining a copy// of this software and associated documentation files (the "Software"), to// deal in the Software without restriction, including without limitation the// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or// sell copies of the Software, and to permit persons to whom the Software is// furnished to do so, subject to the following conditions:// // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.////==============================================================================////%/////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include <cstdio>#include <cctype>#include <ctime>#if (defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX)) \ && defined(PEGASUS_USE_RELEASE_DIRS)# include <unistd.h>#endif#include <Pegasus/Common/Constants.h>#include <Pegasus/Common/FileSystem.h>#include <Pegasus/Common/Signal.h>#include <Pegasus/Common/HTTPAcceptor.h>#include <Pegasus/Common/Tracer.h>#include <Pegasus/Common/Logger.h>#include <Pegasus/Common/Cimom.h>#include <Pegasus/Common/PegasusVersion.h>#include <Pegasus/Common/SSLContextManager.h>#include <Pegasus/Common/Time.h>#include <Pegasus/Common/MessageLoader.h>#include <Pegasus/Repository/CIMRepository.h>#include <Pegasus/ExportServer/CIMExportRequestDispatcher.h>#include <Pegasus/ExportServer/CIMExportResponseEncoder.h>#include <Pegasus/ExportServer/CIMExportRequestDecoder.h>#include <Pegasus/Config/ConfigManager.h>#include <Pegasus/Security/UserManager/UserManager.h>#include <Pegasus/HandlerService/IndicationHandlerService.h>#include <Pegasus/IndicationService/IndicationService.h>#include <Pegasus/ProviderManagerService/ProviderManagerService.h>#include <Pegasus/ProviderManager2/Default/DefaultProviderManager.h>#ifndef PEGASUS_DISABLE_AUDIT_LOGGER# include <Pegasus/Common/AuditLogger.h>#endif#ifdef PEGASUS_ENABLE_SLP# include <Pegasus/Client/CIMClient.h>#endif// PEGASUS_SLP_REG_TIMEOUT is the time interval in minute for reregistration with SLP.#ifdef PEGASUS_SLP_REG_TIMEOUT#include "SLPAttrib.h"#include <slp/slp_client/src/cmd-utils/slp_client/lslp-common-defs.h>#include <slp/slp_client/src/cmd-utils/slp_client/slp_client.h>#endif#include "CIMServer.h"#include "CIMOperationRequestDispatcher.h"#include "CIMOperationResponseEncoder.h"#include "CIMOperationRequestDecoder.h"#include "CIMOperationRequestAuthorizer.h"#include "HTTPAuthenticatorDelegator.h"#include "ShutdownProvider.h"#include "ShutdownService.h"#include "BinaryMessageHandler.h"#include <Pegasus/Common/ModuleController.h>#include \ <Pegasus/ControlProviders/ConfigSettingProvider/ConfigSettingProvider.h>#include <Pegasus/ControlProviders/UserAuthProvider/UserAuthProvider.h>#include <Pegasus/ControlProviders/ProviderRegistrationProvider/ProviderRegistrationProvider.h>#include <Pegasus/ControlProviders/NamespaceProvider/NamespaceProvider.h>#ifndef PEGASUS_DISABLE_PERFINST# include <Pegasus/ControlProviders/Statistic/CIMOMStatDataProvider.h>#endif#ifdef PEGASUS_HAS_SSL# include <Pegasus/ControlProviders/CertificateProvider/CertificateProvider.h>#endif#ifndef PEGASUS_DISABLE_CQL# include <Pegasus/ControlProviders/QueryCapabilitiesProvider/CIMQueryCapabilitiesProvider.h>#endif#if !defined(PEGASUS_DISABLE_PERFINST) || defined(PEGASUS_ENABLE_SLP)# include <Pegasus/ControlProviders/InteropProvider/InteropProvider.h>#endifPEGASUS_NAMESPACE_BEGIN#ifdef PEGASUS_SLP_REG_TIMEOUTThreadReturnType PEGASUS_THREAD_CDECL registerPegasusWithSLP(void *parm);// Configurable SLP port to be handeled in a separate bug.# define SLP_DEFAULT_PORT 427# define LOCALHOST_IP "127.0.0.1"#endifstatic CIMServer* _cimserver = NULL;static Boolean _slpRegistrationComplete;// Need a static method to act as a callback for the control provider.// This doesn't belong here, but I don't have a better place to put it.static Message* controlProviderReceiveMessageCallback( Message* message, void* instance){ CIMRequestMessage* request = dynamic_cast<CIMRequestMessage*>(message); PEGASUS_ASSERT(request != 0); AcceptLanguageList* langs = new AcceptLanguageList( ((AcceptLanguageListContainer) request->operationContext.get( AcceptLanguageListContainer::NAME)).getLanguages()); Thread::setLanguages(langs); ProviderMessageHandler* pmh = reinterpret_cast<ProviderMessageHandler*>(instance); return pmh->processMessage(request);}//// z/OS console interface waiting for operator stop command//#if defined PEGASUS_PLATFORM_ZOS_ZSERIES_IBM# include <sys/__messag.h>void* waitForStopCommand(void*){ PEG_METHOD_ENTER(TRC_SERVER, "waitForStopCommand"); struct __cons_msg cons; int concmd=0; char modstr[128]; int rc; memset(&cons,0,sizeof(cons)); memset(modstr,0,sizeof(modstr)); do { rc = __console(&cons, modstr, &concmd); if (rc != 0) { PEG_TRACE_STRING(TRC_SERVER, Tracer::LEVEL2, "Failed to issue __console command"); break; } // Check if we received a stop command from the console if (concmd != _CC_stop) { // Just issue a console message that the command was // not recognized and wait again for the stop command. Logger::put_l( Logger::STANDARD_LOG, "CIM Server", Logger::INFORMATION, "Server.CIMServer.CONSOLE_NO_MODIFY.PEGASUS_OS_ZOS", "MODIFY command not recognized by CIM server."); } else { Logger::put_l( Logger::STANDARD_LOG, "CIM Server", Logger::INFORMATION, "Server.CIMServer.CONSOLE_STOP.PEGASUS_OS_ZOS", "STOP command received from z/OS console," " initiating shutdown."); } // keep on until we encounter an error or received a STOP } while ( (concmd != _CC_stop) && (rc == 0) ); CIMServer::shutdownSignal(); PEG_METHOD_EXIT(); pthread_exit(0); return NULL;}#endif//// Signal handler for shutdown signals, currently SIGHUP and SIGTERM//Boolean handleShutdownSignal = false;void shutdownSignalHandler(int s_n, PEGASUS_SIGINFO_T* s_info, void* sig){ PEG_METHOD_ENTER(TRC_SERVER, "shutdownSignalHandler"); Tracer::trace(TRC_SERVER, Tracer::LEVEL2, "Signal %d received.", s_n); CIMServer::shutdownSignal(); PEG_METHOD_EXIT();}void CIMServer::shutdownSignal(){ PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::shutdownSignal()"); handleShutdownSignal = true; _cimserver->tickle_monitor(); PEG_METHOD_EXIT();}CIMServer::CIMServer(Monitor* monitor) : _dieNow(false), _monitor(monitor){ PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::CIMServer()"); _cimserver = this; _init(); PEG_METHOD_EXIT();}void CIMServer::tickle_monitor(){ _monitor->tickle();}void CIMServer::_init(){#ifdef PEGASUS_ENABLE_SLP _runSLP = true; // Boolean cannot be set in definition. _slpRegistrationComplete = false;#endif#if (defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX)) \ && defined(PEGASUS_USE_RELEASE_DIRS) chdir(PEGASUS_CORE_DIR);#endif // -- Create a repository: String repositoryRootPath = ConfigManager::getHomedPath( ConfigManager::getInstance()->getCurrentValue("repositoryDir"));#ifdef DO_NOT_CREATE_REPOSITORY_ON_STARTUP // If this code is enable, the CIMServer will fail to start // if the repository directory does not exit. If called, // the Repository will create an empty repository. // This check has been disabled to allow cimmof to call // the CIMServer to build the initial repository. if (!FileSystem::isDirectory(repositoryRootPath)) { PEG_METHOD_EXIT(); throw NoSuchDirectory(repositoryRootPath); }#endif _repository = new CIMRepository(repositoryRootPath); // -- Create a UserManager object: UserManager* userManager = UserManager::getInstance(_repository); // -- Create a CIMServerState object: _serverState.reset(new CIMServerState()); _providerRegistrationManager = new ProviderRegistrationManager(_repository); // -- Create queue inter-connections: _providerManager = new ProviderManagerService( _providerRegistrationManager, _repository, DefaultProviderManager::createDefaultProviderManagerCallback); // Create IndicationHandlerService: _handlerService = new IndicationHandlerService(_repository); // Create the control service _controlService = new ModuleController(PEGASUS_QUEUENAME_CONTROLSERVICE); // Jump this number up when there are more control providers. _controlProviders.reserveCapacity(16); // Create the Configuration control provider ProviderMessageHandler* configProvider = new ProviderMessageHandler( "ConfigSettingProvider", new ConfigSettingProvider(), 0, 0, false); _controlProviders.append(configProvider); ModuleController::register_module( PEGASUS_QUEUENAME_CONTROLSERVICE, PEGASUS_MODULENAME_CONFIGPROVIDER, configProvider, controlProviderReceiveMessageCallback, 0); // Create the User/Authorization control provider ProviderMessageHandler* userAuthProvider = new ProviderMessageHandler( "UserAuthProvider", new UserAuthProvider(_repository), 0, 0, false); _controlProviders.append(userAuthProvider); ModuleController::register_module( PEGASUS_QUEUENAME_CONTROLSERVICE, PEGASUS_MODULENAME_USERAUTHPROVIDER, userAuthProvider, controlProviderReceiveMessageCallback, 0); // Create the Provider Registration control provider ProviderMessageHandler* provRegProvider = new ProviderMessageHandler( "ProviderRegistrationProvider", new ProviderRegistrationProvider(_providerRegistrationManager), 0, 0, false); // Warning: The ProviderRegistrationProvider destructor deletes // _providerRegistrationManager _controlProviders.append(provRegProvider); ModuleController::register_module( PEGASUS_QUEUENAME_CONTROLSERVICE, PEGASUS_MODULENAME_PROVREGPROVIDER, provRegProvider, controlProviderReceiveMessageCallback, 0); // Create the Shutdown control provider ProviderMessageHandler* shutdownProvider = new ProviderMessageHandler( "ShutdownProvider", new ShutdownProvider(this), 0, 0, false); _controlProviders.append(shutdownProvider); ModuleController::register_module( PEGASUS_QUEUENAME_CONTROLSERVICE, PEGASUS_MODULENAME_SHUTDOWNPROVIDER, shutdownProvider, controlProviderReceiveMessageCallback, 0); // Create the namespace control provider ProviderMessageHandler* namespaceProvider = new ProviderMessageHandler( "NamespaceProvider", new NamespaceProvider(_repository), 0, 0, false); _controlProviders.append(namespaceProvider); ModuleController::register_module( PEGASUS_QUEUENAME_CONTROLSERVICE, PEGASUS_MODULENAME_NAMESPACEPROVIDER, namespaceProvider, controlProviderReceiveMessageCallback, 0); // // Create a SSLContextManager object //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -