Пример #1
0
//
// Class that determines whether or not the origin class in an association
// operation is valid for the given association class, and also determines
// the origin and target "roles". These values generally correspond to the
// role and resultRole parameter of an associators/associatorNames operation.
//
bool InteropProvider::validAssocClassForObject(
    const OperationContext & context,
    const CIMName & assocClass,
    const CIMObjectPath & objectName,
    const CIMNamespaceName & opNamespace,
    String & originProperty,
    String & targetProperty)
{
    PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
                     "InteropProvider::validAssocClassForObject()");
    TARGET_CLASS assocClassEnum = translateClassInput(assocClass);
    TARGET_CLASS originClassEnum = NOCLASS;
    CIMName originClass = objectName.getClassName();
    // If the association class is PG_ElementConformsToProfile, we'll have to
    // do some special processing in case the origin instance for the operation
    // is managed by another provider.
    if(assocClassEnum == PG_ELEMENTCONFORMSTOPROFILE)
    {
        // Test if the origin is an element managed by another provider
        // that has implemented a registered profile.
        if(opNamespace != PEGASUS_NAMESPACENAME_INTEROP ||
                (originClass != PEGASUS_CLASSNAME_PG_REGISTEREDPROFILE &&
#ifdef PEGASUS_ENABLE_DMTF_INDICATION_PROFILE_SUPPORT
                 originClass != PEGASUS_CLASSNAME_CIM_INDICATIONSERVICE &&
#endif
                 originClass != PEGASUS_CLASSNAME_PG_OBJECTMANAGER ))
        {
            //
            // Search the cached conformingElements list for the originClass,
            // returning false if it is not found
            //
            bool found = false;

            PEGASUS_ASSERT(conformingElements.size() ==
                           elementNamespaces.size());
            for(Uint32 i = 0, n = conformingElements.size(); i < n; ++i)
            {
                CIMNameArray & elementList = conformingElements[i];
                CIMNamespaceArray & namespaceList = elementNamespaces[i];
                PEGASUS_ASSERT(elementList.size() == namespaceList.size());
                for(Uint32 j = 0, m = elementList.size(); j < m; ++j)
                {
                    CIMName & curElement = elementList[j];
                    if((curElement == originClass ||
                            curElement.getString().find(PEGASUS_DYNAMIC) == 0) &&
                            opNamespace == namespaceList[j])
                    {
                        found = true;
                        break;
                    }
                }
                if(found)
                    break;
            }

            if(!found)
            {
                PEG_METHOD_EXIT();
                return false;
            }
        }
    }
    else
    {
        // Otherwise, just get the enum value representing the origin class
        // for this operation
        originClassEnum = translateClassInput(originClass);
    }

    CIMName expectedTargetRole;
    CIMName expectedOriginRole;

    Array<CIMName> propNames;
    String profileName;
    CIMPropertyList propertyList;
    CIMInstance tmpInstance;
    Uint32 index;
    propNames.clear();

    //
    // Set the target and origin role values. Note that if these values are
    // not set following the switch block, that implies that the origin class
    // is not valid for the supplied association class.
    //
    switch(assocClassEnum)
    {
    case PG_NAMESPACEINMANAGER:
        if(originClassEnum == PG_OBJECTMANAGER)
        {
            expectedTargetRole = PROPERTY_DEPENDENT;
            expectedOriginRole = PROPERTY_ANTECEDENT;
        }
        else if(originClassEnum == PG_NAMESPACE)
        {
            expectedTargetRole = PROPERTY_ANTECEDENT;
            expectedOriginRole = PROPERTY_DEPENDENT;
        }
        break;
    case PG_COMMMECHANISMFORMANAGER:
        if(originClassEnum == PG_OBJECTMANAGER)
        {
            expectedTargetRole = PROPERTY_DEPENDENT;
            expectedOriginRole = PROPERTY_ANTECEDENT;
        }
        else if(originClassEnum == PG_CIMXMLCOMMUNICATIONMECHANISM)
        {
            expectedTargetRole = PROPERTY_ANTECEDENT;
            expectedOriginRole = PROPERTY_DEPENDENT;
        }
        break;
    case PG_ELEMENTCONFORMSTOPROFILE:
        if(originClass.equal(PEGASUS_CLASSNAME_PG_REGISTEREDPROFILE))
        {
            expectedTargetRole =
                ELEMENTCONFORMSTOPROFILE_PROPERTY_MANAGEDELEMENT;
            expectedOriginRole =
                ELEMENTCONFORMSTOPROFILE_PROPERTY_CONFORMANTSTANDARD;
        }
        else
        {
            expectedTargetRole =
                ELEMENTCONFORMSTOPROFILE_PROPERTY_CONFORMANTSTANDARD;
            expectedOriginRole =
                ELEMENTCONFORMSTOPROFILE_PROPERTY_MANAGEDELEMENT;
        }
        break;
    case PG_ELEMENTCONFORMSTOPROFILE_RP_RP:
        propNames.append(CIMName("RegisteredName"));
        propertyList = CIMPropertyList(propNames);
        try
        {
            tmpInstance = localGetInstance(
                              context,
                              objectName,
                              propertyList);
        }
        catch (CIMException &e)
        {
            PEG_TRACE((TRC_CONTROLPROVIDER, Tracer::LEVEL2,
                       "CIMException while getting instance of Registered Profile "
                       ": %s",
                       (const char*)e.getMessage().getCString()));
        }
        if (!tmpInstance.isUninitialized())
        {
            index = tmpInstance.findProperty("RegisteredName");
            if (index != PEG_NOT_FOUND)
            {
                const CIMValue &tmpVal =
                    tmpInstance.getProperty(index).getValue();
                if (!tmpVal.isNull())
                {
                    tmpVal.get(profileName);
                }
            }
        }
        if (String::compareNoCase(profileName, String("SMI-S")) == 0)
        {
            expectedTargetRole =
                ELEMENTCONFORMSTOPROFILE_PROPERTY_MANAGEDELEMENT;
            expectedOriginRole =
                ELEMENTCONFORMSTOPROFILE_PROPERTY_CONFORMANTSTANDARD;
        }
        else
        {
            expectedTargetRole =
                ELEMENTCONFORMSTOPROFILE_PROPERTY_CONFORMANTSTANDARD;
            expectedOriginRole =
                ELEMENTCONFORMSTOPROFILE_PROPERTY_MANAGEDELEMENT;
        }
        break;
    case PG_SUBPROFILEREQUIRESPROFILE:
        if(originClassEnum == PG_REGISTEREDPROFILE)
        {
            expectedTargetRole = PROPERTY_DEPENDENT;
            expectedOriginRole = PROPERTY_ANTECEDENT;
        }
        else if(originClassEnum == PG_REGISTEREDSUBPROFILE)
        {
            expectedTargetRole = PROPERTY_ANTECEDENT;
            expectedOriginRole = PROPERTY_DEPENDENT;
        }
        break;
    case PG_REFERENCEDPROFILE:
        if (originClassEnum == PG_REGISTEREDSUBPROFILE)
        {
            expectedTargetRole = PROPERTY_ANTECEDENT;
            expectedOriginRole = PROPERTY_DEPENDENT;
        }
        else if (originClassEnum == PG_REGISTEREDPROFILE)
        {
            if ((targetProperty.size() != 0) &&
                    (originProperty.size() != 0) &&
                    String::equalNoCase(targetProperty, originProperty))
            {
                return false;
            }
            if (targetProperty.size() != 0)
            {
                if (!(String::equalNoCase(targetProperty, "Antecedent") ||
                        String::equalNoCase(targetProperty, "Dependent") ))
                {
                    return false;
                }
            }
            if (originProperty.size() != 0)
            {
                if (!(String::equalNoCase(originProperty, "Antecedent") ||
                        String::equalNoCase(originProperty, "Dependent") ))
                {
                    return false;
                }
            }
            if (String::equalNoCase(originProperty, "Antecedent") &&
                    targetProperty.size() == 0)
            {
                targetProperty = String("Dependent");
            }
            if (String::equalNoCase(originProperty, "Dependent") &&
                    targetProperty.size() == 0)
            {
                targetProperty = String("Antecedent");
            }
            if (String::equalNoCase(targetProperty, "Antecedent") &&
                    originProperty.size() == 0)
            {
                originProperty = String("Dependent");
            }
            if (String::equalNoCase(targetProperty, "Dependent") &&
                    originProperty.size() == 0)
            {
                originProperty = String("Antecedent");
            }
            return true;
        }
        break;
    case PG_ELEMENTSOFTWAREIDENTITY:
        if(originClassEnum == PG_SOFTWAREIDENTITY)
        {
            expectedTargetRole = PROPERTY_DEPENDENT;
            expectedOriginRole = PROPERTY_ANTECEDENT;
        }
        else if(originClassEnum == PG_REGISTEREDPROFILE ||
                originClassEnum == PG_REGISTEREDSUBPROFILE)
        {
            expectedTargetRole = PROPERTY_ANTECEDENT;
            expectedOriginRole = PROPERTY_DEPENDENT;
        }
        break;
    case PG_INSTALLEDSOFTWAREIDENTITY:
        if(originClassEnum == PG_SOFTWAREIDENTITY)
        {
            expectedTargetRole = INSTALLEDSOFTWAREIDENTITY_PROPERTY_SYSTEM;
            expectedOriginRole =
                INSTALLEDSOFTWAREIDENTITY_PROPERTY_INSTALLEDSOFTWARE;
        }
        else if(originClassEnum == PG_COMPUTERSYSTEM)
        {
            expectedTargetRole =
                INSTALLEDSOFTWAREIDENTITY_PROPERTY_INSTALLEDSOFTWARE;
            expectedOriginRole = INSTALLEDSOFTWAREIDENTITY_PROPERTY_SYSTEM;
        }
        break;
    case PG_HOSTEDACCESSPOINT:
        if(originClassEnum == PG_COMPUTERSYSTEM)
        {
            expectedTargetRole = PROPERTY_DEPENDENT;
            expectedOriginRole = PROPERTY_ANTECEDENT;
        }
        else if(originClassEnum == PG_CIMXMLCOMMUNICATIONMECHANISM)
        {
            expectedTargetRole = PROPERTY_ANTECEDENT;
            expectedOriginRole = PROPERTY_DEPENDENT;
        }
    case PG_HOSTEDOBJECTMANAGER:
        if(originClassEnum == PG_COMPUTERSYSTEM)
        {
            expectedTargetRole = PROPERTY_DEPENDENT;
            expectedOriginRole = PROPERTY_ANTECEDENT;
        }
        else if(originClassEnum == PG_OBJECTMANAGER)
        {
            expectedTargetRole = PROPERTY_ANTECEDENT;
            expectedOriginRole = PROPERTY_DEPENDENT;
        }
        break;
#ifdef PEGASUS_ENABLE_DMTF_INDICATION_PROFILE_SUPPORT
    case PG_HOSTEDINDICATIONSERVICE:
        if(originClassEnum == PG_COMPUTERSYSTEM)
        {
            expectedTargetRole = PROPERTY_DEPENDENT;
            expectedOriginRole = PROPERTY_ANTECEDENT;
        }
        else if (originClassEnum == CIM_INDICATIONSERVICE)
        {
            expectedTargetRole = PROPERTY_ANTECEDENT;
            expectedOriginRole = PROPERTY_DEPENDENT;
        }
        break;
#endif
    default:
        break;
    }

    //
    // The rest of this method checks to see if target role and origin roles
    // were found for the association and origin class combination and, if
    // found, checks against the input target and origin roles if provided.
    // Failure for any of these tests points to an invalid association
    // traversal request.
    //
    if(expectedTargetRole.isNull() ||
            expectedOriginRole.isNull())
    {
        PEG_METHOD_EXIT();
        return false;
    }

    if(targetProperty.size() == 0)
    {
        targetProperty = expectedTargetRole.getString();
    }
    else if(!expectedTargetRole.equal(targetProperty))
    {
        PEG_METHOD_EXIT();
        return false;
    }

    if(originProperty.size() == 0)
    {
        originProperty = expectedOriginRole.getString();
    }
    else if(!expectedOriginRole.equal(originProperty))
    {
        PEG_METHOD_EXIT();
        return false;
    }

    PEG_METHOD_EXIT();
    return true;
}
static void
_test2 (CIMClient & client)
{
  Uint32 exceptions = 0;
  CIMObjectPath instanceName;
  Array < CIMKeyBinding > keyBindings;

  keyBindings.append (CIMKeyBinding ("ElementNameName",
                                     "TestCMPI_ExecQuery",
                                     CIMKeyBinding::STRING));

  instanceName.setNameSpace (providerNamespace);
  instanceName.setClassName ("TestCMPI_ExecQuery");
  instanceName.setKeyBindings (keyBindings);

  /* Call the unsupported functions of the provider. */
  try
  {
    CIMInstance instance (client.getInstance (providerNamespace,
                                              instanceName));
  } catch (const CIMException &)
  {
     exceptions ++;
  }


  try
  {
    client.deleteInstance (providerNamespace, instanceName);

  } catch (const CIMException & )
  {
     exceptions ++;
  }
  CIMClass thisClass = client.getClass(
                           providerNamespace,
                           "TestCMPI_ExecQuery",
                           false,
                           true,
                           true,
                           CIMPropertyList());
  Array<CIMName> propertyNameList;
  propertyNameList.append(CIMName("ElementName"));
  CIMPropertyList myPropertyList(propertyNameList);
  // create the instance with the defined properties
  CIMInstance newInstance = thisClass.buildInstance(true, true, myPropertyList);
  newInstance.getProperty(0).setValue(CIMValue(String("TestCMPI_execQuery") ));
  try
  {

    CIMObjectPath objectPath (client.createInstance (providerNamespace,
                                                     newInstance));


  } catch (const CIMException &)
  {
     exceptions ++;
  }

  try
  {
    client.modifyInstance (providerNamespace, newInstance);

  } catch (const CIMException &)
  {
     exceptions ++;
  }
  try
  {

    Array < CIMInstance > instances =
      client.enumerateInstances (providerNamespace,
                                 CIMName ("TestCMPI_ExecQuery"));
  } catch (const CIMException &)
  {
     exceptions ++;
  }

  try
  {
    Array < CIMObjectPath > objectPaths =
      client.enumerateInstanceNames (providerNamespace,
                                     CIMName ("TestCMPI_ExecQuery"));
  } catch (const CIMException &)
  {
     exceptions ++;
  }

  PEGASUS_TEST_ASSERT(exceptions ==  6);

}
void _test4(CIMClient & client)
{
    static const String NAMESPACE("test/TestProvider");
    static const String CLASSNAME("cmpiPerf_TestClassA");
    Array<CIMObjectPath> cimInstanceNames =
    client.enumerateInstanceNames(
        NAMESPACE,
        CLASSNAME);
    cout<<"+++++++++empty property list filtered output++++++"<<endl;
    {
        Array<CIMName> propNames;
        for (Uint32 i = 0, n = cimInstanceNames.size(); i < n; i++)
        {
            CIMInstance cimInstance=client.getInstance(
                NAMESPACE,
                cimInstanceNames[i],
                true,
                false,
                false,
                CIMPropertyList(propNames));
            if (verbose)
            {
                XmlWriter::printInstanceElement(cimInstance);
            }
            Uint32 propertyCount = cimInstance.getPropertyCount();
            if(propertyCount == 0)
            {
                cout<<"Filter getInstance test on "
                    <<"cmpiPerf_TestClassA SUCCEEDED :Filtering "
                    <<"the ciminstance with a empty property list "
                    <<"returned zero properties as expected"<<endl;
            }
            else
            {
                cout<<"Filter getInstance test on cmpiPerf_TestClassA"
                    <<" FAILED:Filtering the ciminstance with a empty "
                    <<"property list returned some properties "
                    <<"which is not expected"<<endl;
                PEGASUS_TEST_ASSERT(false);
            } 
        }
    }
    cout<<"+++++++++wrong property list filtered output++++++"<<endl;
    {
        Array<CIMName> propNames;
        propNames.append(CIMName(String("theK")));
        for (Uint32 i = 0, n = cimInstanceNames.size(); i < n; i++)
        {
            CIMInstance cimInstance=client.getInstance(
                NAMESPACE,
                cimInstanceNames[i],
                true,
                false,
                false,
                CIMPropertyList(propNames));
            if (verbose)
            {
                XmlWriter::printInstanceElement(cimInstance);
            }
            Uint32 propertyCount = cimInstance.getPropertyCount();
            if(propertyCount == 0)
            {
                cout<<"Filter getInstance test on "
                    <<"cmpiPerf_TestClassA SUCCEEDED :Filtering "
                    <<"the ciminstance with a wrong property list "
                    <<"returned zero properties as expected"<<endl;
            }
            else
            {
                cout<<"Filter getInstance test on cmpiPerf_TestClassA"
                    <<" FAILED:Filtering the ciminstance with a wrong "
                    <<"property list returned some properties "
                    <<"which is not expected"<<endl;
                PEGASUS_TEST_ASSERT(false);
            }
        }
    }
    cout<<"+++++++++NULL property list filtered output++++++"<<endl;
    {
        for (Uint32 i = 0, n = cimInstanceNames.size(); i < n; i++)
        {
            CIMInstance cimInstance=client.getInstance(
                NAMESPACE,
                cimInstanceNames[i],
                true,
                false,
                false,
                CIMPropertyList());
            if (verbose)
            {
                XmlWriter::printInstanceElement(cimInstance);
            }
            Uint32 propertyCount = cimInstance.getPropertyCount();
            if(propertyCount == 24)
            {
                cout<<"Filter getInstance test on "
                    <<"cmpiPerf_TestClassA SUCCEEDED :Filtering "
                    <<"the ciminstance with a NULL property list "
                    <<"returned all properties as expected"<<endl;
            }
            else
            {
                cout<<"Filter getInstance test on cmpiPerf_TestClassA"
                    <<" FAILED:Filtering the ciminstance with a NULL "
                    <<"property list did not return all properties "
                    <<"as expected"<<endl;
                PEGASUS_TEST_ASSERT(false);
            }
        }
    }
    cout<<"+++++++++mentioned  property list filtered output++++++"<<endl;
    {
        Array<CIMName> propNames;
        propNames.append(CIMName(String("RequestedState")));
        propNames.append(CIMName(String("theKey")));
        for (Uint32 i = 0, n = cimInstanceNames.size(); i < n; i++)
        {
            CIMInstance cimInstance=client.getInstance(
                NAMESPACE,
                cimInstanceNames[i],
                true,
                false,
                false,
                CIMPropertyList(propNames));
            if (verbose)
            {
                XmlWriter::printInstanceElement(cimInstance);
            }
            Uint32 propertyCount = cimInstance.getPropertyCount();
            Uint32 propNameCount = 0;
            for(Uint32 j=0;j<propertyCount;j++)
            {
                String propName=
                    cimInstance.getProperty(j).getName().
                    getString();
                if((propName == "RequestedState")||(propName == "theKey"))
                {
                    propNameCount++;
                }
            } 
            if((propertyCount == 2) && (propNameCount == 2))
            {
                cout<<"Filter getInstance test on "
                    <<"cmpiPerf_TestClassA SUCCEEDED :Filtering "
                    <<"the ciminstance with a mentioned property list "
                    <<"returned all properties as expected"<<endl;
            }
            else
            {
                cout<<"Filter getInstance test on cmpiPerf_TestClassA"
                    <<" FAILED:Filtering the ciminstance with a mentioned "
                    <<"property list did not return all properties "
                    <<"as expected"<<endl;
                PEGASUS_TEST_ASSERT(false);
            }
        }
    } 
}
Пример #4
0
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//==============================================================================
//
// Author: Lyle Wilkinson, Hewlett-Packard Company <*****@*****.**>
//
// Modified By:
//
//%/////////////////////////////////////////////////////////////////////////////

