diff options
-rw-r--r-- | file.c | 22 | ||||
-rw-r--r-- | ui/gtk/capture_file_dlg.c | 14 | ||||
-rw-r--r-- | ui/qt/capture_file_dialog.cpp | 7 | ||||
-rw-r--r-- | ui/win32/file_dlg_win32.c | 7 | ||||
-rw-r--r-- | wiretap/file_access.c | 70 | ||||
-rw-r--r-- | wiretap/wtap.h | 14 |
6 files changed, 72 insertions, 62 deletions
@@ -3971,20 +3971,14 @@ save_packet(capture_file *cf _U_, frame_data *fdata, gboolean cf_can_write_with_wiretap(capture_file *cf) { - int ft; - - for (ft = 0; ft < WTAP_NUM_FILE_TYPES; ft++) { - /* To save a file with Wiretap, Wiretap has to handle that format, - and its code to handle that format must be able to write a file - with this file's encapsulation types. */ - if (wtap_dump_can_write_encaps(ft, cf->linktypes)) { - /* OK, we can write it out in this type. */ - return TRUE; - } - } - - /* No, we couldn't save it in any format. */ - return FALSE; + /* We don't care whether we support the comments in this file or not; + if we can't, we'll offer the user the option of discarding the + comments. + + XXX - we shouldn't offer the option of adding or editing comments + of a particular type if we don't support that particular type of + comment in any file format. */ + return wtap_dump_can_write(cf->linktypes, 0); } /* diff --git a/ui/gtk/capture_file_dlg.c b/ui/gtk/capture_file_dlg.c index 573057d6d8..cabbd712e3 100644 --- a/ui/gtk/capture_file_dlg.c +++ b/ui/gtk/capture_file_dlg.c @@ -1291,7 +1291,6 @@ static check_savability_t check_save_with_comments(capture_file *cf) { guint32 comment_types; - GArray *savable_file_types; GtkWidget *msg_dialog; gint response; @@ -1307,11 +1306,7 @@ check_save_with_comments(capture_file *cf) /* No. Are there formats in which we can write this file that supports all the comments in this file? */ - savable_file_types = wtap_get_savable_file_types(cf->cd_t, cf->linktypes, - comment_types); - if (savable_file_types != NULL) { - g_array_free(savable_file_types, TRUE); - + if (wtap_dump_can_write(cf->linktypes, comment_types)) { /* Yes. Offer the user a choice of "Save in a format that supports comments", "Discard comments and save in the file's own format", or "Cancel", meaning "don't bother @@ -1577,7 +1572,6 @@ static check_savability_t gtk_check_save_as_with_comments(GtkWidget *w, capture_file *cf, int file_type) { guint32 comment_types; - GArray *savable_file_types; GtkWidget *msg_dialog; gint response; @@ -1593,11 +1587,7 @@ gtk_check_save_as_with_comments(GtkWidget *w, capture_file *cf, int file_type) /* No. Are there formats in which we can write this file that supports all the comments in this file? */ - savable_file_types = wtap_get_savable_file_types(file_type, cf->linktypes, - comment_types); - if (savable_file_types != NULL) { - g_array_free(savable_file_types, TRUE); - + if (wtap_dump_can_write(cf->linktypes, comment_types)) { /* Yes. Offer the user a choice of "Save in a format that supports comments", "Discard comments and save in the format you selected", or "Cancel", meaning "don't bother diff --git a/ui/qt/capture_file_dialog.cpp b/ui/qt/capture_file_dialog.cpp index 2e2a992263..a62d0ad9c3 100644 --- a/ui/qt/capture_file_dialog.cpp +++ b/ui/qt/capture_file_dialog.cpp @@ -136,7 +136,6 @@ check_savability_t CaptureFileDialog::checkSaveAsWithComments(QWidget * return win32_check_save_as_with_comments(parent->effectiveWinId(), cf, file_type); #else // Q_WS_WIN guint32 comment_types; - GArray *savable_file_types; QMessageBox msg_dialog; int response; @@ -152,11 +151,7 @@ check_savability_t CaptureFileDialog::checkSaveAsWithComments(QWidget * /* No. Are there formats in which we can write this file that supports all the comments in this file? */ - savable_file_types = wtap_get_savable_file_types(file_type, cf->linktypes, - comment_types); - if (savable_file_types != NULL) { - g_array_free(savable_file_types, TRUE); - + if (wtap_dump_can_write(cf->linktypes, comment_types)) { QPushButton *default_button; /* Yes. Offer the user a choice of "Save in a format that supports comments", "Discard comments and save in the diff --git a/ui/win32/file_dlg_win32.c b/ui/win32/file_dlg_win32.c index e1fcb8c3f6..08e718c0fa 100644 --- a/ui/win32/file_dlg_win32.c +++ b/ui/win32/file_dlg_win32.c @@ -238,7 +238,6 @@ check_savability_t win32_check_save_as_with_comments(HWND parent, capture_file *cf, int file_type) { guint32 comment_types; - GArray *savable_file_types; gint response; /* What types of comments do we have? */ @@ -253,11 +252,7 @@ win32_check_save_as_with_comments(HWND parent, capture_file *cf, int file_type) /* No. Are there formats in which we can write this file that supports all the comments in this file? */ - savable_file_types = wtap_get_savable_file_types(cf->cd_t, cf->linktypes, - comment_types); - if (savable_file_types != NULL) { - g_array_free(savable_file_types, TRUE); - + if (wtap_dump_can_write(cf->linktypes, comment_types)) { /* Yes. Offer the user a choice of "Save in a format that supports comments", "Discard comments and save in the format you selected", or "Cancel", meaning "don't bother diff --git a/wiretap/file_access.c b/wiretap/file_access.c index 3e1e8b8e4a..bf0c22cf3e 100644 --- a/wiretap/file_access.c +++ b/wiretap/file_access.c @@ -877,11 +877,13 @@ wtap_dump_file_encap_type(const GArray *file_encaps) } /* - * Return TRUE if a capture with a given GArray of WTAP_ENCAP_ types - * can be written in a specified format, and FALSE if it can't. + * Return TRUE if a capture with a given GArray of encapsulation types + * and a given bitset of comment types can be written in a specified + * format, and FALSE if it can't. */ -gboolean -wtap_dump_can_write_encaps(int ft, const GArray *file_encaps) +static gboolean +wtap_dump_can_write_format(int ft, const GArray *file_encaps, + guint32 required_comment_types) { guint i; @@ -894,11 +896,22 @@ wtap_dump_can_write_encaps(int ft, const GArray *file_encaps) } /* - * Is the required per-file encapsulation type supported? + * Yes. Can we write out all the required comments in this + * format? + */ + if (!wtap_dump_supports_comment_types(ft, required_comment_types)) { + /* No. */ + return FALSE; + } + + /* + * Yes. Is the required per-file encapsulation type supported? * This might be WTAP_ENCAP_PER_PACKET. */ - if (!wtap_dump_can_write_encap(ft, wtap_dump_file_encap_type(file_encaps))) + if (!wtap_dump_can_write_encap(ft, wtap_dump_file_encap_type(file_encaps))) { + /* No. */ return FALSE; + } /* * Yes. Are all the individual encapsulation types supported? @@ -916,8 +929,31 @@ wtap_dump_can_write_encaps(int ft, const GArray *file_encaps) } /** + * Return TRUE if we can write a file with the given GArray of + * encapsulation types and the given bitmask of comment types. + */ +gboolean +wtap_dump_can_write(const GArray *file_encaps, guint32 required_comment_types) +{ + int ft; + + for (ft = 0; ft < WTAP_NUM_FILE_TYPES; ft++) { + /* To save a file with Wiretap, Wiretap has to handle that format, + and its code to handle that format must be able to write a file + with this file's encapsulation types. */ + if (wtap_dump_can_write_format(ft, file_encaps, required_comment_types)) { + /* OK, we can write it out in this type. */ + return TRUE; + } + } + + /* No, we couldn't save it in any format. */ + return FALSE; +} + +/** * Get a GArray of WTAP_FILE_ values for file types that can be used - * to save a file of a given type with a given GArray of WTAP_ENCAP_ + * to save a file of a given type with a given GArray of encapsulation * types and the given bitmask of comment types. */ GArray * @@ -930,16 +966,16 @@ wtap_get_savable_file_types(int file_type, const GArray *file_encaps, int other_file_type = -1; /* Can we save this file in its own file type? */ - if (wtap_dump_can_write_encaps(file_type, file_encaps) && - wtap_dump_supports_comment_types(file_type, required_comment_types)) { + if (wtap_dump_can_write_format(file_type, file_encaps, + required_comment_types)) { /* Yes - make that the default file type. */ default_file_type = file_type; } else { /* OK, find the first file type we *can* save it as. */ default_file_type = -1; for (ft = 0; ft < WTAP_NUM_FILE_TYPES; ft++) { - if (wtap_dump_can_write_encaps(ft, file_encaps) && - wtap_dump_supports_comment_types(ft, required_comment_types)) { + if (wtap_dump_can_write_format(ft, file_encaps, + required_comment_types)) { /* OK, got it. */ default_file_type = ft; } @@ -962,12 +998,12 @@ wtap_get_savable_file_types(int file_type, const GArray *file_encaps, pcap-NG, put pcap right after it if we can also write it in pcap format. */ if (default_file_type == WTAP_FILE_PCAP) { - if (wtap_dump_can_write_encaps(WTAP_FILE_PCAPNG, file_encaps) && - wtap_dump_supports_comment_types(WTAP_FILE_PCAPNG, required_comment_types)) + if (wtap_dump_can_write_format(WTAP_FILE_PCAPNG, file_encaps, + required_comment_types)) other_file_type = WTAP_FILE_PCAPNG; } else if (default_file_type == WTAP_FILE_PCAPNG) { - if (wtap_dump_can_write_encaps(WTAP_FILE_PCAP, file_encaps) && - wtap_dump_supports_comment_types(WTAP_FILE_PCAP, required_comment_types)) + if (wtap_dump_can_write_format(WTAP_FILE_PCAP, file_encaps, + required_comment_types)) other_file_type = WTAP_FILE_PCAP; } if (other_file_type != -1) @@ -979,8 +1015,8 @@ wtap_get_savable_file_types(int file_type, const GArray *file_encaps, continue; /* not a real file type */ if (ft == default_file_type || ft == other_file_type) continue; /* we've already done this one */ - if (wtap_dump_can_write_encaps(ft, file_encaps) && - wtap_dump_supports_comment_types(ft, required_comment_types)) { + if (wtap_dump_can_write_format(ft, file_encaps, + required_comment_types)) { /* OK, we can write it out in this type. */ g_array_append_val(savable_file_types, ft); } diff --git a/wiretap/wtap.h b/wiretap/wtap.h index 16bc87433e..1a1d1b8f97 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -1249,13 +1249,6 @@ WS_DLL_PUBLIC int wtap_dump_file_encap_type(const GArray *file_encaps); /** - * Return TRUE if a capture with a given GArray of WTAP_ENCAP_ types - * can be written in a specified format, and FALSE if it can't. - */ -WS_DLL_PUBLIC -gboolean wtap_dump_can_write_encaps(int ft, const GArray *file_encaps); - -/** * Return TRUE if we can write this capture file format out in * compressed form, FALSE if not. */ @@ -1308,6 +1301,13 @@ WS_DLL_PUBLIC gboolean wtap_dump_close(wtap_dumper *, int *); /** + * Return TRUE if we can write a file out with the given GArray of file + * encapsulations and the given bitmask of comment types. + */ +WS_DLL_PUBLIC +gboolean wtap_dump_can_write(const GArray *file_encaps, guint32 required_comment_types); + +/** * Get a GArray of WTAP_FILE_ values for file types that can be used * to save a file of a given type with a given GArray of WTAP_ENCAP_ * types and the given bitmask of comment types. |