From Harald Welte:
[obnox/wireshark/wip.git] / epan / ptvcursor.h
1 /* ptvcursor.h
2  *
3  * Proto Tree TVBuff cursor
4  * Gilbert Ramirez <gram@alumni.rice.edu>
5  *
6  * $Id$
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 2000 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 #ifndef __PTVCURSOR_H__
28 #define __PTVCURSOR_H__
29
30 #include <glib.h>
31 #include <epan/packet.h>
32
33 #define SUBTREE_UNDEFINED_LENGTH -1
34
35 typedef struct ptvcursor ptvcursor_t;
36
37 /* Allocates an initializes a ptvcursor_t with 3 variables:
38  * proto_tree, tvbuff, and offset. */
39 ptvcursor_t*
40 ptvcursor_new(proto_tree* tree, tvbuff_t* tvb, gint offset);
41
42 /* Gets data from tvbuff, adds it to proto_tree, increments offset,
43  * and returns proto_item* */
44 proto_item*
45 ptvcursor_add(ptvcursor_t* ptvc, int hf, gint length, const guint encoding);
46
47
48 /* Gets data from tvbuff, adds it to proto_tree, *DOES NOT* increment
49  * offset, and returns proto_item* */
50 proto_item*
51 ptvcursor_add_no_advance(ptvcursor_t* ptvc, int hf, gint length, const guint encoding);
52
53 /* Advance the ptvcursor's offset within its tvbuff without
54  * adding anything to the proto_tree. */
55 void
56 ptvcursor_advance(ptvcursor_t* ptvc, gint length);
57
58 /* Frees memory for ptvcursor_t, but nothing deeper than that. */
59 void
60 ptvcursor_free(ptvcursor_t* ptvc);
61
62 /* Returns tvbuff. */
63 tvbuff_t*
64 ptvcursor_tvbuff(ptvcursor_t* ptvc);
65
66 /* Returns current offset. */
67 gint
68 ptvcursor_current_offset(ptvcursor_t* ptvc);
69
70 /* Returns the proto_tree* */
71 proto_tree*
72 ptvcursor_tree(ptvcursor_t* ptvc);
73
74 /* Sets a new proto_tree* for the ptvcursor_t */
75 void
76 ptvcursor_set_tree(ptvcursor_t* ptvc, proto_tree* tree);
77
78 /* push a subtree in the tree stack of the cursor */
79 proto_tree*
80 ptvcursor_push_subtree(ptvcursor_t* ptvc, proto_item* it, gint ett_subtree);
81
82 /* pop a subtree in the tree stack of the cursor */
83 void
84 ptvcursor_pop_subtree(ptvcursor_t* ptvc);
85
86 /* Add an item to the tree and create a subtree
87  * If the length is unknown, length may be defined as SUBTREE_UNDEFINED_LENGTH.
88  * In this case, when the subtree will be closed, the parent item length will
89  * be equal to the advancement of the cursor since the creation of the subtree.
90  */
91 proto_tree*
92 ptvcursor_add_with_subtree(ptvcursor_t* ptvc, int hfindex, gint length,
93     const guint encoding, gint ett_subtree);
94
95 /* Add a text node to the tree and create a subtree
96  * If the length is unknown, length may be defined as SUBTREE_UNDEFINED_LENGTH.
97  * In this case, when the subtree will be closed, the item length will be equal
98  * to the advancement of the cursor since the creation of the subtree.
99  */
100 proto_tree*
101 ptvcursor_add_text_with_subtree(ptvcursor_t* ptvc, gint length,
102     gint ett_subtree, const char* format, ...);
103
104 /* Creates a subtree and adds it to the cursor as the working tree but does not
105  * save the old working tree */
106 proto_tree*
107 ptvcursor_set_subtree(ptvcursor_t* ptvc, proto_item* it, gint ett_subtree);
108
109 #endif /* __PTVCURSOR_H__ */