aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil/jsmn.c
diff options
context:
space:
mode:
authorDario Lombardo <lomato@gmail.com>2016-09-28 12:01:33 +0200
committerPeter Wu <peter@lekensteyn.nl>2016-09-30 20:12:00 +0000
commit11c10244ef5168a337d88611d61c5ebc88acd29e (patch)
treec1503548a6ae38cb372632d14169a880cc5ae95d /wsutil/jsmn.c
parent534787e402d6aa8b349638f911a2a65b013c6594 (diff)
wsutil: split libjsmn.
The libjsmn was imported into the tree and enhanced with a new function. This change splits it into the "original" libjsmn and an addictional module wsjsmn that contains the new function. This will make easier to port within the tree future versions of the library. Change-Id: I3f1caa91bee462e0767e5e18d0b6a10f0b1cad32 Reviewed-on: https://code.wireshark.org/review/17963 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'wsutil/jsmn.c')
-rw-r--r--wsutil/jsmn.c105
1 files changed, 21 insertions, 84 deletions
diff --git a/wsutil/jsmn.c b/wsutil/jsmn.c
index b87e373c58..d5e3bb5faf 100644
--- a/wsutil/jsmn.c
+++ b/wsutil/jsmn.c
@@ -1,34 +1,26 @@
/*
- * Copyright (c) 2010 Serge A. Zaitsev
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
+Copyright (c) 2010 Serge A. Zaitsev
-#include <stdlib.h>
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
-/* WS modification starts here */
-#define JSMN_STRICT
-/* WS modification ends here */
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
-#include "jsmn.h"
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
-#include "log.h"
+#include "jsmn.h"
/**
* Allocates a fresh unused token from the token pull.
@@ -52,7 +44,7 @@ static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser,
* Fills token type and boundaries.
*/
static void jsmn_fill_token(jsmntok_t *token, jsmntype_t type,
- int start, int end) {
+ int start, int end) {
token->type = type;
token->start = start;
token->end = end;
@@ -109,7 +101,7 @@ found:
}
/**
- * Filsl next token with JSON string.
+ * Fills next token with JSON string.
*/
static int jsmn_parse_string(jsmn_parser *parser, const char *js,
size_t len, jsmntok_t *tokens, size_t num_tokens) {
@@ -183,7 +175,7 @@ int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
int r;
int i;
jsmntok_t *token;
- int count = 0;
+ int count = parser->toknext;
for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) {
char c;
@@ -338,58 +330,3 @@ void jsmn_init(jsmn_parser *parser) {
parser->toknext = 0;
parser->toksuper = -1;
}
-
-/* WS modification starts here */
-gboolean jsmn_is_json(const guint8* buf, const size_t len)
-{
- /* 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);
-
- 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);
-
- return ret;
-}
-/* WS modification ends here */
-
-/*
- * Editor modelines - https://www.wireshark.org/tools/modelines.html
- *
- * Local variables:
- * c-basic-offset: 8
- * tab-width: 8
- * indent-tabs-mode: t
- * End:
- *
- * vi: set shiftwidth=8 tabstop=8 noexpandtab:
- * :indentSize=8:tabSize=8:noTabs=false:
- */