Commit a592af7a authored by Yury Popov's avatar Yury Popov Committed by Arnim Läuger
Browse files

Depend http client secure part on CLIENT_SSL_ENABLE (#1702)

parent cad1632e
...@@ -27,7 +27,9 @@ ...@@ -27,7 +27,9 @@
typedef struct request_args_t { typedef struct request_args_t {
char * hostname; char * hostname;
int port; int port;
#ifdef CLIENT_SSL_ENABLE
bool secure; bool secure;
#endif
char * method; char * method;
char * path; char * path;
char * headers; char * headers;
...@@ -140,9 +142,11 @@ static void ICACHE_FLASH_ATTR http_receive_callback( void * arg, char * buf, uns ...@@ -140,9 +142,11 @@ static void ICACHE_FLASH_ATTR http_receive_callback( void * arg, char * buf, uns
{ {
HTTPCLIENT_ERR( "Response too long (%d)", new_size ); HTTPCLIENT_ERR( "Response too long (%d)", new_size );
req->buffer[0] = '\0'; /* Discard the buffer to avoid using an incomplete response. */ req->buffer[0] = '\0'; /* Discard the buffer to avoid using an incomplete response. */
#ifdef CLIENT_SSL_ENABLE
if ( req->secure ) if ( req->secure )
espconn_secure_disconnect( conn ); espconn_secure_disconnect( conn );
else else
#endif
espconn_disconnect( conn ); espconn_disconnect( conn );
return; /* The disconnect callback will be called. */ return; /* The disconnect callback will be called. */
} }
...@@ -170,9 +174,11 @@ static void ICACHE_FLASH_ATTR http_send_callback( void * arg ) ...@@ -170,9 +174,11 @@ static void ICACHE_FLASH_ATTR http_send_callback( void * arg )
{ {
/* The headers were sent, now send the contents. */ /* The headers were sent, now send the contents. */
HTTPCLIENT_DEBUG( "Sending request body" ); HTTPCLIENT_DEBUG( "Sending request body" );
#ifdef CLIENT_SSL_ENABLE
if ( req->secure ) if ( req->secure )
espconn_secure_send( conn, (uint8_t *) req->post_data, strlen( req->post_data ) ); espconn_secure_send( conn, (uint8_t *) req->post_data, strlen( req->post_data ) );
else else
#endif
espconn_send( conn, (uint8_t *) req->post_data, strlen( req->post_data ) ); espconn_send( conn, (uint8_t *) req->post_data, strlen( req->post_data ) );
os_free( req->post_data ); os_free( req->post_data );
req->post_data = NULL; req->post_data = NULL;
...@@ -213,7 +219,11 @@ static void ICACHE_FLASH_ATTR http_connect_callback( void * arg ) ...@@ -213,7 +219,11 @@ static void ICACHE_FLASH_ATTR http_connect_callback( void * arg )
int host_len = 0; int host_len = 0;
if ( os_strstr( req->headers, "Host:" ) == NULL && os_strstr( req->headers, "host:" ) == NULL) if ( os_strstr( req->headers, "Host:" ) == NULL && os_strstr( req->headers, "host:" ) == NULL)
{ {
if ((req->port == 80) || ((req->port == 443) && ( req->secure ))) if ((req->port == 80)
#ifdef CLIENT_SSL_ENABLE
|| ((req->port == 443) && ( req->secure ))
#endif
)
{ {
os_sprintf( host_header, "Host: %s\r\n", req->hostname ); os_sprintf( host_header, "Host: %s\r\n", req->hostname );
} }
...@@ -236,11 +246,13 @@ static void ICACHE_FLASH_ATTR http_connect_callback( void * arg ) ...@@ -236,11 +246,13 @@ static void ICACHE_FLASH_ATTR http_connect_callback( void * arg )
"\r\n", "\r\n",
req->method, req->path, host_header, req->headers, ua_header, post_headers ); req->method, req->path, host_header, req->headers, ua_header, post_headers );
#ifdef CLIENT_SSL_ENABLE
if (req->secure) if (req->secure)
{ {
espconn_secure_send( conn, (uint8_t *) buf, len ); espconn_secure_send( conn, (uint8_t *) buf, len );
} }
else else
#endif
{ {
espconn_send( conn, (uint8_t *) buf, len ); espconn_send( conn, (uint8_t *) buf, len );
} }
...@@ -343,8 +355,13 @@ static void ICACHE_FLASH_ATTR http_disconnect_callback( void * arg ) ...@@ -343,8 +355,13 @@ static void ICACHE_FLASH_ATTR http_disconnect_callback( void * arg )
req->post_data, req->callback_handle, req->redirect_follow_count ); req->post_data, req->callback_handle, req->redirect_follow_count );
} else { } else {
if ( os_strncmp( locationOffset, "/", 1 ) == 0) { // relative and full path if ( os_strncmp( locationOffset, "/", 1 ) == 0) { // relative and full path
http_raw_request( req->hostname, req->port, req->secure, req->method, http_raw_request( req->hostname, req->port,
locationOffset, req->headers, req->post_data, req->callback_handle, req->redirect_follow_count ); #ifdef CLIENT_SSL_ENABLE
req->secure,
#else
0,
#endif
req->method, locationOffset, req->headers, req->post_data, req->callback_handle, req->redirect_follow_count );
} else { // relative and relative path } else { // relative and relative path
// find last / // find last /
...@@ -360,8 +377,13 @@ static void ICACHE_FLASH_ATTR http_disconnect_callback( void * arg ) ...@@ -360,8 +377,13 @@ static void ICACHE_FLASH_ATTR http_disconnect_callback( void * arg )
os_memcpy( completeRelativePath, req->path, pathFolderLength ); os_memcpy( completeRelativePath, req->path, pathFolderLength );
os_memcpy( completeRelativePath + pathFolderLength, locationOffset, locationLength); os_memcpy( completeRelativePath + pathFolderLength, locationOffset, locationLength);
http_raw_request( req->hostname, req->port, req->secure, req->method, http_raw_request( req->hostname, req->port,
completeRelativePath, req->headers, req->post_data, req->callback_handle, req->redirect_follow_count ); #ifdef CLIENT_SSL_ENABLE
req->secure,
#else
0,
#endif
req->method, completeRelativePath, req->headers, req->post_data, req->callback_handle, req->redirect_follow_count );
os_free( completeRelativePath ); os_free( completeRelativePath );
} }
...@@ -437,9 +459,11 @@ static void ICACHE_FLASH_ATTR http_timeout_callback( void *arg ) ...@@ -437,9 +459,11 @@ static void ICACHE_FLASH_ATTR http_timeout_callback( void *arg )
} }
request_args_t * req = (request_args_t *) conn->reverse; request_args_t * req = (request_args_t *) conn->reverse;
/* Call disconnect */ /* Call disconnect */
#ifdef CLIENT_SSL_ENABLE
if ( req->secure ) if ( req->secure )
espconn_secure_disconnect( conn ); espconn_secure_disconnect( conn );
else else
#endif
espconn_disconnect( conn ); espconn_disconnect( conn );
} }
...@@ -487,11 +511,13 @@ static void ICACHE_FLASH_ATTR http_dns_callback( const char * hostname, ip_addr_ ...@@ -487,11 +511,13 @@ static void ICACHE_FLASH_ATTR http_dns_callback( const char * hostname, ip_addr_
os_timer_setfn( &(req->timeout_timer), (os_timer_func_t *) http_timeout_callback, conn ); os_timer_setfn( &(req->timeout_timer), (os_timer_func_t *) http_timeout_callback, conn );
os_timer_arm( &(req->timeout_timer), req->timeout, false ); os_timer_arm( &(req->timeout_timer), req->timeout, false );
#ifdef CLIENT_SSL_ENABLE
if ( req->secure ) if ( req->secure )
{ {
espconn_secure_connect( conn ); espconn_secure_connect( conn );
} }
else else
#endif
{ {
espconn_connect( conn ); espconn_connect( conn );
} }
...@@ -506,7 +532,9 @@ void ICACHE_FLASH_ATTR http_raw_request( const char * hostname, int port, bool s ...@@ -506,7 +532,9 @@ void ICACHE_FLASH_ATTR http_raw_request( const char * hostname, int port, bool s
request_args_t * req = (request_args_t *) os_zalloc( sizeof(request_args_t) ); request_args_t * req = (request_args_t *) os_zalloc( sizeof(request_args_t) );
req->hostname = esp_strdup( hostname ); req->hostname = esp_strdup( hostname );
req->port = port; req->port = port;
#ifdef CLIENT_SSL_ENABLE
req->secure = secure; req->secure = secure;
#endif
req->method = esp_strdup( method ); req->method = esp_strdup( method );
req->path = esp_strdup( path ); req->path = esp_strdup( path );
req->headers = esp_strdup( headers ); req->headers = esp_strdup( headers );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment