diff options
author | Guy Harris <guy@alum.mit.edu> | 2015-01-18 02:22:19 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2015-01-18 10:22:59 +0000 |
commit | cfcbb286712ae392689e7cd1a640b57b611dd277 (patch) | |
tree | c41ab4705bb0b790da02bc8b29768b5879543474 /epan/ftypes | |
parent | c60fb3038e4a449c5488a32574d838a6599cb33f (diff) | |
download | wireshark-cfcbb286712ae392689e7cd1a640b57b611dd277.tar.gz |
Clean up ftype-conversion and dfilter error message string handling.
Have dfilter_compile() take an additional gchar ** argument, pointing to
a gchar * item that, on error, gets set to point to a g_malloc()ed error
string. That removes one bit of global state from the display filter
parser, and doesn't impose a fixed limit on the error message strings.
Have fvalue_from_string() and fvalue_from_unparsed() take a gchar **
argument, pointer to a gchar * item, rather than an error-reporting
function, and set the gchar * item to point to a g_malloc()ed error
string on an error.
Allow either gchar ** argument to be null; if the argument is null, no
error message is allocated or provided.
Change-Id: Ibd36b8aaa9bf4234aa6efa1e7fb95f7037493b4c
Reviewed-on: https://code.wireshark.org/review/6608
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/ftypes')
-rw-r--r-- | epan/ftypes/ftype-bytes.c | 137 | ||||
-rw-r--r-- | epan/ftypes/ftype-double.c | 16 | ||||
-rw-r--r-- | epan/ftypes/ftype-guid.c | 5 | ||||
-rw-r--r-- | epan/ftypes/ftype-integer.c | 135 | ||||
-rw-r--r-- | epan/ftypes/ftype-ipv4.c | 15 | ||||
-rw-r--r-- | epan/ftypes/ftype-ipv6.c | 13 | ||||
-rw-r--r-- | epan/ftypes/ftype-pcre.c | 16 | ||||
-rw-r--r-- | epan/ftypes/ftype-string.c | 6 | ||||
-rw-r--r-- | epan/ftypes/ftype-time.c | 16 | ||||
-rw-r--r-- | epan/ftypes/ftype-tvbuff.c | 6 | ||||
-rw-r--r-- | epan/ftypes/ftypes-int.h | 4 | ||||
-rw-r--r-- | epan/ftypes/ftypes.c | 26 | ||||
-rw-r--r-- | epan/ftypes/ftypes.h | 6 |
13 files changed, 221 insertions, 180 deletions
diff --git a/epan/ftypes/ftype-bytes.c b/epan/ftypes/ftype-bytes.c index 75552e9115..fc42f0c9f0 100644 --- a/epan/ftypes/ftype-bytes.c +++ b/epan/ftypes/ftype-bytes.c @@ -232,7 +232,7 @@ value_get(fvalue_t *fv) } static gboolean -bytes_from_string(fvalue_t *fv, const char *s, LogFunc logfunc _U_) +bytes_from_string(fvalue_t *fv, const char *s, gchar **err_msg _U_) { GByteArray *bytes; @@ -248,7 +248,7 @@ bytes_from_string(fvalue_t *fv, const char *s, LogFunc logfunc _U_) } static gboolean -bytes_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, LogFunc logfunc) +bytes_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg) { GByteArray *bytes; gboolean res; @@ -258,8 +258,8 @@ bytes_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U res = hex_str_to_bytes(s, bytes, TRUE); if (!res) { - if (logfunc != NULL) - logfunc("\"%s\" is not a valid byte string.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" is not a valid byte string.", s); g_byte_array_free(bytes, TRUE); return FALSE; } @@ -273,22 +273,26 @@ bytes_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U } static gboolean -ax25_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, LogFunc logfunc) +ax25_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, gchar **err_msg) { /* - * Don't log a message if this fails; we'll try looking it - * up as another way if it does, and if that fails, - * we'll log a message. + * Don't request an error message if bytes_from_unparsed fails; + * if it does, we'll report an error specific to this address + * type. */ if (bytes_from_unparsed(fv, s, TRUE, NULL)) { if (fv->value.bytes->len > FT_AX25_ADDR_LEN) { - logfunc("\"%s\" contains too many bytes to be a valid AX.25 address.", - s); + if (err_msg != NULL) { + *err_msg = g_strdup_printf("\"%s\" contains too many bytes to be a valid AX.25 address.", + s); + } return FALSE; } else if (fv->value.bytes->len < FT_AX25_ADDR_LEN && !allow_partial_value) { - logfunc("\"%s\" contains too few bytes to be a valid AX.25 address.", - s); + if (err_msg != NULL) { + *err_msg = g_strdup_printf("\"%s\" contains too few bytes to be a valid AX.25 address.", + s); + } return FALSE; } @@ -326,27 +330,32 @@ ax25_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, Lo * * http://www.itu.int/ITU-R/terrestrial/docs/fixedmobile/fxm-art19-sec3.pdf */ - logfunc("\"%s\" is not a valid AX.25 address.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" is not a valid AX.25 address.", s); return FALSE; } static gboolean -vines_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, LogFunc logfunc) +vines_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, gchar **err_msg) { /* - * Don't log a message if this fails; we'll try looking it - * up as another way if it does, and if that fails, - * we'll log a message. + * Don't request an error message if bytes_from_unparsed fails; + * if it does, we'll report an error specific to this address + * type. */ if (bytes_from_unparsed(fv, s, TRUE, NULL)) { if (fv->value.bytes->len > FT_VINES_ADDR_LEN) { - logfunc("\"%s\" contains too many bytes to be a valid Vines address.", - s); + if (err_msg != NULL) { + *err_msg = g_strdup_printf("\"%s\" contains too many bytes to be a valid Vines address.", + s); + } return FALSE; } else if (fv->value.bytes->len < FT_VINES_ADDR_LEN && !allow_partial_value) { - logfunc("\"%s\" contains too few bytes to be a valid Vines address.", - s); + if (err_msg != NULL) { + *err_msg = g_strdup_printf("\"%s\" contains too few bytes to be a valid Vines address.", + s); + } return FALSE; } @@ -355,29 +364,34 @@ vines_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, L /* XXX - need better validation of Vines address */ - logfunc("\"%s\" is not a valid Vines address.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" is not a valid Vines address.", s); return FALSE; } static gboolean -ether_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, LogFunc logfunc) +ether_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, gchar **err_msg) { guint8 *mac; /* - * Don't log a message if this fails; we'll try looking it - * up as an Ethernet host name if it does, and if that fails, - * we'll log a message. + * Don't request an error message if bytes_from_unparsed fails; + * if it does, we'll report an error specific to this address + * type. */ if (bytes_from_unparsed(fv, s, TRUE, NULL)) { if (fv->value.bytes->len > FT_ETHER_LEN) { - logfunc("\"%s\" contains too many bytes to be a valid Ethernet address.", - s); + if (err_msg != NULL) { + *err_msg = g_strdup_printf("\"%s\" contains too many bytes to be a valid Ethernet address.", + s); + } return FALSE; } else if (fv->value.bytes->len < FT_ETHER_LEN && !allow_partial_value) { - logfunc("\"%s\" contains too few bytes to be a valid Ethernet address.", - s); + if (err_msg != NULL) { + *err_msg = g_strdup_printf("\"%s\" contains too few bytes to be a valid Ethernet address.", + s); + } return FALSE; } @@ -386,8 +400,10 @@ ether_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, L mac = get_ether_addr(s); if (!mac) { - logfunc("\"%s\" is not a valid hostname or Ethernet address.", - s); + if (err_msg != NULL) { + *err_msg = g_strdup_printf("\"%s\" is not a valid hostname or Ethernet address.", + s); + } return FALSE; } @@ -396,28 +412,29 @@ ether_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, L } static gboolean -oid_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, LogFunc logfunc) +oid_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg) { GByteArray *bytes; gboolean res; +#if 0 /* * Don't log a message if this fails; we'll try looking it * up as an OID if it does, and if that fails, * we'll log a message. */ - /* do not try it as '.' is handled as valid separator for hexbytes :( + /* do not try it as '.' is handled as valid separator for hexbytes :( */ if (bytes_from_unparsed(fv, s, TRUE, NULL)) { return TRUE; } - */ +#endif bytes = g_byte_array_new(); res = oid_str_to_bytes(s, bytes); if (!res) { - if (logfunc != NULL) - logfunc("\"%s\" is not a valid OBJECT IDENTIFIER.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" is not a valid OBJECT IDENTIFIER.", s); g_byte_array_free(bytes, TRUE); return FALSE; } @@ -430,22 +447,16 @@ oid_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, } static gboolean -rel_oid_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, LogFunc logfunc) +rel_oid_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg) { GByteArray *bytes; gboolean res; - - /* - * Don't log a message if this fails; we'll try looking it - * up as an OID if it does, and if that fails, - * we'll log a message. - */ bytes = g_byte_array_new(); res = rel_oid_str_to_bytes(s, bytes, FALSE); if (!res) { - if (logfunc != NULL) - logfunc("\"%s\" is not a valid RELATIVE-OID.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" is not a valid RELATIVE-OID.", s); g_byte_array_free(bytes, TRUE); return FALSE; } @@ -458,17 +469,19 @@ rel_oid_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value } static gboolean -system_id_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, LogFunc logfunc) +system_id_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg) { /* - * Don't log a message if this fails; we'll try looking it - * up as another way if it does, and if that fails, - * we'll log a message. + * Don't request an error message if bytes_from_unparsed fails; + * if it does, we'll report an error specific to this address + * type. */ if (bytes_from_unparsed(fv, s, TRUE, NULL)) { if (fv->value.bytes->len > MAX_SYSTEMID_LEN) { - logfunc("\"%s\" contains too many bytes to be a valid OSI System-ID.", - s); + if (err_msg != NULL) { + *err_msg = g_strdup_printf("\"%s\" contains too many bytes to be a valid OSI System-ID.", + s); + } return FALSE; } @@ -477,22 +490,25 @@ system_id_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_valu /* XXX - need better validation of OSI System-ID address */ - logfunc("\"%s\" is not a valid OSI System-ID.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" is not a valid OSI System-ID.", s); return FALSE; } static gboolean -fcwwn_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, LogFunc logfunc) +fcwwn_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg) { /* - * Don't log a message if this fails; we'll try looking it - * up as another way if it does, and if that fails, - * we'll log a message. + * Don't request an error message if bytes_from_unparsed fails; + * if it does, we'll report an error specific to this address + * type. */ if (bytes_from_unparsed(fv, s, TRUE, NULL)) { if (fv->value.bytes->len > FT_FCWWN_LEN) { - logfunc("\"%s\" contains too many bytes to be a valid FCWWN.", - s); + if (err_msg != NULL) { + *err_msg = g_strdup_printf("\"%s\" contains too many bytes to be a valid FCWWN.", + s); + } return FALSE; } @@ -501,7 +517,8 @@ fcwwn_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U /* XXX - need better validation of FCWWN address */ - logfunc("\"%s\" is not a valid FCWWN.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" is not a valid FCWWN.", s); return FALSE; } diff --git a/epan/ftypes/ftype-double.c b/epan/ftypes/ftype-double.c index ef1991815e..d4778b55ce 100644 --- a/epan/ftypes/ftype-double.c +++ b/epan/ftypes/ftype-double.c @@ -47,7 +47,7 @@ value_get_floating(fvalue_t *fv) } static gboolean -val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, LogFunc logfunc) +val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg) { char *endptr = NULL; @@ -55,19 +55,23 @@ val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, if (endptr == s || *endptr != '\0') { /* This isn't a valid number. */ - logfunc("\"%s\" is not a valid number.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" is not a valid number.", s); return FALSE; } if (errno == ERANGE) { if (fv->value.floating == 0) { - logfunc("\"%s\" causes floating-point underflow.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" causes floating-point underflow.", s); } else if (fv->value.floating == HUGE_VAL) { - logfunc("\"%s\" causes floating-point overflow.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" causes floating-point overflow.", s); } else { - logfunc("\"%s\" is not a valid floating-point number.", - s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" is not a valid floating-point number.", + s); } return FALSE; } diff --git a/epan/ftypes/ftype-guid.c b/epan/ftypes/ftype-guid.c index 290738ae20..20d448d078 100644 --- a/epan/ftypes/ftype-guid.c +++ b/epan/ftypes/ftype-guid.c @@ -84,12 +84,13 @@ get_guid(const char *s, e_guid_t *guid) } static gboolean -guid_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, LogFunc logfunc) +guid_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg) { e_guid_t guid; if (!get_guid(s, &guid)) { - logfunc("\"%s\" is not a valid GUID.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" is not a valid GUID.", s); return FALSE; } diff --git a/epan/ftypes/ftype-integer.c b/epan/ftypes/ftype-integer.c index 7b1e8577e4..7fe8342cb6 100644 --- a/epan/ftypes/ftype-integer.c +++ b/epan/ftypes/ftype-integer.c @@ -62,7 +62,7 @@ get_sinteger(fvalue_t *fv) static gboolean -uint_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, LogFunc logfunc, +uint_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg, guint32 max) { unsigned long value; @@ -73,8 +73,8 @@ uint_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_ * Probably a negative integer, but will be * "converted in the obvious manner" by strtoul(). */ - if (logfunc != NULL) - logfunc("\"%s\" too small for this field, minimum 0.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" too small for this field, minimum 0.", s); return FALSE; } @@ -83,14 +83,14 @@ uint_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_ if (errno == EINVAL || endptr == s || *endptr != '\0') { /* This isn't a valid number. */ - if (logfunc != NULL) - logfunc("\"%s\" is not a valid number.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" is not a valid number.", s); return FALSE; } if (errno == ERANGE) { - if (logfunc != NULL) { + if (err_msg != NULL) { if (value == ULONG_MAX) { - logfunc("\"%s\" causes an integer overflow.", + *err_msg = g_strdup_printf("\"%s\" causes an integer overflow.", s); } else { @@ -98,15 +98,15 @@ uint_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_ * XXX - can "strtoul()" set errno to * ERANGE without returning ULONG_MAX? */ - logfunc("\"%s\" is not an integer.", s); + *err_msg = g_strdup_printf("\"%s\" is not an integer.", s); } } return FALSE; } if (value > max) { - if (logfunc != NULL) - logfunc("\"%s\" too big for this field, maximum %u.", s, max); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" too big for this field, maximum %u.", s, max); return FALSE; } @@ -115,31 +115,31 @@ uint_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_ } static gboolean -uint32_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, LogFunc logfunc) +uint32_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, gchar **err_msg) { - return uint_from_unparsed (fv, s, allow_partial_value, logfunc, G_MAXUINT32); + return uint_from_unparsed (fv, s, allow_partial_value, err_msg, G_MAXUINT32); } static gboolean -uint24_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, LogFunc logfunc) +uint24_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, gchar **err_msg) { - return uint_from_unparsed (fv, s, allow_partial_value, logfunc, 0xFFFFFF); + return uint_from_unparsed (fv, s, allow_partial_value, err_msg, 0xFFFFFF); } static gboolean -uint16_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, LogFunc logfunc) +uint16_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, gchar **err_msg) { - return uint_from_unparsed (fv, s, allow_partial_value, logfunc, G_MAXUINT16); + return uint_from_unparsed (fv, s, allow_partial_value, err_msg, G_MAXUINT16); } static gboolean -uint8_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, LogFunc logfunc) +uint8_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, gchar **err_msg) { - return uint_from_unparsed (fv, s, allow_partial_value, logfunc, G_MAXUINT8); + return uint_from_unparsed (fv, s, allow_partial_value, err_msg, G_MAXUINT8); } static gboolean -sint_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, LogFunc logfunc, +sint_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg, gint32 max, gint32 min) { long value; @@ -150,8 +150,8 @@ sint_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_ * Probably a positive integer > G_MAXINT32, but will be * "converted in the obvious manner" by strtol(). */ - if (logfunc != NULL) - logfunc("\"%s\" causes an integer overflow.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" causes an integer overflow.", s); return FALSE; } @@ -160,37 +160,37 @@ sint_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_ if (errno == EINVAL || endptr == s || *endptr != '\0') { /* This isn't a valid number. */ - if (logfunc != NULL) - logfunc("\"%s\" is not a valid number.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" is not a valid number.", s); return FALSE; } if (errno == ERANGE) { - if (logfunc != NULL) { + if (err_msg != NULL) { if (value == LONG_MAX) { - logfunc("\"%s\" causes an integer overflow.", s); + *err_msg = g_strdup_printf("\"%s\" causes an integer overflow.", s); } else if (value == LONG_MIN) { - logfunc("\"%s\" causes an integer underflow.", s); + *err_msg = g_strdup_printf("\"%s\" causes an integer underflow.", s); } else { /* * XXX - can "strtol()" set errno to * ERANGE without returning ULONG_MAX? */ - logfunc("\"%s\" is not an integer.", s); + *err_msg = g_strdup_printf("\"%s\" is not an integer.", s); } } return FALSE; } if (value > max) { - if (logfunc != NULL) - logfunc("\"%s\" too big for this field, maximum %d.", + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" too big for this field, maximum %d.", s, max); return FALSE; } else if (value < min) { - if (logfunc != NULL) - logfunc("\"%s\" too small for this field, minimum %d.", + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" too small for this field, minimum %d.", s, min); return FALSE; } @@ -200,27 +200,27 @@ sint_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_ } static gboolean -sint32_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, LogFunc logfunc) +sint32_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, gchar **err_msg) { - return sint_from_unparsed (fv, s, allow_partial_value, logfunc, G_MAXINT32, G_MININT32); + return sint_from_unparsed (fv, s, allow_partial_value, err_msg, G_MAXINT32, G_MININT32); } static gboolean -sint24_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, LogFunc logfunc) +sint24_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, gchar **err_msg) { - return sint_from_unparsed (fv, s, allow_partial_value, logfunc, 0x7FFFFF, -0x800000); + return sint_from_unparsed (fv, s, allow_partial_value, err_msg, 0x7FFFFF, -0x800000); } static gboolean -sint16_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, LogFunc logfunc) +sint16_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, gchar **err_msg) { - return sint_from_unparsed (fv, s, allow_partial_value, logfunc, G_MAXINT16, G_MININT16); + return sint_from_unparsed (fv, s, allow_partial_value, err_msg, G_MAXINT16, G_MININT16); } static gboolean -sint8_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, LogFunc logfunc) +sint8_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value, gchar **err_msg) { - return sint_from_unparsed (fv, s, allow_partial_value, logfunc, G_MAXINT8, G_MININT8); + return sint_from_unparsed (fv, s, allow_partial_value, err_msg, G_MAXINT8, G_MININT8); } static int @@ -256,15 +256,15 @@ uinteger_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char * } static gboolean -ipxnet_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, LogFunc logfunc) +ipxnet_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg) { guint32 val; gboolean known; /* - * Don't log a message if this fails; we'll try looking it - * up as an IPX network name if it does, and if that fails, - * we'll log a message. + * Don't request an errror message if uint32_from_unparsed fails; + * if it does, we'll try looking it up as an IPX network name, and + * if that fails, we'll report an error message for that. */ if (uint32_from_unparsed(fv, s, TRUE, NULL)) { return TRUE; @@ -276,7 +276,8 @@ ipxnet_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _ return TRUE; } - logfunc("\"%s\" is not a valid IPX network name or address.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" is not a valid IPX network name or address.", s); return FALSE; } @@ -377,7 +378,7 @@ get_integer64(fvalue_t *fv) } static gboolean -uint64_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, LogFunc logfunc) +uint64_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg) { guint64 value; char *endptr; @@ -387,8 +388,8 @@ uint64_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _ * Probably a negative integer, but will be * "converted in the obvious manner" by g_ascii_strtoull(). */ - if (logfunc != NULL) - logfunc("\"%s\" causes an integer underflow.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" causes an integer underflow.", s); return FALSE; } @@ -397,21 +398,21 @@ uint64_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _ if (errno == EINVAL || endptr == s || *endptr != '\0') { /* This isn't a valid number. */ - if (logfunc != NULL) - logfunc("\"%s\" is not a valid number.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" is not a valid number.", s); return FALSE; } if (errno == ERANGE) { - if (logfunc != NULL) { + if (err_msg != NULL) { if (value == G_MAXUINT64) { - logfunc("\"%s\" causes an integer overflow.", s); + *err_msg = g_strdup_printf("\"%s\" causes an integer overflow.", s); } else { /* * XXX - can "strtoul()" set errno to * ERANGE without returning ULONG_MAX? */ - logfunc("\"%s\" is not an integer.", s); + *err_msg = g_strdup_printf("\"%s\" is not an integer.", s); } } return FALSE; @@ -422,7 +423,7 @@ uint64_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _ } static gboolean -sint64_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, LogFunc logfunc) +sint64_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg) { gint64 value; char *endptr; @@ -432,8 +433,8 @@ sint64_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _ * Probably a positive integer > G_MAXINT64, but will be * "converted in the obvious manner" by g_ascii_strtoll(). */ - if (logfunc != NULL) - logfunc("\"%s\" causes an integer overflow.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" causes an integer overflow.", s); return FALSE; } @@ -442,24 +443,24 @@ sint64_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _ if (errno == EINVAL || endptr == s || *endptr != '\0') { /* This isn't a valid number. */ - if (logfunc != NULL) - logfunc("\"%s\" is not a valid number.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" is not a valid number.", s); return FALSE; } if (errno == ERANGE) { - if (logfunc != NULL) { + if (err_msg != NULL) { if (value == G_MAXINT64) { - logfunc("\"%s\" causes an integer overflow.", s); + *err_msg = g_strdup_printf("\"%s\" causes an integer overflow.", s); } else if (value == G_MININT64) { - logfunc("\"%s\" causes an integer underflow.", s); + *err_msg = g_strdup_printf("\"%s\" causes an integer underflow.", s); } else { /* * XXX - can "strtol()" set errno to * ERANGE without returning LONG_MAX? */ - logfunc("\"%s\" is not an integer.", s); + *err_msg = g_strdup_printf("\"%s\" is not an integer.", s); } } return FALSE; @@ -611,19 +612,19 @@ bool_ne(const fvalue_t *a, const fvalue_t *b) /* EUI64-specific */ static gboolean -eui64_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, LogFunc logfunc) +eui64_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg) { - /* - * Don't log a message if this fails; we'll try looking it - * up as an EUI64 Address if it does, and if that fails, - * we'll log a message. + * Don't request an error message if uint64_from_unparsed fails; + * if it does, we'll report an error specific to this address + * type. */ if (uint64_from_unparsed(fv, s, TRUE, NULL)) { return TRUE; } - logfunc("\"%s\" is not a valid EUI64 Address", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" is not a valid EUI64 Address", s); return FALSE; } diff --git a/epan/ftypes/ftype-ipv4.c b/epan/ftypes/ftype-ipv4.c index d7dada34ea..7f46a35e12 100644 --- a/epan/ftypes/ftype-ipv4.c +++ b/epan/ftypes/ftype-ipv4.c @@ -41,7 +41,7 @@ value_get(fvalue_t *fv) } static gboolean -val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, LogFunc logfunc) +val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg) { guint32 addr; unsigned int nmask_bits; @@ -64,7 +64,10 @@ val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, } if (!get_host_ipaddr(addr_str, &addr)) { - logfunc("\"%s\" is not a valid hostname or IPv4 address.", addr_str); + if (err_msg != NULL) { + *err_msg = g_strdup_printf("\"%s\" is not a valid hostname or IPv4 address.", + addr_str); + } if (free_addr_str) wmem_free(NULL, addr_str); return FALSE; @@ -80,7 +83,7 @@ val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, net_str = has_slash + 1; /* XXX - this is inefficient */ - nmask_fvalue = fvalue_from_unparsed(FT_UINT32, net_str, FALSE, logfunc); + nmask_fvalue = fvalue_from_unparsed(FT_UINT32, net_str, FALSE, err_msg); if (!nmask_fvalue) { return FALSE; } @@ -88,8 +91,10 @@ val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, FVALUE_FREE(nmask_fvalue); if (nmask_bits > 32) { - logfunc("Netmask bits in a CIDR IPv4 address should be <= 32, not %u", - nmask_bits); + if (err_msg != NULL) { + *err_msg = g_strdup_printf("Netmask bits in a CIDR IPv4 address should be <= 32, not %u", + nmask_bits); + } return FALSE; } ipv4_addr_set_netmask_bits(&fv->value.ipv4, nmask_bits); diff --git a/epan/ftypes/ftype-ipv6.c b/epan/ftypes/ftype-ipv6.c index bc72f58144..b69139df11 100644 --- a/epan/ftypes/ftype-ipv6.c +++ b/epan/ftypes/ftype-ipv6.c @@ -34,7 +34,7 @@ ipv6_fvalue_set(fvalue_t *fv, const guint8 *value) } static gboolean -ipv6_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, LogFunc logfunc) +ipv6_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg) { const char *has_slash; char *addr_str; @@ -51,7 +51,8 @@ ipv6_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_ addr_str = (char*)s; if (!get_host_ipaddr6(addr_str, &(fv->value.ipv6.addr))) { - logfunc("\"%s\" is not a valid hostname or IPv6 address.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" is not a valid hostname or IPv6 address.", s); if (free_addr_str) wmem_free(NULL, addr_str); return FALSE; @@ -63,7 +64,7 @@ ipv6_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_ /* If prefix */ if (has_slash) { /* XXX - this is inefficient */ - nmask_fvalue = fvalue_from_unparsed(FT_UINT32, has_slash+1, FALSE, logfunc); + nmask_fvalue = fvalue_from_unparsed(FT_UINT32, has_slash+1, FALSE, err_msg); if (!nmask_fvalue) { return FALSE; } @@ -71,8 +72,10 @@ ipv6_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_ FVALUE_FREE(nmask_fvalue); if (nmask_bits > 128) { - logfunc("Prefix in a IPv6 address should be <= 128, not %u", - nmask_bits); + if (err_msg != NULL) { + *err_msg = g_strdup_printf("Prefix in a IPv6 address should be <= 128, not %u", + nmask_bits); + } return FALSE; } fv->value.ipv6.prefix = nmask_bits; diff --git a/epan/ftypes/ftype-pcre.c b/epan/ftypes/ftype-pcre.c index f324370527..88ecb104d4 100644 --- a/epan/ftypes/ftype-pcre.c +++ b/epan/ftypes/ftype-pcre.c @@ -68,9 +68,10 @@ raw_flag_needed(const gchar *pattern) } /* Generate a FT_PCRE from a parsed string pattern. - * Uses the specified logfunc() to report errors. */ + * On failure, if err_msg is non-null, set *err_msg to point to a + * g_malloc()ed error message. */ static gboolean -val_from_string(fvalue_t *fv, const char *pattern, LogFunc logfunc) +val_from_string(fvalue_t *fv, const char *pattern, gchar **err_msg) { GError *regex_error = NULL; GRegexCompileFlags cflags = G_REGEX_OPTIMIZE; @@ -93,8 +94,8 @@ val_from_string(fvalue_t *fv, const char *pattern, LogFunc logfunc) ); if (regex_error) { - if (logfunc) { - logfunc(regex_error->message); + if (err_msg) { + *err_msg = g_strdup(regex_error->message); } g_error_free(regex_error); if (fv->value.re) { @@ -106,13 +107,14 @@ val_from_string(fvalue_t *fv, const char *pattern, LogFunc logfunc) } /* Generate a FT_PCRE from an unparsed string pattern. - * Uses the specified logfunc() to report errors. */ + * On failure, if err_msg is non-null, set *err_msg to point to a + * g_malloc()ed error message. */ static gboolean -val_from_unparsed(fvalue_t *fv, const char *pattern, gboolean allow_partial_value _U_, LogFunc logfunc) +val_from_unparsed(fvalue_t *fv, const char *pattern, gboolean allow_partial_value _U_, gchar **err_msg) { g_assert(! allow_partial_value); - return val_from_string(fv, pattern, logfunc); + return val_from_string(fv, pattern, err_msg); } static int diff --git a/epan/ftypes/ftype-string.c b/epan/ftypes/ftype-string.c index ff3b9c3c6c..d7d0a0060e 100644 --- a/epan/ftypes/ftype-string.c +++ b/epan/ftypes/ftype-string.c @@ -89,7 +89,7 @@ value_get(fvalue_t *fv) } static gboolean -val_from_string(fvalue_t *fv, const char *s, LogFunc logfunc _U_) +val_from_string(fvalue_t *fv, const char *s, gchar **err_msg _U_) { /* Free up the old value, if we have one */ string_fvalue_free(fv); @@ -99,7 +99,7 @@ val_from_string(fvalue_t *fv, const char *s, LogFunc logfunc _U_) } static gboolean -val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, LogFunc logfunc) +val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg) { fvalue_t *fv_bytes; @@ -123,7 +123,7 @@ val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, } /* Just turn it into a string */ - return val_from_string(fv, s, logfunc); + return val_from_string(fv, s, err_msg); } static guint diff --git a/epan/ftypes/ftype-time.c b/epan/ftypes/ftype-time.c index 09ae23f869..6ee8907142 100644 --- a/epan/ftypes/ftype-time.c +++ b/epan/ftypes/ftype-time.c @@ -168,7 +168,7 @@ get_nsecs(const char *startp, int *nsecs) } static gboolean -relative_val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, LogFunc logfunc) +relative_val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg) { const char *curptr; char *endptr; @@ -227,14 +227,14 @@ relative_val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_v return TRUE; fail: - if (logfunc != NULL) - logfunc("\"%s\" is not a valid time.", s); + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" is not a valid time.", s); return FALSE; } static gboolean -absolute_val_from_string(fvalue_t *fv, const char *s, LogFunc logfunc) +absolute_val_from_string(fvalue_t *fv, const char *s, gchar **err_msg) { struct tm tm; char *curptr; @@ -291,16 +291,16 @@ absolute_val_from_string(fvalue_t *fv, const char *s, LogFunc logfunc) return TRUE; fail: - if (logfunc != NULL) - logfunc("\"%s\" is not a valid absolute time. Example: \"Nov 12, 1999 08:55:44.123\" or \"2011-07-04 12:34:56\"", + if (err_msg != NULL) + *err_msg = g_strdup_printf("\"%s\" is not a valid absolute time. Example: \"Nov 12, 1999 08:55:44.123\" or \"2011-07-04 12:34:56\"", s); return FALSE; } static gboolean -absolute_val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, LogFunc logfunc) +absolute_val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg) { - return absolute_val_from_string(fv, s, logfunc); + return absolute_val_from_string(fv, s, err_msg); } static void diff --git a/epan/ftypes/ftype-tvbuff.c b/epan/ftypes/ftype-tvbuff.c index 714f545dfe..950379a879 100644 --- a/epan/ftypes/ftype-tvbuff.c +++ b/epan/ftypes/ftype-tvbuff.c @@ -61,7 +61,7 @@ free_tvb_data(void *data) } static gboolean -val_from_string(fvalue_t *fv, const char *s, LogFunc logfunc _U_) +val_from_string(fvalue_t *fv, const char *s, gchar **err_msg _U_) { tvbuff_t *new_tvb; guint8 *private_data; @@ -85,7 +85,7 @@ val_from_string(fvalue_t *fv, const char *s, LogFunc logfunc _U_) } static gboolean -val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, LogFunc logfunc) +val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, gchar **err_msg) { fvalue_t *fv_bytes; tvbuff_t *new_tvb; @@ -114,7 +114,7 @@ val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, } /* Treat it as a string. */ - return val_from_string(fv, s, logfunc); + return val_from_string(fv, s, err_msg); } static int diff --git a/epan/ftypes/ftypes-int.h b/epan/ftypes/ftypes-int.h index c2aaf11427..020a571f21 100644 --- a/epan/ftypes/ftypes-int.h +++ b/epan/ftypes/ftypes-int.h @@ -48,8 +48,8 @@ void ftype_register_pcre(void); typedef void (*FvalueNewFunc)(fvalue_t*); typedef void (*FvalueFreeFunc)(fvalue_t*); -typedef gboolean (*FvalueFromUnparsed)(fvalue_t*, const char*, gboolean, LogFunc); -typedef gboolean (*FvalueFromString)(fvalue_t*, const char*, LogFunc); +typedef gboolean (*FvalueFromUnparsed)(fvalue_t*, const char*, gboolean, gchar **); +typedef gboolean (*FvalueFromString)(fvalue_t*, const char*, gchar **); typedef void (*FvalueToStringRepr)(fvalue_t*, ftrepr_t, int field_display, char*volatile); typedef int (*FvalueStringReprLen)(fvalue_t*, ftrepr_t, int field_display); diff --git a/epan/ftypes/ftypes.c b/epan/ftypes/ftypes.c index a06594392c..7f4aba791c 100644 --- a/epan/ftypes/ftypes.c +++ b/epan/ftypes/ftypes.c @@ -288,38 +288,48 @@ fvalue_init(fvalue_t *fv, ftenum_t ftype) } fvalue_t* -fvalue_from_unparsed(ftenum_t ftype, const char *s, gboolean allow_partial_value, LogFunc logfunc) +fvalue_from_unparsed(ftenum_t ftype, const char *s, gboolean allow_partial_value, gchar **err_msg) { fvalue_t *fv; fv = fvalue_new(ftype); if (fv->ftype->val_from_unparsed) { - if (fv->ftype->val_from_unparsed(fv, s, allow_partial_value, logfunc)) { + if (fv->ftype->val_from_unparsed(fv, s, allow_partial_value, err_msg)) { + /* Success */ + if (err_msg != NULL) + *err_msg = NULL; return fv; } } else { - logfunc("\"%s\" cannot be converted to %s.", - s, ftype_pretty_name(ftype)); + if (err_msg != NULL) { + *err_msg = g_strdup_printf("\"%s\" cannot be converted to %s.", + s, ftype_pretty_name(ftype)); + } } FVALUE_FREE(fv); return NULL; } fvalue_t* -fvalue_from_string(ftenum_t ftype, const char *s, LogFunc logfunc) +fvalue_from_string(ftenum_t ftype, const char *s, gchar **err_msg) { fvalue_t *fv; fv = fvalue_new(ftype); if (fv->ftype->val_from_string) { - if (fv->ftype->val_from_string(fv, s, logfunc)) { + if (fv->ftype->val_from_string(fv, s, err_msg)) { + /* Success */ + if (err_msg != NULL) + *err_msg = NULL; return fv; } } else { - logfunc("\"%s\" cannot be converted to %s.", - s, ftype_pretty_name(ftype)); + if (err_msg != NULL) { + *err_msg = g_strdup_printf("\"%s\" cannot be converted to %s.", + s, ftype_pretty_name(ftype)); + } } FVALUE_FREE(fv); return NULL; diff --git a/epan/ftypes/ftypes.h b/epan/ftypes/ftypes.h index 6e969043ca..d830722fc4 100644 --- a/epan/ftypes/ftypes.h +++ b/epan/ftypes/ftypes.h @@ -203,8 +203,6 @@ typedef struct _fvalue_t { } fvalue_t; -typedef void (*LogFunc)(const char*,...); - fvalue_t* fvalue_new(ftenum_t ftype); @@ -213,10 +211,10 @@ fvalue_init(fvalue_t *fv, ftenum_t ftype); WS_DLL_PUBLIC fvalue_t* -fvalue_from_unparsed(ftenum_t ftype, const char *s, gboolean allow_partial_value, LogFunc logfunc); +fvalue_from_unparsed(ftenum_t ftype, const char *s, gboolean allow_partial_value, gchar **err_msg); fvalue_t* -fvalue_from_string(ftenum_t ftype, const char *s, LogFunc logfunc); +fvalue_from_string(ftenum_t ftype, const char *s, gchar **err_msg); /* Returns the length of the string required to hold the * string representation of the the field value. |