const CIMPropertyList WQLSelectStatementRep::getSelectPropertyList(
    const CIMObjectPath& inClassName) const
{
    //
    //  Check for "*"
    //
    if (_allProperties)
    {
        //
        //  Return null CIMPropertyList for all properties
        //
        return CIMPropertyList ();
    }

    CIMName className = inClassName.getClassName();
    if (className.isNull())
    {
        //
        //  If the caller passed in an empty className, then the FROM class is
        //  to be used
        //
        className = _className;
    }

    //
    //  Check if inClassName is the FROM class
    //
    if (!(className == _className))
    {
        //
        //  Check for NULL Query Context
        //
        if (_ctx == NULL)
        {
            MessageLoaderParms parms
                ("WQL.WQLSelectStatementRep.QUERY_CONTEXT_IS_NULL",
                "Trying to process a query with a NULL Query Context.");
            throw QueryRuntimeException(parms);
        }

        //
        //  Check if inClassName is a subclass of the FROM class
        //
        if (!_ctx->isSubClass(_className,className))
        {
            MessageLoaderParms parms
                ("WQL.WQLSelectStatementRep.CLASS_NOT_FROM_LIST_CLASS",
                "Class $0 does not match the FROM class or any of its "
                "subclasses.",
                className.getString());
            throw QueryRuntimeException(parms);
        }
    }

    //
    //  Return CIMPropertyList for properties referenced in the projection
    //  list (SELECT clause)
    //
    return CIMPropertyList (_selectPropertyNames);
}
CIMPropertyList WQLSelectStatementRep::getPropertyList(
        const CIMObjectPath& inClassName)
{
    if(_ctx == NULL){
        MessageLoaderParms parms(
            "WQL.WQLSelectStatementRep.QUERY_CONTEXT_IS_NULL",
            "Trying to process a query with a NULL Query Context.");
      throw QueryRuntimeException(parms);
    }

    if(_allProperties)
     return CIMPropertyList();

    CIMName className = inClassName.getClassName();
    if (className.isNull())
    {
     // If the caller passed in an empty className, then the
     // FROM class is to be used.
     className = _className;
    }

    // check if inClassName is the From class
    if(!(className == _className)){
        // check if inClassName is a subclass of the From class
        if(!_ctx->isSubClass(_className,className)){
            MessageLoaderParms parms(
                "WQL.WQLSelectStatementRep.CLASS_NOT_FROM_LIST_CLASS",
                "Class $0 does not match the FROM class or any of its"
                    " subclasses.",
                className.getString());
            throw QueryRuntimeException(parms);
        }
    }

    Array<CIMName> names =
            getWherePropertyList(inClassName).getPropertyNameArray();
    Array<CIMName> selectList =
            getSelectPropertyList(inClassName).getPropertyNameArray();

    // check for duplicates and remove them
    for(Uint32 i = 0; i < names.size(); i++){
        for(Uint32 j = 0; j < selectList.size(); j++){
            if(names[i] == selectList[j])
                selectList.remove(j);
            }
    }

    names.appendArray(selectList);
    CIMPropertyList list = CIMPropertyList();
    list.set(names);
    return list;
}
Пример #3
0
// Constructor
testEnumSequence::testEnumSequence(CIMClient& client, const char*nameSpace):
    _nameSpace(nameSpace),
    _className(),
    _cimObjectName(),
    _deepInheritance(true),
    _includeClassOrigin(false),
    _operationTimeout(25),
    _continueOnError(false),
    _maxObjectCount(100),

    _filterQueryLanguage(""),
    _filterQuery(""),

    _role(""),
    _resultRole(""),
    _assocClass(CIMName()),
    _resultClass(CIMName()),

    _cimPropertyList(CIMPropertyList()),
    _client(client),
    _expectGoodReturn(true),
    _expectedCIMExceptionCode(CIM_ERR_SUCCESS),
    _expectedCIMExceptionMessage(""),
    _returnedCIMExceptionCode(CIM_ERR_SUCCESS),
    _testName("unknown"),
    _operationName("unknown")
{}
Пример #4
0
CIMClass* mbGetClass(const CMPIBroker *mb, const CIMObjectPath &cop) {
   DDD(cout<<"--- mbGetClass()"<<endl);
   mb=CM_BROKER;
   CMPI_Broker *xBroker=(CMPI_Broker*)mb;
   String clsId=cop.getNameSpace().getString()+":"+cop.getClassName().getString();
   CIMClass *ccp;

   AutoMutex mtx(((CMPI_Broker*)mb)->mtx);
   if (xBroker->clsCache) {
      if (xBroker->clsCache->lookup(clsId,ccp)) return ccp;
   }
   else xBroker->clsCache=new ClassCache();

   try {
      CIMClass cc=CM_CIMOM(mb)->getClass(
                  OperationContext(),
		  cop.getNameSpace(),
		  cop.getClassName(),
		  (bool)0,
		  (bool)1,
		  (bool)0,
		  CIMPropertyList());
      ccp=new CIMClass(cc);
      xBroker->clsCache->insert(clsId,ccp);
      return ccp;
   }
   catch (const CIMException &e) {
      DDD(cout<<"### exception: mbGetClass - code: "<<e.getCode()<<" msg: "<<e.getMessage()<<endl);
   }
   return NULL;
}
Пример #5
0
Array<CIMObjectPath> PG_TestPropertyTypes::_enumerateInstanceNames(
    const OperationContext& context,
    const CIMObjectPath& classReference)
{
    Array<CIMObjectPath> instanceNames;

    // get class definition from repository
    CIMClass cimclass = _cimom.getClass(
        context,
        classReference.getNameSpace(),
        classReference.getClassName(),
        false,
        true,
        true,
        CIMPropertyList());

    // convert instances to references;
    for (Uint32 i = 0; i < _instances.size(); i++)
    {
        CIMObjectPath tempRef = _instances[i].buildPath(cimclass);

        // ensure references are fully qualified
        tempRef.setHost(classReference.getHost());
        tempRef.setNameSpace(classReference.getNameSpace());

        instanceNames.append(tempRef);
    }

    return instanceNames;
}
Пример #6
0
PEGASUS_NAMESPACE_BEGIN