#include "IPInfo.h"

PEGASUS_USING_PEGASUS;
PEGASUS_USING_STD;

static const CIMName          CLASS_NAME = CIMName          ("PG_IPRoute");
static const CIMNamespaceName NAMESPACE  = CIMNamespaceName ("root/cimv2");
#define HeaderFormat "%-16s %-10s %-16s %-16s %-16s"


////////////////////////////////////////////////////////////////////////////////
//  Constructor for IP Route Info
////////////////////////////////////////////////////////////////////////////////
IPRouteInfo::IPRouteInfo(CIMClient &client, Boolean enableDebug,
                  ostream& outPrintWriter, ostream& errPrintWriter)
{
    _enableDebug = enableDebug;

    try
    {
        Boolean deepInheritance = true;
Пример #5
0
void test01()
{
    NameSpaceManager nsm;

    _nameSpaceNames.append(CIMNamespaceName("aa"));
    _nameSpaceNames.append(CIMNamespaceName("aa/bb"));
    _nameSpaceNames.append(CIMNamespaceName("aa/bb/cc"));
    _nameSpaceNames.append(CIMNamespaceName("/lmnop/qrstuv"));
    _nameSpaceNames.append(CIMNamespaceName("root"));
    _nameSpaceNames.append(CIMNamespaceName("xx"));
    _nameSpaceNames.append(CIMNamespaceName("xx/yy"));

    for (Uint32 j = 0; j < _nameSpaceNames.size(); j++)
    {
        // NOTE: The "root" namespace is created by CIMRepository, which is not
        // used by this test program.  So the "root" namespace is not expected
        // to be created automatically in this case.
        //if (!_nameSpaceNames[j].equal(CIMNamespaceName("root")))
        {
            // Create a namespace
            nsm.createNameSpace(_nameSpaceNames[j], true, true, String::EMPTY);
        }
    }

    Array<CIMNamespaceName> nameSpaceNames;
    nsm.getNameSpaceNames(nameSpaceNames);
    if (verbose)
        nsm.print(cout);
    PEGASUS_TEST_ASSERT(nameSpaceNames.size() == NUM_NAMESPACE_NAMES);
    BubbleSort(nameSpaceNames);

    for (Uint32 i = 0; i < NUM_NAMESPACE_NAMES; i++)
    {
        PEGASUS_TEST_ASSERT(_nameSpaceNames[i] == nameSpaceNames[i]);
        PEGASUS_TEST_ASSERT(nsm.nameSpaceExists(nameSpaceNames[i]));
    }

    nsm.deleteNameSpace(CIMNamespaceName("lmnop/qrstuv"));
    nsm.getNameSpaceNames(nameSpaceNames);
    PEGASUS_TEST_ASSERT(nameSpaceNames.size() == NUM_NAMESPACE_NAMES - 1);

    // Create and delete a class to test these functions
    nsm.createClass(CIMNamespaceName("aa/bb"), "MySuperClass", CIMName());
    nsm.createClass(CIMNamespaceName("aa/bb"), "MyClass", "MySuperClass");
    PEGASUS_TEST_ASSERT(
        nsm.getSuperClassName(CIMNamespaceName("aa/bb"), "MySuperClass") ==
        CIMName());
    PEGASUS_TEST_ASSERT(
        nsm.getSuperClassName(CIMNamespaceName("aa/bb"), "MyClass") ==
        "MySuperClass");
    nsm.deleteClass(CIMNamespaceName("aa/bb"), "MyClass");
    nsm.deleteClass(CIMNamespaceName("aa/bb"), "MySuperClass");

    for (Uint32 j = 0; j < _nameSpaceNames.size(); j++)
    {
        if (!_nameSpaceNames[j].equal(CIMNamespaceName("root")) &&
            !_nameSpaceNames[j].equal(CIMNamespaceName("lmnop/qrstuv")))
        {
            nsm.deleteNameSpace(CIMNamespaceName(_nameSpaceNames[j]));
        }
    }
    nsm.getNameSpaceNames(nameSpaceNames);
    // Only the root namespace should be left.
    PEGASUS_TEST_ASSERT(nameSpaceNames.size() == 1);
    PEGASUS_TEST_ASSERT(nameSpaceNames[0].equal(CIMNamespaceName("root")));
    // confirm we can delete root
    nsm.deleteNameSpace(nameSpaceNames[0]);
    nsm.getNameSpaceNames(nameSpaceNames);
    PEGASUS_TEST_ASSERT(nameSpaceNames.size() == 0);
}
Пример #6
0
//

#include "RUEpProvider.h"

PEGASUS_USING_STD;
PEGASUS_USING_PEGASUS;

//********************************************************
//  Constants
//********************************************************

// Namespace name
static const CIMNamespaceName NAMESPACE = CIMNamespaceName("root/cimv2");

// Class names
static const CIMName CLASS_CIM_PROTOCOL_ENDPOINT = CIMName(
    "CIM_ProtocolEndpoint");
static const CIMName CLASS_CIM_NEXT_HOP_ROUTE = CIMName("CIM_NextHopRoute");
static const CIMName CLASS_PG_ROUTE_USES_ENDPOINT = CIMName(
    "PG_RouteUsesEndpoint");

// Property names.
static const CIMName PROPERTY_INSTANCE_ID = CIMName("InstanceID");
static const CIMName PROPERTY_DESTINATION_ADDRESS = CIMName(
    "DestinationAddress");
static const CIMName PROPERTY_DESTINATION_MASK = CIMName("DestinationMask");
static const CIMName PROPERTY_PREFIX_LENGTH = CIMName("PrefixLength");
static const CIMName PROPERTY_SUBNET_MASK = CIMName("SubnetMask");
static const CIMName PROPERTY_ADDRESS_TYPE = CIMName("AddressType");
static const CIMName PROPERTY_PROTOCOL_IF_TYPE = CIMName("ProtocolIFType");
static const CIMName PROPERTY_IPV4ADDRESS = CIMName("IPv4Address");
static const CIMName PROPERTY_IPV6ADDRESS = CIMName("IPv6Address");
CIMInstance UNIX_BGPServiceAttributes::getPartComponent() const
{
	return CIMInstance(CIMName("CIM_Component"));
}
Пример #8
0
int main()
{
    cout << "Starting Server Profile Tests" << endl << endl;
    // Create a locally-connected client
    CIMClient client;

    try
    {
        client.connectLocal();
        client.setTimeout(60000); // Set the timeout to one minute
    }
    catch(Exception &)
    {
        exitFailure(String("Could not connect to server"));
    }

    CIMName currentClass;
    try
    {
        currentClass = CIMName("CIM_ComputerSystem");
        testInstanceClass(client, currentClass);
        currentClass = CIMName("CIM_ObjectManager");
        testInstanceClass(client, currentClass);
        currentClass = CIMName("CIM_RegisteredSubProfile");
        testInstanceClass(client, currentClass);
        currentClass = CIMName("CIM_RegisteredProfile");
        testInstanceClass(client, currentClass);
        currentClass = CIMName("CIM_CIMXMLCommunicationMechanism");
        testInstanceClass(client, currentClass);
        currentClass = CIMName("CIM_Namespace");
        testInstanceClass(client, currentClass);
        currentClass = CIMName("CIM_SoftwareIdentity");
        testInstanceClass(client, currentClass);

        currentClass = CIMName("CIM_HostedService");
        testAssociationClass(client, currentClass);
        currentClass = CIMName("CIM_ElementConformsToProfile");
        testAssociationClass(client, currentClass);
        currentClass = CIMName("CIM_SubprofileRequiresProfile");
        testAssociationClass(client, currentClass);
        currentClass = CIMName("CIM_ReferencedProfile");
        testAssociationClass(client, currentClass);
        currentClass = CIMName("CIM_ElementSoftwareIdentity");
        testAssociationClass(client, currentClass);
        currentClass = CIMName("CIM_CommMechanismForManager");
        testAssociationClass(client, currentClass);
    }
    catch(Exception & e)
    {
        exitFailure(String("Caught exception while testing class ") +
            currentClass.getString() + String(": ") + e.getMessage());
    }
    catch(...)
    {
        exitFailure(String("Caught unknown exception while testing class ") +
            currentClass.getString());
    }

    testDMTFProfileInstances(client);
#ifdef PEGASUS_ENABLE_DMTF_INDICATION_PROFILE_SUPPORT
    testIndicationProfileInstances(client);
#endif
    //testAssociationTraversal(client);

    cout << endl << "Server Profile Tests complete" << endl;
    return 0;
}
Пример #9
0
#include <Pegasus/Common/Config.h>
#include <Pegasus/Common/Constants.h>
#include <Pegasus/Common/System.h>
#include <Pegasus/Common/FileSystem.h>
#include <Pegasus/Common/InternalException.h>
#include <Pegasus/Client/CIMClient.h>
#include <Pegasus/Common/XmlWriter.h>

#include <iostream>

PEGASUS_USING_PEGASUS;
PEGASUS_USING_STD;

const CIMNamespaceName SOURCE_NAMESPACE = CIMNamespaceName(
                                              "root/SampleProvider");
const CIMName SAMPLE_CLASSNAME  = CIMName("CWS_PlainFile");

Array<CIMObjectPath> objectNames;
CIMInstance instance;
CIMValue value;

static Boolean verbose;

void _enumerateInstanceNames(CIMClient & client)
{
    try
    {
        objectNames = client.enumerateInstanceNames(
                                 SOURCE_NAMESPACE,
                                 SAMPLE_CLASSNAME);
        if (verbose)
void LifecycleIndicationProvider::createInstance(
    const OperationContext & context,
    const CIMObjectPath & instanceReference,
    const CIMInstance & instanceObject,
    ObjectPathResponseHandler & handler)
{
//  cout << "LifecycleIndicationProvider::createInstance()" << endl;
    // Validate the class name
    if(!instanceObject.getClassName().equal(
           "Sample_LifecycleIndicationProviderClass"))
    {
        throw CIMNotSupportedException(
            instanceObject.getClassName().getString());
    }

    // Find the key property
    Uint32 idIndex = instanceObject.findProperty("uniqueId");

    if(idIndex == PEG_NOT_FOUND)
    {
        throw CIMInvalidParameterException("Missing key value");
    }

    CIMInstance cimInstance = instanceObject.clone();

    // Create the new instance name
    CIMValue idValue = instanceObject.getProperty(idIndex).getValue();
    Array<CIMKeyBinding> keys;
    keys.append(CIMKeyBinding("uniqueId", idValue));

    CIMObjectPath instanceName =
        CIMObjectPath(
            String(),
            CIMNamespaceName(),
            instanceObject.getClassName(),
            keys);

    cimInstance.setPath(instanceName);

    // Determine whether this instance already exists
    for(Uint32 i = 0, n = _instances.size(); i < n; i++)
    {
        if(instanceName == _instances[i].getPath())
        {
            throw CIMObjectAlreadyExistsException(instanceName.toString());
        }
    }

    // begin processing the request
    handler.processing();

    // add the new instance to the array
    _instances.append(cimInstance);

    // deliver the new instance name
    handler.deliver(instanceName);

    // complete processing the request
    handler.complete();

    // If there is at least one subscription active for the lifecycle indication
    // InstCreation_for_Sample_LifecycleIndicationProviderClass, then generate
    // that indication here, embedding the newly-created instance as
    // the SourceInstance property. See LifecycleIndicationProviderR.mof.
    if (_lifecycle_indications_enabled)
    {
        CIMInstance indicationInstance(
            CIMName(
                "InstCreation_for_Sample_LifecycleIndicationProviderClass"));
        CIMObjectPath path;
        path.setNameSpace("root/SampleProvider");
        path.setClassName(
            "InstCreation_for_Sample_LifecycleIndicationProviderClass");
        indicationInstance.setPath(path);

        char buffer[32];
        sprintf(buffer, "%d", _nextUID++);
        indicationInstance.addProperty
            (CIMProperty ("IndicationIdentifier",String(buffer)));

        CIMDateTime currentDateTime = CIMDateTime::getCurrentDateTime ();
        indicationInstance.addProperty
            (CIMProperty ("IndicationTime", currentDateTime));

        indicationInstance.addProperty
            (CIMProperty ("SourceInstance",CIMObject(cimInstance)));

        _indication_handler->deliver (indicationInstance);

//      cout << "LifecycleIndicationProvider::createInstance() sent "
//                  "InstCreation_for_Sample_LifecycleIndicationProviderClass"
//           << endl;
    }
}
void LifecycleIndicationProvider::deleteInstance(
    const OperationContext & context,
    const CIMObjectPath & instanceReference,
    ResponseHandler & handler)
{
//  cout << "LifecycleIndicationProvider::deleteInstance()" << endl;
    CIMInstance localInstance;
    // convert a potential fully qualified reference into a local reference
    // (class name and keys only).
    CIMObjectPath localReference =
        CIMObjectPath(
            String(),
            CIMNamespaceName(),
            instanceReference.getClassName(),
            instanceReference.getKeyBindings());

    // begin processing the request
    handler.processing();

    // instance index corresponds to reference index
    for(Uint32 i = 0, n = _instances.size(); i < n; i++)
    {
        if(localReference == _instances[i].getPath())
        {
            localInstance = _instances[i];
            // remove instance from the array
            _instances.remove(i);

            break;
        }
    }

    // complete processing the request
    handler.complete();

    // If there is at least one subscription active for the lifecycle indication
    // InstDeletion_for_Sample_LifecycleIndicationProviderClass, then generate
    // that indication here, embedding the just-deleted instance as the
    // SourceInstance property. See LifecycleIndicationProviderR.mof.
    if (_lifecycle_indications_enabled)
    {
        CIMInstance indicationInstance(
            CIMName(
                "InstDeletion_for_Sample_LifecycleIndicationProviderClass"));
        CIMObjectPath path;
        path.setNameSpace("root/SampleProvider");
        path.setClassName(
            "InstDeletion_for_Sample_LifecycleIndicationProviderClass");
        indicationInstance.setPath(path);

        char buffer[32];
        sprintf(buffer, "%d", _nextUID++);
        indicationInstance.addProperty
            (CIMProperty ("IndicationIdentifier",String(buffer)));

        CIMDateTime currentDateTime = CIMDateTime::getCurrentDateTime ();
        indicationInstance.addProperty
            (CIMProperty ("IndicationTime", currentDateTime));

        // Before we send the Lifecycle Indication for the delete of this
        // instance, change the "lastOp" property value to "deleteInstance".
        Uint32 ix = localInstance.findProperty(CIMName("lastOp"));
        if (ix != PEG_NOT_FOUND)
        {
            localInstance.removeProperty(ix);
            localInstance.addProperty(
                CIMProperty(
                    CIMName("lastOp"),
                    String("deleteInstance")));
        }

        indicationInstance.addProperty
            (CIMProperty ("SourceInstance",CIMObject(localInstance)));

        _indication_handler->deliver (indicationInstance);

//      cout << "LifecycleIndicationProvider::deleteInstance() sent "
//                  "InstDeletion_for_Sample_LifecycleIndicationProviderClass"
//           << endl;
    }
}
Пример #12
0
void Test01(Uint32 mode)
{
    String repositoryRoot;
    const char* tmpDir = getenv ("PEGASUS_TMP");
    if (tmpDir == NULL)
    {
        repositoryRoot = ".";
    }
    else
    {
        repositoryRoot = tmpDir;
    }

    repositoryRoot.append("/repository");

    FileSystem::removeDirectoryHier(repositoryRoot);

    CIMRepository r (repositoryRoot, mode);

    // Create a namespace:

    const CIMNamespaceName NAMESPACE = CIMNamespaceName ("zzz");
    r.createNameSpace(NAMESPACE);

    // Create a qualifier (and read it back):

    CIMQualifierDecl q1(CIMName ("abstract"), false, CIMScope::CLASS);
    r.setQualifier(NAMESPACE, q1);

    CIMConstQualifierDecl q2 = r.getQualifier(NAMESPACE, CIMName ("abstract"));
    PEGASUS_TEST_ASSERT(q1.identical(q2));

    // Create two simple classes:

    CIMClass class1(CIMName ("Class1"));
    class1.addQualifier(
        CIMQualifier(CIMName ("abstract"), true, CIMFlavor::DEFAULTS));
    CIMClass class2(CIMName ("Class2"), CIMName ("Class1"));

    r.createClass(NAMESPACE, class1);
    r.createClass(NAMESPACE, class2);

    // Enumerate the class names:
    Array<CIMName> classNames =
        r.enumerateClassNames(NAMESPACE, CIMName(), true);

    BubbleSort(classNames);

    PEGASUS_TEST_ASSERT(classNames.size() == 2);
    PEGASUS_TEST_ASSERT(classNames[0] == "Class1");
    PEGASUS_TEST_ASSERT(classNames[1] == "Class2");

    // Get the classes and determine if they are identical with input

    CIMClass c1 = r.getClass(NAMESPACE, CIMName ("Class1"), true, true, false);
    CIMClass c2 = r.getClass(NAMESPACE, CIMName ("Class2"), true, true, false);

    PEGASUS_TEST_ASSERT(c1.identical(class1));
    PEGASUS_TEST_ASSERT(c1.identical(class1));

    Array<CIMClass> classes =
        r.enumerateClasses(NAMESPACE, CIMName (), true, true, true);

    // Attempt to delete Class1. It should fail since the class has
    // children.

    try
    {
        r.deleteClass(NAMESPACE, CIMName ("Class1"));
    }
    catch (CIMException& e)
    {
        PEGASUS_TEST_ASSERT(e.getCode() == CIM_ERR_CLASS_HAS_CHILDREN);
    }

    // Delete all classes created here:

    r.deleteClass(NAMESPACE, CIMName ("Class2"));
    r.deleteClass(NAMESPACE, CIMName ("Class1"));

    // Be sure the classes are really gone:

    try
    {
        CIMClass c1 = r.getClass(
            NAMESPACE, CIMName ("Class1"), true, true, true);
        PEGASUS_TEST_ASSERT(false);
    }
    catch (CIMException& e)
    {
        PEGASUS_TEST_ASSERT(e.getCode() == CIM_ERR_NOT_FOUND);
    }

    try
    {
        CIMClass c2 = r.getClass(
            NAMESPACE, CIMName ("Class2"), true, true, true);
        PEGASUS_TEST_ASSERT(false);
    }
    catch (CIMException& e)
    {
        PEGASUS_TEST_ASSERT(e.getCode() == CIM_ERR_NOT_FOUND);
    }

    FileSystem::removeDirectoryHier(repositoryRoot);
}
void _testCMPIFilterOfAssociation(CIMClient& client)
{
    try
    {
        Array<CIMObjectPath> personRefs;
        Uint32 numPersonInstances ;
        personRefs = 
            client.enumerateInstanceNames(providerNamespace,CMPI_TEST_PERSON);
        numPersonInstances = personRefs.size();
        CIMName resultClass;
        String role;
        String resultRole;
        cout<<"++++++++Filtering the NULL propery list+++"<<endl;
        for (Uint32 i = 0; i < numPersonInstances; ++i)
        {
            Array<CIMObject> resultObjects =
                client.associators(
                    providerNamespace,
                    personRefs[i],
                    CMPI_TEST_RACING,
                    resultClass,
                    role,
                    resultRole,
                    false,
                    false,
                    CIMPropertyList());
            Uint32 size = resultObjects.size();
            for(Uint32 j = 0;j<size;j++)
            {
                Uint32 propCount = resultObjects[j].getPropertyCount();
                Uint32 propNameCount = 0;
                if(propCount != 0)
                {
                    String propName=
                        resultObjects[j].getProperty(0).getName().getString();
                    if(verbose)
                    {
                        cout<<"Property Name of :"<<i<<":"<<propName<<endl;
                    }
                    if(propName == "vehiclename") 
                    {
                        propNameCount++;
                    }
                }
                if((size != 0)&&(propCount == 1) &&(propNameCount == 1))
                {
                    cout<<"Filter associator test on CMPI_TEST_RACING SUCCEEDED"
                        <<":Filtering the ciminstance with a NULL property list"
                        <<" returned all properties as expected"<<endl;
                }
                else
                {
                    cout<<"Filter associator test on CMPI_TEST_RACING FAILED"
                        <<":Filtering the ciminstance with a NULL property list"
                        <<" did not return all properties as expected"<<endl;
                    PEGASUS_TEST_ASSERT(false);
                }
            }

        }
        cout<<"++++++Filtering the empty propery list+++"<<endl;
        Array<CIMName> propList;
        for (Uint32 i = 0; i < numPersonInstances; ++i)
        {
            Array<CIMObject> resultObjects =
                client.associators(
                    providerNamespace,
                    personRefs[i],
                    CMPI_TEST_RACING,
                    resultClass,
                    role,
                    resultRole,
                    false,
                    false,
                    CIMPropertyList(propList));
            Uint32 size = resultObjects.size();
            for(Uint32 j = 0;j<size;j++)
            {
                Uint32 propCount = resultObjects[j].getPropertyCount();
                if((size != 0)&&(propCount == 0))
                {
                    cout<<"Filter associator test on CMPI_TEST_RACING SUCCEEDED"
                        <<":Filtering the ciminstance with a empty property "
                        <<"list returned zero properties as expected"<<endl;
                }
                else
                { 
                    cout<<"Filter associators test on CMPI_TEST_RACING FAILED"
                        <<":Filtering the ciminstance with a empty property "
                        <<"list returned some properties which is not expected"
                        <<endl; 
                    PEGASUS_TEST_ASSERT(false);
                }
            }
        }
        cout<<"+++filtering the wrong properties ++++++"<<endl;
        Array<CIMName> propList1;
        propList1.append(CIMName(String("nam")));
        for (Uint32 i = 0; i < numPersonInstances; ++i)
        {
            Array<CIMObject> resultObjects =
                client.associators(
                    providerNamespace,
                    personRefs[i],
                    CMPI_TEST_RACING,
                    resultClass,
                    role,
                    resultRole,
                    false,
                    false,
                    CIMPropertyList(propList1));
            Uint32 size = resultObjects.size();
            for(Uint32 j = 0;j<size;j++)
            {
                Uint32 propCount = resultObjects[j].getPropertyCount();
                if((size != 0)&&(propCount == 0))
                {
                    cout<<"Filter associators test on CMPI_TEST_RACING "
                        <<"SUCCEEDED:Filtering the ciminstance with a wrong "
                        <<"property list returned zero properties as " 
                        <<"expected"<<endl;
                }
                else
                {
                    cout<<"Filter associators test on CMPI_TEST_RACING FAILED"
                         <<":Filtering the ciminstance with a wrong property "
                         <<"list returned some properties which is not"
                         <<" expected"<<endl; 
                    PEGASUS_TEST_ASSERT(false);
                }
            }
        }
        cout<<"++++++++Filtering the mentioned propery list+++"<<endl;
        Array<CIMName> propArr;
        propArr.append(CIMName(String("vehiclename")));
        for (Uint32 i = 0; i < numPersonInstances; ++i)
        {
            Array<CIMObject> resultObjects =
                client.associators(
                    providerNamespace,
                    personRefs[i],
                    CMPI_TEST_RACING,
                    resultClass,
                    role,
                    resultRole,
                    false,
                    false,
                    CIMPropertyList( propArr));
            Uint32 size = resultObjects.size();
            for(Uint32 j = 0;j<size;j++)
            {
                Uint32 propCount = resultObjects[j].getPropertyCount();
                Uint32 propNameCount = 0;
                if(propCount != 0)
                {
                    String propName=
                        resultObjects[j].getProperty(0).getName().getString();
                    if(verbose)
                    {
                        cout<<"Property Name of :"<<i<<":"<<propName<<endl;
                    }
                    if(propName == "vehiclename")
                    {
                        propNameCount++;
                    }
                }
                if((size != 0)&&(propCount == 1) &&(propNameCount == 1))
                {
                     cout<<"Filter associators test on CMPI_TEST_RACING "
                         <<"SUCCEEDED:Filtering the ciminstance with a "
                         <<"mentioned property list returned all properties"
                         <<" as expected"<<endl;
                }
                else
                {
                    cout<<"Filter associators test on CMPI_TEST_RACING FAILED"
                        <<":Filtering the ciminstance with a mentioned property"
                        <<" list did not return properties as expected "<<endl;
                    PEGASUS_TEST_ASSERT(false);
                }
            }
        }
    }
    catch(Exception& e)
    {
        cerr << "enumerateInstanceNames() failed." << endl;
            _errorExit(e.getMessage());
    }
}
// is considered a failure.  If there is a failure, an error message is
// displayed and the program terminates.

#include <Pegasus/Client/CIMClient.h>
#include <string.h>

#include <Pegasus/Provider/CMPI/cmpidt.h>
#include <Pegasus/Provider/CMPI/cmpift.h>
#include <Pegasus/Provider/CMPI/cmpimacs.h>
#include <Pegasus/Common/PegasusAssert.h>

PEGASUS_USING_STD;
PEGASUS_USING_PEGASUS;

CIMNamespaceName providerNamespace;
const CIMName CMPI_TEST_PERSON = CIMName ("CMPI_TEST_Person");
const CIMName CMPI_TEST_VEHICLE = CIMName ("CMPI_TEST_Vehicle");
const CIMName CMPI_TEST_RACING = CIMName ("CMPI_TEST_Racing");


Boolean verbose = false;

// exepected results - number of returned objects expected for each test

static const Uint32 resultArray_asso_P1[] = { 3, 3 };
static const Uint32 resultArray_asso_V1[] = { 3, 3 };
static const Uint32 resultArray_ref_P[] =   { 3, 3, 3, 3 };
static const Uint32 resultArray_ref_V[] =   { 3, 3, 3, 3 };

////////////////////////////////////////////////////////////////////////////
//  _errorExit
Пример #15
0
int main(int argc, char** argv)
{
    verbose = getenv("PEGASUS_TEST_VERBOSE");
    String assocTablePath;
    const char* tmpDir = getenv ("PEGASUS_TMP");
    if (tmpDir == NULL)
    {
        assocTablePath = ".";
    }
    else
    {
        assocTablePath = tmpDir;
    }
    assocTablePath.append("/associations.tbl");

    //
    // create class association
    //
    AssocClassTable::append(
        assocTablePath,
	CIMName ("Lineage"),
	CIMName ("Person"),
	CIMName ("parent"),
	CIMName ("Person"),
	CIMName ("child"));

    //
    // delete class association 
    //
    AssocClassTable::deleteAssociation(
        assocTablePath,
        CIMName ("Lineage"));

    //
    // create instance association 
    //
    AssocInstTable::append(
        assocTablePath,
        "A.left=\"x.key=\\\"one\\\"\",right=\"y.key=\\\"two\\\"\"",
        CIMName ("A"),
        "X.key=\"one\"",
        CIMName ("X"),
        CIMName ("left"),
        "Y.key=\"two\"",
        CIMName ("Y"),
        CIMName ("right"));

    //
    // delete instance association 
    //
    AssocInstTable::deleteAssociation(
        assocTablePath,
        CIMObjectPath 
            ("A.left=\"x.key=\\\"one\\\"\",right=\"y.key=\\\"two\\\"\""));

    cout << argv[0] << " +++++ passed all tests" << endl;

    return 0;
}
Пример #16
0
int main(int, char** argv)
{
    verbose = getenv("PEGASUS_TEST_VERBOSE") ? true : false;

    try
    {
        CIMMethod m1(CIMName ("getHostName"), CIMTYPE_STRING);
        m1.addQualifier(CIMQualifier(CIMName ("stuff"), true));
        m1.addQualifier(CIMQualifier(CIMName ("stuff2"), true));
        m1.addParameter(CIMParameter(CIMName ("ipaddress"), CIMTYPE_STRING));


        // Tests for Qualifiers
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff")) != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff2")) != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff21")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuf")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(m1.getQualifierCount() == 2);

        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff")) != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff2")) != PEG_NOT_FOUND);

        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff21")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuf")) == PEG_NOT_FOUND);

        Uint32 posQualifier;
        posQualifier = m1.findQualifier(CIMName ("stuff"));
        PEGASUS_TEST_ASSERT(posQualifier != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(posQualifier < m1.getQualifierCount());

        m1.removeQualifier(posQualifier);
        PEGASUS_TEST_ASSERT(m1.getQualifierCount() == 1);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff2")) != PEG_NOT_FOUND);

        // Tests for Parameters
        PEGASUS_TEST_ASSERT(m1.findParameter(
            CIMName ("ipaddress")) != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(m1.findParameter(
            CIMName ("noparam"))  == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(m1.getParameterCount()  == 1);
        CIMParameter cp = m1.getParameter(
            m1.findParameter(CIMName ("ipaddress")));
        PEGASUS_TEST_ASSERT(cp.getName() == CIMName ("ipaddress"));

        m1.removeParameter (m1.findParameter (
            CIMName (CIMName ("ipaddress"))));
        PEGASUS_TEST_ASSERT (m1.getParameterCount ()  == 0);
        m1.addParameter (CIMParameter (CIMName ("ipaddress"),
                                       CIMTYPE_STRING));
        PEGASUS_TEST_ASSERT (m1.getParameterCount ()  == 1);

        // throws OutOfBounds
        try
        {
            m1.removeParameter (1);
        }
        catch (IndexOutOfBoundsException & oob)
        {
            if (verbose)
            {
                PEGASUS_STD (cout) << "Caught expected exception: "
                                   << oob.getMessage () << PEGASUS_STD (endl);
            }
        }

        CIMMethod m2(CIMName ("test"), CIMTYPE_STRING);
        m2.setName(CIMName ("getVersion"));
        PEGASUS_TEST_ASSERT(m2.getName() == CIMName ("getVersion"));

        m2.setType(CIMTYPE_STRING);
        PEGASUS_TEST_ASSERT(m2.getType() == CIMTYPE_STRING);

        m2.setClassOrigin(CIMName ("test"));
        PEGASUS_TEST_ASSERT(m2.getClassOrigin() == CIMName ("test"));

        m2.setPropagated(true);
        PEGASUS_TEST_ASSERT(m2.getPropagated() == true);

        const CIMMethod cm1(m1);
        PEGASUS_TEST_ASSERT(cm1.findQualifier(
            CIMName ("stuff21")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(cm1.findQualifier(
            CIMName ("stuf")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT((cm1.getParameterCount() != 3));
        PEGASUS_TEST_ASSERT(cm1.findParameter(
            CIMName ("ipaddress")) != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(cm1.findQualifier(
            CIMName ("stuff")) == PEG_NOT_FOUND);

        CIMQualifier q = m1.getQualifier(posQualifier);
        CIMConstParameter ccp = cm1.getParameter(
                    cm1.findParameter(CIMName ("ipaddress")));
        PEGASUS_TEST_ASSERT(cm1.getName() == CIMName ("getHostName"));
        PEGASUS_TEST_ASSERT(cm1.getType() == CIMTYPE_STRING);
        PEGASUS_TEST_ASSERT(!(cm1.getClassOrigin() == CIMName ("test")));
        PEGASUS_TEST_ASSERT(!cm1.getPropagated() == true);
        PEGASUS_TEST_ASSERT(!m1.identical(m2));

        // throws OutOfBounds
        try
        {
            CIMConstParameter p = cm1.getParameter(cm1.findParameter(
                                        CIMName ("ipaddress")));
        }
        catch(IndexOutOfBoundsException&)
        {
        }

        // throws OutOfBounds
        try
        {
            CIMConstQualifier q1 = cm1.getQualifier(cm1.findQualifier(
                                        CIMName ("abstract")));
        }
        catch(IndexOutOfBoundsException&)
        {
        }

        if (verbose)
        {
            XmlWriter::printMethodElement(m1);
            XmlWriter::printMethodElement(cm1);
        }
        Buffer out;
        XmlWriter::appendMethodElement(out, cm1);
        MofWriter::appendMethodElement(out, cm1);

        Boolean nullMethod = cm1.isUninitialized();
        PEGASUS_TEST_ASSERT(!nullMethod);

        CIMMethod m3 = m2.clone();
        m3 = cm1.clone();

        CIMMethod m4;
        CIMMethod m5(m4);

        CIMConstMethod ccm1(CIMName ("getHostName"),CIMTYPE_STRING);
        PEGASUS_TEST_ASSERT(!(ccm1.getParameterCount() == 3));

        PEGASUS_TEST_ASSERT(ccm1.getName() == CIMName ("getHostName"));
        PEGASUS_TEST_ASSERT(ccm1.getType() == CIMTYPE_STRING);
        PEGASUS_TEST_ASSERT(!(ccm1.getClassOrigin() == CIMName ("test")));
        PEGASUS_TEST_ASSERT(!ccm1.getPropagated() == true);
        PEGASUS_TEST_ASSERT(!(ccm1.getParameterCount() == 3));
        PEGASUS_TEST_ASSERT(ccm1.getQualifierCount() == 0);
        PEGASUS_TEST_ASSERT(ccm1.findQualifier(
            CIMName ("Stuff")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(ccm1.findParameter(
            CIMName ("ipaddress")) == PEG_NOT_FOUND);

        if (verbose)
        {
            XmlWriter::printMethodElement(m1);
            XmlWriter::printMethodElement(ccm1);
        }

        XmlWriter::appendMethodElement(out, ccm1);

        CIMConstMethod ccm2(ccm1);
        CIMConstMethod ccm3;

        ccm3 = ccm1.clone();
        ccm1 = ccm3;
        PEGASUS_TEST_ASSERT(ccm1.identical(ccm3));
        PEGASUS_TEST_ASSERT(ccm1.findQualifier(
            CIMName ("stuff")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(ccm1.findParameter(
            CIMName ("ipaddress")) == PEG_NOT_FOUND);

        nullMethod = ccm1.isUninitialized();
        PEGASUS_TEST_ASSERT(!nullMethod);

        // throws OutOfBounds
        try
        {
            //CIMParameter p = m1.getParameter(
            //     m1.findParameter(CIMName ("ipaddress")));
            CIMConstParameter p = ccm1.getParameter(0);
        }
        catch(IndexOutOfBoundsException&)
        {
        }

        // throws OutOfBounds
        try
        {
            CIMConstQualifier q1 = ccm1.getQualifier(0);
        }
        catch(IndexOutOfBoundsException&)
        {
        }
    }
    catch(Exception& e)
    {
        cerr << "Exception: " << e.getMessage() << endl;
    }

    // Test for add second qualifier with same name.
    // Should do exception

    cout << argv[0] << " +++++ passed all tests" << endl;

    return 0;
}
void UNIX_ApplicationSystemDependency::setScope(CIMName scope)
{
	currentScope = CIMName(scope.getString());
}
Пример #18
0
#include <Pegasus/Common/CIMName.h>
#include <Pegasus/Common/CIMInstance.h>
#include <Pegasus/Common/CIMProperty.h>
#include <Pegasus/Common/CIMValue.h>
#include <Pegasus/Common/System.h>
#include <Pegasus/Common/InternalException.h>
#include <Pegasus/Common/AcceptLanguageList.h>
#include <Pegasus/Common/ContentLanguageList.h>
#include <Pegasus/Client/CIMClient.h>

PEGASUS_USING_PEGASUS;
PEGASUS_USING_STD;


CIMNamespaceName providerNamespace;
const CIMName CLASSNAME = CIMName ("TestCMPI_Broker");

Boolean verbose;
Boolean useDefaultMsg;


void _checkStringValue (CIMValue & theValue,
    const String & value,
    Boolean null = false)
{
    PEGASUS_TEST_ASSERT (theValue.getType () == CIMTYPE_STRING);
    PEGASUS_TEST_ASSERT (!theValue.isArray ());
    if (null)
    {
        PEGASUS_TEST_ASSERT (theValue.isNull ());
    }
Пример #19
0
void RUEpProvider::_createAssociationInstances(
    Array<CIMInstance> nhrInst,
    Array<CIMInstance> ipifInst)
{
    PEG_METHOD_ENTER(TRC_PROVIDERAGENT,
        "RUEpProvider::_createAssociationInstances()");

    Uint16 nhrInstSize = nhrInst.size();
    Uint16 ipifInstSize = ipifInst.size();

    for (Uint16 i = 0; i < nhrInstSize; i++)  // Routes loop.
    {
        CIMInstance _nhrInstRet, _ipifInstRet;
        CIMInstance _nhrInst = nhrInst[i];

        CIMProperty _ipifAddress;
        CIMProperty _ipifSubnetMask_PrefixLength;
        CIMProperty _ipifProtocolIFType;
        CIMProperty _nhrInstanceID = _nhrInst.getProperty(
            _nhrInst.findProperty(PROPERTY_INSTANCE_ID));
        CIMProperty _nhrAddrType;
        CIMProperty _nhrDestMask_PrefixLength;


        for (Uint16 j = 0; j<ipifInstSize; j++)  // Interfaces loop.
        {
            CIMInstance _ipifInst = ipifInst[j];

            _ipifProtocolIFType = _ipifInst.getProperty(
                _ipifInst.findProperty(PROPERTY_PROTOCOL_IF_TYPE));

            Uint16 _pift;
            CIMValue _piftCIMValue = _ipifProtocolIFType.getValue();
            if ((_piftCIMValue.getType() == CIMTYPE_UINT16) &&
                (!_piftCIMValue.isNull ()))
            {
                _piftCIMValue.get(_pift);
            }
            else
            {
                throw CIMOperationFailedException(
                    "Can't determine CIMValue::TYPE of ProtocolIFType:" +
                    String(cimTypeToString(_piftCIMValue.getType())));
            }

            if (_pift == 4096)  // IPv4 address.
            {
                _ipifAddress = _ipifInst.getProperty(
                    _ipifInst.findProperty(
                        PROPERTY_IPV4ADDRESS));
                _ipifSubnetMask_PrefixLength = _ipifInst.getProperty(
                    _ipifInst.findProperty(
                    PROPERTY_SUBNET_MASK));
            }
            else
            {
                if (_pift == 4097)  // IPv6 address.
                {
                    _ipifAddress = _ipifInst.getProperty(
                        _ipifInst.findProperty(
                            PROPERTY_IPV6ADDRESS));
                    _ipifSubnetMask_PrefixLength = _ipifInst.getProperty(
                        _ipifInst.findProperty(
                            PROPERTY_IPV6ADDRESS));
                }
                else
                {
                    char buffer[22];
                    Uint32 sz;
                    String _piftStr = Uint16ToString(buffer, _pift, sz);
                    throw CIMOperationFailedException(
                        "ProtocolIFType == " +  _piftStr );
                }
            }

            // In this implementation, we choose InstanceID to be
            // equal DestinationAddress. So, if Address of interface
            // and InstanceID of route doesn't match, check if SubnetMask
            // of interface and DestinationMask route does.
            if (!_nhrInstanceID.getValue().equal(_ipifAddress.getValue()))
            {
                _nhrAddrType = _nhrInst.getProperty(
                    _nhrInst.findProperty(
                        PROPERTY_ADDRESS_TYPE));
                Uint16 _addrt;
                CIMValue _nhratCIMValue = _nhrAddrType.getValue();
                if ((_nhratCIMValue.getType() == CIMTYPE_UINT16) &&
                    (!_nhratCIMValue.isNull()))
                {
                    _nhratCIMValue.get(_addrt);
                }
                else
                {
                    throw CIMOperationFailedException(
                        "Can't determine CIMValue::TYPE of AddressType: " +
                        String(cimTypeToString(_piftCIMValue.getType())));
                }

                if (_addrt == 1)  // IPv4 address.
                {
                    _nhrDestMask_PrefixLength = _nhrInst.getProperty(
                       _nhrInst.findProperty(
                           PROPERTY_DESTINATION_MASK));
                }
                else
                {
                    if (_addrt == 2)  // IPv6 address.
                    {
                         _nhrDestMask_PrefixLength = _nhrInst.getProperty(
                             _nhrInst.findProperty(
                                 PROPERTY_PREFIX_LENGTH));
                    }
                    else
                    {
                        char buffer[22];
                        Uint32 sz;
                        String _addrtStr = Uint16ToString(buffer, _addrt, sz);
                        throw CIMOperationFailedException(
                            "Unknown AddressType = " + _addrtStr);
                    }
                }

                // If SubnetMask of interface and DestinationMask route
                // doesn't match, these instances are unrelated. So,
                // proceed to the next pair.
                if (!_nhrDestMask_PrefixLength.getValue().equal(
                    _ipifSubnetMask_PrefixLength.getValue()))
                {
                    continue;
                }
            }

            // Build the CIMObjectPath from the instances matching
            CIMObjectPath _ipifObj = _ipifInst.getPath();
            CIMObjectPath _nhrObj = _nhrInst.getPath();

            CIMInstance assocInst(CLASS_PG_ROUTE_USES_ENDPOINT);
            assocInst.addProperty(
                CIMProperty(
                    CIMName("Antecedent"),
                    _ipifObj,
                    0,
                    CLASS_CIM_PROTOCOL_ENDPOINT));
            assocInst.addProperty(
                CIMProperty(
                    CIMName("Dependent"),
                    _nhrObj,
                    0,
                    CLASS_CIM_NEXT_HOP_ROUTE));

            // Build CIMObjectPath from keybindings
            Array<CIMKeyBinding> keyBindings;
            CIMKeyBinding _ipifBinding(
                CIMName("Antecedent"),
                _ipifObj.toString(),
                CIMKeyBinding::REFERENCE);
            CIMKeyBinding _nhrBinding(
                CIMName("Dependent"),
                _nhrObj.toString(),
                CIMKeyBinding::REFERENCE);
            keyBindings.append (_ipifBinding);
            keyBindings.append (_nhrBinding);

            CIMObjectPath path(
                String::EMPTY,
                CIMNamespaceName(),
                CLASS_PG_ROUTE_USES_ENDPOINT,
                keyBindings);

            assocInst.setPath(path);
            _AssociationInstances.append(assocInst);
            break;
        }  // Interfaces loop end.

    }  // Routes loop end.

    PEG_METHOD_EXIT();
}
Пример #20
0
// l10n - note: ignoring indication language
void snmpIndicationHandler::handleIndication(
    const OperationContext& context,
    const String nameSpace,
    CIMInstance& indication,
    CIMInstance& handler, 
    CIMInstance& subscription,
    ContentLanguages & contentLanguages)
{
    Array<String> propOIDs;
    Array<String> propTYPEs;
    Array<String> propVALUEs;

    CIMProperty prop;
    CIMQualifier trapQualifier;

    Uint32 qualifierPos;
    
    String propValue;

    String mapstr1;
    String mapstr2;

    PEG_METHOD_ENTER (TRC_IND_HANDLER, 
	"snmpIndicationHandler::handleIndication");

    try
    {
    	CIMClass indicationClass = _repository->getClass(
	    nameSpace, indication.getClassName(), false, true, 
	    false, CIMPropertyList());

    	Uint32 propertyCount = indication.getPropertyCount();

    	for (Uint32 i=0; i < propertyCount; i++)
    	{
	    prop = indication.getProperty(i);

	    if (!prop.isUninitialized())
            {
                CIMName propName = prop.getName();
                Uint32 propPos = indicationClass.findProperty(propName);
                if (propPos != PEG_NOT_FOUND)
                {
                    CIMProperty trapProp = indicationClass.getProperty(propPos);

                    qualifierPos = trapProp.findQualifier(CIMName ("MappingStrings"));
                    if (qualifierPos != PEG_NOT_FOUND)
                    {
		        trapQualifier = trapProp.getQualifier(qualifierPos);
		
		        mapstr1.clear();
		        mapstr1 = trapQualifier.getValue().toString();

		        if ((mapstr1.find("OID.IETF") != PEG_NOT_FOUND) &&
		            (mapstr1.find("DataType.IETF") != PEG_NOT_FOUND))
		        {
		            if (mapstr1.subString(0, 8) == "OID.IETF")
		            {
			        mapstr1 = mapstr1.subString(mapstr1.find("SNMP.")+5);
                                if (mapstr1.find("|") != PEG_NOT_FOUND)
                                {
			            mapstr2.clear();
			            mapstr2 = mapstr1.subString(0, 
				        mapstr1.find("DataType.IETF")-1);
			            propOIDs.append(mapstr2);
                            
			            propValue.clear();
                                    propValue = prop.getValue().toString();
			            propVALUEs.append(propValue);
                            
			            mapstr2 = mapstr1.subString(mapstr1.find("|")+2);
                                    mapstr2 = mapstr2.subString(0, mapstr2.size()-1);
			            propTYPEs.append(mapstr2);
                                }
		            }
		        }
	            }
                }
            }
        }

        // Collected complete data in arrays and ready to send the trap.
        // trap destination and SNMP type are defined in handlerInstance
        // and passing this instance as it is to deliverTrap() call

#ifdef HPUX_EMANATE
        static snmpDeliverTrap_emanate emanateTrap;
#else
        static snmpDeliverTrap_stub emanateTrap;
#endif

        Uint32 targetHostPos = handler.findProperty(CIMName ("TargetHost"));
        Uint32 targetHostFormatPos = handler.findProperty(CIMName ("TargetHostFormat"));
        Uint32 otherTargetHostFormatPos = handler.findProperty(CIMName (
				      "OtherTargetHostFormat"));
        Uint32 portNumberPos = handler.findProperty(CIMName ("PortNumber"));
        Uint32 snmpVersionPos = handler.findProperty(CIMName ("SNMPVersion"));
        Uint32 securityNamePos =  handler.findProperty(CIMName ("SNMPSecurityName"));
        Uint32 engineIDPos =  handler.findProperty(CIMName ("SNMPEngineID"));

        if ((targetHostPos != PEG_NOT_FOUND) &&
            (targetHostFormatPos != PEG_NOT_FOUND) && 
            (snmpVersionPos != PEG_NOT_FOUND) && 
            (indicationClass.findQualifier(CIMName ("MappingStrings")) != 
                PEG_NOT_FOUND))
        {
    	    // properties from the handler instance
            String targetHost;
	    String otherTargetHostFormat = String();
	    String securityName = String();
	    String engineID = String();
	    Uint16 targetHostFormat = 0;
	    Uint16 snmpVersion = 0;
	    Uint32 portNumber;

	    String trapOid;
	    //
            //  Get snmpTrapOid from context
            //
	    try
	    {
                SnmpTrapOidContainer trapContainer = context.get
                    (SnmpTrapOidContainer::NAME);

                trapOid = trapContainer.getSnmpTrapOid();
	    }
	    catch (Exception& e)
            {
	        // get trapOid from indication Class

	        Uint32 pos = indicationClass.findQualifier(CIMName ("MappingStrings"));
	        if (pos != PEG_NOT_FOUND)
	        {
	            trapOid = indicationClass.getQualifier(pos).getValue().toString();

		    trapOid = trapOid.subString(11, PEG_NOT_FOUND);

                    if ((String::compare(trapOid, "SNMP.", 5)) == 0)
                    {
                        trapOid = trapOid.subString(5, (trapOid.size()-6));
                    }
	            else
	            {
			PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
			    		 "Invalid MappingStrings Value " + trapOid);
			PEG_METHOD_EXIT();
		        // l10n
	                // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Invalid MappingStrings Value");
		        throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
						   MessageLoaderParms("Handler.snmpIndicationHandler.snmpIndicationHandler.INVALID_MS_VALUE",
								       "Invalid MappingStrings Value")); 
	            }
	        }
	        else
	        {
		    PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
		    		 "Qualifier MappingStrings can not be found.");
		    PEG_METHOD_EXIT();
	    	    //L10N_ TODO DONE
	            //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Qualifier MappingStrings can not be found");
		    MessageLoaderParms parms("Handler.snmpIndicationHandler.snmpIndicationHandler.QUALIFIER_MAPPINGS_NOT_FOUND",
								 "Qualifier MappingStrings can not be found");
		    throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, parms);
	        }
	    }

	    handler.getProperty(targetHostPos).getValue().get(targetHost);
	    handler.getProperty(targetHostFormatPos).getValue().get(targetHostFormat);
	    if (otherTargetHostFormatPos != PEG_NOT_FOUND)
	    { 
	        handler.getProperty(otherTargetHostFormatPos).getValue().get
		    (otherTargetHostFormat);
	    }
	    if (portNumberPos != PEG_NOT_FOUND)
	    {
	        handler.getProperty(portNumberPos).getValue().get(portNumber);
	    }
	    else
	    {
	        // default port
	        portNumber = SNMP_TRAP_DEFAULT_PORT;
	    }

	    handler.getProperty(snmpVersionPos).getValue().get(snmpVersion);
	    if (securityNamePos != PEG_NOT_FOUND)
	    {
	        handler.getProperty(securityNamePos).getValue().get(securityName);
	    }
	    if (engineIDPos != PEG_NOT_FOUND)
	    {
	        handler.getProperty(engineIDPos).getValue().get(engineID);
	    }

	    emanateTrap.deliverTrap(
                trapOid,
                securityName,
                targetHost,
                targetHostFormat,
	        otherTargetHostFormat,
	        portNumber,
	        snmpVersion,
	        engineID,
                propOIDs,  
                propTYPEs, 
                propVALUEs);
        }
        else
        {
	    PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
		"Invalid IndicationHandlerSNMPMapper instance.");
	    PEG_METHOD_EXIT();
          // l10n

          // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, 
          // "Invalid IndicationHandlerSNMPMapper instance");

          throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED, 
				     MessageLoaderParms("Handler.snmpIndicationHandler.snmpIndicationHandler.INVALID_SNMP_INSTANCE", 
							"Invalid IndicationHandlerSNMPMapper instance"));
        }
    } 
    catch (CIMException & c)
    {
	PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, c.getMessage()); 
	PEG_METHOD_EXIT();

	throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, c.getMessage());
    }
    catch (Exception& e)
    {
	PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, e.getMessage());
	PEG_METHOD_EXIT();

	throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, e.getMessage());
    }
    catch (...)
    {
	PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
		"Failed to deliver trap.");
	PEG_METHOD_EXIT();

	throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
		MessageLoaderParms("Handler.snmpIndicationHandler.snmpIndicationHandler.FAILED_TO_DELIVER_TRAP", 
				   "Failed to deliver trap."));
    }
}
Пример #21
0
int main(int argc, char** argv)
{

#ifdef PEGASUS_HAS_SSL
	try
	{
		String host = System::getHostName();
		Uint32 port = System::lookupPort(WBEM_HTTPS_SERVICE_NAME, WBEM_DEFAULT_HTTPS_PORT);

		//
		// Note that these files are separate from the client.pem which represents the client's truststore.
		//
		const char* pegasusHome = getenv("PEGASUS_HOME");
		String certPath = FileSystem::getAbsolutePath(pegasusHome, "clientkeystore/client_cert.pem"); 
		String keyPath = FileSystem::getAbsolutePath(pegasusHome, "clientkeystore/client_key.pem");

		PEGASUS_STD(cerr) << "certPath is " << certPath << "\n";
		PEGASUS_STD(cerr) << "keyPath is " << keyPath << "\n";

		String randPath = String::EMPTY;
#ifdef PEGASUS_SSL_RANDOMFILE
		randPath = FileSystem::getAbsolutePath(pegasusHome, PEGASUS_SSLCLIENT_RANDOMFILE);
#endif

		CIMClient client;

		client.connect(
					  host, 
					  port,
					  SSLContext("", certPath, keyPath, NULL, randPath),
					  String::EMPTY, 
					  String::EMPTY);

		//
		// Do a generic call.  We have to do this call to test whether or not we get 401'ed.
		//
		CIMClass cimClass = client.getClass(
										   CIMNamespaceName("root/cimv2"), 
										   CIMName ("CIM_ManagedElement"),
										   true,
										   false,
										   false,
										   CIMPropertyList());

		client.disconnect();

	} catch (Exception& e)
	{
		PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
		PEGASUS_STD(cerr) << "Root cause could be PEGASUS_HAS_SSL is defined but enableHttpsConnection=false" << PEGASUS_STD(endl);
		exit(1);  
	}

	PEGASUS_STD(cout) << "+++++ passed all tests" << PEGASUS_STD(endl);

	return 0;

#endif

	//
	// This returns a false positive result.
	// But we should never get here since this test is only run if PEGASUS_HAS_SSL is defined.
	//

	return 0;
}
Пример #22
0
//
// List of all the CIM Operations
//
// Note: The following tables contain all the existing CIM Operations.
//       Any new CIM Operations created must be included in one of these tables,
//       otherwise no CIM requests will have authorization to execute those
//       new operations.
//

