diff options
author | Michael Mann <mmann78@netscape.net> | 2015-04-12 19:12:35 -0400 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2015-04-13 13:46:11 +0000 |
commit | 6ab6136a94ec4ca7481a837f348050091505c6e0 (patch) | |
tree | 76ccdc6456b22d5138bca40573eb43fcf990cada /epan/proto.c | |
parent | 89cd92d15f16ff99e1601484e3d6e94c1f00a5f9 (diff) |
Add more "bitmask grouping" APIs.
Add proto_tree_add_bitmask_value, proto_tree_add_bitmask_value_with_flags and proto_tree_add_bitmask_list to aid in the removal of proto_tree_add_boolean "groupings" as well as "groups" of fields that use proto_tree_add_item with the same offset/len.
This may be able to be optimized later, but the first step will be converting dissectors to use it. A sample conversion of each API is also included.
Change-Id: I53febc7450ad632482f82615a7fa62174f8472c9
Reviewed-on: https://code.wireshark.org/review/8038
Reviewed-by: Michael Mann <mmann78@netscape.net>
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan/proto.c')
-rw-r--r-- | epan/proto.c | 108 |
1 files changed, 77 insertions, 31 deletions
diff --git a/epan/proto.c b/epan/proto.c index a1ff46aae9..ddad3a7eeb 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -8031,59 +8031,61 @@ static gboolean proto_item_add_bitmask_tree(proto_item *item, tvbuff_t *tvb, const int offset, const int len, const gint ett, const int **fields, const guint encoding, const int flags, - gboolean first) + gboolean first, gboolean use_parent_tree, gboolean use_value, + proto_tree* tree, guint64 value) { - guint64 value = 0; guint64 available_bits = 0; guint64 tmpval; - proto_tree *tree = NULL; header_field_info *hf; switch (len) { case 1: - value = tvb_get_guint8(tvb, offset); + if (use_value == FALSE) + value = tvb_get_guint8(tvb, offset); available_bits = 0xFF; break; case 2: - value = encoding ? tvb_get_letohs(tvb, offset) : - tvb_get_ntohs(tvb, offset); + if (use_value == FALSE) + value = encoding ? tvb_get_letohs(tvb, offset) : tvb_get_ntohs(tvb, offset); available_bits = 0xFFFF; break; case 3: - value = encoding ? tvb_get_letoh24(tvb, offset) : - tvb_get_ntoh24(tvb, offset); + if (use_value == FALSE) + value = encoding ? tvb_get_letoh24(tvb, offset) : tvb_get_ntoh24(tvb, offset); available_bits = 0xFFFFFF; break; case 4: - value = encoding ? tvb_get_letohl(tvb, offset) : - tvb_get_ntohl(tvb, offset); + if (use_value == FALSE) + value = encoding ? tvb_get_letohl(tvb, offset) : tvb_get_ntohl(tvb, offset); available_bits = 0xFFFFFFFF; break; case 5: - value = encoding ? tvb_get_letoh40(tvb, offset) : - tvb_get_ntoh40(tvb, offset); + if (use_value == FALSE) + value = encoding ? tvb_get_letoh40(tvb, offset) : tvb_get_ntoh40(tvb, offset); available_bits = G_GUINT64_CONSTANT(0xFFFFFFFFFF); break; case 6: - value = encoding ? tvb_get_letoh48(tvb, offset) : - tvb_get_ntoh48(tvb, offset); + if (use_value == FALSE) + value = encoding ? tvb_get_letoh48(tvb, offset) : tvb_get_ntoh48(tvb, offset); available_bits = G_GUINT64_CONSTANT(0xFFFFFFFFFFFF); break; case 7: - value = encoding ? tvb_get_letoh56(tvb, offset) : - tvb_get_ntoh56(tvb, offset); + if (use_value == FALSE) + value = encoding ? tvb_get_letoh56(tvb, offset) : tvb_get_ntoh56(tvb, offset); available_bits = G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFF); break; case 8: - value = encoding ? tvb_get_letoh64(tvb, offset) : - tvb_get_ntoh64(tvb, offset); + if (use_value == FALSE) + value = encoding ? tvb_get_letoh64(tvb, offset) : tvb_get_ntoh64(tvb, offset); available_bits = G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF); break; default: g_assert_not_reached(); } - tree = proto_item_add_subtree(item, ett); + if (use_parent_tree == FALSE) + tree = proto_item_add_subtree(item, ett); + while (*fields) { guint64 present_bits; PROTO_REGISTRAR_GET_NTH(**fields,hf); @@ -8096,7 +8098,17 @@ proto_item_add_bitmask_tree(proto_item *item, tvbuff_t *tvb, const int offset, continue; } - proto_tree_add_item(tree, **fields, tvb, offset, len, encoding); + if (use_value) + { + if (len <= 4) + proto_tree_add_uint(tree, **fields, tvb, offset, len, (guint32)value); + else + proto_tree_add_uint64(tree, **fields, tvb, offset, len, value); + } + else + { + proto_tree_add_item(tree, **fields, tvb, offset, len, encoding); + } if (flags & BMT_NO_APPEND) { fields++; continue; @@ -8203,6 +8215,16 @@ proto_tree_add_bitmask(proto_tree *parent_tree, tvbuff_t *tvb, const gint ett, const int **fields, const guint encoding) { + return proto_tree_add_bitmask_with_flags(parent_tree, tvb, offset, hf_hdr, ett, fields, encoding, BMT_NO_INT|BMT_NO_TFS); +} + +/* The same as proto_tree_add_bitmask(), but uses user-supplied flags to determine + * what data is appended to the header. + */ +proto_item * +proto_tree_add_bitmask_with_flags(proto_tree *parent_tree, tvbuff_t *tvb, const guint offset, + const int hf_hdr, const gint ett, const int **fields, const guint encoding, const int flags) +{ proto_item *item = NULL; header_field_info *hf; int len; @@ -8214,18 +8236,26 @@ proto_tree_add_bitmask(proto_tree *parent_tree, tvbuff_t *tvb, if (parent_tree) { item = proto_tree_add_item(parent_tree, hf_hdr, tvb, offset, len, encoding); proto_item_add_bitmask_tree(item, tvb, offset, len, ett, fields, encoding, - BMT_NO_INT|BMT_NO_TFS, FALSE); + flags, FALSE, FALSE, FALSE, NULL, 0); } return item; } -/* The same as proto_tree_add_bitmask(), but uses user-supplied flags to determine - * what data is appended to the header. - */ +/* Similar to proto_tree_add_bitmask(), but with a passed in value (presumably because it + can't be retrieved directly from tvb) */ proto_item * -proto_tree_add_bitmask_with_flags(proto_tree *parent_tree, tvbuff_t *tvb, const guint offset, - const int hf_hdr, const gint ett, const int **fields, const guint encoding, const int flags) +proto_tree_add_bitmask_value(proto_tree *parent_tree, tvbuff_t *tvb, const guint offset, + const int hf_hdr, const gint ett, const int **fields, const guint64 value) +{ + return proto_tree_add_bitmask_value_with_flags(parent_tree, tvb, offset, + hf_hdr, ett, fields, value, BMT_NO_INT|BMT_NO_TFS); +} + +/* Similar to proto_tree_add_bitmask_value(), but with control of flag values */ +WS_DLL_PUBLIC proto_item * +proto_tree_add_bitmask_value_with_flags(proto_tree *parent_tree, tvbuff_t *tvb, const guint offset, + const int hf_hdr, const gint ett, const int **fields, const guint64 value, const int flags) { proto_item *item = NULL; header_field_info *hf; @@ -8236,14 +8266,30 @@ proto_tree_add_bitmask_with_flags(proto_tree *parent_tree, tvbuff_t *tvb, const len = ftype_length(hf->type); if (parent_tree) { - item = proto_tree_add_item(parent_tree, hf_hdr, tvb, offset, len, encoding); - proto_item_add_bitmask_tree(item, tvb, offset, len, ett, fields, encoding, - flags, FALSE); + if (len <= 4) + item = proto_tree_add_uint(parent_tree, hf_hdr, tvb, offset, len, (guint32)value); + else + item = proto_tree_add_uint64(parent_tree, hf_hdr, tvb, offset, len, value); + + proto_item_add_bitmask_tree(item, tvb, offset, len, ett, fields, + 0, flags, FALSE, FALSE, TRUE, NULL, value); + } return item; } +/* Similar to proto_tree_add_bitmask(), but with no "header" item to group all of the fields */ +void +proto_tree_add_bitmask_list(proto_tree *tree, tvbuff_t *tvb, const guint offset, + const int len, const int **fields, const guint encoding) +{ + if (tree) + proto_item_add_bitmask_tree(NULL, tvb, offset, len, -1, fields, + encoding, BMT_NO_APPEND, FALSE, TRUE, FALSE, tree, 0); +} + + /* The same as proto_tree_add_bitmask(), but using a caller-supplied length. * This is intended to support bitmask fields whose lengths can vary, perhaps * as the underlying standard evolves over time. @@ -8298,7 +8344,7 @@ proto_tree_add_bitmask_len(proto_tree *parent_tree, tvbuff_t *tvb, if (item) { proto_item_add_bitmask_tree(item, tvb, decodable_offset, decodable_len, - ett, fields, encoding, BMT_NO_INT|BMT_NO_TFS, FALSE); + ett, fields, encoding, BMT_NO_INT|BMT_NO_TFS, FALSE, FALSE, FALSE, NULL, 0); } return item; @@ -8317,7 +8363,7 @@ proto_tree_add_bitmask_text(proto_tree *parent_tree, tvbuff_t *tvb, if (parent_tree) { item = proto_tree_add_text(parent_tree, tvb, offset, len, "%s", name ? name : ""); if (proto_item_add_bitmask_tree(item, tvb, offset, len, ett, fields, encoding, - flags, TRUE) && fallback) { + flags, TRUE, FALSE, FALSE, NULL, 0) && fallback) { /* Still at first item - append 'fallback' text if any */ proto_item_append_text(item, "%s", fallback); } |