From 044f075c66d6a71aa3e82439d41a6c76c59009d7 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Thu, 25 Mar 2004 23:55:21 +0000 Subject: [PATCH] From Tomas Kukosa: add APIs to get the parent of a protocol tree item and the item N levels up from a protocol tree item. svn path=/trunk/; revision=10486 --- epan/proto.c | 22 +++++++++++++++++++++- epan/proto.h | 8 +++++++- plugins/plugin_api_list.c | 5 ++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/epan/proto.c b/epan/proto.c index cf80391f07..676b082359 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -1,7 +1,7 @@ /* proto.c * Routines for protocol tree * - * $Id: proto.c,v 1.130 2004/03/25 09:17:11 guy Exp $ + * $Id: proto.c,v 1.131 2004/03/25 23:55:21 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -2186,6 +2186,26 @@ proto_item_get_subtree(proto_item *pi) { return (proto_tree*) pi; } +proto_item* +proto_item_get_parent(proto_item *ti) { + if (!ti) + return (NULL); + return ti->parent; +} + +proto_item* +proto_item_get_parent_nth(proto_item *ti, int gen) { + if (!ti) + return (NULL); + while (gen--) { + ti = ti->parent; + if (!ti) + return (NULL); + } + return ti; +} + + proto_item* proto_tree_get_parent(proto_tree *tree) { if (!tree) diff --git a/epan/proto.h b/epan/proto.h index 30532a9ba0..e906c4ec9b 100644 --- a/epan/proto.h +++ b/epan/proto.h @@ -1,7 +1,7 @@ /* proto.h * Definitions for protocol display * - * $Id: proto.h,v 1.56 2004/03/25 09:17:11 guy Exp $ + * $Id: proto.h,v 1.57 2004/03/25 23:55:21 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -208,6 +208,12 @@ extern proto_tree* proto_item_add_subtree(proto_item *ti, gint idx); /* Get a subtree under an item; returns tree pointer */ extern proto_tree* proto_item_get_subtree(proto_item *ti); +/* Get a parent item; returns item pointer */ +extern proto_item* proto_item_get_parent(proto_item *ti); + +/* Get Nth generation parent item; returns item pointer */ +extern proto_item* proto_item_get_parent_nth(proto_item *ti, int gen); + /* Get a parent item of subtree; returns item pointer */ extern proto_item* proto_tree_get_parent(proto_tree *tree); diff --git a/plugins/plugin_api_list.c b/plugins/plugin_api_list.c index 4a9b96e471..5ba305759d 100644 --- a/plugins/plugin_api_list.c +++ b/plugins/plugin_api_list.c @@ -1,7 +1,7 @@ /* plugin_api_list.c * Used to generate various included files for plugin API * - * $Id: plugin_api_list.c,v 1.32 2004/03/25 09:17:11 guy Exp $ + * $Id: plugin_api_list.c,v 1.33 2004/03/25 23:55:21 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -431,3 +431,6 @@ int get_ber_identifier(tvbuff_t *tvb, int offset, guint8 *class, gboolean *pc, g int get_ber_length(tvbuff_t *tvb, int offset, guint32 *length, gboolean *ind); proto_tree* proto_item_get_subtree(proto_item *ti); proto_item* proto_tree_get_parent(proto_tree *tree); +proto_item* proto_item_get_parent(proto_item *ti); +proto_item* proto_item_get_parent_nth(proto_item *ti, int gen); +proto_item *get_ber_last_created_item(void);