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