From 2d7e9e6cd027064163d3a57815a3cbe864f0fc9b Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:19:54 -0400 Subject: [PATCH 1/4] attempt to suppress the WARN thatpops when loading an identity as a file --- library/config.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/library/config.c b/library/config.c index c66ad019..f1dca5e7 100644 --- a/library/config.c +++ b/library/config.c @@ -50,12 +50,25 @@ int ziti_load_config(ziti_config *cfg, const char* cfgstr) { if (!cfgstr) { return ZITI_INVALID_CONFIG; } + bool seems_like_json = false; + const char* c = cfgstr; + while (*cfgstr && isspace((unsigned char)*cfgstr)) { + c++; + } + if (strncmp(c,"{",1) == 0) { + seems_like_json = true; + } memset(cfg, 0, sizeof(*cfg)); - int rc = parse_ziti_config(cfg, cfgstr, strlen(cfgstr)); + int rc; + if(seems_like_json) { + rc = parse_ziti_config(cfg, cfgstr, strlen(cfgstr)); - if (rc < 0) { - ZITI_LOG(DEBUG, "trying to load config from file[%s]", cfgstr); + if (rc < 0) { + ZITI_LOG(DEBUG, "trying to load config from file[%s]", cfgstr); + rc = load_config_file(cfgstr, cfg); + } + } else { rc = load_config_file(cfgstr, cfg); } From 782730f92ae3338d09740d0e077d58346c444bfd Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:22:25 -0400 Subject: [PATCH 2/4] more straightforward compare --- library/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/config.c b/library/config.c index f1dca5e7..82e2c23a 100644 --- a/library/config.c +++ b/library/config.c @@ -55,7 +55,7 @@ int ziti_load_config(ziti_config *cfg, const char* cfgstr) { while (*cfgstr && isspace((unsigned char)*cfgstr)) { c++; } - if (strncmp(c,"{",1) == 0) { + if (*c == '{') { seems_like_json = true; } From bfcd941a9164d81ffb7267c81f6820a20b60fd53 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:37:48 -0400 Subject: [PATCH 3/4] fix macOS and infinite loop --- library/config.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/config.c b/library/config.c index 82e2c23a..9074f2c8 100644 --- a/library/config.c +++ b/library/config.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "zt_internal.h" const char* APP_ID = NULL; @@ -52,7 +53,7 @@ int ziti_load_config(ziti_config *cfg, const char* cfgstr) { } bool seems_like_json = false; const char* c = cfgstr; - while (*cfgstr && isspace((unsigned char)*cfgstr)) { + while (*c && isspace((unsigned char)*c)) { c++; } if (*c == '{') { From 5f0d16ea52ff59385f2258e0b311823bdeaf9ac9 Mon Sep 17 00:00:00 2001 From: dovholuknf <46322585+dovholuknf@users.noreply.github.com> Date: Thu, 17 Oct 2024 15:24:39 -0400 Subject: [PATCH 4/4] whitespace fixes --- library/config.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/config.c b/library/config.c index 9074f2c8..337a3710 100644 --- a/library/config.c +++ b/library/config.c @@ -47,12 +47,12 @@ static int load_config_file(const char *filename, ziti_config *cfg) { return ZITI_OK; } -int ziti_load_config(ziti_config *cfg, const char* cfgstr) { +int ziti_load_config(ziti_config *cfg, const char *cfgstr) { if (!cfgstr) { return ZITI_INVALID_CONFIG; } bool seems_like_json = false; - const char* c = cfgstr; + const char *c = cfgstr; while (*c && isspace((unsigned char)*c)) { c++; } @@ -62,7 +62,7 @@ int ziti_load_config(ziti_config *cfg, const char* cfgstr) { memset(cfg, 0, sizeof(*cfg)); int rc; - if(seems_like_json) { + if (seems_like_json) { rc = parse_ziti_config(cfg, cfgstr, strlen(cfgstr)); if (rc < 0) {