aboutsummaryrefslogtreecommitdiffstats
path: root/epan/proto.h
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-01-08 18:25:26 -0800
committerGuy Harris <guy@alum.mit.edu>2016-01-09 02:26:06 +0000
commitc67c6e8f30b02450de2d9fb02b91026c5f954448 (patch)
treeb2fc637a2e893fe3daaec25718603d529f41e6dc /epan/proto.h
parent628c068a94fd8c4ebb36670637ed83f6dad80223 (diff)
Add routines to add an item and return the item's real length.
proto_item_get_len() is *not* guaranteed to return a correct value. Even if there's a non-null tree item, it might be pointing to a "faked" item; it really shouldn't be used. So add proto_tree_add_item_ret_length() and proto_tree_add_item_new_ret_length(), which calculate the real length themselves and return it through a pointer. Fix as many places as we straightforwardly can to use them rather than to use proto_item_get_len(). (There's a Lua API for proto_item_get_len(), so we keep it around, but we should add Lua APIs for the new routines, and deprecate the old API.) Fix ptvcursor_add() to do the same thing that proto_tree_add_item_ret_length() and proto_tree_add_item_new_ret_length() do. Split the TRY_TO_FAKE_THIS_ITEM macros into a macro to check for the tree being null and to try to fake the item. We don't always use the former macro, as we might need to do more than just return NULL if the incoming tree is null (for example, calculating the item's real length and using it...). new_field_info() never returns NULL; remove checks for it. The check for a null tree is done before the calls to new_field_info(). Change-Id: I002a218d1f810c73e0de837e0ac6ebcde21bacec Reviewed-on: https://code.wireshark.org/review/13139 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/proto.h')
-rw-r--r--epan/proto.h26
1 files changed, 25 insertions, 1 deletions
diff --git a/epan/proto.h b/epan/proto.h
index 51e4dc0bac..0b35a9ce54 100644
--- a/epan/proto.h
+++ b/epan/proto.h
@@ -1003,6 +1003,27 @@ proto_tree_add_item(proto_tree *tree, int hfindex, tvbuff_t *tvb,
const gint start, gint length, const guint encoding);
/** Add an item to a proto_tree, using the text label registered to that item.
+ The item is extracted from the tvbuff handed to it.
+
+ Return the length of the item through the pointer.
+ @param tree the tree to append this item to
+ @param hfinfo field
+ @param tvb the tv buffer of the current data
+ @param start start of data in tvb
+ @param length length of data in tvb
+ @param encoding data encoding
+ @param retval pointer to variable to set to the item length
+ @return the newly created item */
+WS_DLL_PUBLIC proto_item *
+proto_tree_add_item_new_ret_length(proto_tree *tree, header_field_info *hfinfo, tvbuff_t *tvb,
+ const gint start, gint length, const guint encoding, gint *retval);
+
+WS_DLL_PUBLIC proto_item *
+proto_tree_add_item_ret_length(proto_tree *tree, int hfindex, tvbuff_t *tvb,
+ const gint start, gint length,
+ const guint encoding, gint *retval);
+
+/** Add an item to a proto_tree, using the text label registered to that item.
The item is extracted from the tvbuff handed to it, and the retrieved
value is also set to *retval so the caller gets it back for other uses.
@@ -1019,7 +1040,7 @@ encoding in the tvbuff
The length argument must
be set to the appropriate size of the native type as in other proto_add routines.
-Integers of 8, 16, 24 and 32 bits can be retreived with these functions.
+Integers of 8, 16, 24 and 32 bits can be retrieved with these functions.
@param tree the tree to append this item to
@param hfindex field
@@ -2735,6 +2756,9 @@ proto_custom_set(proto_tree* tree, GSList *field_id,
#define proto_tree_add_item(tree, hfinfo, tvb, start, length, encoding) \
proto_tree_add_item_new(tree, hfinfo, tvb, start, length, encoding)
+#define proto_tree_add_item_ret_length(tree, hfinfo, tvb, start, length, encoding, retval) \
+ proto_tree_add_item_new_ret_length(tree, hfinfo, tvb, start, length, encoding, retval)
+
#define proto_tree_add_boolean(tree, hfinfo, tvb, start, length, value) \
proto_tree_add_boolean(tree, (hfinfo)->id, tvb, start, length, value)