//
// List of read only CIM Operations
//
static const CIMName READ_OPERATIONS [] =
{
    CIMName("GetClass"),
    CIMName("GetInstance"),
    CIMName("EnumerateClassNames"),
    CIMName("References"),
    CIMName("ReferenceNames"),
    CIMName("AssociatorNames"),
    CIMName("Associators"),
    CIMName("EnumerateInstanceNames"),
    CIMName("GetQualifier"),
    CIMName("EnumerateQualifiers"),
    CIMName("EnumerateClasses"),
    CIMName("EnumerateInstances"),
    CIMName("ExecQuery"),
    CIMName("GetProperty")
};
void UNIX_CLPSettingData::setScope(CIMName scope)
{
	currentScope = CIMName(scope.getString());
}
CIMInstance UNIX_BGPPeerGroupService::getDependent() const
{
	return CIMInstance(CIMName("CIM_Dependency"));
}
Пример #25
0
PEGASUS_NAMESPACE_BEGIN

/******************************************************************************
**
**             Option Structure object. Initialization and any other
**             used Function Definitions
**
******************************************************************************/

// Constructor - Instantiate the variables of the Option structure
OptionStruct::OptionStruct():
    isXmlOutput(false),

    deepInheritance(false),
    localOnly(true),
    includeQualifiersRequested(false),
    notIncludeQualifiersRequested(false),
    includeQualifiers(false),
    includeClassOrigin(false),

    verboseTest(false),
    summary(false),
    delay(0),
    trace(0),
    debug(false),
    sort(false),

    expectedCount(0),
    executeCountTest(false),
    repeat(0),
    time(false),
    termCondition(0),
    connectionTimeout(0),
    interactive(false),
    setRtnHostNames(false)
{
        // Initialize the option structure values
        location =  String();
#ifdef PEGASUS_HAS_SSL
        ssl = false;
        clientCert = String();
        clientKey = String();
#endif
        nameSpace = String();
        cimCmd = "unknown";
        targetObjectName = CIMObjectPath();

        outputFormatType = OUTPUT_MOF;

        user = String();
        password = String();

        assocClass = CIMName();
        resultClass = CIMName();
        role = String::EMPTY;
        resultRole = String();
        propertyList.clear();
        propertyName = String();
        methodName = CIMName("unknown");
        queryLanguage = "WQL";
        rtnHostSubstituteName = String();
}
void CIMQualifierList::resolve(
    DeclContext* declContext,
    const CIMNamespaceName & nameSpace,
    CIMScope scope, // Scope of the entity being resolved.
    Boolean isInstancePart,
    CIMQualifierList& inheritedQualifiers,
    Boolean propagateQualifiers)
{
    _keyIndex = PEGASUS_ORDEREDSET_INDEX_UNKNOWN;

    PEG_METHOD_ENTER(TRC_OBJECTRESOLUTION, "CIMQualifierList::resolve()");
    // For each qualifier in the qualifiers array, the following
    // is checked:
    //
    //     1. Whether it is declared (can be obtained from the declContext).
    //
    //     2. Whether it has the same type as the declaration.
    //
    //     3. Whether the qualifier is valid for the given scope.
    //
    //     4. Whether the qualifier can be overriden (the flavor is
    //        ENABLEOVERRIDE on the corresponding reference qualifier).
    //
    //     5. Whether the qualifier should be propagated to the subclass.
    //
    // If the qualifier should be overriden, then it is injected into the
    // qualifiers array (from the inheritedQualifiers array).

    for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++)
    {
        CIMQualifier q = _qualifiers[i];
        //----------------------------------------------------------------------
        // 1. Check to see if it's declared.
        //----------------------------------------------------------------------
        // set this back to  CIMConstQualifierDecl
        CIMQualifierDecl qd = declContext->lookupQualifierDecl(
            nameSpace, q.getName());

        if (qd.isUninitialized())
        {
            PEG_METHOD_EXIT();
            throw UndeclaredQualifier(q.getName().getString ());
        }

        //----------------------------------------------------------------------
        // 2. Check the type and isArray.  Must be the same:
        //----------------------------------------------------------------------

        if (!(q.getType() == qd.getType() && q.isArray() == qd.isArray()))
        {
            PEG_METHOD_EXIT();
            throw BadQualifierType(q.getName().getString ());
        }

        //----------------------------------------------------------------------
        // 3. If the qualifier is the EmbeddedInstance qualifier, then check
        // that the class specified by the qualifier exists in the namespace.
        //----------------------------------------------------------------------
        if (q.getName().equal(PEGASUS_QUALIFIERNAME_EMBEDDEDINSTANCE))
        {
            String className;
            q.getValue().get(className);
            CIMClass classDef = declContext->lookupClass(nameSpace,
                    CIMName(className));
            if (classDef.isUninitialized())
            {
                String embeddedInstType("EmbeddedInstance(\"");
                embeddedInstType = embeddedInstType + className + "\")";
                PEG_METHOD_EXIT();
                throw BadQualifierType(embeddedInstType);
            }
        }

        //----------------------------------------------------------------------
        // 4. Check the scope: Must be legal for this qualifier
        //----------------------------------------------------------------------
        // ATTN:  These lines throw a bogus exception if the qualifier has
        // a valid scope (such as Scope::ASSOCIATION) which is not Scope::CLASS
        // ks Mar 2002. Reinstalled 23 March 2002 to test.

        if (!(qd.getScope().hasScope (scope)))
        {
            PEG_METHOD_EXIT();
            throw BadQualifierScope
                (qd.getName().getString (), scope.toString ());
        }

        //----------------------------------------------------------------------
        // Resolve the qualifierflavor. Since Flavors are a combination of
        // inheritance and input characteristics, resolve the inherited
        // characteristics against those provided with the creation.  If
        // there is a superclass the flavor is resolved against that
        // superclass.  If not, it is resolved against the declaration. If
        // the flavor is disableoverride and tosubclass the resolved
        // qualifier value must be identical to the original
        //----------------------------------------------------------------------
        // Test for Qualifier found in SuperClass. If found and qualifier
        // is not overridable.
        // Abstract (not Overridable and restricted) can be found in subclasses
        // Can have nonabstracts below abstracts. That is function of
        // nottosubclass Association (notOverridable and tosubclass) can be
        // found in subclasses but cannot be changed. No non-associatons below
        // associations. In other words once a class becomes an association,
        // no subclass can override that definition apparently
        // Throw exception if DisableOverride and tosubclass and different
        // value.  Gets the source from superclass if qualifier exists or from
        // declaraction.
        // If we do not throw the exception, resolve the flavor from the
        // inheritance point and resolve against current input.
        // Diableoverride is defined in the CIM Spec to mean that the value
        // cannot change.
        // The other characteristics including the flavor can change
        // apparently. Thus, we need only confirm that the value is the same
        // (2.2 pp 33).  Strange since we would think that override implies
        // that you cannot override any of the characteristics (value, type,
        // flavor, etc.) This also leaves the question of NULL or no values.
        // The implication is that we must move the value from the superclass
        // or declaration.

        Uint32 index = inheritedQualifiers.find(q.getName());

        if (index == PEG_NOT_FOUND)
        {   // Qualifier does not exist in superclass
            /* If from declaration, we can override the default value.
              However, we need some way to get the value if we have a Null.
            if (!qd.getFlavor().hasFlavor(CIMFlavor::OVERRIDABLE) &&
                qd.getFlavor().hasFlavor(CIMFlavor::TOSUBCLASS))
            {
                //throw BadQualifierOverride(q.getName());
            }
            */
            // Do not allow change from disable override to enable override.
            if ((!qd.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE))
                  && (q.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE)))
            {
                PEG_METHOD_EXIT();
                throw BadQualifierOverride(q.getName().getString ());
            }

            Resolver::resolveQualifierFlavor(
                q, CIMFlavor (qd.getFlavor ()), false);
        }
        else  // qualifier exists in superclass
        {   ////// Make Const again
            CIMQualifier iq = inheritedQualifiers.getQualifier(index);
            // don't allow change override to notoverride.
            if (!(iq.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE))
                  && q.getFlavor ().hasFlavor (CIMFlavor::OVERRIDABLE))
            {
                PEG_METHOD_EXIT();
                throw BadQualifierOverride(q.getName().getString ());
            }

            if (!(iq.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE))
                  && iq.getFlavor ().hasFlavor(CIMFlavor::TOSUBCLASS))
            {
                // test if values the same.
                CIMValue qv = q.getValue();
                CIMValue iqv = iq.getValue();
                if (!(qv == iqv))
                {
                    PEG_METHOD_EXIT();
                    throw BadQualifierOverride(q.getName().getString());
                }
            }

            Resolver::resolveQualifierFlavor(
                q, CIMFlavor(iq.getFlavor()), true);
        }
    }   // end of this objects qualifier loop

    //--------------------------------------------------------------------------
    // Propagate qualifiers to subclass or to instance that do not have
    // already have those qualifiers:
    //--------------------------------------------------------------------------

    if (propagateQualifiers)
    {
        for (Uint32 i = 0, n = inheritedQualifiers.getCount(); i < n; i++)
        {
            CIMQualifier iq = inheritedQualifiers.getQualifier(i);

            if (isInstancePart)
            {
                if (!(iq.getFlavor().hasFlavor(CIMFlavor::TOINSTANCE)))
                    continue;
            }
            else
            {
                if (!(iq.getFlavor().hasFlavor(CIMFlavor::TOSUBCLASS)))
                    continue;
            }

            // If the qualifiers list does not already contain this qualifier,
            // then propagate it (and set the propagated flag to true).  Else
            // we keep current value. Note we have already eliminated any
            // possibility that a nonoverridable qualifier can be in the list.
            if (find(iq.getName()) != PEG_NOT_FOUND)
                continue;

            CIMQualifier q = iq.clone();
            q.setPropagated(true);
            _qualifiers.insert(0, q);
        }
    }
    PEG_METHOD_EXIT();
}
void _test3(CIMClient & client)
{
    static const String NAMESPACE("test/TestProvider");
    static const String CLASSNAME("cmpiPerf_TestClassA");
    cout<<"enumerate instance request with empty prop list"<<endl;
    {
        try
        {
            Array<CIMName> propNames;
            Array < CIMInstance > instances =
            client.enumerateInstances(
                NAMESPACE,
                CLASSNAME,
                true,
                true,
                false,
                false,
                CIMPropertyList(propNames) );
            for(Uint32 i=0;i<instances.size();i++)
            {
                Uint32 propertyCount = instances[i].getPropertyCount();
                if (verbose)
                {
                    XmlWriter::printInstanceElement(instances[i]);
                }
                if(propertyCount == 0)
                {
                    cout<<"Filter enumerateInstances test on "
                        <<"cmpiPerf_TestClassA SUCCEEDED :Filtering "
                        <<"the ciminstance with a empty property list "
                        <<"returned zero properties as expected"<<endl;
                }
                else
                {
                    cout<<"Filter enumerateInstances test on "
                        <<"cmpiPerf_TestClassA  FAILED:Filtering the" 
                        <<"ciminstance with a empty property list returned " 
                        <<"some properties which is not expected"<<endl;
                    //PEGASUS_TEST_ASSERT(false);
                }
            }    
        }catch (const CIMException &e)
        {
            cout << "CIMException(" << e.getCode() << "): " <<
                e.getMessage() << endl;
        }
    }
    cout<<"++++++++property list with wrong prop names"
        <<" filtered output++++++++"<<endl;
    { 
        try
        {
            Array<CIMName> propNames;
            propNames.append(CIMName(String("theK")));
            Array < CIMInstance > instances =
            client.enumerateInstances(
                NAMESPACE,
                CLASSNAME,
                true,
                true,
                false,
                false,
                CIMPropertyList(propNames) );
            for(Uint32 i=0;i<instances.size();i++)
            {
                Uint32 propertyCount = instances[i].getPropertyCount();
                if (verbose)
                {
                    XmlWriter::printInstanceElement(instances[i]);
                }
                if(propertyCount == 0)
                {
                    cout<<"Filter enumerateInstances test on "
                        <<"cmpiPerf_TestClassA SUCCEEDED :Filtering "
                        <<"the ciminstance with a wrong property list "
                        <<"returned zero properties as expected"<<endl;
                }
                else
                {
                    cout<<"Filter enumerateInstances test on "
                        <<"cmpiPerf_TestClassA FAILED:Filtering the" 
                        <<"ciminstance with a wrong property list returned "
                        <<" some properties which is not expected"<<endl;
                    PEGASUS_TEST_ASSERT(false);
                }
            }
        }catch (const CIMException &e)
        {
            cout << "CIMException(" << e.getCode() << "): " <<
                e.getMessage() << endl;   
        }
    }
    cout<<"++++++++property list with mentioned property names"
            <<" filtered output++++++++"<<endl;
    {
        try
        {
            Array<CIMName> propNames;
            propNames.append(CIMName(String("theKey")));
            Array < CIMInstance > instances =
            client.enumerateInstances (
                NAMESPACE,
                CLASSNAME,
                true,
                true,
                false,
                false,
                CIMPropertyList(propNames) );
            for(Uint32 i=0;i<instances.size();i++)
            {
                Uint32 propertyCount = instances[i].getPropertyCount();
                Uint32 propNameCount = 0;
                if (verbose)
                {
                    XmlWriter::printInstanceElement(instances[i]);
                }
                for(Uint32 j=0;j<propertyCount;j++)
                {
                    String propName=
                        instances[i].getProperty(j).getName().getString();
                    if((propName == "theKey") )
                    {
                       propNameCount++;
                    }
                }
                if((propertyCount == 1)&&(propNameCount == 1))
                {
                    cout<<"Filter enumerateInstances test on "
                        <<"cmpiPerf_TestClassA SUCCEEDED :Filtering "
                        <<"the ciminstance with a mentioned property list "
                        <<"returned all properties as expected"<<endl;
                }
                else
                {
                    cout<<"Filter enumerateInstances test on "
                        <<"cmpiPerf_TestClassA FAILED:Filtering the "
                        <<"ciminstance with a mentioned property list did " 
                        <<"not return all properties as expected"<<endl;
                    PEGASUS_TEST_ASSERT(false);
                }
            }
        }catch (const CIMException &e)
        {
            cout << "CIMException(" << e.getCode() << "): " <<
                e.getMessage() << endl;
        }
    }
    cout<<"++++++++NULL proplist filtered output++++++++"<<endl;
    {
        try
        {
            Array < CIMInstance > instances =
            client.enumerateInstances(
                NAMESPACE,
                CLASSNAME,
                true,
                true,
                false,
                false,
                CIMPropertyList());
            for(Uint32 i=0;i<instances.size();i++)
            {
                Uint32 propertyCount = instances[i].getPropertyCount();
                if (verbose)
                {
                    XmlWriter::printInstanceElement(instances[i]);
                    cout<<"i::"<<i<<endl;
                }
                if(propertyCount == 24)
                {
                    cout<<"Filter enumerateInstances test on "
                        <<"cmpiPerf_TestClassA SUCCEEDED :Filtering "
                        <<"the ciminstance with a NULL property list "
                        <<"returned all properties as expected"<<endl;
                }
                else
                {
                    cout<<"Filter enumerateInstances test on "
                        <<"cmpiPerf_TestClassA FAILED:Filtering the "
                        <<"ciminstance with a NULL property list did not "
                        <<"return all properties as expected"<<endl;
                    PEGASUS_TEST_ASSERT(false);
                }
            }
        }catch (const CIMException &e)
        {
            cout << "CIMException(" << e.getCode() << "): " <<
                e.getMessage() << endl;
        }
    }
}
void UNIX_BGPIPRoute::setScope(CIMName scope)
{
	currentScope = CIMName(scope.getString());
}
CIMInstance UNIX_CardOnCard::getPartComponent() const
{
	return CIMInstance(CIMName("CIM_Component"));
}
Пример #30
0
//
// Initialize the namespaces so that all namespaces with the
// CIM_ElementConformsToProfile class also have the
// PG_ElementConformsToProfile class. Needed in order to implement
// the cross-namespace ElementConformsToProfile association in both
// directions.
//
void InteropProvider::initializeNamespaces()
{
    Array<CIMNamespaceName> namespaceNames =  repository->enumerateNameSpaces();
    // get the PG_ElementConformstoProfile class without the qualifiers
    // and then add just the required ASSOCIATION qualifier, so that
    // resolveclass doesn't fail for the test/EmbeddedInstance/Dynamic
    // namespace, which uses the CIM25 schema that doesn't include any
    // of the new qualifiers added to this class in later versions of
    // the CIMSchema.
    CIMClass conformsClass = repository->getClass(
                                 PEGASUS_NAMESPACENAME_INTEROP,
                                 PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE,
                                 true,
                                 false);
    conformsClass.addQualifier(
        CIMQualifier(CIMName("ASSOCIATION"), CIMValue(true)));
    CIMClass profileClass = repository->getClass(
                                PEGASUS_NAMESPACENAME_INTEROP,
                                PEGASUS_CLASSNAME_PG_REGISTEREDPROFILE,
                                true,
                                false);
    for(Uint32 i = 0, n = namespaceNames.size(); i < n; ++i)
    {
        // Check if the PG_ElementConformsToProfile class is present
        CIMNamespaceName & currentNamespace = namespaceNames[i];
        CIMClass tmpCimClass;
        CIMClass tmpPgClass;
        CIMClass tmpPgProfileClass;
        try
        {
            // Look for these classes in the same try-block since the
            // second depends on the first
            tmpCimClass = repository->getClass(
                              currentNamespace,
                              PEGASUS_CLASSNAME_CIM_ELEMENTCONFORMSTOPROFILE);
            tmpPgClass = repository->getClass(
                             currentNamespace,
                             PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE);
        }
        catch(const Exception &)
        {
        }
        try
        {
            tmpPgProfileClass = repository->getClass(
                                    currentNamespace,
                                    PEGASUS_CLASSNAME_PG_REGISTEREDPROFILE);
        }
        catch(const Exception &)
        {
            // Note: if any of the above three classes aren't found,
            // an exception will be thrown, which we can ignore since it's
            // an expected case
            // TBD: Log trace message?
        }

        // If the CIM_ElementConformsToProfile class is present, but
        // the PG_ElementConformsToProfile or PG_RegisteredProfile
        // class is not, then add it to that namespace.
        //
        // Note that we don't have to check for the
        // CIM_RegisteredProfile class because if the
        // CIM_ElementConformsToProfile class is present, the
        // CIM_RegisteredProfile class must also be present.
        if(!tmpCimClass.isUninitialized())
        {
            if(tmpPgClass.isUninitialized())
            {
                CIMClass newclass = conformsClass.clone();
                CIMObjectPath newPath = conformsClass.getPath();
                newPath.setNameSpace(currentNamespace);
                newclass.setPath(newPath);
                repository->createClass(
                    currentNamespace,
                    newclass);
            }
            if(tmpPgProfileClass.isUninitialized())
            {
                CIMClass newclass = profileClass.clone();
                CIMObjectPath newPath = profileClass.getPath();
                newPath.setNameSpace(currentNamespace);
                newclass.setPath(newPath);
                repository->createClass(
                    currentNamespace,
                    newclass);
            }
        }
    }
}