📄 server.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.////==============================================================================///////////////////////////////////////////////////////////////////////////////// Interop Provider - This provider services those classes from the// DMTF Interop schema in an implementation compliant with the SMI-S v1.1// Server Profile//// Please see PG_ServerProfile20.mof in the directory// $(PEGASUS_ROOT)/Schemas/Pegasus/InterOp/VER20 for retails regarding the// classes supported by this control provider.//// Interop forces all creates to the PEGASUS_NAMESPACENAME_INTEROP // namespace. There is a test on each operation that returns // the Invalid Class CIMDError// This is a control provider and as such uses the Tracer functions// for data and function traces. Since we do not expect high volume// use we added a number of traces to help diagnostics.///////////////////////////////////////////////////////////////////////////////#include <Pegasus/Common/Config.h>#include <Pegasus/Common/PegasusVersion.h>#include <cctype>#include <iostream>#include "InteropProvider.h"#include "InteropProviderUtils.h"#include "InteropConstants.h"#include "Guid.h"#include <Pegasus/Common/StatisticalData.h>PEGASUS_USING_STD;PEGASUS_NAMESPACE_BEGINconst String CIMXMLProtocolVersion = "1.0";// Property names for ObjectManager Class//#define OM_PROPERTY_NAME COMMON_PROPERTY_NAME#define OM_PROPERTY_ELEMENTNAME COMMON_PROPERTY_ELEMENTNAME#define OM_PROPERTY_CREATIONCLASSNAME COMMON_PROPERTY_CREATIONCLASSNAME//const CIMName OM_PROPERTY_GATHERSTATISTICALDATA("GatherStatisticalData");const CIMName OM_PROPERTY_DESCRIPTION("Description");const CIMName OM_PROPERTY_COMMUNICATIONMECHANISM("CommunicationMechanism");const CIMName OM_PROPERTY_FUNCTIONALPROFILESSUPPORTED( "FunctionalProfilesSupported");const CIMName OM_PROPERTY_FUNCTIONALPROFILEDESCRIPTIONS( "FunctionalProfileDescriptions");const CIMName OM_PROPERTY_AUTHENTICATIONMECHANISMSSUPPORTED( "AuthenticationMechanismsSupported");const CIMName OM_PROPERTY_AUTHENTICATIONMECHANISMDESCRIPTIONS( "AuthenticationMechanismDescriptions");const CIMName OM_PROPERTY_MULTIPLEOPERATIONSSUPPORTED( "MultipleOperationsSupported");const CIMName OM_PROPERTY_VERSION("Version");const CIMName OM_PROPERTY_OPERATIONALSTATUS("OperationalStatus");const CIMName OM_PROPERTY_STARTED("Started");// Property Names for CIMXML CommunicationMechanismconst CIMName CIMXMLCOMMMECH_PROPERTY_CIMVALIDATED("CIMValidated");const CIMName CIMXMLCOMMMECH_PROPERTY_COMMUNICATIONMECHANISM( "CommunicationMechanism");const CIMName CIMXMLCOMMMECH_PROPERTY_FUNCTIONALPROFILESSUPPORTED( "FunctionalProfilesSupported");const CIMName CIMXMLCOMMMECH_PROPERTY_FUNCTIONALPROFILEDESCRIPTIONS( "FunctionalProfileDescriptions");const CIMName CIMXMLCOMMMECH_PROPERTY_AUTHENTICATIONMECHANISMSSUPPORTED( "AuthenticationMechanismsSupported");const CIMName CIMXMLCOMMMECH_PROPERTY_AUTHENTICATIONMECHANISMDESCRIPTIONS( "AuthenticationMechanismDescriptions");const CIMName CIMXMLCOMMMECH_PROPERTY_MULTIPLEOPERATIONSSUPPORTED( "MultipleOperationsSupported");const CIMName CIMXMLCOMMMECH_PROPERTY_VERSION("Version");const CIMName CIMXMLCOMMMECH_PROPERTY_NAMESPACETYPE("namespaceType");const CIMName CIMXMLCOMMMECH_PROPERTY_NAMESPACEACCESSPROTOCOL( "namespaceAccessProtocol");const CIMName CIMXMLCOMMMECH_PROPERTY_IPADDRESS("IPAddress");#define CIMXMLCOMMMECH_PROPERTY_ELEMENTNAME OM_PROPERTY_ELEMENTNAME#define CIMXMLCOMMMECH_PROPERTY_OPERATIONALSTATUS OM_PROPERTY_OPERATIONALSTATUS#define CIMXMLCOMMMECH_PROPERTY_NAME COMMON_PROPERTY_NAME#define CIMXMLCOMMMECH_PROPERTY_CREATIONCLASSNAME OM_PROPERTY_CREATIONCLASSNAMEconst CIMName CIMXMLCOMMMECH_PROPERTY_ADVERTISETYPES("AdvertiseTypes");//// Fills in the CIMOperation functional profiles and corresponding description// array. This function is closely linked to compile and configuration// features in the CIM Server to determine if certain features are // enabled and/or compiled. Definitions correspond to the DMTF SLP template// version 1.0.// @param Array<Uint16> profiles provides an array for the profiles// @param Array<String> with the corresponding profile text descriptions//void getFunctionalProfiles( Array<Uint16> & profiles, Array<String> & profileDescriptions){ // Note that zero and 1 are unknown and other. Not used by us // 2 - 5 are not optional in Pegasus profiles.append(2); profileDescriptions.append("Basic Read"); profiles.append(3); profileDescriptions.append("Basic Write"); profiles.append(4); profileDescriptions.append("Schema Manipulation"); profiles.append(5); profileDescriptions.append("Instance Manipulation"); ConfigManager* configManager = ConfigManager::getInstance(); if (String::equal(configManager->getCurrentValue( "enableAssociationTraversal"), "true")) { profiles.append(6); profileDescriptions.append("Association Traversal"); }#ifndef PEGASUS_DISABLE_EXECQUERY profiles.append(7); profileDescriptions.append("Query Execution");#endif profiles.append(8); profileDescriptions.append("Qualifier Declaration"); if (String::equal(configManager->getCurrentValue( "enableIndicationService"), "true")) { profiles.append(9); profileDescriptions.append("Indications"); }}//// Build a single instance of the CIMXMLCommunicationMechanism class using the// parameters provided. Builds the complete instance and sets its object path.//CIMInstance InteropProvider::buildCIMXMLCommunicationMechanismInstance( const String& namespaceType, const Uint16& accessProtocol, const String& IPAddress, const CIMClass & targetClass){ PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::buildCIMXMLCommunicationMechanismInstance()"); CIMInstance instance = targetClass.buildInstance(false, false, CIMPropertyList()); setCommonKeys(instance); // CreationClassName property setPropertyValue(instance, CIMXMLCOMMMECH_PROPERTY_CREATIONCLASSNAME, PEGASUS_CLASSNAME_PG_CIMXMLCOMMUNICATIONMECHANISM.getString()); // Name Property setPropertyValue(instance, CIMXMLCOMMMECH_PROPERTY_NAME, (String("PEGASUSCOMM") + namespaceType)); // CommunicationMechanism Property - Force to 2. setPropertyValue(instance, CIMXMLCOMMMECH_PROPERTY_COMMUNICATIONMECHANISM, Uint16(2)); //Functional Profiles Supported Property. Array<Uint16> profiles; Array<String> profileDescriptions; getFunctionalProfiles(profiles, profileDescriptions); // Set functional profiles for the instance setPropertyValue(instance, CIMXMLCOMMMECH_PROPERTY_FUNCTIONALPROFILESSUPPORTED, profiles); setPropertyValue(instance, CIMXMLCOMMMECH_PROPERTY_FUNCTIONALPROFILEDESCRIPTIONS, profileDescriptions); // MultipleOperationsSupported Property setPropertyValue(instance, CIMXMLCOMMMECH_PROPERTY_MULTIPLEOPERATIONSSUPPORTED, false); // AuthenticationMechanismsSupported Property Array<Uint16> authentications; Array<String> authenticationDescriptions; //TODO - get from system. authentications.append(3); authenticationDescriptions.append("Basic"); setPropertyValue(instance, CIMXMLCOMMMECH_PROPERTY_AUTHENTICATIONMECHANISMSSUPPORTED, authentications); setPropertyValue(instance, CIMXMLCOMMMECH_PROPERTY_AUTHENTICATIONMECHANISMDESCRIPTIONS, authenticationDescriptions); // Version Property setPropertyValue(instance, CIMXMLCOMMMECH_PROPERTY_VERSION, CIMXMLProtocolVersion); // NamespaceType Property setPropertyValue(instance, CIMXMLCOMMMECH_PROPERTY_NAMESPACETYPE, namespaceType); // NamespaceAccessProtocol property setPropertyValue(instance, CIMXMLCOMMMECH_PROPERTY_NAMESPACEACCESSPROTOCOL, accessProtocol); // IPAddress property setPropertyValue(instance, CIMXMLCOMMMECH_PROPERTY_IPADDRESS, IPAddress); // ElementName property setPropertyValue(instance, CIMXMLCOMMMECH_PROPERTY_ELEMENTNAME, String("Pegasus CIMXML Communication Mechanism")); // CIMValidated property setPropertyValue(instance, CIMXMLCOMMMECH_PROPERTY_CIMVALIDATED, Boolean(false)); // OperationalStatus property Array<Uint16> opStatus; opStatus.append(2); // "OK" setPropertyValue(instance, CIMXMLCOMMMECH_PROPERTY_OPERATIONALSTATUS, opStatus); // AdvertiseTypes property Array<Uint16> advertiseTypes; ConfigManager* configManager = ConfigManager::getInstance(); if (String::equal(configManager->getCurrentValue("slp"), "true")) { advertiseTypes.append(3); // Advertised via SLP } else { advertiseTypes.append(2); // Not advertised } setPropertyValue(instance, CIMXMLCOMMMECH_PROPERTY_ADVERTISETYPES, advertiseTypes); // build the instance path and set into instance CIMObjectPath objPath = instance.buildPath(targetClass); objPath.setNameSpace(PEGASUS_NAMESPACENAME_INTEROP); objPath.setHost(hostName); instance.setPath(objPath); PEG_METHOD_EXIT(); return instance;}//// Retrieves all of the instances of CIMXMLCommunicationMechanism for the// CIMOM.//Array<CIMInstance> InteropProvider::enumCIMXMLCommunicationMechanismInstances(){ PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::enumCIMXMLCommunicationMechanismInstances"); ConfigManager* configManager = ConfigManager::getInstance(); Boolean enableHttpConnection = String::equal( configManager->getCurrentValue("enableHttpConnection"), "true"); Boolean enableHttpsConnection = String::equal( configManager->getCurrentValue("enableHttpsConnection"), "true"); Array<CIMInstance> instances; Uint32 namespaceAccessProtocol; String namespaceType; CIMClass commMechClass = repository->getClass( PEGASUS_NAMESPACENAME_INTEROP, PEGASUS_CLASSNAME_PG_CIMXMLCOMMUNICATIONMECHANISM, false, true, false); if (enableHttpConnection) { // Build the CommunicationMechanism instance for the HTTP protocol namespaceAccessProtocol = 2; namespaceType = "http"; Uint32 portNumberHttp; String httpPort = configManager->getCurrentValue("httpPort"); if (httpPort == String::EMPTY) { portNumberHttp = System::lookupPort(WBEM_HTTP_SERVICE_NAME, WBEM_DEFAULT_HTTP_PORT); } CIMInstance instance = buildCIMXMLCommunicationMechanismInstance( namespaceType, namespaceAccessProtocol, getHostAddress(hostName, namespaceAccessProtocol, httpPort, portNumberHttp), commMechClass); instances.append(instance); } if (enableHttpsConnection) { // Build the CommunicationMechanism instance for the HTTPS protocol namespaceAccessProtocol = 3; namespaceType = "https"; Uint32 portNumberHttps; String httpsPort = configManager->getCurrentValue("httpsPort"); if (httpsPort == String::EMPTY) { portNumberHttps = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, WBEM_DEFAULT_HTTPS_PORT); } CIMInstance instance = buildCIMXMLCommunicationMechanismInstance( namespaceType, namespaceAccessProtocol, getHostAddress(hostName, namespaceAccessProtocol, httpsPort, portNumberHttps), commMechClass); instances.append(instance); } PEG_METHOD_EXIT(); return instances;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -