diff options
author | Michal Labedzki <michal.labedzki@tieto.com> | 2014-12-17 11:38:49 +0100 |
---|---|---|
committer | Michal Labedzki <michal.labedzki@tieto.com> | 2014-12-18 11:03:42 +0000 |
commit | 361ea8215d1e39a51579b45eadbedd8288d14b20 (patch) | |
tree | 12b4b8fd9357743f45c3a5f510e16218b683dd54 /epan/column-utils.c | |
parent | f5cd21543d332f6c14da88ebd50730750f791dd4 (diff) |
Add support for multifields in custom column
You can now add column with Custom type with more than one field
by using OR "||" splitter.
Bug: 9695
Change-Id: Ia82a91e7a35b867647d36cb9626e3870f46c0d85
Reviewed-on: https://code.wireshark.org/review/5804
Petri-Dish: Michal Labedzki <michal.labedzki@tieto.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: Michal Labedzki <michal.labedzki@tieto.com>
Diffstat (limited to 'epan/column-utils.c')
-rw-r--r-- | epan/column-utils.c | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/epan/column-utils.c b/epan/column-utils.c index 4bcfded6ee..95615d9961 100644 --- a/epan/column-utils.c +++ b/epan/column-utils.c @@ -59,7 +59,10 @@ col_setup(column_info *cinfo, const gint num_cols) cinfo->col_title = g_new(gchar*, num_cols); cinfo->col_custom_field = g_new(gchar*, num_cols); cinfo->col_custom_occurrence = g_new(gint, num_cols); - cinfo->col_custom_field_id = g_new(int, num_cols); + cinfo->col_custom_field_ids = g_new(GSList *, num_cols); + for (i = 0; i < num_cols; i++) { + cinfo->col_custom_field_ids[i] = NULL; + } cinfo->col_custom_dfilter = g_new(struct epan_dfilter*, num_cols); cinfo->col_data = g_new(const gchar*, num_cols); cinfo->col_buf = g_new(gchar*, num_cols); @@ -73,6 +76,12 @@ col_setup(column_info *cinfo, const gint num_cols) } } +static void +col_custom_field_ids_free(gpointer data) +{ + g_free(data); +} + /* Cleanup all the data structures for constructing column data; undoes the allocations that col_setup() does. */ void @@ -87,6 +96,8 @@ col_cleanup(column_info *cinfo) dfilter_free(cinfo->col_custom_dfilter[i]); g_free(cinfo->col_buf[i]); g_free(cinfo->col_expr.col_expr_val[i]); + if (cinfo->col_custom_field_ids[i]) + g_slist_free_full(cinfo->col_custom_field_ids[i], col_custom_field_ids_free); } g_free(cinfo->col_fmt); @@ -96,7 +107,7 @@ col_cleanup(column_info *cinfo) g_free(cinfo->col_title); g_free(cinfo->col_custom_field); g_free(cinfo->col_custom_occurrence); - g_free(cinfo->col_custom_field_id); + g_free(cinfo->col_custom_field_ids); g_free(cinfo->col_custom_dfilter); /* * XXX - MSVC doesn't correctly handle the "const" qualifier; it thinks @@ -290,9 +301,9 @@ void col_custom_set_edt(epan_dissect_t *edt, column_info *cinfo) i <= cinfo->col_last[COL_CUSTOM]; i++) { if (cinfo->fmt_matx[i][COL_CUSTOM] && cinfo->col_custom_field[i] && - cinfo->col_custom_field_id[i] != -1) { - cinfo->col_data[i] = cinfo->col_buf[i]; - cinfo->col_expr.col_expr[i] = epan_custom_set(edt, cinfo->col_custom_field_id[i], + cinfo->col_custom_field_ids[i]) { + cinfo->col_data[i] = cinfo->col_buf[i]; + cinfo->col_expr.col_expr[i] = epan_custom_set(edt, cinfo->col_custom_field_ids[i], cinfo->col_custom_occurrence[i], cinfo->col_buf[i], cinfo->col_expr.col_expr_val[i], @@ -311,14 +322,38 @@ 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++) { + int i_list = 0; + + if (cinfo->col_custom_field_ids[i]) + g_slist_free_full(cinfo->col_custom_field_ids[i], col_custom_field_ids_free); + + cinfo->col_custom_field_ids[i] = NULL; - cinfo->col_custom_field_id[i] = -1; if (cinfo->fmt_matx[i][COL_CUSTOM] && cinfo->col_custom_dfilter[i]) { epan_dissect_prime_dfilter(edt, cinfo->col_custom_dfilter[i]); if (cinfo->col_custom_field) { - header_field_info* hfinfo = proto_registrar_get_byname(cinfo->col_custom_field[i]); - cinfo->col_custom_field_id[i] = hfinfo ? hfinfo->id : -1; + gchar **fields; + gchar *field; + int i_field = 0; + + fields = g_strsplit(cinfo->col_custom_field[i], " || ", -1); + + while((field = fields[i_field++])) { + int id; + + header_field_info* hfinfo = proto_registrar_get_byname(field); + id = hfinfo ? hfinfo->id : -1; + if (id >= 0) { + int *idx; + + idx = g_new(int, 1); + *idx = id; + cinfo->col_custom_field_ids[i] = g_slist_insert(cinfo->col_custom_field_ids[i], idx, i_list); + i_list += 1; + } + } + g_strfreev(fields); } } } |