summaryrefslogtreecommitdiff
path: root/epan/print.c
diff options
context:
space:
mode:
authorHessam Jalali <hessam.jalali@gmail.com>2016-06-30 21:41:15 +0430
committerPascal Quantin <pascal.quantin@gmail.com>2016-07-01 15:48:41 +0000
commitf3bd70b246a95c7762c3710afa728f646cafa08f (patch)
tree0e8c307e2e741c4be21dda2f3c373e4c2578fa44 /epan/print.c
parentad309999fdff362bbc16dc183ade5103c6a83048 (diff)
downloadwireshark-f3bd70b246a95c7762c3710afa728f646cafa08f.tar.gz
fix missing fields for json, ek and pdml when used with -e fields
Description: when -T json,ed or pdml used in conjunction with -e fields they would always miss the last field. in case of json and ek, if some fields in the middle are empty, the generated json would be invalid. sample for ek: { "_index": "packets-2016-06-30", "_type": "pcap_file", "_score": null, "_source": { "layers": { "e212.mcc": ["255","262"] "frame.time_epoch": ["1426550400.004751510"], "e212.mnc": ["1","1"] } } } command: tshark -T ek -r C:\a.pcap -e e212.mcc -e frame.comment -e frame.time_epoch -e e212.mnc > C:\test.json note: the comma is missing between e212.mcc and frame.time_epoch Change-Id: I2efae0c48036cf6313e2a064453c8dbc49f38b09 Reviewed-on: https://code.wireshark.org/review/16226 Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com> Reviewed-by: Martin Kacer <kacer.martin@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
Diffstat (limited to 'epan/print.c')
-rw-r--r--epan/print.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/epan/print.c b/epan/print.c
index 7bf298c11a..f197b7b7eb 100644
--- a/epan/print.c
+++ b/epan/print.c
@@ -2038,6 +2038,7 @@ static void proto_tree_get_node_field_values(proto_node *node, gpointer data)
static void write_specified_fields(fields_format format, output_fields_t *fields, epan_dissect_t *edt, column_info *cinfo, FILE *fh)
{
gsize i;
+ gboolean first = TRUE;
gint col;
gchar *col_name;
gpointer field_index;
@@ -2131,7 +2132,7 @@ static void write_specified_fields(fields_format format, output_fields_t *fields
fv_p = fields->field_values[i];
/* Output the array of (partial) field values */
- for (j = 0; j < (g_ptr_array_len(fv_p)) - 1; j+=2 ) {
+ for (j = 0; j < (g_ptr_array_len(fv_p)); j+=2 ) {
str = (gchar *)g_ptr_array_index(fv_p, j);
fprintf(fh, " <field name=\"%s\" value=", field);
@@ -2156,10 +2157,13 @@ static void write_specified_fields(fields_format format, output_fields_t *fields
fv_p = fields->field_values[i];
/* Output the array of (partial) field values */
- for (j = 0; j < (g_ptr_array_len(fv_p)) - 1; j+=2 ) {
+ for (j = 0; j < (g_ptr_array_len(fv_p)); j += 2) {
str = (gchar *)g_ptr_array_index(fv_p, j);
if (j == 0) {
+ if (!first) {
+ fputs(",\n", fh);
+ }
fprintf(fh, " \"%s\": [", field);
}
fputs("\"", fh);
@@ -2167,22 +2171,21 @@ static void write_specified_fields(fields_format format, output_fields_t *fields
fputs("\"", fh);
g_free(str);
- if (j + 2 < (g_ptr_array_len(fv_p)) - 1) {
+ if (j + 2 < (g_ptr_array_len(fv_p))) {
fputs(",", fh);
- } else {
+ }
+ else {
fputs("]", fh);
- if ( (i + 1 < fields->fields->len) && (g_ptr_array_len(fields->field_values[i + 1]) > 1) ) {
- fputs(",\n", fh);
- } else {
- fputs("\n", fh);
}
}
- }
+
+ first = FALSE;
g_ptr_array_free(fv_p, TRUE); /* get ready for the next packet */
fields->field_values[i] = NULL;
}
}
+ fputc('\n',fh);
break;
case FORMAT_EK:
for(i = 0; i < fields->fields->len; ++i) {
@@ -2195,10 +2198,13 @@ static void write_specified_fields(fields_format format, output_fields_t *fields
fv_p = fields->field_values[i];
/* Output the array of (partial) field values */
- for (j = 0; j < (g_ptr_array_len(fv_p)) - 1; j+=2 ) {
+ for (j = 0; j < (g_ptr_array_len(fv_p)); j += 2) {
str = (gchar *)g_ptr_array_index(fv_p, j);
if (j == 0) {
+ if (!first) {
+ fputs(",", fh);
+ }
fputs("\"", fh);
print_escaped_ek(fh, field);
fputs("\": [", fh);
@@ -2208,17 +2214,16 @@ static void write_specified_fields(fields_format format, output_fields_t *fields
fputs("\"", fh);
g_free(str);
- if (j + 2 < (g_ptr_array_len(fv_p)) - 1) {
+ if (j + 2 < (g_ptr_array_len(fv_p))) {
fputs(",", fh);
- } else {
+ }
+ else {
fputs("]", fh);
- if ( (i + 1 < fields->fields->len) && (g_ptr_array_len(fields->field_values[i + 1]) > 1) ) {
- fputs(",", fh);
- } else {
}
}
- }
+
+ first = FALSE;
g_ptr_array_free(fv_p, TRUE); /* get ready for the next packet */
fields->field_values[i] = NULL;
}