spice: fix malformed packet exception in LZ image
[metze/wireshark/wip.git] / sharkd_session.c
index aa0f5f613a01af9d34502814a72c972a5ba094f5..5c3bfb74bcf5603ab039efd2e8006e365792ddcd 100644 (file)
@@ -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)
@@ -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);
        }
@@ -2793,6 +2807,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,7 +3234,9 @@ 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
+ *   (o) hidden - set if output hidden tree fields
  *
  * Output object with attributes:
  *   (m) err   - 0 if succeed
@@ -3225,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
@@ -3233,6 +3263,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 +3274,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 +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, tok_bytes, tok_columns, tok_proto, 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);
 }
 
 /**