diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt index 7ee405a334..f3e000f28b 100644 --- a/wsutil/CMakeLists.txt +++ b/wsutil/CMakeLists.txt @@ -227,6 +227,11 @@ set(wsutil_LIBS ${WIN_WSOCK32_LIBRARY} ${GNUTLS_LIBRARIES} ) + +IF(HAVE_JSONGLIB) + list(APPEND wsutil_LIBS ${JSONGLIB_LIBRARIES}) +ENDIF() + IF(WIN32) set(wsutil_LIBS ${wsutil_LIBS} "iphlpapi.lib" "ws2_32.lib") ENDIF(WIN32) diff --git a/wsutil/wsjson.c b/wsutil/wsjson.c index 7c0dafd19c..7d5c442ecd 100644 --- a/wsutil/wsjson.c +++ b/wsutil/wsjson.c @@ -10,6 +10,8 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ +#include "config.h" + #include "wsjson.h" #include @@ -18,13 +20,22 @@ #include #include "log.h" +#ifdef HAVE_JSONGLIB +#include +#endif + gboolean wsjson_is_valid_json(const guint8* buf, const size_t len) { + gboolean ret = TRUE; +#ifdef HAVE_JSONGLIB + JsonParser *parser = json_parser_new(); + GError* error; + ret = json_parser_load_from_data(parser, buf, len, &error); +#else /* We expect no more than 1024 tokens */ guint max_tokens = 1024; jsmntok_t* t; jsmn_parser p; - gboolean ret = TRUE; int rcode; t = g_new0(jsmntok_t, max_tokens); @@ -54,7 +65,7 @@ gboolean wsjson_is_valid_json(const guint8* buf, const size_t len) } g_free(t); - +#endif return ret; }