diff options
author | Jakub Zawadzki <darkjames-ws@darkjames.pl> | 2014-01-08 00:28:13 +0000 |
---|---|---|
committer | Jakub Zawadzki <darkjames-ws@darkjames.pl> | 2014-01-08 00:28:13 +0000 |
commit | d28084d1839bb581229f72acc37608b00c2caba7 (patch) | |
tree | fb6ba22256d5334b83e0279879544f28efcb8601 /epan/dissectors/packet-json.c | |
parent | e8dd800cc16765afadc8543ed9292ea5caf73df1 (diff) |
Move UAT xton() to wsutil library
Use ws_xton() in few more places.
svn path=/trunk/; revision=54642
Diffstat (limited to 'epan/dissectors/packet-json.c')
-rw-r--r-- | epan/dissectors/packet-json.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/epan/dissectors/packet-json.c b/epan/dissectors/packet-json.c index 3c9f09193d..0d67da312c 100644 --- a/epan/dissectors/packet-json.c +++ b/epan/dissectors/packet-json.c @@ -37,6 +37,7 @@ #include <epan/packet.h> #include <epan/tvbparse.h> +#include <wsutil/str_util.h> #include <wsutil/unicode-utils.h> void proto_register_json(void); @@ -281,6 +282,7 @@ static char *json_string_unescape(tvbparse_elem_t *tok) j = 0; for (i = 1; i < tok->len - 1; i++) { guint8 ch = tvb_get_guint8(tok->tvb, tok->offset + i); + int bin; if (ch == '\\') { i++; @@ -320,16 +322,12 @@ static char *json_string_unescape(tvbparse_elem_t *tok) unicode_hex <<= 4; ch = tvb_get_guint8(tok->tvb, tok->offset + i); - if (ch >= '0' && ch <= '9') - unicode_hex |= (ch - '0'); - else if (ch >= 'a' && ch <= 'f') - unicode_hex |= (10 + (ch - 'a')); - else if (ch >= 'A' && ch <= 'F') - unicode_hex |= (10 + (ch - 'A')); - else { + bin = ws_xton(ch); + if (bin == -1) { valid = FALSE; break; } + unicode_hex |= bin; } if ((IS_LEAD_SURROGATE(unicode_hex))) { @@ -348,16 +346,12 @@ static char *json_string_unescape(tvbparse_elem_t *tok) trail_surrogate <<= 4; ch = tvb_get_guint8(tok->tvb, tok->offset + i); - if (ch >= '0' && ch <= '9') - trail_surrogate |= (ch - '0'); - else if (ch >= 'a' && ch <= 'f') - trail_surrogate |= (10 + (ch - 'a')); - else if (ch >= 'A' && ch <= 'F') - trail_surrogate |= (10 + (ch - 'A')); - else { + bin = ws_xton(ch); + if (bin == -1) { valid = FALSE; break; } + trail_surrogate |= bin; } if ((IS_TRAIL_SURROGATE(trail_surrogate))) { |