sharkd: Add support for hidden and generated fields

New json option for frame request to output hidden fields:
"hidden": true

Output has two new optional keys: "g" for generated fields and
"v" for hidden fields.

Change-Id: If51fa5601c1193a03fff378bbe37dc9ab8f5e66d
Reviewed-on: https://code.wireshark.org/review/28955
Petri-Dish: Michal Labedzki <michal.labedzki@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
Michał Łabędzki 2018-07-22 14:54:36 +02:00 committed by Anders Broman
parent 2fa2947be0
commit a7b56fff7e
1 changed files with 32 additions and 12 deletions

View File

@ -2592,7 +2592,7 @@ sharkd_session_process_follow(char *buf, const jsmntok_t *tokens, int count)
}
static void
sharkd_session_process_frame_cb_tree(epan_dissect_t *edt, proto_tree *tree, tvbuff_t **tvbs)
sharkd_session_process_frame_cb_tree(epan_dissect_t *edt, proto_tree *tree, tvbuff_t **tvbs, gboolean display_hidden)
{
proto_node *node;
const char *sepa = "";
@ -2605,8 +2605,7 @@ sharkd_session_process_frame_cb_tree(epan_dissect_t *edt, proto_tree *tree, tvbu
if (!finfo)
continue;
/* XXX, for now always skip hidden */
if (FI_GET_FLAG(finfo, FI_HIDDEN))
if (!display_hidden && FI_GET_FLAG(finfo, FI_HIDDEN))
continue;
printf("%s{", sepa);
@ -2676,6 +2675,16 @@ sharkd_session_process_frame_cb_tree(epan_dissect_t *edt, proto_tree *tree, tvbu
}
}
if (FI_GET_FLAG(finfo, FI_GENERATED))
{
printf(",\"g\":true");
}
if (FI_GET_FLAG(finfo, FI_HIDDEN))
{
printf(",\"v\":true");
}
if (FI_GET_FLAG(finfo, PI_SEVERITY_MASK))
{
const char *severity = try_val_to_str(FI_GET_FLAG(finfo, PI_SEVERITY_MASK), expert_severity_vals);
@ -2690,7 +2699,7 @@ sharkd_session_process_frame_cb_tree(epan_dissect_t *edt, proto_tree *tree, tvbu
if (finfo->tree_type != -1)
printf(",\"e\":%d", finfo->tree_type);
printf(",\"n\":");
sharkd_session_process_frame_cb_tree(edt, (proto_tree *) node, tvbs);
sharkd_session_process_frame_cb_tree(edt, (proto_tree *) node, tvbs, display_hidden);
}
printf("}");
@ -2726,6 +2735,11 @@ sharkd_follower_visit_layers_cb(const void *key _U_, void *value, void *user_dat
return FALSE;
}
struct sharkd_frame_request_data
{
gboolean display_hidden;
};
static void
sharkd_session_process_frame_cb(epan_dissect_t *edt, proto_tree *tree, struct epan_column_info *cinfo, const GSList *data_src, void *data)
{
@ -2733,8 +2747,8 @@ sharkd_session_process_frame_cb(epan_dissect_t *edt, proto_tree *tree, struct ep
frame_data *fdata = pi->fd;
const char *pkt_comment = NULL;
(void) data;
const struct sharkd_frame_request_data * const req_data = (const struct sharkd_frame_request_data * const) data;
const gboolean display_hidden = (req_data) ? req_data->display_hidden : FALSE;
printf("{");
printf("\"err\":0");
@ -2774,7 +2788,7 @@ sharkd_session_process_frame_cb(epan_dissect_t *edt, proto_tree *tree, struct ep
tvbs[count] = NULL;
}
sharkd_session_process_frame_cb_tree(edt, tree, tvbs);
sharkd_session_process_frame_cb_tree(edt, tree, tvbs, display_hidden);
g_free(tvbs);
}
@ -3222,6 +3236,7 @@ sharkd_session_process_intervals(char *buf, const jsmntok_t *tokens, int count)
* (o) columns - set if output frame columns
* (o) color - set if output color-filter bg/fg
* (o) bytes - set if output frame bytes
* (o) hidden - set if output hidden tree fields
*
* Output object with attributes:
* (m) err - 0 if succeed
@ -3238,6 +3253,8 @@ sharkd_session_process_intervals(char *buf, const jsmntok_t *tokens, int count)
* ds- data src index
* url - only for t:'url', url
* fnum - only for t:'framenum', frame number
* g - if field is generated by Wireshark
* v - if field is hidden
*
* (o) col - array of column data
* (o) bytes - base64 of frame bytes
@ -3260,13 +3277,13 @@ sharkd_session_process_frame(char *buf, const jsmntok_t *tokens, int count)
guint32 framenum, ref_frame_num, prev_dis_num;
guint32 dissect_flags = SHARKD_DISSECT_FLAG_NULL;
if (json_find_attr(buf, tokens, count, "proto") != NULL)
dissect_flags |=SHARKD_DISSECT_FLAG_PROTO_TREE;
dissect_flags |= SHARKD_DISSECT_FLAG_PROTO_TREE;
if (json_find_attr(buf, tokens, count, "bytes") != NULL)
dissect_flags |=SHARKD_DISSECT_FLAG_BYTES;
dissect_flags |= SHARKD_DISSECT_FLAG_BYTES;
if (json_find_attr(buf, tokens, count, "columns") != NULL)
dissect_flags |=SHARKD_DISSECT_FLAG_COLUMNS;
dissect_flags |= SHARKD_DISSECT_FLAG_COLUMNS;
if (json_find_attr(buf, tokens, count, "color") != NULL)
dissect_flags |=SHARKD_DISSECT_FLAG_COLOR;
dissect_flags |= SHARKD_DISSECT_FLAG_COLOR;
if (!tok_frame || !ws_strtou32(tok_frame, NULL, &framenum) || framenum == 0)
return;
@ -3279,7 +3296,10 @@ sharkd_session_process_frame(char *buf, const jsmntok_t *tokens, int count)
if (tok_prev_frame && (!ws_strtou32(tok_prev_frame, NULL, &prev_dis_num) || prev_dis_num >= framenum))
return;
sharkd_dissect_request(framenum, ref_frame_num, prev_dis_num, &sharkd_session_process_frame_cb, dissect_flags, NULL);
struct sharkd_frame_request_data req_data;
req_data.display_hidden = (json_find_attr(buf, tokens, count, "v") != NULL);
sharkd_dissect_request(framenum, ref_frame_num, prev_dis_num, &sharkd_session_process_frame_cb, dissect_flags, &req_data);
}
/**