Ejemplo n.º 1
0
inline void DebugOut(const char *format,...)
{

	static char a[50000];
	va_list pz;
	va_start(pz, format);
	vsprintf(a,format,pz);
	USES_CONVERSION;
	LPCWSTR pw = A2CW(a) ;
	OutputDebugString(a);
}
void vmsUrlMonRequestCollector::onHttpNegotiate_OnResponse(IHttpNegotiate* pHN, DWORD dwResponseCode, LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR* pszAdditionalRequestHeaders)
{
	vmsCriticalSectionAutoLock csal (&m_csReq);
	int nIndex = findRequestIndexByHttpNegotiate (pHN);
	if (nIndex == -1)
		return;
	Request *req = getRequest (nIndex);
	req->dwState |= Request::GotResponse;

	IWinInetHttpInfoPtr spWinInetHttpInfo (req->spProt);
	if (spWinInetHttpInfo != NULL)
	{
		DWORD dwSize = 0, dwFlags = 0;
		spWinInetHttpInfo->QueryInfo (HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HEADERS, 0, &dwSize, &dwFlags, 0);
		if (dwSize)
		{
			std::vector <char> vBuf (dwSize);
			LPSTR psz = &vBuf.front (); *psz = 0;
			spWinInetHttpInfo->QueryInfo (HTTP_QUERY_RAW_HEADERS_CRLF | HTTP_QUERY_FLAG_REQUEST_HEADERS, psz, &dwSize, &dwFlags, 0);
			req->strRequestHeaders = psz;
		}
		dwSize = 0; dwFlags = 0;
		spWinInetHttpInfo->QueryInfo (HTTP_QUERY_RAW_HEADERS_CRLF, 0, &dwSize, &dwFlags, 0);
		if (dwSize)
		{
			std::vector <char> vBuf (dwSize);
			LPSTR psz = &vBuf.front (); *psz = 0;
			spWinInetHttpInfo->QueryInfo (HTTP_QUERY_RAW_HEADERS_CRLF, psz, &dwSize, &dwFlags, 0);
			req->strResponseHeaders = psz;
		}
	}

	IWinInetInfoPtr spWinInetInfo (req->spProt);
	if (spWinInetInfo != NULL)
	{
		vector <char> vch; vch.resize (1000); vch [0] = 0;
		DWORD dwSize = vch.size ();
		HRESULT hr = spWinInetInfo->QueryOption (INTERNET_OPTION_URL, &vch[0], &dwSize);
		if (dwSize > vch.size ())
		{
			vch.resize (dwSize); vch [0] = 0;
			hr = spWinInetInfo->QueryOption (INTERNET_OPTION_URL, &vch[0], &dwSize);
		}
		if (SUCCEEDED (hr))
		{
			USES_CONVERSION;
			wstring wstr = A2CW (&vch[0]);
			if (wcscmp (wstr.c_str (), req->wstrUrl.c_str ()))
				req->wstrRedirectedUrl = wstr;
		}
	}
}
CStringW GetUnicodeFromAnsi(LPCSTR a_strString)
{
	USES_CONVERSION;
/*	static TCHAR szBuffer[1024*1024]; // 1MB buffer to handle string 

	if (strlen( a_strString) > 1024*1024)
		AfxThrowMemoryException();
	_tcscpy_s( szBuffer, 1024*1024, CA2CT( a_strString));
	return szBuffer;
*/
	static CStringW csWide;

	csWide = A2CW(a_strString);
	return csWide;

}
Ejemplo n.º 4
0
void call_once(void (*func)(), once_flag& flag)
{
#if defined(BOOST_HAS_WINTHREADS)
    if (compare_exchange(&flag, 1, 1) == 0)
    {
#if defined(BOOST_NO_STRINGSTREAM)
        std::ostrstream strm;
        strm << "2AC1A572DB6944B0A65C38C4140AF2F4" 
             << std::hex
             << GetCurrentProcessId() 
             << &flag 
             << std::ends;
        unfreezer unfreeze(strm);
#   if defined (BOOST_NO_ANSI_APIS)
        USES_CONVERSION;
        HANDLE mutex = CreateMutexW(NULL, FALSE, A2CW(strm.str()));
#   else
        HANDLE mutex = CreateMutexA(NULL, FALSE, strm.str());
#   endif
#else
#   if defined (BOOST_NO_ANSI_APIS)
        std::wostringstream strm;
        strm << L"2AC1A572DB6944B0A65C38C4140AF2F4" 
             << std::hex
             << GetCurrentProcessId() 
             << &flag;
        HANDLE mutex = CreateMutexW(NULL, FALSE, strm.str().c_str());
#   else
        std::ostringstream strm;
        strm << "2AC1A572DB6944B0A65C38C4140AF2F4" 
             << std::hex
             << GetCurrentProcessId() 
             << &flag;
        HANDLE mutex = CreateMutexA(NULL, FALSE, strm.str().c_str());
#   endif
#endif
        assert(mutex != NULL);

        int res = 0;
        res = WaitForSingleObject(mutex, INFINITE);
        assert(res == WAIT_OBJECT_0);

        if (compare_exchange(&flag, 1, 1) == 0)
        {
            try
            {
                func();
            }
            catch (...)
            {
                res = ReleaseMutex(mutex);
                assert(res);
                res = CloseHandle(mutex);
                assert(res);
                throw;
            }
            InterlockedExchange(&flag, 1);
        }

        res = ReleaseMutex(mutex);
        assert(res);
        res = CloseHandle(mutex);
        assert(res);
    }
#elif defined(BOOST_HAS_PTHREADS)
    pthread_once(&once, &key_init);
    pthread_setspecific(key, &func);
    pthread_once(&flag, do_once);
#elif defined(BOOST_HAS_MPTASKS)
    if(flag == false)
    {
        // all we do here is make a remote call to blue, as blue is not
        // reentrant.
        std::pair<void (*)(), once_flag *> sData(func, &flag);
        MPRemoteCall(remote_call_proxy, &sData, kMPOwningProcessRemoteContext);
        assert(flag == true);
    }
#endif
}
Ejemplo n.º 5
0
vmsBtDownload* vmsBtSessionImpl::CreateDownload (vmsBtFile *torrent, LPCSTR pszOutputPath, LPBYTE pbFastResumeData, DWORD dwFRDataSize, vmsBtStorageMode enStorageMode, DWORD dwFlags)
{
	char szPath [10000];
	strcpy (szPath, pszOutputPath);
	LPSTR psz = szPath;
	while (*psz)
	{
		if (*psz == '\\')
			*psz = '/';
		psz++;
	}
	if (strlen (szPath) == 2 && szPath [1] == ':')
		strcat (szPath, "/");

	try 
	{
		libtorrent::torrent_handle th;
		vmsBtFileImpl *torrentimpl = (vmsBtFileImpl*) torrent;

		libtorrent::entry entryFastResume = pbFastResumeData ? libtorrent::bdecode (pbFastResumeData, pbFastResumeData + dwFRDataSize) : libtorrent::entry ();

		try {
			if (entryFastResume.type () != libtorrent::entry::undefined_t)
				entryFastResume ["paused"] = 0;
		}catch (...) {}

		if (dwFlags & BTSCDF_FORCE_IGNORE_TIMESTAMPS)
		{		
			
			
			try {
			if (entryFastResume.type () != libtorrent::entry::undefined_t)
			{
				wchar_t wszPath [MAX_PATH] = L"";
				MultiByteToWideChar (CP_UTF8, 0, pszOutputPath, -1, wszPath, MAX_PATH-1);
				if (wszPath [wcslen (wszPath) - 1] != '\\')
					wcscat (wszPath, L"\\");

				libtorrent::entry::list_type &fl = entryFastResume ["file sizes"].list();
				
				libtorrent::entry::list_type::iterator eFRi = fl.begin ();
				
				libtorrent::torrent_info::file_iterator tiFi = torrentimpl->m_torrent->begin_files ();

				wchar_t wszFile [MAX_PATH];
				wcscpy (wszFile, wszPath);
				int nPathLen = wcslen (wszPath);

				for (; tiFi != torrentimpl->m_torrent->end_files (); tiFi++, eFRi++)
				{
					wszFile [nPathLen] = 0; 
					MultiByteToWideChar (CP_UTF8, 0, tiFi->path.string ().c_str (), -1, wszFile + nPathLen, MAX_PATH - nPathLen);
					WIN32_FILE_ATTRIBUTE_DATA wfad;
					if (GetFileAttributesExW (wszFile, GetFileExInfoStandard, &wfad))
						eFRi->list ().back ().integer () = FILETIMEToUnixTime (wfad.ftLastWriteTime);
				}
			}
			}catch (...){}
		}

		libtorrent::storage_mode_t sm;
		if (enStorageMode == BTSM_SPARSE)
			sm = libtorrent::storage_mode_sparse;
		else if (enStorageMode == BTSM_ALLOCATE)
			sm = libtorrent::storage_mode_allocate;
		else
			sm = libtorrent::storage_mode_compact;

		vmsAUTOLOCKSECTION (m_csDownloads);

		USES_CONVERSION;
		LPCWSTR pwszOutputPath = A2CW (pszOutputPath);
		std::string utf8;
		libtorrent::wchar_utf8 (pwszOutputPath, utf8);
		
		if (torrentimpl->IsMagnetLink())
		{
			boost::system::error_code err;

			libtorrent::add_torrent_params p;
			p.save_path = utf8;
			p.storage_mode = (libtorrent::storage_mode_t)libtorrent::storage_mode_allocate;
			p.paused = true;
			p.duplicate_is_error = false;
			p.auto_managed = true;

			th = libtorrent::add_magnet_uri(m_session, torrentimpl->GetMagnetLink(), p, err);
		}
		else
		{
			th = m_session.add_torrent (*torrentimpl->m_torrent, utf8, entryFastResume, sm);
		}

		th.set_ratio (1);

		vmsBtDownloadImpl *pDld = new vmsBtDownloadImpl(th, torrentimpl, utf8);
		pDld->AddRef ();
		
		m_vDownloads.push_back (pDld);
		return pDld;
	}
	catch (std::exception&) 
	{
		return NULL;
	}
}
Ejemplo n.º 6
0
HRESULT PASCAL CComObjectRoot::Error(const CLSID& clsid, LPCSTR lpszDesc,
	const IID& iid, HRESULT hRes)
{
	USES_CONVERSION;
	return Error(clsid, A2CW(lpszDesc), iid, hRes);
}
Ejemplo n.º 7
0
 static LRESULT LoadResourceData(HWND hWnd, LPCSTR uri )
 {
    USES_CONVERSION;
    return LoadResourceData(hWnd,A2CW(uri));
 }