コード例 #1
0
void NewAsynHttpStatData::Work()
{
	//try
	//{
	TCHAR szPath[MAX_PATH] = {0};
	URLDownloadToCacheFile(NULL, m_strUrl.c_str(), szPath, MAX_PATH, 0, NULL);
	TSDEBUG4CXX(L"send WM_NEWASYNSENDHTTPSTATTASKFINISH");
	g_wndMsg.PostMessage(WM_NEWASYNSENDHTTPSTATTASKFINISH, 0, (LPARAM) this);
	//}
	//catch (...)
	//{
	//	g_wndMsg.PostMessage(WM_NEWASYNSENDHTTPSTATTASKFINISH, -1, (LPARAM) this);
	//}
}
コード例 #2
0
ファイル: LuaAsynUtil.cpp プロジェクト: fanliaokeji/lvdun
void HttpStatData::Work()
{
	//try
	//{
		TCHAR szPath[MAX_PATH] = {0};
		URLDownloadToCacheFile(NULL, m_strUrl.c_str(), szPath, MAX_PATH, 0, NULL);
		if (m_bAsync)
		{
			g_wndMsg.PostMessage(WM_SENDHTTPSTAT, 0, (LPARAM) this);
		}
	//}
	//catch (...)
	//{
	//	if (m_bAsync)
	//	{
	//		g_wndMsg.PostMessage(WM_SENDHTTPSTAT, -1, (LPARAM) this);
	//	}
	//}
}
コード例 #3
0
ファイル: Statistics.cpp プロジェクト: N2oBeef/vc_scan
BOOL CStatistic::InternalDownloadFile( LPCWSTR lpszUrl, LPCWSTR lpszLocalFile, StatUrlSendStateCallback stateCallback)
{
    BOOL bResult = FALSE;

    if(lpszUrl != NULL && *lpszUrl != L'\0') 
    {	
        if(lpszLocalFile == NULL || * lpszLocalFile == L'\0')
        {
            TCHAR szFile[MAX_PATH * 2]={0};
            if (SUCCEEDED(URLDownloadToCacheFile(NULL, lpszUrl, szFile, MAX_PATH, 0, NULL)))
            {
                //LOG(L"[CStatistic] connection success url:%s", lpszUrl);
                DeleteFile(szFile);
                bResult = TRUE;
            }
            else
            {
                //LOG(L"[CStatistic] connection failed:%d, url:%s", GetLastError(), lpszUrl);
            }
        }
        else
        {
            if(SUCCEEDED(URLDownloadToFile(NULL, lpszUrl, lpszLocalFile, 0, NULL)))
            {
                bResult = TRUE;
            }
        }
    }

    if (stateCallback)
    {
        stateCallback(bResult);
    }

    return bResult;
}
コード例 #4
0
ファイル: XMLDOMDocument.cpp プロジェクト: gitrider/wxsj2
UINT APIENTRY CXMLDOMDocument::ParseThread(void *pParm)
{
	ATLTRACE(_T("CXMLDOMDocument::ParseThread\n"));

	CXMLDOMDocument *pThis = reinterpret_cast<CXMLDOMDocument *> (pParm);
	if (NULL == pThis)
		return 0;

	if (!pThis->m_bAbort && pThis->m_FileName.length() > 0) {
		CBindStatCallbackObj *pCallbackObj = NULL;
		HRESULT hr = CBindStatCallbackObj::CreateInstance(&pCallbackObj);
		if (S_OK != hr)
			pCallbackObj = NULL;

		if (pCallbackObj != NULL) {
			pCallbackObj->AddRef();
			pCallbackObj->m_pDoc = pThis;	
		}
		TCHAR name[MAX_PATH] = _T("");
		if (pThis->m_bAsync)
			pThis->PostMessage(MSG_READY_STATE_CHANGE,1);
		
		hr = URLDownloadToCacheFile(NULL,pThis->m_FileName,name,URLOSTRM_GETNEWESTVERSION,0,pCallbackObj);
		if (pCallbackObj != NULL)
			pCallbackObj->Release();

		if (E_ABORT == hr)
			pThis->m_bAbort = true;
		else {	
			if (S_OK != hr) {
				_bstr_t error = _T("Failed to download ") + pThis->m_FileName + _T(": ");
				_com_error comError(hr);
				error += comError.ErrorMessage();
				pThis->m_pParseError->SetData(1,pThis->m_FileName,error,_T(""),0,0,0);
				pThis->m_bParseError = true;
			}
		}

		if (S_OK == hr) {
			pThis->m_FileName = name;
			if (pThis->m_bAsync)
				pThis->PostMessage(MSG_READY_STATE_CHANGE,2);
		}
	}

	XercesDOMParser parser;

	//
	//   If set to true then an node supporting IXMLDOMProcessingInstruction
	//     is added for the XML declaration.
	//
	//   Setting to true in a custom DLL will better mimic
	//      MSXML.DLL but at a cost of conformance errors
	//      using David Brownell's suite
	//parser.setToCreateXMLDeclTypeNode(false);

	parser.setIncludeIgnorableWhitespace(pThis->m_bPreserveWhiteSpace);



	if (!pThis->m_bParseError && !pThis->m_bAbort) {
		parser.setDoValidation(pThis->m_bThreadValidate);
		//
		//   this brings the COM component into better mimicry to MSXML
		//      by not throwing a validation error when there is no DOCTYPE
		//
		parser.setValidationScheme(pThis->m_bThreadValidate ? AbstractDOMParser::Val_Auto : AbstractDOMParser::Val_Never);
	}

	if (!pThis->m_bParseError && !pThis->m_bAbort)
		parser.setErrorHandler(pThis);

	if (!pThis->m_bParseError && !pThis->m_bAbort)
		pThis->m_pParseError->Reset();
	
	if (!pThis->m_bParseError && !pThis->m_bAbort)
		pThis->m_bParseError = false;

	try
	{
		if (!pThis->m_bParseError && !pThis->m_bAbort) {
			if (pThis->m_FileName.length() > 0)
				parser.parse(static_cast<LPCTSTR> (pThis->m_FileName));
			else {
				XMLByte *pXMLByte =  reinterpret_cast<XMLByte*> (static_cast<XMLCh*>(pThis->m_xml));
				MemBufInputSource memBufIS(pXMLByte,pThis->m_xml.length()*sizeof(XMLCh),OLESTR("IBMXMLParser"),false);
				memBufIS.setEncoding(OLESTR("UTF-16LE"));
				if (!pThis->m_bParseError && !pThis->m_bAbort)
					parser.parse(memBufIS);
			}
		}

	}
	catch(...)
	{
		pThis->m_bParseError = true;
		return 0;
	}

	if (!pThis->m_bParseError && !pThis->m_bAbort)
		pThis->m_TmpDocument = parser.adoptDocument();

	if (!pThis->m_bParseError && !pThis->m_bAbort && pThis->m_bAsync)
		pThis->PostMessage(MSG_READY_STATE_CHANGE,4);
  	
	return 0;
}
コード例 #5
0
//fast. doesn't check for server-side date.
HRESULT CInternetFileManagerObject::GetFileComplex(BSTR bstrURL, BSTR *pbstrFinalURL, 
												   BSTR *pbstrFinalPath)
{
	char szPath[INTERNET_MAX_PATH_LENGTH];
	BOOL bRetVal;
	char cinfo[MAX_CACHE_ENTRY_INFO_SIZE];
	HRESULT hr = S_OK;
	CString strFullURL, strFilename, strExtension;
	ULONG length;
	long index=0;
#ifdef _DEBUG
	DWORD dwTick = 0;
#endif
	
	if (bstrURL == NULL)
	{
		TRACE("CInternetFileManagerObject::GetFileComplex: incoming argument (BSTR) is NULL\n");
		return E_INVALIDARG;
	}

	if (pbstrFinalPath == NULL)	
	{
		TRACE("CInternetFileManagerObject::GetFileComplex: outgoing pointer (BSTR*) is NULL\n");
		return E_POINTER;
	}

	*pbstrFinalPath = NULL;

	//extract extension
	_splitpath(CString(bstrURL), NULL, NULL, NULL, szPath);
	strExtension = CString(szPath);
	strExtension = strExtension.Right(strExtension.GetLength()-1);

	strFullURL = bstrURL;

	//check if is fullurl.
	if (IsFullURL(bstrURL))
	{
#ifdef _DEBUG
		dwTick = GetTickCount();
#endif

		hr = URLDownloadToCacheFile(NULL, strFullURL, szPath, INTERNET_MAX_PATH_LENGTH, 0 /*BINDF_GETNEWESTVERSION*/, NULL);

		if (SUCCEEDED(hr))
		{
			strFilename = CString(szPath);
			
#ifdef _DEBUG
			TRACE("CInternetFileManagerObject::GetFileComplex: successfully downloaded %s as %s, duration %3.2f sec\n", strFullURL, strFilename, (float)(GetTickCount() - dwTick) / 1000.0);
#endif

			*pbstrFinalURL = strFullURL.AllocSysString();
			*pbstrFinalPath = strFilename.AllocSysString();
		}
		else
		{
#ifdef _DEBUG
//			TRACE("CInternetFileManagerObject::GetFileComplex: failed to download %s, hr %x, duration %3.2f sec\n", strFullURL, (float)(GetTickCount() - dwTick) / 1000.0);
#endif

			hr = INETFILE_E_FILENOTFOUND;
		}
	}
	else
	{
		if (m_RootURLs.GetSize() == 0)
		{
			TRACE("CInternetFileManagerObject::GetFileComplex: root URL list is empty\n");
			return INETFILE_E_INVALIDROOTURL;
		}

		//iterate through each url;
		for (index=0; index<m_RootURLs.GetSize(); index++)
		{
			hr = S_OK;

#ifdef _DEBUG
			dwTick = GetTickCount();
#endif

			strFullURL = m_RootURLs[index] + "/" + CString(bstrURL);
			
			//find a cache name.
			length = sizeof(cinfo);
			
			bRetVal = RetrieveUrlCacheEntryFile(strFullURL,(INTERNET_CACHE_ENTRY_INFO *)&cinfo, &length, 0);

			UnlockUrlCacheEntryFile(strFullURL, 0);

			if (!bRetVal) 
			{	
				hr = URLDownloadToCacheFile(NULL, strFullURL, szPath, INTERNET_MAX_PATH_LENGTH, 0 /*BINDF_GETNEWESTVERSION*/, NULL);
				if (SUCCEEDED(hr)) 
				{
					strFilename = CString(szPath);
				
#ifdef _DEBUG
					TRACE("CInternetFileManagerObject::GetFileComplex: successfully downloaded %s as %s, duration %3.2f sec\n", strFullURL, strFilename, (float)(GetTickCount() - dwTick) / 1000.0);
#endif
				}
				else
				{
#ifdef _DEBUG
//					TRACE("CInternetFileManagerObject::GetFileComplex: failed to download %s, duration %3.2f sec\n", strFullURL, (float)(GetTickCount() - dwTick) / 1000.0);
#endif

					UnlockUrlCacheEntryFile(strFullURL, 0);
					DeleteUrlCacheEntry(strFullURL);

					hr = INETFILE_E_FILENOTFOUND;

					continue;
				}
			}
			else
			{
				strFilename = CString(((INTERNET_CACHE_ENTRY_INFO *)&cinfo)->lpszLocalFileName);

#ifdef _DEBUG
				TRACE("CInternetFileManagerObject::GetFileComplex: using cached URL %s as %s, duration %3.2f sec\n", 
					strFullURL, strFilename, (float)(GetTickCount() - dwTick) / 1000.0);	
#endif
			}
			
			*pbstrFinalURL = strFullURL.AllocSysString();
			*pbstrFinalPath = strFilename.AllocSysString();

			break;
		}
	}
	
//	if(*pbstrFinalPath==NULL)
//		hr=E_FAIL;

	return hr;
}
コード例 #6
0
//simplified version. slower, checks for server-side date.
HRESULT CInternetFileManagerObject::GetFileSimplified(BSTR bstrURL, BSTR *pbstrFinalURL, 
													  BSTR *pbstrFinalPath)
{
	char szPath[INTERNET_MAX_PATH_LENGTH];
	HRESULT hr = S_OK;
	CString strFullURL,strFilename,strExtension;
	long index = 0;
#ifdef _DEBUG
	DWORD dwTick;
#endif

	if (bstrURL == NULL)
	{
		TRACE("CInternetFileManagerObject::GetFileSimplified: incoming argument (BSTR) is NULL\n");
		return E_INVALIDARG;
	}

	if (pbstrFinalPath == NULL)	
	{
		TRACE("CInternetFileManagerObject::GetFileSimplified: outgoing pointer (BSTR*) is NULL\n");
		return E_POINTER;
	}

	*pbstrFinalPath = NULL;

	strFullURL = CString(bstrURL);

	//check if is fullurl.
	if (IsFullURL(bstrURL))
	{
#ifdef _DEBUG
		dwTick = GetTickCount();
#endif

		hr = URLDownloadToCacheFile(NULL, strFullURL, szPath, INTERNET_MAX_PATH_LENGTH, 0 /*BINDF_GETNEWESTVERSION*/, NULL);

		if (SUCCEEDED(hr))
		{
			strFilename = CString(szPath);

#ifdef _DEBUG
#ifdef DLTHREAD_DEBUG
			TRACE("CInternetFileManagerObject::GetFileSimplified: successfully downloaded %s as %s, duration %3.2f sec\n", strFullURL, strFilename, (float)(GetTickCount() - dwTick) / 1000.0);
#endif

#ifdef DLTHREAD_DEBUG
			DWORD dwNow = GetTickCount();
			CString strTemp;
			
			strTemp.Format("Download URL (succeeded),%d,%s,%d\n", dwNow, strFullURL, dwNow - dwTick);
			OutputDebugString((LPCTSTR)strTemp);
#endif
#endif

			*pbstrFinalURL = strFullURL.AllocSysString();
			*pbstrFinalPath = strFilename.AllocSysString();
		}
		else
		{
#ifdef _DEBUG
#ifdef INETFILE_DOWNLOAD_DEBUG
			TRACE("CInternetFileManagerObject::GetFileSimplified: failed to download %s, hr %x, duration %3.2f sec\n", strFullURL, (float)(GetTickCount() - dwTick) / 1000.0);
#endif

#ifdef DLTHREAD_DEBUG
			DWORD dwNow = GetTickCount();
			CString strTemp;
			
			strTemp.Format("Download URL (failed),%d,%s,%d\n", dwNow, strFullURL, dwNow - dwTick);
			OutputDebugString((LPCTSTR)strTemp);
#endif
#endif

			hr = INETFILE_E_FILENOTFOUND;
		}
	}
	else
	{
		if (m_RootURLs.GetSize() == 0)
		{
			TRACE("CInternetFileManagerObject::GetFileSimplified: root URL list is empty\n");
			return INETFILE_E_INVALIDROOTURL;
		}

		//iterate through each url;
		for (index=0; index<m_RootURLs.GetSize(); index++)
		{
			strFullURL = m_RootURLs[index] + "/" + CString(bstrURL);

#ifdef _DEBUG
			dwTick = GetTickCount();
#endif
			
			hr = URLDownloadToCacheFile(NULL, strFullURL, szPath, INTERNET_MAX_PATH_LENGTH, 0 /*BINDF_GETNEWESTVERSION*/, NULL);

			if (SUCCEEDED(hr)) 
			{
				strFilename = CString(szPath);
			
#ifdef _DEBUG
#ifdef DLTHREAD_DEBUG
				TRACE("CInternetFileManagerObject::GetFileSimplified: successfully downloaded %s as %s, duration %3.2f sec\n", strFullURL, strFilename, (float)(GetTickCount() - dwTick) / 1000.0);
#endif

#ifdef DLTHREAD_DEBUG
				DWORD dwNow = GetTickCount();
				CString strTemp;
			
				strTemp.Format("Download URL (succeeded),%d,%s,%d\n", dwNow, strFullURL, dwNow - dwTick);
				OutputDebugString((LPCTSTR)strTemp);
#endif
#endif

				*pbstrFinalURL = strFullURL.AllocSysString();
				*pbstrFinalPath = strFilename.AllocSysString();

				break;
			}
			else
			{
#ifdef _DEBUG
#ifdef INETFILE_DOWNLOAD_DEBUG
				TRACE("CInternetFileManagerObject::GetFileSimplified: failed to download %s, duration %3.2f sec\n", strFullURL, (float)(GetTickCount() - dwTick) / 1000.0);
#endif

#ifdef DLTHREAD_DEBUG
				DWORD dwNow = GetTickCount();
				CString strTemp;
			
				strTemp.Format("Download URL (failed),%d,%s,%d\n", dwNow, strFullURL, dwNow - dwTick);
				OutputDebugString((LPCTSTR)strTemp);
#endif
#endif

				hr = INETFILE_E_FILENOTFOUND;
			}
		}
	}
	
	return hr;
}