Add config options in menuconfig to enable/disable https and examples

parent baf849bf
menu "HTTPD Server"
choice HTTPS_SERVER_MODE
prompt "http or https"
default HTTPS_SERVER_DISABLED
help
Wheter the http server is secure or not
config HTTPS_SERVER_ENABLED
bool "Https enabled"
config HTTPS_SERVER_DISABLED
bool "Https disabled"
endchoice
config HTTPS_SERVER
bool
default y if HTTPS_SERVER_ENABLED
default n if HTTPS_SERVER_DISABLED
config HTTPD_EXAMPLE
bool "Enable HTTP POST/GET Example functions"
default n
......@@ -51,6 +51,8 @@
#define MBEDTLS_EXAMPLE_RECV_BUF_LEN 1024
#define HTTPD_EXAMPLE CONFIG_HTTPD_EXAMPLE
typedef enum {
HTTP_PARSING_URI, //!< HTTP_PARSING_URI
HTTP_PARSING_HEADER_NAME, //!< HTTP_PARSING_HEADER_NAME
......@@ -102,7 +104,7 @@ struct http_context_ {
const char* data_ptr;
size_t data_size;
http_header_list_t request_args;
#ifdef HTTPS_SERVER
#if HTTPS_SERVER
mbedtls_ssl_context *ssl_conn;
mbedtls_net_context *client_fd;
#else
......@@ -118,7 +120,7 @@ struct http_server_context_ {
SLIST_HEAD(, http_handler_t) handlers;
_lock_t handlers_lock;
struct http_context_ connection_context;
#ifdef HTTPS_SERVER
#if HTTPS_SERVER
mbedtls_net_context *listen_fd;
mbedtls_entropy_context *entropy;
mbedtls_ctr_drbg_context *ctr_drbg;
......@@ -552,7 +554,7 @@ static esp_err_t http_send_response_headers(http_context_t http_ctx)
headers_list_clear(&http_ctx->response_headers);
#ifdef HTTPS_SERVER
#if HTTPS_SERVER
int ret;
int actual_len;
ESP_LOGI(TAG, "Writing response headers..." );
......@@ -636,7 +638,7 @@ esp_err_t http_response_write(http_context_t http_ctx, const http_buffer_t* buff
}
}
len = buffer->size ? buffer->size : strlen((const char*) buffer->data);
#ifdef HTTPS_SERVER
#if HTTPS_SERVER
ESP_LOGI(TAG, "Writing to client:" );
ret = 0;
do
......@@ -776,7 +778,7 @@ static void http_handle_connection(http_server_t server, void *arg_conn)
/* Initialize context */
ctx->state = HTTP_PARSING_URI;
#ifdef HTTPS_SERVER
#if HTTPS_SERVER
#else
struct netbuf *inbuf = NULL;
u16_t buflen;
......@@ -796,7 +798,7 @@ static void http_handle_connection(http_server_t server, void *arg_conn)
.on_message_complete = &http_message_done_cb
};
#ifdef HTTPS_SERVER
#if HTTPS_SERVER
int ret;
size_t parsed_bytes = 0;
/*
......@@ -860,7 +862,7 @@ static void http_handle_connection(http_server_t server, void *arg_conn)
}
#endif
#ifdef HTTPS_SERVER
#if HTTPS_SERVER
if (ret > 0) {
ctx->state = HTTP_COLLECTING_RESPONSE_HEADERS;
if (ctx->handler == NULL) {
......@@ -891,7 +893,7 @@ static void http_handle_connection(http_server_t server, void *arg_conn)
ctx->uri = NULL;
ctx->handler = NULL;
#ifdef HTTPS_SERVER
#if HTTPS_SERVER
ESP_LOGI(TAG, "Closing the connection..." );
while( ( ret = mbedtls_ssl_close_notify( server->connection_context.ssl_conn) ) < 0 )
{
......@@ -934,7 +936,7 @@ static void http_server(void *arg)
//If server has not successfully been started yet,
if (!(bits & SERVER_STARTED_BIT)) {
#ifdef HTTPS_SERVER
#if HTTPS_SERVER
char *error_buf;
ESP_LOGV(TAG, "Declaring local mbedTLS context on task...");
int ret;
......@@ -1291,7 +1293,7 @@ esp_err_t http_server_start(const http_server_options_t* options, http_server_t*
esp_err_t http_server_stop(http_server_t server)
{
/* FIXME: figure out a thread safe way to do this */
#ifdef HTTPS_SERVER
#if HTTPS_SERVER
/* FIXME: Add function to stop HTTPS */
#else
netconn_close(server->server_conn);
......@@ -1301,6 +1303,8 @@ esp_err_t http_server_stop(http_server_t server)
return ESP_OK;
}
#if HTTPD_EXAMPLE
static void cb_GET_method(http_context_t http_ctx, void* ctx)
{
size_t response_size = strlen(index_html);
......@@ -1313,7 +1317,7 @@ static void cb_GET_method(http_context_t http_ctx, void* ctx)
esp_err_t simple_GET_method_example(void)
{
http_server_t server;
#ifdef HTTPS_SERVER
#if HTTPS_SERVER
http_server_options_t http_options = HTTPS_SERVER_OPTIONS_DEFAULT();
#else
http_server_options_t http_options = HTTP_SERVER_OPTIONS_DEFAULT();
......@@ -1361,7 +1365,7 @@ static void cb_POST_method(http_context_t http_ctx, void* ctx)
esp_err_t simple_POST_method_example(void)
{
http_server_t server;
#ifdef HTTPS_SERVER
#if HTTPS_SERVER
http_server_options_t http_options = HTTPS_SERVER_OPTIONS_DEFAULT();
#else
http_server_options_t http_options = HTTP_SERVER_OPTIONS_DEFAULT();
......@@ -1380,3 +1384,4 @@ esp_err_t simple_POST_method_example(void)
return res;
}
#endif // HTTPD_EXAMPLE
......@@ -43,8 +43,10 @@ extern "C" {
/** Error buffer length */
#define ERROR_BUF_LENGTH 100
/** Uncomment to enable secure server */
#define HTTPS_SERVER
#define HTTPS_SERVER CONFIG_HTTPS_SERVER
#define HTTPD_EXAMPLE CONFIG_HTTPD_EXAMPLE
/** Opaque type representing single HTTP connection */
typedef struct http_context_* http_context_t;
......
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