aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2018-11-19 15:21:02 +0100
committerAnders Broman <a.broman58@gmail.com>2018-11-20 05:02:50 +0000
commite2a5ad1febd5352563407ad13057ef82f7756d43 (patch)
treee7d7cd6ef632978ccb8b798cbbbc370d026584e5
parentba3454529302a64e11c498a2185f4b5ddc1ccf3a (diff)
wsutil: fix indentation/modelines in wsjson
The modelines says tabs, but the actual indentation is 8 spaces. Let's change it to match the standard 4 spaces in the top-level .editorconfig. Change-Id: I2b26b095f5e4f6f8d5d083d41ceaae98f9284fba Reviewed-on: https://code.wireshark.org/review/30730 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--wsutil/wsjson.c264
-rw-r--r--wsutil/wsjson.h6
2 files changed, 135 insertions, 135 deletions
diff --git a/wsutil/wsjson.c b/wsutil/wsjson.c
index c19c46c179..9ede1aee1e 100644
--- a/wsutil/wsjson.c
+++ b/wsutil/wsjson.c
@@ -26,156 +26,156 @@
gboolean wsjson_is_valid_json(const guint8* buf, const size_t len)
{
- gboolean ret = TRUE;
+ gboolean ret = TRUE;
#ifdef HAVE_JSONGLIB
- JsonParser *parser = json_parser_new();
- ret = json_parser_load_from_data(parser, buf, len, NULL);
- g_object_unref(parser);
+ JsonParser *parser = json_parser_new();
+ ret = json_parser_load_from_data(parser, buf, len, NULL);
+ g_object_unref(parser);
#else
- /* We expect no more than 1024 tokens */
- guint max_tokens = 1024;
- jsmntok_t* t;
- jsmn_parser p;
- int rcode;
-
- t = g_new0(jsmntok_t, max_tokens);
-
- if (!t)
- return FALSE;
-
- jsmn_init(&p);
- rcode = jsmn_parse(&p, buf, len, t, max_tokens);
- if (rcode < 0) {
- switch (rcode) {
- case JSMN_ERROR_NOMEM:
- g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "jsmn: not enough tokens were provided");
- break;
- case JSMN_ERROR_INVAL:
- g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "jsmn: invalid character inside JSON string");
- break;
- case JSMN_ERROR_PART:
- g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "jsmn: the string is not a full JSON packet, "
- "more bytes expected");
- break;
- default:
- g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "jsmn: unexpected error");
- break;
- }
- ret = FALSE;
+ /* We expect no more than 1024 tokens */
+ guint max_tokens = 1024;
+ jsmntok_t* t;
+ jsmn_parser p;
+ int rcode;
+
+ t = g_new0(jsmntok_t, max_tokens);
+
+ if (!t)
+ return FALSE;
+
+ jsmn_init(&p);
+ rcode = jsmn_parse(&p, buf, len, t, max_tokens);
+ if (rcode < 0) {
+ switch (rcode) {
+ case JSMN_ERROR_NOMEM:
+ g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "jsmn: not enough tokens were provided");
+ break;
+ case JSMN_ERROR_INVAL:
+ g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "jsmn: invalid character inside JSON string");
+ break;
+ case JSMN_ERROR_PART:
+ g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "jsmn: the string is not a full JSON packet, "
+ "more bytes expected");
+ break;
+ default:
+ g_log(LOG_DOMAIN_MAIN, G_LOG_LEVEL_DEBUG, "jsmn: unexpected error");
+ break;
}
+ ret = FALSE;
+ }
- g_free(t);
+ g_free(t);
#endif
- return ret;
+ return ret;
}
int wsjson_parse(const char *buf, jsmntok_t *tokens, unsigned int max_tokens)
{
- jsmn_parser p;
+ jsmn_parser p;
- jsmn_init(&p);
- return jsmn_parse(&p, buf, strlen(buf), tokens, max_tokens);
+ jsmn_init(&p);
+ return jsmn_parse(&p, buf, strlen(buf), tokens, max_tokens);
}
gboolean wsjson_unescape_json_string(const char *input, char *output)
{
- while (*input) {
- char ch = *input++;
+ while (*input) {
+ char ch = *input++;
+
+ if (ch == '\\') {
+ ch = *input++;
+
+ switch (ch) {
+ case '\"':
+ case '\\':
+ case '/':
+ *output++ = ch;
+ break;
+
+ case 'b':
+ *output++ = '\b';
+ break;
+ case 'f':
+ *output++ = '\f';
+ break;
+ case 'n':
+ *output++ = '\n';
+ break;
+ case 'r':
+ *output++ = '\r';
+ break;
+ case 't':
+ *output++ = '\t';
+ break;
+
+ case 'u':
+ {
+ guint32 unicode_hex = 0;
+ int k;
+ int bin;
+
+ for (k = 0; k < 4; k++) {
+ unicode_hex <<= 4;
- if (ch == '\\') {
ch = *input++;
-
- switch (ch) {
- case '\"':
- case '\\':
- case '/':
- *output++ = ch;
- break;
-
- case 'b':
- *output++ = '\b';
- break;
- case 'f':
- *output++ = '\f';
- break;
- case 'n':
- *output++ = '\n';
- break;
- case 'r':
- *output++ = '\r';
- break;
- case 't':
- *output++ = '\t';
- break;
-
- case 'u':
- {
- guint32 unicode_hex = 0;
- int k;
- int bin;
-
- for (k = 0; k < 4; k++) {
- unicode_hex <<= 4;
-
- ch = *input++;
- bin = ws_xton(ch);
- if (bin == -1)
- return FALSE;
- unicode_hex |= bin;
- }
-
- if ((IS_LEAD_SURROGATE(unicode_hex))) {
- guint16 lead_surrogate = unicode_hex;
- guint16 trail_surrogate = 0;
-
- if (input[0] != '\\' || input[1] != 'u')
- return FALSE;
- input += 2;
-
- for (k = 0; k < 4; k++) {
- trail_surrogate <<= 4;
-
- ch = *input++;
- bin = ws_xton(ch);
- if (bin == -1)
- return FALSE;
- trail_surrogate |= bin;
- }
-
- if ((!IS_TRAIL_SURROGATE(trail_surrogate)))
- return FALSE;
-
- unicode_hex = SURROGATE_VALUE(lead_surrogate,trail_surrogate);
-
- } else if ((IS_TRAIL_SURROGATE(unicode_hex))) {
- return FALSE;
- }
-
- if (!g_unichar_validate(unicode_hex))
- return FALSE;
-
- /* Don't allow NUL byte injection. */
- if (unicode_hex == 0)
- return FALSE;
-
- /* \uXXXX => 6 bytes, and g_unichar_to_utf8() requires to have output buffer at least 6 bytes -> OK. */
- k = g_unichar_to_utf8(unicode_hex, output);
- output += k;
- break;
- }
-
- default:
- return FALSE;
+ bin = ws_xton(ch);
+ if (bin == -1)
+ return FALSE;
+ unicode_hex |= bin;
+ }
+
+ if ((IS_LEAD_SURROGATE(unicode_hex))) {
+ guint16 lead_surrogate = unicode_hex;
+ guint16 trail_surrogate = 0;
+
+ if (input[0] != '\\' || input[1] != 'u')
+ return FALSE;
+ input += 2;
+
+ for (k = 0; k < 4; k++) {
+ trail_surrogate <<= 4;
+
+ ch = *input++;
+ bin = ws_xton(ch);
+ if (bin == -1)
+ return FALSE;
+ trail_surrogate |= bin;
}
- } else {
- *output = ch;
- output++;
+ if ((!IS_TRAIL_SURROGATE(trail_surrogate)))
+ return FALSE;
+
+ unicode_hex = SURROGATE_VALUE(lead_surrogate,trail_surrogate);
+
+ } else if ((IS_TRAIL_SURROGATE(unicode_hex))) {
+ return FALSE;
+ }
+
+ if (!g_unichar_validate(unicode_hex))
+ return FALSE;
+
+ /* Don't allow NUL byte injection. */
+ if (unicode_hex == 0)
+ return FALSE;
+
+ /* \uXXXX => 6 bytes, and g_unichar_to_utf8() requires to have output buffer at least 6 bytes -> OK. */
+ k = g_unichar_to_utf8(unicode_hex, output);
+ output += k;
+ break;
}
+
+ default:
+ return FALSE;
+ }
+
+ } else {
+ *output = ch;
+ output++;
}
+ }
- *output = '\0';
- return TRUE;
+ *output = '\0';
+ return TRUE;
}
/*
@@ -184,9 +184,9 @@ gboolean wsjson_unescape_json_string(const char *input, char *output)
* Local variables:
* c-basic-offset: 4
* tab-width: 8
- * indent-tabs-mode: t
+ * indent-tabs-mode: nil
* End:
*
- * vi: set shiftwidth=4 tabstop=8 noexpandtab:
- * :indentSize=4:tabSize=8:noTabs=false:
+ * vi: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
*/
diff --git a/wsutil/wsjson.h b/wsutil/wsjson.h
index e94409a6f0..8560f6b6fe 100644
--- a/wsutil/wsjson.h
+++ b/wsutil/wsjson.h
@@ -46,9 +46,9 @@ WS_DLL_PUBLIC gboolean wsjson_unescape_json_string(const char *input, char *outp
* Local variables:
* c-basic-offset: 4
* tab-width: 8
- * indent-tabs-mode: t
+ * indent-tabs-mode: nil
* End:
*
- * vi: set shiftwidth=4 tabstop=8 noexpandtab:
- * :indentSize=4:tabSize=8:noTabs=false:
+ * vi: set shiftwidth=4 tabstop=8 expandtab:
+ * :indentSize=4:tabSize=8:noTabs=true:
*/