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; }
void _createDuplicate(CIMClient &client, const String &filterHost, const CIMNamespaceName &filterNameSpace, CIMObjectPath &filterPath, const String &handlerHost, const CIMNamespaceName &handlerNameSpace, CIMObjectPath &handlerPath) { Boolean exceptionCaught = false; // // Set Host and Namespace in filter CIMObjectPath // filterPath.setHost(filterHost); filterPath.setNameSpace(filterNameSpace); // // Set Host and Namespace in handler CIMObjectPath // handlerPath.setHost (handlerHost); handlerPath.setNameSpace (handlerNameSpace); try { CreateSbscriptionInstance(client, handlerPath, filterPath, PEGASUS_NAMESPACENAME_INTEROP); } catch (CIMException &e) { if (e.getCode() != CIM_ERR_ALREADY_EXISTS) { PEGASUS_TEST_ASSERT(0); } exceptionCaught = true; } PEGASUS_TEST_ASSERT(exceptionCaught); }
CIMObjectPath _buildFilterOrHandlerPath( const CIMName& className, const String& name, const String& host, const CIMNamespaceName& namespaceName = CIMNamespaceName()) { CIMObjectPath path; Array<CIMKeyBinding> keyBindings; keyBindings.append(CIMKeyBinding("SystemCreationClassName", System::getSystemCreationClassName(), CIMKeyBinding::STRING)); keyBindings.append(CIMKeyBinding("SystemName", System::getFullyQualifiedHostName(), CIMKeyBinding::STRING)); keyBindings.append(CIMKeyBinding("CreationClassName", className.getString(), CIMKeyBinding::STRING)); keyBindings.append(CIMKeyBinding("Name", name, CIMKeyBinding::STRING)); path.setClassName(className); path.setKeyBindings(keyBindings); path.setNameSpace(namespaceName); path.setHost(host); return path; }
// Test non-ASCII character handling void test08() { CIMObjectPath op = CIMObjectPath("//myHost/ns1/ns2:aClass.key1=1"); Boolean errorDetected; // Test non-ASCII first character of hostname errorDetected = false; try { String hostname = "123.123.123.123"; hostname[0] = 0x131; op.setHost(hostname); } catch (const MalformedObjectNameException&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); // Test non-ASCII non-first character of IP address octet errorDetected = false; try { String hostname = "123.123.123.123"; hostname[1] = 0x132; op.setHost(hostname); } catch (const MalformedObjectNameException&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); // Test non-ASCII first character of IP address octet errorDetected = false; try { String hostname = "123.123.123.123"; hostname[4] = 0x131; op.setHost(hostname); } catch (const MalformedObjectNameException&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); // Test non-ASCII first character of hostname segment errorDetected = false; try { String hostname = "myhost.123.com"; hostname[7] = 0x131; op.setHost(hostname); } catch (const MalformedObjectNameException&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); // Test non-ASCII non-first character of hostname segment errorDetected = false; try { String hostname = "myhost.123.com"; hostname[8] = 0x132; op.setHost(hostname); } catch (const MalformedObjectNameException&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); // Test non-ASCII first character of port number errorDetected = false; try { String hostname = "myhost.123.com:1234"; hostname[15] = 0x131; op.setHost(hostname); } catch (const MalformedObjectNameException&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); // Test non-ASCII non-first character of port number errorDetected = false; try { String hostname = "myhost.123.com:1234"; hostname[18] = 0x134; op.setHost(hostname); } catch (const MalformedObjectNameException&) { errorDetected = true; } PEGASUS_TEST_ASSERT(errorDetected); }
// // Local version of the references operation. It validates the input // parameters, setting the origin and target property values if not set // already, and then performs an enumeration on the association class. It then // filters the results of that enumeration to see if one of the reference // properties matches the objectName parameter passed into the method. If so, // then it is added to the array of association instances to be returned. // Array<CIMInstance> InteropProvider::localReferences( const OperationContext & context, const CIMObjectPath & objectName, const CIMName & assocClass, String & originProperty, String & targetProperty, const CIMPropertyList & propertyList, const CIMName & targetClass) { PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::localReferences()"); Array<CIMInstance> instances; CIMName originClass = objectName.getClassName(); Array<CIMName> targetSubclasses; CIMNamespaceName lastTargetNamespace; CIMNamespaceName originNamespace(objectName.getNameSpace()); // Check that the association traversal request is valid if (validAssocClassForObject( context, assocClass, objectName, originNamespace, originProperty, targetProperty)) { // retrieve all of the association class instances Array<CIMInstance> localInstances = localEnumerateInstances(context, CIMObjectPath(hostName, originNamespace, assocClass)); // Filter the association class instances based on the origin instance // and other input parameters. for(Uint32 i = 0, n = localInstances.size(); i < n; ++i) { CIMInstance & currentInstance = localInstances[i]; CIMObjectPath originPath = getRequiredValue<CIMObjectPath>( currentInstance, originProperty); originPath.setNameSpace(objectName.getNameSpace()); originPath.setHost(objectName.getHost()); // Only include instances where the origin instance is present in // the association. if(originPath.identical(objectName)) { if(!targetClass.isNull()) { // Have to check if the target reference is of the // targetClass type. We first must determine all the // possible subclasses of the targetClass in the target // namespace. CIMObjectPath targetPath = getRequiredValue<CIMObjectPath>( currentInstance, targetProperty); CIMNamespaceName targetNamespace( targetPath.getNameSpace()); if(targetNamespace.isNull()) { targetNamespace = originNamespace; targetPath.setNameSpace(targetNamespace); } if(targetNamespace != lastTargetNamespace) { try { targetSubclasses = repository->enumerateClassNames( targetNamespace, targetClass, true); } catch(...) { // If an exception was thrown during enumeration, // then the base class didn't exist in the // namespace, so the target instance retrieved // must not match the targetClass parameter. continue; } targetSubclasses.append(targetClass); lastTargetNamespace = targetNamespace; } // Try to find the targetPath's class in the search space CIMName targetPathClass = targetPath.getClassName(); for(Uint32 j = 0, m = targetSubclasses.size(); j < m; ++j) { if(targetPathClass == targetSubclasses[j]) { instances.append(currentInstance); break; } } } else { instances.append(currentInstance); } } } } PEG_METHOD_EXIT(); return instances; }
// // Local version of getInstance to be used by other functions in the the // provider. Returns a single instance. Note that it always returns an // instance. If none was found, it is uninialitized. // CIMInstance InteropProvider::localGetInstance( const OperationContext & context, const CIMObjectPath & instanceName, const CIMPropertyList & propertyList) { PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::localGetInstance"); PEG_TRACE((TRC_CONTROLPROVIDER, Tracer::LEVEL4, "%s getInstance. instanceName= %s , PropertyList= %s", thisProvider, (const char *)instanceName.toString().getCString(), (const char *)propertyListToString(propertyList).getCString())); // Test if we're looking for something outside of our namespace. This will // happen during associators calls from PG_RegisteredProfile instances // through the PG_ElementConformsToProfile association CIMNamespaceName opNamespace = instanceName.getNameSpace(); CIMName opClass = instanceName.getClassName(); if(opNamespace != PEGASUS_NAMESPACENAME_INTEROP && opClass != PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE // Get CIM_IndicationService instance from IndicationService. #ifdef PEGASUS_ENABLE_DMTF_INDICATION_PROFILE_SUPPORT || opClass == PEGASUS_CLASSNAME_CIM_INDICATIONSERVICE #endif ) { AutoMutex mut(interopMut); CIMInstance gotInstance = cimomHandle.getInstance( context, opNamespace, instanceName, false, false, false, propertyList); PEG_METHOD_EXIT(); return gotInstance; } // Create reference from host, namespace, class components of // instance name CIMObjectPath ref; ref.setHost(instanceName.getHost()); ref.setClassName(opClass); ref.setNameSpace(opNamespace); // Enumerate instances for this class. Returns all instances // Note that this returns paths setup and instances already // filtered per the input criteria. Array<CIMInstance> instances = localEnumerateInstances( context, ref, propertyList); // deliver a single instance if found. CIMInstance retInstance; bool found = false; for(Uint32 i = 0, n = instances.size(); i < n; i++) { CIMObjectPath currentInstRef = instances[i].getPath(); currentInstRef.setHost(instanceName.getHost()); currentInstRef.setNameSpace(instanceName.getNameSpace()); if(instanceName == currentInstRef) { retInstance = instances[i]; found = true; break; } } if(!found) { cout << "Coule not find instance: " << instanceName.toString() << endl; } PEG_METHOD_EXIT(); return retInstance; }
void testInstanceClass(CIMClient & client, const CIMName & className) { cout << "Testing Instance Class " << (const char *)className.getString().getCString() << "..."; Array<CIMInstance> instances = testAnyClass(client, className); for(unsigned int i = 0, n = instances.size(); i < n; ++i) { CIMInstance currentInstance = instances[i]; CIMObjectPath currentPath = currentInstance.getPath(); if(currentPath.getNameSpace().isNull()) currentPath.setNameSpace(interopNamespace); // // Now test association traversal // Note that the "TestAssociationClass" method does a very good job // of testing association traversal between references contained in // instances of the supplied association class. Therefore, all we // really have to do here is make sure that the results of the // associators, associatorNames, references, and referenceNames // operations are consistent. // Boolean failure = false; try { Array<CIMObject> associatorsResults = client.associators( currentPath.getNameSpace(), currentPath); Array<CIMObjectPath> associatorNamesResults = client.associatorNames( currentPath.getNameSpace(), currentPath); Array<CIMObject> referencesResults = client.references( currentPath.getNameSpace(), currentPath); Array<CIMObjectPath> referenceNamesResults = client.referenceNames( currentPath.getNameSpace(), currentPath); Uint32 numResults = associatorsResults.size(); if(numResults != associatorNamesResults.size() || numResults != referencesResults.size() || numResults != referenceNamesResults.size()) { failure = true; } else { // Check that the results for the references and referenceNames // operations are consistent. unsigned int j = 0; for(j = 0; j < numResults; ++j) { CIMObjectPath currentReferenceName = referenceNamesResults[j]; Boolean found = false; for(unsigned int k = 0; k < numResults; ++k) { if(currentReferenceName == referencesResults[k].getPath()) { found = true; break; } } if(!found) { failure = true; break; } } // Check that that results for the associatorNames call is // consistent with the associators call and the references // call. for(j = 0; j < numResults; ++j) { CIMObjectPath currentAssociatorName = associatorNamesResults[j]; Boolean found = false; unsigned int k = 0; for(k = 0; k < numResults; ++k) { if(currentAssociatorName == associatorsResults[k].getPath()) { found = true; break; } } if(!found) { failure = true; break; } found = false; for(k = 0; k < numResults; ++k) { CIMObject referenceInstance = referencesResults[k]; for(unsigned int x = 0, m = referenceInstance.getPropertyCount(); x < m; ++x) { CIMProperty currentProp = referenceInstance.getProperty(x); if(currentProp.getType() == CIMTYPE_REFERENCE) { CIMObjectPath currentRef; currentProp.getValue().get(currentRef); currentRef.setHost( currentAssociatorName.getHost()); if(currentRef == currentAssociatorName) { found = true; break; } } } if(found) break; } if(!found) { failure = true; break; } } } if(failure) { exitFailure( String("Association Operations returned inconsistent ") + String("results for instance ") + currentPath.toString()); } } catch(CIMException & e) { exitFailure(String("Caught exception while performing ") + String("association operations on instance ") + currentPath.toString() + String(": ") + e.getMessage()); } } cout << "Test Complete" << endl; }
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(); }
void testAssociationClass(CIMClient & client, const CIMName & className) { cout << "Testing Association Class " << (const char *)className.getString().getCString() << "..."; Array<CIMInstance> instances = testAnyClass(client, className); for(unsigned int i = 0, n = instances.size(); i < n; ++i) { // // Now make sure that the references are valid and that association // traversal between them is working properly. // CIMObjectPath referenceA; CIMObjectPath referenceB; CIMInstance currentInstance = instances[i]; CIMObjectPath currentInstanceName = currentInstance.getPath(); if(currentInstanceName.getNameSpace().isNull()) currentInstanceName.setNameSpace(interopNamespace); for(unsigned int j = 0, m = currentInstance.getPropertyCount(); j < m; ++j) { CIMProperty currentProp = currentInstance.getProperty(j); if(currentProp.getValue().getType() == CIMTYPE_REFERENCE) { if(referenceA.getKeyBindings().size() == 0) { currentProp.getValue().get(referenceA); } else { currentProp.getValue().get(referenceB); break; } } } if(referenceA.getKeyBindings().size() == 0 || referenceB.getKeyBindings().size() == 0) { exitFailure( String("Could not find reference properties for ") + String("association: ") + currentInstanceName.toString()); } try { client.getInstance(referenceA.getNameSpace(), referenceA); client.getInstance(referenceB.getNameSpace(), referenceB); } catch(CIMException &) { exitFailure(String("Could not get instances for association : ") + currentInstanceName.toString()); } Boolean associationFailure = false; try { Array<CIMObjectPath> results = client.associatorNames( referenceA.getNameSpace(), referenceA, className); Boolean found = false; for(unsigned int j = 0, m = results.size(); j < m; ++j) { CIMObjectPath result = results[j]; result.setHost(referenceB.getHost()); result.setNameSpace(referenceB.getNameSpace()); if(result == referenceB) { found = true; break; } } if(found) { results = client.associatorNames(referenceB.getNameSpace(), referenceB, className); for(unsigned int j = 0, m = results.size(); j < m; ++j) { CIMObjectPath result = results[j]; result.setHost(referenceA.getHost()); result.setNameSpace(referenceA.getNameSpace()); if(result == referenceA) { found = true; break; } } } if(!found) { associationFailure = true; } } catch(CIMException & e) { cout << "Exception: " << e.getMessage() << endl; associationFailure = true; } if(associationFailure) { exitFailure(String("Association traversal failed between ") + String("instances of association: ") + currentInstanceName.toString()); } Boolean referencesFailure = false; try { Array<CIMObjectPath> results = client.referenceNames( referenceA.getNameSpace(), referenceA, className); Boolean found = false; for(unsigned int j = 0, m = results.size(); j < m; ++j) { CIMObjectPath currentPath = results[j]; if(currentPath.getNameSpace().isNull()) currentPath.setNameSpace(interopNamespace); if(currentPath.getHost().size() != 0) currentPath.setHost(String::EMPTY); if(currentPath == currentInstanceName) { found = true; break; } } if(found) { results = client.referenceNames(referenceB.getNameSpace(), referenceB, className); for(unsigned int j = 0, m = results.size(); j < m; ++j) { CIMObjectPath currentPath = results[j]; if(currentPath.getNameSpace().isNull()) currentPath.setNameSpace(interopNamespace); if(currentPath.getHost().size() != 0) currentPath.setHost(String::EMPTY); if(currentPath == currentInstanceName) { found = true; break; } } } if(!found) { referencesFailure = true; } } catch(CIMException &) { referencesFailure = true; } if(referencesFailure) { exitFailure(String("References operation failed for ") + String("instances of association: ") + currentInstanceName.toString()); } } cout << "Test Complete" << endl; }
Array<CIMInstance> InteropProvider::getReferencedInstances( const Array<CIMInstance> &refs, const String &targetRole, const OperationContext & context, const CIMPropertyList & propertyList) { PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::getReferencedObjects"); Array<CIMInstance> referencedInstances; Array<CIMInstance> classInstances; CIMName prevClassName; ConstArrayIterator<CIMInstance> refsIter(refs); for(Uint32 i = 0; i < refsIter.size(); i++) { CIMInstance thisRef = refsIter[i]; CIMObjectPath thisTarget = getRequiredValue<CIMObjectPath>( thisRef, targetRole); // Test if we're looking for something outside of our namespace. This // will happen during associators calls from PG_RegisteredProfile // instances through the PG_ElementConformsToProfile association CIMNamespaceName opNamespace = thisTarget.getNameSpace(); CIMName opClass = thisTarget.getClassName(); if((opNamespace != PEGASUS_NAMESPACENAME_INTEROP && opClass != PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE) // Get CIM_IndicationService instance from IndicationService. #ifdef PEGASUS_ENABLE_DMTF_INDICATION_PROFILE_SUPPORT || opClass == PEGASUS_CLASSNAME_CIM_INDICATIONSERVICE #endif ) { AutoMutex mut(interopMut); CIMInstance gotInstance = cimomHandle.getInstance( context, opNamespace, thisTarget, false, false, false, propertyList); referencedInstances.append(gotInstance); continue; } TARGET_CLASS classEnum = translateClassInput(opClass); CIMInstance retInstance; switch(classEnum) { case PG_SOFTWAREIDENTITY: { CIMInstance retInstance = getSoftwareIdentityInstance(thisTarget); normalizeInstance( retInstance, thisTarget, false, false, propertyList); retInstance.setPath(thisTarget); referencedInstances.append(retInstance); } break; case PG_NAMESPACE: { CIMInstance retInstance = getNameSpaceInstance(thisTarget); normalizeInstance( retInstance, thisTarget, false, false, propertyList); retInstance.setPath(thisTarget); referencedInstances.append(retInstance); } break; default: { if( opClass != prevClassName ) { CIMObjectPath ref; ref.setHost(thisTarget.getHost()); ref.setClassName(thisTarget.getClassName()); ref.setNameSpace(thisTarget.getNameSpace()); classInstances = localEnumerateInstances( context, ref, propertyList); ArrayIterator<CIMInstance> instsIter(classInstances); for(Uint32 n = 0; n < instsIter.size(); n++) { CIMObjectPath tmpInst = instsIter[n].getPath(); tmpInst.setHost(thisTarget.getHost()); tmpInst.setNameSpace(thisTarget.getNameSpace()); instsIter[n].setPath(tmpInst); } prevClassName = opClass; } ConstArrayIterator<CIMInstance> instsConstIter(classInstances); for(Uint32 j = 0; j < instsConstIter.size(); j++) { if(thisTarget == instsConstIter[j].getPath()) { referencedInstances.append(instsConstIter[j]); break; } } } break; } } PEG_METHOD_EXIT(); return referencedInstances; }
// // Local version of getInstance to be used by other functions in the the // provider. Returns a single instance. Note that it always returns an // instance. If none was found, it is uninialitized. // CIMInstance InteropProvider::localGetInstance( const OperationContext & context, const CIMObjectPath & instanceName, const CIMPropertyList & propertyList) { PEG_METHOD_ENTER(TRC_CONTROLPROVIDER, "InteropProvider::localGetInstance"); PEG_TRACE((TRC_CONTROLPROVIDER, Tracer::LEVEL4, "%s getInstance. instanceName= %s , PropertyList= %s", thisProvider, (const char *)instanceName.toString().getCString(), (const char *)propertyList.toString().getCString())); // Test if we're looking for something outside of our namespace. This will // happen during associators calls from PG_RegisteredProfile instances // through the PG_ElementConformsToProfile association CIMNamespaceName opNamespace = instanceName.getNameSpace(); CIMName opClass = instanceName.getClassName(); if((opNamespace != PEGASUS_NAMESPACENAME_INTEROP && opClass != PEGASUS_CLASSNAME_PG_ELEMENTCONFORMSTOPROFILE) // Get CIM_IndicationService instance from IndicationService. #ifdef PEGASUS_ENABLE_DMTF_INDICATION_PROFILE_SUPPORT || opClass == PEGASUS_CLASSNAME_CIM_INDICATIONSERVICE #endif ) { AutoMutex mut(interopMut); CIMInstance gotInstance = cimomHandle.getInstance( context, opNamespace, instanceName, false, false, false, propertyList); PEG_METHOD_EXIT(); return gotInstance; } TARGET_CLASS classEnum = translateClassInput(opClass); CIMInstance retInstance; switch(classEnum) { case PG_SOFTWAREIDENTITY: { retInstance = getSoftwareIdentityInstance(instanceName); normalizeInstance( retInstance, instanceName, false, false, propertyList); } break; case PG_NAMESPACE: { retInstance = getNameSpaceInstance(instanceName); normalizeInstance( retInstance, instanceName, false, false, propertyList); } break; // ATTN: Implement getIntstance for all other classes. Currently // this method calls localEnumerateInstances() to select instance // which is too expensive. default: { // Create reference from host, namespace, class components of // instance name CIMObjectPath ref; ref.setHost(instanceName.getHost()); ref.setClassName(opClass); ref.setNameSpace(opNamespace); // Enumerate instances for this class. Returns all instances // Note that this returns paths setup and instances already // filtered per the input criteria. Array<CIMInstance> instances = localEnumerateInstances( context, ref, propertyList); ConstArrayIterator<CIMInstance> instancesIter(instances); // deliver a single instance if found. bool found = false; for(Uint32 i = 0; i < instancesIter.size(); i++) { CIMObjectPath currentInstRef = instancesIter[i].getPath(); currentInstRef.setHost(instanceName.getHost()); currentInstRef.setNameSpace(instanceName.getNameSpace()); if(instanceName == currentInstRef) { retInstance = instancesIter[i]; found = true; break; } } if (!found) { PEG_METHOD_EXIT(); throw CIMObjectNotFoundException(instanceName.toString()); } } } PEG_METHOD_EXIT(); return retInstance; }
void MCCA_TestAssocProvider::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) { CDEBUG("MCCA_TestAssocProvider::associators() called."); // create a new CIMInstance based on class with name className CIMInstance constructedInstance = CIMInstance(testClassName); CIMObjectPath targetObjectPath = CIMObjectPath(); Array<CIMKeyBinding> keyBindings = Array<CIMKeyBinding>(); Uint32 sourceKey = 0; CDEBUG("Initialisation ended."); handler.processing(); CDEBUG("handler.processing started."); // we do ignore role, resultRole, includeQualifiers, includeClassOrigin, // propertyList CDEBUG("Next building object path."); ///////////////////////////////////////////////////////////////////// // BUILD OBJECTPATH ///////////////////////////////////////////////////////////////////// // preparing object path first targetObjectPath.setHost("localhost:5988"); targetObjectPath.setClassName(testClassName); CDEBUG("Host and classname set, host=" << objectName.getHost()); // determine if source namespace is namespace A or B // and build respective target namespace ... if (objectName.getNameSpace().equal(nameSpaceA)) { targetObjectPath.setNameSpace(nameSpaceB); } if (objectName.getNameSpace().equal(nameSpaceB)) { targetObjectPath.setNameSpace(nameSpaceA); } CDEBUG("NameSpace set."); // determine key of source object so we can create target object Array<CIMKeyBinding> sourceKeyBindings = objectName.getKeyBindings(); CDEBUG("Determining sourceKey."); // only one keyvalue, so we take that first one String keyValueString = String(sourceKeyBindings[0].getValue()); CDEBUG("keyValueString=" << keyValueString); sourceKey = strtoul((const char*) keyValueString.getCString(), NULL, 0); CDEBUG("sourceKey=" << sourceKey); CIMKeyBinding testClassKey = CIMKeyBinding(CIMName("theKey"), CIMValue(sourceKey) ); CDEBUG("Created new KeyBinding testClassKey."); // testClassKey.setValue(keyValueString); CDEBUG("sourceKey = string(set keybinding),int(sourceKey)" << testClassKey.getValue() << "," << sourceKey); keyBindings.append(testClassKey); CDEBUG("Appended(testClassKey)."); targetObjectPath.setKeyBindings(keyBindings); ///////////////////////////////////////////////////////////////////// // ADD PROPERTIES ///////////////////////////////////////////////////////////////////// // add properties to the CIMInstance object constructedInstance.addProperty( CIMProperty( CIMName("theKey"), sourceKey)); constructedInstance.addProperty( CIMProperty( CIMName("theData"), 20+sourceKey)); char buffer[100]; sprintf(buffer,"ABC-%u",20*sourceKey+sourceKey); constructedInstance.addProperty(CIMProperty(CIMName ("theString"), String(buffer))); CDEBUG("Added properties to the CIMInstance object"); CIMObject cimObject(constructedInstance); cimObject.setPath (targetObjectPath); // lets deliver all instances of CIMObjectpaths I do think are okay handler.deliver(cimObject); // complete processing the request handler.complete(); CDEBUG("Association call conmplete."); }
///////////////////////////////////////////////////////////////////////////// // WMIInstanceProvider::enumerateInstanceNames // // /////////////////////////////////////////////////////////////////////////// Array<CIMObjectPath> WMIInstanceProvider::enumerateInstanceNames( const String& nameSpace, const String& userName, const String& password, const String& className) { HRESULT hr; long lCount = 0; DWORD dwReturned; CComPtr<IEnumWbemClassObject> pInstEnum; CComPtr<IWbemClassObject> pInstance; Array<CIMObjectPath> instanceNames; PEG_METHOD_ENTER(TRC_WMIPROVIDER, "WMIInstanceProvider::enumerateInstanceNames()"); setup(nameSpace, userName, password); if (!m_bInitialized) { PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL1, "WMIInstanceProvider::enumerateInstanceNames - m_bInitilized= %x," " throw CIM_ERR_FAILED exception", m_bInitialized)); throw CIMException(CIM_ERR_FAILED); } // retrieve the instance enumeration object if (!(_collector->getInstanceEnum(&pInstEnum, className, TRUE))) { if (pInstEnum) pInstEnum.Release(); throw CIMException(CIM_ERR_FAILED); } // set proxy security on pInstEnum bool bSecurity = _collector->setProxySecurity(pInstEnum); // Get the names of the instances and send to handler hr = pInstEnum->Next(WBEM_INFINITE, 1, &pInstance, &dwReturned); while (SUCCEEDED(hr) && (1 == dwReturned)) { CIMInstance tempInst(className); if (_collector->getCIMInstance(pInstance, tempInst, FALSE, FALSE, FALSE)) { //new code CIMObjectPath tempRef; CComVariant vAux; char * strAux = NULL; //set hostname if (pInstance->Get(L"__SERVER", 0, &vAux, NULL, NULL) != S_OK) throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Failed to retrieve WMI Data."); strAux = new char[wcslen(vAux.bstrVal)+1]; if (strAux == NULL) throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Out of Memory."); wcstombs(strAux, vAux.bstrVal, wcslen(vAux.bstrVal)+1); tempRef.setHost(strAux); delete [] strAux; strAux = NULL; vAux.Clear(); //set class name if (pInstance->Get(L"__CLASS", 0, &vAux, NULL, NULL) != S_OK) throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Failed to retrieve WMI Data."); strAux = new char[wcslen(vAux.bstrVal)+1]; if (strAux == NULL) throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Out of Memory."); wcstombs(strAux, vAux.bstrVal, wcslen(vAux.bstrVal)+1); tempRef.setClassName(strAux); delete [] strAux; strAux = NULL; vAux.Clear(); //set namespace if (pInstance->Get(L"__NAMESPACE", 0, &vAux, NULL, NULL) != S_OK) throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Failed to retrieve WMI Data."); strAux = new char[wcslen(vAux.bstrVal)+1]; if (strAux == NULL) throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Out of Memory."); wcstombs(strAux, vAux.bstrVal, wcslen(vAux.bstrVal)+1); //converts '\' to '/' _translateBackslashes(strAux); tempRef.setNameSpace(strAux); delete [] strAux; strAux = NULL; vAux.Clear(); //get key bindings SAFEARRAY * aNames; if (pInstance->GetNames(NULL, WBEM_FLAG_KEYS_ONLY, NULL, &aNames) != S_OK) throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Failed to retrieve WMI Data."); LONG lLBuond; LONG lUBuond; SafeArrayGetLBound(aNames, 1, &lLBuond); SafeArrayGetUBound(aNames, 1, &lUBuond); Array<CIMKeyBinding> keyBindings; for(LONG i = lLBuond; i <=lUBuond; i++) { CComBSTR bstrName; SafeArrayGetElement(aNames, &i, &bstrName); char * strPropertyName = new char[bstrName.Length()+1]; if (strPropertyName == NULL) throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Out of Memory."); wcstombs(strPropertyName, bstrName, bstrName.Length()+1); CIMName keyname(strPropertyName); Uint32 Index = tempInst.findProperty(keyname); if (Index == PEG_NOT_FOUND) throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Failed to retrieve WMI Data."); CIMValue keyvalue = tempInst.getProperty(Index).getValue(); CIMKeyBinding key(keyname, keyvalue); keyBindings.append(key); delete [] strPropertyName; } SafeArrayDestroy(aNames); tempRef.setKeyBindings(keyBindings); instanceNames.append(tempRef); } if (pInstance) pInstance.Release(); hr = pInstEnum->Next(WBEM_INFINITE, 1, &pInstance, &dwReturned); } if (pInstEnum) pInstEnum.Release(); PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL4, "WMIInstanceProvider::enumerateInstanceNames() -" " Instance count is %d", lCount)); if (lCount == 0) { PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL2, "WMIInstanceProvider::enumerateInstanceNames() -" " hResult value is %x", hr)); } PEG_METHOD_EXIT(); return instanceNames; }