1 // Copyright 2019 Google LLC 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are 5 // met: 6 // 7 // * Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // * Redistributions in binary form must reproduce the above 10 // copyright notice, this list of conditions and the following disclaimer 11 // in the documentation and/or other materials provided with the 12 // distribution. 13 // * Neither the name of Google LLC nor the names of its 14 // contributors may be used to endorse or promote products derived from 15 // this software without specific prior written permission. 16 // 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29 #ifndef TOOLS_CRASH_CONVERTER_WINDOWS_HTTP_CLIENT_H_ 30 #define TOOLS_CRASH_CONVERTER_WINDOWS_HTTP_CLIENT_H_ 31 32 #include <tchar.h> 33 #include <windows.h> 34 #include <vector> 35 36 typedef void* HttpHandle; 37 38 namespace crash { 39 40 // HttpClient provides an abstract layer for HTTP APIs. The actual 41 // implementation can be based on either WinHttp or WinInet. 42 class HttpClient { 43 public: 44 enum AccessType { 45 ACCESS_TYPE_PRECONFIG, 46 ACCESS_TYPE_DIRECT, 47 ACCESS_TYPE_PROXY, 48 }; 49 ~HttpClient()50 virtual ~HttpClient() {} 51 52 virtual bool CrackUrl(const TCHAR* url, 53 DWORD flags, 54 TCHAR* scheme, 55 size_t scheme_buffer_length, 56 TCHAR* host, 57 size_t host_buffer_length, 58 TCHAR* uri, 59 size_t uri_buffer_length, 60 int* port) const = 0; 61 virtual bool Open(const TCHAR* user_agent, 62 DWORD access_type, 63 const TCHAR* proxy_name, 64 const TCHAR* proxy_bypass, 65 HttpHandle* session_handle) const = 0; 66 virtual bool Connect(HttpHandle session_handle, 67 const TCHAR* server, 68 int port, 69 HttpHandle* connection_handle) const = 0; 70 virtual bool OpenRequest(HttpHandle connection_handle, 71 const TCHAR* verb, 72 const TCHAR* uri, 73 const TCHAR* version, 74 const TCHAR* referrer, 75 bool is_secure, 76 HttpHandle* request_handle) const = 0; 77 virtual bool SendRequest(HttpHandle request_handle, 78 const TCHAR* headers, 79 DWORD headers_length) const = 0; 80 virtual bool ReceiveResponse(HttpHandle request_handle) const = 0; 81 virtual bool GetHttpStatusCode(HttpHandle request_handle, 82 int* status_code) const = 0; 83 virtual bool GetContentLength(HttpHandle request_handle, 84 DWORD* content_length) const = 0; 85 virtual bool ReadData(HttpHandle request_handle, 86 void* buffer, 87 DWORD buffer_length, 88 DWORD* bytes_read) const = 0; 89 virtual bool Close(HttpHandle handle) const = 0; 90 91 static const DWORD kUnknownContentLength = (DWORD)-1; 92 }; 93 94 } // namespace crash 95 96 #endif // TOOLS_CRASH_CONVERTER_WINDOWS_HTTP_CLIENT_H_ 97