Use logging API for HTTP proxy

This commit is contained in:
Christian Plattner 2016-12-10 18:59:58 +01:00
parent 5d10b3bf5b
commit d9e28c24ad
1 changed files with 8 additions and 5 deletions

View File

@ -25,6 +25,7 @@
#include "winpr/environment.h" /* For GetEnvironmentVariableA */ #include "winpr/environment.h" /* For GetEnvironmentVariableA */
#define CRLF "\r\n" #define CRLF "\r\n"
#define TAG FREERDP_TAG("core.proxy")
void http_proxy_read_environment(rdpSettings *settings, char *envname) void http_proxy_read_environment(rdpSettings *settings, char *envname)
{ {
@ -37,7 +38,7 @@ void http_proxy_read_environment(rdpSettings *settings, char *envname)
return; return;
if (strncmp(env, "http://", 7)) { if (strncmp(env, "http://", 7)) {
fprintf(stderr, "Proxy url must have scheme http. Ignoring.\n"); WLog_ERR(TAG, "Proxy url must have scheme http. Ignoring.");
return; return;
} }
@ -59,6 +60,7 @@ void http_proxy_read_environment(rdpSettings *settings, char *envname)
} }
freerdp_set_param_string(settings, FreeRDP_HTTPProxyHostname, hostname); freerdp_set_param_string(settings, FreeRDP_HTTPProxyHostname, hostname);
WLog_INFO(TAG, "Parsed proxy configuration: %s:%d", settings->HTTPProxyHostname, settings->HTTPProxyPort);
} }
BOOL http_proxy_connect(BIO* bufferedBio, const char* hostname, UINT16 port) BOOL http_proxy_connect(BIO* bufferedBio, const char* hostname, UINT16 port)
@ -84,7 +86,7 @@ BOOL http_proxy_connect(BIO* bufferedBio, const char* hostname, UINT16 port)
status = BIO_write(bufferedBio, Stream_Buffer(s), Stream_GetPosition(s)); status = BIO_write(bufferedBio, Stream_Buffer(s), Stream_GetPosition(s));
if (status != Stream_GetPosition(s)) { if (status != Stream_GetPosition(s)) {
fprintf(stderr, "HTTP proxy: failed to write CONNECT request\n"); WLog_ERR(TAG, "HTTP proxy: failed to write CONNECT request");
return FALSE; return FALSE;
} }
@ -98,7 +100,7 @@ BOOL http_proxy_connect(BIO* bufferedBio, const char* hostname, UINT16 port)
resultsize = 0; resultsize = 0;
while ( strstr(recv_buf, CRLF CRLF) == NULL ) { while ( strstr(recv_buf, CRLF CRLF) == NULL ) {
if (resultsize >= sizeof(recv_buf)-1) { if (resultsize >= sizeof(recv_buf)-1) {
fprintf(stderr, "HTTP Reply headers too long.\n"); WLog_ERR(TAG, "HTTP Reply headers too long.");
return FALSE; return FALSE;
} }
@ -109,11 +111,12 @@ BOOL http_proxy_connect(BIO* bufferedBio, const char* hostname, UINT16 port)
USleep(100); USleep(100);
continue; continue;
} }
WLog_ERR(TAG, "Failed reading reply from HTTP proxy (Status %d)", status);
return FALSE; return FALSE;
} }
else if (status == 0) { else if (status == 0) {
/* Error? */ /* Error? */
fprintf(stderr, "BIO_read() returned zero\n"); WLog_ERR(TAG, "Failed reading reply from HTTP proxy (BIO_read returned zero)");
return FALSE; return FALSE;
} }
resultsize += status; resultsize += status;
@ -128,7 +131,7 @@ BOOL http_proxy_connect(BIO* bufferedBio, const char* hostname, UINT16 port)
*eol = '\0'; *eol = '\0';
fprintf(stderr, "HTTP proxy: %s\n", recv_buf); WLog_INFO(TAG, "HTTP Proxy: %s", recv_buf);
if (strlen(recv_buf) < 12) { if (strlen(recv_buf) < 12) {
return FALSE; return FALSE;