Use ws_xton() in few more places.
svn path=/trunk/; revision=54642
static guint8
hex2dec(guint8 x)
{
+ /* XXX, ws_xton() */
if ((x >= 'a') && (x <= 'f'))
x = x - 'a' + 10;
else if ((x >= 'A') && (x <= 'F'))
#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);
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)
{
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;
}
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] = ' ';
#include <epan/packet.h>
#include <epan/tvbparse.h>
+#include <wsutil/str_util.h>
#include <wsutil/unicode-utils.h>
void proto_register_json(void);
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++;
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))) {
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))) {
#include <epan/ipv6-utils.h>
#include <epan/expert.h>
#include <wsutil/file_util.h>
+#include <wsutil/str_util.h>
/*
* Lookup tables
static guint8
from_hex_char(gchar c) {
+ /* XXX, ws_xton() */
if ((c >= '0') && (c <= '9'))
return c - '0';
if ((c >= 'A') && (c <= 'F'))
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;
}
#include "strutil.h"
#include "emem.h"
+#include <wsutil/str_util.h>
#ifdef _WIN32
#include <windows.h>
if (c==':' || c=='.' || c=='-')
continue; /* skip any ':', '.', or '-' between bytes */
/* From the loop above, we know this is a hex digit */
- if (isdigit(c))
- byte_val = c - '0';
- else if (c >= 'a')
- byte_val = (c - 'a') + 10;
- else
- byte_val = (c - 'A') + 10;
+ byte_val = ws_xton(c);
byte_val <<= 4;
/* We also know this is a hex digit */
c = *p++;
- if (isdigit(c))
- byte_val |= c - '0';
- else if (c >= 'a')
- byte_val |= (c - 'a') + 10;
- else if (c >= 'A')
- byte_val |= (c - 'A') + 10;
+ byte_val |= ws_xton(c);
*q++ = byte_val;
}
}
}
-static int xton(char d) {
- switch(d) {
- case '0': return 0;
- case '1': return 1;
- case '2': return 2;
- case '3': return 3;
- case '4': return 4;
- case '5': return 5;
- case '6': return 6;
- case '7': return 7;
- case '8': return 8;
- case '9': return 9;
- case 'a': case 'A': return 10;
- case 'b': case 'B': return 11;
- case 'c': case 'C': return 12;
- case 'd': case 'D': return 13;
- case 'e': case 'E': return 14;
- case 'f': case 'F': return 15;
- default: return -1;
- }
-}
-
char* uat_unbinstring(const char* si, guint in_len, guint* len_p) {
guint8* buf;
guint len = in_len/2;
if (len_p) *len_p = len;
while(in_len) {
- d1 = xton(*(si++));
- d0 = xton(*(si++));
+ d1 = ws_xton(*(si++));
+ d0 = ws_xton(*(si++));
buf[i++] = (d1 * 16) + d0;
char c0 = *(s+2);
if (isxdigit((guchar)c1) && isxdigit((guchar)c0)) {
- *(p++) = (xton(c1) * 0x10) + xton(c0);
+ *(p++) = (ws_xton(c1) * 0x10) + ws_xton(c0);
s += 2;
} else {
*(p++) = *s;
#include <ctype.h>
+int
+ws_xton(char ch)
+{
+ switch (ch) {
+ case '0': return 0;
+ case '1': return 1;
+ case '2': return 2;
+ case '3': return 3;
+ case '4': return 4;
+ case '5': return 5;
+ case '6': return 6;
+ case '7': return 7;
+ case '8': return 8;
+ case '9': return 9;
+ case 'a': case 'A': return 10;
+ case 'b': case 'B': return 11;
+ case 'c': case 'C': return 12;
+ case 'd': case 'D': return 13;
+ case 'e': case 'E': return 14;
+ case 'f': case 'F': return 15;
+ default: return -1;
+ }
+}
+
/* Convert all ASCII letters to lower case, in place. */
gchar *
ascii_strdown_inplace(gchar *str)
WS_DLL_PUBLIC
gboolean isdigit_string(guchar *string);
+WS_DLL_PUBLIC
+int ws_xton(char ch);
+
typedef enum {
format_size_unit_none = 0, /**< No unit will be appended. You must supply your own. */
format_size_unit_bytes = 1, /**< "bytes" for un-prefixed sizes, "B" otherwise. */