From Michael Tuexen: add missing support for the T-Bit in ABORT chunks.
[obnox/wireshark/wip.git] / ptvcursor.c
1 /* ptvcursor.c
2  * 
3  * Proto Tree TVBuff cursor
4  * Gilbert Ramirez <gram@alumni.rice.edu>
5  *
6  * $Id: ptvcursor.c,v 1.5 2002/01/10 04:44:34 gram Exp $
7  *
8  * Ethereal - Network traffic analyzer
9  * By Gerald Combs <gerald@zing.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 #include "ptvcursor.h"
28
29
30 struct ptvcursor {
31         proto_tree      *tree;
32         tvbuff_t        *tvb;
33         gint            offset;
34 };
35
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         ptvcursor_t     *ptvc;
43
44         ptvc = g_new(ptvcursor_t, 1);
45         ptvc->tree      = tree;
46         ptvc->tvb       = tvb;
47         ptvc->offset    = offset;
48         return ptvc;
49 }
50
51
52 /* Gets data from tvbuff, adds it to proto_tree, increments offset,
53  * and returns proto_item* */
54 proto_item*
55 ptvcursor_add(ptvcursor_t *ptvc, int hf, gint length, gboolean endianness)
56 {
57         proto_item      *item;
58
59         item = ptvcursor_add_no_advance(ptvc, hf, length, endianness);
60         ptvc->offset += proto_item_get_len(item);
61         return item;
62 }
63
64 /* Gets data from tvbuff, adds it to proto_tree, *DOES NOT* increment
65  * offset, and returns proto_item* */
66 proto_item*
67 ptvcursor_add_no_advance(ptvcursor_t* ptvc, int hf, gint length,
68                 gboolean endianness)
69 {
70         proto_item      *item;
71
72         item = proto_tree_add_item(ptvc->tree, hf, ptvc->tvb, ptvc->offset,
73                         length, endianness);
74
75         return item;
76 }
77
78 /* Frees memory for ptvcursor_t, but nothing deeper than that. */
79 void
80 ptvcursor_free(ptvcursor_t *ptvc)
81 {
82         g_free(ptvc);
83 }
84 /* Returns tvbuff. */
85 tvbuff_t*
86 ptvcursor_tvbuff(ptvcursor_t* ptvc)
87 {
88         return ptvc->tvb;
89 }
90
91 /* Returns current offset. */
92 gint
93 ptvcursor_current_offset(ptvcursor_t* ptvc)
94 {
95         return ptvc->offset;
96 }