diff options
-rw-r--r-- | file.c | 46 | ||||
-rw-r--r-- | file.h | 12 | ||||
-rw-r--r-- | ui/gtk/packet_win.c | 28 |
3 files changed, 61 insertions, 25 deletions
@@ -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) { @@ -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 } |