aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--debian/libwsutil0.symbols6
-rw-r--r--epan/dissectors/packet-json.c2
-rw-r--r--sharkd_session.c12
-rw-r--r--wiretap/json.c2
-rw-r--r--wsutil/wsjson.c13
-rw-r--r--wsutil/wsjson.h11
6 files changed, 23 insertions, 23 deletions
diff --git a/debian/libwsutil0.symbols b/debian/libwsutil0.symbols
index 7e88cfeac7..e5b9e771bc 100644
--- a/debian/libwsutil0.symbols
+++ b/debian/libwsutil0.symbols
@@ -100,6 +100,9 @@ libwsutil.so.0 libwsutil0 #MINVER#
isdigit_string@Base 1.10.0
isprint_string@Base 1.10.0
isprint_utf8_string@Base 2.6.1
+ json_decode_string_inplace@Base 2.9.0
+ json_parse@Base 2.9.0
+ json_validate@Base 2.9.0
linear2alaw@Base 1.12.0~rc1
linear2ulaw@Base 1.12.0~rc1
local_interfaces_to_list@Base 2.1.2
@@ -201,6 +204,3 @@ libwsutil.so.0 libwsutil0 #MINVER#
ws_utf8_char_len@Base 1.12.0~rc1
ws_vadd_crash_info@Base 2.5.2
ws_xton@Base 1.12.0~rc1
- wsjson_parse@Base 2.9.0
- wsjson_unescape_json_string@Base 2.9.0
- wsjson_is_valid_json@Base 2.9.0
diff --git a/epan/dissectors/packet-json.c b/epan/dissectors/packet-json.c
index c9c88eac0d..9ab2dbddc4 100644
--- a/epan/dissectors/packet-json.c
+++ b/epan/dissectors/packet-json.c
@@ -755,7 +755,7 @@ dissect_json_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *dat
guint len = tvb_captured_length(tvb);
const guint8* buf = tvb_get_string_enc(wmem_packet_scope(), tvb, 0, len, ENC_ASCII);
- if (wsjson_is_valid_json(buf, len) == FALSE)
+ if (json_validate(buf, len) == FALSE)
return FALSE;
return (dissect_json(tvb, pinfo, tree, data) != 0);
diff --git a/sharkd_session.c b/sharkd_session.c
index 79f266d239..dea7d9bc9a 100644
--- a/sharkd_session.c
+++ b/sharkd_session.c
@@ -79,12 +79,6 @@ struct sharkd_filter_item
static GHashTable *filter_table = NULL;
-static gboolean
-json_unescape_str(char *input)
-{
- return wsjson_unescape_json_string(input, input);
-}
-
static const char *
json_find_attr(const char *buf, const jsmntok_t *tokens, int count, const char *attr)
{
@@ -4321,7 +4315,7 @@ sharkd_session_process(char *buf, const jsmntok_t *tokens, int count)
buf[tokens[i + 1].end] = '\0';
/* unescape only value, as keys are simple strings */
- if (tokens[i + 1].type == JSMN_STRING && !json_unescape_str(&buf[tokens[i + 1].start]))
+ if (tokens[i + 1].type == JSMN_STRING && !json_decode_string_inplace(&buf[tokens[i + 1].start]))
{
fprintf(stderr, "sanity check(3b): [%d] cannot unescape string\n", i + 1);
return;
@@ -4416,7 +4410,7 @@ sharkd_session_main(void)
/* every command is line seperated JSON */
int ret;
- ret = wsjson_parse(buf, NULL, 0);
+ ret = json_parse(buf, NULL, 0);
if (ret < 0)
{
fprintf(stderr, "invalid JSON -> closing\n");
@@ -4434,7 +4428,7 @@ sharkd_session_main(void)
memset(tokens, 0, ret * sizeof(jsmntok_t));
- ret = wsjson_parse(buf, tokens, ret);
+ ret = json_parse(buf, tokens, ret);
if (ret < 0)
{
fprintf(stderr, "invalid JSON(2) -> closing\n");
diff --git a/wiretap/json.c b/wiretap/json.c
index 8bb7fe4d20..5c1b1bf796 100644
--- a/wiretap/json.c
+++ b/wiretap/json.c
@@ -42,7 +42,7 @@ wtap_open_return_val json_open(wtap *wth, int *err, gchar **err_info)
return WTAP_OPEN_NOT_MINE;
}
- if (wsjson_is_valid_json(filebuf, bytes_read) == FALSE) {
+ if (json_validate(filebuf, bytes_read) == FALSE) {
g_free(filebuf);
return WTAP_OPEN_NOT_MINE;
}
diff --git a/wsutil/wsjson.c b/wsutil/wsjson.c
index 9ede1aee1e..dd10832bfb 100644
--- a/wsutil/wsjson.c
+++ b/wsutil/wsjson.c
@@ -1,5 +1,5 @@
/* wsjson.c
- * Utility to check if a payload is json using other libraries.
+ * JSON parsing functions.
*
* Copyright 2016, Dario Lombardo
*
@@ -24,7 +24,8 @@
#include <json-glib/json-glib.h>
#endif
-gboolean wsjson_is_valid_json(const guint8* buf, const size_t len)
+gboolean
+json_validate(const guint8 *buf, const size_t len)
{
gboolean ret = TRUE;
#ifdef HAVE_JSONGLIB
@@ -69,7 +70,8 @@ gboolean wsjson_is_valid_json(const guint8* buf, const size_t len)
return ret;
}
-int wsjson_parse(const char *buf, jsmntok_t *tokens, unsigned int max_tokens)
+int
+json_parse(const char *buf, jsmntok_t *tokens, unsigned int max_tokens)
{
jsmn_parser p;
@@ -77,8 +79,11 @@ int wsjson_parse(const char *buf, jsmntok_t *tokens, unsigned int max_tokens)
return jsmn_parse(&p, buf, strlen(buf), tokens, max_tokens);
}
-gboolean wsjson_unescape_json_string(const char *input, char *output)
+gboolean
+json_decode_string_inplace(char *text)
{
+ const char *input = text;
+ char *output = text;
while (*input) {
char ch = *input++;
diff --git a/wsutil/wsjson.h b/wsutil/wsjson.h
index 8560f6b6fe..197e82eccf 100644
--- a/wsutil/wsjson.h
+++ b/wsutil/wsjson.h
@@ -1,5 +1,5 @@
/* wsjson.h
- * Utility to check if a payload is json using libjsmn
+ * JSON parsing functions.
*
* Copyright 2016, Dario Lombardo
*
@@ -25,14 +25,15 @@ extern "C" {
/**
* Check if a buffer is json an returns true if it is.
*/
-WS_DLL_PUBLIC gboolean wsjson_is_valid_json(const guint8* buf, const size_t len);
+WS_DLL_PUBLIC gboolean json_validate(const guint8 *buf, const size_t len);
-WS_DLL_PUBLIC int wsjson_parse(const char *buf, jsmntok_t *tokens, unsigned int max_tokens);
+WS_DLL_PUBLIC int json_parse(const char *buf, jsmntok_t *tokens, unsigned int max_tokens);
/**
- * Try to unescape input JSON string. output can be the same pointer as input, or must have the same buffer size as input.
+ * Decode the contents of a JSON string value by overwriting the input data.
+ * Returns TRUE on success and FALSE if invalid characters were encountered.
*/
-WS_DLL_PUBLIC gboolean wsjson_unescape_json_string(const char *input, char *output);
+WS_DLL_PUBLIC gboolean json_decode_string_inplace(char *text);
#ifdef __cplusplus
}