GateKeeper.cpp
branchsync
changeset 367 38698c75fbbf
parent 366 f369f8053681
parent 364 2259aa4c6a64
child 370 8be91c5f6570
     1.1 --- a/GateKeeper.cpp	Mon Oct 21 11:59:42 2019 +0200
     1.2 +++ b/GateKeeper.cpp	Fri Nov 01 15:06:30 2019 +0100
     1.3 @@ -392,52 +392,52 @@
     1.4          return fileName;
     1.5      }
     1.6  
     1.7 -	// Retrieving Headers Using HTTP_QUERY_CUSTOM
     1.8 -	static tstring httpQueryCustom(HINTERNET hHttp, tstring header)
     1.9 -	{
    1.10 -		DWORD dwResult = 0;
    1.11 -		LPTSTR lpOutBuffer = StrDup(header.c_str());
    1.12 +    // Retrieving Headers Using HTTP_QUERY_CUSTOM
    1.13 +    static tstring httpQueryCustom(HINTERNET hHttp, tstring header)
    1.14 +    {
    1.15 +        DWORD dwResult = 0;
    1.16 +        LPTSTR lpOutBuffer = StrDup(header.c_str());
    1.17  
    1.18 -	retry:
    1.19 +    retry:
    1.20  
    1.21 -		if (!HttpQueryInfo(hHttp, HTTP_QUERY_CUSTOM, (LPVOID)lpOutBuffer, &dwResult, NULL))
    1.22 -		{
    1.23 -			if (GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND)
    1.24 -			{
    1.25 -				// Code to handle the case where the header isn't available.
    1.26 -				LocalFree(lpOutBuffer);
    1.27 -				throw(runtime_error("ERROR_HTTP_HEADER_NOT_FOUND"));
    1.28 -			}
    1.29 -			else
    1.30 -			{
    1.31 -				// Check for an insufficient buffer.
    1.32 -				if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
    1.33 -				{
    1.34 -					// Allocate the necessary buffer.
    1.35 -					LocalFree(lpOutBuffer);
    1.36 -					lpOutBuffer = (LPTSTR)LocalAlloc(LMEM_FIXED, dwResult + 1);
    1.37 +        if (!HttpQueryInfo(hHttp, HTTP_QUERY_CUSTOM, (LPVOID)lpOutBuffer, &dwResult, NULL))
    1.38 +        {
    1.39 +            if (GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND)
    1.40 +            {
    1.41 +                // Code to handle the case where the header isn't available.
    1.42 +                LocalFree(lpOutBuffer);
    1.43 +                throw(runtime_error("ERROR_HTTP_HEADER_NOT_FOUND"));
    1.44 +            }
    1.45 +            else
    1.46 +            {
    1.47 +                // Check for an insufficient buffer.
    1.48 +                if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
    1.49 +                {
    1.50 +                    // Allocate the necessary buffer.
    1.51 +                    LocalFree(lpOutBuffer);
    1.52 +                    lpOutBuffer = (LPTSTR)LocalAlloc(LMEM_FIXED, dwResult + 1);
    1.53  
    1.54 -					// Rewrite the header name in the buffer.
    1.55 -					StringCchPrintf(lpOutBuffer, dwResult, header.c_str());
    1.56 +                    // Rewrite the header name in the buffer.
    1.57 +                    StringCchPrintf(lpOutBuffer, dwResult, header.c_str());
    1.58  
    1.59 -					// Retry the call.
    1.60 -					goto retry;
    1.61 -				}
    1.62 -				else
    1.63 -				{
    1.64 -					// Error handling code.
    1.65 -					LocalFree(lpOutBuffer);
    1.66 -					// FIXME: Add GetLastError()
    1.67 -					throw(runtime_error("Unknown"));
    1.68 -				}
    1.69 -			}
    1.70 -		}
    1.71 +                    // Retry the call.
    1.72 +                    goto retry;
    1.73 +                }
    1.74 +                else
    1.75 +                {
    1.76 +                    // Error handling code.
    1.77 +                    LocalFree(lpOutBuffer);
    1.78 +                    // FIXME: Add GetLastError()
    1.79 +                    throw(runtime_error("Unknown"));
    1.80 +                }
    1.81 +            }
    1.82 +        }
    1.83  
    1.84 -		tstring result(lpOutBuffer);
    1.85 -		LocalFree(lpOutBuffer);
    1.86 +        tstring result(lpOutBuffer);
    1.87 +        LocalFree(lpOutBuffer);
    1.88  
    1.89 -		return result;
    1.90 -	}
    1.91 +        return result;
    1.92 +    }
    1.93  
    1.94      bool GateKeeper::update_product(product p, DWORD context)
    1.95      {
    1.96 @@ -475,7 +475,7 @@
    1.97          tstring filename;
    1.98          HANDLE hFile = NULL;
    1.99          char *unencrypted_buffer = NULL;
   1.100 -		bool result = false;
   1.101 +        bool result = false;
   1.102  
   1.103          try {
   1.104  
   1.105 @@ -490,14 +490,14 @@
   1.106                  crypted += string(buffer, reading);
   1.107              } while (1);
   1.108  
   1.109 -			tstring contentDisposition = httpQueryCustom(hUrl, _T("Content-Disposition"));
   1.110 +            tstring contentDisposition = httpQueryCustom(hUrl, _T("Content-Disposition"));
   1.111  
   1.112 -			tregex filenameRegex(_T("filename=.([^\"]*)"), regex::extended); //FIXME: case insensitive
   1.113 -			tsmatch match;
   1.114 +            tregex filenameRegex(_T("filename=.([^\"]*)"), regex::extended); //FIXME: case insensitive
   1.115 +            tsmatch match;
   1.116  
   1.117 -			if (regex_search(contentDisposition, match, filenameRegex)) {
   1.118 -				filename = match[1];
   1.119 -			}
   1.120 +            if (regex_search(contentDisposition, match, filenameRegex)) {
   1.121 +                filename = match[1];
   1.122 +            }
   1.123  
   1.124              InternetCloseHandle(hUrl);
   1.125              hUrl = NULL;
   1.126 @@ -533,15 +533,15 @@
   1.127              TCHAR temp_path[MAX_PATH + 1];
   1.128              GetTempPath(MAX_PATH, temp_path);
   1.129  
   1.130 -			if (filename == _T("")) {
   1.131 -				filename = temp_path;
   1.132 -				filename += _T("\\pEp_");
   1.133 -				filename += delivery.substr(0, 32);
   1.134 -				filename += _T(".msi");
   1.135 -			}
   1.136 -			else {
   1.137 -				filename = tstring(temp_path) + _T("\\") + filename;
   1.138 -			}
   1.139 +            if (filename == _T("")) {
   1.140 +                filename = temp_path;
   1.141 +                filename += _T("\\pEp_");
   1.142 +                filename += delivery.substr(0, 32);
   1.143 +                filename += _T(".msi");
   1.144 +            }
   1.145 +            else {
   1.146 +                filename = tstring(temp_path) + _T("\\") + filename;
   1.147 +            }
   1.148  
   1.149              hFile = CreateFile(filename.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
   1.150              if (!hFile)
   1.151 @@ -549,7 +549,7 @@
   1.152              DWORD writing;
   1.153              WriteFile(hFile, unencrypted_buffer, unencrypted_size, &writing, NULL);
   1.154              CloseHandle(hFile);
   1.155 -			hFile = NULL;
   1.156 +            hFile = NULL;
   1.157              delete[] unencrypted_buffer;
   1.158              unencrypted_buffer = nullptr;
   1.159          }
   1.160 @@ -558,7 +558,7 @@
   1.161          }
   1.162  
   1.163          execute_file(filename);
   1.164 -		result = true;
   1.165 +        result = true;
   1.166  
   1.167      closing:
   1.168          if (unencrypted_buffer)
   1.169 @@ -569,7 +569,7 @@
   1.170              InternetCloseHandle(hUrl);
   1.171          BCryptDestroyKey(dk);
   1.172  
   1.173 -		return result;
   1.174 +        return result;
   1.175      }
   1.176  
   1.177      void GateKeeper::keep_updated()