From Aaron Woo (via Jeff Weston): Optimized Link State Routing Protocol
[obnox/wireshark/wip.git] / packet-text-media.c
index 41a14370d149befb90a7e3af5681d8253dbef6d5..a1a51b471ae5fb0d4f6801b45957e33d870a05eb 100644 (file)
-/* packet-text-media.c\r
- * Routines for text-based media dissection.\r
- *\r
- * NOTE - The media type is either found in pinfo->match_string\r
- *        or in pinfo->provate_data.\r
- *\r
- * (C) Olivier Biot, 2004 <Olivier.Biot (ad) siemens.com>\r
- *\r
- * $Id: packet-text-media.c,v 1.1 2004/01/10 02:38:38 obiot Exp $\r
- *\r
- * Ethereal - Network traffic analyzer\r
- * By Gerald Combs <gerald@ethereal.com>\r
- * Copyright 1998 Gerald Combs\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
- */\r
-\r
-/* Edit this file with 4-space tabs */\r
-\r
-#ifdef HAVE_CONFIG_H\r
-#include "config.h"\r
-#endif\r
-\r
-#include <string.h>\r
-#include <ctype.h>\r
-\r
-#include <glib.h>\r
-#include <epan/packet.h>\r
-#include <epan/strutil.h>\r
-\r
-\r
-/*\r
- * Media dissector for line-based text media like text/plain, message/http.\r
- *\r
- * TODO - character set and chunked transfer-coding\r
- */\r
-\r
-static gint proto_text_lines = -1;\r
-static gint ett_text_lines = -1;\r
-static dissector_handle_t text_lines_handle;\r
-\r
-static const char default_data_name[] = "Line-based text data";\r
-\r
-static void\r
-dissect_text_lines(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)\r
-{\r
-       proto_tree      *subtree;\r
-       proto_item      *ti;\r
-       gint            offset = 0, next_offset;\r
-       gint            len;\r
-       const char      *data_name;\r
-\r
-       data_name = pinfo->match_string;\r
-       if (! (data_name && data_name[0])) {\r
-               /*\r
-                * No information from "match_string"\r
-                */\r
-               data_name = (char *)(pinfo->private_data);\r
-               if (! (data_name && data_name[0])) {\r
-                       /*\r
-                        * No information from "private_data"\r
-                        */\r
-                       data_name = NULL;\r
-               }\r
-       }\r
-\r
-       if (data_name && check_col(pinfo->cinfo, COL_INFO))\r
-               col_append_fstr(pinfo->cinfo, COL_INFO, " (%s)", data_name);\r
-\r
-       if (tree) {\r
-               ti = proto_tree_add_item(tree, proto_text_lines,\r
-                               tvb, 0, -1, FALSE);\r
-               if (data_name)\r
-                       proto_item_append_text(ti, ": %s", data_name);\r
-               subtree = proto_item_add_subtree(ti, ett_text_lines);\r
-               /* Read the media line by line */\r
-               while (tvb_reported_length_remaining(tvb, offset) != 0) {\r
-                       len = tvb_find_line_end(tvb, offset,\r
-                                       tvb_ensure_length_remaining(tvb, offset),\r
-                                       &next_offset, FALSE);\r
-                       if (len == -1)\r
-                               break;\r
-                       proto_tree_add_text(subtree, tvb, offset, next_offset - offset,\r
-                                       "%s", tvb_format_text(tvb, offset, len));\r
-                       offset = next_offset;\r
-               }\r
-       }\r
-}\r
-\r
-void\r
-proto_register_text_lines(void)\r
-{\r
-       static gint *ett[] = {\r
-               &ett_text_lines,\r
-       };\r
-\r
-       proto_register_subtree_array(ett, array_length(ett));\r
-\r
-       proto_text_lines = proto_register_protocol(\r
-                       "Line-based text data", /* Long name */\r
-                       "Line-based text data", /* Short name */\r
-                       "data-text-lines");             /* Filter name */\r
-       register_dissector("data-text-lines", dissect_text_lines, proto_text_lines);\r
-}\r
-\r
-void\r
-proto_reg_handoff_text_lines(void)\r
-{\r
-       text_lines_handle = create_dissector_handle(\r
-                                       dissect_text_lines, proto_text_lines);\r
-\r
-       dissector_add_string("media_type", "text/plain", text_lines_handle);\r
-       /* W3C line-based textual media */\r
-       dissector_add_string("media_type", "text/html", text_lines_handle);\r
-       dissector_add_string("media_type", "text/css", text_lines_handle);\r
-       dissector_add_string("media_type", "application/xml", text_lines_handle);\r
-       dissector_add_string("media_type", "application/x-javascript", text_lines_handle);\r
-       dissector_add_string("media_type", "application/x-www-form-urlencoded", text_lines_handle);\r
-       dissector_add_string("media_type", "application/x-ns-proxy-autoconfig", text_lines_handle);\r
-       /* WAP line-based textual media */\r
-       dissector_add_string("media_type", "text/vnd.wap.wml", text_lines_handle);\r
-       dissector_add_string("media_type", "text/vnd.wap.si", text_lines_handle);\r
-       dissector_add_string("media_type", "text/vnd.wap.sl", text_lines_handle);\r
-       dissector_add_string("media_type", "text/vnd.wap.co", text_lines_handle);\r
-       dissector_add_string("media_type", "text/vnd.wap.emn", text_lines_handle);\r
-       /* Other */\r
-       dissector_add_string("media_type", "text/vnd.sun.j2me.app-descriptor", text_lines_handle);\r
-}\r
+/* packet-text-media.c
+ * Routines for text-based media dissection.
+ *
+ * NOTE - The media type is either found in pinfo->match_string
+ *        or in pinfo->provate_data.
+ *
+ * (C) Olivier Biot, 2004 <Olivier.Biot (ad) siemens.com>
+ *
+ * $Id: packet-text-media.c,v 1.3 2004/01/13 07:55:24 guy Exp $
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@ethereal.com>
+ * 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;
+
+/* Dissector handles */
+static dissector_handle_t text_lines_handle;
+
+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))
+               col_append_fstr(pinfo->cinfo, COL_INFO, " (%s)", data_name);
+
+       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;
+                       proto_tree_add_text(subtree, tvb, offset, next_offset - offset,
+                                       "%s", tvb_format_text(tvb, offset, len));
+                       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)
+{
+       text_lines_handle = create_dissector_handle(
+                                       dissect_text_lines, proto_text_lines);
+
+       dissector_add_string("media_type", "text/plain", text_lines_handle);
+       /* W3C line-based textual media */
+       dissector_add_string("media_type", "text/html", text_lines_handle);
+       dissector_add_string("media_type", "text/css", text_lines_handle);
+       dissector_add_string("media_type", "application/xml", text_lines_handle);
+       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);
+       /* WAP line-based textual media */
+       dissector_add_string("media_type", "text/vnd.wap.wml", text_lines_handle);
+       dissector_add_string("media_type", "text/vnd.wap.si", text_lines_handle);
+       dissector_add_string("media_type", "text/vnd.wap.sl", text_lines_handle);
+       dissector_add_string("media_type", "text/vnd.wap.co", text_lines_handle);
+       dissector_add_string("media_type", "text/vnd.wap.emn", text_lines_handle);
+       /* Other */
+       dissector_add_string("media_type", "text/vnd.sun.j2me.app-descriptor", text_lines_handle);
+}