Get rid of an unused variable.
[obnox/wireshark/wip.git] / packet-text-media.c
1 /* packet-text-media.c\r
2  * Routines for text-based media dissection.\r
3  *\r
4  * NOTE - The media type is either found in pinfo->match_string\r
5  *        or in pinfo->provate_data.\r
6  *\r
7  * (C) Olivier Biot, 2004 <Olivier.Biot (ad) siemens.com>\r
8  *\r
9  * $Id: packet-text-media.c,v 1.2 2004/01/10 02:54:50 obiot Exp $\r
10  *\r
11  * Ethereal - Network traffic analyzer\r
12  * By Gerald Combs <gerald@ethereal.com>\r
13  * Copyright 1998 Gerald Combs\r
14  *\r
15  * This program is free software; you can redistribute it and/or\r
16  * modify it under the terms of the GNU General Public License\r
17  * as published by the Free Software Foundation; either version 2\r
18  * of the License, or (at your option) any later version.\r
19  *\r
20  * This program is distributed in the hope that it will be useful,\r
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
23  * GNU General Public License for more details.\r
24  *\r
25  * You should have received a copy of the GNU General Public License\r
26  * along with this program; if not, write to the Free Software\r
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
28  */\r
29 \r
30 /* Edit this file with 4-space tabs */\r
31 \r
32 #ifdef HAVE_CONFIG_H\r
33 #include "config.h"\r
34 #endif\r
35 \r
36 #include <string.h>\r
37 #include <ctype.h>\r
38 \r
39 #include <glib.h>\r
40 #include <epan/packet.h>\r
41 #include <epan/strutil.h>\r
42 \r
43 \r
44 /*\r
45  * Media dissector for line-based text media like text/plain, message/http.\r
46  *\r
47  * TODO - character set and chunked transfer-coding\r
48  */\r
49 \r
50 /* Filterable header fields */\r
51 static gint proto_text_lines = -1;\r
52 \r
53 /* Subtrees */\r
54 static gint ett_text_lines = -1;\r
55 \r
56 /* Dissector handles */\r
57 static dissector_handle_t text_lines_handle;\r
58 \r
59 static void\r
60 dissect_text_lines(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)\r
61 {\r
62         proto_tree      *subtree;\r
63         proto_item      *ti;\r
64         gint            offset = 0, next_offset;\r
65         gint            len;\r
66         const char      *data_name;\r
67 \r
68         data_name = pinfo->match_string;\r
69         if (! (data_name && data_name[0])) {\r
70                 /*\r
71                  * No information from "match_string"\r
72                  */\r
73                 data_name = (char *)(pinfo->private_data);\r
74                 if (! (data_name && data_name[0])) {\r
75                         /*\r
76                          * No information from "private_data"\r
77                          */\r
78                         data_name = NULL;\r
79                 }\r
80         }\r
81 \r
82         if (data_name && check_col(pinfo->cinfo, COL_INFO))\r
83                 col_append_fstr(pinfo->cinfo, COL_INFO, " (%s)", data_name);\r
84 \r
85         if (tree) {\r
86                 ti = proto_tree_add_item(tree, proto_text_lines,\r
87                                 tvb, 0, -1, FALSE);\r
88                 if (data_name)\r
89                         proto_item_append_text(ti, ": %s", data_name);\r
90                 subtree = proto_item_add_subtree(ti, ett_text_lines);\r
91                 /* Read the media line by line */\r
92                 while (tvb_reported_length_remaining(tvb, offset) != 0) {\r
93                         len = tvb_find_line_end(tvb, offset,\r
94                                         tvb_ensure_length_remaining(tvb, offset),\r
95                                         &next_offset, FALSE);\r
96                         if (len == -1)\r
97                                 break;\r
98                         proto_tree_add_text(subtree, tvb, offset, next_offset - offset,\r
99                                         "%s", tvb_format_text(tvb, offset, len));\r
100                         offset = next_offset;\r
101                 }\r
102         }\r
103 }\r
104 \r
105 void\r
106 proto_register_text_lines(void)\r
107 {\r
108         static gint *ett[] = {\r
109                 &ett_text_lines,\r
110         };\r
111 \r
112         proto_register_subtree_array(ett, array_length(ett));\r
113 \r
114         proto_text_lines = proto_register_protocol(\r
115                         "Line-based text data", /* Long name */\r
116                         "Line-based text data", /* Short name */\r
117                         "data-text-lines");             /* Filter name */\r
118         register_dissector("data-text-lines", dissect_text_lines, proto_text_lines);\r
119 }\r
120 \r
121 void\r
122 proto_reg_handoff_text_lines(void)\r
123 {\r
124         text_lines_handle = create_dissector_handle(\r
125                                         dissect_text_lines, proto_text_lines);\r
126 \r
127         dissector_add_string("media_type", "text/plain", text_lines_handle);\r
128         /* W3C line-based textual media */\r
129         dissector_add_string("media_type", "text/html", text_lines_handle);\r
130         dissector_add_string("media_type", "text/css", text_lines_handle);\r
131         dissector_add_string("media_type", "application/xml", text_lines_handle);\r
132         dissector_add_string("media_type", "application/x-javascript", text_lines_handle);\r
133         dissector_add_string("media_type", "application/x-www-form-urlencoded", text_lines_handle);\r
134         dissector_add_string("media_type", "application/x-ns-proxy-autoconfig", text_lines_handle);\r
135         /* WAP line-based textual media */\r
136         dissector_add_string("media_type", "text/vnd.wap.wml", text_lines_handle);\r
137         dissector_add_string("media_type", "text/vnd.wap.si", text_lines_handle);\r
138         dissector_add_string("media_type", "text/vnd.wap.sl", text_lines_handle);\r
139         dissector_add_string("media_type", "text/vnd.wap.co", text_lines_handle);\r
140         dissector_add_string("media_type", "text/vnd.wap.emn", text_lines_handle);\r
141         /* Other */\r
142         dissector_add_string("media_type", "text/vnd.sun.j2me.app-descriptor", text_lines_handle);\r
143 }\r