void test01() { // class MyClass : YourClass // { // string message = "Hello"; // } try { CIMName a = "A_class1"; CIMName b = "A_class2"; CIMClass c0(a, b); CIMClass c1(a, CIMName("A_class2")); CIMClass c2(CIMName("A_class1"), b); CIMClass c3(b, a); } catch (InvalidNameException & ine) { if (verbose) { cout << "Caught unexpected exception: " << ine.getMessage() << endl; } } try { // // Invalid class name // CIMClass class0(CIMName ("//localhost/root/cimv2:MyClass"), CIMName ("YourClass")); PEGASUS_TEST_ASSERT(class0.getPath() == CIMObjectPath("//localhost/root/cimv2:MyClass")); } catch (InvalidNameException & ine) { if (verbose) { cout << "Caught expected exception: " << ine.getMessage() << endl; } } CIMClass class1(CIMName ("MyClass"), CIMName ("YourClass")); class1 .addQualifier(CIMQualifier(CIMName ("association"), true)) .addQualifier(CIMQualifier(CIMName ("q1"), Uint32(55))) .addQualifier(CIMQualifier(CIMName ("q2"), String("Hello"))) .addProperty(CIMProperty(CIMName ("message"), String("Hello"))) .addProperty(CIMProperty(CIMName ("count"), Uint32(77), 0, CIMName(), CIMName("YourClass"), true)) .addMethod(CIMMethod(CIMName ("isActive"), CIMTYPE_BOOLEAN) .addParameter(CIMParameter(CIMName ("hostname"), CIMTYPE_STRING)) .addParameter(CIMParameter(CIMName ("port"), CIMTYPE_UINT32))); // Test the method count function PEGASUS_TEST_ASSERT(class1.getClassName().equal(CIMName ("myclass"))); PEGASUS_TEST_ASSERT(class1.getSuperClassName() == CIMName ("YourClass")); PEGASUS_TEST_ASSERT(class1.getMethodCount() ==1); // Test the findMethod and isMethod functions PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("isActive")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("DoesNotExist")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("isActive")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("DoesNotExist")) == PEG_NOT_FOUND); // Test the manipulation of an embeddedObjectProperty CIMClass embedClass(CIMName ("embedObj"), CIMName ()); class1.addProperty(CIMProperty(CIMName ("embedObj"), CIMObject(embedClass), 0, CIMName(), CIMName(), false)); PEGASUS_TEST_ASSERT(class1.findProperty( CIMName ("embedObj")) != PEG_NOT_FOUND); Uint32 posProp = class1.findProperty(CIMName ("embedObj")); CIMConstProperty constprop1 = class1.getProperty(posProp); PEGASUS_TEST_ASSERT(constprop1.getClassOrigin() == CIMName()); PEGASUS_TEST_ASSERT(constprop1.getType() == CIMTYPE_OBJECT); class1.removeProperty(posProp); // Now add another method and reconfirm. class1.addMethod(CIMMethod(CIMName ("makeActive"), CIMTYPE_BOOLEAN) .addParameter(CIMParameter(CIMName ("hostname"), CIMTYPE_STRING)) .addParameter(CIMParameter(CIMName ("port"), CIMTYPE_UINT32))); PEGASUS_TEST_ASSERT(class1.getMethodCount() == 2); // Test the findMethod and isMethod functions // with two methods defined PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("isActive")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("makeActive")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("DoesNotExist")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("isActive")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("makeActive")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("DoesNotExist")) == PEG_NOT_FOUND); // Test RemoveMethod function Uint32 posMethod; posMethod = class1.findMethod(CIMName ("isActive")); PEGASUS_TEST_ASSERT(posMethod != PEG_NOT_FOUND); class1.removeMethod(posMethod); PEGASUS_TEST_ASSERT(class1.findMethod( CIMName ("isActive")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.getMethodCount() == 1); //ATTN: P3 TODO add tests for different case names //Qualifier manipulation tests (find, remove) PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q1")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q2")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("qx")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q1")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q2")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findQualifier( CIMName ("association")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.isAssociation()); // Remove middle Qualifier "q2" Uint32 posQualifier; posQualifier = class1.findQualifier(CIMName ("q2")); CIMConstQualifier qconst = class1.getQualifier(posQualifier); PEGASUS_TEST_ASSERT(class1.getQualifierCount() == 3); PEGASUS_TEST_ASSERT(posQualifier <= class1.getQualifierCount()); class1.removeQualifier(posQualifier); PEGASUS_TEST_ASSERT(class1.getQualifierCount() == 2); PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q2")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q1")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.isAssociation()); // Remove the first parameter "q1" posQualifier = class1.findQualifier(CIMName ("q1")); PEGASUS_TEST_ASSERT(class1.getQualifierCount() == 2); CIMQualifier cq = class1.getQualifier( class1.findQualifier( CIMName ("q1"))); PEGASUS_TEST_ASSERT(posQualifier <= class1.getQualifierCount()); class1.removeQualifier(posQualifier); PEGASUS_TEST_ASSERT(class1.getQualifierCount() == 1); PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q1")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findQualifier(CIMName ("q2")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.isAssociation()); // ATTH: P3 Add tests for try block for outofbounds //The property manipulation tests. PEGASUS_TEST_ASSERT(class1.findProperty( CIMName ("count")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findProperty( CIMName ("message")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findProperty( CIMName ("isActive")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.getPropertyCount() == 2); Uint32 posProperty; posProperty = class1.findProperty(CIMName ("count")); CIMConstProperty constprop = class1.getProperty(posProperty); PEGASUS_TEST_ASSERT(constprop.getClassOrigin() == CIMName("YourClass")); PEGASUS_TEST_ASSERT(constprop.getPropagated()); class1.removeProperty(posProperty); PEGASUS_TEST_ASSERT(class1.findProperty( CIMName ("message")) != PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.findProperty( CIMName ("count")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(class1.getPropertyCount() == 1); CIMProperty cp = class1.getProperty( class1.findProperty (CIMName ("message"))); PEGASUS_TEST_ASSERT(cp.getClassOrigin().isNull()); PEGASUS_TEST_ASSERT(!cp.getPropagated()); if(verbose) { XmlWriter::printClassElement(class1); MofWriter::printClassElement(class1); } Buffer out; MofWriter::appendClassElement(out, class1); out.clear(); XmlWriter::appendClassElement(out, class1); PEGASUS_TEST_ASSERT(!class1.isAbstract()); CIMName squal("q1"); PEGASUS_TEST_ASSERT(class1.findQualifier(squal) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(!class1.hasKeys()); Array<CIMName> keyNames; class1.getKeyNames(keyNames); CIMClass c2(CIMName ("MyClass")); PEGASUS_TEST_ASSERT(c2.getClassName().equal(CIMName ("myclass"))); // Error uninitialized handle c2.setSuperClassName(CIMName ("CIM_Element")); PEGASUS_TEST_ASSERT(c2.getSuperClassName() == CIMName ("CIM_Element")); CIMClass c3 = c2.clone(); c3 = c2; try { CIMMethod cm = c2.getMethod(0); } catch(IndexOutOfBoundsException& e) { if(verbose) cout << "Exception: " << e.getMessage() << endl; } const CIMClass c4(CIMName ("MyClass"), CIMName ("YourClass")); CIMConstClass c5(CIMName ("MyClass"), CIMName ("YourClass")); CIMConstClass c6(CIMName ("MyClass")); CIMConstClass cc7(c6); CIMClass c7 = c5.clone(); const CIMClass c8(class1); // Test the findMethod and isMethod functions PEGASUS_TEST_ASSERT(c7.findMethod( CIMName ("DoesNotExist")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(c7.findQualifier(CIMName ("dummy")) == PEG_NOT_FOUND); try { CIMConstMethod cm = c8.getMethod(0); } catch(IndexOutOfBoundsException& e) { if(verbose) cout << "Exception: " << e.getMessage() << endl; } try { CIMConstProperty ccp = c8.getProperty(c8.findProperty (CIMName ("count"))); } catch(IndexOutOfBoundsException& e) { if(verbose) cout << "Exception: " << e.getMessage() << endl; } if(verbose) { XmlWriter::printClassElement(c5); } try { CIMConstMethod cm = cc7.getMethod(0); } catch(IndexOutOfBoundsException& e) { if(verbose) cout << "Exception: " << e.getMessage() << endl; } // Test the findMethod and isMethod functions PEGASUS_TEST_ASSERT(c4.findMethod( CIMName ("DoesNotExist")) == PEG_NOT_FOUND); //Qualifier manipulation tests (find, remove) PEGASUS_TEST_ASSERT(c4.findQualifier(CIMName ("qx")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(c4.findQualifier(CIMName ("q1")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(c4.findQualifier(CIMName ("q2")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(c4.findQualifier( CIMName ("association")) == PEG_NOT_FOUND); posProperty = c4.findProperty(CIMName ("count")); try { CIMConstQualifier ccq = c4.getQualifier(c4.findQualifier (CIMName ("q1"))); } catch (IndexOutOfBoundsException& e) { if(verbose) cout << "Exception: " << e.getMessage() << endl; } PEGASUS_TEST_ASSERT(c4.findProperty(CIMName ("count")) == PEG_NOT_FOUND); PEGASUS_TEST_ASSERT(c4.getClassName() == CIMName ("MyClass")); PEGASUS_TEST_ASSERT(c4.getClassName().equal(CIMName ("MyClass"))); PEGASUS_TEST_ASSERT(c4.getClassName().equal(CIMName ("MYCLASS"))); PEGASUS_TEST_ASSERT(c4.getClassName().equal(CIMName ("myclass"))); PEGASUS_TEST_ASSERT(!c4.getClassName().equal(CIMName ("blob"))); PEGASUS_TEST_ASSERT(c4.getSuperClassName() == CIMName ("YourClass")); // test the setSuperClassName function /* ATTN KS 29 April. This test has problems. Relook later. Think test, not code. c4.setSuperClassName(CIMName ("JunkClass")); PEGASUS_TEST_ASSERT(c4.getSuperClassName() == CIMName ("JunkClass")); c4.setSuperClassName(CIMName ("YourClass")); */ PEGASUS_TEST_ASSERT(c5.getSuperClassName() == CIMName ("YourClass")); PEGASUS_TEST_ASSERT(c5.getQualifierCount() == 0); posQualifier = c5.findQualifier(CIMName ("q2")); // throws out of bounds try { CIMConstQualifier qconst1 = c5.getQualifier(posQualifier); } catch(IndexOutOfBoundsException& e) { if(verbose) cout << "Exception: " << e.getMessage() << endl; } if(verbose) { cout << "All tests" << endl; } }
void WQLSelectStatementRep::validate() { if(_ctx == NULL){ MessageLoaderParms parms( "WQL.WQLSelectStatementRep.QUERY_CONTEXT_IS_NULL", "Trying to process a query with a NULL Query Context."); throw QueryValidationException(parms); } CIMClass fromClass; try { fromClass = _ctx->getClass(_className); CIMObjectPath className (String::EMPTY, _ctx->getNamespace (), _className); Array<CIMName> whereProps = getWherePropertyList(className).getPropertyNameArray(); Array<CIMName> selectProps = getSelectPropertyList(className).getPropertyNameArray(); // make sure all properties match properties on the from class for(Uint32 i = 0; i < whereProps.size(); i++){ Uint32 index = fromClass.findProperty(whereProps[i]); if(index == PEG_NOT_FOUND){ MessageLoaderParms parms( "WQL.WQLSelectStatementRep.PROP_NOT_FOUND", "The property $0 was not found in the FROM class $1", whereProps[i].getString(), fromClass.getClassName().getString()); throw QueryMissingPropertyException(parms); } else { // // Property exists in class // Verify it is not an array property // CIMProperty classProperty = fromClass.getProperty(index); if (classProperty.isArray ()) { MessageLoaderParms parms( "WQL.WQLSelectStatementRep.WHERE_PROP_IS_ARRAY", "Array property $0 is not supported in the WQL WHERE clause.", whereProps[i].getString()); throw QueryValidationException(parms); } } } for(Uint32 i = 0; i < selectProps.size(); i++){ if(fromClass.findProperty(selectProps[i]) == PEG_NOT_FOUND){ MessageLoaderParms parms( "WQL.WQLSelectStatementRep.PROP_NOT_FOUND", "The property $0 was not found in the FROM class $1", selectProps[i].getString(), fromClass.getClassName().getString()); throw QueryMissingPropertyException(parms); } } } catch (const CIMException& ce) { if (ce.getCode() == CIM_ERR_INVALID_CLASS || ce.getCode() == CIM_ERR_NOT_FOUND) { MessageLoaderParms parms( "WQL.WQLSelectStatementRep.CLASSNAME_NOT_IN_REPOSITORY", "The class name $0 was not found in the repository.", _className.getString()); throw QueryValidationException(parms); } else { throw; } } }
// 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(); }
// l10n - note: ignoring indication language void snmpIndicationHandler::handleIndication( const OperationContext& context, const String nameSpace, CIMInstance& indication, CIMInstance& handler, CIMInstance& subscription, ContentLanguages & contentLanguages) { Array<String> propOIDs; Array<String> propTYPEs; Array<String> propVALUEs; CIMProperty prop; CIMQualifier trapQualifier; Uint32 qualifierPos; String propValue; String mapstr1; String mapstr2; PEG_METHOD_ENTER (TRC_IND_HANDLER, "snmpIndicationHandler::handleIndication"); try { CIMClass indicationClass = _repository->getClass( nameSpace, indication.getClassName(), false, true, false, CIMPropertyList()); Uint32 propertyCount = indication.getPropertyCount(); for (Uint32 i=0; i < propertyCount; i++) { prop = indication.getProperty(i); if (!prop.isUninitialized()) { CIMName propName = prop.getName(); Uint32 propPos = indicationClass.findProperty(propName); if (propPos != PEG_NOT_FOUND) { CIMProperty trapProp = indicationClass.getProperty(propPos); qualifierPos = trapProp.findQualifier(CIMName ("MappingStrings")); if (qualifierPos != PEG_NOT_FOUND) { trapQualifier = trapProp.getQualifier(qualifierPos); mapstr1.clear(); mapstr1 = trapQualifier.getValue().toString(); if ((mapstr1.find("OID.IETF") != PEG_NOT_FOUND) && (mapstr1.find("DataType.IETF") != PEG_NOT_FOUND)) { if (mapstr1.subString(0, 8) == "OID.IETF") { mapstr1 = mapstr1.subString(mapstr1.find("SNMP.")+5); if (mapstr1.find("|") != PEG_NOT_FOUND) { mapstr2.clear(); mapstr2 = mapstr1.subString(0, mapstr1.find("DataType.IETF")-1); propOIDs.append(mapstr2); propValue.clear(); propValue = prop.getValue().toString(); propVALUEs.append(propValue); mapstr2 = mapstr1.subString(mapstr1.find("|")+2); mapstr2 = mapstr2.subString(0, mapstr2.size()-1); propTYPEs.append(mapstr2); } } } } } } } // Collected complete data in arrays and ready to send the trap. // trap destination and SNMP type are defined in handlerInstance // and passing this instance as it is to deliverTrap() call #ifdef HPUX_EMANATE static snmpDeliverTrap_emanate emanateTrap; #else static snmpDeliverTrap_stub emanateTrap; #endif Uint32 targetHostPos = handler.findProperty(CIMName ("TargetHost")); Uint32 targetHostFormatPos = handler.findProperty(CIMName ("TargetHostFormat")); Uint32 otherTargetHostFormatPos = handler.findProperty(CIMName ( "OtherTargetHostFormat")); Uint32 portNumberPos = handler.findProperty(CIMName ("PortNumber")); Uint32 snmpVersionPos = handler.findProperty(CIMName ("SNMPVersion")); Uint32 securityNamePos = handler.findProperty(CIMName ("SNMPSecurityName")); Uint32 engineIDPos = handler.findProperty(CIMName ("SNMPEngineID")); if ((targetHostPos != PEG_NOT_FOUND) && (targetHostFormatPos != PEG_NOT_FOUND) && (snmpVersionPos != PEG_NOT_FOUND) && (indicationClass.findQualifier(CIMName ("MappingStrings")) != PEG_NOT_FOUND)) { // properties from the handler instance String targetHost; String otherTargetHostFormat = String(); String securityName = String(); String engineID = String(); Uint16 targetHostFormat = 0; Uint16 snmpVersion = 0; Uint32 portNumber; String trapOid; // // Get snmpTrapOid from context // try { SnmpTrapOidContainer trapContainer = context.get (SnmpTrapOidContainer::NAME); trapOid = trapContainer.getSnmpTrapOid(); } catch (Exception& e) { // get trapOid from indication Class Uint32 pos = indicationClass.findQualifier(CIMName ("MappingStrings")); if (pos != PEG_NOT_FOUND) { trapOid = indicationClass.getQualifier(pos).getValue().toString(); trapOid = trapOid.subString(11, PEG_NOT_FOUND); if ((String::compare(trapOid, "SNMP.", 5)) == 0) { trapOid = trapOid.subString(5, (trapOid.size()-6)); } else { PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, "Invalid MappingStrings Value " + trapOid); PEG_METHOD_EXIT(); // l10n // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Invalid MappingStrings Value"); throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED, MessageLoaderParms("Handler.snmpIndicationHandler.snmpIndicationHandler.INVALID_MS_VALUE", "Invalid MappingStrings Value")); } } else { PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, "Qualifier MappingStrings can not be found."); PEG_METHOD_EXIT(); //L10N_ TODO DONE //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Qualifier MappingStrings can not be found"); MessageLoaderParms parms("Handler.snmpIndicationHandler.snmpIndicationHandler.QUALIFIER_MAPPINGS_NOT_FOUND", "Qualifier MappingStrings can not be found"); throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, parms); } } handler.getProperty(targetHostPos).getValue().get(targetHost); handler.getProperty(targetHostFormatPos).getValue().get(targetHostFormat); if (otherTargetHostFormatPos != PEG_NOT_FOUND) { handler.getProperty(otherTargetHostFormatPos).getValue().get (otherTargetHostFormat); } if (portNumberPos != PEG_NOT_FOUND) { handler.getProperty(portNumberPos).getValue().get(portNumber); } else { // default port portNumber = SNMP_TRAP_DEFAULT_PORT; } handler.getProperty(snmpVersionPos).getValue().get(snmpVersion); if (securityNamePos != PEG_NOT_FOUND) { handler.getProperty(securityNamePos).getValue().get(securityName); } if (engineIDPos != PEG_NOT_FOUND) { handler.getProperty(engineIDPos).getValue().get(engineID); } emanateTrap.deliverTrap( trapOid, securityName, targetHost, targetHostFormat, otherTargetHostFormat, portNumber, snmpVersion, engineID, propOIDs, propTYPEs, propVALUEs); } else { PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, "Invalid IndicationHandlerSNMPMapper instance."); PEG_METHOD_EXIT(); // l10n // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, // "Invalid IndicationHandlerSNMPMapper instance"); throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED, MessageLoaderParms("Handler.snmpIndicationHandler.snmpIndicationHandler.INVALID_SNMP_INSTANCE", "Invalid IndicationHandlerSNMPMapper instance")); } } catch (CIMException & c) { PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, c.getMessage()); PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, c.getMessage()); } catch (Exception& e) { PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, e.getMessage()); PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, e.getMessage()); } catch (...) { PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, "Failed to deliver trap."); PEG_METHOD_EXIT(); throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED, MessageLoaderParms("Handler.snmpIndicationHandler.snmpIndicationHandler.FAILED_TO_DELIVER_TRAP", "Failed to deliver trap.")); } }