Removed trailing whitespaces from .h and .c files using the
[obnox/wireshark/wip.git] / packet-cups.c
index e87dda7fcd2466c38fe22204cdc41f398a689a1f..d52a2d8aeae0f9974b70ae9b7f37954d6e4c581c 100644 (file)
@@ -5,8 +5,7 @@
 * Charles Levert <charles@comm.polymtl.ca>
 * Copyright 2001 Charles Levert
 *
-* $Id: packet-cups.c,v 1.4 2001/03/15 07:03:13 guy Exp $
-*
+* $Id: packet-cups.c,v 1.11 2002/08/02 23:35:48 jmayer Exp $
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 #include "config.h"
 #endif
 
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-
 #include <string.h>
 #include <ctype.h>
 
 #include <glib.h>
-#include "packet.h"
-#include "strutil.h"
+#include <epan/packet.h>
+#include <epan/strutil.h>
 
 /**********************************************************************/
 
@@ -124,7 +119,8 @@ typedef enum _cups_state {
 static const value_string cups_state_values[] = {
        { CUPS_IDLE,            "idle" },
        { CUPS_PROCESSING,      "processing" },
-       { CUPS_STOPPED,         "stopped" }
+       { CUPS_STOPPED,         "stopped" },
+       { 0,                    NULL }
 };
 
 static int proto_cups = -1;
@@ -164,14 +160,14 @@ dissect_cups(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        cups_ptype_t    ptype;
        unsigned int    state;
 
-       if (check_col(pinfo->fd, COL_PROTOCOL))
-               col_set_str(pinfo->fd, COL_PROTOCOL, PROTO_TAG_CUPS);
-       if (check_col(pinfo->fd, COL_INFO))
-               col_clear(pinfo->fd, COL_INFO);
+       if (check_col(pinfo->cinfo, COL_PROTOCOL))
+               col_set_str(pinfo->cinfo, COL_PROTOCOL, PROTO_TAG_CUPS);
+       if (check_col(pinfo->cinfo, COL_INFO))
+               col_clear(pinfo->cinfo, COL_INFO);
 
        if (tree) {
-               ti = proto_tree_add_item(tree, proto_cups, tvb, offset,
-                   tvb_length_remaining(tvb, offset), FALSE);
+               ti = proto_tree_add_item(tree, proto_cups, tvb, offset, -1,
+                   FALSE);
                cups_tree = proto_item_add_subtree(ti, ett_cups);
        }
 
@@ -180,17 +176,20 @@ dissect_cups(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
        ptype = get_hex_uint(tvb, offset, &next_offset);
        len = next_offset - offset;
-       if (cups_tree) {
-               ti = proto_tree_add_uint(cups_tree, hf_cups_ptype,
-                   tvb, offset, len, ptype);
-               ptype_subtree = proto_item_add_subtree(ti, ett_cups_ptype);
-               for (u = 0; u < N_CUPS_PTYPE_BITS; u++) {
-                       proto_tree_add_text(ptype_subtree, tvb, offset, len,
-                           "%s",
-                           decode_boolean_bitfield(ptype,
-                             cups_ptype_bits[u].bit, sizeof (ptype)*8,
-                             cups_ptype_bits[u].on_string,
-                             cups_ptype_bits[u].off_string));
+       if (len != 0) {
+               if (cups_tree) {
+                       ti = proto_tree_add_uint(cups_tree, hf_cups_ptype,
+                           tvb, offset, len, ptype);
+                       ptype_subtree = proto_item_add_subtree(ti,
+                           ett_cups_ptype);
+                       for (u = 0; u < N_CUPS_PTYPE_BITS; u++) {
+                               proto_tree_add_text(ptype_subtree, tvb,
+                                   offset, len, "%s",
+                                   decode_boolean_bitfield(ptype,
+                                     cups_ptype_bits[u].bit, sizeof (ptype)*8,
+                                     cups_ptype_bits[u].on_string,
+                                     cups_ptype_bits[u].off_string));
+                       }
                }
        }
        offset = next_offset;
@@ -201,9 +200,11 @@ dissect_cups(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
        state = get_hex_uint(tvb, offset, &next_offset);
        len = next_offset - offset;
-       if (cups_tree)
-               proto_tree_add_uint(cups_tree, hf_cups_state,
-                   tvb, offset, len, state);
+       if (len != 0) {
+               if (cups_tree)
+                       proto_tree_add_uint(cups_tree, hf_cups_state,
+                           tvb, offset, len, state);
+       }
        offset = next_offset;
 
        if (!skip_space(tvb, offset, &next_offset))
@@ -211,12 +212,14 @@ dissect_cups(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        offset = next_offset;
 
        str = get_unquoted_string(tvb, offset, &next_offset, &len);
+       if (str == NULL)
+               return; /* separator/terminator not found */
        if (cups_tree)
                proto_tree_add_text(cups_tree, tvb, offset, len,
                    "URI: %.*s",
                    (guint16) len, str);
-       if (check_col(pinfo->fd, COL_INFO))
-               col_add_fstr(pinfo->fd, COL_INFO,
+       if (check_col(pinfo->cinfo, COL_INFO))
+               col_add_fstr(pinfo->cinfo, COL_INFO,
                    "%.*s (%s)",
                    (guint16) len, str,
                    val_to_str(state, cups_state_values, "0x%x"));
@@ -230,6 +233,8 @@ dissect_cups(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        offset = next_offset;
 
        str = get_quoted_string(tvb, offset, &next_offset, &len);
+       if (str == NULL)
+               return; /* separator/terminator not found */
        proto_tree_add_text(cups_tree, tvb, offset+1, len,
            "Location: \"%.*s\"",
            (guint16) len, str);
@@ -240,6 +245,8 @@ dissect_cups(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        offset = next_offset;
 
        str = get_quoted_string(tvb, offset, &next_offset, &len);
+       if (str == NULL)
+               return; /* separator/terminator not found */
        proto_tree_add_text(cups_tree, tvb, offset+1, len,
            "Information: \"%.*s\"",
            (guint16) len, str);
@@ -250,6 +257,8 @@ dissect_cups(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        offset = next_offset;
 
        str = get_quoted_string(tvb, offset, &next_offset, &len);
+       if (str == NULL)
+               return; /* separator/terminator not found */
        proto_tree_add_text(cups_tree, tvb, offset+1, len,
            "Make and model: \"%.*s\"",
            (guint16) len, str);
@@ -353,11 +362,11 @@ proto_register_cups(void)
                /* This one could be split in separate fields. */
                { &hf_cups_ptype,
                        { "Type",       "cups.ptype", FT_UINT32, BASE_HEX,
-                         NULL, 0x0, ""}},
+                         NULL, 0x0, "", HFILL }},
 
                { &hf_cups_state,
                        { "State",      "cups.state", FT_UINT8, BASE_HEX,
-                         VALS(cups_state_values), 0x0, "" }}
+                         VALS(cups_state_values), 0x0, "", HFILL }}
        };
 
        static gint *ett[] = {
@@ -375,5 +384,8 @@ proto_register_cups(void)
 void
 proto_reg_handoff_cups(void)
 {
-       dissector_add("udp.port", UDP_PORT_CUPS, dissect_cups, proto_cups);
+       dissector_handle_t cups_handle;
+
+       cups_handle = create_dissector_handle(dissect_cups, proto_cups);
+       dissector_add("udp.port", UDP_PORT_CUPS, cups_handle);
 }