wsutil: use json-glib instead of jsmn if present.
Change-Id: I61b0fc2c23ad08aba3e29471bdfef6cab682bb21 Reviewed-on: https://code.wireshark.org/review/27056 Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
parent
631fec3e1b
commit
73a1e98f4e
|
@ -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)
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "wsjson.h"
|
||||
|
||||
#include <string.h>
|
||||
|
@ -18,13 +20,22 @@
|
|||
#include <wsutil/unicode-utils.h>
|
||||
#include "log.h"
|
||||
|
||||
#ifdef HAVE_JSONGLIB
|
||||
#include <json-glib/json-glib.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue