aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Zawadzki <darkjames-ws@darkjames.pl>2017-12-06 19:51:18 +0100
committerGuy Harris <guy@alum.mit.edu>2017-12-06 19:54:30 +0000
commitb59c39b271e1cb39e4faa54f1af4bfcc2a602807 (patch)
treeb47fee183828e7279121926aa6fb05a0b34af7fc
parent038fe4c2d44da58ca626cc0fb63c482ced660f84 (diff)
frame user comments: move to epan, add support for user comments in sharkd.
Change-Id: Id15edc60177b160fd09cae99de1c9e01e17d9421 Reviewed-on: https://code.wireshark.org/review/24714 Petri-Dish: Jakub Zawadzki <darkjames-ws@darkjames.pl> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r--epan/frame_set.c33
-rw-r--r--epan/frame_set.h2
-rw-r--r--file.c43
-rw-r--r--sharkd.c15
-rw-r--r--sharkd.h2
-rw-r--r--sharkd_session.c46
6 files changed, 98 insertions, 43 deletions
diff --git a/epan/frame_set.c b/epan/frame_set.c
index 572c43b9f8..99e75248e5 100644
--- a/epan/frame_set.c
+++ b/epan/frame_set.c
@@ -12,6 +12,17 @@
#include <epan/frame_set.h>
+static int
+frame_cmp(gconstpointer a, gconstpointer b, gpointer user_data _U_)
+{
+ const frame_data *fdata1 = (const frame_data *) a;
+ const frame_data *fdata2 = (const frame_data *) b;
+
+ return (fdata1->num < fdata2->num) ? -1 :
+ (fdata1->num > fdata2->num) ? 1 :
+ 0;
+}
+
const char *
frame_set_get_interface_name(frame_set *fs, guint32 interface_id)
{
@@ -55,3 +66,25 @@ frame_set_get_interface_description(frame_set *fs, guint32 interface_id)
}
return NULL;
}
+
+const char *
+frame_set_get_user_comment(frame_set *fs, const frame_data *fd)
+{
+ if (fs->frames_user_comments)
+ return (const char *)g_tree_lookup(fs->frames_user_comments, fd);
+
+ /* g_warning? */
+ return NULL;
+}
+
+void
+frame_set_set_user_comment(frame_set *fs, frame_data *fd, const char *new_comment)
+{
+ if (!fs->frames_user_comments)
+ fs->frames_user_comments = g_tree_new_full(frame_cmp, NULL, NULL, g_free);
+
+ /* insert new packet comment */
+ g_tree_replace(fs->frames_user_comments, fd, g_strdup(new_comment));
+
+ fd->flags.has_user_comment = TRUE;
+}
diff --git a/epan/frame_set.h b/epan/frame_set.h
index 213d140d8e..d12dac767b 100644
--- a/epan/frame_set.h
+++ b/epan/frame_set.h
@@ -28,5 +28,7 @@ typedef struct {
WS_DLL_PUBLIC const char *frame_set_get_interface_name(frame_set *fs, guint32 interface_id);
WS_DLL_PUBLIC const char *frame_set_get_interface_description(frame_set *fs, guint32 interface_id);
+WS_DLL_PUBLIC const char *frame_set_get_user_comment(frame_set *fs, const frame_data *fd);
+WS_DLL_PUBLIC void frame_set_set_user_comment(frame_set *fs, frame_data *fd, const char *new_comment);
#endif /* frame_set.h */
diff --git a/file.c b/file.c
index 0bc3023527..5c38ee029b 100644
--- a/file.c
+++ b/file.c
@@ -111,8 +111,6 @@ static gboolean find_packet(capture_file *cf,
match_result (*match_function)(capture_file *, frame_data *, void *),
void *criterion, search_direction dir);
-static const char *cf_get_user_packet_comment(frame_set *fs, const frame_data *fd);
-
static void cf_rename_failure_alert_box(const char *filename, int err);
static void ref_time_packets(capture_file *cf);
@@ -242,12 +240,6 @@ ws_get_frame_ts(frame_set *fs, guint32 frame_num)
return NULL;
}
-static const char *
-ws_get_user_comment(frame_set *fs, const frame_data *fd)
-{
- return cf_get_user_packet_comment(fs, fd);
-}
-
static epan_t *
ws_epan_new(capture_file *cf)
{
@@ -257,7 +249,7 @@ ws_epan_new(capture_file *cf)
epan->get_frame_ts = ws_get_frame_ts;
epan->get_interface_name = frame_set_get_interface_name;
epan->get_interface_description = frame_set_get_interface_description;
- epan->get_user_comment = ws_get_user_comment;
+ epan->get_user_comment = frame_set_get_user_comment;
return epan;
}
@@ -3803,16 +3795,6 @@ cf_update_section_comment(capture_file *cf, gchar *comment)
cf->unsaved_changes = TRUE;
}
-static const char *
-cf_get_user_packet_comment(frame_set *fs, const frame_data *fd)
-{
- if (fs->frames_user_comments)
- return (const char *)g_tree_lookup(fs->frames_user_comments, fd);
-
- /* g_warning? */
- return NULL;
-}
-
/*
* Get the comment on a packet (record).
* If the comment has been edited, it returns the result of the edit,
@@ -3825,7 +3807,7 @@ cf_get_packet_comment(capture_file *cf, const frame_data *fd)
/* fetch user comment */
if (fd->flags.has_user_comment)
- return g_strdup(cf_get_user_packet_comment(&cf->frame_set_info, fd));
+ return g_strdup(frame_set_get_user_comment(&cf->frame_set_info, fd));
/* fetch phdr comment */
if (fd->flags.has_phdr_comment) {
@@ -3846,17 +3828,6 @@ cf_get_packet_comment(capture_file *cf, const frame_data *fd)
return NULL;
}
-static int
-frame_cmp(gconstpointer a, gconstpointer b, gpointer user_data _U_)
-{
- const frame_data *fdata1 = (const frame_data *) a;
- const frame_data *fdata2 = (const frame_data *) b;
-
- return (fdata1->num < fdata2->num) ? -1 :
- (fdata1->num > fdata2->num) ? 1 :
- 0;
-}
-
/*
* Update(replace) the comment on a capture from a frame
*/
@@ -3878,13 +3849,7 @@ cf_set_user_packet_comment(capture_file *cf, frame_data *fd, const gchar *new_co
if (new_comment)
cf->packet_comment_count++;
- fd->flags.has_user_comment = TRUE;
-
- if (!cf->frame_set_info.frames_user_comments)
- cf->frame_set_info.frames_user_comments = g_tree_new_full(frame_cmp, NULL, NULL, g_free);
-
- /* insert new packet comment */
- g_tree_replace(cf->frame_set_info.frames_user_comments, fd, g_strdup(new_comment));
+ frame_set_set_user_comment(&cf->frame_set_info, fd, new_comment);
expert_update_comment_count(cf->packet_comment_count);
@@ -3951,7 +3916,7 @@ save_record(capture_file *cf, frame_data *fdata,
const char *pkt_comment;
if (fdata->flags.has_user_comment)
- pkt_comment = cf_get_user_packet_comment(&cf->frame_set_info, fdata);
+ pkt_comment = frame_set_get_user_comment(&cf->frame_set_info, fdata);
else
pkt_comment = phdr->opt_comment;
diff --git a/sharkd.c b/sharkd.c
index fdd13ae4b2..564e38087c 100644
--- a/sharkd.c
+++ b/sharkd.c
@@ -250,7 +250,7 @@ sharkd_epan_new(capture_file *cf)
epan->get_frame_ts = sharkd_get_frame_ts;
epan->get_interface_name = frame_set_get_interface_name;
epan->get_interface_description = frame_set_get_interface_description;
- epan->get_user_comment = NULL;
+ epan->get_user_comment = frame_set_get_user_comment;
return epan;
}
@@ -764,6 +764,19 @@ sharkd_filter(const char *dftext, guint8 **result)
return framenum;
}
+const char *
+sharkd_get_user_comment(const frame_data *fd)
+{
+ return frame_set_get_user_comment(&cfile.frame_set_info, fd);
+}
+
+int
+sharkd_set_user_comment(frame_data *fd, const gchar *new_comment)
+{
+ frame_set_set_user_comment(&cfile.frame_set_info, fd, new_comment);
+ return 0;
+}
+
#include "version.h"
const char *sharkd_version(void)
{
diff --git a/sharkd.h b/sharkd.h
index 7b75788290..b2549f879e 100644
--- a/sharkd.h
+++ b/sharkd.h
@@ -22,6 +22,8 @@ int sharkd_retap(void);
int sharkd_filter(const char *dftext, guint8 **result);
int sharkd_dissect_columns(int framenum, column_info *cinfo, gboolean dissect_color);
int sharkd_dissect_request(unsigned int framenum, void (*cb)(epan_dissect_t *, proto_tree *, struct epan_column_info *, const GSList *, void *), int dissect_bytes, int dissect_columns, int dissect_tree, 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);
/* sharkd_daemon.c */
diff --git a/sharkd_session.c b/sharkd_session.c
index c417108ad6..541166798a 100644
--- a/sharkd_session.c
+++ b/sharkd_session.c
@@ -870,8 +870,11 @@ sharkd_session_process_frames(const char *buf, const jsmntok_t *tokens, int coun
}
printf("],\"num\":%u", framenum);
- if (fdata->flags.has_phdr_comment)
- printf(",\"ct\":true");
+ if (fdata->flags.has_user_comment || fdata->flags.has_phdr_comment)
+ {
+ if (!fdata->flags.has_user_comment || sharkd_get_user_comment(fdata) != NULL)
+ printf(",\"ct\":true");
+ }
if (fdata->flags.ignored)
printf(",\"i\":true");
@@ -2768,7 +2771,9 @@ sharkd_session_process_frame_cb(epan_dissect_t *edt, proto_tree *tree, struct ep
printf("\"err\":0");
- if (fdata->flags.has_phdr_comment)
+ if (fdata->flags.has_user_comment)
+ pkt_comment = sharkd_get_user_comment(fdata);
+ else if (fdata->flags.has_phdr_comment)
pkt_comment = pi->phdr->opt_comment;
if (pkt_comment)
@@ -3280,6 +3285,39 @@ sharkd_session_process_complete(char *buf, const jsmntok_t *tokens, int count)
}
/**
+ * sharkd_session_process_setcomment()
+ *
+ * Process setcomment request
+ *
+ * Input:
+ * (m) frame - frame number
+ * (o) comment - user comment
+ *
+ * Output object with attributes:
+ * (m) err - error code: 0 succeed
+ */
+static void
+sharkd_session_process_setcomment(char *buf, const jsmntok_t *tokens, int count)
+{
+ const char *tok_frame = json_find_attr(buf, tokens, count, "frame");
+ const char *tok_comment = json_find_attr(buf, tokens, count, "comment");
+
+ guint32 framenum;
+ frame_data *fdata;
+ int ret;
+
+ if (!tok_frame || !ws_strtou32(tok_frame, NULL, &framenum) || framenum == 0)
+ return;
+
+ fdata = frame_data_sequence_find(cfile.frame_set_info.frames, framenum);
+ if (!fdata)
+ return;
+
+ ret = sharkd_set_user_comment(fdata, tok_comment);
+ printf("{\"err\":%d}\n", ret);
+}
+
+/**
* sharkd_session_process_setconf()
*
* Process setconf request
@@ -3911,6 +3949,8 @@ sharkd_session_process(char *buf, const jsmntok_t *tokens, int count)
sharkd_session_process_intervals(buf, tokens, count);
else if (!strcmp(tok_req, "frame"))
sharkd_session_process_frame(buf, tokens, count);
+ else if (!strcmp(tok_req, "setcomment"))
+ sharkd_session_process_setcomment(buf, tokens, count);
else if (!strcmp(tok_req, "setconf"))
sharkd_session_process_setconf(buf, tokens, count);
else if (!strcmp(tok_req, "dumpconf"))