aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2018-11-19 15:52:30 +0100
committerAnders Broman <a.broman58@gmail.com>2018-11-20 05:03:26 +0000
commitfb9c6905eff10f6f49a433ead8bd78e232fa068d (patch)
tree31154d39f805ba9527ad93a58f7dc7212799eef7 /wsutil
parente2a5ad1febd5352563407ad13057ef82f7756d43 (diff)
wsutil: rename some wsjson functions
Rename wsjson_unescape_json_string to json_decode_string_inplace (inspired by the g_base64_decode_inplace name). Rename wsjson_is_valid_json to json_validate (inspired by g_unichar_validate). Ideally json_parse is inlined with its user (sharkd_session.c), but that requires exporting the jsmn_init and jsmn_parse functions... Hence the dependency on jsmn.h remains in wsjson.h. Change-Id: I7ecfe3565f15516e9115cbd7e025362df2da5416 Reviewed-on: https://code.wireshark.org/review/30731 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'wsutil')
-rw-r--r--wsutil/wsjson.c13
-rw-r--r--wsutil/wsjson.h11
2 files changed, 15 insertions, 9 deletions
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
}