Remove support for pinfo->private_data in "data-text-lines", "data-l1-events" and...
[metze/wireshark/wip.git] / epan / dissectors / packet-l1-events.c
1 /* packet-l1-events.c
2  * Routines for text-based layer 1 messages in EyeSDN trace files
3  *
4  * (C) Rolf Fiedler 2008, based on packet-text-media.c by Olivier Biot, 2004.
5  *
6  * Refer to the AUTHORS file or the AUTHORS section in the man page
7  * for contacting the author(s) of this file.
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26  */
27
28 /* Edit this file with 4-space tabs */
29
30 #include "config.h"
31
32 #include <glib.h>
33
34 #include <epan/packet.h>
35 #include <wiretap/wtap.h>
36 #include <epan/strutil.h>
37
38 void proto_register_l1_events(void);
39 void proto_reg_handoff_l1_events(void);
40
41 /*
42  * dissector for line-based text messages from layer 1
43  */
44
45 /* Filterable header fields */
46 static gint proto_l1_events = -1;
47
48 /* Subtrees */
49 static gint ett_l1_events = -1;
50
51 static int
52 dissect_l1_events(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
53 {
54         proto_tree      *subtree;
55         proto_item      *ti;
56         gint            offset = 0, next_offset;
57         gint            len;
58         const char      *data_name;
59
60         data_name = pinfo->match_string;
61         if (! (data_name && data_name[0])) {
62                 /*
63                  * No information from "match_string"
64                  */
65                 data_name = (char *)data;
66                 if (! (data_name && data_name[0])) {
67                         /*
68                          * No information from dissector data
69                          */
70                         data_name = NULL;
71                 }
72         }
73
74         col_set_str(pinfo->cinfo, COL_PROTOCOL, "Layer1");
75         col_set_str(pinfo->cinfo, COL_DEF_SRC,
76                             pinfo->pseudo_header->l1event.uton? "TE" : "NT");
77         len = tvb_find_line_end(tvb, 0, tvb_ensure_length_remaining(tvb, 0),
78                                         &next_offset, FALSE);
79         if(len>0)
80                 col_add_str(pinfo->cinfo, COL_INFO, tvb_format_text(tvb, 0, len));
81
82         if (tree) {
83                 ti = proto_tree_add_item(tree, proto_l1_events,
84                                 tvb, 0, -1, ENC_NA);
85                 if (data_name)
86                         proto_item_append_text(ti, ": %s", data_name);
87                 subtree = proto_item_add_subtree(ti, ett_l1_events);
88                 /* Read the media line by line */
89                 while (tvb_reported_length_remaining(tvb, offset) != 0) {
90                         /*
91                          * XXX - we need to be passed the parameters
92                          * of the content type via data parameter,
93                          * so that we know the character set.  We'd
94                          * have to handle that character set, which
95                          * might be a multibyte character set such
96                          * as "iso-10646-ucs-2", or might require other
97                          * special processing.
98                          */
99                         len = tvb_find_line_end(tvb, offset,
100                                         tvb_ensure_length_remaining(tvb, offset),
101                                         &next_offset, FALSE);
102                         if (len == -1)
103                                 break;
104
105                         /* We use next_offset - offset instead of len in the
106                          * call to proto_tree_add_format_text() so it will include the
107                          * line terminator(s) (\r and/or \n) in the display.
108                          */
109                         proto_tree_add_format_text(subtree, tvb, offset, next_offset - offset);
110                         offset = next_offset;
111                 }
112         }
113
114         return tvb_length(tvb);
115 }
116
117 void
118 proto_register_l1_events(void)
119 {
120         static gint *ett[] = {
121                 &ett_l1_events,
122         };
123
124         proto_register_subtree_array(ett, array_length(ett));
125
126         proto_l1_events = proto_register_protocol(
127                         "Layer 1 Event Messages", /* Long name */
128                         "Layer 1 Events",         /* Short name */
129                         "data-l1-events");              /* Filter name */
130         new_register_dissector("data-l1-events", dissect_l1_events, proto_l1_events);
131 }
132
133 void
134 proto_reg_handoff_l1_events(void)
135 {
136         dissector_handle_t l1_events_handle;
137
138         l1_events_handle = find_dissector("data-l1-events");
139         dissector_add_uint("wtap_encap", WTAP_ENCAP_LAYER1_EVENT, l1_events_handle); /* for text msgs from trace files */
140 }
141
142 /*
143  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
144  *
145  * Local variables:
146  * c-basic-offset: 8
147  * tab-width: 8
148  * indent-tabs-mode: t
149  * End:
150  *
151  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
152  * :indentSize=8:tabSize=8:noTabs=false:
153  */