From 2ae0d2ff1d5e2b123763b15f2c4cc885dd423e69 Mon Sep 17 00:00:00 2001 From: Indu Prakash Date: Wed, 24 Aug 2022 21:57:10 -0500 Subject: [PATCH] Adjusted tryGetTokenString to get successful build --- src/httpserver/rest_interface.c | 22 ++++++++++++++++++++++ src/jsmn/jsmn.c | 19 ------------------- src/jsmn/jsmn_h.h | 6 +----- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/httpserver/rest_interface.c b/src/httpserver/rest_interface.c index ebf720e75..81f1672dc 100644 --- a/src/httpserver/rest_interface.c +++ b/src/httpserver/rest_interface.c @@ -31,6 +31,9 @@ uint32_t flash_read(uint32_t flash, uint32_t addr,void *buf, uint32_t size); extern UINT32 flash_read(char *user_buf, UINT32 count, UINT32 address); #endif +#define MAX_JSON_VALUE_LENGTH 128 + + static int http_rest_error(http_request_t *request, int code, char *msg); static int http_rest_get(http_request_t *request); @@ -119,6 +122,25 @@ const char * apppage4 = "startup.js\">" "" ""; + +/* Extracts string token value into outBuffer (128 char). Returns true if the operation was successful. */ +bool tryGetTokenString(const char *json, jsmntok_t *tok, char *outBuffer){ + if (tok == NULL || tok->type != JSMN_STRING){ + return false; + } + + int length = tok->end - tok->start; + + //Don't have enough buffer + if (length > MAX_JSON_VALUE_LENGTH) { + return false; + } + + memset(outBuffer, '\0', MAX_JSON_VALUE_LENGTH); //Wipe previous value + strncpy(outBuffer, json + tok->start, length); + return true; +} + static int http_rest_get(http_request_t *request){ ADDLOG_DEBUG(LOG_FEATURE_API, "GET of %s", request->url); diff --git a/src/jsmn/jsmn.c b/src/jsmn/jsmn.c index ee22a7124..aff46d9f8 100644 --- a/src/jsmn/jsmn.c +++ b/src/jsmn/jsmn.c @@ -2,7 +2,6 @@ #include "string.h" // this includes the source code. #include "jsmn.h" -#include "jsmn_h.h" int jsoneq(const char *json, jsmntok_t *tok, const char *s) { if (tok->type == JSMN_STRING && (int)strlen(s) == tok->end - tok->start && @@ -11,21 +10,3 @@ int jsoneq(const char *json, jsmntok_t *tok, const char *s) { } return -1; } - -/* Extracts string token value into outBuffer (128 char). Returns true if the operation was successful. */ -bool tryGetTokenString(const char *json, jsmntok_t *tok, char *outBuffer){ - if (tok == NULL || tok->type != JSMN_STRING){ - return false; - } - - int length = tok->end - tok->start; - - //Don't have enough buffer - if (length > MAX_JSON_VALUE_LENGTH) { - return false; - } - - memset(outBuffer, '\0', MAX_JSON_VALUE_LENGTH); //Wipe previous value - strncpy(outBuffer, json + tok->start, length); - return true; -} \ No newline at end of file diff --git a/src/jsmn/jsmn_h.h b/src/jsmn/jsmn_h.h index 126dacf8a..c18b4f17c 100644 --- a/src/jsmn/jsmn_h.h +++ b/src/jsmn/jsmn_h.h @@ -1,10 +1,6 @@ -// prevent inclusion of the source code +// prevent includsion of the source code #define JSMN_HEADER #include "string.h" #include "jsmn.h" -#include "../new_common.h" - -#define MAX_JSON_VALUE_LENGTH 128 int jsoneq(const char *json, jsmntok_t *tok, const char *s); -bool tryGetTokenString(const char *json, jsmntok_t *tok, char *outBuffer);