From a9daec05903db9d35f74d17aee71f5c8dc80044a Mon Sep 17 00:00:00 2001 From: openshwprojects Date: Tue, 18 Apr 2023 00:33:36 +0200 Subject: [PATCH] formatting --- src/cmnds/cmd_tokenizer.c | 5 ++++- src/httpserver/http_fns.c | 4 +--- src/new_common.h | 3 +++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cmnds/cmd_tokenizer.c b/src/cmnds/cmd_tokenizer.c index ea55c245a..ca4c6cedf 100644 --- a/src/cmnds/cmd_tokenizer.c +++ b/src/cmnds/cmd_tokenizer.c @@ -20,8 +20,11 @@ static int tok_flags = 0; #define g_bAllowQuotes (tok_flags&TOKENIZER_ALLOW_QUOTES) #define g_bAllowExpand (!(tok_flags&TOKENIZER_DONT_EXPAND)) +int str_to_ip(const char *s, byte *ip) { + return sscanf(s, IP_STRING_FORMAT, &ip[0], &ip[1], &ip[2], &ip[3]); +} void convert_IP_to_string(char *o, unsigned char *ip) { - sprintf(o, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); + sprintf(o, IP_STRING_FORMAT, ip[0], ip[1], ip[2], ip[3]); } bool isWhiteSpace(char ch) { if(ch == ' ') diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index e9367b022..fcdbb2b5b 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -958,9 +958,7 @@ int http_fn_cfg_mqtt(http_request_t* request) { poststr(request, NULL); return 0; } -int str_to_ip(const char *s, byte *ip) { - return sscanf(s, "%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3]); -} + int http_fn_cfg_ip(http_request_t* request) { char tmp[64]; int g_changes = 0; diff --git a/src/new_common.h b/src/new_common.h index 000a7c9eb..c27deb1c7 100644 --- a/src/new_common.h +++ b/src/new_common.h @@ -433,6 +433,8 @@ typedef enum EXCELLENT, } WIFI_RSSI_LEVEL; +#define IP_STRING_FORMAT "%hhu.%hhu.%hhu.%hhu" + WIFI_RSSI_LEVEL wifi_rssi_scale(int8_t rssi_value); extern const char *str_rssi[]; extern int bSafeMode; @@ -446,6 +448,7 @@ int JSON_ProcessCommandReply(const char *cmd, const char *args, void *request, j void ScheduleDriverStart(const char *name, int delay); bool isWhiteSpace(char ch); void convert_IP_to_string(char *o, unsigned char *ip); +int str_to_ip(const char *s, byte *ip); #endif /* __NEW_COMMON_H__ */