2004-01-13 07:55:24 +00:00
|
|
|
/* packet-text-media.c
|
|
|
|
* Routines for text-based media dissection.
|
|
|
|
*
|
|
|
|
* NOTE - The media type is either found in pinfo->match_string
|
2004-03-08 22:03:59 +00:00
|
|
|
* or in pinfo->private_data.
|
2004-01-13 07:55:24 +00:00
|
|
|
*
|
2004-03-08 22:03:59 +00:00
|
|
|
* (C) Olivier Biot, 2004.
|
2004-01-13 07:55:24 +00:00
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2004-03-08 22:03:59 +00:00
|
|
|
*
|
|
|
|
* Refer to the AUTHORS file or the AUTHORS section in the man page
|
|
|
|
* for contacting the author(s) of this file.
|
2004-01-13 07:55:24 +00:00
|
|
|
*
|
2006-05-21 04:49:01 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2004-01-13 07:55:24 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Edit this file with 4-space tabs */
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <epan/strutil.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Media dissector for line-based text media like text/plain, message/http.
|
|
|
|
*
|
|
|
|
* TODO - character set and chunked transfer-coding
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Filterable header fields */
|
|
|
|
static gint proto_text_lines = -1;
|
|
|
|
|
|
|
|
/* Subtrees */
|
|
|
|
static gint ett_text_lines = -1;
|
|
|
|
|
|
|
|
static void
|
|
|
|
dissect_text_lines(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|
|
|
{
|
|
|
|
proto_tree *subtree;
|
|
|
|
proto_item *ti;
|
|
|
|
gint offset = 0, next_offset;
|
|
|
|
gint len;
|
|
|
|
const char *data_name;
|
|
|
|
|
|
|
|
data_name = pinfo->match_string;
|
|
|
|
if (! (data_name && data_name[0])) {
|
|
|
|
/*
|
|
|
|
* No information from "match_string"
|
|
|
|
*/
|
|
|
|
data_name = (char *)(pinfo->private_data);
|
|
|
|
if (! (data_name && data_name[0])) {
|
|
|
|
/*
|
|
|
|
* No information from "private_data"
|
|
|
|
*/
|
|
|
|
data_name = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data_name && check_col(pinfo->cinfo, COL_INFO))
|
2004-02-16 18:47:57 +00:00
|
|
|
col_append_sep_fstr(pinfo->cinfo, COL_INFO, " ", "(%s)",
|
|
|
|
data_name);
|
2004-01-13 07:55:24 +00:00
|
|
|
|
|
|
|
if (tree) {
|
|
|
|
ti = proto_tree_add_item(tree, proto_text_lines,
|
|
|
|
tvb, 0, -1, FALSE);
|
|
|
|
if (data_name)
|
|
|
|
proto_item_append_text(ti, ": %s", data_name);
|
|
|
|
subtree = proto_item_add_subtree(ti, ett_text_lines);
|
|
|
|
/* Read the media line by line */
|
|
|
|
while (tvb_reported_length_remaining(tvb, offset) != 0) {
|
|
|
|
/*
|
|
|
|
* XXX - we need to be passed the parameters
|
|
|
|
* of the content type via "pinfo->private_data",
|
|
|
|
* so that we know the character set. We'd
|
|
|
|
* have to handle that character set, which
|
|
|
|
* might be a multibyte character set such
|
|
|
|
* as "iso-10646-ucs-2", or might require other
|
|
|
|
* special processing.
|
|
|
|
*/
|
|
|
|
len = tvb_find_line_end(tvb, offset,
|
|
|
|
tvb_ensure_length_remaining(tvb, offset),
|
|
|
|
&next_offset, FALSE);
|
|
|
|
if (len == -1)
|
|
|
|
break;
|
2006-12-06 23:34:28 +00:00
|
|
|
|
|
|
|
/* We use next_offset - offset instead of len in the
|
|
|
|
* call to tvb_format_text() so it will include the
|
|
|
|
* line terminator(s) (\r and/or \n) in the display.
|
|
|
|
*/
|
2004-01-13 07:55:24 +00:00
|
|
|
proto_tree_add_text(subtree, tvb, offset, next_offset - offset,
|
2006-12-06 23:34:28 +00:00
|
|
|
"%s", tvb_format_text(tvb, offset,
|
|
|
|
next_offset - offset));
|
2004-01-13 07:55:24 +00:00
|
|
|
offset = next_offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_register_text_lines(void)
|
|
|
|
{
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_text_lines,
|
|
|
|
};
|
|
|
|
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
|
|
|
|
proto_text_lines = proto_register_protocol(
|
|
|
|
"Line-based text data", /* Long name */
|
|
|
|
"Line-based text data", /* Short name */
|
|
|
|
"data-text-lines"); /* Filter name */
|
|
|
|
register_dissector("data-text-lines", dissect_text_lines, proto_text_lines);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_text_lines(void)
|
|
|
|
{
|
2008-09-27 14:02:23 +00:00
|
|
|
dissector_handle_t text_lines_handle;
|
|
|
|
|
|
|
|
text_lines_handle = find_dissector("data-text-lines");
|
2004-01-13 07:55:24 +00:00
|
|
|
|
2006-08-15 18:13:35 +00:00
|
|
|
dissector_add_string("media_type", "text/plain", text_lines_handle); /* RFC 2046 */
|
|
|
|
dissector_add_string("media_type", "text/richtext", text_lines_handle); /* RFC 1341 */
|
|
|
|
dissector_add_string("media_type", "text/enriched", text_lines_handle); /* RFC 1896 */
|
2004-01-13 07:55:24 +00:00
|
|
|
/* W3C line-based textual media */
|
|
|
|
dissector_add_string("media_type", "text/html", text_lines_handle);
|
2004-05-04 07:24:33 +00:00
|
|
|
dissector_add_string("media_type", "text/xml-external-parsed-entity", text_lines_handle);
|
2004-01-13 07:55:24 +00:00
|
|
|
dissector_add_string("media_type", "text/css", text_lines_handle);
|
2004-05-04 07:24:33 +00:00
|
|
|
dissector_add_string("media_type", "application/xml-external-parsed-entity", text_lines_handle);
|
2007-11-01 22:14:46 +00:00
|
|
|
dissector_add_string("media_type", "text/javascript", text_lines_handle);
|
2004-01-13 07:55:24 +00:00
|
|
|
dissector_add_string("media_type", "application/x-javascript", text_lines_handle);
|
|
|
|
dissector_add_string("media_type", "application/x-www-form-urlencoded", text_lines_handle);
|
|
|
|
dissector_add_string("media_type", "application/x-ns-proxy-autoconfig", text_lines_handle);
|
2005-09-08 22:51:12 +00:00
|
|
|
|
2004-01-13 07:55:24 +00:00
|
|
|
dissector_add_string("media_type", "text/vnd.sun.j2me.app-descriptor", text_lines_handle);
|
2004-06-17 20:49:01 +00:00
|
|
|
dissector_add_string("media_type", "application/vnd.poc.refer-to", text_lines_handle);
|
2007-01-18 11:02:26 +00:00
|
|
|
dissector_add_string("media_type", "application/vnd.drm.message", text_lines_handle);
|
2007-07-30 13:06:01 +00:00
|
|
|
|
|
|
|
dissector_add_string("media_type", "application/json", text_lines_handle); /* RFC 4627 */
|
2007-10-24 21:47:13 +00:00
|
|
|
|
|
|
|
dissector_add_string("media_type", "application/x-wms-logplaystats", text_lines_handle);
|
|
|
|
dissector_add_string("media_type", "application/x-rtsp-udp-packetpair", text_lines_handle);
|
2004-01-13 07:55:24 +00:00
|
|
|
}
|