diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2015-03-24 09:06:20 -0400 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2015-03-24 09:06:20 -0400 |
commit | aa7a4a507786ed9ad414d76843debafc61f1f334 (patch) | |
tree | b4896c549a16ffc8a515a7c3c104a64c788f58a5 /src | |
parent | 95d1624b8d7dcda58527cb26b9e7c9c8b2af0d6a (diff) | |
parent | b631e0d96d4dfd3a254b9fc46aaf561428da7c9c (diff) | |
download | libgit2-aa7a4a507786ed9ad414d76843debafc61f1f334.tar.gz |
Merge pull request #2986 from tkelman/mingw_winhttp
WinHTTP for MinGW
Diffstat (limited to 'src')
-rw-r--r-- | src/transports/winhttp.c | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c index 278ef22c4..f93a031f1 100644 --- a/src/transports/winhttp.c +++ b/src/transports/winhttp.c @@ -17,19 +17,12 @@ #include "repository.h" #include <wincrypt.h> -#pragma comment(lib, "crypt32") #include <winhttp.h> -#pragma comment(lib, "winhttp") - -#include <strsafe.h> /* For IInternetSecurityManager zone check */ #include <objbase.h> #include <urlmon.h> -/* For UuidCreate */ -#pragma comment(lib, "rpcrt4") - #define WIDEN2(s) L ## s #define WIDEN(s) WIDEN2(s) @@ -43,7 +36,6 @@ #define WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH 0 #endif -static const char *prefix_http = "http://"; static const char *prefix_https = "https://"; static const char *upload_pack_service = "upload-pack"; static const char *upload_pack_ls_service_url = "/info/refs?service=git-upload-pack"; @@ -59,6 +51,13 @@ static const int no_check_cert_flags = SECURITY_FLAG_IGNORE_CERT_CN_INVALID | SECURITY_FLAG_IGNORE_CERT_DATE_INVALID | SECURITY_FLAG_IGNORE_UNKNOWN_CA; +#if defined(__MINGW32__) +const CLSID CLSID_InternetSecurityManager = { 0x7B8A2D94, 0x0AC9, 0x11D1, + { 0x89, 0x6C, 0x00, 0xC0, 0x4F, 0xB6, 0xBF, 0xC4 } }; +const IID IID_IInternetSecurityManager = { 0x79EAC9EE, 0xBAF9, 0x11CE, + { 0x8C, 0x82, 0x00, 0xAA, 0x00, 0x4B, 0xA9, 0x0B } }; +#endif + #define OWNING_SUBTRANSPORT(s) ((winhttp_subtransport *)(s)->parent.subtransport) typedef enum { @@ -272,7 +271,7 @@ static int winhttp_stream_connect(winhttp_stream *s) git_buf buf = GIT_BUF_INIT; char *proxy_url = NULL; wchar_t ct[MAX_CONTENT_TYPE_LEN]; - wchar_t *types[] = { L"*/*", NULL }; + LPCWSTR types[] = { L"*/*", NULL }; BOOL peerdist = FALSE; int error = -1; unsigned long disable_redirects = WINHTTP_DISABLE_REDIRECTS; @@ -551,8 +550,7 @@ static int winhttp_close_connection(winhttp_subtransport *t) } static int winhttp_connect( - winhttp_subtransport *t, - const char *url) + winhttp_subtransport *t) { wchar_t *ua = L"git/1.0 (libgit2 " WIDEN(LIBGIT2_VERSION) L")"; wchar_t *wide_host; @@ -561,8 +559,6 @@ static int winhttp_connect( int default_timeout = TIMEOUT_INFINITE; int default_connect_timeout = DEFAULT_CONNECT_TIMEOUT; - GIT_UNUSED(url); - t->session = NULL; t->connection = NULL; @@ -860,7 +856,7 @@ replay: winhttp_close_connection(t); - if (winhttp_connect(t, location8) < 0) + if (winhttp_connect(t) < 0) return -1; } @@ -963,7 +959,6 @@ static int winhttp_stream_write_single( size_t len) { winhttp_stream *s = (winhttp_stream *)stream; - winhttp_subtransport *t = OWNING_SUBTRANSPORT(s); DWORD bytes_written; int error; @@ -998,7 +993,7 @@ static int put_uuid_string(LPWSTR buffer, size_t buffer_len_cch) { UUID uuid; RPC_STATUS status = UuidCreate(&uuid); - HRESULT result; + int result; if (RPC_S_OK != status && RPC_S_UUID_LOCAL_ONLY != status && @@ -1012,14 +1007,17 @@ static int put_uuid_string(LPWSTR buffer, size_t buffer_len_cch) return -1; } - result = StringCbPrintfW( - buffer, buffer_len_cch, +#if !defined(__MINGW32__) || defined(MINGW_HAS_SECURE_API) + result = swprintf_s(buffer, buffer_len_cch, +#else + result = wsprintfW(buffer, +#endif L"%08x%04x%04x%02x%02x%02x%02x%02x%02x%02x%02x", uuid.Data1, uuid.Data2, uuid.Data3, uuid.Data4[0], uuid.Data4[1], uuid.Data4[2], uuid.Data4[3], uuid.Data4[4], uuid.Data4[5], uuid.Data4[6], uuid.Data4[7]); - if (FAILED(result)) { + if (result < UUID_LENGTH_CCH) { giterr_set(GITERR_OS, "Unable to generate name for temp file"); return -1; } @@ -1053,7 +1051,6 @@ static int winhttp_stream_write_buffered( size_t len) { winhttp_stream *s = (winhttp_stream *)stream; - winhttp_subtransport *t = OWNING_SUBTRANSPORT(s); DWORD bytes_written; if (!s->request && winhttp_stream_connect(s) < 0) @@ -1135,7 +1132,7 @@ static int winhttp_stream_write_chunked( } else { /* Append as much to the buffer as we can */ - int count = min(CACHED_POST_BODY_BUF_SIZE - s->chunk_buffer_len, (int)len); + int count = (int)min(CACHED_POST_BODY_BUF_SIZE - s->chunk_buffer_len, len); if (!s->chunk_buffer) s->chunk_buffer = git__malloc(CACHED_POST_BODY_BUF_SIZE); @@ -1195,6 +1192,8 @@ static int winhttp_uploadpack_ls( winhttp_subtransport *t, winhttp_stream *s) { + GIT_UNUSED(t); + s->service = upload_pack_service; s->service_url = upload_pack_ls_service_url; s->verb = get_verb; @@ -1206,6 +1205,8 @@ static int winhttp_uploadpack( winhttp_subtransport *t, winhttp_stream *s) { + GIT_UNUSED(t); + s->service = upload_pack_service; s->service_url = upload_pack_service_url; s->verb = post_verb; @@ -1217,6 +1218,8 @@ static int winhttp_receivepack_ls( winhttp_subtransport *t, winhttp_stream *s) { + GIT_UNUSED(t); + s->service = receive_pack_service; s->service_url = receive_pack_ls_service_url; s->verb = get_verb; @@ -1228,6 +1231,8 @@ static int winhttp_receivepack( winhttp_subtransport *t, winhttp_stream *s) { + GIT_UNUSED(t); + /* WinHTTP only supports Transfer-Encoding: chunked * on Windows Vista (NT 6.0) and higher. */ s->chunked = git_has_win32_version(6, 0, 0); @@ -1256,7 +1261,7 @@ static int winhttp_action( if (!t->connection) if ((ret = gitno_connection_data_from_url(&t->connection_data, url, NULL)) < 0 || - (ret = winhttp_connect(t, url)) < 0) + (ret = winhttp_connect(t)) < 0) return ret; if (winhttp_stream_alloc(t, &s) < 0) |