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 | |
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')
-rw-r--r-- | epan/dissectors/packet-gtp.c | 1 | ||||
-rw-r--r-- | epan/dissectors/packet-http-urlencoded.c | 20 | ||||
-rw-r--r-- | epan/dissectors/packet-json.c | 22 | ||||
-rw-r--r-- | epan/dissectors/packet-ssl-utils.c | 8 |
4 files changed, 18 insertions, 33 deletions
diff --git a/epan/dissectors/packet-gtp.c b/epan/dissectors/packet-gtp.c index aa83b2e4de..9faad3b73c 100644 --- a/epan/dissectors/packet-gtp.c +++ b/epan/dissectors/packet-gtp.c @@ -4140,6 +4140,7 @@ decode_gtp_mm_cntxt(tvbuff_t * tvb, int offset, packet_info * pinfo, proto_tree static guint8 hex2dec(guint8 x) { + /* XXX, ws_xton() */ if ((x >= 'a') && (x <= 'f')) x = x - 'a' + 10; else if ((x >= 'A') && (x <= 'F')) diff --git a/epan/dissectors/packet-http-urlencoded.c b/epan/dissectors/packet-http-urlencoded.c index 7236022bf9..b24ce507dc 100644 --- a/epan/dissectors/packet-http-urlencoded.c +++ b/epan/dissectors/packet-http-urlencoded.c @@ -30,6 +30,7 @@ #include <epan/packet.h> #include <epan/wmem/wmem.h> +#include <wsutil/str_util.h> void proto_register_http_urlencoded(void); void proto_reg_handoff_http_urlencoded(void); @@ -52,19 +53,6 @@ static header_field_info hfi_form_value URLENCODED_HFI_INIT = static gint ett_form_urlencoded = -1; static gint ett_form_keyvalue = -1; -static guint8 -get_hexa(guint8 a) -{ - if (a >= '0' && a <= '9') - return a - '0'; - if (a >= 'A' && a <= 'F') - return (a - 'A') + 10; - if (a >= 'a' && a <= 'f') - return (a - 'a') + 10; - - return 0xff; -} - static int get_form_key_value(tvbuff_t *tvb, char **ptr, int offset, char stop) { @@ -84,12 +72,12 @@ get_form_key_value(tvbuff_t *tvb, char **ptr, int offset, char stop) if (ch == '%') { offset++; ch = tvb_get_guint8(tvb, offset); - if (get_hexa(ch) > 15) + if (ws_xton(ch) == -1) return -1; offset++; ch = tvb_get_guint8(tvb, offset); - if (get_hexa(ch) > 15) + if (ws_xton(ch) == -1) return -1; } @@ -120,7 +108,7 @@ get_form_key_value(tvbuff_t *tvb, char **ptr, int offset, char stop) offset++; ch2 = tvb_get_guint8(tvb, offset); - tmp[len] = get_hexa(ch1) << 4 | get_hexa(ch2); + tmp[len] = ws_xton(ch1) << 4 | ws_xton(ch2); } else if (ch == '+') tmp[len] = ' '; 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))) { diff --git a/epan/dissectors/packet-ssl-utils.c b/epan/dissectors/packet-ssl-utils.c index cd3a79a20a..bb04e00ee6 100644 --- a/epan/dissectors/packet-ssl-utils.c +++ b/epan/dissectors/packet-ssl-utils.c @@ -42,6 +42,7 @@ #include <epan/ipv6-utils.h> #include <epan/expert.h> #include <wsutil/file_util.h> +#include <wsutil/str_util.h> /* * Lookup tables @@ -1356,6 +1357,7 @@ ssl_data_set(StringInfo* str, const guchar* data, guint len) static guint8 from_hex_char(gchar c) { + /* XXX, ws_xton() */ if ((c >= '0') && (c <= '9')) return c - '0'; if ((c >= 'A') && (c <= 'F')) @@ -1377,9 +1379,9 @@ static gboolean from_hex(StringInfo* out, const char* in, gsize hex_len) { out->data_len = (guint)hex_len/2; out->data = (guchar *)wmem_alloc(wmem_file_scope(), out->data_len); for (i = 0; i < out->data_len; i++) { - guint8 a = from_hex_char(in[i*2]); - guint8 b = from_hex_char(in[i*2 + 1]); - if (a == 16 || b == 16) + int a = ws_xton(in[i*2]); + int b = ws_xton(in[i*2 + 1]); + if (a == -1 || b == -1) return FALSE; out->data[i] = a << 4 | b; } |