aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2014-06-20 02:52:37 -0400
committerMichael Mann <mmann78@netscape.net>2014-06-20 06:58:12 +0000
commit28e8ce59cc5d83fdf426d56924fe01edd31d480d (patch)
treebf911d9f35ee67690c965de5d2f2396e29163b44
parentee2885f9e8203e07c690d73c9613a28f7810b5ff (diff)
Add proto_tree_add_subtree and proto_tree_add_subtree_format
This is intended as a replacement for all of the proto_tree_add_text followed by proto_item_add_subtree calls. Change-Id: I892136d7b9d8b4e100996097eff62ce7af9512d2 Reviewed-on: https://code.wireshark.org/review/2472 Reviewed-by: Michael Mann <mmann78@netscape.net>
-rw-r--r--epan/proto.c37
-rw-r--r--epan/proto.h29
2 files changed, 66 insertions, 0 deletions
diff --git a/epan/proto.c b/epan/proto.c
index 56c19908eb..08bbf01168 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -1122,6 +1122,43 @@ proto_tree_add_text_valist(proto_tree *tree, tvbuff_t *tvb, gint start,
return pi;
}
+/* Add a text-only node that creates a subtree underneath.
+ * proto_tree_add_text + proto_item_add_subtree
+ */
+proto_tree *
+proto_tree_add_subtree(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, gint idx, proto_item **tree_item, const char *text)
+{
+ return proto_tree_add_subtree_format(tree, tvb, start, length, idx, tree_item, "%s", text);
+}
+
+/* Add a text-only node that creates a subtree underneath.
+ * proto_tree_add_text + proto_item_add_subtree
+ */
+proto_tree *
+proto_tree_add_subtree_format(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, gint idx, proto_item **tree_item, const char *format, ...)
+{
+ proto_tree *pt;
+ proto_item *pi;
+ va_list ap;
+ header_field_info *hfinfo;
+
+ TRY_TO_FAKE_THIS_ITEM(tree, hf_text_only, hfinfo);
+
+ pi = proto_tree_add_text_node(tree, tvb, start, length);
+
+ TRY_TO_FAKE_THIS_REPR(pi);
+
+ va_start(ap, format);
+ proto_tree_set_representation(pi, format, ap);
+ va_end(ap);
+
+ pt = proto_item_add_subtree(pi, idx);
+ if (tree_item != NULL)
+ *tree_item = pi;
+
+ return pt;
+}
+
/* Add a text-only node for debugging purposes. The caller doesn't need
* to worry about tvbuff, start, or length. Debug message gets sent to
* STDOUT, too */
diff --git a/epan/proto.h b/epan/proto.h
index 70fbb1ac10..0f85750848 100644
--- a/epan/proto.h
+++ b/epan/proto.h
@@ -879,6 +879,35 @@ proto_item *
proto_tree_add_text_valist(proto_tree *tree, tvbuff_t *tvb, gint start,
gint length, const char *format, va_list ap);
+/** Add a text-only node that creates a subtree underneath.
+ proto_tree_add_text + proto_item_add_subtree
+ @param tree the tree to append this item to
+ @param tvb the tv buffer of the current data
+ @param start start of data in tvb
+ @param length length of data in tvb
+ @param idx one of the ett_ array elements registered with proto_register_subtree_array()
+ @param tree_item item returned with tree creation.
+ @param Can be NULL if going to be unused
+ @param text label for the tree
+ @return the newly created tree */
+proto_tree *
+proto_tree_add_subtree(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, gint idx, proto_item **tree_item, const char *text);
+
+/** Add a text-only node that creates a subtree underneath.
+ proto_tree_add_text + proto_item_add_subtree
+ @param tree the tree to append this item to
+ @param tvb the tv buffer of the current data
+ @param start start of data in tvb
+ @param length length of data in tvb
+ @param idx one of the ett_ array elements registered with proto_register_subtree_array()
+ @param tree_item item returned with tree creation.
+ @param Can be NULL if going to be unused
+ @param format printf like format string
+ @param ... printf like parameters
+ @return the newly created tree */
+proto_tree *
+proto_tree_add_subtree_format(proto_tree *tree, tvbuff_t *tvb, gint start, gint length, gint idx, proto_item **tree_item, const char *format,
+ ...) G_GNUC_PRINTF(5,6);
/** Add a text-only node to a proto_tree with tvb_format_text() string. */
proto_item *