void xTEDSQualifierList::Parse(const char* quallist) { char quals[256]; int start = 0,end = 0; size_t count = 0; bool equalfound = false; bool parseValid = false; quals[0] = 0; count = strlen(quallist); for(unsigned int i = 0; i < count; i++) { if((quallist[i] != '<' && quallist[i] != ' ')&& end >= start) { start = i; } if(start > end && equalfound == false && quallist[i] == '=') { equalfound = true; i++; while(quallist[i] == ' '&& i < count) { i++; } } if(equalfound == true && (quallist[i] == ' ' || quallist[i] == '/')) { end = i; } if(end > start) { xTEDSQualifier m_qual; strncpy(quals,&quallist[start],end-start); quals[end-start] = 0; parseValid = m_qual.Parse(quals); if(parseValid == true) { addQualifier(m_qual); } else { printf("!!! Improperly formated Qualifier List !!!\n"); } equalfound = false; parseValid = false; start = end; } } }
WMIMethod::WMIMethod(const BSTR & name, const CComPtr<IWbemClassObject>& inParameters, const CComPtr<IWbemClassObject>& outParameters, IWbemQualifierSet * pQualifierSet, Boolean includeQualifiers) { CIMQualifierList qualifierList; CComBSTR bsName = name; CComVariant vValue = NULL; CIMTYPE returnValueType; HRESULT hr; WMIQualifierSet(pQualifierSet).cloneTo(qualifierList); // Get method return value String referenceClass = String::EMPTY; CComBSTR propertyName = L"ReturnValue"; // modified to correct bug JAGaf25827 // JAGaf25827 - new code begin if (outParameters) { hr = outParameters->Get( propertyName, 0, &vValue, &returnValueType, NULL); } else { hr = WBEM_E_NOT_FOUND; } // not found. Maybe it is a 'void' return value if (hr == WBEM_E_NOT_FOUND) { vValue = NULL; returnValueType = CIM_UINT32; } else if (hr != WBEM_S_NO_ERROR) { // Error: throw? throw Exception("WMIMethod::WMIMethod Get ReturnValue Failed."); } vValue.Clear(); // the WMI 'CIMTYPE' qualifier stores a string that contains the reference // class name cimtype_qualifier ::= ["ref:" + <reference_class_name>] // NOTE: CIMMethod does not seem to store the reference class anywhere, // but it seems like it should, so this code is here in case a reference // class member is ever added to the CIMMethod class in the future: if (CIM_REFERENCE == returnValueType) { // strip "ref:" Uint32 pos = qualifierList.find(CIMName("CIMTYPE")); if (PEG_NOT_FOUND != pos) { qualifierList.getQualifier(pos).getValue().get(referenceClass); //strip off "ref:" or, if not found, erase the whole string if ((pos = referenceClass.find(qString(Q_COLON))) != PEG_NOT_FOUND) { referenceClass.remove(0, pos + 1); } } } String classOrigin = String::EMPTY; // the 'Propagated" qualifier stores a string containing the class origin // propagated qualifier ::= [<class_origin>"."]<method_name> { Uint32 pos = qualifierList.find(CIMName("Propagated")); if (PEG_NOT_FOUND != pos) { qualifierList.getQualifier(pos).getValue().get(classOrigin); // strip on the ".<method_name> portion if there... if ((pos = classOrigin.find(".")) != PEG_NOT_FOUND) { classOrigin.remove(pos); } } } // NOTE: Currently no mapping of WMI "object" types, so this could // throw if the param is of type "object" or other un-supported // WMI type: CIMType cimType; try { cimType = WMITypeToCIMType(returnValueType); } catch (TypeMismatchException tme) { // Don't want method enumeration to fail, just because // we don't handle the type, so making this type "reference" // for now and making the reference class name "UNKNOWN_TYPE": cimType = CIMTYPE_REFERENCE; referenceClass = "UNKNOWN_TYPE"; } // Build the method CIMName cimRef; CIMName cimClsOrigin; BSTR tmpBstr = (BSTR)bsName.Copy(); String s(_bstr_t(tmpBstr, FALSE)); SysFreeString(tmpBstr); bsName.Empty(); if (0 != referenceClass.size()) { cimRef = referenceClass; } if (0 != classOrigin.size()) { cimClsOrigin = classOrigin; } *this = CIMMethod( CIMName(s), cimType, cimClsOrigin, (classOrigin.size() != 0)); // Add the qualifiers if (includeQualifiers) { Uint32 i, n; for (i = 0, n = qualifierList.getCount(); i < n; i++) { addQualifier(qualifierList.getQualifier(i)); } } // Enumerate the parameters of the WMI method in and out classes here, // adding them to the CIMMethos as appropriate. // NOTE: In WMI parameters method parameters are defined as in, out, or // both, meaning that they cold show up in both the inParameters and // outParameters lists. The addWMIParametersToCIMMethod() function will // check for the existing parameters by name, and will not attempt to // re-add any existing params (there is no need, since the "in" and "out" // versions of an in/out param are simply identical copies) addWMIParametersToCIMMethod(outParameters, *this, includeQualifiers); addWMIParametersToCIMMethod(inParameters, *this, includeQualifiers); }
WMIProperty::WMIProperty(const BSTR & name, const VARIANT & value, const CIMTYPE type, IWbemQualifierSet * pQualifierSet, Boolean includeQualifiers) { CIMQualifierList qualifierList; CComBSTR bsName = name; CComVariant vValue = value; qualifierList = WMIQualifierSet(pQualifierSet); // get additional property information String referenceClass = String::EMPTY; // the WMI 'CIMTYPE' qualifier stores a string that contains the reference class name // cimtype_qualifier ::= ["ref:" + <reference_class_name>] if (CIM_REFERENCE == type) { // strip "ref:" Uint32 pos = qualifierList.find(CIMName("CIMTYPE")); if (PEG_NOT_FOUND != pos) { qualifierList.getQualifier(pos).getValue().get(referenceClass); //strip off "ref:" or, if not found, erase the whole string if ((pos = referenceClass.find(qString(Q_COLON))) != PEG_NOT_FOUND) { referenceClass.remove(0, pos + 1); } } } String classOrigin = String::EMPTY; // the 'Propagated" qualifier stores a string containing the class origin // propagated qualifier ::= [<class_origin>"."]<property_name> { Uint32 pos = qualifierList.find(CIMName("Propagated")); if (PEG_NOT_FOUND != pos) { qualifierList.getQualifier(pos).getValue().get(classOrigin); // strip on the ".<property_name> portion if there... if ((pos = classOrigin.find(".")) != PEG_NOT_FOUND) { classOrigin.remove(pos); } } } // build the property BSTR tmpBstr = (BSTR)bsName.Copy(); String s(_bstr_t(tmpBstr, FALSE)); SysFreeString(tmpBstr); // old way -- memory leak?: // String s = WMIString(bsName); CIMName cimRef; CIMName cimClsOrigin; if (0 != referenceClass.size()) { cimRef = referenceClass; } if (0 != classOrigin.size()) { cimClsOrigin = classOrigin; } *this = CIMProperty(CIMName(s), WMIValue(vValue, type), 0, cimRef, cimClsOrigin, (classOrigin.size() != 0)); vValue.Clear(); // add the qualifiers if (includeQualifiers) { Uint32 i, n; for (i = 0, n = qualifierList.getCount(); i < n; i++) { addQualifier(qualifierList.getQualifier(i)); } } }