2 * Routines for text-based media dissection.
4 * NOTE - The media type is either found in pinfo->match_string
5 * or in pinfo->private_data.
7 * (C) Olivier Biot, 2004.
11 * Refer to the AUTHORS file or the AUTHORS section in the man page
12 * for contacting the author(s) of this file.
14 * Wireshark - Network traffic analyzer
15 * By Gerald Combs <gerald@wireshark.org>
16 * Copyright 1998 Gerald Combs
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version 2
21 * of the License, or (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 /* Edit this file with 4-space tabs */
42 #include <epan/packet.h>
43 #include <epan/strutil.h>
47 * Media dissector for line-based text media like text/plain, message/http.
49 * TODO - character set and chunked transfer-coding
52 /* Filterable header fields */
53 static gint proto_text_lines = -1;
56 static gint ett_text_lines = -1;
58 /* Dissector handles */
59 static dissector_handle_t xml_handle;
62 dissect_text_lines(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
66 gint offset = 0, next_offset;
68 const char *data_name;
70 int length = tvb_length(tvb);
72 /* Check if this is actually xml
73 * If there is less than 38 characters this is not XML
74 * <?xml version="1.0" encoding="UTF-8"?>
77 tvb_get_nstringz0(tvb, 0, sizeof(word),word);
78 if (g_ascii_strncasecmp(word, "<?xml", 5) == 0){
79 call_dissector(xml_handle, tvb, pinfo, tree);
84 data_name = pinfo->match_string;
85 if (! (data_name && data_name[0])) {
87 * No information from "match_string"
89 data_name = (char *)(pinfo->private_data);
90 if (! (data_name && data_name[0])) {
92 * No information from "private_data"
98 if (data_name && check_col(pinfo->cinfo, COL_INFO))
99 col_append_sep_fstr(pinfo->cinfo, COL_INFO, " ", "(%s)",
103 ti = proto_tree_add_item(tree, proto_text_lines,
106 proto_item_append_text(ti, ": %s", data_name);
107 subtree = proto_item_add_subtree(ti, ett_text_lines);
108 /* Read the media line by line */
109 while (tvb_reported_length_remaining(tvb, offset) != 0) {
111 * XXX - we need to be passed the parameters
112 * of the content type via "pinfo->private_data",
113 * so that we know the character set. We'd
114 * have to handle that character set, which
115 * might be a multibyte character set such
116 * as "iso-10646-ucs-2", or might require other
117 * special processing.
119 len = tvb_find_line_end(tvb, offset,
120 tvb_ensure_length_remaining(tvb, offset),
121 &next_offset, FALSE);
125 /* We use next_offset - offset instead of len in the
126 * call to tvb_format_text() so it will include the
127 * line terminator(s) (\r and/or \n) in the display.
129 proto_tree_add_text(subtree, tvb, offset, next_offset - offset,
130 "%s", tvb_format_text(tvb, offset,
131 next_offset - offset));
132 offset = next_offset;
138 proto_register_text_lines(void)
140 static gint *ett[] = {
144 proto_register_subtree_array(ett, array_length(ett));
146 proto_text_lines = proto_register_protocol(
147 "Line-based text data", /* Long name */
148 "Line-based text data", /* Short name */
149 "data-text-lines"); /* Filter name */
150 register_dissector("data-text-lines", dissect_text_lines, proto_text_lines);
154 proto_reg_handoff_text_lines(void)
156 dissector_handle_t text_lines_handle;
158 text_lines_handle = find_dissector("data-text-lines");
160 dissector_add_string("media_type", "text/plain", text_lines_handle); /* RFC 2046 */
161 dissector_add_string("media_type", "text/richtext", text_lines_handle); /* RFC 1341 */
162 dissector_add_string("media_type", "text/enriched", text_lines_handle); /* RFC 1896 */
163 /* W3C line-based textual media */
164 dissector_add_string("media_type", "text/html", text_lines_handle);
165 dissector_add_string("media_type", "text/xml-external-parsed-entity", text_lines_handle);
166 dissector_add_string("media_type", "text/css", text_lines_handle);
167 dissector_add_string("media_type", "application/xml-external-parsed-entity", text_lines_handle);
168 dissector_add_string("media_type", "text/javascript", text_lines_handle);
169 dissector_add_string("media_type", "application/x-javascript", text_lines_handle);
170 dissector_add_string("media_type", "application/x-www-form-urlencoded", text_lines_handle);
171 dissector_add_string("media_type", "application/x-ns-proxy-autoconfig", text_lines_handle);
173 dissector_add_string("media_type", "text/vnd.sun.j2me.app-descriptor", text_lines_handle);
174 dissector_add_string("media_type", "application/vnd.poc.refer-to", text_lines_handle);
175 dissector_add_string("media_type", "application/vnd.drm.message", text_lines_handle);
177 dissector_add_string("media_type", "application/x-wms-logplaystats", text_lines_handle);
178 dissector_add_string("media_type", "application/x-rtsp-udp-packetpair", text_lines_handle);
180 xml_handle = find_dissector("xml");