net: http: Move heap init into net/lib/http/http.c
This is done so that both http_client and http_server functionality can share the same heap. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
393ab90785
commit
0d43bbfb77
4 changed files with 38 additions and 20 deletions
|
@ -38,6 +38,12 @@
|
||||||
|
|
||||||
#define HTTP_CRLF "\r\n"
|
#define HTTP_CRLF "\r\n"
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
||||||
|
void http_heap_init(void);
|
||||||
|
#else
|
||||||
|
#define http_heap_init()
|
||||||
|
#endif /* MBEDTLS_MEMORY_BUFFER_ALLOC_C */
|
||||||
|
|
||||||
#if defined(CONFIG_HTTP_CLIENT)
|
#if defined(CONFIG_HTTP_CLIENT)
|
||||||
|
|
||||||
#include <net/http_parser.h>
|
#include <net/http_parser.h>
|
||||||
|
|
|
@ -3,3 +3,4 @@ ccflags-$(CONFIG_HTTP_PARSER_STRICT) += -DHTTP_PARSER_STRICT
|
||||||
obj-$(CONFIG_HTTP_PARSER) := http_parser.o
|
obj-$(CONFIG_HTTP_PARSER) := http_parser.o
|
||||||
obj-$(CONFIG_HTTP_CLIENT) += http_client.o
|
obj-$(CONFIG_HTTP_CLIENT) += http_client.o
|
||||||
obj-$(CONFIG_HTTP_SERVER) += http_server.o
|
obj-$(CONFIG_HTTP_SERVER) += http_server.o
|
||||||
|
obj-$(CONFIG_HTTP) += http.o
|
||||||
|
|
29
subsys/net/lib/http/http.c
Normal file
29
subsys/net/lib/http/http.c
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2017 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(CONFIG_NET_DEBUG_HTTP)
|
||||||
|
#define SYS_LOG_DOMAIN "http"
|
||||||
|
#define NET_LOG_ENABLED 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include <net/http.h>
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
||||||
|
#include <mbedtls/memory_buffer_alloc.h>
|
||||||
|
static unsigned char heap[CONFIG_HTTPS_HEAP_SIZE];
|
||||||
|
|
||||||
|
void http_heap_init(void)
|
||||||
|
{
|
||||||
|
static bool heap_init;
|
||||||
|
|
||||||
|
if (!heap_init) {
|
||||||
|
heap_init = true;
|
||||||
|
mbedtls_memory_buffer_alloc_init(heap, sizeof(heap));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* MBEDTLS_MEMORY_BUFFER_ALLOC_C */
|
|
@ -39,11 +39,7 @@ static void https_disable(struct http_server_ctx *ctx);
|
||||||
#define DEBUG_THRESHOLD 0
|
#define DEBUG_THRESHOLD 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
#endif /* CONFIG_HTTPS */
|
||||||
#include <mbedtls/memory_buffer_alloc.h>
|
|
||||||
static unsigned char heap[CONFIG_HTTPS_HEAP_SIZE];
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define HTTP_DEFAULT_PORT 80
|
#define HTTP_DEFAULT_PORT 80
|
||||||
#define HTTPS_DEFAULT_PORT 443
|
#define HTTPS_DEFAULT_PORT 443
|
||||||
|
@ -1270,20 +1266,6 @@ out:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
|
|
||||||
static void heap_init(struct http_server_ctx *ctx)
|
|
||||||
{
|
|
||||||
static bool heap_init;
|
|
||||||
|
|
||||||
if (!heap_init) {
|
|
||||||
mbedtls_memory_buffer_alloc_init(heap, sizeof(heap));
|
|
||||||
heap_init = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#define heap_init(...)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void https_handler(struct http_server_ctx *ctx)
|
static void https_handler(struct http_server_ctx *ctx)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
|
@ -1293,7 +1275,7 @@ static void https_handler(struct http_server_ctx *ctx)
|
||||||
|
|
||||||
mbedtls_platform_set_printf(printk);
|
mbedtls_platform_set_printf(printk);
|
||||||
|
|
||||||
heap_init(ctx);
|
http_heap_init();
|
||||||
|
|
||||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||||
mbedtls_x509_crt_init(&ctx->https.mbedtls.srvcert);
|
mbedtls_x509_crt_init(&ctx->https.mbedtls.srvcert);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue