diff options
author | Jakub Zawadzki <darkjames-ws@darkjames.pl> | 2013-08-01 20:59:38 +0000 |
---|---|---|
committer | Jakub Zawadzki <darkjames-ws@darkjames.pl> | 2013-08-01 20:59:38 +0000 |
commit | 08eb36b5af5da365087ea19194a0a00bd1310ce2 (patch) | |
tree | bc8a0b2ba1a0816c79a164025e72873a4cbab715 | |
parent | 6c5e16185dfd4c9e955618f56ac8827ad7eda9e7 (diff) |
Remove fdata->opt_comment, add pkt_comment to pinfo
Original (read from file) comments can be accessed by pkthdr->opt_comment
Keep user comments in seperated BST, add new method for epan session to get it.
svn path=/trunk/; revision=51090
-rw-r--r-- | cfile.h | 1 | ||||
-rw-r--r-- | epan/dissectors/packet-frame.c | 8 | ||||
-rw-r--r-- | epan/epan-int.h | 2 | ||||
-rw-r--r-- | epan/epan.c | 9 | ||||
-rw-r--r-- | epan/epan.h | 2 | ||||
-rw-r--r-- | epan/frame_data.c | 7 | ||||
-rw-r--r-- | epan/frame_data.h | 3 | ||||
-rw-r--r-- | epan/packet.c | 6 | ||||
-rw-r--r-- | epan/packet_info.h | 1 | ||||
-rw-r--r-- | epan/wslua/wslua_dumper.c | 6 | ||||
-rw-r--r-- | file.c | 126 | ||||
-rw-r--r-- | file.h | 6 | ||||
-rw-r--r-- | rawshark.c | 1 | ||||
-rw-r--r-- | tshark.c | 1 | ||||
-rw-r--r-- | ui/gtk/edit_packet_comment_dlg.c | 8 | ||||
-rw-r--r-- | ui/gtk/export_pdu_dlg.c | 6 | ||||
-rw-r--r-- | ui/gtk/packet_list.c | 34 | ||||
-rw-r--r-- | ui/gtk/packet_list.h | 2 | ||||
-rw-r--r-- | ui/qt/packet_list.cpp | 25 |
19 files changed, 179 insertions, 75 deletions
@@ -124,6 +124,7 @@ typedef struct _capture_file { GTree *edited_frames; /* BST with modified frames */ #endif gpointer window; /* Top-level window associated with file */ + GTree *frames_user_comments; /* BST with user comments for frames (key = frame_data) */ } capture_file; extern void cap_file_init(capture_file *cf); diff --git a/epan/dissectors/packet-frame.c b/epan/dissectors/packet-frame.c index d5d7f48fff..0eccdba794 100644 --- a/epan/dissectors/packet-frame.c +++ b/epan/dissectors/packet-frame.c @@ -229,14 +229,14 @@ dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) } } - if(pinfo->fd->opt_comment){ + if(pinfo->pkt_comment){ item = proto_tree_add_item(tree, proto_pkt_comment, tvb, 0, -1, ENC_NA); comments_tree = proto_item_add_subtree(item, ett_comments); comment_item = proto_tree_add_string_format(comments_tree, hf_comments_text, tvb, 0, -1, - pinfo->fd->opt_comment, "%s", - pinfo->fd->opt_comment); + pinfo->pkt_comment, "%s", + pinfo->pkt_comment); expert_add_info_format_text(pinfo, comment_item, &ei_comments_text, - "%s", pinfo->fd->opt_comment); + "%s", pinfo->pkt_comment); } diff --git a/epan/epan-int.h b/epan/epan-int.h index 0fa38d0427..7890cd51b4 100644 --- a/epan/epan-int.h +++ b/epan/epan-int.h @@ -24,6 +24,7 @@ #ifndef __EPAN_INT_H__ #define __EPAN_INT_H__ +#include <epan/frame_data.h> #include <wsutil/nstime.h> struct epan_session { @@ -31,6 +32,7 @@ struct epan_session { const nstime_t *(*get_frame_ts)(void *data, guint32 frame_num); const char *(*get_interface_name)(void *data, guint32 interface_id); + const char *(*get_user_comment)(void *data, const frame_data *fd); }; #endif diff --git a/epan/epan.c b/epan/epan.c index a18360d370..7d311a1027 100644 --- a/epan/epan.c +++ b/epan/epan.c @@ -149,6 +149,15 @@ epan_new(void) } const char * +epan_get_user_comment(const epan_t *session, const frame_data *fd) +{ + if (session->get_user_comment) + return session->get_user_comment(session->data, fd); + + return NULL; +} + +const char * epan_get_interface_name(const epan_t *session, guint32 interface_id) { if (session->get_interface_name) diff --git a/epan/epan.h b/epan/epan.h index 63d1e41828..f022cf2fa6 100644 --- a/epan/epan.h +++ b/epan/epan.h @@ -129,6 +129,8 @@ typedef struct epan_session epan_t; WS_DLL_PUBLIC epan_t *epan_new(void); +const char *epan_get_user_comment(const epan_t *session, const frame_data *fd); + const char *epan_get_interface_name(const epan_t *session, guint32 interface_id); const nstime_t *epan_get_frame_ts(const epan_t *session, guint32 frame_num); diff --git a/epan/frame_data.c b/epan/frame_data.c index a7d66c73bf..0b2d8b83bb 100644 --- a/epan/frame_data.c +++ b/epan/frame_data.c @@ -279,6 +279,7 @@ frame_data_init(frame_data *fdata, guint32 num, fdata->flags.ref_time = 0; fdata->flags.ignored = 0; fdata->flags.has_ts = (phdr->presence_flags & WTAP_HAS_TS) ? 1 : 0; + fdata->flags.has_phdr_comment = (phdr->opt_comment != NULL); fdata->color_filter = NULL; fdata->abs_ts.secs = phdr->ts.secs; fdata->abs_ts.nsecs = phdr->ts.nsecs; @@ -286,7 +287,6 @@ frame_data_init(frame_data *fdata, guint32 num, fdata->shift_offset.nsecs = 0; fdata->frame_ref_num = 0; fdata->prev_dis_num = 0; - fdata->opt_comment = phdr->opt_comment; } void @@ -357,11 +357,6 @@ frame_data_destroy(frame_data *fdata) g_slist_free(fdata->pfd); fdata->pfd = NULL; } - - if (fdata->opt_comment) { - g_free(fdata->opt_comment); - fdata->opt_comment = NULL; - } } /* diff --git a/epan/frame_data.h b/epan/frame_data.h index 2545b7577c..57f95e5c0b 100644 --- a/epan/frame_data.h +++ b/epan/frame_data.h @@ -73,6 +73,8 @@ typedef struct _frame_data { unsigned int ref_time : 1; /**< 1 = marked as a reference time frame, 0 = normal */ unsigned int ignored : 1; /**< 1 = ignore this frame, 0 = normal */ unsigned int has_ts : 1; /**< 1 = has time stamp, 0 = no time stamp */ + unsigned int has_phdr_comment : 1; /** 1 = there's comment for this packet */ + unsigned int has_user_comment : 1; /** 1 = user set (also deleted) comment for this packet */ } flags; const void *color_filter; /**< Per-packet matching color_filter_t object */ @@ -81,7 +83,6 @@ typedef struct _frame_data { nstime_t shift_offset; /**< How much the abs_tm of the frame is shifted */ guint32 frame_ref_num; /**< Previous reference frame (0 if this is one) */ guint32 prev_dis_num; /**< Previous displayed frame (0 if first one) */ - gchar *opt_comment; /**< NULL if not available */ } frame_data; #ifdef WANT_PACKET_EDITOR diff --git a/epan/packet.c b/epan/packet.c index 7680038b58..95f98678bc 100644 --- a/epan/packet.c +++ b/epan/packet.c @@ -358,6 +358,12 @@ dissect_packet(epan_dissect_t *edt, struct wtap_pkthdr *phdr, frame_delta_abs_time(edt->session, fd, fd->frame_ref_num, &edt->pi.rel_ts); + /* pkt comment use first user, later from phdr */ + if (fd->flags.has_user_comment) + edt->pi.pkt_comment = epan_get_user_comment(edt->session, fd); + else + edt->pi.pkt_comment = phdr->opt_comment; + /* to enable decode as for ethertype=0x0000 (fix for bug 4721) */ edt->pi.ethertype = G_MAXINT; diff --git a/epan/packet_info.h b/epan/packet_info.h index 612c3cd1c2..33c899a429 100644 --- a/epan/packet_info.h +++ b/epan/packet_info.h @@ -227,6 +227,7 @@ typedef struct _packet_info { struct _wmem_allocator_t *pool; /**< Memory pool scoped to the pinfo struct */ struct epan_session *epan; nstime_t rel_ts; /**< Relative timestamp (yes, it can be negative) */ + const gchar *pkt_comment; /**< NULL if not available */ } packet_info; /**< For old code that hasn't yet been changed. */ diff --git a/epan/wslua/wslua_dumper.c b/epan/wslua/wslua_dumper.c index c29cf43d24..d4dd59eff5 100644 --- a/epan/wslua/wslua_dumper.c +++ b/epan/wslua/wslua_dumper.c @@ -317,7 +317,7 @@ WSLUA_METHOD Dumper_dump(lua_State* L) { pkthdr.pkt_encap = DUMPER_ENCAP(d); pkthdr.pseudo_header = *ph->wph; - /* TODO: Can we get access to pinfo->fd->opt_comment here somehow? We + /* TODO: Can we get access to pinfo->pkt_comment here somehow? We * should be copying it to pkthdr.opt_comment if we can. */ if (! wtap_dump(d, &pkthdr, ba->data, &err)) { @@ -409,8 +409,8 @@ WSLUA_METHOD Dumper_dump_current(lua_State* L) { pkthdr.pkt_encap = lua_pinfo->fd->lnk_t; pkthdr.pseudo_header = *lua_pinfo->pseudo_header; - if (lua_pinfo->fd->opt_comment) - pkthdr.opt_comment = ep_strdup(lua_pinfo->fd->opt_comment); + if (lua_pinfo->pkt_comment) + pkthdr.opt_comment = ep_strdup(lua_pinfo->pkt_comment); data = (const guchar *)ep_tvb_memdup(tvb,0,pkthdr.caplen); @@ -150,6 +150,8 @@ 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(capture_file *cf, const frame_data *fd); + static void cf_open_failure_alert_box(const char *filename, int err, gchar *err_info, gboolean for_writing, int file_type); @@ -323,6 +325,14 @@ ws_get_frame_ts(void *data, guint32 frame_num) return NULL; } +static const char * +ws_get_user_comment(void *data, const frame_data *fd) +{ + capture_file *cf = (capture_file *) data; + + return cf_get_user_packet_comment(cf, fd); +} + static epan_t * ws_epan_new(capture_file *cf) { @@ -331,6 +341,7 @@ ws_epan_new(capture_file *cf) epan->data = cf; epan->get_frame_ts = ws_get_frame_ts; epan->get_interface_name = cap_file_get_interface_name; + epan->get_user_comment = ws_get_user_comment; return epan; } @@ -486,6 +497,10 @@ cf_reset_state(capture_file *cf) cf->edited_frames = NULL; } #endif + if (cf->frames_user_comments) { + g_tree_destroy(cf->frames_user_comments); + cf->frames_user_comments = NULL; + } cf_unselect_packet(cf); /* nothing to select */ cf->first_displayed = 0; cf->last_displayed = 0; @@ -1262,7 +1277,7 @@ read_packet(capture_file *cf, dfilter_t *dfcode, fdata = frame_data_sequence_add(cf->frames, &fdlocal); cf->count++; - if (fdlocal.opt_comment != NULL) + if (phdr->opt_comment != NULL) cf->packet_comment_count++; cf->f_datalen = offset + fdlocal.cap_len; @@ -1719,7 +1734,7 @@ cf_redissect_packets(capture_file *cf) } gboolean -cf_read_frame_r(capture_file *cf, frame_data *fdata, +cf_read_frame_r(capture_file *cf, const frame_data *fdata, struct wtap_pkthdr *phdr, Buffer *buf) { int err; @@ -3921,25 +3936,82 @@ cf_update_capture_comment(capture_file *cf, gchar *comment) cf->unsaved_changes = TRUE; } -void -cf_update_packet_comment(capture_file *cf, frame_data *fdata, gchar *comment) +static const char * +cf_get_user_packet_comment(capture_file *cf, const frame_data *fd) { - if (fdata->opt_comment != NULL) { - /* OK, remove the old comment. */ - g_free(fdata->opt_comment); - fdata->opt_comment = NULL; - cf->packet_comment_count--; + if (cf->frames_user_comments) + return g_tree_lookup(cf->frames_user_comments, fd); + + /* g_warning? */ + return NULL; +} + +char * +cf_get_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, fd)); + + /* fetch phdr comment */ + if (fd->flags.has_phdr_comment) { + struct wtap_pkthdr phdr; /* Packet header */ + Buffer buf; /* Packet data */ + + phdr.opt_comment = NULL; + + buffer_init(&buf, 1500); + if (!cf_read_frame_r(cf, fd, &phdr, &buf)) + { /* XXX, what we can do here? */ } + + buffer_free(&buf); + return phdr.opt_comment; } - if (comment != NULL) { - /* Add the new comment. */ - fdata->opt_comment = comment; - cf->packet_comment_count++; + 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; +} + +gboolean +cf_set_user_packet_comment(capture_file *cf, frame_data *fd, const gchar *new_comment) +{ + char *pkt_comment = cf_get_comment(cf, fd); + + /* Check if the comment has changed */ + if (!g_strcmp0(pkt_comment, new_comment)) { + g_free(pkt_comment); + return FALSE; } + g_free(pkt_comment); + + if (pkt_comment) + cf->packet_comment_count--; + + if (new_comment) + cf->packet_comment_count++; + + fd->flags.has_user_comment = TRUE; + + if (!cf->frames_user_comments) + cf->frames_user_comments = g_tree_new_full(frame_cmp, NULL, NULL, g_free); + + /* insert new packet comment */ + g_tree_replace(cf->frames_user_comments, fd, g_strdup(new_comment)); expert_update_comment_count(cf->packet_comment_count); /* OK, we have unsaved changes. */ cf->unsaved_changes = TRUE; + return TRUE; } /* @@ -3979,6 +4051,12 @@ save_packet(capture_file *cf _U_, frame_data *fdata, struct wtap_pkthdr hdr; int err; gchar *display_basename; + const char *pkt_comment; + + if (fdata->flags.has_user_comment) + pkt_comment = cf_get_user_packet_comment(cf, fdata); + else + pkt_comment = phdr->opt_comment; /* init the wtap header for saving */ /* TODO: reuse phdr */ @@ -4009,7 +4087,8 @@ save_packet(capture_file *cf _U_, frame_data *fdata, hdr.interface_id = phdr->interface_id; /* identifier of the interface. */ /* options */ hdr.pack_flags = phdr->pack_flags; - hdr.opt_comment = fdata->opt_comment; /* NULL if not available */ + hdr.opt_comment = g_strdup(pkt_comment); + /* pseudo */ hdr.pseudo_header = phdr->pseudo_header; #if 0 @@ -4046,6 +4125,8 @@ save_packet(capture_file *cf _U_, frame_data *fdata, } return FALSE; } + + g_free(hdr.opt_comment); return TRUE; } @@ -4665,15 +4746,20 @@ cf_save_packets(capture_file *cf, const char *fname, guint save_format, /* Remove SHB comment, if any. */ wtap_write_shb_comment(cf->wth, NULL); - /* Remove packet comments. */ + /* remove all user comments */ for (framenum = 1; framenum <= cf->count; framenum++) { fdata = frame_data_sequence_find(cf->frames, framenum); - if (fdata->opt_comment) { - g_free(fdata->opt_comment); - fdata->opt_comment = NULL; - cf->packet_comment_count--; - } + + fdata->flags.has_phdr_comment = FALSE; + fdata->flags.has_user_comment = FALSE; } + + if (cf->frames_user_comments) { + g_tree_destroy(cf->frames_user_comments); + cf->frames_user_comments = NULL; + } + + cf->packet_comment_count = 0; } } return CF_WRITE_OK; @@ -148,7 +148,7 @@ cf_read_status_t cf_read(capture_file *cf, gboolean from_save); * @param buf a Buffer into which to read the packet's raw data * @return TRUE if the read succeeded, FALSE if there was an error */ -gboolean cf_read_frame_r(capture_file *cf, frame_data *fdata, +gboolean cf_read_frame_r(capture_file *cf, const frame_data *fdata, struct wtap_pkthdr *phdr, Buffer *buf); /** @@ -667,6 +667,8 @@ const gchar* cf_read_shb_comment(capture_file *cf); */ void cf_update_capture_comment(capture_file *cf, gchar *comment); +char *cf_get_comment(capture_file *cf, const frame_data *fd); + /** * Update(replace) the comment on a capture from a frame * @@ -674,7 +676,7 @@ void cf_update_capture_comment(capture_file *cf, gchar *comment); * @param fdata the frame_data structure for the frame * @param comment the string replacing the old comment */ -void cf_update_packet_comment(capture_file *cf, frame_data *fdata, gchar *comment); +gboolean cf_set_user_packet_comment(capture_file *cf, frame_data *fd, const gchar *new_comment); /** * What types of comments does this file have? diff --git a/rawshark.c b/rawshark.c index bc9a14e1dc..0c46c29b44 100644 --- a/rawshark.c +++ b/rawshark.c @@ -1611,6 +1611,7 @@ raw_epan_new(capture_file *cf) epan->data = cf; epan->get_frame_ts = raw_get_frame_ts; epan->get_interface_name = cap_file_get_interface_name; + epan->get_user_comment = NULL; return epan; } @@ -2198,6 +2198,7 @@ tshark_epan_new(capture_file *cf) epan->data = cf; epan->get_frame_ts = tshark_get_frame_ts; epan->get_interface_name = cap_file_get_interface_name; + epan->get_user_comment = NULL; return epan; } diff --git a/ui/gtk/edit_packet_comment_dlg.c b/ui/gtk/edit_packet_comment_dlg.c index 71652e7096..9cffb6cb67 100644 --- a/ui/gtk/edit_packet_comment_dlg.c +++ b/ui/gtk/edit_packet_comment_dlg.c @@ -109,8 +109,7 @@ edit_packet_comment_dlg (GtkAction *action _U_, gpointer data _U_) GtkWidget *bbox; GtkWidget *ok_bt, *cancel_bt, *help_bt; GtkTextBuffer *buffer; - const gchar *opt_comment; - gchar *buf_str; + gchar *opt_comment; edit_or_add_pkt_comment_dlg = dlg_window_new ("Edit or Add Packet Comments"); gtk_widget_set_size_request (edit_or_add_pkt_comment_dlg, 500, 160); @@ -138,9 +137,8 @@ edit_packet_comment_dlg (GtkAction *action _U_, gpointer data _U_) /*g_warning("Fetched comment '%s'",opt_comment);*/ if(opt_comment){ - buf_str = g_strdup_printf("%s", opt_comment); - gtk_text_buffer_set_text (buffer, buf_str, -1); - g_free(buf_str); + gtk_text_buffer_set_text(buffer, opt_comment, -1); + g_free(opt_comment); } /* Button row. */ diff --git a/ui/gtk/export_pdu_dlg.c b/ui/gtk/export_pdu_dlg.c index 1a0d07c091..99752a4b8c 100644 --- a/ui/gtk/export_pdu_dlg.c +++ b/ui/gtk/export_pdu_dlg.c @@ -88,11 +88,7 @@ export_pdu_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt _U_, co pkthdr.pkt_encap = exp_pdu_tap_data->pkt_encap; pkthdr.interface_id = 0; pkthdr.presence_flags = 0; - if(pinfo->fd->opt_comment == NULL){ - pkthdr.opt_comment = NULL; - }else{ - pkthdr.opt_comment = g_strdup(pinfo->fd->opt_comment); - } + pkthdr.opt_comment = g_strdup(pinfo->pkt_comment); pkthdr.drop_count = 0; pkthdr.pack_flags = 0; pkthdr.presence_flags = WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID|WTAP_HAS_TS|WTAP_HAS_PACK_FLAGS; diff --git a/ui/gtk/packet_list.c b/ui/gtk/packet_list.c index 7e9ea7f575..b74166388d 100644 --- a/ui/gtk/packet_list.c +++ b/ui/gtk/packet_list.c @@ -1559,7 +1559,7 @@ packet_list_copy_summary_cb(gpointer data _U_, copy_summary_type copy_type) g_string_free(text,TRUE); } -const gchar * +gchar * packet_list_get_packet_comment(void) { GtkTreeModel *model; @@ -1574,7 +1574,7 @@ packet_list_get_packet_comment(void) fdata = packet_list_get_record(model, &iter); - return fdata->opt_comment; + return cf_get_comment(&cfile, fdata); } void @@ -1585,11 +1585,15 @@ packet_list_return_all_comments(GtkTextBuffer *buffer) gchar *buf_str; for (framenum = 1; framenum <= cfile.count ; framenum++) { + char *pkt_comment; + fdata = frame_data_sequence_find(cfile.frames, framenum); - if (fdata->opt_comment) { - buf_str = g_strdup_printf("Frame %u: %s \n\n",framenum, fdata->opt_comment); + pkt_comment = cf_get_comment(&cfile, fdata); + if (pkt_comment) { + buf_str = g_strdup_printf("Frame %u: %s \n\n",framenum, pkt_comment); gtk_text_buffer_insert_at_cursor (buffer, buf_str, -1); g_free(buf_str); + g_free(pkt_comment); } if (gtk_text_buffer_get_char_count(buffer) > MAX_COMMENTS_TO_FETCH) { buf_str = g_strdup_printf("[ Comment text exceeds %s. Stopping. ]", @@ -1616,22 +1620,15 @@ packet_list_update_packet_comment(gchar *new_packet_comment) fdata = packet_list_get_record(model, &iter); - /* Check if the comment has changed */ - if (fdata->opt_comment) { - if (strcmp(fdata->opt_comment, new_packet_comment) == 0) { - g_free(new_packet_comment); - return; - } - } - /* Check if we are clearing the comment */ if(strlen(new_packet_comment) == 0) { g_free(new_packet_comment); new_packet_comment = NULL; } - /* The comment has changed, let's update it */ - cf_update_packet_comment(&cfile, fdata, new_packet_comment); + cf_set_user_packet_comment(&cfile, fdata, new_packet_comment); + + g_free(new_packet_comment); /* Update the main window, as we now have unsaved changes. */ main_update_for_unsaved_changes(&cfile); @@ -1707,6 +1704,8 @@ query_packet_list_tooltip_cb(GtkWidget *widget, gint x, gint y, gboolean keyboar return result; if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tree_view), x, y, NULL, &column, NULL, NULL)) { + char *pkt_comment; + num_cols = g_list_length(prefs.col_list); for (col = 0; col < num_cols; col++) { @@ -1715,8 +1714,10 @@ query_packet_list_tooltip_cb(GtkWidget *widget, gint x, gint y, gboolean keyboar } fdata = packet_list_get_record(model, &iter); - if (fdata->opt_comment != NULL) { - gtk_tooltip_set_markup (tooltip, fdata->opt_comment); + pkt_comment = cf_get_comment(&cfile, fdata); + + if (pkt_comment != NULL) { + gtk_tooltip_set_markup(tooltip, pkt_comment); renderer_list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(column)); /* get the first renderer */ if (g_list_first(renderer_list)) { @@ -1724,6 +1725,7 @@ query_packet_list_tooltip_cb(GtkWidget *widget, gint x, gint y, gboolean keyboar gtk_tree_view_set_tooltip_cell (tree_view, tooltip, path, column, renderer); } g_list_free(renderer_list); + g_free(pkt_comment); result = TRUE; } } diff --git a/ui/gtk/packet_list.h b/ui/gtk/packet_list.h index 2936b02e95..0cf157ce5d 100644 --- a/ui/gtk/packet_list.h +++ b/ui/gtk/packet_list.h @@ -132,7 +132,7 @@ typedef enum { */ void packet_list_copy_summary_cb(gpointer data _U_, copy_summary_type copy_type); -const gchar *packet_list_get_packet_comment(void); +gchar *packet_list_get_packet_comment(void); void packet_list_update_packet_comment(gchar *new_packet_comment); void packet_list_return_all_comments(GtkTextBuffer *buffer); diff --git a/ui/qt/packet_list.cpp b/ui/qt/packet_list.cpp index 957a288439..0016b0395d 100644 --- a/ui/qt/packet_list.cpp +++ b/ui/qt/packet_list.cpp @@ -628,6 +628,7 @@ QString PacketList::packetComment() { int row = currentIndex().row(); frame_data *fdata; + char *pkt_comment; if (!cap_file_ || !packet_list_model_) return NULL; @@ -635,7 +636,11 @@ QString PacketList::packetComment() if (!fdata) return NULL; - return QString(fdata->opt_comment); + pkt_comment = cf_get_comment(cap_file_, fdata); + + return QString(pkt_comment); + + /* XXX, g_free(pkt_comment) */ } void PacketList::setPacketComment(QString new_comment) @@ -650,20 +655,12 @@ void PacketList::setPacketComment(QString new_comment) if (!fdata) return; - /* Check if the comment has changed */ - if (fdata->opt_comment) { - if (strcmp(fdata->opt_comment, new_packet_comment) == 0) { - return; - } - } - /* Check if we are clearing the comment */ if(new_comment.isEmpty()) { new_packet_comment = NULL; } - /* The comment has changed, let's update it */ - cf_update_packet_comment(cap_file_, fdata, g_strdup(new_packet_comment)); + cf_set_user_packet_comment(cap_file_, fdata, new_packet_comment); updateAll(); } @@ -678,8 +675,12 @@ QString PacketList::allPacketComments() for (framenum = 1; framenum <= cap_file_->count ; framenum++) { fdata = frame_data_sequence_find(cap_file_->frames, framenum); - if (fdata->opt_comment) { - buf_str.append(QString(tr("Frame %1: %2 \n\n")).arg(framenum).arg(fdata->opt_comment)); + + char *pkt_comment = cf_get_comment(cap_file_, fdata); + + if (pkt_comment) { + buf_str.append(QString(tr("Frame %1: %2 \n\n")).arg(framenum).arg(pkt_comment)); + g_free(pkt_comment); } if (buf_str.length() > max_comments_to_fetch_) { buf_str.append(QString(tr("[ Comment text exceeds %1. Stopping. ]")) |