⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 interopproviderutils.cpp

📁 Pegasus is an open-source implementationof the DMTF CIM and WBEM standards. It is designed to be por
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//%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.////////////////////////////////////////////////////////////////////////////////* TODO LIST:    1. UUID generation should become a system function since it will be used       by many providers, etc. as part of id generation.    2. Review the key parameters on create, etc. to be sort out which are       required from user and which we can supply.  I think we are asking too       much of the user right now.*/#include <Pegasus/Common/Config.h>#include <Pegasus/Common/PegasusVersion.h>#include <cctype>#include <iostream>#include "InteropProvider.h"#include "InteropProviderUtils.h"#include "InteropConstants.h"#include <stdlib.h>//The following include is needed for gethostbyname#if defined(PEGASUS_OS_TYPE_WINDOWS)#include <objbase.h>#else#include <netdb.h>#include <arpa/inet.h>#endifPEGASUS_USING_STD;PEGASUS_NAMESPACE_BEGIN/*************************************************************** *                                                             * *               Provider Utility Functions                    * *                                                             * ***************************************************************/const char * boolToString(Boolean x){    return (x ? "true" : "false");}//// Utility function used to produce trace/logging statements//String propertyListToString(const CIMPropertyList& pl){    if(pl.isNull())        return "NULL";    else if(pl.size() == 0)        return "EMPTY";    String tmp;    for (Uint32 i = 0; i < pl.size() ; i++)    {        if (i > 0)            tmp.append(", ");        tmp.append(pl[i].getString());    }    return tmp;}//// function that creates an object path given a class definition, an// instance of that class, the host name, and the namespace.//CIMObjectPath buildInstancePath(    const CIMClass & cimClass,    const String & hostName,    const CIMNamespaceName & nameSpace,    const CIMInstance & instance){    CIMObjectPath objPath = instance.buildPath(cimClass);    objPath.setHost(hostName);    objPath.setNameSpace(nameSpace);    return objPath;}//// Determines if the namespace is allowable for this operation.// This provider is designed to accept either all namespaces or// limit itself to just one for operations.  In all cases, it// will provide the required answers and use the correct namespace// for any persistent information.  However, it may be configured// to either accept input operations from any namespace or simply// from one (normally the interop namespace).// @ objectReference for the operation.  This must include the// namespace and class name for the operation.// @return Returns normally if the namespace test is passed. Otherwise// it generates a CIMException (CIM_ERR_NOT_SUPPORTED)// @exception CIMException(CIM_ERR_NOT_SUPPORTED)//// NOTE:This function is commented out because the routing tables will always// do the right thing and that's the only way requests get here. If this// changes, then this function should be reinstated along with the various// locations where calls to the function are also commented out.///*bool namespaceSupported(const CIMObjectPath & path){    // To allow use of all namespaces, uncomment the following line    // return;    if(path.getNameSpace().getString() == PEGASUS_NAMESPACENAME_INTEROP)      return true;    throw CIMNotSupportedException(path.getClassName().getString() +      " in namespace " + path.getNameSpace().getString());        return false;}*///// Normalize the instance by setting the complete path for the instance and// executing the instance filter to set the qualifiers, classorigin, and// property list in accordance with the input.  Note that this can only remove// characteristics, except for the path completion, so that it expects// instances with qualifiers, class origin, and a complete set of properties// already present in the instance.//void normalizeInstance(CIMInstance& instance, const CIMObjectPath& path,                       Boolean includeQualifiers, Boolean includeClassOrigin,                       const CIMPropertyList& propertyList){    CIMObjectPath p = instance.getPath();    p.setHost(path.getHost());    p.setNameSpace(path.getNameSpace());    instance.setPath(p);    instance.filter(includeQualifiers,                    includeClassOrigin,                    propertyList );}//// Get one string property from an instance. Note that these functions simply// return the default value if the property cannot be found or is of the wrong// type.// @param instance CIMInstance from which we get property value// @param propertyName String name of the property containing the value// @param default String optional parameter that is substituted if the property// does not exist or is NULL.// @return String value found or defaultValue.//String getPropertyValue(const CIMInstance & instance,    const CIMName & propertyName, const String & defaultValue){    String output = defaultValue;    Uint32 pos = instance.findProperty(propertyName);    if(pos != PEG_NOT_FOUND)    {        CIMConstProperty p1 = instance.getProperty(pos);        if(p1.getType() == CIMTYPE_STRING)        {            CIMValue v1  = p1.getValue();            if(!v1.isNull())                v1.get(output);        }        else        {            throw CIMInvalidParameterException(                "Incorrect Property Type for Property " +                propertyName.getString());        }    }    return output;}//// Overload of getPropertyValue for boolean type//Boolean getPropertyValue(const CIMInstance & instance,    const CIMName & propertyName, const Boolean defaultValue){    Boolean output = defaultValue;    Uint32 pos = instance.findProperty(propertyName);    if(pos != PEG_NOT_FOUND)    {        CIMConstProperty p1 = instance.getProperty(pos);        if (p1.getType() == CIMTYPE_BOOLEAN)        {            CIMValue v1  = p1.getValue();            if (!v1.isNull())                v1.get(output);        }        else        {            throw CIMInvalidParameterException(                "Incorrect Property Type for Property " +                propertyName.getString());        }    }    return output;}//// Get Host IP address from host name. If the host name is not provided,// uses internal function. If everything fails, gets the definition normally// used for localhost (127.0.0.1).//// @param hostName String with the name of the host. Allows String:EMPTY and//     in that case, gets it directly from system.// @param namespaceType - Uint32 representing the access protocol for this//     request.  This is exactly the definition in the//     PG_CIMXMLCommunicationMechanism mof for the property//     namespaceAccessProtocol.// @param port String defining the port to be used.  If String::EMPTY, it is//     not valid and the defaultPortNumber is inserted instead.// @param defaultPortNumber Uint32 defining a default port number to be used//     if port string is not provided.//// @return String with the IP address to be used. This must be the complete//     address sufficient to access the IP address. Therefore, it includes the//     port number.//String getHostAddress(const String & hostName, Uint32 namespaceType,    const String & port, Uint32 defaultPortNumber){  String ipAddress;  if(hostName == String::EMPTY)      ipAddress = System::getHostIP(System::getHostName());  else      ipAddress = System::getHostIP(hostName);  if(ipAddress == String::EMPTY)  {      // set default address if everything else failed      ipAddress = String("127.0.0.1");  }  // Question: Is there a case where we leave off the port number?  // Code to get the property service_location_tcp ( which is equivalent to  // "IP address:5988")  // If port is valid port number, we use it.  Else use the default port  // number provided. One or the other MUST not be zero.  ipAddress.append(":");  if(port == String::EMPTY)  {      // convert portNumber to ascii      char buffer[32];      sprintf(buffer, "%u", defaultPortNumber);      ipAddress.append(buffer);  }  else  {      ipAddress.append(port);  }  return ipAddress;}//// Validate that the property exists, is string type and optionally the value// itself. NOTE: This function processes only String properties.//// @param Instance to search for property.// @param CIMName containing property Name// @param String containing value. If not String::EMPTY, compare to value//     in the property// @return True if passes all tests//Boolean validateRequiredProperty(    const CIMInstance & instance,    const CIMName & propertyName,    const String & value){    PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,            "InteropProvider::_validateRequiredProperty()");    Uint32 pos = instance.findProperty(propertyName);    if(pos == PEG_NOT_FOUND)    {        PEG_METHOD_EXIT();        return false;    }    //    //  Get the property    //    CIMConstProperty theProperty = instance.getProperty(pos);    const CIMValue theValue = theProperty.getValue();    //    // Required property must have a non-null value    //    if(theValue.getType() != CIMTYPE_STRING || theValue.isNull())    {        PEG_METHOD_EXIT();        return false;    }    String valueField;    theValue.get(valueField);    if(value == String::EMPTY || valueField == value)    {        PEG_METHOD_EXIT();        return true;    }    PEG_METHOD_EXIT();    return false;}//// Same as above method, overloaded for Uint16 values///*Boolean validateRequiredProperty(    const CIMInstance & instance,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -