aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2003-04-16 04:52:55 +0000
committerGuy Harris <guy@alum.mit.edu>2003-04-16 04:52:55 +0000
commit24ec2110d129373d9652f1667eed8faa075cd8f0 (patch)
treed91c4e7b602692fac4cd86a53d42ce5230bcf3c0
parent77923868c96774a53ece0d097329dd20834ce6a9 (diff)
Add the notion of a "fence" to columns. A dissector can set the fence
to "protect" what's currently in the column, so that attempts to clear the column will only clear stuff after the fence and attempts to overwrite the column will append stuff after the fence. This, for example, allows a dissector to arrange that the Info column contain information for its protocol and for protocols running atop it. svn path=/trunk/; revision=7466
-rw-r--r--epan/column-utils.c160
-rw-r--r--epan/column-utils.h3
-rw-r--r--epan/column_info.h7
-rw-r--r--epan/packet.c3
-rw-r--r--gtk/main.c3
-rw-r--r--tethereal.c4
6 files changed, 143 insertions, 37 deletions
diff --git a/epan/column-utils.c b/epan/column-utils.c
index dcec9ce15b..006b66d509 100644
--- a/epan/column-utils.c
+++ b/epan/column-utils.c
@@ -1,7 +1,7 @@
/* column-utils.c
* Routines for column utilities.
*
- * $Id: column-utils.c,v 1.32 2003/01/28 18:35:40 guy Exp $
+ * $Id: column-utils.c,v 1.33 2003/04/16 04:52:52 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -57,6 +57,7 @@ col_init(column_info *col_info, gint num_cols)
col_info->col_title = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
col_info->col_data = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
col_info->col_buf = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
+ col_info->col_fence = (int *) g_malloc(sizeof(int) * num_cols);
col_info->col_expr = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
col_info->col_expr_val = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
}
@@ -89,7 +90,19 @@ check_col(column_info *cinfo, gint el) {
return FALSE;
}
+/* Sets the fence for a column to be at the end of the column. */
+void
+col_set_fence(column_info *cinfo, gint el)
+{
+ int i;
+ if (cinfo && cinfo->writable) {
+ for (i = 0; i < cinfo->num_cols; i++) {
+ if (cinfo->fmt_matx[i][el])
+ cinfo->col_fence[i] = strlen(cinfo->col_data[i]);
+ }
+ }
+}
/* Use this to clear out a column, especially if you're going to be
appending to it later; at least on some platforms, it's more
@@ -98,28 +111,88 @@ check_col(column_info *cinfo, gint el) {
later append to it, as the later append will cause a string
copy to be done. */
void
-col_clear(column_info *cinfo, gint el) {
+col_clear(column_info *cinfo, gint el)
+{
int i;
+ int fence;
for (i = 0; i < cinfo->num_cols; i++) {
if (cinfo->fmt_matx[i][el]) {
- cinfo->col_buf[i][0] = 0;
- cinfo->col_data[i] = cinfo->col_buf[i];
+ /*
+ * At this point, either
+ *
+ * 1) col_data[i] is equal to col_buf[i], in which case we
+ * don't have to worry about copying col_data[i] to
+ * col_buf[i];
+ *
+ * 2) col_data[i] isn't equal to col_buf[i], in which case
+ * the only thing that's been done to the column is
+ * "col_set_str()" calls and possibly "col_set_fence()"
+ * calls, in which case the fence is either unset and
+ * at the beginning of the string or set and at the end
+ * of the string - if it's at the beginning, we're just
+ * going to clear the column, and if it's at the end,
+ * we don't do anything.
+ */
+ fence = cinfo->col_fence[i];
+ if (fence == 0 || cinfo->col_buf[i] == cinfo->col_data[i]) {
+ /*
+ * The fence isn't at the end of the column, or the column wasn't
+ * last set with "col_set_str()", so clear the column out.
+ */
+ cinfo->col_buf[i][fence] = '\0';
+ cinfo->col_data[i] = cinfo->col_buf[i];
+ }
cinfo->col_expr[i][0] = '\0';
cinfo->col_expr_val[i][0] = '\0';
}
}
}
+#define COL_CHECK_APPEND(cinfo, i, max_len) \
+ if (cinfo->col_data[i] != cinfo->col_buf[i]) { \
+ /* This was set with "col_set_str()"; copy the string they \
+ set it to into the buffer, so we can append to it. */ \
+ strncpy(cinfo->col_buf[i], cinfo->col_data[i], max_len); \
+ cinfo->col_buf[i][max_len - 1] = '\0'; \
+ cinfo->col_data[i] = cinfo->col_buf[i]; \
+ }
+
/* Use this if "str" points to something that will stay around (and thus
needn't be copied). */
void
-col_set_str(column_info *cinfo, gint el, gchar* str) {
+col_set_str(column_info *cinfo, gint el, gchar* str)
+{
int i;
+ int fence;
+ size_t len, max_len;
+
+ if (el == COL_INFO)
+ max_len = COL_MAX_INFO_LEN;
+ else
+ max_len = COL_MAX_LEN;
for (i = 0; i < cinfo->num_cols; i++) {
- if (cinfo->fmt_matx[i][el])
- cinfo->col_data[i] = str;
+ if (cinfo->fmt_matx[i][el]) {
+ fence = cinfo->col_fence[i];
+ if (fence != 0) {
+ /*
+ * We will append the string after the fence.
+ * First arrange that we can append, if necessary.
+ */
+ COL_CHECK_APPEND(cinfo, i, max_len);
+
+ len = strlen(cinfo->col_buf[i]);
+ strncat(cinfo->col_buf[i], str, max_len - len);
+ cinfo->col_buf[i][max_len - 1] = 0;
+ } else {
+ /*
+ * There's no fence, so we can just set the column to point
+ * to the string.
+ */
+ cinfo->col_data[i] = str;
+ }
+ }
}
}
@@ -128,6 +201,7 @@ void
col_add_fstr(column_info *cinfo, gint el, const gchar *format, ...) {
va_list ap;
int i;
+ int fence;
size_t max_len;
if (el == COL_INFO)
@@ -138,8 +212,20 @@ col_add_fstr(column_info *cinfo, gint el, const gchar *format, ...) {
va_start(ap, format);
for (i = 0; i < cinfo->num_cols; i++) {
if (cinfo->fmt_matx[i][el]) {
- vsnprintf(cinfo->col_buf[i], max_len, format, ap);
- cinfo->col_data[i] = cinfo->col_buf[i];
+ fence = cinfo->col_fence[i];
+ if (fence != 0) {
+ /*
+ * We will append the string after the fence.
+ * First arrange that we can append, if necessary.
+ */
+ COL_CHECK_APPEND(cinfo, i, max_len);
+ } else {
+ /*
+ * There's no fence, so we can just write to the string.
+ */
+ cinfo->col_data[i] = cinfo->col_buf[i];
+ }
+ vsnprintf(&cinfo->col_buf[i][fence], max_len - fence, format, ap);
}
}
va_end(ap);
@@ -147,7 +233,8 @@ col_add_fstr(column_info *cinfo, gint el, const gchar *format, ...) {
/* Appends a vararg list to a packet info string. */
void
-col_append_fstr(column_info *cinfo, gint el, const gchar *format, ...) {
+col_append_fstr(column_info *cinfo, gint el, const gchar *format, ...)
+{
va_list ap;
int i;
size_t len, max_len;
@@ -160,15 +247,12 @@ col_append_fstr(column_info *cinfo, gint el, const gchar *format, ...) {
va_start(ap, format);
for (i = 0; i < cinfo->num_cols; i++) {
if (cinfo->fmt_matx[i][el]) {
- if (cinfo->col_data[i] != cinfo->col_buf[i]) {
- /* This was set with "col_set_str()"; copy the string they
- set it to into the buffer, so we can append to it. */
- strncpy(cinfo->col_buf[i], cinfo->col_data[i], max_len);
- cinfo->col_buf[i][max_len - 1] = '\0';
- }
+ /*
+ * First arrange that we can append, if necessary.
+ */
+ COL_CHECK_APPEND(cinfo, i, max_len);
len = strlen(cinfo->col_buf[i]);
vsnprintf(&cinfo->col_buf[i][len], max_len - len, format, ap);
- cinfo->col_data[i] = cinfo->col_buf[i];
}
}
va_end(ap);
@@ -203,6 +287,14 @@ col_prepend_fstr(column_info *cinfo, gint el, const gchar *format, ...)
orig[max_len - 1] = '\0';
}
vsnprintf(cinfo->col_buf[i], max_len, format, ap);
+ cinfo->col_buf[i][max_len - 1] = '\0';
+
+ /*
+ * Move the fence, unless it's at the beginning of the string.
+ */
+ if (cinfo->col_fence[i] > 0)
+ cinfo->col_fence[i] += strlen(cinfo->col_buf[i]);
+
strncat(cinfo->col_buf[i], orig, max_len);
cinfo->col_buf[i][max_len - 1] = '\0';
cinfo->col_data[i] = cinfo->col_buf[i];
@@ -214,8 +306,10 @@ col_prepend_fstr(column_info *cinfo, gint el, const gchar *format, ...)
/* Use this if "str" points to something that won't stay around (and
must thus be copied). */
void
-col_add_str(column_info *cinfo, gint el, const gchar* str) {
+col_add_str(column_info *cinfo, gint el, const gchar* str)
+{
int i;
+ int fence;
size_t max_len;
if (el == COL_INFO)
@@ -225,15 +319,28 @@ col_add_str(column_info *cinfo, gint el, const gchar* str) {
for (i = 0; i < cinfo->num_cols; i++) {
if (cinfo->fmt_matx[i][el]) {
- strncpy(cinfo->col_buf[i], str, max_len);
+ fence = cinfo->col_fence[i];
+ if (fence != 0) {
+ /*
+ * We will append the string after the fence.
+ * First arrange that we can append, if necessary.
+ */
+ COL_CHECK_APPEND(cinfo, i, max_len);
+ } else {
+ /*
+ * There's no fence, so we can just write to the string.
+ */
+ cinfo->col_data[i] = cinfo->col_buf[i];
+ }
+ strncpy(&cinfo->col_buf[i][fence], str, max_len - fence);
cinfo->col_buf[i][max_len - 1] = 0;
- cinfo->col_data[i] = cinfo->col_buf[i];
}
}
}
void
-col_append_str(column_info *cinfo, gint el, const gchar* str) {
+col_append_str(column_info *cinfo, gint el, const gchar* str)
+{
int i;
size_t len, max_len;
@@ -244,16 +351,13 @@ col_append_str(column_info *cinfo, gint el, const gchar* str) {
for (i = 0; i < cinfo->num_cols; i++) {
if (cinfo->fmt_matx[i][el]) {
- if (cinfo->col_data[i] != cinfo->col_buf[i]) {
- /* This was set with "col_set_str()"; copy the string they
- set it to into the buffer, so we can append to it. */
- strncpy(cinfo->col_buf[i], cinfo->col_data[i], max_len);
- cinfo->col_buf[i][max_len - 1] = '\0';
- }
+ /*
+ * First arrange that we can append, if necessary.
+ */
+ COL_CHECK_APPEND(cinfo, i, max_len);
len = strlen(cinfo->col_buf[i]);
strncat(cinfo->col_buf[i], str, max_len - len);
cinfo->col_buf[i][max_len - 1] = 0;
- cinfo->col_data[i] = cinfo->col_buf[i];
}
}
}
diff --git a/epan/column-utils.h b/epan/column-utils.h
index 512667e31d..9c331fe703 100644
--- a/epan/column-utils.h
+++ b/epan/column-utils.h
@@ -1,7 +1,7 @@
/* column-utils.h
* Definitions for column utility structures and routines
*
- * $Id: column-utils.h,v 1.9 2002/12/02 23:34:38 guy Exp $
+ * $Id: column-utils.h,v 1.10 2003/04/16 04:52:53 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -42,6 +42,7 @@ extern void col_init(column_info *, gint);
extern gboolean col_get_writable(column_info *);
extern void col_set_writable(column_info *, gboolean);
extern gint check_col(column_info *, gint);
+extern void col_set_fence(column_info *, gint);
extern void col_clear(column_info *, gint);
extern void col_set_str(column_info *, gint, gchar *);
#if __GNUC__ >= 2
diff --git a/epan/column_info.h b/epan/column_info.h
index 1aa14e45ae..8498fd1bba 100644
--- a/epan/column_info.h
+++ b/epan/column_info.h
@@ -1,13 +1,12 @@
/* column.h
* Definitions for column structures and routines
*
- * $Id: column_info.h,v 1.7 2003/01/22 06:26:36 guy Exp $
+ * $Id: column_info.h,v 1.8 2003/04/16 04:52:53 guy Exp $
*
* Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * 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
@@ -23,7 +22,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-
#ifndef __COLUMN_INFO_H__
#define __COLUMN_INFO_H__
@@ -40,6 +38,7 @@ typedef struct _column_info {
gchar **col_title; /* Column titles */
gchar **col_data; /* Column data */
gchar **col_buf; /* Buffer into which to copy data for column */
+ int *col_fence; /* Stuff in column buffer before this index is immutable */
gchar **col_expr; /* Filter expression */
gchar **col_expr_val; /* Value for filter expression */
gboolean writable; /* Are we stil writing to the columns? */
diff --git a/epan/packet.c b/epan/packet.c
index 992b9f5a42..d9562f0ce0 100644
--- a/epan/packet.c
+++ b/epan/packet.c
@@ -1,7 +1,7 @@
/* packet.c
* Routines for packet disassembly
*
- * $Id: packet.c,v 1.88 2003/03/01 09:38:41 guy Exp $
+ * $Id: packet.c,v 1.89 2003/04/16 04:52:53 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -255,6 +255,7 @@ dissect_packet(epan_dissect_t *edt, union wtap_pseudo_header *pseudo_header,
for (i = 0; i < cinfo->num_cols; i++) {
cinfo->col_buf[i][0] = '\0';
cinfo->col_data[i] = cinfo->col_buf[i];
+ cinfo->col_fence[i] = 0;
cinfo->col_expr[i][0] = '\0';
cinfo->col_expr_val[i][0] = '\0';
}
diff --git a/gtk/main.c b/gtk/main.c
index 0810ef3d1d..7c56bec410 100644
--- a/gtk/main.c
+++ b/gtk/main.c
@@ -1,6 +1,6 @@
/* main.c
*
- * $Id: main.c,v 1.286 2003/03/12 00:07:46 guy Exp $
+ * $Id: main.c,v 1.287 2003/04/16 04:52:55 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -1963,6 +1963,7 @@ main(int argc, char *argv[])
cfile.cinfo.col_buf[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_INFO_LEN);
else
cfile.cinfo.col_buf[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
+ cfile.cinfo.col_fence[i] = 0;
cfile.cinfo.col_expr[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
cfile.cinfo.col_expr_val[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
}
diff --git a/tethereal.c b/tethereal.c
index 2a2a548be4..8de42a8d59 100644
--- a/tethereal.c
+++ b/tethereal.c
@@ -1,6 +1,6 @@
/* tethereal.c
*
- * $Id: tethereal.c,v 1.178 2003/03/12 00:07:32 guy Exp $
+ * $Id: tethereal.c,v 1.179 2003/04/16 04:52:50 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -792,7 +792,7 @@ main(int argc, char *argv[])
cfile.cinfo.col_buf[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_INFO_LEN);
else
cfile.cinfo.col_buf[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
-
+ cfile.cinfo.col_fence[i] = 0;
cfile.cinfo.col_expr[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
cfile.cinfo.col_expr_val[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
}