aboutsummaryrefslogtreecommitdiffstats
path: root/epan/proto.c
diff options
context:
space:
mode:
authorLuis Ontanon <luis.ontanon@gmail.com>2006-03-27 19:28:02 +0000
committerLuis Ontanon <luis.ontanon@gmail.com>2006-03-27 19:28:02 +0000
commit850dfe8fa2ac1afa1a5c15341b5a35f912e9142b (patch)
treee0c9c72a0d4760f23c35d5dacdcdc6c44008a419 /epan/proto.c
parentc9179bea2e6b91e1469f2acbd5610b60f5090062 (diff)
add proto_all_finfos() that will return a GPtrArray containing every finfo found in a tree.
svn path=/trunk/; revision=17741
Diffstat (limited to 'epan/proto.c')
-rw-r--r--epan/proto.c48
1 files changed, 39 insertions, 9 deletions
diff --git a/epan/proto.c b/epan/proto.c
index 9cb904c8ef..ed8255f447 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -1033,6 +1033,7 @@ proto_tree_new_item(field_info *new_fi, proto_tree *tree, int hfindex,
/* If the proto_tree wants to keep a record of this finfo
* for quick lookup, then record it. */
if (new_fi->hfinfo->ref_count) {
+ /*HERE*/
hash = PTREE_DATA(tree)->interesting_hfids;
ptrs = g_hash_table_lookup(hash, GINT_TO_POINTER(hfindex));
if (ptrs) {
@@ -2708,6 +2709,7 @@ proto_tree_add_pi(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
/* If the proto_tree wants to keep a record of this finfo
* for quick lookup, then record it. */
if (fi->hfinfo->ref_count) {
+ /*HERE*/
hash = PTREE_DATA(tree)->interesting_hfids;
ptrs = g_hash_table_lookup(hash, GINT_TO_POINTER(hfindex));
if (ptrs) {
@@ -4572,12 +4574,13 @@ proto_get_finfo_ptr_array(proto_tree *tree, int id)
}
-/* Helper struct and function for proto_find_info() */
+/* Helper struct for proto_find_info() and proto_all_finfos() */
typedef struct {
GPtrArray *array;
int id;
} ffdata_t;
+/* Helper function for proto_find_info() */
static gboolean
find_finfo(proto_node *node, gpointer data)
{
@@ -4587,27 +4590,54 @@ find_finfo(proto_node *node, gpointer data)
g_ptr_array_add(((ffdata_t*)data)->array, fi);
}
}
-
+
/* Don't stop traversing. */
return FALSE;
}
/* Return GPtrArray* of field_info pointers for all hfindex that appear in a tree.
- * This works on any proto_tree, primed or unprimed, but actually searches
- * the tree, so it is slower than using proto_get_finfo_ptr_array on a primed tree.
- * The caller does need to free the returned GPtrArray with
- * g_ptr_array_free(<array>, FALSE).
- */
+* This works on any proto_tree, primed or unprimed, but actually searches
+* the tree, so it is slower than using proto_get_finfo_ptr_array on a primed tree.
+* The caller does need to free the returned GPtrArray with
+* g_ptr_array_free(<array>, FALSE).
+*/
GPtrArray*
proto_find_finfo(proto_tree *tree, int id)
{
ffdata_t ffdata;
-
+
ffdata.array = g_ptr_array_new();
ffdata.id = id;
-
+
proto_tree_traverse_pre_order(tree, find_finfo, &ffdata);
+
+ return ffdata.array;
+}
+
+/* Helper function for proto_all_finfos() */
+static gboolean
+every_finfo(proto_node *node, gpointer data)
+{
+ field_info *fi = PITEM_FINFO(node);
+ if (fi && fi->hfinfo) {
+ g_ptr_array_add(((ffdata_t*)data)->array, fi);
+ }
+
+ /* Don't stop traversing. */
+ return FALSE;
+}
+/* Return GPtrArray* of field_info pointers containing all hfindexes that appear in a tree. */
+GPtrArray*
+proto_all_finfos(proto_tree *tree)
+{
+ ffdata_t ffdata;
+
+ ffdata.array = g_ptr_array_new();
+ ffdata.id = 0;
+
+ proto_tree_traverse_pre_order(tree, every_finfo, &ffdata);
+
return ffdata.array;
}