const CIMPropertyList FQLQueryExpressionRep::getPropertyList() const
{
   PEGASUS_ASSERT(false);
   return CIMPropertyList();
}
Пример #7
0
/*
    Build an instance of the test class
*/
CIMInstance buildInstance(CIMClient& client, String& instanceId)
{
    CIMClass cl = client.getClass(PROVIDERNS, TEST_CLASS);
    CIMInstance inst = cl.buildInstance(false, false, CIMPropertyList());
    setPropertyValue(inst, "Id", CIMValue(instanceId));

    return inst;
}
Пример #8
0
void testClearMethod()
{
    // Test with a variety of object types in the From ResponseData
    // Build the class
    CIMClass CIMclass1 = buildClass();

    // Build a CIM Instance. NOTE: key is defaulted in class

    CIMInstance CIMInst1 = CIMclass1.buildInstance(true, true,
                                                   CIMPropertyList());

        // Clone the instance and change key
    CIMInstance CIMInst2 = CIMInst1.clone();
    setPropertyValue(CIMInst2, "id", 2);

    CIMInstance CIMInst3 = CIMInst1.clone();
    setPropertyValue(CIMInst3, "id", 3);
    CIMInstance CIMInst4 = CIMInst1.clone();
    setPropertyValue(CIMInst4, "id", 4);

    // build CIMInstance array
    Array<CIMInstance> CIMInstArray;
    CIMInstArray.append(CIMInst1);
    CIMInstArray.append(CIMInst2);
    CIMInstArray.append(CIMInst3);
    CIMInstArray.append(CIMInst4);

    // Create CIMReponseData object
    CIMResponseData crd = CIMResponseData(CIMResponseData::RESP_INSTANCES);

    // Append an array of CIMInstances
    crd.appendInstances(CIMInstArray);
    PEGASUS_TEST_ASSERT(crd.size() == 4);

    // Build SCMO instances
    SCMOClass SCMO_CSClass(CIMclass1);

    VCOUT << "Creating SCMOInstance from CIMInstance" << endl;
    SCMOInstance SCMO_CSInstance3(SCMO_CSClass,CIMInst3);
    SCMOInstance SCMO_CSInstance4(SCMO_CSClass,CIMInst4);

    // Create array of 2 SCMO Instances
    Array<SCMOInstance> SCMOInstArray;
    SCMOInstArray.append(SCMO_CSInstance3);
    SCMOInstArray.append(SCMO_CSInstance4);
    crd.appendSCMO(SCMOInstArray);

    PEGASUS_TEST_ASSERT(crd.size() == 6);

    crd.clear();

    PEGASUS_TEST_ASSERT(crd.size() == 0);
}
Пример #9
0
static Array<CIMInstance> _getDestinationQueues(CIMClient &client)
{
    return client.enumerateInstances(
        "root/PG_Internal",
        "PG_ListenerDestinationQueue",
        false,
        false,
        false,
        false,
        CIMPropertyList());

}
Пример #10
0
/////////////////////////////////////////////////////////////////////////////
// WMIInstanceProvider::getProperty
//
// ///////////////////////////////////////////////////////////////////////////
CIMValue WMIInstanceProvider::getProperty(
        const String& nameSpace,
        const String& userName,
        const String& password,
        const CIMObjectPath& instanceName,
        const String& propertyName)
{

    CIMInstance cimInstance;
    Array<CIMName> propertyNames;

    PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMIInstanceProvider::getProperty()");

    setup(nameSpace,userName,password);

    if (!m_bInitialized)
    {
        throw CIMException(CIM_ERR_FAILED, "[getProperty] m_bInitialized");
    }

    CIMName propName = propertyName;

    propertyNames.append(propName);

    CIMPropertyList propertyList = CIMPropertyList(propertyNames);

    // get the relevant CIMInstance object
    cimInstance = getCIMInstance(nameSpace,
                                 userName,
                                 password,
                                 instanceName,
                                 propertyList);

    // now fetch the property
    Uint32 pos = cimInstance.findProperty(propName);

    if (PEG_NOT_FOUND == pos)
    {
        throw CIMException(CIM_ERR_NO_SUCH_PROPERTY,
            "[getProperty] findproperty");
    }

    CIMProperty property = cimInstance.getProperty(pos);

    // and return the value
    CIMValue value = property.getValue();

    PEG_METHOD_EXIT();

    return value;
}
Пример #11
0
CIMClass compilerDeclContext::lookupClass(const CIMNamespaceName &nameSpace,
                 const CIMName &className) const
{
    const CIMClass *pTheClass;

    if (_ot != compilerCommonDefs::USE_REPOSITORY) {
        if ( (pTheClass =_findClassInMemory(className)) )
            return *pTheClass;
    }
    if (_repository && _ot != compilerCommonDefs::IGNORE_REPOSITORY) {
        return _repository->_getClass(
                nameSpace, className, false, true, true, CIMPropertyList());
    }
    return CIMClass();
}
Пример #12
0
//
// Builds an instance of the class named className. Gets Class defintion and
// fills in the correct properties from the class.  This requires a repository
// getClass request for each instance built. The skeleton is built by
// creating the instance and copying qualifiers and properties from
// the class. Finally the instance is cloned to separate it from the
// original objects.
// NOTE: This is very inefficient for anything larger than a few instances.
// We should separate the get from the createSkeleton.
// @param className CIMName of the class for which the instance is to be built
// @return CIMInstance of this class with properties complete.
// @exception passes on any exceptions received from the repository request.
//
CIMInstance InteropProvider::buildInstanceSkeleton(
      const CIMNamespaceName & nameSpace,
      const CIMName& className,
      Boolean includeQualifiers,
      CIMClass& returnedClass)
{
    PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
        "InteropProvider::_buildInstanceSkeleton()");
    // get class with lo = false, qualifier = true classorig = true
    returnedClass = repository->getClass(nameSpace,
        className, false, true, true);
    CIMInstance skeleton = returnedClass.buildInstance(
        includeQualifiers, true, CIMPropertyList());

    PEG_METHOD_EXIT();
    return skeleton;
}
Пример #13
0
void PG_TestPropertyTypes::enumerateInstances(
    const OperationContext& context,
    const CIMObjectPath& ref,
    const Boolean includeQualifiers,
    const Boolean includeClassOrigin,
    const CIMPropertyList& propertyList,
    InstanceResponseHandler& handler)
{

    // ensure the Namespace is valid
    if (!ref.getNameSpace().equal ("test/static"))
    {
        throw CIMException(CIM_ERR_INVALID_NAMESPACE);
    }

    // ensure the class existing in the specified namespace
    if (!ref.getClassName().equal ("PG_TestPropertyTypes"))
    {
        throw CIMException(CIM_ERR_INVALID_CLASS);
    }

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

    // NOTE: It would be much more efficient to remember the instance names

    // get class definition from repository
    CIMClass cimclass = _cimom.getClass(
        context,
        ref.getNameSpace(),
        ref.getClassName(),
        false,
        true,
        true,
        CIMPropertyList());

    for (Uint32 i = 0; i < _instances.size(); i++)
    {
        handler.deliver(_instances[i]);
    }

    // complete processing the request
    handler.complete();
}
Пример #14
0
SCMOClass CIMServer::_scmoClassCache_GetClass(
    const CIMNamespaceName& nameSpace,
    const CIMName& className)
{
    CIMClass cc;

    PEG_METHOD_ENTER(TRC_SERVER, "CIMServer::_scmoClassCache_GetClass()");
    try
    {
        cc = _cimserver->_repository->getClass(
            nameSpace,
            className,
            false, // localOnly
            true, // includeQualifiers
            true, // includeClassOrigin
            CIMPropertyList());
    }
    catch (Exception& e)
    {
        PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL2,
                   "The class '%s' in the name space '%s' was not found. "
                       "The repository throws the following exception: %s",
                   (const char*)className.getString().getCString(),
                   (const char*)nameSpace.getString().getCString(),
                   (const char*)e.getMessage().getCString()));
        // Return a empty class.
        PEG_METHOD_EXIT();
        return SCMOClass("","");
    }

    if (cc.isUninitialized())
    {
        // The requested class was not found !
        // Return a empty class.
        PEG_METHOD_EXIT();
        return SCMOClass("","");
    }
    PEG_METHOD_EXIT();
    return SCMOClass(cc,(const char*)nameSpace.getString().getCString());

}
Пример #15
0
/*****************************************************************************
 *
 * Implementation of InstanceProvider enumerateInstanceNames method
 *
 *****************************************************************************/
void InteropProvider::enumerateInstanceNames(
    const OperationContext & context,
    const CIMObjectPath & classReference,
    ObjectPathResponseHandler & handler)
{
    PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
        "InteropProvider::enumerateInstanceNames()");

    initProvider();

    PEG_TRACE((TRC_CONTROLPROVIDER, Tracer::LEVEL4,
        "%s enumerateInstanceNames. classReference= %s",
        thisProvider,
        (const char *) classReference.toString().getCString()));

    // test for legal namespace for this provider. Exception if not
    // namespaceSupported(classReference);
    // NOTE: Above is commented out because the routing tables will always
    // do the right thing and that's the only way requests get here.

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

    // Utilize the local enumeration method to retrieve the instances and
    // extract the instance names.
    Array<CIMInstance> instances = localEnumerateInstances(
        context,
        classReference,
        CIMPropertyList());

    for (Uint32 i = 0 ; i < instances.size() ; i++)
    {
        handler.deliver(instances[i].getPath());
    }

    handler.complete();
    PEG_METHOD_EXIT();
}
/*****************************************************************************
 *
 * Implementation of AssociationProvider associatorNames method
 *
 *****************************************************************************/
