Minor spelling etc updates.
[metze/wireshark/wip.git] / packet-pop.c
index ad73038174ac7e962dde30d48aa75b025f965c44..b8c23bafa3413d63a13db8a014ba0bb42b6b61fb 100644 (file)
@@ -2,24 +2,24 @@
  * Routines for pop packet dissection
  * Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
  *
- * $Id: packet-pop.c,v 1.23 2001/01/09 06:31:40 guy Exp $
+ * $Id: packet-pop.c,v 1.33 2002/08/28 21:00:25 jmayer Exp $
  *
  * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * By Gerald Combs <gerald@ethereal.com>
  * Copyright 1998 Gerald Combs
  *
  * Copied from packet-tftp.c
- * 
+ *
  * 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.
 
 #include <stdio.h>
 
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
-#ifdef HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-
 #include <string.h>
 #include <glib.h>
-#include "packet.h"
-#include "strutil.h"
+#include <epan/packet.h>
+#include <epan/strutil.h>
 
 static int proto_pop = -1;
 static int hf_pop_response = -1;
@@ -50,10 +42,12 @@ static int hf_pop_request = -1;
 
 static gint ett_pop = -1;
 
+static dissector_handle_t data_handle;
+
 #define TCP_PORT_POP                   110
 
-static gboolean response_is_continuation(const u_char *data);
-       
+static gboolean response_is_continuation(const guchar *data);
+
 static void
 dissect_pop(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
@@ -62,23 +56,23 @@ dissect_pop(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
         proto_tree      *pop_tree;
        proto_item      *ti;
        gint            offset = 0;
-       const u_char    *line;
+       const guchar    *line;
        gint            next_offset;
        int             linelen;
        int             tokenlen;
-       const u_char    *next_token;
+       const guchar    *next_token;
 
-       CHECK_DISPLAY_AS_DATA(proto_pop, tvb, pinfo, tree);
-
-       pinfo->current_proto = "POP";
-
-       if (check_col(pinfo->fd, COL_PROTOCOL))
-               col_set_str(pinfo->fd, COL_PROTOCOL, "POP");
+       if (check_col(pinfo->cinfo, COL_PROTOCOL))
+               col_set_str(pinfo->cinfo, COL_PROTOCOL, "POP");
 
        /*
         * Find the end of the first line.
+        *
+        * Note that "tvb_find_line_end()" will return a value that is
+        * not longer than what's in the buffer, so the "tvb_get_ptr()"
+        * call won't throw an exception.
         */
-       linelen = tvb_find_line_end(tvb, offset, -1, &next_offset);
+       linelen = tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE);
        line = tvb_get_ptr(tvb, offset, linelen);
 
        if (pinfo->match_port == pinfo->destport) {
@@ -89,7 +83,7 @@ dissect_pop(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                is_continuation = response_is_continuation(line);
        }
 
-       if (check_col(pinfo->fd, COL_INFO)) {
+       if (check_col(pinfo->cinfo, COL_INFO)) {
                /*
                 * Put the first line from the buffer into the summary
                 * if it's a POP request or reply (but leave out the
@@ -97,23 +91,23 @@ dissect_pop(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                 * Otherwise, just call it a continuation.
                 */
                if (is_continuation)
-                       col_set_str(pinfo->fd, COL_INFO, "Continuation");
+                       col_set_str(pinfo->cinfo, COL_INFO, "Continuation");
                else
-                       col_add_fstr(pinfo->fd, COL_INFO, "%s: %s",
+                       col_add_fstr(pinfo->cinfo, COL_INFO, "%s: %s",
                            is_request ? "Request" : "Response",
                            format_text(line, linelen));
        }
 
        if (tree) {
-               ti = proto_tree_add_item(tree, proto_pop, tvb, offset,
-                   tvb_length_remaining(tvb, offset), FALSE);
+               ti = proto_tree_add_item(tree, proto_pop, tvb, offset, -1,
+                   FALSE);
                pop_tree = proto_item_add_subtree(ti, ett_pop);
 
                if (is_continuation) {
                        /*
                         * Put the whole packet into the tree as data.
                         */
-                       dissect_data(tvb, 0, pinfo, pop_tree);
+                       call_dissector(data_handle,tvb, pinfo, pop_tree);
                        return;
                }
 
@@ -171,7 +165,7 @@ dissect_pop(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                         * Find the end of the line.
                         */
                        linelen = tvb_find_line_end(tvb, offset, -1,
-                           &next_offset);
+                           &next_offset, FALSE);
 
                        /*
                         * Put this line.
@@ -184,7 +178,7 @@ dissect_pop(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        }
 }
 
-static gboolean response_is_continuation(const u_char *data)
+static gboolean response_is_continuation(const guchar *data)
 {
   if (strncmp(data, "+OK", strlen("+OK")) == 0)
     return FALSE;
@@ -203,12 +197,12 @@ proto_register_pop(void)
     { &hf_pop_response,
       { "Response",           "pop.response",
        FT_BOOLEAN, BASE_NONE, NULL, 0x0,
-       "TRUE if POP response" }},
+       "TRUE if POP response", HFILL }},
 
     { &hf_pop_request,
       { "Request",            "pop.request",
        FT_BOOLEAN, BASE_NONE, NULL, 0x0,
-       "TRUE if POP request" }}
+       "TRUE if POP request", HFILL }}
   };
   static gint *ett[] = {
     &ett_pop,
@@ -222,5 +216,9 @@ proto_register_pop(void)
 void
 proto_reg_handoff_pop(void)
 {
-  dissector_add("tcp.port", TCP_PORT_POP, dissect_pop, proto_pop);
+  dissector_handle_t pop_handle;
+
+  pop_handle = create_dissector_handle(dissect_pop, proto_pop);
+  dissector_add("tcp.port", TCP_PORT_POP, pop_handle);
+  data_handle = find_dissector("data");
 }