diff options
-rw-r--r-- | epan/ftypes/ftype-bytes.c | 158 | ||||
-rw-r--r-- | epan/ftypes/ftype-double.c | 54 | ||||
-rw-r--r-- | epan/ftypes/ftype-guid.c | 19 | ||||
-rw-r--r-- | epan/ftypes/ftype-ieee-11073-float.c | 546 | ||||
-rw-r--r-- | epan/ftypes/ftype-integer.c | 310 | ||||
-rw-r--r-- | epan/ftypes/ftype-ipv4.c | 70 | ||||
-rw-r--r-- | epan/ftypes/ftype-ipv6.c | 47 | ||||
-rw-r--r-- | epan/ftypes/ftype-none.c | 7 | ||||
-rw-r--r-- | epan/ftypes/ftype-protocol.c | 123 | ||||
-rw-r--r-- | epan/ftypes/ftype-string.c | 72 | ||||
-rw-r--r-- | epan/ftypes/ftype-time.c | 75 | ||||
-rw-r--r-- | epan/ftypes/ftypes-int.h | 15 | ||||
-rw-r--r-- | epan/ftypes/ftypes.c | 44 |
13 files changed, 151 insertions, 1389 deletions
diff --git a/epan/ftypes/ftype-bytes.c b/epan/ftypes/ftype-bytes.c index 7072bbaf23..daeb74a826 100644 --- a/epan/ftypes/ftype-bytes.c +++ b/epan/ftypes/ftype-bytes.c @@ -525,101 +525,16 @@ slice(fvalue_t *fv, GByteArray *bytes, guint offset, guint length) g_byte_array_append(bytes, data, length); } - -static gboolean -cmp_eq(const fvalue_t *fv_a, const fvalue_t *fv_b) -{ - GByteArray *a = fv_a->value.bytes; - GByteArray *b = fv_b->value.bytes; - - if (a->len != b->len) { - return FALSE; - } - - return (memcmp(a->data, b->data, a->len) == 0); -} - - -static gboolean -cmp_ne(const fvalue_t *fv_a, const fvalue_t *fv_b) -{ - GByteArray *a = fv_a->value.bytes; - GByteArray *b = fv_b->value.bytes; - - if (a->len != b->len) { - return TRUE; - } - - return (memcmp(a->data, b->data, a->len) != 0); -} - - -static gboolean -cmp_gt(const fvalue_t *fv_a, const fvalue_t *fv_b) -{ - GByteArray *a = fv_a->value.bytes; - GByteArray *b = fv_b->value.bytes; - - if (a->len > b->len) { - return TRUE; - } - - if (a->len < b->len) { - return FALSE; - } - - return (memcmp(a->data, b->data, a->len) > 0); -} - -static gboolean -cmp_ge(const fvalue_t *fv_a, const fvalue_t *fv_b) -{ - GByteArray *a = fv_a->value.bytes; - GByteArray *b = fv_b->value.bytes; - - if (a->len > b->len) { - return TRUE; - } - - if (a->len < b->len) { - return FALSE; - } - - return (memcmp(a->data, b->data, a->len) >= 0); -} - -static gboolean -cmp_lt(const fvalue_t *fv_a, const fvalue_t *fv_b) -{ - GByteArray *a = fv_a->value.bytes; - GByteArray *b = fv_b->value.bytes; - - if (a->len < b->len) { - return TRUE; - } - - if (a->len > b->len) { - return FALSE; - } - - return (memcmp(a->data, b->data, a->len) < 0); -} - -static gboolean -cmp_le(const fvalue_t *fv_a, const fvalue_t *fv_b) +static int +cmp_order(const fvalue_t *fv_a, const fvalue_t *fv_b) { GByteArray *a = fv_a->value.bytes; GByteArray *b = fv_b->value.bytes; - if (a->len < b->len) { - return TRUE; - } - - if (a->len > b->len) { - return FALSE; - } + if (a->len != b->len) + return a->len < b->len ? -1 : 1; - return (memcmp(a->data, b->data, a->len) <= 0); + return memcmp(a->data, b->data, a->len); } static gboolean @@ -694,12 +609,7 @@ ftype_register_bytes(void) { .set_value_byte_array = bytes_fvalue_set }, /* union set_value */ { .get_value_ptr = value_get }, /* union get_value */ - cmp_eq, - cmp_ne, - cmp_gt, - cmp_ge, - cmp_lt, - cmp_le, + cmp_order, cmp_bitwise_and, cmp_contains, CMP_MATCHES, @@ -723,12 +633,7 @@ ftype_register_bytes(void) { .set_value_byte_array = bytes_fvalue_set }, /* union set_value */ { .get_value_ptr = value_get }, /* union get_value */ - cmp_eq, - cmp_ne, - cmp_gt, - cmp_ge, - cmp_lt, - cmp_le, + cmp_order, cmp_bitwise_and, cmp_contains, NULL, /* cmp_matches */ @@ -752,12 +657,7 @@ ftype_register_bytes(void) { .set_value_bytes = ax25_fvalue_set }, /* union set_value */ { .get_value_ptr = value_get }, /* union get_value */ - cmp_eq, - cmp_ne, - cmp_gt, - cmp_ge, - cmp_lt, - cmp_le, + cmp_order, cmp_bitwise_and, cmp_contains, CMP_MATCHES, @@ -781,12 +681,7 @@ ftype_register_bytes(void) { .set_value_bytes = vines_fvalue_set }, /* union set_value */ { .get_value_ptr = value_get }, /* union get_value */ - cmp_eq, - cmp_ne, - cmp_gt, - cmp_ge, - cmp_lt, - cmp_le, + cmp_order, cmp_bitwise_and, cmp_contains, CMP_MATCHES, @@ -810,12 +705,7 @@ ftype_register_bytes(void) { .set_value_bytes = ether_fvalue_set }, /* union set_value */ { .get_value_ptr = value_get }, /* union get_value */ - cmp_eq, - cmp_ne, - cmp_gt, - cmp_ge, - cmp_lt, - cmp_le, + cmp_order, cmp_bitwise_and, cmp_contains, CMP_MATCHES, @@ -839,12 +729,7 @@ ftype_register_bytes(void) { .set_value_byte_array = oid_fvalue_set }, /* union set_value */ { .get_value_ptr = value_get }, /* union get_value */ - cmp_eq, - cmp_ne, - cmp_gt, - cmp_ge, - cmp_lt, - cmp_le, + cmp_order, cmp_bitwise_and, cmp_contains, NULL, /* cmp_matches */ @@ -868,12 +753,7 @@ ftype_register_bytes(void) { .set_value_byte_array = oid_fvalue_set }, /* union set_value */ { .get_value_ptr = value_get }, /* union get_value */ - cmp_eq, - cmp_ne, - cmp_gt, - cmp_ge, - cmp_lt, - cmp_le, + cmp_order, cmp_bitwise_and, cmp_contains, NULL, /* cmp_matches */ @@ -897,12 +777,7 @@ ftype_register_bytes(void) { .set_value_byte_array = system_id_fvalue_set }, /* union set_value */ { .get_value_ptr = value_get }, /* union get_value */ - cmp_eq, - cmp_ne, - cmp_gt, - cmp_ge, - cmp_lt, - cmp_le, + cmp_order, cmp_bitwise_and, cmp_contains, NULL, /* cmp_matches */ @@ -926,12 +801,7 @@ ftype_register_bytes(void) { .set_value_bytes = fcwwn_fvalue_set }, /* union set_value */ { .get_value_ptr = value_get }, /* union get_value */ - cmp_eq, - cmp_ne, - cmp_gt, - cmp_ge, - cmp_lt, - cmp_le, + cmp_order, cmp_bitwise_and, cmp_contains, CMP_MATCHES, diff --git a/epan/ftypes/ftype-double.c b/epan/ftypes/ftype-double.c index 39fcccb28f..bf3ce30418 100644 --- a/epan/ftypes/ftype-double.c +++ b/epan/ftypes/ftype-double.c @@ -91,40 +91,14 @@ double_val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char g_ascii_formatd(buf, size, "%." G_STRINGIFY(DBL_DIG) "g", fv->value.floating); } -static gboolean -cmp_eq(const fvalue_t *a, const fvalue_t *b) -{ - return a->value.floating == b->value.floating; -} - -static gboolean -cmp_ne(const fvalue_t *a, const fvalue_t *b) -{ - return a->value.floating != b->value.floating; -} - -static gboolean -cmp_gt(const fvalue_t *a, const fvalue_t *b) -{ - return a->value.floating > b->value.floating; -} - -static gboolean -cmp_ge(const fvalue_t *a, const fvalue_t *b) -{ - return a->value.floating >= b->value.floating; -} - -static gboolean -cmp_lt(const fvalue_t *a, const fvalue_t *b) -{ - return a->value.floating < b->value.floating; -} - -static gboolean -cmp_le(const fvalue_t *a, const fvalue_t *b) +static int +cmp_order(const fvalue_t *a, const fvalue_t *b) { - return a->value.floating <= b->value.floating; + if (a->value.floating < b->value.floating) + return -1; + if (a->value.floating > b->value.floating) + return 1; + return 0; } void @@ -146,12 +120,7 @@ ftype_register_double(void) { .set_value_floating = double_fvalue_set_floating }, /* union set_value */ { .get_value_floating = value_get_floating }, /* union get_value */ - cmp_eq, - cmp_ne, - cmp_gt, - cmp_ge, - cmp_lt, - cmp_le, + cmp_order, NULL, /* cmp_bitwise_and */ NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -175,12 +144,7 @@ ftype_register_double(void) { .set_value_floating = double_fvalue_set_floating }, /* union set_value */ { .get_value_floating = value_get_floating }, /* union get_value */ - cmp_eq, - cmp_ne, - cmp_gt, - cmp_ge, - cmp_lt, - cmp_le, + cmp_order, NULL, /* cmp_bitwise_and */ NULL, /* cmp_contains */ NULL, /* cmp_matches */ diff --git a/epan/ftypes/ftype-guid.c b/epan/ftypes/ftype-guid.c index 96fb476fb0..648757b161 100644 --- a/epan/ftypes/ftype-guid.c +++ b/epan/ftypes/ftype-guid.c @@ -93,16 +93,10 @@ guid_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, guid_to_str_buf(&fv->value.guid, buf, size); } -static gboolean -cmp_eq(const fvalue_t *a, const fvalue_t *b) -{ - return memcmp(&a->value.guid, &b->value.guid, sizeof(e_guid_t)) == 0; -} - -static gboolean -cmp_ne(const fvalue_t *a, const fvalue_t *b) +static int +cmp_order(const fvalue_t *a, const fvalue_t *b) { - return memcmp(&a->value.guid, &b->value.guid, sizeof(e_guid_t)) != 0; + return memcmp(&a->value.guid, &b->value.guid, sizeof(e_guid_t)); } void @@ -124,12 +118,7 @@ ftype_register_guid(void) { .set_value_guid = guid_fvalue_set_guid }, /* union set_value */ { .get_value_ptr = value_get }, /* union get_value */ - cmp_eq, - cmp_ne, - NULL, - NULL, - NULL, - NULL, + cmp_order, NULL, NULL, NULL, /* cmp_matches */ diff --git a/epan/ftypes/ftype-ieee-11073-float.c b/epan/ftypes/ftype-ieee-11073-float.c index 4f5371f4ab..457fc182e4 100644 --- a/epan/ftypes/ftype-ieee-11073-float.c +++ b/epan/ftypes/ftype-ieee-11073-float.c @@ -358,192 +358,6 @@ sfloat_ieee_11073_cmp_eq(const fvalue_t *a, const fvalue_t *b) } static gboolean -sfloat_ieee_11073_cmp_ne(const fvalue_t *a, const fvalue_t *b) -{ - return sfloat_to_normal_form(a->value.sfloat_ieee_11073) != sfloat_to_normal_form(b->value.sfloat_ieee_11073); -} - -static gboolean -sfloat_ieee_11073_cmp_gt(const fvalue_t *a, const fvalue_t *b) -{ - guint16 a_norm; - guint16 b_norm; - gint16 a_norm_mantissa; - gint16 b_norm_mantissa; - gint8 a_norm_exponent; - gint8 b_norm_exponent; - - a_norm = sfloat_to_normal_form(a->value.sfloat_ieee_11073); - b_norm = sfloat_to_normal_form(b->value.sfloat_ieee_11073); - - if (a_norm == b_norm) - return FALSE; - - switch (a_norm) { - case SFLOAT_VALUE_NAN: - case SFLOAT_VALUE_NRES: - case SFLOAT_VALUE_RFU: - case SFLOAT_VALUE_INFINITY_MINUS: - return FALSE; - case SFLOAT_VALUE_INFINITY_PLUS: - switch (b_norm) { - case SFLOAT_VALUE_NAN: - case SFLOAT_VALUE_NRES: - case SFLOAT_VALUE_RFU: - case SFLOAT_VALUE_INFINITY_PLUS: /* Dead, informative case */ - return FALSE; - case SFLOAT_VALUE_INFINITY_MINUS: - default: - return TRUE; - } - } - - a_norm_mantissa = a_norm & 0x0FFF; - b_norm_mantissa = b_norm & 0x0FFF; - if (a_norm & 0x0800) - a_norm_mantissa |= 0xF000; - - if (b_norm & 0x0800) - b_norm_mantissa |= 0xF000; - - a_norm_exponent = a_norm >> 12; - b_norm_exponent = b_norm >> 12; - - if (a_norm_exponent & 0x08) { - a_norm_exponent |= 0xF0; - } - - if (b_norm_exponent & 0x08) { - b_norm_exponent |= 0xF0; - } - - if (a_norm_mantissa == b_norm_mantissa && a_norm_exponent > b_norm_exponent) - return TRUE; - - if (a_norm_exponent == b_norm_exponent && a_norm_mantissa > b_norm_mantissa) - return TRUE; - - if (a_norm_exponent < b_norm_exponent) { - guint8 exponent_difference; - - exponent_difference = b_norm_exponent - a_norm_exponent; - - if (exponent_difference >= 4) - return FALSE; - - while (exponent_difference--) { - b_norm_mantissa *= 10; - } - } else { - guint8 exponent_difference; - - exponent_difference = a_norm_exponent - b_norm_exponent; - - if (exponent_difference >= 4) - return TRUE; - - while (exponent_difference--) { - a_norm_mantissa *= 10; - } - } - - if (a_norm_mantissa > b_norm_mantissa) - return TRUE; - - return FALSE; -} - -static gboolean -sfloat_ieee_11073_cmp_ge(const fvalue_t *a, const fvalue_t *b) -{ - guint16 a_norm; - guint16 b_norm; - gint16 a_norm_mantissa; - gint16 b_norm_mantissa; - gint8 a_norm_exponent; - gint8 b_norm_exponent; - - a_norm = sfloat_to_normal_form(a->value.sfloat_ieee_11073); - b_norm = sfloat_to_normal_form(b->value.sfloat_ieee_11073); - - if (a_norm == b_norm) - return TRUE; - - switch (a_norm) { - case SFLOAT_VALUE_NAN: - case SFLOAT_VALUE_NRES: - case SFLOAT_VALUE_RFU: - case SFLOAT_VALUE_INFINITY_MINUS: - return FALSE; - case SFLOAT_VALUE_INFINITY_PLUS: - switch (b_norm) { - case SFLOAT_VALUE_NAN: - case SFLOAT_VALUE_NRES: - case SFLOAT_VALUE_RFU: - case SFLOAT_VALUE_INFINITY_PLUS: /* Dead, informative case */ - return FALSE; - case SFLOAT_VALUE_INFINITY_MINUS: - default: - return TRUE; - } - } - - a_norm_mantissa = a_norm & 0x0FFF; - b_norm_mantissa = b_norm & 0x0FFF; - if (a_norm & 0x0800) - a_norm_mantissa |= 0xF000; - - if (b_norm & 0x0800) - b_norm_mantissa |= 0xF000; - - a_norm_exponent = a_norm >> 12; - b_norm_exponent = b_norm >> 12; - - if (a_norm_exponent & 0x08) { - a_norm_exponent |= 0xF0; - } - - if (b_norm_exponent & 0x08) { - b_norm_exponent |= 0xF0; - } - - if (a_norm_mantissa == b_norm_mantissa && a_norm_exponent >= b_norm_exponent) - return TRUE; - - if (a_norm_exponent == b_norm_exponent && a_norm_mantissa >= b_norm_mantissa) - return TRUE; - - if (a_norm_exponent < b_norm_exponent) { - guint8 exponent_difference; - - exponent_difference = b_norm_exponent - a_norm_exponent; - - if (exponent_difference >= 4) - return FALSE; - - while (exponent_difference--) { - b_norm_mantissa *= 10; - } - } else { - guint8 exponent_difference; - - exponent_difference = a_norm_exponent - b_norm_exponent; - - if (exponent_difference >= 4) - return TRUE; - - while (exponent_difference--) { - a_norm_mantissa *= 10; - } - } - - if (a_norm_mantissa > b_norm_mantissa) - return TRUE; - - return FALSE; -} - -static gboolean sfloat_ieee_11073_cmp_lt(const fvalue_t *a, const fvalue_t *b) { guint16 a_norm; @@ -633,94 +447,12 @@ sfloat_ieee_11073_cmp_lt(const fvalue_t *a, const fvalue_t *b) return FALSE; } -static gboolean -sfloat_ieee_11073_cmp_le(const fvalue_t *a, const fvalue_t *b) +static int +sfloat_ieee_11073_cmp_order(const fvalue_t *a, const fvalue_t *b) { - guint16 a_norm; - guint16 b_norm; - gint16 a_norm_mantissa; - gint16 b_norm_mantissa; - gint8 a_norm_exponent; - gint8 b_norm_exponent; - - a_norm = sfloat_to_normal_form(a->value.sfloat_ieee_11073); - b_norm = sfloat_to_normal_form(b->value.sfloat_ieee_11073); - - if (a_norm == b_norm) - return TRUE; - - switch (a_norm) { - case SFLOAT_VALUE_NAN: - case SFLOAT_VALUE_NRES: - case SFLOAT_VALUE_RFU: - case SFLOAT_VALUE_INFINITY_PLUS: - return FALSE; - case SFLOAT_VALUE_INFINITY_MINUS: - switch (b_norm) { - case SFLOAT_VALUE_NAN: - case SFLOAT_VALUE_NRES: - case SFLOAT_VALUE_RFU: - case SFLOAT_VALUE_INFINITY_MINUS: /* Dead, informative case */ - return FALSE; - case SFLOAT_VALUE_INFINITY_PLUS: - default: - return TRUE; - } - } - - a_norm_mantissa = a_norm & 0x0FFF; - b_norm_mantissa = b_norm & 0x0FFF; - if (a_norm & 0x0800) - a_norm_mantissa |= 0xF000; - - if (b_norm & 0x0800) - b_norm_mantissa |= 0xF000; - - a_norm_exponent = a_norm >> 12; - b_norm_exponent = b_norm >> 12; - - if (a_norm_exponent & 0x08) { - a_norm_exponent |= 0xF0; - } - - if (b_norm_exponent & 0x08) { - b_norm_exponent |= 0xF0; - } - - if (a_norm_mantissa == b_norm_mantissa && a_norm_exponent <= b_norm_exponent) - return TRUE; - - if (a_norm_exponent == b_norm_exponent && a_norm_mantissa <= b_norm_mantissa) - return TRUE; - - if (a_norm_exponent < b_norm_exponent) { - guint8 exponent_difference; - - exponent_difference = b_norm_exponent - a_norm_exponent; - - if (exponent_difference >= 4) - return TRUE; - - while (exponent_difference--) { - b_norm_mantissa *= 10; - } - } else { - guint8 exponent_difference; - - exponent_difference = a_norm_exponent - b_norm_exponent; - - if (exponent_difference >= 4) - return FALSE; - - while (exponent_difference--) { - a_norm_mantissa *= 10; - } - } - - if (a_norm_mantissa < b_norm_mantissa) - return TRUE; - - return FALSE; + if (sfloat_ieee_11073_cmp_lt(a, b)) + return -1; + return sfloat_ieee_11073_cmp_eq(a, b) ? 0 : 1; } static gboolean @@ -1046,176 +778,6 @@ float_ieee_11073_cmp_eq(const fvalue_t *a, const fvalue_t *b) } static gboolean -float_ieee_11073_cmp_ne(const fvalue_t *a, const fvalue_t *b) -{ - return float_to_normal_form(a->value.float_ieee_11073) != float_to_normal_form(b->value.float_ieee_11073); -} - -static gboolean -float_ieee_11073_cmp_gt(const fvalue_t *a, const fvalue_t *b) -{ - guint32 a_norm; - guint32 b_norm; - gint32 a_norm_mantissa; - gint32 b_norm_mantissa; - gint8 a_norm_exponent; - gint8 b_norm_exponent; - - a_norm = float_to_normal_form(a->value.float_ieee_11073); - b_norm = float_to_normal_form(b->value.float_ieee_11073); - - if (a_norm == b_norm) - return FALSE; - - switch (a_norm) { - case FLOAT_VALUE_NAN: - case FLOAT_VALUE_NRES: - case FLOAT_VALUE_RFU: - case FLOAT_VALUE_INFINITY_MINUS: - return FALSE; - case FLOAT_VALUE_INFINITY_PLUS: - switch (b_norm) { - case FLOAT_VALUE_NAN: - case FLOAT_VALUE_NRES: - case FLOAT_VALUE_RFU: - case FLOAT_VALUE_INFINITY_PLUS: /* Dead, informative case */ - return FALSE; - case FLOAT_VALUE_INFINITY_MINUS: - default: - return TRUE; - } - } - - a_norm_mantissa = a_norm & 0x00FFFFFF; - b_norm_mantissa = b_norm & 0x00FFFFFF; - if (a_norm & 0x00800000) - a_norm_mantissa |= 0xFF000000; - - if (b_norm & 0x00800000) - b_norm_mantissa |= 0xFF000000; - - a_norm_exponent = a_norm >> 24; - b_norm_exponent = b_norm >> 24; - - if (a_norm_mantissa == b_norm_mantissa && a_norm_exponent > b_norm_exponent) - return TRUE; - - if (a_norm_exponent == b_norm_exponent && a_norm_mantissa > b_norm_mantissa) - return TRUE; - - if (a_norm_exponent < b_norm_exponent) { - guint8 exponent_difference; - - exponent_difference = b_norm_exponent - a_norm_exponent; - - if (exponent_difference >= 7) - return FALSE; - - while (exponent_difference--) { - b_norm_mantissa *= 10; - } - } else { - guint8 exponent_difference; - - exponent_difference = a_norm_exponent - b_norm_exponent; - - if (exponent_difference >= 7) - return TRUE; - - while (exponent_difference--) { - a_norm_mantissa *= 10; - } - } - - if (a_norm_mantissa > b_norm_mantissa) - return TRUE; - - return FALSE; -} - -static gboolean -float_ieee_11073_cmp_ge(const fvalue_t *a, const fvalue_t *b) -{ - guint32 a_norm; - guint32 b_norm; - gint32 a_norm_mantissa; - gint32 b_norm_mantissa; - gint8 a_norm_exponent; - gint8 b_norm_exponent; - - a_norm = float_to_normal_form(a->value.float_ieee_11073); - b_norm = float_to_normal_form(b->value.float_ieee_11073); - - if (a_norm == b_norm) - return TRUE; - - switch (a_norm) { - case FLOAT_VALUE_NAN: - case FLOAT_VALUE_NRES: - case FLOAT_VALUE_RFU: - case FLOAT_VALUE_INFINITY_MINUS: - return FALSE; - case FLOAT_VALUE_INFINITY_PLUS: - switch (b_norm) { - case FLOAT_VALUE_NAN: - case FLOAT_VALUE_NRES: - case FLOAT_VALUE_RFU: - case FLOAT_VALUE_INFINITY_PLUS: /* Dead, informative case */ - return FALSE; - case FLOAT_VALUE_INFINITY_MINUS: - default: - return TRUE; - } - } - - a_norm_mantissa = a_norm & 0x00FFFFFF; - b_norm_mantissa = b_norm & 0x00FFFFFF; - if (a_norm & 0x00800000) - a_norm_mantissa |= 0xFF000000; - - if (b_norm & 0x00800000) - b_norm_mantissa |= 0xFF000000; - - a_norm_exponent = a_norm >> 24; - b_norm_exponent = b_norm >> 24; - - if (a_norm_mantissa == b_norm_mantissa && a_norm_exponent >= b_norm_exponent) - return TRUE; - - if (a_norm_exponent == b_norm_exponent && a_norm_mantissa >= b_norm_mantissa) - return TRUE; - - if (a_norm_exponent < b_norm_exponent) { - guint8 exponent_difference; - - exponent_difference = b_norm_exponent - a_norm_exponent; - - if (exponent_difference >= 7) - return FALSE; - - while (exponent_difference--) { - b_norm_mantissa *= 10; - } - } else { - guint8 exponent_difference; - - exponent_difference = a_norm_exponent - b_norm_exponent; - - if (exponent_difference >= 7) - return TRUE; - - while (exponent_difference--) { - a_norm_mantissa *= 10; - } - } - - if (a_norm_mantissa > b_norm_mantissa) - return TRUE; - - return FALSE; -} - -static gboolean float_ieee_11073_cmp_lt(const fvalue_t *a, const fvalue_t *b) { guint32 a_norm; @@ -1297,86 +859,12 @@ float_ieee_11073_cmp_lt(const fvalue_t *a, const fvalue_t *b) return FALSE; } -static gboolean -float_ieee_11073_cmp_le(const fvalue_t *a, const fvalue_t *b) +static int +float_ieee_11073_cmp_order(const fvalue_t *a, const fvalue_t *b) { - guint32 a_norm; - guint32 b_norm; - gint32 a_norm_mantissa; - gint32 b_norm_mantissa; - gint8 a_norm_exponent; - gint8 b_norm_exponent; - - a_norm = float_to_normal_form(a->value.float_ieee_11073); - b_norm = float_to_normal_form(b->value.float_ieee_11073); - - if (a_norm == b_norm) - return TRUE; - - switch (a_norm) { - case FLOAT_VALUE_NAN: - case FLOAT_VALUE_NRES: - case FLOAT_VALUE_RFU: - case FLOAT_VALUE_INFINITY_PLUS: - return FALSE; - case FLOAT_VALUE_INFINITY_MINUS: - switch (b_norm) { - case FLOAT_VALUE_NAN: - case FLOAT_VALUE_NRES: - case FLOAT_VALUE_RFU: - case FLOAT_VALUE_INFINITY_MINUS: /* Dead, informative case */ - return FALSE; - case FLOAT_VALUE_INFINITY_PLUS: - default: - return TRUE; - } - } - - a_norm_mantissa = a_norm & 0x00FFFFFF; - b_norm_mantissa = b_norm & 0x00FFFFFF; - if (a_norm & 0x00800000) - a_norm_mantissa |= 0xFF000000; - - if (b_norm & 0x00800000) - b_norm_mantissa |= 0xFF000000; - - a_norm_exponent = a_norm >> 24; - b_norm_exponent = b_norm >> 24; - - if (a_norm_mantissa == b_norm_mantissa && a_norm_exponent <= b_norm_exponent) - return TRUE; - - if (a_norm_exponent == b_norm_exponent && a_norm_mantissa <= b_norm_mantissa) - return TRUE; - - if (a_norm_exponent < b_norm_exponent) { - guint8 exponent_difference; - - exponent_difference = b_norm_exponent - a_norm_exponent; - - if (exponent_difference >= 7) - return TRUE; - - while (exponent_difference--) { - b_norm_mantissa *= 10; - } - } else { - guint8 exponent_difference; - - exponent_difference = a_norm_exponent - b_norm_exponent; - - if (exponent_difference >= 7) - return FALSE; - - while (exponent_difference--) { - a_norm_mantissa *= 10; - } - } - - if (a_norm_mantissa < b_norm_mantissa) - return TRUE; - - return FALSE; + if (float_ieee_11073_cmp_lt(a, b)) + return -1; + return float_ieee_11073_cmp_eq(a, b) ? 0 : 1; } static gboolean @@ -1431,12 +919,7 @@ Example: 114 is 0x0072 { .set_value_uinteger = sfloat_ieee_11073_value_set }, /* union set_value */ { .get_value_uinteger = sfloat_ieee_11073_value_get }, /* union get_value */ - sfloat_ieee_11073_cmp_eq, - sfloat_ieee_11073_cmp_ne, - sfloat_ieee_11073_cmp_gt, - sfloat_ieee_11073_cmp_ge, - sfloat_ieee_11073_cmp_lt, - sfloat_ieee_11073_cmp_le, + sfloat_ieee_11073_cmp_order, sfloat_ieee_11073_cmp_bitwise_and, /* cmp_bitwise_and */ NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -1487,12 +970,7 @@ Example: 36.4 is 0xFF00016C { .set_value_uinteger = float_ieee_11073_value_set }, /* union set_value */ { .get_value_uinteger = float_ieee_11073_value_get }, /* union get_value */ - float_ieee_11073_cmp_eq, - float_ieee_11073_cmp_ne, - float_ieee_11073_cmp_gt, - float_ieee_11073_cmp_ge, - float_ieee_11073_cmp_lt, - float_ieee_11073_cmp_le, + float_ieee_11073_cmp_order, float_ieee_11073_cmp_bitwise_and, /* cmp_bitwise_and */ NULL, /* cmp_contains */ NULL, /* cmp_matches */ diff --git a/epan/ftypes/ftype-integer.c b/epan/ftypes/ftype-integer.c index 512bc8a78d..55218c55ee 100644 --- a/epan/ftypes/ftype-integer.c +++ b/epan/ftypes/ftype-integer.c @@ -557,64 +557,36 @@ ipxnet_to_repr(fvalue_t *fv, ftrepr_t rtype, int field_display _U_, char *buf, u uinteger_to_repr(fv, rtype, BASE_HEX, buf, size); } -static gboolean -cmp_eq(const fvalue_t *a, const fvalue_t *b) -{ - return a->value.uinteger == b->value.uinteger; -} - -static gboolean -cmp_ne(const fvalue_t *a, const fvalue_t *b) -{ - return a->value.uinteger != b->value.uinteger; -} - -static gboolean -u_cmp_gt(const fvalue_t *a, const fvalue_t *b) -{ - return a->value.uinteger > b->value.uinteger; -} - -static gboolean -u_cmp_ge(const fvalue_t *a, const fvalue_t *b) -{ - return a->value.uinteger >= b->value.uinteger; -} - -static gboolean -u_cmp_lt(const fvalue_t *a, const fvalue_t *b) -{ - return a->value.uinteger < b->value.uinteger; -} - -static gboolean -u_cmp_le(const fvalue_t *a, const fvalue_t *b) -{ - return a->value.uinteger <= b->value.uinteger; -} - -static gboolean -s_cmp_gt(const fvalue_t *a, const fvalue_t *b) +static int +uinteger_cmp_order(const fvalue_t *a, const fvalue_t *b) { - return a->value.sinteger > b->value.sinteger; + if (a->value.uinteger == b->value.uinteger) + return 0; + return a->value.uinteger < b->value.uinteger ? -1 : 1; } -static gboolean -s_cmp_ge(const fvalue_t *a, const fvalue_t *b) +static int +sinteger_cmp_order(const fvalue_t *a, const fvalue_t *b) { - return a->value.sinteger >= b->value.sinteger; + if (a->value.sinteger == b->value.sinteger) + return 0; + return a->value.sinteger < b->value.sinteger ? -1 : 1; } -static gboolean -s_cmp_lt(const fvalue_t *a, const fvalue_t *b) +static int +uinteger64_cmp_order(const fvalue_t *a, const fvalue_t *b) { - return a->value.sinteger < b->value.sinteger; + if (a->value.uinteger64 == b->value.uinteger64) + return 0; + return a->value.uinteger64 < b->value.uinteger64 ? -1 : 1; } -static gboolean -s_cmp_le(const fvalue_t *a, const fvalue_t *b) +static int +sinteger64_cmp_order(const fvalue_t *a, const fvalue_t *b) { - return a->value.sinteger <= b->value.sinteger; + if (a->value.sinteger64 == b->value.sinteger64) + return 0; + return a->value.sinteger64 < b->value.sinteger64 ? -1 : 1; } static gboolean @@ -857,66 +829,6 @@ uinteger64_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display, char *bu } static gboolean -cmp_eq64(const fvalue_t *a, const fvalue_t *b) -{ - return a->value.uinteger64 == b->value.uinteger64; -} - -static gboolean -cmp_ne64(const fvalue_t *a, const fvalue_t *b) -{ - return a->value.uinteger64 != b->value.uinteger64; -} - -static gboolean -u_cmp_gt64(const fvalue_t *a, const fvalue_t *b) -{ - return a->value.uinteger64 > b->value.uinteger64; -} - -static gboolean -u_cmp_ge64(const fvalue_t *a, const fvalue_t *b) -{ - return a->value.uinteger64 >= b->value.uinteger64; -} - -static gboolean -u_cmp_lt64(const fvalue_t *a, const fvalue_t *b) -{ - return a->value.uinteger64 < b->value.uinteger64; -} - -static gboolean -u_cmp_le64(const fvalue_t *a, const fvalue_t *b) -{ - return a->value.uinteger64 <= b->value.uinteger64; -} - -static gboolean -s_cmp_gt64(const fvalue_t *a, const fvalue_t *b) -{ - return (gint64)a->value.sinteger64 > (gint64)b->value.sinteger64; -} - -static gboolean -s_cmp_ge64(const fvalue_t *a, const fvalue_t *b) -{ - return (gint64)a->value.sinteger64 >= (gint64)b->value.sinteger64; -} - -static gboolean -s_cmp_lt64(const fvalue_t *a, const fvalue_t *b) -{ - return (gint64)a->value.sinteger64 < (gint64)b->value.sinteger64; -} - -static gboolean -s_cmp_le64(const fvalue_t *a, const fvalue_t *b) -{ - return (gint64)a->value.sinteger64 <= (gint64)b->value.sinteger64; -} - -static gboolean cmp_bitwise_and64(const fvalue_t *a, const fvalue_t *b) { return ((a->value.uinteger64 & b->value.uinteger64) != 0); @@ -943,33 +855,26 @@ boolean_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *b *buf = '\0'; } -/* Checks for equality with zero or non-zero */ -static gboolean -bool_eq(const fvalue_t *a, const fvalue_t *b) +/* False is less than True (arbitrary): + * A B cmp(A, B) + * T T 0 + * F F 0 + * F T -1 + * T F 1 + */ +static int +bool_cmp_order(const fvalue_t *a, const fvalue_t *b) { if (a->value.uinteger64) { if (b->value.uinteger64) { - return TRUE; - } - else { - return FALSE; + return 0; } + return 1; } - else { - if (b->value.uinteger64) { - return FALSE; - } - else { - return TRUE; - } + if (b->value.uinteger64) { + return -1; } -} - -/* Checks for inequality with zero or non-zero */ -static gboolean -bool_ne(const fvalue_t *a, const fvalue_t *b) -{ - return (!bool_eq(a,b)); + return 0; } /* EUI64-specific */ @@ -1047,12 +952,7 @@ ftype_register_integers(void) { .set_value_uinteger = set_uinteger }, /* union set_value */ { .get_value_uinteger = get_uinteger }, /* union get_value */ - cmp_eq, - cmp_ne, - u_cmp_gt, - u_cmp_ge, - u_cmp_lt, - u_cmp_le, + uinteger_cmp_order, cmp_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -1075,12 +975,7 @@ ftype_register_integers(void) { .set_value_uinteger = set_uinteger }, /* union set_value */ { .get_value_uinteger = get_uinteger }, /* union get_value */ - cmp_eq, - cmp_ne, - u_cmp_gt, - u_cmp_ge, - u_cmp_lt, - u_cmp_le, + uinteger_cmp_order, cmp_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -1103,12 +998,7 @@ ftype_register_integers(void) { .set_value_uinteger = set_uinteger }, /* union set_value */ { .get_value_uinteger = get_uinteger }, /* union get_value */ - cmp_eq, - cmp_ne, - u_cmp_gt, - u_cmp_ge, - u_cmp_lt, - u_cmp_le, + uinteger_cmp_order, cmp_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -1131,12 +1021,7 @@ ftype_register_integers(void) { .set_value_uinteger = set_uinteger }, /* union set_value */ { .get_value_uinteger = get_uinteger }, /* union get_value */ - cmp_eq, - cmp_ne, - u_cmp_gt, - u_cmp_ge, - u_cmp_lt, - u_cmp_le, + uinteger_cmp_order, cmp_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -1159,12 +1044,7 @@ ftype_register_integers(void) { .set_value_uinteger = set_uinteger }, /* union set_value */ { .get_value_uinteger = get_uinteger }, /* union get_value */ - cmp_eq, - cmp_ne, - u_cmp_gt, - u_cmp_ge, - u_cmp_lt, - u_cmp_le, + uinteger_cmp_order, cmp_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -1187,12 +1067,7 @@ ftype_register_integers(void) { .set_value_uinteger64 = set_uinteger64 }, /* union set_value */ { .get_value_uinteger64 = get_uinteger64 }, /* union get_value */ - cmp_eq64, - cmp_ne64, - u_cmp_gt64, - u_cmp_ge64, - u_cmp_lt64, - u_cmp_le64, + uinteger64_cmp_order, cmp_bitwise_and64, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -1215,12 +1090,7 @@ ftype_register_integers(void) { .set_value_uinteger64 = set_uinteger64 }, /* union set_value */ { .get_value_uinteger64 = get_uinteger64 }, /* union get_value */ - cmp_eq64, - cmp_ne64, - u_cmp_gt64, - u_cmp_ge64, - u_cmp_lt64, - u_cmp_le64, + uinteger64_cmp_order, cmp_bitwise_and64, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -1243,12 +1113,7 @@ ftype_register_integers(void) { .set_value_uinteger64 = set_uinteger64 }, /* union set_value */ { .get_value_uinteger64 = get_uinteger64 }, /* union get_value */ - cmp_eq64, - cmp_ne64, - u_cmp_gt64, - u_cmp_ge64, - u_cmp_lt64, - u_cmp_le64, + uinteger64_cmp_order, cmp_bitwise_and64, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -1271,12 +1136,7 @@ ftype_register_integers(void) { .set_value_uinteger64 = set_uinteger64 }, /* union set_value */ { .get_value_uinteger64 = get_uinteger64 }, /* union get_value */ - cmp_eq64, - cmp_ne64, - u_cmp_gt64, - u_cmp_ge64, - u_cmp_lt64, - u_cmp_le64, + uinteger64_cmp_order, cmp_bitwise_and64, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -1299,12 +1159,7 @@ ftype_register_integers(void) { .set_value_sinteger = set_sinteger }, /* union set_value */ { .get_value_sinteger = get_sinteger }, /* union get_value */ - cmp_eq, - cmp_ne, - s_cmp_gt, - s_cmp_ge, - s_cmp_lt, - s_cmp_le, + sinteger_cmp_order, cmp_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -1327,12 +1182,7 @@ ftype_register_integers(void) { .set_value_sinteger = set_sinteger }, /* union set_value */ { .get_value_sinteger = get_sinteger }, /* union get_value */ - cmp_eq, - cmp_ne, - s_cmp_gt, - s_cmp_ge, - s_cmp_lt, - s_cmp_le, + sinteger_cmp_order, cmp_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -1355,12 +1205,7 @@ ftype_register_integers(void) { .set_value_sinteger = set_sinteger }, /* union set_value */ { .get_value_sinteger = get_sinteger }, /* union get_value */ - cmp_eq, - cmp_ne, - s_cmp_gt, - s_cmp_ge, - s_cmp_lt, - s_cmp_le, + sinteger_cmp_order, cmp_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -1383,12 +1228,7 @@ ftype_register_integers(void) { .set_value_sinteger = set_sinteger }, /* union set_value */ { .get_value_sinteger = get_sinteger }, /* union get_value */ - cmp_eq, - cmp_ne, - s_cmp_gt, - s_cmp_ge, - s_cmp_lt, - s_cmp_le, + sinteger_cmp_order, cmp_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -1411,12 +1251,7 @@ ftype_register_integers(void) { .set_value_sinteger64 = set_sinteger64 }, /* union set_value */ { .get_value_sinteger64 = get_sinteger64 }, /* union get_value */ - cmp_eq64, - cmp_ne64, - s_cmp_gt64, - s_cmp_ge64, - s_cmp_lt64, - s_cmp_le64, + sinteger64_cmp_order, cmp_bitwise_and64, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -1439,12 +1274,7 @@ ftype_register_integers(void) { .set_value_sinteger64 = set_sinteger64 }, /* union set_value */ { .get_value_sinteger64 = get_sinteger64 }, /* union get_value */ - cmp_eq64, - cmp_ne64, - s_cmp_gt64, - s_cmp_ge64, - s_cmp_lt64, - s_cmp_le64, + sinteger64_cmp_order, cmp_bitwise_and64, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -1467,12 +1297,7 @@ ftype_register_integers(void) { .set_value_sinteger64 = set_sinteger64 }, /* union set_value */ { .get_value_sinteger64 = get_sinteger64 }, /* union get_value */ - cmp_eq64, - cmp_ne64, - s_cmp_gt64, - s_cmp_ge64, - s_cmp_lt64, - s_cmp_le64, + sinteger64_cmp_order, cmp_bitwise_and64, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -1495,12 +1320,7 @@ ftype_register_integers(void) { .set_value_sinteger64 = set_sinteger64 }, /* union set_value */ { .get_value_sinteger64 = get_sinteger64 }, /* union get_value */ - cmp_eq64, - cmp_ne64, - s_cmp_gt64, - s_cmp_ge64, - s_cmp_lt64, - s_cmp_le64, + sinteger64_cmp_order, cmp_bitwise_and64, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -1523,12 +1343,7 @@ ftype_register_integers(void) { .set_value_uinteger64 = set_uinteger64 }, /* union set_value */ { .get_value_uinteger64 = get_uinteger64 }, /* union get_value */ - bool_eq, /* cmp_eq */ - bool_ne, /* cmp_ne */ - NULL, /* cmp_gt */ - NULL, /* cmp_ge */ - NULL, /* cmp_lt */ - NULL, /* cmp_le */ + bool_cmp_order, /* cmp_eq */ NULL, /* cmp_bitwise_and */ NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -1552,12 +1367,7 @@ ftype_register_integers(void) { .set_value_uinteger = set_uinteger }, /* union set_value */ { .get_value_uinteger = get_uinteger }, /* union get_value */ - cmp_eq, - cmp_ne, - u_cmp_gt, - u_cmp_ge, - u_cmp_lt, - u_cmp_le, + uinteger_cmp_order, cmp_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -1581,12 +1391,7 @@ ftype_register_integers(void) { .set_value_uinteger = set_uinteger }, /* union set_value */ { .get_value_uinteger = get_uinteger }, /* union get_value */ - cmp_eq, - cmp_ne, - u_cmp_gt, - u_cmp_ge, - u_cmp_lt, - u_cmp_le, + uinteger_cmp_order, NULL, /* cmp_bitwise_and */ NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -1610,12 +1415,7 @@ ftype_register_integers(void) { .set_value_uinteger64 = set_uinteger64 }, /* union set_value */ { .get_value_uinteger64 = get_uinteger64 }, /* union get_value */ - cmp_eq64, - cmp_ne64, - u_cmp_gt64, - u_cmp_ge64, - u_cmp_lt64, - u_cmp_le64, + uinteger64_cmp_order, cmp_bitwise_and64, NULL, /* cmp_contains */ NULL, /* cmp_matches */ diff --git a/epan/ftypes/ftype-ipv4.c b/epan/ftypes/ftype-ipv4.c index b2ba0b6a3b..f558e795b9 100644 --- a/epan/ftypes/ftype-ipv4.c +++ b/epan/ftypes/ftype-ipv4.c @@ -119,70 +119,17 @@ val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, * So, for example, w.x.y.z/32 eq w.x.y.0/24 is TRUE. */ -static gboolean -cmp_eq(const fvalue_t *fv_a, const fvalue_t *fv_b) -{ - guint32 addr_a, addr_b, nmask; - - nmask = MIN(fv_a->value.ipv4.nmask, fv_b->value.ipv4.nmask); - addr_a = fv_a->value.ipv4.addr & nmask; - addr_b = fv_b->value.ipv4.addr & nmask; - return (addr_a == addr_b); -} - -static gboolean -cmp_ne(const fvalue_t *fv_a, const fvalue_t *fv_b) -{ - guint32 addr_a, addr_b, nmask; - - nmask = MIN(fv_a->value.ipv4.nmask, fv_b->value.ipv4.nmask); - addr_a = fv_a->value.ipv4.addr & nmask; - addr_b = fv_b->value.ipv4.addr & nmask; - return (addr_a != addr_b); -} - -static gboolean -cmp_gt(const fvalue_t *fv_a, const fvalue_t *fv_b) -{ - guint32 addr_a, addr_b, nmask; - - nmask = MIN(fv_a->value.ipv4.nmask, fv_b->value.ipv4.nmask); - addr_a = fv_a->value.ipv4.addr & nmask; - addr_b = fv_b->value.ipv4.addr & nmask; - return (addr_a > addr_b); -} - -static gboolean -cmp_ge(const fvalue_t *fv_a, const fvalue_t *fv_b) -{ - guint32 addr_a, addr_b, nmask; - - nmask = MIN(fv_a->value.ipv4.nmask, fv_b->value.ipv4.nmask); - addr_a = fv_a->value.ipv4.addr & nmask; - addr_b = fv_b->value.ipv4.addr & nmask; - return (addr_a >= addr_b); -} - -static gboolean -cmp_lt(const fvalue_t *fv_a, const fvalue_t *fv_b) -{ - guint32 addr_a, addr_b, nmask; - - nmask = MIN(fv_a->value.ipv4.nmask, fv_b->value.ipv4.nmask); - addr_a = fv_a->value.ipv4.addr & nmask; - addr_b = fv_b->value.ipv4.addr & nmask; - return (addr_a < addr_b); -} - -static gboolean -cmp_le(const fvalue_t *fv_a, const fvalue_t *fv_b) +static int +cmp_order(const fvalue_t *fv_a, const fvalue_t *fv_b) { guint32 addr_a, addr_b, nmask; nmask = MIN(fv_a->value.ipv4.nmask, fv_b->value.ipv4.nmask); addr_a = fv_a->value.ipv4.addr & nmask; addr_b = fv_b->value.ipv4.addr & nmask; - return (addr_a <= addr_b); + if (addr_a == addr_b) + return 0; + return addr_a < addr_b ? -1 : 1; } static gboolean @@ -224,12 +171,7 @@ ftype_register_ipv4(void) { .set_value_uinteger = set_uinteger }, /* union set_value */ { .get_value_uinteger = value_get }, /* union get_value */ - cmp_eq, - cmp_ne, - cmp_gt, - cmp_ge, - cmp_lt, - cmp_le, + cmp_order, cmp_bitwise_and, NULL, /* cmp_contains */ NULL, /* cmp_matches */ diff --git a/epan/ftypes/ftype-ipv6.c b/epan/ftypes/ftype-ipv6.c index 8b00c4e4f7..63a20cb54e 100644 --- a/epan/ftypes/ftype-ipv6.c +++ b/epan/ftypes/ftype-ipv6.c @@ -100,8 +100,8 @@ value_get(fvalue_t *fv) static const guint8 bitmasks[9] = { 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff }; -static gint -cmp_compare(const fvalue_t *fv_a, const fvalue_t *fv_b) +static int +cmp_order(const fvalue_t *fv_a, const fvalue_t *fv_b) { const ipv6_addr_and_prefix *a = &(fv_a->value.ipv6); const ipv6_addr_and_prefix *b = &(fv_b->value.ipv6); @@ -133,42 +133,6 @@ cmp_compare(const fvalue_t *fv_a, const fvalue_t *fv_b) } static gboolean -cmp_eq(const fvalue_t *fv_a, const fvalue_t *fv_b) -{ - return (cmp_compare(fv_a, fv_b) == 0); -} - -static gboolean -cmp_ne(const fvalue_t *fv_a, const fvalue_t *fv_b) -{ - return (cmp_compare(fv_a, fv_b) != 0); -} - -static gboolean -cmp_gt(const fvalue_t *fv_a, const fvalue_t *fv_b) -{ - return (cmp_compare(fv_a, fv_b) > 0); -} - -static gboolean -cmp_ge(const fvalue_t *fv_a, const fvalue_t *fv_b) -{ - return (cmp_compare(fv_a, fv_b) >= 0); -} - -static gboolean -cmp_lt(const fvalue_t *fv_a, const fvalue_t *fv_b) -{ - return (cmp_compare(fv_a, fv_b) < 0); -} - -static gboolean -cmp_le(const fvalue_t *fv_a, const fvalue_t *fv_b) -{ - return (cmp_compare(fv_a, fv_b) <= 0); -} - -static gboolean cmp_bitwise_and(const fvalue_t *fv_a, const fvalue_t *fv_b) { const ipv6_addr_and_prefix *a = &(fv_a->value.ipv6); @@ -225,12 +189,7 @@ ftype_register_ipv6(void) { .set_value_bytes = ipv6_fvalue_set }, /* union set_value */ { .get_value_ptr = value_get }, /* union get_value */ - cmp_eq, - cmp_ne, - cmp_gt, - cmp_ge, - cmp_lt, - cmp_le, + cmp_order, cmp_bitwise_and, NULL, /* XXX, cmp_contains, needed? ipv4 doesn't support it */ NULL, /* cmp_matches */ diff --git a/epan/ftypes/ftype-none.c b/epan/ftypes/ftype-none.c index 13ffa7774e..c504cf7600 100644 --- a/epan/ftypes/ftype-none.c +++ b/epan/ftypes/ftype-none.c @@ -30,12 +30,7 @@ ftype_register_none(void) { NULL }, /* union set_value */ { NULL }, /* union get_value */ - NULL, /* cmp_eq */ - NULL, /* cmp_ne */ - NULL, /* cmp_gt */ - NULL, /* cmp_ge */ - NULL, /* cmp_lt */ - NULL, /* cmp_le */ + NULL, /* cmp_order */ NULL, /* cmp_bitwise_and */ NULL, /* cmp_contains */ NULL, /* cmp_matches */ diff --git a/epan/ftypes/ftype-protocol.c b/epan/ftypes/ftype-protocol.c index 21d39b0454..fd6c89cc2a 100644 --- a/epan/ftypes/ftype-protocol.c +++ b/epan/ftypes/ftype-protocol.c @@ -224,89 +224,6 @@ cmp_eq(const fvalue_t *fv_a, const fvalue_t *fv_b) } static gboolean -cmp_ne(const fvalue_t *fv_a, const fvalue_t *fv_b) -{ - const protocol_value_t *a = (const protocol_value_t *)&fv_a->value.protocol; - const protocol_value_t *b = (const protocol_value_t *)&fv_b->value.protocol; - volatile gboolean ne = TRUE; - - TRY { - if ((a->tvb != NULL) && (b->tvb != NULL)) { - guint a_len = tvb_captured_length(a->tvb); - - if (a_len == tvb_captured_length(b->tvb)) - ne = (memcmp(tvb_get_ptr(a->tvb, 0, a_len), tvb_get_ptr(b->tvb, 0, a_len), a_len) != 0); - } else { - ne = (strcmp(a->proto_string, b->proto_string) != 0); - } - } - CATCH_ALL { - /* nothing */ - } - ENDTRY; - - return ne; -} - -static gboolean -cmp_gt(const fvalue_t *fv_a, const fvalue_t *fv_b) -{ - const protocol_value_t *a = (const protocol_value_t *)&fv_a->value.protocol; - const protocol_value_t *b = (const protocol_value_t *)&fv_b->value.protocol; - volatile gboolean gt = FALSE; - - TRY { - if ((a->tvb != NULL) && (b->tvb != NULL)) { - guint a_len = tvb_captured_length(a->tvb); - guint b_len = tvb_captured_length(b->tvb); - - if (a_len > b_len) { - gt = TRUE; - } else if (a_len == b_len) { - gt = (memcmp(tvb_get_ptr(a->tvb, 0, a_len), tvb_get_ptr(b->tvb, 0, a_len), a_len) > 0); - } - } else { - gt = (strcmp(a->proto_string, b->proto_string) > 0); - } - } - CATCH_ALL { - /* nothing */ - } - ENDTRY; - - return gt; -} - -static gboolean -cmp_ge(const fvalue_t *fv_a, const fvalue_t *fv_b) -{ - const protocol_value_t *a = (const protocol_value_t *)&fv_a->value.protocol; - const protocol_value_t *b = (const protocol_value_t *)&fv_b->value.protocol; - volatile gboolean ge = FALSE; - - TRY { - if ((a->tvb != NULL) && (b->tvb != NULL)) { - guint a_len = tvb_captured_length(a->tvb); - guint b_len = tvb_captured_length(b->tvb); - - if (a_len > b_len) { - ge = TRUE; - } else if (a_len == b_len) { - ge = (memcmp(tvb_get_ptr(a->tvb, 0, a_len), tvb_get_ptr(b->tvb, 0, a_len), a_len) >= 0); - } - } else { - ge = (strcmp(a->proto_string, b->proto_string) >= 0); - } - } - CATCH_ALL { - /* nothing */ - } - ENDTRY; - - return ge; -} - -static gboolean cmp_lt(const fvalue_t *fv_a, const fvalue_t *fv_b) { const protocol_value_t *a = (const protocol_value_t *)&fv_a->value.protocol; @@ -335,33 +252,14 @@ cmp_lt(const fvalue_t *fv_a, const fvalue_t *fv_b) return lt; } -static gboolean -cmp_le(const fvalue_t *fv_a, const fvalue_t *fv_b) +static int +cmp_order(const fvalue_t *fv_a, const fvalue_t *fv_b) { - const protocol_value_t *a = (const protocol_value_t *)&fv_a->value.protocol; - const protocol_value_t *b = (const protocol_value_t *)&fv_b->value.protocol; - volatile gboolean le = FALSE; - - TRY { - if ((a->tvb != NULL) && (b->tvb != NULL)) { - guint a_len = tvb_captured_length(a->tvb); - guint b_len = tvb_captured_length(b->tvb); - - if (a_len < b_len) { - le = TRUE; - } else if (a_len == b_len) { - le = (memcmp(tvb_get_ptr(a->tvb, 0, a_len), tvb_get_ptr(b->tvb, 0, a_len), a_len) <= 0); - } - } else { - le = (strcmp(a->proto_string, b->proto_string) <= 0); - } - } - CATCH_ALL { - /* nothing */ - } - ENDTRY; - - return le; + if (cmp_lt(fv_a, fv_b)) + return -1; + if (cmp_eq(fv_a, fv_b)) + return 0; + return 1; } static gboolean @@ -454,12 +352,7 @@ ftype_register_tvbuff(void) { .set_value_protocol = value_set }, /* union set_value */ { .get_value_ptr = value_get }, /* union get_value */ - cmp_eq, - cmp_ne, - cmp_gt, - cmp_ge, - cmp_lt, - cmp_le, + cmp_order, NULL, /* cmp_bitwise_and */ cmp_contains, CMP_MATCHES, diff --git a/epan/ftypes/ftype-string.c b/epan/ftypes/ftype-string.c index 3ab7740cb5..28d5636fab 100644 --- a/epan/ftypes/ftype-string.c +++ b/epan/ftypes/ftype-string.c @@ -130,41 +130,10 @@ slice(fvalue_t *fv, GByteArray *bytes, guint offset, guint length) g_byte_array_append(bytes, data, length); } - -static gboolean -cmp_eq(const fvalue_t *a, const fvalue_t *b) -{ - return (strcmp(a->value.string, b->value.string) == 0); -} - -static gboolean -cmp_ne(const fvalue_t *a, const fvalue_t *b) -{ - return (strcmp(a->value.string, b->value.string) != 0); -} - -static gboolean -cmp_gt(const fvalue_t *a, const fvalue_t *b) -{ - return (strcmp(a->value.string, b->value.string) > 0); -} - -static gboolean -cmp_ge(const fvalue_t *a, const fvalue_t *b) -{ - return (strcmp(a->value.string, b->value.string) >= 0); -} - -static gboolean -cmp_lt(const fvalue_t *a, const fvalue_t *b) -{ - return (strcmp(a->value.string, b->value.string) < 0); -} - -static gboolean -cmp_le(const fvalue_t *a, const fvalue_t *b) +static int +cmp_order(const fvalue_t *a, const fvalue_t *b) { - return (strcmp(a->value.string, b->value.string) <= 0); + return strcmp(a->value.string, b->value.string); } static gboolean @@ -224,12 +193,7 @@ ftype_register_string(void) { .set_value_string = string_fvalue_set_string }, /* union set_value */ { .get_value_ptr = value_get }, /* union get_value */ - cmp_eq, - cmp_ne, - cmp_gt, - cmp_ge, - cmp_lt, - cmp_le, + cmp_order, NULL, /* cmp_bitwise_and */ cmp_contains, CMP_MATCHES, @@ -252,12 +216,7 @@ ftype_register_string(void) { .set_value_string = string_fvalue_set_string }, /* union set_value */ { .get_value_ptr = value_get }, /* union get_value */ - cmp_eq, - cmp_ne, - cmp_gt, - cmp_ge, - cmp_lt, - cmp_le, + cmp_order, NULL, /* cmp_bitwise_and */ cmp_contains, /* cmp_contains */ CMP_MATCHES, @@ -280,12 +239,7 @@ ftype_register_string(void) { .set_value_string = string_fvalue_set_string }, /* union set_value */ { .get_value_ptr = value_get }, /* union get_value */ - cmp_eq, - cmp_ne, - cmp_gt, - cmp_ge, - cmp_lt, - cmp_le, + cmp_order, NULL, /* cmp_bitwise_and */ cmp_contains, /* cmp_contains */ CMP_MATCHES, @@ -308,12 +262,7 @@ ftype_register_string(void) { .set_value_string = string_fvalue_set_string }, /* union set_value */ { .get_value_ptr = value_get }, /* union get_value */ - cmp_eq, - cmp_ne, - cmp_gt, - cmp_ge, - cmp_lt, - cmp_le, + cmp_order, NULL, /* cmp_bitwise_and */ cmp_contains, /* cmp_contains */ CMP_MATCHES, @@ -336,12 +285,7 @@ ftype_register_string(void) { .set_value_string = string_fvalue_set_string }, /* union set_value */ { .get_value_ptr = value_get }, /* union get_value */ - cmp_eq, - cmp_ne, - cmp_gt, - cmp_ge, - cmp_lt, - cmp_le, + cmp_order, NULL, /* cmp_bitwise_and */ cmp_contains, /* cmp_contains */ CMP_MATCHES, diff --git a/epan/ftypes/ftype-time.c b/epan/ftypes/ftype-time.c index 2181a951a7..c900617792 100644 --- a/epan/ftypes/ftype-time.c +++ b/epan/ftypes/ftype-time.c @@ -30,68 +30,13 @@ #include "wsutil/strptime.h" #endif -static gboolean -cmp_eq(const fvalue_t *a, const fvalue_t *b) -{ - return ((a->value.time.secs) ==(b->value.time.secs)) - &&((a->value.time.nsecs)==(b->value.time.nsecs)); -} -static gboolean -cmp_ne(const fvalue_t *a, const fvalue_t *b) -{ - return (a->value.time.secs !=b->value.time.secs) - ||(a->value.time.nsecs!=b->value.time.nsecs); -} -static gboolean -cmp_gt(const fvalue_t *a, const fvalue_t *b) -{ - if (a->value.time.secs > b->value.time.secs) { - return TRUE; - } - if (a->value.time.secs < b->value.time.secs) { - return FALSE; - } - return a->value.time.nsecs > b->value.time.nsecs; -} -static gboolean -cmp_ge(const fvalue_t *a, const fvalue_t *b) -{ - if (a->value.time.secs > b->value.time.secs) { - return TRUE; - } - if (a->value.time.secs < b->value.time.secs) { - return FALSE; - } - - return a->value.time.nsecs >= b->value.time.nsecs; -} -static gboolean -cmp_lt(const fvalue_t *a, const fvalue_t *b) -{ - if (a->value.time.secs < b->value.time.secs) { - return TRUE; - } - if (a->value.time.secs > b->value.time.secs) { - return FALSE; - } - - return a->value.time.nsecs < b->value.time.nsecs; -} -static gboolean -cmp_le(const fvalue_t *a, const fvalue_t *b) +static int +cmp_order(const fvalue_t *a, const fvalue_t *b) { - if (a->value.time.secs < b->value.time.secs) { - return TRUE; - } - if (a->value.time.secs > b->value.time.secs) { - return FALSE; - } - - return a->value.time.nsecs <= b->value.time.nsecs; + return nstime_cmp(&(a->value.time), &(b->value.time)); } - /* * Get a nanoseconds value, starting at "p". * @@ -451,12 +396,7 @@ ftype_register_time(void) { .set_value_time = time_fvalue_set }, /* union set_value */ { .get_value_ptr = value_get }, /* union get_value */ - cmp_eq, - cmp_ne, - cmp_gt, - cmp_ge, - cmp_lt, - cmp_le, + cmp_order, NULL, /* cmp_bitwise_and */ NULL, /* cmp_contains */ NULL, /* cmp_matches */ @@ -479,12 +419,7 @@ ftype_register_time(void) { .set_value_time = time_fvalue_set }, /* union set_value */ { .get_value_ptr = value_get }, /* union get_value */ - cmp_eq, - cmp_ne, - cmp_gt, - cmp_ge, - cmp_lt, - cmp_le, + cmp_order, NULL, /* cmp_bitwise_and */ NULL, /* cmp_contains */ NULL, /* cmp_matches */ diff --git a/epan/ftypes/ftypes-int.h b/epan/ftypes/ftypes-int.h index 98af5997c2..6b1300e53f 100644 --- a/epan/ftypes/ftypes-int.h +++ b/epan/ftypes/ftypes-int.h @@ -61,7 +61,9 @@ typedef guint64 (*FvalueGetUnsignedInteger64Func)(fvalue_t*); typedef gint64 (*FvalueGetSignedInteger64Func)(fvalue_t*); typedef double (*FvalueGetFloatingFunc)(fvalue_t*); -typedef gboolean (*FvalueCmp)(const fvalue_t*, const fvalue_t*); +typedef int (*FvalueCmp)(const fvalue_t*, const fvalue_t*); +typedef gboolean (*FvalueBitwiseAnd)(const fvalue_t*, const fvalue_t*); +typedef gboolean (*FvalueContains)(const fvalue_t*, const fvalue_t*); typedef gboolean (*FvalueMatches)(const fvalue_t*, const GRegex*); typedef guint (*FvalueLen)(fvalue_t*); @@ -102,14 +104,9 @@ struct _ftype_t { FvalueGetFloatingFunc get_value_floating; } get_value; - FvalueCmp cmp_eq; - FvalueCmp cmp_ne; - FvalueCmp cmp_gt; - FvalueCmp cmp_ge; - FvalueCmp cmp_lt; - FvalueCmp cmp_le; - FvalueCmp cmp_bitwise_and; - FvalueCmp cmp_contains; + FvalueCmp cmp_order; + FvalueBitwiseAnd cmp_bitwise_and; + FvalueContains cmp_contains; FvalueMatches cmp_matches; FvalueLen len; diff --git a/epan/ftypes/ftypes.c b/epan/ftypes/ftypes.c index 52d3217a67..e10a38513d 100644 --- a/epan/ftypes/ftypes.c +++ b/epan/ftypes/ftypes.c @@ -173,7 +173,7 @@ ftype_can_eq(enum ftenum ftype) ftype_t *ft; FTYPE_LOOKUP(ftype, ft); - return ft->cmp_eq ? TRUE : FALSE; + return ft->cmp_order != NULL; } gboolean @@ -182,7 +182,7 @@ ftype_can_ne(enum ftenum ftype) ftype_t *ft; FTYPE_LOOKUP(ftype, ft); - return ft->cmp_ne ? TRUE : FALSE; + return ft->cmp_order != NULL; } gboolean @@ -191,7 +191,7 @@ ftype_can_gt(enum ftenum ftype) ftype_t *ft; FTYPE_LOOKUP(ftype, ft); - return ft->cmp_gt ? TRUE : FALSE; + return ft->cmp_order != NULL; } gboolean @@ -200,7 +200,7 @@ ftype_can_ge(enum ftenum ftype) ftype_t *ft; FTYPE_LOOKUP(ftype, ft); - return ft->cmp_ge ? TRUE : FALSE; + return ft->cmp_order != NULL; } gboolean @@ -209,7 +209,7 @@ ftype_can_lt(enum ftenum ftype) ftype_t *ft; FTYPE_LOOKUP(ftype, ft); - return ft->cmp_lt ? TRUE : FALSE; + return ft->cmp_order != NULL; } gboolean @@ -218,7 +218,7 @@ ftype_can_le(enum ftenum ftype) ftype_t *ft; FTYPE_LOOKUP(ftype, ft); - return ft->cmp_le ? TRUE : FALSE; + return ft->cmp_order != NULL; } gboolean @@ -686,52 +686,48 @@ fvalue_get_floating(fvalue_t *fv) return fv->ftype->get_value.get_value_floating(fv); } +static inline int +_fvalue_cmp(const fvalue_t *a, const fvalue_t *b) +{ + /* XXX - check compatibility of a and b */ + ws_assert(a->ftype->cmp_order); + return a->ftype->cmp_order(a, b); +} + gboolean fvalue_eq(const fvalue_t *a, const fvalue_t *b) { - /* XXX - check compatibility of a and b */ - ws_assert(a->ftype->cmp_eq); - return a->ftype->cmp_eq(a, b); + return _fvalue_cmp(a, b) == 0; } gboolean fvalue_ne(const fvalue_t *a, const fvalue_t *b) { - /* XXX - check compatibility of a and b */ - ws_assert(a->ftype->cmp_ne); - return a->ftype->cmp_ne(a, b); + return _fvalue_cmp(a, b) != 0; } gboolean fvalue_gt(const fvalue_t *a, const fvalue_t *b) { - /* XXX - check compatibility of a and b */ - ws_assert(a->ftype->cmp_gt); - return a->ftype->cmp_gt(a, b); + return _fvalue_cmp(a, b) > 0; } gboolean fvalue_ge(const fvalue_t *a, const fvalue_t *b) { - /* XXX - check compatibility of a and b */ - ws_assert(a->ftype->cmp_ge); - return a->ftype->cmp_ge(a, b); + return _fvalue_cmp(a, b) >= 0; } gboolean fvalue_lt(const fvalue_t *a, const fvalue_t *b) { - /* XXX - check compatibility of a and b */ - ws_assert(a->ftype->cmp_lt); - return a->ftype->cmp_lt(a, b); + return _fvalue_cmp(a, b) < 0; } gboolean fvalue_le(const fvalue_t *a, const fvalue_t *b) { - /* XXX - check compatibility of a and b */ - ws_assert(a->ftype->cmp_le); - return a->ftype->cmp_le(a, b); + return _fvalue_cmp(a, b) <= 0; } gboolean |