ssl,dtls: use ProtocolVersion from Server Hello
[metze/wireshark/wip.git] / epan / next_tvb.c
1 /* next_tvb.c
2  * Routines for "next tvb" list
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include "config.h"
24
25 #include <glib.h>
26
27 #include <epan/packet.h>
28
29 #include "next_tvb.h"
30
31 void next_tvb_init(next_tvb_list_t *list) {
32   list->first = NULL;
33   list->last = NULL;
34   list->count = 0;
35 }
36
37 void next_tvb_add_handle(next_tvb_list_t *list, tvbuff_t *tvb, proto_tree *tree, dissector_handle_t handle) {
38   next_tvb_item_t *item;
39
40   item = wmem_new(wmem_packet_scope(), next_tvb_item_t);
41
42   item->type = NTVB_HANDLE;
43   item->handle = handle;
44   item->tvb = tvb;
45   item->tree = tree;
46
47   if (list->last) {
48     list->last->next = item;
49   } else {
50     list->first = item;
51   }
52   item->next = NULL;
53   item->previous = list->last;
54   list->last = item;
55   list->count++;
56 }
57
58 void next_tvb_add_uint(next_tvb_list_t *list, tvbuff_t *tvb, proto_tree *tree, dissector_table_t table, guint32 uint_val) {
59   next_tvb_item_t *item;
60
61   item = wmem_new(wmem_packet_scope(), next_tvb_item_t);
62
63   item->type = NTVB_UINT;
64   item->table = table;
65   item->uint_val = uint_val;
66   item->tvb = tvb;
67   item->tree = tree;
68
69   if (list->last) {
70     list->last->next = item;
71   } else {
72     list->first = item;
73   }
74   item->next = NULL;
75   item->previous = list->last;
76   list->last = item;
77   list->count++;
78 }
79
80 void next_tvb_add_string(next_tvb_list_t *list, tvbuff_t *tvb, proto_tree *tree, dissector_table_t table, const gchar *string) {
81   next_tvb_item_t *item;
82
83   item = wmem_new(wmem_packet_scope(), next_tvb_item_t);
84
85   item->type = NTVB_STRING;
86   item->table = table;
87   item->string = string;
88   item->tvb = tvb;
89   item->tree = tree;
90
91   if (list->last) {
92     list->last->next = item;
93   } else {
94     list->first = item;
95   }
96   item->next = NULL;
97   item->previous = list->last;
98   list->last = item;
99   list->count++;
100 }
101
102 void next_tvb_call(next_tvb_list_t *list, packet_info *pinfo, proto_tree *tree, dissector_handle_t handle, dissector_handle_t data_handle) {
103   next_tvb_item_t *item;
104
105   item = list->first;
106   while (item) {
107     if (item->tvb && tvb_captured_length(item->tvb)) {
108       switch (item->type) {
109         case NTVB_HANDLE:
110           call_dissector((item->handle) ? item->handle : ((handle) ? handle : data_handle), item->tvb, pinfo, (item->tree) ? item->tree : tree);
111           break;
112         case NTVB_UINT:
113           dissector_try_uint(item->table, item->uint_val, item->tvb, pinfo, (item->tree) ? item->tree : tree);
114           break;
115         case NTVB_STRING:
116           dissector_try_string(item->table, item->string, item->tvb, pinfo, (item->tree) ? item->tree : tree, NULL);
117           break;
118       }
119     }
120     item = item->next;
121   }
122 }
123
124
125 /*
126  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
127  *
128  * Local Variables:
129  * c-basic-offset: 2
130  * tab-width: 8
131  * indent-tabs-mode: nil
132  * End:
133  *
134  * ex: set shiftwidth=2 tabstop=8 expandtab:
135  * :indentSize=2:tabSize=8:noTabs=true:
136  */