Example #1
0
void VerifyCorrectWorkIstreamOperator(std::string const &str)
{
	std::istringstream strm(str);
	CMyString myStr;
	strm >> myStr;
	BOOST_CHECK_EQUAL(myStr.GetStringData(), str);
}
Example #2
0
/////////////////////////////////////////////////////////////////////////////
// WMIClassProvider::deleteClass
//
// ///////////////////////////////////////////////////////////////////////////
void WMIClassProvider::deleteClass(const String& nameSpace,
								   const String& userName,
								   const String& password,
								   const String& className)
{
	HRESULT hr;
	
	PEG_METHOD_ENTER(TRC_WMIPROVIDER,"WMIClassProvider::deleteClass()");

	CComPtr<IWbemServices> pServices;

	//Connect to namespace
	setup(nameSpace,userName,password);
	
	bool bConnected = _collector->Connect(&pServices);
	
	if (!bConnected) 
	{
		if (pServices)
			pServices.Release();

		throw CIMException(CIM_ERR_ACCESS_DENIED);
	}
	
	//Convert the parameters to make the WMI call
	CComBSTR bsClassName = className.getCString();
	
	LONG lFlags = 0L;

	//Perform the WMI operation
	hr = pServices->DeleteClass(bsClassName,
							    lFlags,
								NULL,
								NULL);
	if (pServices)
		pServices.Release();

	//Handle the WMI operation result
	if (FAILED(hr))
	{
		CMyString msg;
		msg.Format("Failed to delete class [%s]. Error: 0x%X", 255, className.getCString(), hr);

		Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, 
						  "WMIClassProvider::deleteClass() - %s", (LPCTSTR)msg);

		switch (hr)
		{
			case WBEM_E_ACCESS_DENIED: throw CIMException(CIM_ERR_ACCESS_DENIED); break;
			case WBEM_E_FAILED: throw CIMException(CIM_ERR_FAILED); break;
			case WBEM_E_INVALID_PARAMETER: throw CIMException(CIM_ERR_FAILED, "WMI Invalid Parameter"); break;
			case WBEM_E_INVALID_CLASS: throw CIMException(CIM_ERR_NOT_FOUND); break;
			case WBEM_E_NOT_FOUND: throw CIMException(CIM_ERR_NOT_FOUND); break;
			case WBEM_E_CLASS_HAS_CHILDREN: throw CIMException(CIM_ERR_CLASS_HAS_CHILDREN); break;
			default: throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
		}
	}

	PEG_METHOD_EXIT();
}
Example #3
0
int main(){
	CMyString ss = "141412";
	CMyString aa = "111111";
	CMyString bb, cc, dd;
	aa = cc = aa;
	dd = aa;
	aa.Print();
	dd.Print();
	return 0;
}
Example #4
0
CMyString CMyString::FlagString(int val, int* valList, CMyString* strList, int num)
{
   CMyString dst;
   for (int i=0; i<num; i++) {
      if (val & valList[i]) {
         if (!dst.IsEmpty()) dst += _T("|");
         dst += strList[i];
      }
   }
   if (dst.IsEmpty()) dst << (int)val; 
   return dst;
}
Example #5
0
int CMyAsyncHttp::HttpQueryInfo(HINTERNET request,CMyString &info,int code)
{
	unsigned long rl=0;
	::HttpQueryInfo(request,code,NULL,&rl,0);

	if(rl>0)
	{
		info.Resize(rl+1);
		return ::HttpQueryInfo(request,code,info.GetBuffer(),&rl,0);
	}
	return false;
}
Example #6
0
void CFunc::GetAlpha(BOOL& src, BOOL& dst) const
{
   src = dst = FALSE;
   CMyString sDescr = DescrName();
   CMyString srcStr = firstChanStr(sDescr);
   CMyString dstStr = firstChanStr(sDescr);
   src = alphaChannel(srcStr);
   if (dstStr.IsEmpty())
      dst = src;
   else
      dst = alphaChannel(dstStr);
}
Example #7
0
void CFunc::GetChannels(int& src, int& dst) const
{
   src = dst = 0;
   CMyString sDescr = DescrName();
   CMyString srcStr = firstChanStr(sDescr);
   CMyString dstStr = firstChanStr(sDescr);
   src = numChannels(srcStr);
   if (dstStr.IsEmpty())
      dst = src;
   else
      dst = numChannels(dstStr);
   UpdateChannels(src, dst);
}
Example #8
0
CFunc CParmStatDlg::GetFunc(int index, int dstType) 
{
   CMyString funcBase = FuncBase(index);
   CMyString typeName;
   if (TypeFlag(funcBase))
      typeName = TypeName(dstType);
   CFunc func = "ipps" + funcBase + "_" + typeName;
   if (typeName.IsEmpty())
      func += m_pDocSrc->GetVector()->TypeString();
   if (func.DstType() & PP_SIGN)
      func += "_Sfs";
   return func;
}
Example #9
0
void CFunc::GetPlanes(BOOL& src, BOOL& dst) const
{
   src = dst = FALSE;
   CMyString sDescr = DescrName();
   CMyString srcStr = firstChanStr(sDescr);
   CMyString dstStr = firstChanStr(sDescr);
   src = planeChannel(srcStr);
   if (dstStr.IsEmpty())
      dst = src;
   else
      dst = planeChannel(dstStr);
   if (!src && !dst && sDescr.Found(_T("P")))
      src = dst = TRUE;
   UpdatePlanes(src,dst);
}
Example #10
0
	void GetDirName(CMyString &path)
	{
		int len=path.GetStrLen();
		int start=0;
		for(int i=len-1;i>=0;i++)
		{
			if(path[i]=='/')
			{
				start=i+1;
				break;
			}
		}
		m_TempStr=path.GetSubStr(start);
		if(path[len-1]=='/')
			m_TempStr.EraseFromRight(1);
	}
Example #11
0
static int numChannels(CMyString str)
{
   if (str.IsEmpty()) return 0;
   CMyString numStr((str[0] == 'A') ? str[2] : str[1]);
   int num = _ttoi(numStr);
   if (num > 4) num = 0;
   return num;
}
Example #12
0
void CFunc::GetChannelsName(CMyString& src, CMyString& dst) const
{
   src = dst = _T("");
   CMyString sDescr = DescrName();
   src = firstChanStr(sDescr);
   dst = firstChanStr(sDescr);
   if (dst.IsEmpty()) dst = src;
}
Example #13
0
int	CMyAsyncHttp::HttpGetStatusCode(HINTERNET request,int &code)
{
	CMyString str;
	code=0;

	if(HttpQueryInfo(request,str,HTTP_QUERY_STATUS_CODE))
	{
		code=str.ToInt();
	};
#ifdef _DEBUG
	int d=::GetLastError();
	if(d==ERROR_HTTP_HEADER_NOT_FOUND)
	{
		LOG(TAG,"HttpGetStatusCode,can't find the header!");
	}
#endif
	return 1;
}
Example #14
0
int CMyString::CompareNoCase(CMyString strVal_UP) const	// Compare respect to "strVal", case insensitive
{
	CMyString			strThis_UP = *this;

	strThis_UP.MakeUpper();
	strVal_UP.MakeUpper();

	return strThis_UP.Compare(strVal_UP);
}
Example #15
0
/////////////////////////////////////////////////////////////////////////////
// WMIClassProvider::createQualifier  creates a qualifiers 
//                                      
/////////////////////////////////////////////////////////////////////////////
void WMIClassProvider::createQualifier (const WMIQualifier &qualifier, 
                                        IWbemQualifierSet *pQual)
{
    HRESULT hr;
    
    PEG_METHOD_ENTER(TRC_WMIPROVIDER, "WmiClassProvider::createQualifier()");

    String sName = qualifier.getName().getString(); 
    CComBSTR bs = sName.getCString();
    WMIValue value(qualifier.getValue());
    WMIFlavor flavor(qualifier.getFlavor());
    
    CComVariant v;
    value.getAsVariant(&v);

    // key is created using a special call to wmi
    //if (!stricmp("key", ))
    if (String::equalNoCase("key", sName))
    {
        hr = pQual->Put(bs, &v, NULL);
    }
    else
    {
        hr = pQual->Put(bs, &v, flavor.getAsWMIValue());
    }
    v.Clear();
    bs.Empty();

    if (FAILED(hr))
    {
        CMyString msg;
        msg.Format("It is not possible to add the qualifier [%s] to "
            "the object! Error: 0x%X", 255, sName.getCString(), hr);
        
        PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL1, 
            "WmiClassProvider::createQualifier() - %s", (LPCTSTR)msg));

        throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
    }

    PEG_METHOD_EXIT();

    return;
}
Example #16
0
void 
CMyNumString::SetString(const CMyString &str)
{
    if (!CheckNum(str.GetString()))
    {
        return;
    }

    CMyString::SetString(str);
}
Example #17
0
int CMyAsyncHttp::HttpGetCharset(HINTERNET request,CMyString &charset)
{
	CMyString str;
	if(HttpQueryInfo(request,str,HTTP_QUERY_CONTENT_TYPE))
	{
		char *p=str.GetBuffer();
		p=strstr(p,"charset=");
		if(p)charset=p+8;
		return 1;
	}
#ifdef _DEBUG
	int d=::GetLastError();
	if(d==ERROR_HTTP_HEADER_NOT_FOUND)
	{
		LOG(TAG,"HttpGetCharset,can't find the header!");
	}
#endif
	return 1;
	
}
Example #18
0
BOOL CippsRun::PickSetID(CMyString& vectorName, UINT& pickID, UINT& grabID)
{
   if (m_PickVecPos == VEC_SRC3) {
      vectorName = m_Func.VecName(VEC_SRC3,m_UsedVectors);
      if (m_Func.Inplace()) {
         vectorName = "SrcDst";
         pickID = IDC_CURSOR_PSD;
         grabID = IDC_CURSOR_SD;
      } else {
         vectorName = "Src3";
         pickID = IDC_CURSOR_PS3;
         grabID = IDC_CURSOR_S3;
      }
   } else if (m_PickVecPos == VEC_SRC2) {
      vectorName = m_Func.VecName(VEC_SRC2,m_UsedVectors);
      if (vectorName.Found("Im")) {
         pickID = IDC_CURSOR_PIM;
         grabID = IDC_CURSOR_IM;
      } else if (vectorName.Found("Phase")) {
         pickID = IDC_CURSOR_PPH;
         grabID = IDC_CURSOR_PH;
      } else if (vectorName.Found("High")) {
         pickID = IDC_CURSOR_PHI;
         grabID = IDC_CURSOR_HI;
      } else if (vectorName.Found("Ref")) {
         pickID = IDC_CURSOR_PR;
         grabID = IDC_CURSOR_R;
      } else if (!(m_UsedVectors & VEC_SRC3) && m_Func.Inplace()) {
         vectorName = "SrcDst";
         pickID = IDC_CURSOR_PSD;
         grabID = IDC_CURSOR_SD;
      } else {
         vectorName = "Src2";
         pickID = IDC_CURSOR_PS2;
         grabID = IDC_CURSOR_S2;
      }
   } else {
      return FALSE;
   }
   return TRUE;
}
Example #19
0
	virtual	void FileProcess(const char *parentUrl,const char* url,const char* fileData,int dataLen)
	{
		CMyString lUrl=(char*)url;
		CMyString path=CUrl::GetUrlPath(lUrl);
		CMyString name=CUrl::GetFileName(lUrl);
		if(path!=""&&name!="")
		{
			GetDirName(path);
			m_TempStr=m_FilePath+m_TempStr;
			CMyFile::CreateDir(m_TempStr.GetBuffer());
			m_TempStr+="\\"+name;
		}
	}
