HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-text-media.c
blobe53de719a407d33b8d3f3eaa82d5ee4c8c9fd6a7
1 /* packet-text-media.c
2 * Routines for text-based media dissection.
4 * NOTE - The media type is either found in pinfo->match_string,
5 * pinfo->private_data, or passed into the dissector (preferred)
7 * (C) Olivier Biot, 2004.
9 * $Id$
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 /* Edit this file with 4-space tabs */
35 #include "config.h"
37 #include <glib.h>
39 #include <epan/packet.h>
43 * Media dissector for line-based text media like text/plain, message/http.
45 * TODO - character set and chunked transfer-coding
48 /* Filterable header fields */
49 static gint proto_text_lines = -1;
51 /* Subtrees */
52 static gint ett_text_lines = -1;
54 /* Dissector handles */
55 static dissector_handle_t xml_handle;
57 static int
58 dissect_text_lines(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
60 proto_tree *subtree;
61 proto_item *ti;
62 gint offset = 0, next_offset;
63 gint len;
64 const char *data_name;
65 guint8 word[6];
66 int length = tvb_length(tvb);
68 /* Check if this is actually xml
69 * If there is less than 38 characters this is not XML
70 * <?xml version="1.0" encoding="UTF-8"?>
72 if(length > 38){
73 tvb_get_nstringz0(tvb, 0, sizeof(word),word);
74 if (g_ascii_strncasecmp(word, "<?xml", 5) == 0){
75 call_dissector(xml_handle, tvb, pinfo, tree);
76 return tvb_length(tvb);
80 data_name = pinfo->match_string;
81 if (! (data_name && data_name[0])) {
83 * No information from "match_string"
85 data_name = (char *)data;
86 if (! (data_name && data_name[0])) {
88 * No information from dissector data
90 data_name = (char *)(pinfo->private_data);
91 if (! (data_name && data_name[0])) {
93 * No information from "private_data"
95 data_name = NULL;
100 if (data_name)
101 col_append_sep_fstr(pinfo->cinfo, COL_INFO, " ", "(%s)",
102 data_name);
104 if (tree) {
105 ti = proto_tree_add_item(tree, proto_text_lines,
106 tvb, 0, -1, ENC_NA);
107 if (data_name)
108 proto_item_append_text(ti, ": %s", data_name);
109 subtree = proto_item_add_subtree(ti, ett_text_lines);
110 /* Read the media line by line */
111 while (tvb_reported_length_remaining(tvb, offset) != 0) {
113 * XXX - we need to be passed the parameters
114 * of the content type via "pinfo->private_data",
115 * so that we know the character set. We'd
116 * have to handle that character set, which
117 * might be a multibyte character set such
118 * as "iso-10646-ucs-2", or might require other
119 * special processing.
121 len = tvb_find_line_end(tvb, offset,
122 tvb_ensure_length_remaining(tvb, offset),
123 &next_offset, FALSE);
124 if (len == -1)
125 break;
127 /* We use next_offset - offset instead of len in the
128 * call to tvb_format_text() so it will include the
129 * line terminator(s) (\r and/or \n) in the display.
131 proto_tree_add_text(subtree, tvb, offset, next_offset - offset,
132 "%s", tvb_format_text(tvb, offset,
133 next_offset - offset));
134 offset = next_offset;
138 return tvb_length(tvb);
141 void
142 proto_register_text_lines(void)
144 static gint *ett[] = {
145 &ett_text_lines,
148 proto_register_subtree_array(ett, array_length(ett));
150 proto_text_lines = proto_register_protocol(
151 "Line-based text data", /* Long name */
152 "Line-based text data", /* Short name */
153 "data-text-lines"); /* Filter name */
154 new_register_dissector("data-text-lines", dissect_text_lines, proto_text_lines);
157 void
158 proto_reg_handoff_text_lines(void)
160 dissector_handle_t text_lines_handle;
162 text_lines_handle = find_dissector("data-text-lines");
164 dissector_add_string("media_type", "text/plain", text_lines_handle); /* RFC 2046 */
165 dissector_add_string("media_type", "text/richtext", text_lines_handle); /* RFC 1341 */
166 dissector_add_string("media_type", "text/enriched", text_lines_handle); /* RFC 1896 */
167 dissector_add_string("media_type", "text/parameters", text_lines_handle);
168 /* W3C line-based textual media */
169 dissector_add_string("media_type", "text/html", text_lines_handle);
170 dissector_add_string("media_type", "text/xml-external-parsed-entity", text_lines_handle);
171 dissector_add_string("media_type", "text/css", text_lines_handle);
172 dissector_add_string("media_type", "application/xml-external-parsed-entity", text_lines_handle);
173 dissector_add_string("media_type", "text/javascript", text_lines_handle);
174 dissector_add_string("media_type", "application/x-javascript", text_lines_handle);
175 dissector_add_string("media_type", "application/x-tia-p25-issi", text_lines_handle);
176 dissector_add_string("media_type", "application/x-tia-p25-sndcp", text_lines_handle);
177 dissector_add_string("media_type", "application/x-ns-proxy-autoconfig", text_lines_handle);
179 dissector_add_string("media_type", "text/vnd.sun.j2me.app-descriptor", text_lines_handle);
180 dissector_add_string("media_type", "application/vnd.poc.refer-to", text_lines_handle);
181 dissector_add_string("media_type", "application/vnd.drm.message", text_lines_handle);
183 dissector_add_string("media_type", "application/x-wms-logplaystats", text_lines_handle);
184 dissector_add_string("media_type", "application/x-rtsp-udp-packetpair", text_lines_handle);
185 xml_handle = find_dissector("xml");