From 015d9194e1471455371ce7a8a591125a7c492619 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Thu, 27 Apr 2017 18:23:48 -0700 Subject: Add proto_tree_add_item_ret_boolean(). It does what it says on the label. You get back TRUE or FALSE in a gboolean. While we're at it, remove a copied-and-pasted comment that doesn't apply, and update another comment. Change-Id: I117391d2ffe44124a614a7f64dad1b389c1ebc6a Reviewed-on: https://code.wireshark.org/review/21394 Reviewed-by: Guy Harris --- epan/proto.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'epan/proto.c') diff --git a/epan/proto.c b/epan/proto.c index 766d22cb04..5b8a08470c 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -2678,7 +2678,6 @@ proto_tree_add_item_ret_uint64(proto_tree *tree, int hfindex, tvbuff_t *tvb, REPORT_DISSECTOR_BUG("wrong encoding"); } /* I believe it's ok if this is called with a NULL tree */ - /* XXX - modify if we ever support EBCDIC FT_CHAR */ value = get_uint64_value(tree, tvb, start, length, encoding); if (retval) { @@ -2704,6 +2703,57 @@ proto_tree_add_item_ret_uint64(proto_tree *tree, int hfindex, tvbuff_t *tvb, return proto_tree_add_node(tree, new_fi); } +proto_item * +proto_tree_add_item_ret_boolean(proto_tree *tree, int hfindex, tvbuff_t *tvb, + const gint start, gint length, + const guint encoding, gboolean *retval) +{ + header_field_info *hfinfo = proto_registrar_get_nth(hfindex); + field_info *new_fi; + guint64 value, bitval; + + DISSECTOR_ASSERT_HINT(hfinfo != NULL, "Not passed hfi!"); + + if (hfinfo->type != FT_BOOLEAN) { + REPORT_DISSECTOR_BUG(wmem_strdup_printf(wmem_packet_scope(), + "field %s is not of type FT_BOOLEAN", hfinfo->abbrev)); + } + + /* length validation for native number encoding caught by get_uint64_value() */ + /* length has to be -1 or > 0 regardless of encoding */ + if (length < -1 || length == 0) + REPORT_DISSECTOR_BUG(wmem_strdup_printf(wmem_packet_scope(), + "Invalid length %d passed to proto_tree_add_item_ret_uint", + length)); + + if (encoding & ENC_STRING) { + REPORT_DISSECTOR_BUG("wrong encoding"); + } + /* I believe it's ok if this is called with a NULL tree */ + value = get_uint64_value(tree, tvb, start, length, encoding); + + if (retval) { + bitval = value; + if (hfinfo->bitmask) { + /* Mask out irrelevant portions */ + bitval &= hfinfo->bitmask; + } + *retval = (bitval != 0); + } + + CHECK_FOR_NULL_TREE(tree); + + TRY_TO_FAKE_THIS_ITEM(tree, hfinfo->id, hfinfo); + + new_fi = new_field_info(tree, hfinfo, tvb, start, length); + + proto_tree_set_boolean(new_fi, value); + + new_fi->flags |= (encoding & ENC_LITTLE_ENDIAN) ? FI_LITTLE_ENDIAN : FI_BIG_ENDIAN; + + return proto_tree_add_node(tree, new_fi); +} + proto_item * proto_tree_add_item_ret_string_and_length(proto_tree *tree, int hfindex, tvbuff_t *tvb, -- cgit v1.2.3