3 * Proto Tree TVBuff cursor
4 * Gilbert Ramirez <gram@alumni.rice.edu>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 2000 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 #ifndef __PTVCURSOR_H__
14 #define __PTVCURSOR_H__
16 #include <epan/packet.h>
17 #include "ws_symbol_export.h"
19 #define SUBTREE_UNDEFINED_LENGTH -1
21 typedef struct ptvcursor ptvcursor_t
;
23 /* Allocates an initializes a ptvcursor_t with 3 variables:
24 * proto_tree, tvbuff, and offset. */
27 ptvcursor_new(wmem_allocator_t
*scope
, proto_tree
* tree
, tvbuff_t
* tvb
, int offset
);
29 /* Gets data from tvbuff, adds it to proto_tree, increments offset,
30 * and returns proto_item* */
33 ptvcursor_add(ptvcursor_t
* ptvc
, int hf
, int length
, const unsigned encoding
);
35 /* Gets data from tvbuff, adds it to proto_tree, increments offset,
36 * and returns proto_item* and uint value retrieved*/
39 ptvcursor_add_ret_uint(ptvcursor_t
* ptvc
, int hf
, int length
, const unsigned encoding
, uint32_t *retval
);
41 /* Gets data from tvbuff, adds it to proto_tree, increments offset,
42 * and returns proto_item* and int value retrieved */
45 ptvcursor_add_ret_int(ptvcursor_t
* ptvc
, int hf
, int length
, const unsigned encoding
, int32_t *retval
);
47 /* Gets data from tvbuff, adds it to proto_tree, increments offset,
48 * and returns proto_item* and string value retrieved */
51 ptvcursor_add_ret_string(ptvcursor_t
* ptvc
, int hf
, int length
, const unsigned encoding
, wmem_allocator_t
*scope
, const uint8_t **retval
);
53 /* Gets data from tvbuff, adds it to proto_tree, increments offset,
54 * and returns proto_item* and boolean value retrieved */
57 ptvcursor_add_ret_boolean(ptvcursor_t
* ptvc
, int hf
, int length
, const unsigned encoding
, bool *retval
);
59 /* Gets data from tvbuff, adds it to proto_tree, *DOES NOT* increment
60 * offset, and returns proto_item* */
63 ptvcursor_add_no_advance(ptvcursor_t
* ptvc
, int hf
, int length
, const unsigned encoding
);
65 /* Advance the ptvcursor's offset within its tvbuff without
66 * adding anything to the proto_tree. */
69 ptvcursor_advance(ptvcursor_t
* ptvc
, int length
);
71 /* Frees memory for ptvcursor_t, but nothing deeper than that. */
74 ptvcursor_free(ptvcursor_t
* ptvc
);
79 ptvcursor_tvbuff(ptvcursor_t
* ptvc
);
81 /* Returns current offset. */
84 ptvcursor_current_offset(ptvcursor_t
* ptvc
);
86 /* Returns the proto_tree* */
89 ptvcursor_tree(ptvcursor_t
* ptvc
);
91 /* Sets a new proto_tree* for the ptvcursor_t */
94 ptvcursor_set_tree(ptvcursor_t
* ptvc
, proto_tree
* tree
);
96 /* push a subtree in the tree stack of the cursor */
99 ptvcursor_push_subtree(ptvcursor_t
* ptvc
, proto_item
* it
, int ett_subtree
);
101 /* pop a subtree in the tree stack of the cursor */
104 ptvcursor_pop_subtree(ptvcursor_t
* ptvc
);
106 /* Add an item to the tree and create a subtree
107 * If the length is unknown, length may be defined as SUBTREE_UNDEFINED_LENGTH.
108 * In this case, when the subtree will be closed, the parent item length will
109 * be equal to the advancement of the cursor since the creation of the subtree.
113 ptvcursor_add_with_subtree(ptvcursor_t
* ptvc
, int hfindex
, int length
,
114 const unsigned encoding
, int ett_subtree
);
116 /* Add a text node to the tree and create a subtree
117 * If the length is unknown, length may be defined as SUBTREE_UNDEFINED_LENGTH.
118 * In this case, when the subtree will be closed, the item length will be equal
119 * to the advancement of the cursor since the creation of the subtree.
123 ptvcursor_add_text_with_subtree(ptvcursor_t
* ptvc
, int length
,
124 int ett_subtree
, const char* format
, ...)
127 /* Creates a subtree and adds it to the cursor as the working tree but does not
128 * save the old working tree */
131 ptvcursor_set_subtree(ptvcursor_t
* ptvc
, proto_item
* it
, int ett_subtree
);
133 #endif /* __PTVCURSOR_H__ */