Commit 751a90df98d845b2623f1217123c049105c0d817
1 parent
e6c186aa
Exists in
master
and in
3 other branches
Improving trace of the http download engine; adding some proxy support.
Showing
6 changed files
with
57 additions
and
18 deletions
Show diff stats
src/core/windows/http.c
@@ -57,7 +57,7 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co | @@ -57,7 +57,7 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co | ||
57 | wchar_t wHostname[4096]; | 57 | wchar_t wHostname[4096]; |
58 | wchar_t wPath[4096]; | 58 | wchar_t wPath[4096]; |
59 | 59 | ||
60 | - lib3270_trace_event(hSession,"Getting data from %s",url); | 60 | + lib3270_write_nettrace(hSession,"Getting data from %s\n",url); |
61 | 61 | ||
62 | { | 62 | { |
63 | // Strip URL | 63 | // Strip URL |
@@ -87,11 +87,16 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co | @@ -87,11 +87,16 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co | ||
87 | static const char * userAgent = PACKAGE_NAME "/" PACKAGE_VERSION; | 87 | static const char * userAgent = PACKAGE_NAME "/" PACKAGE_VERSION; |
88 | wchar_t wUserAgent[256]; | 88 | wchar_t wUserAgent[256]; |
89 | mbstowcs(wUserAgent, userAgent, strlen(userAgent)+1); | 89 | mbstowcs(wUserAgent, userAgent, strlen(userAgent)+1); |
90 | - lib3270_autoptr(HINTERNET) httpSession = WinHttpOpen(wUserAgent, WINHTTP_ACCESS_TYPE_NO_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0 ); | 90 | + |
91 | + // https://docs.microsoft.com/en-us/windows/win32/api/winhttp/nf-winhttp-winhttpopen | ||
92 | + | ||
93 | + /// @TODO Use WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY when available! | ||
94 | + lib3270_autoptr(HINTERNET) httpSession = WinHttpOpen(wUserAgent, WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0 ); | ||
95 | + | ||
91 | if(!httpSession) | 96 | if(!httpSession) |
92 | { | 97 | { |
93 | lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(GetLastError()); | 98 | lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(GetLastError()); |
94 | - lib3270_write_log(hSession,"http","%s: %s",url, windows_error); | 99 | + lib3270_write_nettrace(hSession,"Can't open session for %s: %s\n",url, windows_error); |
95 | 100 | ||
96 | *error_message = _( "Can't open HTTP session" ); | 101 | *error_message = _( "Can't open HTTP session" ); |
97 | errno = EINVAL; | 102 | errno = EINVAL; |
@@ -103,7 +108,7 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co | @@ -103,7 +108,7 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co | ||
103 | if(!hConnect) | 108 | if(!hConnect) |
104 | { | 109 | { |
105 | lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(GetLastError()); | 110 | lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(GetLastError()); |
106 | - lib3270_write_log(hSession,"http","%s: %s", url, windows_error); | 111 | + lib3270_write_nettrace(hSession,"Can't connect to %s: %s\n", url, windows_error); |
107 | 112 | ||
108 | *error_message = _( "Can't connect to HTTP server." ); | 113 | *error_message = _( "Can't connect to HTTP server." ); |
109 | 114 | ||
@@ -115,7 +120,7 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co | @@ -115,7 +120,7 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co | ||
115 | if(!hConnect) | 120 | if(!hConnect) |
116 | { | 121 | { |
117 | lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(GetLastError()); | 122 | lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(GetLastError()); |
118 | - lib3270_write_log(hSession,"http","%s: %s", url, windows_error); | 123 | + lib3270_write_nettrace(hSession,"Can't open request for %s: %s\n", url, windows_error); |
119 | 124 | ||
120 | *error_message = _( "Can't create HTTP request." ); | 125 | *error_message = _( "Can't create HTTP request." ); |
121 | 126 | ||
@@ -129,7 +134,7 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co | @@ -129,7 +134,7 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co | ||
129 | if(!WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0)) | 134 | if(!WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0)) |
130 | { | 135 | { |
131 | lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(GetLastError()); | 136 | lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(GetLastError()); |
132 | - lib3270_write_log(hSession,"http","%s: %s", url, windows_error); | 137 | + lib3270_write_nettrace(hSession,"Can't send request for %s: %s\n", url, windows_error); |
133 | 138 | ||
134 | *error_message = _( "Can't send HTTP request." ); | 139 | *error_message = _( "Can't send HTTP request." ); |
135 | 140 | ||
@@ -141,7 +146,7 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co | @@ -141,7 +146,7 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co | ||
141 | if(!WinHttpReceiveResponse(hRequest, NULL)) | 146 | if(!WinHttpReceiveResponse(hRequest, NULL)) |
142 | { | 147 | { |
143 | lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(GetLastError()); | 148 | lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(GetLastError()); |
144 | - lib3270_write_log(hSession,"http","%s: %s", url, windows_error); | 149 | + lib3270_write_nettrace(hSession,"Can't receive response for %s: %s\n", url, windows_error); |
145 | 150 | ||
146 | *error_message = _( "Error receiving HTTP response." ); | 151 | *error_message = _( "Error receiving HTTP response." ); |
147 | 152 | ||
@@ -154,7 +159,7 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co | @@ -154,7 +159,7 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co | ||
154 | if(!WinHttpQueryDataAvailable(hRequest, &szResponse)) | 159 | if(!WinHttpQueryDataAvailable(hRequest, &szResponse)) |
155 | { | 160 | { |
156 | lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(GetLastError()); | 161 | lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(GetLastError()); |
157 | - lib3270_write_log(hSession,"http","%s: %s", url, windows_error); | 162 | + lib3270_write_nettrace(hSession,"Error checking for available data after response to %s: %s\n", url, windows_error); |
158 | 163 | ||
159 | *error_message = _( "Empty response from HTTP server." ); | 164 | *error_message = _( "Empty response from HTTP server." ); |
160 | 165 | ||
@@ -170,7 +175,7 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co | @@ -170,7 +175,7 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co | ||
170 | 175 | ||
171 | if(!WinHttpReadData(hRequest,httpText,szResponse,&szResponse)){ | 176 | if(!WinHttpReadData(hRequest,httpText,szResponse,&szResponse)){ |
172 | lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(GetLastError()); | 177 | lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(GetLastError()); |
173 | - lib3270_write_log(hSession,"http","%s: %s", url, windows_error); | 178 | + lib3270_write_nettrace(hSession,"Can't read response size for %s: %s\n", url, windows_error); |
174 | 179 | ||
175 | *error_message = _( "Can't read HTTP response size." ); | 180 | *error_message = _( "Can't read HTTP response size." ); |
176 | 181 | ||
@@ -183,6 +188,8 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co | @@ -183,6 +188,8 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co | ||
183 | if(length) | 188 | if(length) |
184 | *length = (size_t) szResponse; | 189 | *length = (size_t) szResponse; |
185 | 190 | ||
191 | + lib3270_write_nettrace(hSession,"Got %u bytes from %s\n",(unsigned int) szResponse, url); | ||
192 | + | ||
186 | return httpText; | 193 | return httpText; |
187 | 194 | ||
188 | } | 195 | } |
src/ssl/crl.c
@@ -144,6 +144,8 @@ int lib3270_crl_new_from_url(H3270 *hSession, void *ssl_error, const char *url) | @@ -144,6 +144,8 @@ int lib3270_crl_new_from_url(H3270 *hSession, void *ssl_error, const char *url) | ||
144 | return 0; | 144 | return 0; |
145 | } | 145 | } |
146 | 146 | ||
147 | + trace_ssl(hSession,"Can't get CRL using %s\n",url); | ||
148 | + | ||
147 | return -1; | 149 | return -1; |
148 | 150 | ||
149 | } | 151 | } |
src/ssl/linux/getcrl.c
@@ -107,10 +107,18 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co | @@ -107,10 +107,18 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co | ||
107 | // Can't get CRL. | 107 | // Can't get CRL. |
108 | 108 | ||
109 | message->error = hSession->ssl.error = 0; | 109 | message->error = hSession->ssl.error = 0; |
110 | - message->title = _( "Security error" ); | ||
111 | - message->text = _( "Unexpected or invalid CRL URL" ); | ||
112 | - message->description = _("The URL scheme is unknown"); | ||
113 | - lib3270_write_log(hSession,"ssl","%s: %s",consturl, message->description); | 110 | + |
111 | + if(!(message->text && message->description)) | ||
112 | + message->title = _( "Security error" ); | ||
113 | + | ||
114 | + if(!message->text) | ||
115 | + message->text = _( "Unexpected or invalid CRL URL" ); | ||
116 | + | ||
117 | + if(!message->description) | ||
118 | + message->description = _("The URL scheme is unknown"); | ||
119 | + | ||
120 | + trace_ssl(hSession,"%s: The URL scheme is unknown",consturl); | ||
121 | + | ||
114 | errno = EINVAL; | 122 | errno = EINVAL; |
115 | return NULL; | 123 | return NULL; |
116 | #endif // HAVE_LIBCURL | 124 | #endif // HAVE_LIBCURL |
src/ssl/windows/getcrl.c
@@ -113,10 +113,18 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co | @@ -113,10 +113,18 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co | ||
113 | // Can't get CRL. | 113 | // Can't get CRL. |
114 | 114 | ||
115 | message->error = hSession->ssl.error = 0; | 115 | message->error = hSession->ssl.error = 0; |
116 | - message->title = _( "Security error" ); | ||
117 | - message->text = _( "Unexpected or invalid CRL URL" ); | ||
118 | - message->description = _("The URL scheme is unknown"); | ||
119 | - lib3270_write_log(hSession,"ssl","%s: %s",consturl, message->description); | 116 | + |
117 | + if(!(message->text && message->description)) | ||
118 | + message->title = _( "Security error" ); | ||
119 | + | ||
120 | + if(!message->text) | ||
121 | + message->text = _( "Unexpected or invalid CRL URL" ); | ||
122 | + | ||
123 | + if(!message->description) | ||
124 | + message->description = _("The URL scheme is unknown"); | ||
125 | + | ||
126 | + trace_ssl(hSession,"%s: The URL scheme is unknown",consturl); | ||
127 | + | ||
120 | errno = EINVAL; | 128 | errno = EINVAL; |
121 | return NULL; | 129 | return NULL; |
122 | 130 |
src/ssl/windows/http.c
@@ -55,6 +55,11 @@ X509_CRL * get_crl_using_http(H3270 *hSession, SSL_ERROR_MESSAGE * message, cons | @@ -55,6 +55,11 @@ X509_CRL * get_crl_using_http(H3270 *hSession, SSL_ERROR_MESSAGE * message, cons | ||
55 | { | 55 | { |
56 | message->error = hSession->ssl.error = 0; | 56 | message->error = hSession->ssl.error = 0; |
57 | message->title = _( "Security error" ); | 57 | message->title = _( "Security error" ); |
58 | + trace_ssl( | ||
59 | + hSession,"Can't get %s: %s\n", | ||
60 | + consturl, | ||
61 | + message->description ? message->description : "Undefined message" | ||
62 | + ); | ||
58 | return NULL; | 63 | return NULL; |
59 | } | 64 | } |
60 | 65 | ||
@@ -68,9 +73,18 @@ X509_CRL * get_crl_using_http(H3270 *hSession, SSL_ERROR_MESSAGE * message, cons | @@ -68,9 +73,18 @@ X509_CRL * get_crl_using_http(H3270 *hSession, SSL_ERROR_MESSAGE * message, cons | ||
68 | message->title = _( "Security error" ); | 73 | message->title = _( "Security error" ); |
69 | message->text = _( "Can't decode certificate revocation list" ); | 74 | message->text = _( "Can't decode certificate revocation list" ); |
70 | lib3270_write_log(hSession,"ssl","%s: %s",consturl, message->text); | 75 | lib3270_write_log(hSession,"ssl","%s: %s",consturl, message->text); |
76 | + | ||
77 | + trace_ssl( | ||
78 | + hSession,"%s: %s\n", | ||
79 | + consturl, | ||
80 | + message->text | ||
81 | + ); | ||
82 | + | ||
71 | return NULL; | 83 | return NULL; |
72 | } | 84 | } |
73 | 85 | ||
86 | + trace_ssl(hSession,"Got CRL from %s\n",consturl); | ||
87 | + | ||
74 | return x509_crl; | 88 | return x509_crl; |
75 | 89 | ||
76 | } | 90 | } |
src/ssl/windows/init.c
@@ -112,7 +112,7 @@ int ssl_ctx_init(H3270 *hSession, SSL_ERROR_MESSAGE * message) | @@ -112,7 +112,7 @@ int ssl_ctx_init(H3270 *hSession, SSL_ERROR_MESSAGE * message) | ||
112 | message->title = N_( "Security error" ); | 112 | message->title = N_( "Security error" ); |
113 | message->text = N_( "Cant open custom certificate directory." ); | 113 | message->text = N_( "Cant open custom certificate directory." ); |
114 | 114 | ||
115 | - trace_ssl(hSession, _( "Can't open \"%s\" (The Windows error code was %ld)" ), certpath, (long) GetLastError()); | 115 | + trace_ssl(hSession, _( "Can't open \"%s\" (The Windows error code was %ld)\n" ), certpath, (long) GetLastError()); |
116 | } | 116 | } |
117 | else | 117 | else |
118 | { | 118 | { |