2 * Routines for text-based media dissection.
4 * NOTE - The media type is either found in pinfo->match_string,
5 * or passed into the dissector
7 * (C) Olivier Biot, 2004.
9 * Refer to the AUTHORS file or the AUTHORS section in the man page
10 * for contacting the author(s) of this file.
12 * Wireshark - Network traffic analyzer
13 * By Gerald Combs <gerald@wireshark.org>
14 * Copyright 1998 Gerald Combs
16 * SPDX-License-Identifier: GPL-2.0-or-later
19 /* Edit this file with 4-space tabs */
23 #include <epan/packet.h>
25 #include "packet-media-type.h"
28 * Media dissector for line-based text media like text/plain, message/http.
30 * TODO - character set and chunked transfer-coding
32 void proto_register_text_lines(void);
33 void proto_reg_handoff_text_lines(void);
35 /* Filterable header fields */
36 static int proto_text_lines
;
39 static int ett_text_lines
;
41 /* Dissector handles */
42 static dissector_handle_t xml_handle
;
45 dissect_text_lines(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data
)
49 int offset
= 0, next_offset
;
51 media_content_info_t
*content_info
;
52 const char *data_name
;
53 int length
= tvb_captured_length(tvb
);
55 /* Check if this is actually xml
56 * If there is less than 38 characters this is not XML
57 * <?xml version="1.0" encoding="UTF-8"?>
60 if (tvb_strncaseeql(tvb
, 0, "<?xml", 5) == 0){
61 call_dissector(xml_handle
, tvb
, pinfo
, tree
);
66 data_name
= pinfo
->match_string
;
67 if (! (data_name
&& data_name
[0])) {
69 * No information from "match_string"
71 content_info
= (media_content_info_t
*)data
;
72 if (content_info
== NULL
) {
74 * No information from dissector data
78 data_name
= content_info
->media_str
;
79 if (! (data_name
&& data_name
[0])) {
81 * No information from dissector data
89 col_append_sep_fstr(pinfo
->cinfo
, COL_INFO
, " ", "(%s)",
93 unsigned lines_read
= 0;
94 ti
= proto_tree_add_item(tree
, proto_text_lines
,
97 proto_item_append_text(ti
, ": %s", data_name
);
98 subtree
= proto_item_add_subtree(ti
, ett_text_lines
);
99 /* Read the media line by line */
100 while (tvb_offset_exists(tvb
, offset
)) {
102 * XXX - we need to be passed the parameters
103 * of the content type via data parameter,
104 * so that we know the character set. We'd
105 * have to handle that character set, which
106 * might be a multibyte character set such
107 * as "iso-10646-ucs-2", or might require other
108 * special processing.
110 len
= tvb_find_line_end(tvb
, offset
, -1, &next_offset
, false);
114 /* We use next_offset - offset instead of len in the
115 * call to proto_tree_add_format_text() so it will include the
116 * line terminator(s) (\r and/or \n) in the display.
118 proto_tree_add_format_text(subtree
, tvb
, offset
, next_offset
- offset
);
120 offset
= next_offset
;
122 proto_item_append_text(subtree
, " (%u lines)", lines_read
);
129 proto_register_text_lines(void)
131 static int *ett
[] = {
135 proto_register_subtree_array(ett
, array_length(ett
));
137 proto_text_lines
= proto_register_protocol("Line-based text data", "Line-based text data", "data-text-lines");
138 register_dissector("data-text-lines", dissect_text_lines
, proto_text_lines
);
142 proto_reg_handoff_text_lines(void)
144 dissector_handle_t text_lines_handle
;
146 text_lines_handle
= find_dissector("data-text-lines");
148 dissector_add_string("media_type", "text/plain", text_lines_handle
); /* RFC 2046 */
149 dissector_add_string("media_type", "text/richtext", text_lines_handle
); /* RFC 1341 */
150 dissector_add_string("media_type", "text/enriched", text_lines_handle
); /* RFC 1896 */
151 dissector_add_string("media_type", "text/parameters", text_lines_handle
);
152 /* W3C line-based textual media */
153 dissector_add_string("media_type", "text/html", text_lines_handle
);
154 dissector_add_string("media_type", "text/xml-external-parsed-entity", text_lines_handle
);
155 dissector_add_string("media_type", "text/css", text_lines_handle
);
156 dissector_add_string("media_type", "application/xml-external-parsed-entity", text_lines_handle
);
157 dissector_add_string("media_type", "text/javascript", text_lines_handle
);
158 dissector_add_string("media_type", "application/x-javascript", text_lines_handle
);
159 dissector_add_string("media_type", "application/x-tia-p25-issi", text_lines_handle
);
160 dissector_add_string("media_type", "application/x-tia-p25-sndcp", text_lines_handle
);
161 dissector_add_string("media_type", "application/x-ns-proxy-autoconfig", text_lines_handle
);
163 dissector_add_string("media_type", "text/vnd.sun.j2me.app-descriptor", text_lines_handle
);
164 dissector_add_string("media_type", "application/vnd.poc.refer-to", text_lines_handle
);
165 dissector_add_string("media_type", "application/vnd.drm.message", text_lines_handle
);
167 dissector_add_string("media_type", "application/x-wms-logplaystats", text_lines_handle
);
168 dissector_add_string("media_type", "application/x-rtsp-udp-packetpair", text_lines_handle
);
169 xml_handle
= find_dissector_add_dependency("xml", proto_text_lines
);
173 * Editor modelines - https://www.wireshark.org/tools/modelines.html
178 * indent-tabs-mode: t
181 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
182 * :indentSize=8:tabSize=8:noTabs=false: