aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2014-10-20 14:36:52 -0700
committerGuy Harris <guy@alum.mit.edu>2014-10-20 21:37:41 +0000
commit77f969958c75a8ba138d5adeeddbef50664f52c0 (patch)
tree1651eb1a190dde5c94b934665d10b6b863e0c410
parent0bbe48304a50b6f664c2cef8181c5ba90b62b073 (diff)
Fix support for writing out edited records.
Add a cf_set_frame_edited() routine to set the record header and data for a record; have it do all the non-GUI work, and have it set the file's "unsaved changes" flag. Have the GUI code just call that routine and then update the title bar to reflect the unsaved changes. While we're at it, unmark a no-longer-unused argument to save_record(). Change-Id: Ieb513fdf423b388519527621ecec4cf634b98caf Reviewed-on: https://code.wireshark.org/review/4885 Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r--file.c46
-rw-r--r--file.h12
-rw-r--r--ui/gtk/packet_win.c28
3 files changed, 61 insertions, 25 deletions
diff --git a/file.c b/file.c
index 31d2b6a713..ecb42887b5 100644
--- a/file.c
+++ b/file.c
@@ -4036,6 +4036,50 @@ cf_comment_types(capture_file *cf)
return comment_types;
}
+#ifdef WANT_PACKET_EDITOR
+static gint
+g_direct_compare_func(gconstpointer a, gconstpointer b, gpointer user_data _U_)
+{
+ if (a > b)
+ return 1;
+ else if (a < b)
+ return -1;
+ else
+ return 0;
+}
+
+static void
+modified_frame_data_free(gpointer data)
+{
+ modified_frame_data *mfd = (modified_frame_data *)data;
+
+ g_free(mfd->pd);
+ g_free(mfd);
+}
+
+/*
+ * Give a frame new, edited data.
+ */
+void
+cf_set_frame_edited(capture_file *cf, frame_data *fd,
+ struct wtap_pkthdr *phdr, guint8 *pd)
+{
+ modified_frame_data *mfd = (modified_frame_data *)g_malloc(sizeof(modified_frame_data));
+
+ mfd->phdr = *phdr;
+ mfd->pd = pd;
+
+ if (cf->edited_frames == NULL)
+ cf->edited_frames = g_tree_new_full(g_direct_compare_func, NULL, NULL,
+ modified_frame_data_free);
+ g_tree_insert(cf->edited_frames, GINT_TO_POINTER(fd->num), mfd);
+ fd->file_off = -1;
+
+ /* Mark the file as having unsaved changes */
+ cf->unsaved_changes = TRUE;
+}
+#endif
+
typedef struct {
wtap_dumper *pdh;
const char *fname;
@@ -4050,7 +4094,7 @@ typedef struct {
* up a message box for the failure.
*/
static gboolean
-save_record(capture_file *cf _U_, frame_data *fdata,
+save_record(capture_file *cf, frame_data *fdata,
struct wtap_pkthdr *phdr, const guint8 *pd,
void *argsp)
{
diff --git a/file.h b/file.h
index 79c76d29f3..51ed688f6d 100644
--- a/file.h
+++ b/file.h
@@ -673,6 +673,18 @@ gboolean cf_set_user_packet_comment(capture_file *cf, frame_data *fd, const gcha
*/
guint32 cf_comment_types(capture_file *cf);
+#ifdef WANT_PACKET_EDITOR
+/**
+ * Give a frame new, edited data.
+ *
+ * @param cf the capture file
+ * @param fd frame_data structure for the frame
+ * @param phdr the struct wtap_pkthdr for the frame
+ * @param pd the raw packet data for the frame
+ */
+void cf_set_frame_edited(capture_file *cf, frame_data *fd, struct wtap_pkthdr *phdr, guint8 *pd);
+#endif
+
#if defined(HAVE_HEIMDAL_KERBEROS) || defined(HAVE_MIT_KERBEROS)
WS_DLL_PUBLIC
void read_keytab_file(const char *);
diff --git a/ui/gtk/packet_win.c b/ui/gtk/packet_win.c
index 5be2aa707b..b842e9425a 100644
--- a/ui/gtk/packet_win.c
+++ b/ui/gtk/packet_win.c
@@ -900,22 +900,6 @@ edit_pkt_destroy_new_window(GObject *object _U_, gpointer user_data)
/* XXX, notify main packet list that packet should be redisplayed */
}
-static gint g_direct_compare_func(gconstpointer a, gconstpointer b, gpointer user_data _U_) {
- if (a > b)
- return 1;
- else if (a < b)
- return -1;
- else
- return 0;
-}
-
-static void modifed_frame_data_free(gpointer data) {
- modified_frame_data *mfd = (modified_frame_data *) data;
-
- g_free(mfd->pd);
- g_free(mfd);
-}
-
#endif /* WANT_PACKET_EDITOR */
void new_packet_window(GtkWidget *w _U_, gboolean reference, gboolean editable _U_)
@@ -1044,15 +1028,11 @@ void new_packet_window(GtkWidget *w _U_, gboolean reference, gboolean editable _
#ifdef WANT_PACKET_EDITOR
if (editable && DataPtr->frame->cap_len != 0) {
/* XXX, there's no Save button here, so lets assume packet is always edited */
- modified_frame_data *mfd = (modified_frame_data *)g_malloc(sizeof(modified_frame_data));
-
- mfd->pd = DataPtr->pd;
- mfd->phdr = DataPtr->phdr;
+ cf_set_frame_edited(&cfile, DataPtr->frame, &DataPtr->phdr,
+ DataPtr->pd);
- if (cfile.edited_frames == NULL)
- cfile.edited_frames = g_tree_new_full(g_direct_compare_func, NULL, NULL, modifed_frame_data_free);
- g_tree_insert(cfile.edited_frames, GINT_TO_POINTER(DataPtr->frame->num), mfd);
- DataPtr->frame->file_off = -1;
+ /* Update the main window, as we now have unsaved changes. */
+ main_update_for_unsaved_changes(&cfile);
}
#endif
}