MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / DoBlockingHttpCall

Function DoBlockingHttpCall

3rdparty/rainterface/RA_Interface.cpp:365–567  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

363typedef size_t (DownloadFunc)(char* pData, size_t nDataSize, void* pUserData, DWORD* pStatusCode);
364
365static BOOL DoBlockingHttpCall(const char* sHostUrl, const char* sRequestedPage, const char* sPostData,
366 DownloadFunc fnDownload, void* pDownloadUserData, DWORD* pBytesRead, DWORD* pStatusCode, IProgressDialog* pProgressDialog)
367{
368 BOOL bResults = FALSE, bSuccess = FALSE;
369 HINTERNET hSession = nullptr, hConnect = nullptr, hRequest = nullptr;
370 size_t nHostnameLen;
371
372 WCHAR wBuffer[1024];
373 size_t nTemp;
374 DWORD nBytesAvailable = 0;
375 DWORD nBytesToRead = 0;
376 DWORD nBytesFetched = 0;
377 (*pBytesRead) = 0;
378
379 INTERNET_PORT nPort = INTERNET_DEFAULT_HTTP_PORT;
380 const char* sHostName = sHostUrl;
381 if (_strnicmp(sHostName, "http://", 7) == 0)
382 {
383 sHostName += 7;
384 }
385 else if (_strnicmp(sHostName, "https://", 8) == 0)
386 {
387 sHostName += 8;
388 nPort = INTERNET_DEFAULT_HTTPS_PORT;
389 }
390
391 const char* sPort = strchr(sHostName, ':');
392 if (sPort)
393 {
394 nHostnameLen = sPort - sHostName;
395 nPort = atoi(sPort + 1);
396 }
397 else
398 {
399 nHostnameLen = strlen(sHostName);
400 }
401
402 // Use WinHttpOpen to obtain a session handle.
403 hSession = WinHttpOpen(L"RetroAchievements Client Bootstrap",
404 WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
405 WINHTTP_NO_PROXY_NAME,
406 WINHTTP_NO_PROXY_BYPASS, 0);
407
408 // Specify an HTTP server.
409 if (hSession == nullptr)
410 {
411 *pStatusCode = GetLastError();
412 }
413 else
414 {
415#if defined(_MSC_VER) && _MSC_VER >= 1400
416 mbstowcs_s(&nTemp, wBuffer, sizeof(wBuffer) / sizeof(wBuffer[0]), sHostName, nHostnameLen);
417#else
418 nTemp = mbstowcs(wBuffer, sHostName, nHostnameLen);
419 if (nTemp > 0)
420 wBuffer[nTemp] = '\0';
421#endif
422

Callers 1

Calls 2

GetLastErrorFunction · 0.85
SetProgressMessageFunction · 0.85

Tested by

no test coverage detected