From a0814af296aa597867125a75094c7d7cfb1b045d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=C5=81ab=C4=99dzki?= Date: Sat, 16 Jun 2018 18:22:00 +0200 Subject: [PATCH] sharkd: Return frame's color-filter colors Return color-filter bg/fg colors for single frame if requested. Also return marked/ignored fields for frame. Change-Id: I4480b733f54991c72bea1664fa6e7337812e6231 Reviewed-on: https://code.wireshark.org/review/28304 Petri-Dish: Michal Labedzki Tested-by: Petri Dish Buildbot Reviewed-by: Michal Labedzki --- sharkd.c | 19 ++++++++++++++----- sharkd.h | 8 +++++++- sharkd_session.c | 34 ++++++++++++++++++++++++++++------ 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/sharkd.c b/sharkd.c index 0b61074c8a..fcc6160f1d 100644 --- a/sharkd.c +++ b/sharkd.c @@ -526,10 +526,10 @@ sharkd_get_frame(guint32 framenum) } int -sharkd_dissect_request(guint32 framenum, guint32 frame_ref_num, guint32 prev_dis_num, sharkd_dissect_func_t cb, int dissect_bytes, int dissect_columns, int dissect_tree, void *data) +sharkd_dissect_request(guint32 framenum, guint32 frame_ref_num, guint32 prev_dis_num, sharkd_dissect_func_t cb, guint32 dissect_flags, void *data) { frame_data *fdata; - column_info *cinfo = (dissect_columns) ? &cfile.cinfo : NULL; + column_info *cinfo = (dissect_flags & SHARKD_DISSECT_FLAG_COLUMNS) ? &cfile.cinfo : NULL; epan_dissect_t edt; gboolean create_proto_tree; wtap_rec rec; /* Record metadata */ @@ -550,8 +550,15 @@ sharkd_dissect_request(guint32 framenum, guint32 frame_ref_num, guint32 prev_dis return -1; /* error reading the record */ } - create_proto_tree = (dissect_tree) || (cinfo && have_custom_cols(cinfo)); - epan_dissect_init(&edt, cfile.epan, create_proto_tree, dissect_tree); + create_proto_tree = ((dissect_flags & SHARKD_DISSECT_FLAG_PROTO_TREE) || + ((dissect_flags & SHARKD_DISSECT_FLAG_COLOR) && color_filters_used()) || + (cinfo && have_custom_cols(cinfo))); + epan_dissect_init(&edt, cfile.epan, create_proto_tree, (dissect_flags & SHARKD_DISSECT_FLAG_PROTO_TREE)); + + if (dissect_flags & SHARKD_DISSECT_FLAG_COLOR) { + color_filters_prime_edt(&edt); + fdata->flags.need_colorize = 1; + } if (cinfo) col_custom_prime_edt(&edt, cinfo); @@ -572,7 +579,9 @@ sharkd_dissect_request(guint32 framenum, guint32 frame_ref_num, guint32 prev_dis epan_dissect_fill_in_columns(&edt, FALSE, TRUE/* fill_fd_columns */); } - cb(&edt, dissect_tree ? edt.tree : NULL, cinfo, dissect_bytes ? edt.pi.data_src : NULL, data); + cb(&edt, (dissect_flags & SHARKD_DISSECT_FLAG_PROTO_TREE) ? edt.tree : NULL, + cinfo, (dissect_flags & SHARKD_DISSECT_FLAG_BYTES) ? edt.pi.data_src : NULL, + data); epan_dissect_cleanup(&edt); wtap_rec_cleanup(&rec); diff --git a/sharkd.h b/sharkd.h index 80cd8d9edf..271d2d2ef8 100644 --- a/sharkd.h +++ b/sharkd.h @@ -14,6 +14,12 @@ #include +#define SHARKD_DISSECT_FLAG_NULL 0x00u +#define SHARKD_DISSECT_FLAG_BYTES 0x01u +#define SHARKD_DISSECT_FLAG_COLUMNS 0x02u +#define SHARKD_DISSECT_FLAG_PROTO_TREE 0x04u +#define SHARKD_DISSECT_FLAG_COLOR 0x08u + typedef void (*sharkd_dissect_func_t)(epan_dissect_t *edt, proto_tree *tree, struct epan_column_info *cinfo, const GSList *data_src, void *data); /* sharkd.c */ @@ -23,7 +29,7 @@ int sharkd_retap(void); int sharkd_filter(const char *dftext, guint8 **result); frame_data *sharkd_get_frame(guint32 framenum); int sharkd_dissect_columns(frame_data *fdata, guint32 frame_ref_num, guint32 prev_dis_num, column_info *cinfo, gboolean dissect_color); -int sharkd_dissect_request(guint32 framenum, guint32 frame_ref_num, guint32 prev_dis_num, sharkd_dissect_func_t cb, int dissect_bytes, int dissect_columns, int dissect_tree, void *data); +int sharkd_dissect_request(guint32 framenum, guint32 frame_ref_num, guint32 prev_dis_num, sharkd_dissect_func_t cb, guint32 dissect_flags, void *data); const char *sharkd_get_user_comment(const frame_data *fd); int sharkd_set_user_comment(frame_data *fd, const gchar *new_comment); const char *sharkd_version(void); diff --git a/sharkd_session.c b/sharkd_session.c index aa0f5f613a..e22cf61021 100644 --- a/sharkd_session.c +++ b/sharkd_session.c @@ -670,7 +670,7 @@ sharkd_session_process_analyse(void) printf(",\"protocols\":["); for (framenum = 1; framenum <= cfile.count; framenum++) - sharkd_dissect_request(framenum, (framenum != 1) ? 1 : 0, framenum - 1, &sharkd_session_process_analyse_cb, 0, 0, 0, &analyser); + sharkd_dissect_request(framenum, (framenum != 1) ? 1 : 0, framenum - 1, &sharkd_session_process_analyse_cb, SHARKD_DISSECT_FLAG_NULL, &analyser); printf("]"); if (analyser.first_time) @@ -2793,6 +2793,18 @@ sharkd_session_process_frame_cb(epan_dissect_t *edt, proto_tree *tree, struct ep printf("]"); } + if (fdata->flags.ignored) + printf(",\"i\":true"); + + if (fdata->flags.marked) + printf(",\"m\":true"); + + if (fdata->color_filter) + { + printf(",\"bg\":\"%x\"", color_t_to_rgb(&fdata->color_filter->bg_color)); + printf(",\"fg\":\"%x\"", color_t_to_rgb(&fdata->color_filter->fg_color)); + } + if (data_src) { struct data_source *src = (struct data_source *) data_src->data; @@ -3208,6 +3220,7 @@ sharkd_session_process_intervals(char *buf, const jsmntok_t *tokens, int count) * (o) prev_frame - previously displayed frame number * (o) proto - set if output frame tree * (o) columns - set if output frame columns + * (o) color - set if output color-filter bg/fg * (o) bytes - set if output frame bytes * * Output object with attributes: @@ -3233,6 +3246,10 @@ sharkd_session_process_intervals(char *buf, const jsmntok_t *tokens, int count) * (o) fol - array of follow filters: * [0] - protocol * [1] - filter string + * (o) i - if frame is ignored + * (o) m - if frame is marked + * (o) bg - color filter - background color in hex + * (o) fg - color filter - foreground color in hex */ static void sharkd_session_process_frame(char *buf, const jsmntok_t *tokens, int count) @@ -3240,11 +3257,16 @@ sharkd_session_process_frame(char *buf, const jsmntok_t *tokens, int count) const char *tok_frame = json_find_attr(buf, tokens, count, "frame"); const char *tok_ref_frame = json_find_attr(buf, tokens, count, "ref_frame"); const char *tok_prev_frame = json_find_attr(buf, tokens, count, "prev_frame"); - int tok_proto = (json_find_attr(buf, tokens, count, "proto") != NULL); - int tok_bytes = (json_find_attr(buf, tokens, count, "bytes") != NULL); - int tok_columns = (json_find_attr(buf, tokens, count, "columns") != NULL); - 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; + if (json_find_attr(buf, tokens, count, "bytes") != NULL) + dissect_flags |=SHARKD_DISSECT_FLAG_BYTES; + if (json_find_attr(buf, tokens, count, "columns") != NULL) + dissect_flags |=SHARKD_DISSECT_FLAG_COLUMNS; + if (json_find_attr(buf, tokens, count, "color") != NULL) + dissect_flags |=SHARKD_DISSECT_FLAG_COLOR; if (!tok_frame || !ws_strtou32(tok_frame, NULL, &framenum) || framenum == 0) return; @@ -3257,7 +3279,7 @@ 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, tok_bytes, tok_columns, tok_proto, NULL); + sharkd_dissect_request(framenum, ref_frame_num, prev_dis_num, &sharkd_session_process_frame_cb, dissect_flags, NULL); } /**