update epan/dissectors/pidl/drsuapi/drsuapi.idl from samba
[wireshark-sm.git] / epan / next_tvb.c
blob8aa8571500614d6d67f00110f8444677e3f24118
1 /* next_tvb.c
2 * Routines for "next tvb" list
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
11 #include "config.h"
13 #include <glib.h>
15 #include <epan/packet.h>
17 #include "next_tvb.h"
19 next_tvb_list_t* next_tvb_list_new(wmem_allocator_t *pool) {
20 next_tvb_list_t *list = wmem_new0(pool, next_tvb_list_t);
21 list->pool = pool;
22 return list;
25 void next_tvb_add_handle(next_tvb_list_t *list, tvbuff_t *tvb, proto_tree *tree, dissector_handle_t handle) {
26 next_tvb_item_t *item;
28 item = wmem_new(list->pool, next_tvb_item_t);
30 item->type = NTVB_HANDLE;
31 item->handle = handle;
32 item->tvb = tvb;
33 item->tree = tree;
35 if (list->last) {
36 list->last->next = item;
37 } else {
38 list->first = item;
40 item->next = NULL;
41 item->previous = list->last;
42 list->last = item;
43 list->count++;
46 void next_tvb_add_uint(next_tvb_list_t *list, tvbuff_t *tvb, proto_tree *tree, dissector_table_t table, uint32_t uint_val) {
47 next_tvb_item_t *item;
49 item = wmem_new(list->pool, next_tvb_item_t);
51 item->type = NTVB_UINT;
52 item->table = table;
53 item->uint_val = uint_val;
54 item->tvb = tvb;
55 item->tree = tree;
57 if (list->last) {
58 list->last->next = item;
59 } else {
60 list->first = item;
62 item->next = NULL;
63 item->previous = list->last;
64 list->last = item;
65 list->count++;
68 void next_tvb_add_string(next_tvb_list_t *list, tvbuff_t *tvb, proto_tree *tree, dissector_table_t table, const char *string) {
69 next_tvb_item_t *item;
71 item = wmem_new(list->pool, next_tvb_item_t);
73 item->type = NTVB_STRING;
74 item->table = table;
75 item->string = string;
76 item->tvb = tvb;
77 item->tree = tree;
79 if (list->last) {
80 list->last->next = item;
81 } else {
82 list->first = item;
84 item->next = NULL;
85 item->previous = list->last;
86 list->last = item;
87 list->count++;
90 void next_tvb_call(next_tvb_list_t *list, packet_info *pinfo, proto_tree *tree, dissector_handle_t handle, dissector_handle_t data_handle) {
91 next_tvb_item_t *item;
93 item = list->first;
94 while (item) {
95 if (item->tvb && tvb_captured_length(item->tvb)) {
96 switch (item->type) {
97 case NTVB_HANDLE:
98 call_dissector((item->handle) ? item->handle : ((handle) ? handle : data_handle), item->tvb, pinfo, (item->tree) ? item->tree : tree);
99 break;
100 case NTVB_UINT:
101 dissector_try_uint(item->table, item->uint_val, item->tvb, pinfo, (item->tree) ? item->tree : tree);
102 break;
103 case NTVB_STRING:
104 dissector_try_string(item->table, item->string, item->tvb, pinfo, (item->tree) ? item->tree : tree, NULL);
105 break;
108 item = item->next;
114 * Editor modelines - https://www.wireshark.org/tools/modelines.html
116 * Local Variables:
117 * c-basic-offset: 2
118 * tab-width: 8
119 * indent-tabs-mode: nil
120 * End:
122 * ex: set shiftwidth=2 tabstop=8 expandtab:
123 * :indentSize=2:tabSize=8:noTabs=true: