Reverse commit 20209, breaking the build across the board.
[obnox/wireshark/wip.git] / print.c
diff --git a/print.c b/print.c
index 660791e2bb988c8757a420efb8904225bddcb01b..7297c10daf6bd16a9733fcec06cdb58254171b8e 100644 (file)
--- a/print.c
+++ b/print.c
@@ -5,8 +5,8 @@
  *
  * Gilbert Ramirez <gram@alumni.rice.edu>
  *
- * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@ethereal.com>
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
  *
  * This program is free software; you can redistribute it and/or
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 
-/* With MSVC and a libethereal.dll this file needs to import some variables 
-   in a special way. Therefore _NEED_VAR_IMPORT_ is defined. */  
-#define _NEED_VAR_IMPORT_
-
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
@@ -43,7 +39,8 @@
 #include "packet-range.h"
 #include "print.h"
 #include "ps.h"
-#include "util.h"
+#include "file_util.h"
+#include <epan/charsets.h>
 #include <epan/dissectors/packet-data.h>
 #include <epan/dissectors/packet-frame.h>
 
@@ -76,7 +73,7 @@ static gboolean print_hex_data_buffer(print_stream_t *stream, const guchar *cp,
     guint length, char_enc encoding);
 static void ps_clean_string(unsigned char *out, const unsigned char *in,
                        int outbuf_size);
-static void print_escaped_xml(FILE *fh, char *unescaped_string);
+static void print_escaped_xml(FILE *fh, const char *unescaped_string);
 
 static void print_pdml_geninfo(proto_tree *tree, FILE *fh);
 
@@ -87,7 +84,7 @@ open_print_dest(int to_file, const char *dest)
 
        /* Open the file or command for output */
        if (to_file)
-               fh = fopen(dest, "w");
+               fh = eth_fopen(dest, "w");
        else
                fh = popen(dest, "w");
 
@@ -157,11 +154,19 @@ void proto_tree_print_node(proto_node *node, gpointer data)
                proto_item_fill_label(fi, label_str);
        }
 
+       if (PROTO_ITEM_IS_GENERATED(node)) {
+               label_ptr = g_strdup_printf("[%s]", label_ptr);
+       }
+
        if (!print_line(pdata->stream, pdata->level, label_ptr)) {
                pdata->success = FALSE;
                return;
        }
 
+       if (PROTO_ITEM_IS_GENERATED(node)) {
+               g_free(label_ptr);
+       }
+
        /* If it's uninterpreted data, dump it (unless our caller will
           be printing the entire packet in hex). */
        if (fi->hfinfo->id == proto_data && pdata->print_hex_for_data) {
@@ -232,7 +237,7 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data)
 {
        field_info      *fi = PITEM_FINFO(node);
        write_pdml_data *pdata = (write_pdml_data*) data;
-       gchar           *label_ptr;
+       const gchar     *label_ptr;
        gchar           label_str[ITEM_LABEL_LENGTH];
        char            *dfilter_string;
        int             chop_len;
@@ -252,7 +257,9 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data)
                        label_ptr = "";
                }
 
-               fputs("<field show=\"", pdata->fh);
+               /* Show empty name since it is a required field */
+               fputs("<field name=\"", pdata->fh);
+               fputs("\" show=\"", pdata->fh);
                print_escaped_xml(pdata->fh, label_ptr);
 
                fprintf(pdata->fh, "\" size=\"%d", fi->length);
@@ -325,13 +332,19 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data)
                fprintf(pdata->fh, "\" pos=\"%d", fi->start);
 /*             fprintf(pdata->fh, "\" id=\"%d", fi->hfinfo->id);*/
 
-               if (fi->hfinfo->type != FT_PROTOCOL) {
-                       /* Field */
-
+               /* show, value, and unmaskedvalue attributes */
+               switch (fi->hfinfo->type)
+               {
+               case FT_PROTOCOL:
+                       break;
+               case FT_NONE:
+                       fputs("\" show=\"\" value=\"",  pdata->fh);
+                       break;
+               default:
                        /* XXX - this is a hack until we can just call
                         * fvalue_to_string_repr() for *all* FT_* types. */
-                       dfilter_string = proto_construct_dfilter_string(fi,
-                                       pdata->edt);
+                       dfilter_string = proto_construct_match_selected_string(fi,
+                           pdata->edt);
                        if (dfilter_string != NULL) {
                                chop_len = strlen(fi->hfinfo->abbrev) + 4; /* for " == " */
 
@@ -348,9 +361,25 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data)
                                fputs("\" show=\"", pdata->fh);
                                print_escaped_xml(pdata->fh, &dfilter_string[chop_len]);
                        }
+
+                       /*
+                        * XXX - should we omit "value" for any fields?
+                        * What should we do for fields whose length is 0?
+                        * They might come from a pseudo-header or from
+                        * the capture header (e.g., time stamps), or
+                        * they might be generated fields.
+                        */
                        if (fi->length > 0) {
                                fputs("\" value=\"", pdata->fh);
-                               write_pdml_field_hex_value(pdata, fi);
+
+                               if (fi->hfinfo->bitmask!=0) {
+                                       fprintf(pdata->fh, "%X", fvalue_get_integer(&fi->value));
+                                       fputs("\" unmaskedvalue=\"", pdata->fh);
+                                       write_pdml_field_hex_value(pdata, fi);
+                               }
+                               else {
+                                       write_pdml_field_hex_value(pdata, fi);
+                               }
                        }
                }
 
@@ -387,7 +416,7 @@ proto_tree_write_node_pdml(proto_node *node, gpointer data)
 }
 
 /* Print info for a 'geninfo' pseudo-protocol. This is required by
- * the PDML spec. The information is contained in Ethereal's 'frame' protocol,
+ * the PDML spec. The information is contained in Wireshark's 'frame' protocol,
  * but we produce a 'geninfo' protocol in the PDML to conform to spec.
  * The 'frame' protocol follows the 'geninfo' protocol in the PDML. */
 static void
@@ -517,6 +546,37 @@ write_psml_finale(FILE *fh)
        fputs("</psml>\n", fh);
 }
 
+void
+write_csv_preamble(FILE *fh _U_)
+{
+
+}
+
+void
+proto_tree_write_csv(epan_dissect_t *edt, FILE *fh)
+{
+        gint    i;
+
+        /* if this is the first packet, we have to write the CSV header */
+        if(edt->pi.fd->num == 1) {
+            for(i=0; i < edt->pi.cinfo->num_cols - 1; i++)
+               fprintf(fh, "\"%s\",", edt->pi.cinfo->col_title[i]);
+
+            fprintf(fh, "\"%s\"\n", edt->pi.cinfo->col_title[i]);
+        }
+
+        for(i=0; i < edt->pi.cinfo->num_cols - 1; i++)
+            fprintf(fh, "\"%s\",", edt->pi.cinfo->col_data[i]);
+
+        fprintf(fh, "\"%s\"\n", edt->pi.cinfo->col_data[i]);
+}
+
+void
+write_csv_finale(FILE *fh _U_)
+{
+
+}
+
 /*
  * Find the data source for a specified field, and return a pointer
  * to the data in it. Returns NULL if the data is out of bounds.
@@ -561,9 +621,9 @@ get_field_data(GSList *src_list, field_info *fi)
 /* Print a string, escaping out certain characters that need to
  * escaped out for XML. */
 static void
-print_escaped_xml(FILE *fh, char *unescaped_string)
+print_escaped_xml(FILE *fh, const char *unescaped_string)
 {
-       unsigned char *p;
+       const unsigned char *p;
 
        for (p = unescaped_string; *p != '\0'; p++) {
                switch (*p) {
@@ -644,6 +704,8 @@ print_hex_data(print_stream_t *stream, epan_dissect_t *edt)
                        g_free(line);
                }
                length = tvb_length(tvb);
+               if (length == 0)
+                   return TRUE;
                cp = tvb_get_ptr(tvb, 0, length);
                if (!print_hex_data_buffer(stream, cp, length,
                    edt->pi.fd->flags.encoding))
@@ -656,7 +718,7 @@ print_hex_data(print_stream_t *stream, epan_dissect_t *edt)
  * This routine is based on a routine created by Dan Lasley
  * <DLASLEY@PROMUS.com>.
  *
- * It was modified for Ethereal by Gilbert Ramirez and others.
+ * It was modified for Wireshark by Gilbert Ramirez and others.
  */
 
 #define MAX_OFFSET_LEN 8       /* max length of hex offset of bytes */
@@ -960,7 +1022,7 @@ print_preamble_ps(print_stream_t *self, gchar *filename)
        fputs("\n", output->fh);
        fputs("%% the page title\n", output->fh);
        ps_clean_string(psbuffer, filename, MAX_PS_LINE_LENGTH);
-       fprintf(output->fh, "/eth_pagetitle (%s - Ethereal) def\n", psbuffer);
+       fprintf(output->fh, "/eth_pagetitle (%s - Wireshark) def\n", psbuffer);
        fputs("\n", output->fh);
        return !ferror(output->fh);
 }