diff --git a/src/core/windows/http.c b/src/core/windows/http.c index c80821e..a206359 100644 --- a/src/core/windows/http.c +++ b/src/core/windows/http.c @@ -57,7 +57,7 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co wchar_t wHostname[4096]; wchar_t wPath[4096]; - lib3270_trace_event(hSession,"Getting data from %s",url); + lib3270_write_nettrace(hSession,"Getting data from %s\n",url); { // Strip URL @@ -87,11 +87,16 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co static const char * userAgent = PACKAGE_NAME "/" PACKAGE_VERSION; wchar_t wUserAgent[256]; mbstowcs(wUserAgent, userAgent, strlen(userAgent)+1); - lib3270_autoptr(HINTERNET) httpSession = WinHttpOpen(wUserAgent, WINHTTP_ACCESS_TYPE_NO_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0 ); + + // https://docs.microsoft.com/en-us/windows/win32/api/winhttp/nf-winhttp-winhttpopen + + /// @TODO Use WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY when available! + lib3270_autoptr(HINTERNET) httpSession = WinHttpOpen(wUserAgent, WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0 ); + if(!httpSession) { lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(GetLastError()); - lib3270_write_log(hSession,"http","%s: %s",url, windows_error); + lib3270_write_nettrace(hSession,"Can't open session for %s: %s\n",url, windows_error); *error_message = _( "Can't open HTTP session" ); errno = EINVAL; @@ -103,7 +108,7 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co if(!hConnect) { lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(GetLastError()); - lib3270_write_log(hSession,"http","%s: %s", url, windows_error); + lib3270_write_nettrace(hSession,"Can't connect to %s: %s\n", url, windows_error); *error_message = _( "Can't connect to HTTP server." ); @@ -115,7 +120,7 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co if(!hConnect) { lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(GetLastError()); - lib3270_write_log(hSession,"http","%s: %s", url, windows_error); + lib3270_write_nettrace(hSession,"Can't open request for %s: %s\n", url, windows_error); *error_message = _( "Can't create HTTP request." ); @@ -129,7 +134,7 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co if(!WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0)) { lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(GetLastError()); - lib3270_write_log(hSession,"http","%s: %s", url, windows_error); + lib3270_write_nettrace(hSession,"Can't send request for %s: %s\n", url, windows_error); *error_message = _( "Can't send HTTP request." ); @@ -141,7 +146,7 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co if(!WinHttpReceiveResponse(hRequest, NULL)) { lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(GetLastError()); - lib3270_write_log(hSession,"http","%s: %s", url, windows_error); + lib3270_write_nettrace(hSession,"Can't receive response for %s: %s\n", url, windows_error); *error_message = _( "Error receiving HTTP response." ); @@ -154,7 +159,7 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co if(!WinHttpQueryDataAvailable(hRequest, &szResponse)) { lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(GetLastError()); - lib3270_write_log(hSession,"http","%s: %s", url, windows_error); + lib3270_write_nettrace(hSession,"Error checking for available data after response to %s: %s\n", url, windows_error); *error_message = _( "Empty response from HTTP server." ); @@ -170,7 +175,7 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co if(!WinHttpReadData(hRequest,httpText,szResponse,&szResponse)){ lib3270_autoptr(char) windows_error = lib3270_win32_translate_error_code(GetLastError()); - lib3270_write_log(hSession,"http","%s: %s", url, windows_error); + lib3270_write_nettrace(hSession,"Can't read response size for %s: %s\n", url, windows_error); *error_message = _( "Can't read HTTP response size." ); @@ -183,6 +188,8 @@ char * lib3270_get_from_url(H3270 *hSession, const char *url, size_t *length, co if(length) *length = (size_t) szResponse; + lib3270_write_nettrace(hSession,"Got %u bytes from %s\n",(unsigned int) szResponse, url); + return httpText; } diff --git a/src/ssl/crl.c b/src/ssl/crl.c index 63bcdef..45054f2 100644 --- a/src/ssl/crl.c +++ b/src/ssl/crl.c @@ -144,6 +144,8 @@ int lib3270_crl_new_from_url(H3270 *hSession, void *ssl_error, const char *url) return 0; } + trace_ssl(hSession,"Can't get CRL using %s\n",url); + return -1; } diff --git a/src/ssl/linux/getcrl.c b/src/ssl/linux/getcrl.c index b9dd85a..99ec938 100644 --- a/src/ssl/linux/getcrl.c +++ b/src/ssl/linux/getcrl.c @@ -107,10 +107,18 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co // Can't get CRL. message->error = hSession->ssl.error = 0; - message->title = _( "Security error" ); - message->text = _( "Unexpected or invalid CRL URL" ); - message->description = _("The URL scheme is unknown"); - lib3270_write_log(hSession,"ssl","%s: %s",consturl, message->description); + + if(!(message->text && message->description)) + message->title = _( "Security error" ); + + if(!message->text) + message->text = _( "Unexpected or invalid CRL URL" ); + + if(!message->description) + message->description = _("The URL scheme is unknown"); + + trace_ssl(hSession,"%s: The URL scheme is unknown",consturl); + errno = EINVAL; return NULL; #endif // HAVE_LIBCURL diff --git a/src/ssl/windows/getcrl.c b/src/ssl/windows/getcrl.c index 2c9cb4c..f0558f0 100644 --- a/src/ssl/windows/getcrl.c +++ b/src/ssl/windows/getcrl.c @@ -113,10 +113,18 @@ X509_CRL * lib3270_download_crl(H3270 *hSession, SSL_ERROR_MESSAGE * message, co // Can't get CRL. message->error = hSession->ssl.error = 0; - message->title = _( "Security error" ); - message->text = _( "Unexpected or invalid CRL URL" ); - message->description = _("The URL scheme is unknown"); - lib3270_write_log(hSession,"ssl","%s: %s",consturl, message->description); + + if(!(message->text && message->description)) + message->title = _( "Security error" ); + + if(!message->text) + message->text = _( "Unexpected or invalid CRL URL" ); + + if(!message->description) + message->description = _("The URL scheme is unknown"); + + trace_ssl(hSession,"%s: The URL scheme is unknown",consturl); + errno = EINVAL; return NULL; diff --git a/src/ssl/windows/http.c b/src/ssl/windows/http.c index 76a8cbb..cb339ed 100644 --- a/src/ssl/windows/http.c +++ b/src/ssl/windows/http.c @@ -55,6 +55,11 @@ X509_CRL * get_crl_using_http(H3270 *hSession, SSL_ERROR_MESSAGE * message, cons { message->error = hSession->ssl.error = 0; message->title = _( "Security error" ); + trace_ssl( + hSession,"Can't get %s: %s\n", + consturl, + message->description ? message->description : "Undefined message" + ); return NULL; } @@ -68,9 +73,18 @@ X509_CRL * get_crl_using_http(H3270 *hSession, SSL_ERROR_MESSAGE * message, cons message->title = _( "Security error" ); message->text = _( "Can't decode certificate revocation list" ); lib3270_write_log(hSession,"ssl","%s: %s",consturl, message->text); + + trace_ssl( + hSession,"%s: %s\n", + consturl, + message->text + ); + return NULL; } + trace_ssl(hSession,"Got CRL from %s\n",consturl); + return x509_crl; } diff --git a/src/ssl/windows/init.c b/src/ssl/windows/init.c index 9609042..d9c8e0f 100644 --- a/src/ssl/windows/init.c +++ b/src/ssl/windows/init.c @@ -112,7 +112,7 @@ int ssl_ctx_init(H3270 *hSession, SSL_ERROR_MESSAGE * message) message->title = N_( "Security error" ); message->text = N_( "Cant open custom certificate directory." ); - trace_ssl(hSession, _( "Can't open \"%s\" (The Windows error code was %ld)" ), certpath, (long) GetLastError()); + trace_ssl(hSession, _( "Can't open \"%s\" (The Windows error code was %ld)\n" ), certpath, (long) GetLastError()); } else { -- libgit2 0.21.2