void InteropProvider::associatorNames(
    const OperationContext & context,
    const CIMObjectPath & objectName,
    const CIMName & associationClass,
    const CIMName & resultClass,
    const String & role,
    const String & resultRole,
    ObjectPathResponseHandler & handler)
{
    PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
        "InteropProvider::associatorNames()");
    initProvider();
    PEG_TRACE((TRC_CONTROLPROVIDER, Tracer::LEVEL4,
        "%s associatorNames.objectName= %s, assocClass= %s resultClass= %s "
            "role= %s resultRole = %s",
        thisProvider,
        (const char *)objectName.toString().getCString(),
        (const char *)associationClass.getString().getCString(),
        (const char *)resultClass.getString().getCString(),
        (const char *)role.getCString(),
        (const char *)resultRole.getCString()));

    handler.processing();
    String originRole = role;
    String targetRole = resultRole;
    Uint32 numIterations = 1;
    //
    // The localReferences call retrieves instances of the desired association
    // class and sets the originRole and targetRole properties if currently
    // empty.
    //
    if (associationClass.equal(PEGASUS_CLASSNAME_PG_REFERENCEDPROFILE))
    {
        if (originRole.size() == 0 && targetRole.size() == 0)
        {
            originRole = String("Antecedent");
            targetRole = String("Dependent");
            numIterations = 2;
        }
    }
    for (Uint32 i = 0; i < numIterations; ++i)
    {
        Array<CIMInstance> refs = localReferences(
            context,
            objectName,
            associationClass,
            originRole,
            targetRole,
            CIMPropertyList(),
            resultClass);
        for (Uint32 j = 0, n = refs.size(); j < n; ++j)
        {
            CIMInstance & currentRef = refs[j];
            CIMObjectPath currentTarget = getRequiredValue<CIMObjectPath>(
                currentRef,
                targetRole);
            handler.deliver(currentTarget);
        }
        if (numIterations == 2)
        {
            originRole = String("Dependent");
            targetRole = String("Antecedent");
        }
    }
    handler.complete();
    PEG_METHOD_EXIT();
}
Пример #17
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;
    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 &&
             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);
          tmpInstance = localGetInstance(
              context, 
              objectName,
              propertyList);
          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;
          }
          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;
}
Пример #18
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;
}
Пример #19
0
/*
    Execute a defined query and return the instances found
*/
void testEnumerate(
    CIMClient& client,
    const String& query,
    Uint32 testCount,
    CIMStatusCode expectedError = CIM_ERR_SUCCESS)
{
    Array<CIMInstance> pulledInstances;
    Boolean endOfSequence = false;
    CIMEnumerationContext enumerationContext;

    try
    {
        pulledInstances = client.openEnumerateInstances(
            enumerationContext,
            endOfSequence,
            PROVIDERNS,
            TEST_CLASS,
            true,
            false,
            CIMPropertyList(),
            "DMTF:FQL",
            query,
            30,
            false,
            10);

        if (expectedError != CIM_ERR_SUCCESS)
        {
            cout << "ERROR. Error code expected but good response receied."
                << endl;
        }
    }
    catch (CIMException& e)
    {
        if (e.getCode() == expectedError)
        {
            VCOUT << "Error caught correctly. " << e.getCode() << endl;
            return;
        }
        else
        {
            cout << "Error Rtn expected but Incorrect code received"
                 << " Query " << query << endl;
            exit(1);
        }
    }
    while (!endOfSequence)
    {
        Array<CIMInstance> cimInstancesPulled = client.pullInstancesWithPath(
        enumerationContext,
        endOfSequence,
        10);
        pulledInstances.appendArray(cimInstancesPulled);
    }
    if (testCount != pulledInstances.size())
    {
        cout << "Incorrect Count returned. Expected " << testCount
             << " Received " << pulledInstances.size()
             << " Query " << query
             << endl;
        exit(1);
    }
    else
    {
        return;
    }
}
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 _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 _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);
            }
        }
    } 
}
//
// Enumerates all of the ElementConformsToProfile association instances.
//
Array<CIMInstance> InteropProvider::enumElementConformsToProfileInstances(
    const OperationContext & opContext, const CIMNamespaceName & opNamespace)
{
    CIMClass elementConformsClass = repository->getClass(
        PEGASUS_NAMESPACENAME_INTEROP,
        PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE,
        false, true, false);

    AutoMutex holder(interopMut);
    Array<CIMInstance> instances;
    verifyCachedInfo();
    // Loop through the cached profile Id's and related info about its
    // conforming elements.
    for (Uint32 i = 0, n = profileIds.size(); i < n; ++i)
    {
        String & profileId = profileIds[i];
        Array<CIMName> & elementList = conformingElements[i];
        Array<CIMNamespaceName> & namespaceList = elementNamespaces[i];
        Array<CIMObjectPath> conformingElementPaths;
        for (Uint32 j = 0, m = elementList.size(); j < m; ++j)
        {
            CIMName & currentElement = elementList[j];
            CIMNamespaceName & currentNamespace = namespaceList[j];

            if (opNamespace == PEGASUS_NAMESPACENAME_INTEROP ||
                opNamespace == currentNamespace)
            {
                String currentElementStr(currentElement.getString());
                if (currentElementStr.find(PEGASUS_DYNAMIC) == 0)
                {
                    // If the provider profile registration did not provide a
                    // list of conforming elements (presumably because there is
                    // no such definite list), then the provider is required
                    // to provide instances of ElementConformsToProfile in the
                    // vendor namespace, so we do not generate instances.
                    if (opNamespace != PEGASUS_NAMESPACENAME_INTEROP)
                    {
                        continue;
                    }
                    CIMName subclassName(
                        currentElementStr.subString(PEGASUS_DYNAMIC_LEN));
                    Array<CIMInstance> elementConformsInstances =
                        cimomHandle.enumerateInstances(opContext,
                        currentNamespace, subclassName, true, false, false,
                        true, CIMPropertyList());

                    // Retrieve the Conforming Element
                    for (Uint32 k = 0, x = elementConformsInstances.size();
                        k < x; ++k)
                    {
                        CIMInstance & currentInstance =
                            elementConformsInstances[k];

                        // NOCHKSRC
                        // Make sure that the current instance points to the
                        // current profile ID.
                        CIMObjectPath profilePath =
                            getRequiredValue<CIMObjectPath>(
                                elementConformsInstances[k],
                                ELEMENTCONFORMSTOPROFILE_PROPERTY_CONFORMANTSTANDARD);
                        // DOCHKSRC
                        const Array<CIMKeyBinding> & keys =
                            profilePath.getKeyBindings();
                        if (keys.size() != 1)
                            continue;
                        if (keys.size() == 1 && keys[0].getValue() == profileId)
                        {
                            // NOCHKSRC
                            conformingElementPaths.append(
                                getRequiredValue<CIMObjectPath>(
                                currentInstance,
                                ELEMENTCONFORMSTOPROFILE_PROPERTY_MANAGEDELEMENT));
                            // DOCHKSRC
                        }
                    }
                }
                else
                {
                    // All of the instances of the current element in the
                    // corresponding namespace conform to the current profile.
                    Array<CIMObjectPath> paths =
                        cimomHandle.enumerateInstanceNames(opContext,
                            currentNamespace, currentElement);
                    // Set the namespace in the paths just in case
                    for (Uint32 k = 0, x = paths.size();
                        k < x; ++k)
                    {
                        CIMObjectPath & curPath = paths[k];
                        curPath.setNameSpace(currentNamespace);
                        curPath.setHost(hostName);
                    }
                    conformingElementPaths.appendArray(paths);
                }
            }
        }

        // Create the object path for the RegisteredProfile using the given
        // profileId.
        CIMObjectPath profilePath = buildDependencyReference(
            hostName, profileIds[i], PEGASUS_CLASSNAME_PG_REGISTEREDPROFILE);

        // Build all of the ElementConformsToProfile instances for the current
        // profile.
        for (Uint32 k = 0, x = conformingElementPaths.size(); k < x; ++k)
        {
            instances.append(buildElementConformsToProfile(profilePath,
                conformingElementPaths[k], elementConformsClass));
        }
    }

    // Now add the default instance: the association between the Server Profile
    // and the ObjectManager (if we're in the Interop namespace)
    if (opNamespace == PEGASUS_NAMESPACENAME_INTEROP)
    {
        // Build up the Object Path for the server profile version 1.1.0
        CIMObjectPath serverProfile = buildDependencyReference(
            hostName,
            buildProfileInstanceId(SNIA_NAME, "Server", SNIA_VER_110),
            PEGASUS_CLASSNAME_PG_REGISTEREDPROFILE);
        // Retrieve the Object Manager instance
        CIMInstance objManager = getObjectManagerInstance();

        instances.append(
            buildElementConformsToProfile(
                serverProfile,
                objManager.getPath(), 
                elementConformsClass));

        // Build up the Object Path for the server profile ver 1.2.0
        // and add the elementconformstoprofile association instance
        serverProfile = buildDependencyReference(
            hostName,
            buildProfileInstanceId(SNIA_NAME, "Server", SNIA_VER_120),
            PEGASUS_CLASSNAME_PG_REGISTEREDPROFILE);
        instances.append(
            buildElementConformsToProfile(
                serverProfile,
                objManager.getPath(), 
                elementConformsClass));
        
    }
    return instances;
}
Пример #24
0
void PG_TestPropertyTypes::getInstance(
    const OperationContext& context,
    const CIMObjectPath& instanceReference,
    const Boolean includeQualifiers,
    const Boolean includeClassOrigin,
    const CIMPropertyList& propertyList,
    InstanceResponseHandler& handler)
{
    // synchronously get references
    //Get extra instance created for testing negative realValues.
    Array<CIMObjectPath> references =
        _enumerateInstanceNames(context, instanceReference);

    // ensure the InstanceId key is valid
    Array<CIMKeyBinding> keys = instanceReference.getKeyBindings();
    Uint32 i;
    for (i=0; i<keys.size() && !keys[i].getName().equal("InstanceId"); i++);

    if (i==keys.size())
    {
        throw CIMException(CIM_ERR_INVALID_PARAMETER);
    }

    // ensure the Namespace is valid
    if (!instanceReference.getNameSpace().equal ("test/static"))
    {
        throw CIMException(CIM_ERR_INVALID_NAMESPACE);
    }

    // ensure the class existing in the specified namespace
    if (!instanceReference.getClassName().equal ("PG_TestPropertyTypes"))
    {
        throw CIMException(CIM_ERR_INVALID_CLASS);
    }
        Boolean testRealValue = false;
    // ensure the request object exists
    Uint32 index = findObjectPath(references, instanceReference);
    if (index == PEG_NOT_FOUND)
    {
        CIMClass cimclass = _cimom.getClass(
            context,
            instanceReference.getNameSpace(),
            instanceReference.getClassName(),
            false,
            true,
            true,
            CIMPropertyList());
        CIMObjectPath tempRef = realValueTestInstance.buildPath(cimclass);
        tempRef.setHost(instanceReference.getHost());
        tempRef.setNameSpace(instanceReference.getNameSpace());
        if (instanceReference != tempRef)
        {
            throw CIMException(CIM_ERR_NOT_FOUND);
        }
        testRealValue = true;
    }

    // begin processing the request
    handler.processing();
    if (testRealValue)
    {
        handler.deliver(realValueTestInstance);
    }
    else
    {
        // instance index corresponds to reference index
        handler.deliver(_instances[index]);
    }
    // complete processing the request
    handler.complete();
}
PEGASUS_NAMESPACE_BEGIN

