PEGASUS_NAMESPACE_BEGIN //////////////////////////////////////////////////////////////// // // addQualifiersToCIMParameter // // Add qualifiers from a WMI class to a CIMParameter. // /////////////////////////////////////////////////////////////// void addQualifiersToCIMParameter(const CIMQualifierList& cimQualifierList, CIMParameter& cimParam, Boolean includeQualifiers) { static const CIMName idName("ID"); static const CIMName inName("in"); static const CIMName outName("out"); for (Uint32 i = 0, n = cimQualifierList.getCount(); i < n; i++) { CIMQualifier cimQual = cimQualifierList.getQualifier(i); // Add this qualifier if includeQualifiers is true or if // this is an "ID", "in", or "out" qualifier: if (includeQualifiers || cimQual.getName().equal(inName) || cimQual.getName().equal(outName) || cimQual.getName().equal(idName)) { cimParam.addQualifier(cimQualifierList.getQualifier(i)); } } }
CIMQualifier CIMMethod::getQualifier(const CIMName& name) const { int tsize = m_pdata->m_qualifiers.size(); for (int i = 0; i < tsize; i++) { CIMQualifier nq = m_pdata->m_qualifiers[i]; if (nq.getName() == name) { return nq; } } return CIMQualifier(CIMNULL); }
CIMParameterArray CIMMethod::getINParameters() const { CIMParameterArray rval; for (size_t i = 0; i < m_pdata->m_parameters.size(); ++i) { // TODO // Note: The following code assumes the default value for the // CIM_QUAL_IN qualifier is true. The is per the CIM 2.2 spec. // THE SPEC ALSO STATES THAT THE DEFAULT VALUE FOR QUALIFIERS CAN // BE CHANGED. CIMQualifier q = m_pdata->m_parameters[i].getQualifier(CIMQualifier::CIM_QUAL_IN); if (!q || q.getValue() == CIMValue(true)) { rval.push_back(m_pdata->m_parameters[i]); } } return rval; }
int _getClass(const int argc, const char **argv) { CIMClass cldef; try { cldef = _c.getClass( PEGASUS_NAMESPACENAME_INTEROP, argv[0] ); } catch (Exception& e) { cerr << /* "getClass: " << */ e.getMessage() << endl; return 1; } // Display the class definition // without qualifiers, for the moment // First the class name and superclass cout << "class " << cldef.getClassName().getString() << " : " << cldef.getSuperClassName().getString() << endl; cout << "{" << endl; // Now the properties // No qualifiers except [key], but specify type, array for (int i=0; i<cldef.getPropertyCount(); i++) { CIMProperty p = cldef.getProperty(i); cout << " "; // output key, if required if (_isKey(p)) cout << "[ Key ] "; // prepare to output type, but // first, if type is "reference", find target class if (p.getType() == CIMTYPE_REFERENCE) cout << p.getReferenceClassName().getString() << " REF "; // output type else cout << cimTypeToString(p.getType()) << " "; // output name cout << p.getName().getString(); // output array, if required if (p.isArray()) cout << "[]"; // final eol cout << ";" << endl; } // need to do methods for (int i=0; i<cldef.getMethodCount(); i++) { CIMMethod m = cldef.getMethod(i); // output type cout << " " << cimTypeToString(m.getType()) << " "; // output name cout << m.getName().getString() << "("; // output parameters // new line if there are any parameters for (int j=0; j<m.getParameterCount(); j++) { CIMParameter p = m.getParameter(j); // output IN/OUT qualifiers on a fresh line cout << endl << " [ "; // loop through qualifiers looking for IN, OUT for (int k=0; k<p.getQualifierCount(); k++) { // when one found, output its value CIMQualifier q = p.getQualifier(k); if (q.getName().equal("in") || q.getName().equal("out")) { cout << q.getName().getString() << " "; } } // Now the type cout << "] " << cimTypeToString(p.getType()) << " "; // finally the name cout << p.getName().getString(); // array brackets if (p.isArray()) cout << "[]"; // closing , on parameter if not last if (j != m.getParameterCount()-1) cout << ","; } // after last param, indent before closing paren // close paren cout << ")"; // if (m.isArray()) cout << "[]"; // finish output cout << ";" << endl; } // final brace and done cout << "};" << endl; return 0; }
void CIMQualifierList::resolve( DeclContext* declContext, const CIMNamespaceName & nameSpace, CIMScope scope, // Scope of the entity being resolved. Boolean isInstancePart, CIMQualifierList& inheritedQualifiers, Boolean propagateQualifiers) { _keyIndex = PEGASUS_ORDEREDSET_INDEX_UNKNOWN; PEG_METHOD_ENTER(TRC_OBJECTRESOLUTION, "CIMQualifierList::resolve()"); // For each qualifier in the qualifiers array, the following // is checked: // // 1. Whether it is declared (can be obtained from the declContext). // // 2. Whether it has the same type as the declaration. // // 3. Whether the qualifier is valid for the given scope. // // 4. Whether the qualifier can be overriden (the flavor is // ENABLEOVERRIDE on the corresponding reference qualifier). // // 5. Whether the qualifier should be propagated to the subclass. // // If the qualifier should be overriden, then it is injected into the // qualifiers array (from the inheritedQualifiers array). for (Uint32 i = 0, n = _qualifiers.size(); i < n; i++) { CIMQualifier q = _qualifiers[i]; //---------------------------------------------------------------------- // 1. Check to see if it's declared. //---------------------------------------------------------------------- // set this back to CIMConstQualifierDecl CIMQualifierDecl qd = declContext->lookupQualifierDecl( nameSpace, q.getName()); if (qd.isUninitialized()) { PEG_METHOD_EXIT(); throw UndeclaredQualifier(q.getName().getString ()); } //---------------------------------------------------------------------- // 2. Check the type and isArray. Must be the same: //---------------------------------------------------------------------- if (!(q.getType() == qd.getType() && q.isArray() == qd.isArray())) { PEG_METHOD_EXIT(); throw BadQualifierType(q.getName().getString ()); } //---------------------------------------------------------------------- // 3. If the qualifier is the EmbeddedInstance qualifier, then check // that the class specified by the qualifier exists in the namespace. //---------------------------------------------------------------------- if (q.getName().equal(PEGASUS_QUALIFIERNAME_EMBEDDEDINSTANCE)) { String className; q.getValue().get(className); CIMClass classDef = declContext->lookupClass(nameSpace, CIMName(className)); if (classDef.isUninitialized()) { String embeddedInstType("EmbeddedInstance(\""); embeddedInstType = embeddedInstType + className + "\")"; PEG_METHOD_EXIT(); throw BadQualifierType(embeddedInstType); } } //---------------------------------------------------------------------- // 4. Check the scope: Must be legal for this qualifier //---------------------------------------------------------------------- // ATTN: These lines throw a bogus exception if the qualifier has // a valid scope (such as Scope::ASSOCIATION) which is not Scope::CLASS // ks Mar 2002. Reinstalled 23 March 2002 to test. if (!(qd.getScope().hasScope (scope))) { PEG_METHOD_EXIT(); throw BadQualifierScope (qd.getName().getString (), scope.toString ()); } //---------------------------------------------------------------------- // Resolve the qualifierflavor. Since Flavors are a combination of // inheritance and input characteristics, resolve the inherited // characteristics against those provided with the creation. If // there is a superclass the flavor is resolved against that // superclass. If not, it is resolved against the declaration. If // the flavor is disableoverride and tosubclass the resolved // qualifier value must be identical to the original //---------------------------------------------------------------------- // Test for Qualifier found in SuperClass. If found and qualifier // is not overridable. // Abstract (not Overridable and restricted) can be found in subclasses // Can have nonabstracts below abstracts. That is function of // nottosubclass Association (notOverridable and tosubclass) can be // found in subclasses but cannot be changed. No non-associatons below // associations. In other words once a class becomes an association, // no subclass can override that definition apparently // Throw exception if DisableOverride and tosubclass and different // value. Gets the source from superclass if qualifier exists or from // declaraction. // If we do not throw the exception, resolve the flavor from the // inheritance point and resolve against current input. // Diableoverride is defined in the CIM Spec to mean that the value // cannot change. // The other characteristics including the flavor can change // apparently. Thus, we need only confirm that the value is the same // (2.2 pp 33). Strange since we would think that override implies // that you cannot override any of the characteristics (value, type, // flavor, etc.) This also leaves the question of NULL or no values. // The implication is that we must move the value from the superclass // or declaration. Uint32 index = inheritedQualifiers.find(q.getName()); if (index == PEG_NOT_FOUND) { // Qualifier does not exist in superclass /* If from declaration, we can override the default value. However, we need some way to get the value if we have a Null. if (!qd.getFlavor().hasFlavor(CIMFlavor::OVERRIDABLE) && qd.getFlavor().hasFlavor(CIMFlavor::TOSUBCLASS)) { //throw BadQualifierOverride(q.getName()); } */ // Do not allow change from disable override to enable override. if ((!qd.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE)) && (q.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE))) { PEG_METHOD_EXIT(); throw BadQualifierOverride(q.getName().getString ()); } Resolver::resolveQualifierFlavor( q, CIMFlavor (qd.getFlavor ()), false); } else // qualifier exists in superclass { ////// Make Const again CIMQualifier iq = inheritedQualifiers.getQualifier(index); // don't allow change override to notoverride. if (!(iq.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE)) && q.getFlavor ().hasFlavor (CIMFlavor::OVERRIDABLE)) { PEG_METHOD_EXIT(); throw BadQualifierOverride(q.getName().getString ()); } if (!(iq.getFlavor ().hasFlavor(CIMFlavor::OVERRIDABLE)) && iq.getFlavor ().hasFlavor(CIMFlavor::TOSUBCLASS)) { // test if values the same. CIMValue qv = q.getValue(); CIMValue iqv = iq.getValue(); if (!(qv == iqv)) { PEG_METHOD_EXIT(); throw BadQualifierOverride(q.getName().getString()); } } Resolver::resolveQualifierFlavor( q, CIMFlavor(iq.getFlavor()), true); } } // end of this objects qualifier loop //-------------------------------------------------------------------------- // Propagate qualifiers to subclass or to instance that do not have // already have those qualifiers: //-------------------------------------------------------------------------- if (propagateQualifiers) { for (Uint32 i = 0, n = inheritedQualifiers.getCount(); i < n; i++) { CIMQualifier iq = inheritedQualifiers.getQualifier(i); if (isInstancePart) { if (!(iq.getFlavor().hasFlavor(CIMFlavor::TOINSTANCE))) continue; } else { if (!(iq.getFlavor().hasFlavor(CIMFlavor::TOSUBCLASS))) continue; } // If the qualifiers list does not already contain this qualifier, // then propagate it (and set the propagated flag to true). Else // we keep current value. Note we have already eliminated any // possibility that a nonoverridable qualifier can be in the list. if (find(iq.getName()) != PEG_NOT_FOUND) continue; CIMQualifier q = iq.clone(); q.setPropagated(true); _qualifiers.insert(0, q); } } PEG_METHOD_EXIT(); }
// 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.")); } }
void CIMtoXML(CIMQualifier const& cq, ostream& ostr) { CIMFlavor fv; if (cq.getName().empty()) { OW_THROWCIMMSG(CIMException::FAILED, "qualifier must have a name"); } CIMValue dv = cq.getDefaults().getDefaultValue(); CIMDataType dt = cq.getDefaults().getDataType(); CIMValue cv = cq.getValue(); if (!cv) { cv = dv; } if (cv) { if (cv.isArray()) { dt = CIMDataType(cv.getType(),cv.getArraySize()); } else { dt = CIMDataType(cv.getType()); } } OW_ASSERT(dt); ostr << "<QUALIFIER NAME=\"" << cq.getName() << "\" TYPE=\""; CIMtoXML(dt,ostr); ostr << "\" "; if (cq.getPropagated()) { ostr << "PROPAGATED=\"true\" "; } // // Create flavors // fv = CIMFlavor(CIMFlavor::ENABLEOVERRIDE); if (cq.hasFlavor(fv)) { // // Not needed, because OVERRIDABLE defaults to true! } else { fv = CIMFlavor(CIMFlavor::DISABLEOVERRIDE); if (cq.hasFlavor(fv)) { CIMtoXML(fv, ostr); ostr << "=\"false\" "; } } fv = CIMFlavor(CIMFlavor::TOSUBCLASS); if (cq.hasFlavor(fv)) { // // Not needed, because TOSUBCLASS defaults to true! } else { fv = CIMFlavor(CIMFlavor::RESTRICTED); if (cq.hasFlavor(fv)) { CIMtoXML(fv, ostr); ostr << "=\"false\" "; } } // This is a bug in the spec, but we still support it for backward compatibility. //fv = CIMFlavor(CIMFlavor::TOINSTANCE); //if (cq.hasFlavor(fv)) //{ // CIMtoXML(fv, ostr); // ostr << "=\"true\" "; //} //else //{ // // Not needed, because TOINSTANCE defaults to false! //} fv = CIMFlavor(CIMFlavor::TRANSLATE); if (cq.hasFlavor(fv)) { CIMtoXML(fv, ostr); ostr << "=\"true\" "; } else { // // Not needed, because TRANSLATABLE defaults to false! } String lang = cq.getLanguage(); if (!lang.empty()) { ostr << " xml:lang=\""; ostr << lang; ostr << '\"'; } ostr << '>'; if (cv) { CIMtoXML(cv, ostr); } ostr << "</QUALIFIER>"; }