diff options
author | AndersBroman <anders.broman@ericsson.com> | 2016-09-26 15:04:34 +0200 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2016-09-27 03:39:28 +0000 |
commit | 1a384ef4161470bf4a1af18da9b0b98cbc9c7f56 (patch) | |
tree | 4c1e9aa565b78152d82fd4a946f2359805e16f75 /epan | |
parent | 0a45d13652cd0f34a9cabfbc6dbbdc8faaaf3554 (diff) | |
download | wireshark-1a384ef4161470bf4a1af18da9b0b98cbc9c7f56.tar.gz |
[proto.c] Add proto_find_first_finfo() to find first occurance of a field.
Change-Id: I11f50d7b00851880f77067260e2496175d227e76
Reviewed-on: https://code.wireshark.org/review/17937
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan')
-rw-r--r-- | epan/print.c | 2 | ||||
-rw-r--r-- | epan/proto.c | 34 | ||||
-rw-r--r-- | epan/proto.h | 8 |
3 files changed, 43 insertions, 1 deletions
diff --git a/epan/print.c b/epan/print.c index 0840d00ca7..bf477544b0 100644 --- a/epan/print.c +++ b/epan/print.c @@ -1108,7 +1108,7 @@ print_pdml_geninfo(epan_dissect_t *edt, FILE *fh) gchar *tmp; /* Get frame protocol's finfo. */ - finfo_array = proto_find_finfo(edt->tree, proto_frame); + finfo_array = proto_find_first_finfo(edt->tree, proto_frame); if (g_ptr_array_len(finfo_array) < 1) { return; } diff --git a/epan/proto.c b/epan/proto.c index d0763d490c..022dba9624 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -8377,6 +8377,21 @@ find_finfo(proto_node *node, gpointer data) return FALSE; } +/* Helper function for proto_find_first_info() */ +static gboolean +find_first_finfo(proto_node *node, gpointer data) +{ + field_info *fi = PNODE_FINFO(node); + if (fi && fi->hfinfo) { + if (fi->hfinfo->id == ((ffdata_t*)data)->id) { + g_ptr_array_add(((ffdata_t*)data)->array, fi); + } + } + + /* Stop traversing. */ + return TRUE; +} + /* 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. @@ -8396,6 +8411,25 @@ proto_find_finfo(proto_tree *tree, const int id) return ffdata.array; } +/* Return GPtrArray* of first field_info pointers for the searched 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>, TRUE). +*/ +GPtrArray * +proto_find_first_finfo(proto_tree *tree, const int id) +{ + ffdata_t ffdata; + + ffdata.array = g_ptr_array_new(); + ffdata.id = id; + + proto_tree_traverse_pre_order(tree, find_first_finfo, &ffdata); + + return ffdata.array; +} + /* Helper function for proto_all_finfos() */ static gboolean every_finfo(proto_node *node, gpointer data) diff --git a/epan/proto.h b/epan/proto.h index 63c380a6c7..18d8161265 100644 --- a/epan/proto.h +++ b/epan/proto.h @@ -2333,6 +2333,14 @@ WS_DLL_PUBLIC gboolean proto_tracking_interesting_fields(const proto_tree *tree) @return GPtrArry pointer */ WS_DLL_PUBLIC GPtrArray* proto_find_finfo(proto_tree *tree, const int hfindex); +/** Return GPtrArray* of field_info pointer for first hfindex that appear in +tree. Works with any tree, primed or unprimed, and is slower than +proto_get_finfo_ptr_array because it has to search through the tree. +@param tree tree of interest +@param hfindex index of field info of interest +@return GPtrArry pointer */ +WS_DLL_PUBLIC GPtrArray* proto_find_first_finfo(proto_tree *tree, const int hfindex); + /** Return GPtrArray* of field_info pointers containg all hfindexes that appear in tree. @param tree tree of interest |