/*****************************************************************************
 *
 * Implementation of AssociationProvider associators method
 *
 *****************************************************************************/
void InteropProvider::associators(
    const OperationContext & context,
    const CIMObjectPath & objectName,
    const CIMName & associationClass,
    const CIMName & resultClass,
    const String & role,
    const String & resultRole,
    const Boolean includeQualifiers,
    const Boolean includeClassOrigin,
    const CIMPropertyList & propertyList,
    ObjectResponseHandler & handler)
{
    PEG_METHOD_ENTER(TRC_CONTROLPROVIDER,
            "InteropProvider::associators()");
    initProvider();
    PEG_TRACE((TRC_CONTROLPROVIDER, Tracer::LEVEL4,
        "%s associators. objectName= %s, assocClass= %s resultClass= %s "
            "role= %s resultRole %s, includeQualifiers= %s, "
            "includeClassOrigin= %s, PropertyList= %s",
        thisProvider,
        (const char *)objectName.toString().getCString(),
        (const char *)associationClass.getString().getCString(),
        (const char *)resultClass.getString().getCString(),
        (const char *)role.getCString(),
        (const char *)resultRole.getCString(),
                      boolToString(includeQualifiers),
                      boolToString(includeClassOrigin),
        (const char *)propertyListToString(propertyList).getCString()));

    handler.processing();
    String originRole = role;
    String targetRole = resultRole;
    Uint32 numIterations = 1;
    //
    // The localReferences call retrieves instances of the desired association
    // class and sets the originRole and targetRole properties if currently
    // empty.
    //
    if (associationClass.equal(PEGASUS_CLASSNAME_PG_REFERENCEDPROFILE))
    {
        if (originRole.size() == 0 && targetRole.size() == 0)
        {
            originRole = String("Antecedent");
            targetRole = String("Dependent");
            numIterations = 2;
        }
    }
    for (Uint32 i = 0; i < numIterations; ++i)
    {
        Array<CIMInstance> refs = localReferences(
            context,
            objectName,
            associationClass,
            originRole,
            targetRole,
            CIMPropertyList(),
            resultClass);

        if( refs.size() )
        {
            Array<CIMInstance> refObjs = 
                getReferencedInstances(refs,targetRole,context,propertyList);
            ConstArrayIterator<CIMInstance> refsIterator(refObjs);
            for(Uint32 i = 0; i < refsIterator.size(); i++)
            {
                handler.deliver(refsIterator[i]);
            }
        }

        if (numIterations == 2)
        {
            originRole = String("Dependent");
            targetRole = String("Antecedent");
        }
    }
    handler.complete();

    PEG_METHOD_EXIT();
}
int main()
{
    String host;

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

    const char* pegasusHome = getenv("PEGASUS_HOME");
    String cipherSuite;
    String trustStorePath;
    String certPath;
    String keyPath;

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

    CIMClient *cc = new CIMClient ();
    SSLContext *sslContext = 0;
    cipherSuite = "LOW";

    try
    {
        sslContext = new SSLContext (trustStorePath, certPath, keyPath,
            String::EMPTY, 0, randPath, cipherSuite); 

        if (sslContext)
        {
            cc->connect (host, port, *sslContext, "", "");
            //
            // Do a generic call. We have to do this call to test whether or 
            // not we get 401'ed.
            //
            PEGASUS_TEST_ASSERT(0);

            cc->disconnect();
        }
    }
    catch(Exception &e)
    {
        cout << "SSLCipherTest:  "<< e.getMessage() << endl;
        cout << "Test passed. Connecting with cipher list as " << cipherSuite
            << " failed " << endl;
    }

    cipherSuite = "HIGH";

    try
    {

        sslContext = new SSLContext (trustStorePath, certPath, keyPath, 
            String::EMPTY, 0, randPath, cipherSuite);
        if (sslContext)
        {
            cc->connect (host, port, *sslContext, "", "");
            //
            // Do a generic call. We have to do this call to test whether or
            // not we get 401'ed.
            //
            CIMClass cimClass = cc->getClass(CIMNamespaceName("root/cimv2"),
                CIMName ("CIM_ManagedElement"), true, false, false,
                CIMPropertyList());
            cc->disconnect();
        }
    }
    catch(Exception &e)
    {
        cerr << "SSLCipherTest Error: "<< e.getMessage() << endl;
        PEGASUS_TEST_ASSERT(0);
    }

    cout << "Test passed. Connected with cipher suite as " << cipherSuite
        << endl;
    cout << "+++++ passed all tests" << 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;
}
Пример #27
0
// l10n - note: ignoring indication language
void snmpIndicationHandler::handleIndication(
    const OperationContext& context,
    const String nameSpace,
    CIMInstance& indication,
    CIMInstance& handler,
    CIMInstance& subscription,
    ContentLanguageList & contentLanguages)
{
    Array<String> propOIDs;
    Array<String> propTYPEs;
    Array<String> propVALUEs;

    Array<String> mapStr;

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

    try
    {
        PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4,
            "snmpIndicationHandler %s:%s.%s processing %s Indication",
           (const char*)(nameSpace.getCString()),
           (const char*)(handler.getClassName().getString().getCString()),
           (const char*)(handler.getProperty(
           handler.findProperty(PEGASUS_PROPERTYNAME_NAME)).
           getValue().toString().getCString()),
           (const char*)(indication.getClassName().getString().
           getCString())));
        CIMClass indicationClass = _repository->getClass(
            nameSpace, indication.getClassName(), false, true,
            false, CIMPropertyList());

        Uint32 propertyCount = indication.getPropertyCount();

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

            Uint32 propDeclPos = indicationClass.findProperty(prop.getName());
            if (propDeclPos != PEG_NOT_FOUND)
            {
                CIMProperty propDecl = indicationClass.getProperty(propDeclPos);

                Uint32 qualifierPos =
                    propDecl.findQualifier(CIMName("MappingStrings"));
                if (qualifierPos != PEG_NOT_FOUND)
                {
                    //
                    // We are looking for following fields:
                    // MappingStrings {"OID.IETF | SNMP." oidStr,
                    //     "DataType.IETF |" dataType}
                    // oidStr is the object identifier (e.g. "1.3.6.1.2.1.5..."
                    // dataType is either Integer, or OctetString,
                    // or OID
                    // Following is one example:
                    // MappingStrings {"OID.IETF | SNMP.1.3.6.6.3.1.1.5.2",
                    //    "DataType.IETF | Integer"}
                    //

                    propDecl.getQualifier(qualifierPos).getValue().get(
                        mapStr);

                    String oidStr, dataType;
                    String mapStr1, mapStr2;
                    Boolean isValidAuthority = false;
                    Boolean isValidDataType = false;

                    for (Uint32 j=0; j < mapStr.size(); j++)
                    {
                        Uint32 barPos = mapStr[j].find("|");

                        if (barPos != PEG_NOT_FOUND)
                        {
                            mapStr1 = mapStr[j].subString(0, barPos);
                            mapStr2 = mapStr[j].subString(barPos + 1);

                            _trimWhitespace(mapStr1);
                            _trimWhitespace(mapStr2);

                            if ((mapStr1 == "OID.IETF") &&
                                (String::compare(mapStr2,
                                 String("SNMP."), 5) == 0))
                            {
                                isValidAuthority = true;
                                oidStr = mapStr2.subString(5);
                            }
                            else if (mapStr1 == "DataType.IETF")
                            {
                                isValidDataType = true;
                                dataType = mapStr2;
                            }

                            if (isValidAuthority && isValidDataType)
                            {
                                propOIDs.append(oidStr);
                                propTYPEs.append(dataType);
                                propVALUEs.append(prop.getValue().toString());

                                break;
                            }
                        }
                    }
                }
            }
        }

        // 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

        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"));
        Uint32 snmpSecLevelPos = 
            handler.findProperty(CIMName("SNMPSecurityLevel"));
        Uint32 snmpSecAuthProtoPos = 
            handler.findProperty(CIMName("SNMPSecurityAuthProtocol"));
        Uint32 snmpSecAuthKeyPos =
            handler.findProperty(CIMName("SNMPSecurityAuthKey"));
        Uint32 snmpSecPrivProtoPos =
            handler.findProperty(CIMName("SNMPSecurityPrivProtocol"));
        Uint32 snmpSecPrivKeyPos =
            handler.findProperty(CIMName("SNMPSecurityPrivKey"));

        if (targetHostPos == PEG_NOT_FOUND)
        {
            PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL1,
                "Target host is not set for IndicationHandlerSNMPMapper %s"
                " Indication.",
                (const char*)(indication.getClassName().getString().
                getCString())));
            PEG_METHOD_EXIT();
            throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
                "Handler.snmpIndicationHandler.snmpIndicationHandler."
                "INVALID_SNMP_INSTANCE",
                "Invalid IndicationHandlerSNMPMapper instance"));
        }
        if (targetHostFormatPos == PEG_NOT_FOUND)
        {
            PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL1,
                "Target host format is not set for IndicationHandlerSNMPMapper"
                " %s Indication.",
                (const char*)(indication.getClassName().getString().
                getCString())));
            PEG_METHOD_EXIT();
            throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
                "Handler.snmpIndicationHandler.snmpIndicationHandler."
                "INVALID_SNMP_INSTANCE",
                "Invalid IndicationHandlerSNMPMapper instance"));
        }
        if (snmpVersionPos == PEG_NOT_FOUND)
        {
            PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL1,
                "SNMP Version is not set for IndicationHandlerSNMPMapper %s"
                " Indication.",
                (const char*)(indication.getClassName().getString().
                getCString())));
            PEG_METHOD_EXIT();
            throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
                "Handler.snmpIndicationHandler.snmpIndicationHandler."
                "INVALID_SNMP_INSTANCE",
                "Invalid IndicationHandlerSNMPMapper instance"));
        }
        else
        {
            // properties from the handler instance
            String targetHost;
            String otherTargetHostFormat = String();
            String securityName = String();
            String engineID = String();
            Uint16 targetHostFormat = 0;
            Uint16 snmpVersion = 0;
            Uint32 portNumber;
            Uint8 snmpSecLevel = 1; // noAuthnoPriv
            Uint8 snmpSecAuthProto = 0; 
            Array<Uint8> snmpSecAuthKey;// no key
            Uint8 snmpSecPrivProto = 0; 
            Array<Uint8> snmpSecPrivKey ;// no key

            String trapOid;
            Boolean trapOidAvailable = false;
            //
            //  Get snmpTrapOid from context
            //
            if (context.contains(SnmpTrapOidContainer::NAME))
            {
                SnmpTrapOidContainer trapContainer =
                    context.get(SnmpTrapOidContainer::NAME);

                trapOid = trapContainer.getSnmpTrapOid();
                trapOidAvailable = true;
            }
            else
            {
                // get trapOid from indication Class

                Uint32 pos =
                    indicationClass.findQualifier(CIMName("MappingStrings"));
                if (pos != PEG_NOT_FOUND)
                {
                    Array<String> classMapStr;
                    indicationClass.getQualifier(pos).getValue().
                        get(classMapStr);

                    for (Uint32 i=0; i < classMapStr.size(); i++)
                    {
                        Uint32 barPos = classMapStr[i].find("|");

                        if (barPos != PEG_NOT_FOUND)
                        {
                            String authorityName =
                                classMapStr[i].subString(0, barPos);
                            String oidStr = classMapStr[i].subString(
                                barPos+1, PEG_NOT_FOUND);

                            _trimWhitespace(authorityName);
                            _trimWhitespace(oidStr);

                            if ((authorityName == "OID.IETF") &&
                                (String::compare(oidStr,
                                 String("SNMP."), 5) == 0))
                            {
                                trapOid = oidStr.subString(5);
                                trapOidAvailable = true;
                                break;
                            }
                        }
                    }

                    if (!trapOidAvailable)
                    {
                        PEG_TRACE((
                            TRC_IND_HANDLER,
                            Tracer::LEVEL1,
                            "No MappingStrings for snmp trap is specified "
                                "for class: %s",
                            (const char*)
                              indication.getClassName().getString().getCString()
                            ));

                        PEG_METHOD_EXIT();

                        throw PEGASUS_CIM_EXCEPTION_L(
                            CIM_ERR_FAILED,
                            MessageLoaderParms(
                                "Handler.snmpIndicationHandler."
                                "snmpIndicationHandler.NO_MS_FOR_SNMP_TRAP",
                                "No MappingStrings for snmp trap is specified "
                                    "for class: $0",
                                indication.getClassName().getString()));
                    }
                }
                else
                {
                    PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1,
                        "Qualifier MappingStrings can not be found.");
                    PEG_METHOD_EXIT();
                    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);
            }

            if(snmpVersion == 5) // SNMPv3 Trap
            {
                //fetch the security data
                if(snmpSecLevelPos != PEG_NOT_FOUND)
                {
                    handler.getProperty(snmpSecLevelPos).getValue(). \
                        get(snmpSecLevel);
                }
                if(snmpSecAuthProtoPos != PEG_NOT_FOUND)
                {
                    handler.getProperty(snmpSecAuthProtoPos).getValue(). \
                        get(snmpSecAuthProto);
                }
                if(snmpSecAuthKeyPos != PEG_NOT_FOUND)
                {
                    handler.getProperty(snmpSecAuthKeyPos).getValue(). \
                        get(snmpSecAuthKey);
                }
                if(snmpSecPrivProtoPos != PEG_NOT_FOUND)
                {
                    handler.getProperty(snmpSecPrivProtoPos).getValue(). \
                        get(snmpSecPrivProto);
                }
                if(snmpSecPrivKeyPos!= PEG_NOT_FOUND)
                {
                    handler.getProperty(snmpSecPrivKeyPos).getValue(). \
                        get(snmpSecPrivKey);
                }
            }

            PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4,
               "snmpIndicationHandler sending %s Indication trap %s to target"
               " host %s target port %d",
               (const char*)(indication.getClassName().getString().
               getCString()),
               (const char*)(trapOid.getCString()),
               (const char*)(targetHost.getCString()),portNumber));
           _snmpTrapSender->deliverTrap(
                trapOid,
                securityName,
                targetHost,
                targetHostFormat,
                otherTargetHostFormat,
                portNumber,
                snmpVersion,
                engineID,
                snmpSecLevel,
                snmpSecAuthProto,
                snmpSecAuthKey,
                snmpSecPrivProto,
                snmpSecPrivKey,
                propOIDs,
                propTYPEs,
                propVALUEs);

        PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4,
           "%s Indication trap %s sent to target host %s target port %d "
           "successfully",
           (const char*)(indication.getClassName().getString().getCString()),
           (const char*)(trapOid.getCString()),
           (const char*)(targetHost.getCString()),portNumber));
        }
    }
    catch (CIMException& c)
    {
        PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL1, "CIMException %s",
            (const char*)c.getMessage().getCString()));
        PEG_METHOD_EXIT();
        throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, c.getMessage());
    }
    catch (Exception& e)
    {
        PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL1, "Exception %s",
            (const char*)e.getMessage().getCString()));
        PEG_METHOD_EXIT();

        throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
    }
    catch (...)
    {
        PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1,
            "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."));
    }
    PEG_METHOD_EXIT();
}
Пример #28
0
void testReferences(
    CIMClient& client,
    const String& query,
    CIMObjectPath targetPath,
    Uint32 testCount,
    CIMStatusCode expectedError = CIM_ERR_SUCCESS)
{
    Array<CIMInstance> pulledInstances;
    Boolean endOfSequence = false;
    CIMEnumerationContext enumerationContext;
    //CIMObjectPath assoc = CIMObjectPath("TEST_CLASS.Id=\"Mike"\")
    try
    {
        pulledInstances = client.openReferenceInstances(
            enumerationContext,
            endOfSequence,
            PROVIDERNS,
            targetPath,
            CIMName(),
            String(),
            false,
            CIMPropertyList(),
            "DMTF:FQL",
            query,
            30,
            false,
            10);

        if (expectedError != CIM_ERR_SUCCESS)
        {
            cout << "ERROR. Error code expected but good response receied."
                << endl;
        }
    }
    catch (CIMException& e)
    {
        if (e.getCode() == expectedError)
        {
            VCOUT << "Error caught correctly. " << e.getCode() << endl;
            return;
        }
        else
        {
            cout << "Error Rtn expected but Incorrect code received"
                 << " Query " << query << " Expected " << expectedError
                 << " received " << e.getCode()
                 << " msg " << e.getMessage() << endl;
            exit(1);
        }
    }
    while (!endOfSequence)
    {
        Array<CIMInstance> cimInstancesPulled = client.pullInstancesWithPath(
        enumerationContext,
        endOfSequence,
        10);
        pulledInstances.appendArray(cimInstancesPulled);
    }

    VCOUT << "pullAssociators " << targetPath.toString()
          << " returned " << pulledInstances.size() << " instances."
          << endl;
    if (testCount != pulledInstances.size())
    {
        cout << "Incorrect Count returned. Expected " << testCount
             << " Received " << pulledInstances.size()
             << " Query " << query
             << endl;
        exit(1);
    }
    else
    {
        return;
    }
}
//
// Method that caches certain profile registration information. Specifically,
// information pertaining to the ElementConformsToProfofile association
// implementation is kept here.
//
void InteropProvider::cacheProfileRegistrationInfo()
{
    Array<CIMInstance> instances;
    Array<CIMInstance> providerCapabilitiesInstances;

    // Clear existing cache
    profileIds.clear();
    conformingElements.clear();
    elementNamespaces.clear();

    // Retrieve all of the provider profile registration info
    Array<CIMName> propList;
    propList.append(CAPABILITIES_PROPERTY_PROVIDERMODULENAME);
    propList.append(CAPABILITIES_PROPERTY_PROVIDERNAME);
    propList.append(PROFILECAPABILITIES_PROPERTY_PROFILEVERSION);
    propList.append(PROFILECAPABILITIES_PROPERTY_REGISTEREDPROFILE);
    propList.append(PROFILECAPABILITIES_PROPERTY_OTHERREGISTEREDPROFILE);
    propList.append(PROFILECAPABILITIES_PROPERTY_OTHERPROFILEORGANIZATION);
    propList.append(PROFILECAPABILITIES_PROPERTY_CONFORMINGELEMENTS);

    Array<CIMInstance> providerProfileInstances = 
        enumProviderProfileCapabilityInstances(
            true,
            false,
            false,
            false,
            CIMPropertyList(propList));

    CIMClass elementConformsClass = repository->getClass(
        PEGASUS_NAMESPACENAME_INTEROP,
        PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE,
        false, true, false);
    CIMClass registeredProfileClass = repository->getClass(
        PEGASUS_NAMESPACENAME_INTEROP,
        PEGASUS_CLASSNAME_PG_REGISTEREDPROFILE,
        false, true, false);
    Array<CIMInstance> capabilities;

    // Loop through the provider profile info to determine what profiles are
    // supported by what providers, and to build the ElementConformsToProfile
    // associations.
    for (Uint32 i = 0, n = providerProfileInstances.size(); i < n; ++i)
    {
        CIMInstance & currentProfileInstance = providerProfileInstances[i];
        String moduleName = getRequiredValue<String>(currentProfileInstance,
            CAPABILITIES_PROPERTY_PROVIDERMODULENAME);
        String providerName = getRequiredValue<String>(currentProfileInstance,
            CAPABILITIES_PROPERTY_PROVIDERNAME);
        String profileName;
        Uint16 profileOrganization = 0;
        String profileVersion;
        String organizationName;
        Array<String> profileNames; // Not going to use this info
        Array<String> profileVersions; // Not going to use this info
        Array<Uint16> profileOrganizations; // Not going to use this info
        Array<String> profileOrganizationNames; // Not going to use this info
        Array<String> providerModuleNames; // Not going to use this info
        Array<String> providerNames; // Not going to use this info

        String profileId = extractProfileInfo(currentProfileInstance,
            profileCapabilitiesClass,
            registeredProfileClass,
            profileName,
            profileVersion,
            profileOrganization,
            organizationName,
            profileNames,
            profileVersions,
            profileOrganizations,
            profileOrganizationNames,
            providerModuleNames,
            providerNames,
            true);

        Uint32 propIndex = currentProfileInstance.findProperty(
              PROFILECAPABILITIES_PROPERTY_CONFORMINGELEMENTS);

        Array<CIMName> elementPropArray;
        elementPropArray.append(
            ELEMENTCONFORMSTOPROFILE_PROPERTY_CONFORMANTSTANDARD);
        elementPropArray.append(
            ELEMENTCONFORMSTOPROFILE_PROPERTY_MANAGEDELEMENT);
        CIMPropertyList elementPropList(elementPropArray);

        Array<CIMName> conformingElementsForProfile;
        Array<CIMNamespaceName> elementNamespacesForProfile;

        Array<String> elementClasses;
        currentProfileInstance.getProperty(propIndex).getValue().get(
            elementClasses);
        //if (propIndex == PEG_NOT_FOUND)
        if (elementClasses.size() == 0)
        {
            // Get the namespaces in which this provider operates and trim down
            // the list of capabilities instaces to just those that are related
            // to this one.
            if (capabilities.size() == 0)
            {
                Array<CIMName> capPropList;
                capPropList.append(
                    PROVIDERCAPABILITIES_PROPERTY_PROVIDERMODULENAME);
                capPropList.append(PROVIDERCAPABILITIES_PROPERTY_PROVIDERNAME);
                capPropList.append(PROVIDERCAPABILITIES_PROPERTY_NAMESPACES);
                capPropList.append(PROVIDERCAPABILITIES_PROPERTY_CLASSNAME);
                capabilities = repository->enumerateInstancesForClass(
                    PEGASUS_NAMESPACENAME_INTEROP,
                    PEGASUS_CLASSNAME_PROVIDERCAPABILITIES, false, false,
                    false);
            }
            Array<CIMInstance> capabilitiesForProvider;
            Array<CIMNamespaceName> namespacesForProvider;
            Array<CIMNameArray> subclassesForNamespace;
            for (Uint32 j = 0, m = capabilities.size(); j < m; ++j)
            {
                CIMInstance & currentInstance = capabilities[j];
                String curModuleName = getRequiredValue<String>(
                    currentInstance, CAPABILITIES_PROPERTY_PROVIDERMODULENAME);
                String curProviderName = getRequiredValue<String>(
                    currentInstance, CAPABILITIES_PROPERTY_PROVIDERNAME);
                if (curModuleName == moduleName &&
                    curProviderName == providerName)
                {
                    CIMName currentClass(getRequiredValue<String>(
                        currentInstance,
                        PROVIDERCAPABILITIES_PROPERTY_CLASSNAME));
                    capabilitiesForProvider.append(currentInstance);
                    StringArray curNamespaces =
                        getRequiredValue<StringArray>(currentInstance,
                            PROVIDERCAPABILITIES_PROPERTY_NAMESPACES);
                    Sint32 z = 0;
                    Sint32 y = curNamespaces.size();

                    // If one of the namespaces is Interop, then continue
                    bool interopNamespaceFound = false;
                    for (; z < y; ++z)
                    {
                        if (CIMNamespaceName(curNamespaces[z]) ==
                            PEGASUS_NAMESPACENAME_INTEROP)
                        {
                            interopNamespaceFound = true;
                            break;
                        }
                    }
                    if (interopNamespaceFound)
                        continue;

                    // See if the current namespaces are already listed
                    for (Sint32 w = 0; w < y; ++w)
                    {
                        Sint32 foundIndex = -1;
                        CIMNamespaceName curNamespace = curNamespaces[w];
                        Uint32 k = 0;
                        Uint32 x = namespacesForProvider.size();
                        for (; k < x; ++k)
                        {
                            if (curNamespace == namespacesForProvider[k])
                            {
                                foundIndex = (Sint32)k;
                                break;
                            }
                        }
                        if (foundIndex == -1)
                        {
                            // Get all the subclasses of
                            // ElementConformsToProfile in the namespace and
                            // cache them.
                            foundIndex = namespacesForProvider.size();
                            Array<CIMName> subClasses = 
                                repository->enumerateClassNames(curNamespace,
                                PEGASUS_CLASSNAME_CIM_ELEMENTCONFORMSTOPROFILE,
                                true);
                            subClasses.append(
                                PEGASUS_CLASSNAME_CIM_ELEMENTCONFORMSTOPROFILE
                                );
                            namespacesForProvider.append(curNamespace);
                            subclassesForNamespace.append(subClasses);
                        }

                        // Now search to see if the current class is one of the
                        // subclasses in this namespace, and finally, if it is
                        // add it to the list
                        Array<CIMName> & subClasses =
                            subclassesForNamespace[foundIndex];
                        for (k = 0, x = subClasses.size(); k < x; ++k)
                        {
                            if (subClasses[k] == currentClass)
                            {
                                String dynamicElement = PEGASUS_DYNAMIC +
                                    currentClass.getString();
                                conformingElementsForProfile.append(
                                    dynamicElement);
                                elementNamespacesForProfile.append(
                                    curNamespace);
                            }
                        }
                    }
                }
            }
        }
        else
        {
            //Array<String> elementClasses;
            //currentProfileInstance.getProperty(propIndex).getValue().get(
            //    elementClasses);
            for (Uint32 j = 0, m = elementClasses.size(); j < m; ++j)
            {
                CIMName elementClass(elementClasses[j]);
                Array<String> searchNamespaces =
                    findProviderNamespacesForElement(
                        moduleName, providerName,
                        elementClass,
                        repository,
                        providerCapabilitiesInstances);
                Uint32 k = 0;
                Uint32 x = searchNamespaces.size();
                for (; k < x; ++k)
                {
                    conformingElementsForProfile.append(elementClass);
                    elementNamespacesForProfile.append(searchNamespaces[k]);
                }
            }
        }

        Sint32 foundIndex = -1;
        for (Sint32 j = 0, m = profileIds.size(); j < m; ++j)
        {
            if (profileIds[j] == profileId)
            {
                foundIndex = j;
                break;
            }
        }

        if (foundIndex >= 0)
        {
            // Append the results to already existing entries
            conformingElements[foundIndex].appendArray(
                conformingElementsForProfile);
            elementNamespaces[foundIndex].appendArray(
                elementNamespacesForProfile);
        }
        else
        {
            profileIds.append(profileId);
            conformingElements.append(conformingElementsForProfile);
            elementNamespaces.append(elementNamespacesForProfile);
        }
    }
}
Пример #30
0
//
// Test of the Instance creation and instance filtering
//
void test04()
{
    if (verbose)
    {
        cout << "Test04 - Create instance from Class. " << endl;
    }

    const CIMNamespaceName NAMESPACE = CIMNamespaceName("/zzz");

    // Create and populate a declaration context:

    SimpleDeclContext* context = new SimpleDeclContext;

    context->addQualifierDecl(
        NAMESPACE, CIMQualifierDecl(CIMName("counter"), false,
        CIMScope::PROPERTY));

    context->addQualifierDecl(
        NAMESPACE, CIMQualifierDecl(CIMName("classcounter"), false,
        CIMScope::CLASS));

    context->addQualifierDecl(
        NAMESPACE, CIMQualifierDecl(CIMName("min"), String(),
        CIMScope::PROPERTY));

    context->addQualifierDecl(
        NAMESPACE, CIMQualifierDecl(CIMName("max"), String(),
        CIMScope::PROPERTY));

    context->addQualifierDecl(NAMESPACE,
        CIMQualifierDecl(CIMName("Description"), String(),
        CIMScope::PROPERTY));

    CIMClass class1(CIMName("MyClass"));

    class1
        .addProperty(CIMProperty(CIMName("count"), Uint32(55))
            .addQualifier(CIMQualifier(CIMName("counter"), true))
            .addQualifier(CIMQualifier(CIMName("min"), String("0")))
            .addQualifier(CIMQualifier(CIMName("max"), String("1"))))
        .addProperty(CIMProperty(CIMName("message"), String("Hello"))
            .addQualifier(CIMQualifier(CIMName("description"),
                String("My Message"))))
        .addProperty(CIMProperty(CIMName("ratio"), Real32(1.5)));


    Resolver::resolveClass(class1, context, NAMESPACE);
    context->addClass(NAMESPACE, class1);


    if (verbose)
    {
        XmlWriter::printClassElement(class1);
    }

    //
    // Create instance with qualifiers, classorigin, and Null propertyList
    //
    {
        CIMInstance newInstance;

        newInstance = class1.buildInstance(true, true, CIMPropertyList());

        if (verbose)
        {
            XmlWriter::printInstanceElement(newInstance);
        }

        assert(newInstance.getPropertyCount() == class1.getPropertyCount());
        assert(newInstance.getQualifierCount() == class1.getQualifierCount());
        assert(newInstance.findProperty("ratio") != PEG_NOT_FOUND);
        assert(newInstance.findProperty("message") != PEG_NOT_FOUND);

    }

    //
    // Test with include qualifiers false. Should be no qualifiers in result
    //
    {
        CIMInstance newInstance =
            class1.buildInstance(false, true, CIMPropertyList());

        assert(newInstance.getQualifierCount() == 0);
        assert(newInstance.getPropertyCount() == class1.getPropertyCount());
        assert(newInstance.findProperty("ratio") != PEG_NOT_FOUND);
        assert(newInstance.findProperty("message") != PEG_NOT_FOUND);
    }

    //
    // Test with empty property list.  Should have no properties.
    //
    {
        Array<CIMName> pl1Array;
        CIMPropertyList pl1(pl1Array);

        CIMInstance newInstance = class1.buildInstance(false, true, pl1);

        assert(newInstance.getQualifierCount() == 0);
        assert(newInstance.getPropertyCount() == 0);
    }

    //
    // Test with a property that exists in property list.
    //
    {
        Array<CIMName> pl1Array;
        pl1Array.append("ratio");
        CIMPropertyList pl1(pl1Array);

        CIMInstance newInstance = class1.buildInstance(false, true, pl1);

        if (verbose)
        {
            cout << "Test with one property in new instance" << endl;
            XmlWriter::printInstanceElement(newInstance);
        }

        assert(newInstance.getPropertyCount() == 1);
        assert(newInstance.findProperty("ratio") != PEG_NOT_FOUND);
        assert(newInstance.findProperty("message") == PEG_NOT_FOUND);
        assert(newInstance.getQualifierCount() == 0);
    }

    //
    // Test with a property that does/does not exist in property list
    //
    {
        Array<CIMName> pl1Array;
        CIMPropertyList pl1(pl1Array);
        pl1.clear();
        pl1Array.append("blob");
        pl1Array.append("ratio");
        pl1.set(pl1Array);

        CIMInstance newInstance = class1.buildInstance(false, true, pl1);

        assert(newInstance.getPropertyCount() == 1);
        assert(newInstance.findProperty("ratio") != PEG_NOT_FOUND);
        assert(newInstance.findProperty("blob") == PEG_NOT_FOUND);
        assert(newInstance.findProperty("message") == PEG_NOT_FOUND);
        assert(newInstance.getQualifierCount() == 0);
    }

    ///////////////////////////////////////////////////////////////////////
    //
    // Instance Filtering function tests
    //
    ///////////////////////////////////////////////////////////////////////

    // build instance as starting point for tests.
    CIMInstance tstInstance =
        class1.buildInstance(true, true, CIMPropertyList());

    //
    // Test complete copy, no change
    //
    {
        if (verbose)
        {
            cout << "Test1" << endl;
        }

        CIMInstance filterInstance = tstInstance.clone();
        filterInstance.filter(true, true, CIMPropertyList());

        assert(tstInstance.identical(filterInstance));
        assert(filterInstance.getPropertyCount() == 3);
        assert(filterInstance.getQualifierCount() ==
            tstInstance.getQualifierCount());
    }

    //
    // Filter to one property, ratio
    //
    {
        if (verbose)
        {
            cout << "Test2" << endl;
        }

        Array<CIMName> pl1Array;
        pl1Array.append("ratio");
        CIMPropertyList pl1(pl1Array);

        CIMInstance filterInstance = tstInstance.clone();
        filterInstance.filter(true, true, pl1);

        if (verbose)
        {
            XmlWriter::printInstanceElement(filterInstance);
        }

        assert(filterInstance.getPropertyCount() == 1);
        assert(filterInstance.findProperty("ratio") != PEG_NOT_FOUND);
        assert(_propertyIdentical("ratio", filterInstance, tstInstance));
        assert(filterInstance.getQualifierCount() ==
                tstInstance.getQualifierCount());
    }

    //
    // Filter to one property, message
    //
    {
        if (verbose)
        {
            cout << "Test3" << endl;
        }

        Array<CIMName> pl1Array;
        pl1Array.append("message");
        CIMPropertyList pl1(pl1Array);

        CIMInstance filterInstance = tstInstance.clone();
        filterInstance.filter(true, true, pl1);

        if (verbose)
        {
            XmlWriter::printInstanceElement(filterInstance);
        }

        assert(filterInstance.getPropertyCount() == 1);
        assert(filterInstance.findProperty("message") != PEG_NOT_FOUND);
        assert(_propertyIdentical("message", filterInstance, tstInstance));
        assert(filterInstance.getQualifierCount() ==
                tstInstance.getQualifierCount());
    }

    //
    // Filter to one property, count
    //
    {
        if (verbose)
        {
            cout << "Test4" << endl;
        }

        Array<CIMName> pl1Array;
        pl1Array.append("count");
        CIMPropertyList pl1(pl1Array);

        CIMInstance filterInstance = tstInstance.clone();
        filterInstance.filter(true, true, pl1);

        if (verbose)
        {
            XmlWriter::printInstanceElement(filterInstance);
        }

        assert(filterInstance.getPropertyCount() == 1);
        assert(filterInstance.findProperty("count") != PEG_NOT_FOUND);
        assert(filterInstance.getQualifierCount() ==
                tstInstance.getQualifierCount());
    }

    //
    // Filter to no properties
    //
    {
        if (verbose)
        {
            cout << "Test5a" << endl;
        }

        Array<CIMName> pl1Array;
        CIMPropertyList pl1(pl1Array);

        CIMInstance filterInstance = tstInstance.clone();
        filterInstance.filter(true, true, pl1);

        assert(filterInstance.getPropertyCount() == 0);
        assert(filterInstance.findProperty("ratio") == PEG_NOT_FOUND);
        assert(filterInstance.getQualifierCount() ==
            tstInstance.getQualifierCount());
    }

    //
    // Filter to two properties
    //
    {
        if (verbose)
        {
            cout << "Test5b" << endl;
        }

        Array<CIMName> pl1Array;
        pl1Array.append("count");
        pl1Array.append("message");
        CIMPropertyList pl1(pl1Array);

        CIMInstance filterInstance = tstInstance.clone();
        filterInstance.filter(true, true, pl1);

        assert(filterInstance.getPropertyCount() == 2);
        assert(filterInstance.findProperty("ratio") == PEG_NOT_FOUND);
        assert(filterInstance.findProperty("message") != PEG_NOT_FOUND);
        assert(_propertyIdentical("message", filterInstance, tstInstance));
        assert(filterInstance.findProperty("count") != PEG_NOT_FOUND);
        assert(_propertyIdentical("count", filterInstance, tstInstance));
        assert(filterInstance.getQualifierCount() ==
                tstInstance.getQualifierCount());
    }

    //
    // Filter to no qualifiers and all properties.
    //
    {
        if (verbose)
        {
            cout << "Test6" << endl;
        }

        CIMInstance filterInstance = tstInstance.clone();
        filterInstance.filter(false, true, CIMPropertyList());

        assert(filterInstance.getPropertyCount() == 3);
        assert(filterInstance.findProperty("ratio") != PEG_NOT_FOUND);
        assert(filterInstance.getQualifierCount() == 0);
        for (Uint32 i = 0; i < filterInstance.getPropertyCount() ; i++)
        {
            CIMConstProperty p = filterInstance.getProperty(i);
            assert(p.getQualifierCount() == 0);
        }
    }

    //
    // Filter to no qualifiers and no properties.
    //
    {
        if (verbose)
        {
            cout << "Test6a" << endl;
        }

        Array<CIMName> pl1Array;
        CIMPropertyList pl1(pl1Array);

        CIMInstance filterInstance = tstInstance.clone();
        filterInstance.filter(false, true, pl1);

        assert(filterInstance.getPropertyCount() == 0);
        assert(filterInstance.findProperty("ratio") == PEG_NOT_FOUND);
        assert(filterInstance.getQualifierCount() == 0);
    }

    //
    // Test Class Origin Filter
    //
    {
        if (verbose)
        {
            cout << "Test7 Class Origin" << endl;
        }

        // Create a subclass to do classOrigin testing
        CIMClass mySubClass(CIMName("subclass"));
        mySubClass.setSuperClassName(CIMName("MyClass"));

        Resolver::resolveClass(mySubClass, context, NAMESPACE);
        context->addClass(NAMESPACE, mySubClass);

        // build instance
        CIMInstance filterInstance =
            mySubClass.buildInstance(true, true, CIMPropertyList());
        filterInstance.filter(false, true, CIMPropertyList());

        assert(filterInstance.getPropertyCount() == 3);
        assert(filterInstance.findProperty("ratio") != PEG_NOT_FOUND);
        assert(filterInstance.getQualifierCount() == 0);
        for (Uint32 i = 0 ; i < filterInstance.getPropertyCount() ; i++)
        {
            CIMProperty p = filterInstance.getProperty(i);
            assert(!(p.getClassOrigin() == CIMName()));

        }
        filterInstance.filter(false, false, CIMPropertyList());

        for (Uint32 i = 0 ; i < filterInstance.getPropertyCount() ; i++)
        {
            CIMProperty p = filterInstance.getProperty(i);
            assert(p.getClassOrigin() == CIMName());
        }

        CIMInstance filterInstance2 =
            mySubClass.buildInstance(true, false, CIMPropertyList());

        for (Uint32 i = 0 ; i < filterInstance2.getPropertyCount() ; i++)
        {
            CIMProperty p = filterInstance2.getProperty(i);
            assert(p.getClassOrigin() == CIMName());
        }
    }
    delete context;
}