Example #20
0
/////////////////////////////////////////////////////////////////////////////
// WMIClassProvider::createProperty   creates one property 
//                                      doesn't create the qualifiers
/////////////////////////////////////////////////////////////////////////////
void WMIClassProvider::createProperty(const CIMProperty &keyProp, 
                                      IWbemClassObject *pNewClass)
{
    PEG_METHOD_ENTER(TRC_WMIPROVIDER, "WmiClassProvider::createProperty()");

    // create the property
    //Get the CIMTYPE of the parameter
    CIMTYPE type = CIMTypeToWMIType(keyProp.getType());

    //If the property is an array, add CIM_FLAG_ARRAY to CIMType
    if (keyProp.isArray())
    {
        type |= CIM_FLAG_ARRAY;
    }

    // add the property to the class
    CComBSTR bs = keyProp.getName().getString().getCString();
    HRESULT hr = pNewClass->Put(bs, NULL, NULL, type);

    bs.Empty();

    //handle the error, if failed
    if (FAILED(hr))
    {
        CMyString msg;
        msg.Format("Failed to add property [%s]. Error: 0x%X", 255, 
            keyProp.getName().getString().getCString(), hr);

        PEG_TRACE((TRC_WMIPROVIDER, Tracer::LEVEL1, 
                      "WMIClassProvider::createProperty () - %s", 
                      (LPCTSTR)msg));

        throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg); 
    }

    PEG_METHOD_EXIT();

    return;
}
void SpiderThread::AnalysisData(SpiderHttp* spiderHttp)
{
	CMyString url;
	CMyString host;

	bool	  haveUrl=true;
	if(spiderHttp->IsTxtPage())
	{
		if(!InitalFetchEngine(spiderHttp->GetReceiveData(),spiderHttp->GetReceiveDataLen()))
			haveUrl=false;
		while(haveUrl)
		{
			int urlCount=m_InterfaceConfig.m_FetchUrl->FetchUrl(m_CurrentP,m_Regex.GetMatchStrLen(),m_SameRegex);
			for(int i=0;i<urlCount;i++)
			{
				url	=*(m_InterfaceConfig.m_FetchUrl->GetUrl(i));
				if(url=="./")continue;
				ReBuildUrlIfNeed(spiderHttp->m_Url,url,host);
				if(HaveAcess(host,url))continue;
				for(int i=0;i<m_InterfaceConfig.m_UrlFilterList.size();i++)
				{
					if(!m_InterfaceConfig.m_UrlFilterList[i]->FilterCheck(spiderHttp->m_Url.GetBuffer(),url.GetBuffer()))break;
				}
				if(i<m_InterfaceConfig.m_UrlFilterList.size())continue;
				if(m_InterfaceConfig.m_UrlModify)
				{
					m_InterfaceConfig.m_UrlModify->ModifyUrl(spiderHttp->m_Url.GetBuffer(),url);
				}
				AddHashMap(host,url);
				AddTempUrlList(url);
			}
			if(!FetchUrl(url))break;
		}
		
		if(m_InterfaceConfig.m_PageProcess)
		{
			m_InterfaceConfig.m_PageProcess->PageProcess(spiderHttp->m_ParentUrl.GetBuffer(),spiderHttp->m_Url.GetBuffer(),spiderHttp->GetReceiveData(),spiderHttp->GetReceiveDataLen());
		}
		if(m_UrlCmp)
		{
			SortTempUrlList();
		}
		
		//根据深度优先还是广度优先进行抓取
		AddAllUrlToUrlList(spiderHttp->m_Url);
	}
	else if(m_InterfaceConfig.m_FileProcess)
	{
		m_InterfaceConfig.m_FileProcess->FileProcess(spiderHttp->m_ParentUrl.GetBuffer(),spiderHttp->m_Url.GetBuffer(),spiderHttp->GetReceiveData(),spiderHttp->GetReceiveDataLen());
	}	
}
Example #22
0
static CMyString firstType(CMyString type)
{
   if (type.Find(_T("64fc")) == 0) return _T("64fc");
   if (type.Find(_T("64sc")) == 0) return _T("64sc");
   if (type.Find(_T("64s" )) == 0) return _T("64s") ;
   if (type.Find(_T("64f" )) == 0) return _T("64f") ;
   if (type.Find(_T("32fc")) == 0) return _T("32fc");
   if (type.Find(_T("32sc")) == 0) return _T("32sc");
   if (type.Find(_T("32u" )) == 0) return _T("32u") ;
   if (type.Find(_T("32s" )) == 0) return _T("32s") ;
   if (type.Find(_T("32f" )) == 0) return _T("32f") ;
   if (type.Find(_T("24u" )) == 0) return _T("24u") ;
   if (type.Find(_T("24s" )) == 0) return _T("24s") ;
   if (type.Find(_T("16sc")) == 0) return _T("16sc");
   if (type.Find(_T("16u" )) == 0) return _T("16u") ;
   if (type.Find(_T("16s" )) == 0) return _T("16s") ;
   if (type.Find(_T("16f" )) == 0) return _T("16f") ;
   if (type.Find(_T("8sc" )) == 0) return _T("8sc")  ;
   if (type.Find(_T("8u"  )) == 0) return _T("8u")  ;
   if (type.Find(_T("8s"  )) == 0) return _T("8s")  ;
   if (type.Find(_T("1u"  )) == 0) return _T("8u")  ;
   return _T("");
}
Example #23
0
static bool fitString(CMyString str, CMyString sample, int shift)
{
   str.MakeLower();
   sample.MakeLower();
   CMyString shiftSample = sample.Mid(shift);
   if (shiftSample.Find(str) == 0) return true;
   if (sample.Find(str) == 0) return true;
   return false;
}
Example #24
0
bool const operator>(CMyString const& a, CMyString const& b)
{
	int const result = memcmp(a.GetStringData(), b.GetStringData(), min(a.GetLength(), b.GetLength()));

	if (result != 0)
	{
		return (result > 0);
	}

	return (a.GetLength() > b.GetLength());
}
Example #25
0
void CFunc::ParseFunction(CMyString& base, CMyString& type1, CMyString& type2,
                          CMyString& type3, CMyString& descr) const
{
   CMyString type;
   ParseFunction(base,type,descr);
   int len = type.GetLength();
   type1 = firstType(type);
   int len1 = type1.GetLength();
   if (len1 == len) {
      type2 = type3 = type1;
   } else {
      type2 = firstType(type.Mid(len1));
      int len2 = type2.GetLength();
      if (len1 + len2 == len) {
         type3 = type2;
         if (!descr.Found(_T("I")))
            type2 = type1;
      } else {
         type3 = firstType(type.Mid(len1+len2));
      }
   }
} 
Example #26
0
static CMyString firstChanStr(CMyString& descr)
{
   CMyString numStr = _T("1234");
   int index = descr.Find(_T("C"));
   int iP = descr.Find(_T("P"));
   int len = 0;
   CMyString chanStr = _T("");
   if ((iP >= 0) && (index < 0 || (iP < index))) index = iP;
   if ((index < 0) ||
       (descr.GetLength() == index + 1) ||
       (!numStr.Found(descr[index + 1]))) {
      len = 0;
   } else {
      len = 2;
      if ((index > 0) && (descr[index - 1] == 'A')) {
         index--;
         len++;
      }
   }
   CMyString str = descr.Mid(index,len);
   descr = descr.Mid(index + len);
   return str;
}
Example #27
0
CMyString::CMyString(const CMyString& str)
{
	m_pData = new char[str.size() + 1];
	strcpy(m_pData, str.m_pData);
}
Example #28
0
/////////////////////////////////////////////////////////////////////////////
// WMIClassProvider::createProperties creates all properties including keys 
//									  add the qualifiers too
// ///////////////////////////////////////////////////////////////////////////
void WMIClassProvider::createProperties(const CIMClass& newClass,
									    IWbemServices *pServices,
										IWbemClassObject *pNewClass)
{
	HRESULT hr;
	
	PEG_METHOD_ENTER(TRC_WMIPROVIDER, "WmiClassProvider::createProperties()");

	// create the properties but don't create the keys again
	CIMProperty prop;

	for (Uint32 i = 0; i < newClass.getPropertyCount(); i++)
	{
		prop = newClass.getProperty(i).clone();

		// create the properties
		try 
		{
			createProperty(prop, pNewClass);
		}
		catch (CIMException&)
		{
			throw;
		}
		
		// get a pointer to work with qualifiers 
		CComPtr<IWbemQualifierSet> pQual;
		CComBSTR bs = prop.getName().getString().getCString();
		
		hr = pNewClass->GetPropertyQualifierSet(bs, &pQual);
		bs.Empty();

		if (FAILED(hr))
		{
			CMyString msg;
			msg.Format("Failed get Qualifier set of [%s]. Error: 0x%X", 255, 
				prop.getName().getString().getCString(), hr);
		
			Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, 
						  "WMIClassProvider::createProperties() - %s", (LPCTSTR)msg);

			if (pQual)
				pQual.Release();
			
			throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg); 
		}

		// set the qualifiers to the property
		for (Uint32 j = 0; j < prop.getQualifierCount(); j++)
		{
			WMIQualifier qualifier(prop.getQualifier(j));
			try 
			{
				createQualifier(qualifier, pQual);
			}
			catch (CIMException&)
			{
				if (pQual)
					pQual.Release();

				throw;
			}
		}

		// set the CLASSORIGIN qualifier if it wasn't set yet
		String strClassorigin = prop.getClassOrigin().getString();
		
		if (strClassorigin.size() == 0)
		{
			strClassorigin = newClass.getClassName().getString();
		}

		WMIFlavor flavor(CIMFlavor::DEFAULTS);
		
		/*
		v.vt = VT_BSTR;
		v.bstrVal = strClassorigin.getCString();
		*/
		CComVariant v;
		v = strClassorigin.getCString();
		
		hr = pQual->Put(L"CLASSORIGIN", &v, flavor.getAsWMIValue());
		v.Clear();

		if (pQual)
			pQual.Release();

		if (FAILED(hr))
		{
			CMyString msg;
			msg.Format("Failed to add CLASSORIGIN qualifier in [%s]. Error: 0x%X", 255, 
				prop.getName().getString().getCString(), hr);

			Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, 
						  "WMIClassProvider::createProperties () - %s", (LPCTSTR)msg);
			
			throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
		}
	}

	PEG_METHOD_EXIT();

	return;
}
Example #29
0
/////////////////////////////////////////////////////////////////////////////
// WMIClassProvider::createClassNameAndClassQualifiers
//
// ///////////////////////////////////////////////////////////////////////////
void WMIClassProvider::createClassNameAndClassQualifiers(const CIMClass& newClass,
														 IWbemServices *pServices,
														 IWbemClassObject **pNewClass,
														 const bool hasSuperClass)
{
	HRESULT hr;

	PEG_METHOD_ENTER(TRC_WMIPROVIDER, "WmiClassProvider::createClassNameAndClassQualifiers()");

	// if the class has a superclass, we need to spwan a derived
	if (hasSuperClass)
	{
		// get the superclass name
		CComPtr<IWbemClassObject> pSuperClass;
		String tmp = newClass.getSuperClassName().getString();
		CComBSTR bs = tmp.getCString();

		hr = pServices->GetObject(
				bs, 
				NULL, 
				NULL, 
				&pSuperClass, 
				NULL);

		bs.Empty();

		if (FAILED(hr))
		{
			if (pSuperClass)
				pSuperClass.Release();

			CMyString msg;
			msg.Format("Failed to get a pointer to Superclass [%s]. Error: 0x%X", 255, tmp.getCString(), hr);

			Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, 
						  "WMIClassProvider::createClassNameAndClassQualifiers() - %s", (LPCTSTR)msg);

			throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg); 
		}

		//Creates the new class
		pSuperClass->SpawnDerivedClass(NULL, pNewClass);
		if (pSuperClass)
			pSuperClass.Release();
	}
	else
	{
		// we are creating a base class
		hr = pServices->GetObject(NULL, 
								  NULL, 
								  NULL, 
								  pNewClass, 
								  NULL);

		if (FAILED(hr))
		{
			CMyString msg;
			msg.Format("Failed to get a pointer to a new class. Error: 0x%X", hr);

			Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, 
						  "WMIClassProvider::createClassNameAndClassQualifiers() - %s", (LPCTSTR)msg);
			
			throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
		}
	}
	
	// create the class name
	CComVariant v;
	v = newClass.getClassName().getString().getCString();
	hr = (*pNewClass)->Put(L"__CLASS", 0, &v, 0);
	
	v.Clear();

	if (FAILED(hr))
	{
		CMyString msg;
		msg.Format("Failed to add class name on class [%s]. Error: 0x%X", 255, 
			newClass.getClassName().getString().getCString(), hr);

		Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, 
			          "WMIClassProvider::createClassNameAndClassQualifiers() - %s", (LPCTSTR)msg);

		if (*pNewClass)
			(*pNewClass)->Release();
		
		throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
	}

	// get a pointer to work with qualifiers
	CComPtr<IWbemQualifierSet> pNewClassQualifier;
	hr = (*pNewClass)->GetQualifierSet(&pNewClassQualifier);

	if (FAILED(hr))
	{
		CMyString msg;
		msg.Format("Failed to get the Qualifier set pointer of class [%s]. Error: 0x%X", 255, 
			newClass.getClassName().getString().getCString(), hr);

		Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, 
			          "WMIClassProvider::createClassNameAndClassQualifiers() - %s", (LPCTSTR)msg);
		
		if (*pNewClass)
			(*pNewClass)->Release();

		if (pNewClassQualifier)
			pNewClassQualifier.Release();

		throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
	}
	
	// check the class qualifiers and create them if they are valid
	// we are taking care of the class qualifiers and not methods/properties qualifiers :D
	for (Uint32 i = 0; i < newClass.getQualifierCount(); i++)
	{
		try 
		{
			WMIQualifier qualifier(newClass.getQualifier(i).clone());
			
			createQualifier(qualifier, pNewClassQualifier);
		}
		catch (CIMException&)
		{
			if (*pNewClass)
				(*pNewClass)->Release();

			if (pNewClassQualifier)
				pNewClassQualifier.Release();

			throw;
		}
	}

	if (pNewClassQualifier)
		pNewClassQualifier.Release();

	PEG_METHOD_EXIT();

	return;
}
Example #30
0
/////////////////////////////////////////////////////////////////////////////
// WMIClassProvider::createClass
//
// ///////////////////////////////////////////////////////////////////////////
void WMIClassProvider::createClass(const String& nameSpace,
								   const String& userName,
								   const String& password,
								   const CIMClass& newClass,
								   Boolean updateClass)
{
	
	PEG_METHOD_ENTER(TRC_WMIPROVIDER, "WmiClassProvider::createClass()");

	setup(nameSpace, userName, password);

	if (!m_bInitialized)
	{
		Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3,
			"WMIClassProvider::createClass - m_bInitilized= %x, throw CIM_ERR_FAILED exception",  
			m_bInitialized);

		throw CIMException(CIM_ERR_FAILED);
	}
	
	// Check if the class does not exist and if if has a valid
	// superclass
	performInitialCheck(newClass, updateClass);
	bool hasSuperClass = (newClass.getSuperClassName().getString() != String::EMPTY);

	// gets the pointers
	CComPtr<IWbemServices> pServices;
	CComPtr<IWbemClassObject> pNewClass;

	if (!_collector->Connect(&pServices))
	{
		if (pServices)
			pServices.Release();

		throw CIMException (CIM_ERR_FAILED);
	}

	try 
	{
	    // starts the class creation by name and class qualifiers
		createClassNameAndClassQualifiers(
			newClass, 
			pServices, 
			&pNewClass, 
			hasSuperClass);

		// create properties
		createProperties(
			newClass, 
			pServices, 
			pNewClass);

		// create methods
		createMethods(
			newClass, 
			pServices, 
			pNewClass);
	}
	catch (CIMException&) 
	{
		if (pServices)
			pServices.Release();

		if (pNewClass)
			pNewClass.Release();

		throw;
	}
	
	// Store the new class into WMI
	LONG lFlags = 0L;
	
	//if updateClass is set, we are trying a modifyclass
	if (updateClass) lFlags = WBEM_FLAG_UPDATE_ONLY;

	HRESULT hr = pServices->PutClass(pNewClass, lFlags, NULL, NULL);
	
	if (pServices)
		pServices.Release();
	
	if (pNewClass)
		pNewClass.Release();
	
	if (FAILED(hr))
	{
		CMyString msg;
		msg.Format("It is not possible to create the class [%s]. Error: 0x%X", 255, 
					newClass.getClassName().getString(), hr);

		Tracer::trace(TRC_WMIPROVIDER, Tracer::LEVEL3, 
						  "WMIClassProvider::createClass() - %s", (LPCTSTR)msg);

		switch(hr)
		{
			case E_ACCESSDENIED: throw CIMException(CIM_ERR_ACCESS_DENIED); break;
			case WBEM_E_ACCESS_DENIED: throw CIMException(CIM_ERR_ACCESS_DENIED); break;
			case WBEM_E_CLASS_HAS_CHILDREN: throw CIMException(CIM_ERR_CLASS_HAS_CHILDREN); break;
			case WBEM_E_CLASS_HAS_INSTANCES: throw CIMException(CIM_ERR_CLASS_HAS_INSTANCES); break;
			case WBEM_E_NOT_FOUND: throw CIMException(CIM_ERR_NOT_FOUND); break;
			case WBEM_E_INVALID_CLASS: throw CIMException(CIM_ERR_INVALID_PARAMETER); break;
			default: throw CIMException(CIM_ERR_FAILED, (LPCTSTR)msg);
		}
	}

	PEG_METHOD_EXIT();

	return;
}