net: lib: Convert http library to use log level

Use network log level in HTTP library.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2018-07-10 15:44:02 +03:00
commit 8ffb0fc968
4 changed files with 61 additions and 71 deletions

View file

@ -67,11 +67,11 @@ config HTTP_CLIENT_NETWORK_TIMEOUT
Default network activity timeout in seconds. This setting is used
for TCP connection timeout.
config NET_DEBUG_HTTP
bool "Debug HTTP"
depends on HTTP && NET_LOG
help
Enables HTTP output debug messages
module=HTTP
module-dep=NET_LOG
module-str=Log level for HTTP
module-help=Enables routing engine debug messages.
source "subsys/net/Kconfig.template.log_config.net"
config NET_DEBUG_HTTP_CONN
bool "Debug HTTP connections"

View file

@ -4,11 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#if defined(CONFIG_NET_DEBUG_HTTP)
#define SYS_LOG_DOMAIN "http"
#define NET_SYS_LOG_LEVEL SYS_LOG_LEVEL_DEBUG
#define NET_LOG_ENABLED 1
#endif
#define LOG_MODULE_NAME net_http
#define NET_LOG_LEVEL CONFIG_HTTP_LOG_LEVEL
#include <zephyr.h>
#include <string.h>

View file

@ -4,15 +4,12 @@
* SPDX-License-Identifier: Apache-2.0
*/
#if defined(CONFIG_NET_DEBUG_HTTP)
#if defined(CONFIG_HTTPS)
#define SYS_LOG_DOMAIN "https/client"
#define LOG_MODULE_NAME net_https_client
#else
#define SYS_LOG_DOMAIN "http/client"
#endif
#define NET_SYS_LOG_LEVEL SYS_LOG_LEVEL_DEBUG
#define NET_LOG_ENABLED 1
#define LOG_MODULE_NAME net_http_client
#endif
#define NET_LOG_LEVEL CONFIG_HTTP_LOG_LEVEL
#include <zephyr.h>
#include <string.h>
@ -168,7 +165,6 @@ out:
return ret;
}
#if defined(CONFIG_NET_DEBUG_HTTP)
static void sprint_addr(char *buf, int len,
sa_family_t family,
struct sockaddr *addr)
@ -181,12 +177,11 @@ static void sprint_addr(char *buf, int len,
NET_DBG("Invalid protocol family");
}
}
#endif
static inline void print_info(struct http_ctx *ctx,
enum http_method method)
{
#if defined(CONFIG_NET_DEBUG_HTTP)
if (NET_LOG_LEVEL >= LOG_LEVEL_INF) {
char local[NET_IPV6_ADDR_LEN];
char remote[NET_IPV6_ADDR_LEN];
@ -199,9 +194,11 @@ static inline void print_info(struct http_ctx *ctx,
&ctx->app_ctx.default_ctx->remote);
NET_DBG("HTTP %s (%s) %s -> %s port %d",
http_method_str(method), ctx->http.req.host, local, remote,
ntohs(net_sin(&ctx->app_ctx.default_ctx->remote)->sin_port));
#endif
http_method_str(method), ctx->http.req.host, local,
remote,
ntohs(net_sin(&ctx->app_ctx.default_ctx->remote)->
sin_port));
}
}
int http_client_send_req(struct http_ctx *ctx,
@ -273,7 +270,7 @@ out:
static void print_header_field(size_t len, const char *str)
{
#if defined(CONFIG_NET_DEBUG_HTTP)
if (NET_LOG_LEVEL >= LOG_LEVEL_INF) {
#define MAX_OUTPUT_LEN 128
char output[MAX_OUTPUT_LEN];
@ -287,7 +284,7 @@ static void print_header_field(size_t len, const char *str)
snprintk(output, len + 1, "%s", str);
NET_DBG("[%zd] %s", len, output);
#endif
}
}
static int on_url(struct http_parser *parser, const char *at, size_t length)
@ -435,16 +432,15 @@ static int on_headers_complete(struct http_parser *parser)
static int on_message_begin(struct http_parser *parser)
{
#if defined(CONFIG_NET_DEBUG_HTTP) && (CONFIG_SYS_LOG_NET_LEVEL > 2)
if (NET_LOG_LEVEL >= LOG_LEVEL_INF) {
struct http_ctx *ctx = CONTAINER_OF(parser,
struct http_ctx,
http.parser);
NET_DBG("-- HTTP %s response (headers) --",
http_method_str(ctx->http.req.method));
#else
ARG_UNUSED(parser);
#endif
}
return 0;
}

View file

@ -4,15 +4,12 @@
* SPDX-License-Identifier: Apache-2.0
*/
#if defined(CONFIG_NET_DEBUG_HTTP)
#if defined(CONFIG_HTTPS)
#define SYS_LOG_DOMAIN "https/server"
#define LOG_MODULE_NAME net_https_server
#else
#define SYS_LOG_DOMAIN "http/server"
#endif
#define NET_SYS_LOG_LEVEL SYS_LOG_LEVEL_DEBUG
#define NET_LOG_ENABLED 1
#define LOG_MODULE_NAME net_http_server
#endif
#define NET_LOG_LEVEL CONFIG_HTTP_LOG_LEVEL
#include <zephyr.h>
#include <string.h>
@ -81,7 +78,7 @@ void http_server_conn_monitor(http_server_cb_t cb, void *user_data)
const char * const http_state_str(enum http_state state)
{
#if defined(CONFIG_NET_DEBUG_HTTP)
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG
switch (state) {
case HTTP_STATE_CLOSED:
return "CLOSED";
@ -94,14 +91,14 @@ const char * const http_state_str(enum http_state state)
case HTTP_STATE_OPEN:
return "OPEN";
}
#else /* CONFIG_NET_DEBUG_HTTP */
#else
ARG_UNUSED(state);
#endif /* CONFIG_NET_DEBUG_HTTP */
#endif
return "";
}
#if defined(CONFIG_NET_DEBUG_HTTP)
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG
static void validate_state_transition(struct http_ctx *ctx,
enum http_state current,
enum http_state new)
@ -127,7 +124,7 @@ static void validate_state_transition(struct http_ctx *ctx,
http_state_str(new), new);
}
}
#endif /* CONFIG_NET_DEBUG_HTTP */
#endif /* NET_LOG_LEVEL */
void _http_change_state(struct http_ctx *ctx,
enum http_state new_state,
@ -145,9 +142,9 @@ void _http_change_state(struct http_ctx *ctx,
http_state_str(new_state), new_state,
func, line);
#if defined(CONFIG_NET_DEBUG_HTTP)
#if NET_LOG_LEVEL >= LOG_LEVEL_DBG
validate_state_transition(ctx, ctx->state, new_state);
#endif /* CONFIG_NET_DEBUG_HTTP */
#endif
ctx->state = new_state;
}
@ -217,7 +214,7 @@ quit:
return ret;
}
#if defined(CONFIG_NET_DEBUG_HTTP) && (CONFIG_SYS_LOG_NET_LEVEL > 2)
#if NET_LOG_LEVEL >= LOG_LEVEL_INF
static char *sprint_ipaddr(char *buf, int buflen, const struct sockaddr *addr)
{
if (addr->sa_family == AF_INET6) {
@ -300,14 +297,14 @@ static struct net_context *get_server_ctx(struct net_app_ctx *ctx,
return NULL;
}
#endif /* CONFIG_NET_DEBUG_HTTP */
#endif /* NET_LOG_LEVEL */
static inline void new_client(struct http_ctx *ctx,
enum http_connection_type type,
struct net_app_ctx *app_ctx,
const struct sockaddr *dst)
{
#if defined(CONFIG_NET_DEBUG_HTTP) && (CONFIG_SYS_LOG_NET_LEVEL > 2)
#if NET_LOG_LEVEL >= LOG_LEVEL_INF
#if defined(CONFIG_NET_IPV6)
#define PORT_LEN sizeof("[]:xxxxx")
#define ADDR_LEN NET_IPV6_ADDR_LEN
@ -331,7 +328,7 @@ static inline void new_client(struct http_ctx *ctx,
} else {
NET_INFO("[%p] %s connection", ctx, type_str);
}
#endif /* CONFIG_NET_DEBUG_HTTP */
#endif /* NET_LOG_LEVEL */
}
static void url_connected(struct http_ctx *ctx,
@ -996,7 +993,7 @@ static inline void new_server(struct http_ctx *ctx,
const char *server_banner,
const struct sockaddr *addr)
{
#if defined(CONFIG_NET_DEBUG_HTTP) && (CONFIG_SYS_LOG_NET_LEVEL > 2)
#if NET_LOG_LEVEL >= LOG_LEVEL_INF
#if defined(CONFIG_NET_IPV6)
#define PORT_STR sizeof("[]:xxxxx")
char buf[NET_IPV6_ADDR_LEN + PORT_STR];
@ -1011,7 +1008,7 @@ static inline void new_server(struct http_ctx *ctx,
} else {
NET_INFO("%s (%p)", server_banner, ctx);
}
#endif /* CONFIG_NET_DEBUG_HTTP */
#endif /* NET_LOG_LEVEL */
}
static void init_net(struct http_ctx *ctx,