From 08eb36b5af5da365087ea19194a0a00bd1310ce2 Mon Sep 17 00:00:00 2001 From: Jakub Zawadzki Date: Thu, 1 Aug 2013 20:59:38 +0000 Subject: 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 --- ui/gtk/edit_packet_comment_dlg.c | 8 +++----- ui/gtk/export_pdu_dlg.c | 6 +----- ui/gtk/packet_list.c | 34 ++++++++++++++++++---------------- ui/gtk/packet_list.h | 2 +- ui/qt/packet_list.cpp | 25 +++++++++++++------------ 5 files changed, 36 insertions(+), 39 deletions(-) (limited to 'ui') 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. ]")) -- cgit v1.2.1