aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2008-02-22 22:47:19 +0000
committerStig Bjørlykke <stig@bjorlykke.org>2008-02-22 22:47:19 +0000
commit51b26f95f3cb88a528f089096d8afeb2d81c2004 (patch)
treef4bed2fedbbbf26138ec196abe668d41572904f5 /epan
parent396d5b4c4c02ea062a144a65c1c644e624063f89 (diff)
Improved custom columns with custom title.
Fixed a crash when adding an empty custom field. svn path=/trunk/; revision=24438
Diffstat (limited to 'epan')
-rw-r--r--epan/column-utils.c10
-rw-r--r--epan/column.c15
-rw-r--r--epan/column.h2
-rw-r--r--epan/column_info.h1
-rw-r--r--epan/prefs.c39
5 files changed, 57 insertions, 10 deletions
diff --git a/epan/column-utils.c b/epan/column-utils.c
index a472206652..df1062b003 100644
--- a/epan/column-utils.c
+++ b/epan/column-utils.c
@@ -60,6 +60,7 @@ col_setup(column_info *cinfo, gint num_cols)
cinfo->col_first = (int *) g_malloc(sizeof(int) * (NUM_COL_FMTS));
cinfo->col_last = (int *) g_malloc(sizeof(int) * (NUM_COL_FMTS));
cinfo->col_title = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
+ cinfo->col_custom_field = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
cinfo->col_data = (const gchar **) g_malloc(sizeof(gchar *) * num_cols);
cinfo->col_buf = (gchar **) g_malloc(sizeof(gchar *) * num_cols);
cinfo->col_fence = (int *) g_malloc(sizeof(int) * num_cols);
@@ -282,8 +283,8 @@ col_custom_set_fstr(const gchar *field_name, const gchar *format, ...)
va_start(ap, format);
for (i = ci->col_first[COL_CUSTOM];
i <= ci->col_last[COL_CUSTOM]; i++) {
- if (strcmp(ci->col_title[i], field_name) == 0 &&
- ci->fmt_matx[i][COL_CUSTOM]) {
+ if (ci->fmt_matx[i][COL_CUSTOM] &&
+ strcmp(ci->col_custom_field[i], field_name) == 0) {
ci->col_data[i] = ci->col_buf[i];
g_vsnprintf(ci->col_buf[i], COL_MAX_LEN, format, ap);
strncpy(ci->col_expr[i], field_name, COL_MAX_LEN);
@@ -307,8 +308,9 @@ col_custom_prime_edt(epan_dissect_t *edt, column_info *cinfo)
for (i = cinfo->col_first[COL_CUSTOM];
i <= cinfo->col_last[COL_CUSTOM]; i++) {
- if (cinfo->fmt_matx[i][COL_CUSTOM]) {
- if(dfilter_compile(cinfo->col_title[i], &dfilter_code))
+ if (cinfo->fmt_matx[i][COL_CUSTOM] &&
+ strlen(cinfo->col_custom_field[i]) > 0) {
+ if(dfilter_compile(cinfo->col_custom_field[i], &dfilter_code))
epan_dissect_prime_dfilter(edt, dfilter_code);
}
}
diff --git a/epan/column.c b/epan/column.c
index a50bcbd93d..a549a3b979 100644
--- a/epan/column.c
+++ b/epan/column.c
@@ -647,6 +647,16 @@ get_column_title(gint col) {
return(cfmt->title);
}
+gchar *
+get_column_custom_field(gint col) {
+ GList *clp = g_list_nth(prefs.col_list, col);
+ fmt_data *cfmt;
+
+ cfmt = (fmt_data *) clp->data;
+
+ return(cfmt->custom_field);
+}
+
void
build_column_format_array(capture_file *cfile, gboolean reset_fences)
{
@@ -657,6 +667,11 @@ build_column_format_array(capture_file *cfile, gboolean reset_fences)
for (i = 0; i < cfile->cinfo.num_cols; i++) {
cfile->cinfo.col_fmt[i] = get_column_format(i);
cfile->cinfo.col_title[i] = g_strdup(get_column_title(i));
+ if (cfile->cinfo.col_fmt[i] == COL_CUSTOM) {
+ cfile->cinfo.col_custom_field[i] = g_strdup(get_column_custom_field(i));
+ } else {
+ cfile->cinfo.col_custom_field[i] = NULL;
+ }
cfile->cinfo.fmt_matx[i] = (gboolean *) g_malloc0(sizeof(gboolean) *
NUM_COL_FMTS);
get_column_format_matches(cfile->cinfo.fmt_matx[i],
diff --git a/epan/column.h b/epan/column.h
index 43ec2aa581..78aea67d5b 100644
--- a/epan/column.h
+++ b/epan/column.h
@@ -32,6 +32,7 @@ extern "C" {
typedef struct _fmt_data {
gchar *title;
gchar *fmt;
+ gchar *custom_field;
} fmt_data;
const gchar *col_format_to_string(gint);
@@ -40,6 +41,7 @@ gint get_column_format(gint);
void get_column_format_matches(gboolean *, gint);
gint get_column_format_from_str(gchar *);
gchar *get_column_title(gint);
+gchar *get_column_custom_field(gint);
const gchar *get_column_width_string(gint, gint);
const char *get_column_longest_string(gint);
gint get_column_char_width(gint format);
diff --git a/epan/column_info.h b/epan/column_info.h
index e71c874529..5d86085035 100644
--- a/epan/column_info.h
+++ b/epan/column_info.h
@@ -41,6 +41,7 @@ typedef struct _column_info {
gint *col_first; /* First column number with a given format */
gint *col_last; /* Last column number with a given format */
gchar **col_title; /* Column titles */
+ gchar **col_custom_field; /* Custom column field */
const 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 */
diff --git a/epan/prefs.c b/epan/prefs.c
index 6ba297f42a..5bcbb42447 100644
--- a/epan/prefs.c
+++ b/epan/prefs.c
@@ -1088,6 +1088,7 @@ init_prefs(void) {
cfmt = (fmt_data *) g_malloc(sizeof(fmt_data));
cfmt->title = g_strdup(col_fmt[i * 2]);
cfmt->fmt = g_strdup(col_fmt[(i * 2) + 1]);
+ cfmt->custom_field = NULL;
prefs.col_list = g_list_append(prefs.col_list, cfmt);
}
prefs.num_cols = DEF_NUM_COLS;
@@ -1783,6 +1784,8 @@ set_pref(gchar *pref_name, gchar *value, void *private_data _U_)
module_t *module;
pref_t *pref;
gboolean had_a_dot;
+ const gchar *cust_format = col_format_to_string(COL_CUSTOM);
+ int cust_format_len = strlen(cust_format);
if (strcmp(pref_name, PRS_PRINT_FMT) == 0) {
if (strcmp(value, pr_formats[PR_FMT_TEXT]) == 0) {
@@ -1829,10 +1832,12 @@ set_pref(gchar *pref_name, gchar *value, void *private_data _U_)
col_l_elt = col_l_elt->next;
/* Check the format. */
- if (get_column_format_from_str(col_l_elt->data) == -1) {
- /* It's not a valid column format. */
- clear_string_list(col_l);
- return PREFS_SET_SYNTAX_ERR;
+ if (strncmp(col_l_elt->data, cust_format, cust_format_len) != 0) {
+ if (get_column_format_from_str(col_l_elt->data) == -1) {
+ /* It's not a valid column format. */
+ clear_string_list(col_l);
+ return PREFS_SET_SYNTAX_ERR;
+ }
}
/* Go past the format. */
@@ -1847,7 +1852,15 @@ set_pref(gchar *pref_name, gchar *value, void *private_data _U_)
cfmt = (fmt_data *) g_malloc(sizeof(fmt_data));
cfmt->title = g_strdup(col_l_elt->data);
col_l_elt = col_l_elt->next;
- cfmt->fmt = g_strdup(col_l_elt->data);
+ if (strncmp(col_l_elt->data, cust_format, cust_format_len) == 0) {
+ gchar *fmt = g_strdup(col_l_elt->data);
+ cfmt->fmt = g_strdup(cust_format);
+ cfmt->custom_field = g_strdup(&fmt[cust_format_len+1]); /* add 1 for ':' */
+ g_free (fmt);
+ } else {
+ cfmt->fmt = g_strdup(col_l_elt->data);
+ cfmt->custom_field = NULL;
+ }
col_l_elt = col_l_elt->next;
prefs.col_list = g_list_append(prefs.col_list, cfmt);
}
@@ -2546,6 +2559,7 @@ write_prefs(char **pf_path_return)
FILE *pf;
GList *clp, *col_l;
fmt_data *cfmt;
+ const gchar *cust_format = col_format_to_string(COL_CUSTOM);
/* Needed for "-G defaultprefs" */
init_prefs();
@@ -2704,7 +2718,12 @@ write_prefs(char **pf_path_return)
while (clp) {
cfmt = (fmt_data *) clp->data;
col_l = g_list_append(col_l, cfmt->title);
- col_l = g_list_append(col_l, cfmt->fmt);
+ if ((strcmp(cfmt->fmt, cust_format) == 0) && (cfmt->custom_field)) {
+ gchar *fmt = g_strdup_printf("%s:%s", cfmt->fmt, cfmt->custom_field);
+ col_l = g_list_append(col_l, fmt);
+ } else {
+ col_l = g_list_append(col_l, cfmt->fmt);
+ }
clp = clp->next;
}
fprintf (pf, "\n# Packet list column format.\n");
@@ -2884,6 +2903,11 @@ copy_prefs(e_prefs *dest, e_prefs *src)
dest_cfmt = (fmt_data *) g_malloc(sizeof(fmt_data));
dest_cfmt->title = g_strdup(src_cfmt->title);
dest_cfmt->fmt = g_strdup(src_cfmt->fmt);
+ if (src_cfmt->custom_field) {
+ dest_cfmt->custom_field = g_strdup(src_cfmt->custom_field);
+ } else {
+ dest_cfmt->custom_field = NULL;
+ }
dest->col_list = g_list_append(dest->col_list, dest_cfmt);
}
dest->num_cols = src->num_cols;
@@ -2988,6 +3012,9 @@ free_col_info(e_prefs *pr)
cfmt = pr->col_list->data;
g_free(cfmt->title);
g_free(cfmt->fmt);
+ if (cfmt->custom_field) {
+ g_free(cfmt->custom_field);
+ }
g_free(cfmt);
pr->col_list = g_list_remove_link(pr->col_list, pr->col_list);
}