aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2013-04-01 20:36:42 +0000
committerGuy Harris <guy@alum.mit.edu>2013-04-01 20:36:42 +0000
commit82a602d697b03314a11b3fd914dc7173fe18b293 (patch)
tree85adc187849d0ebcbcc2997db1edfab1ab15fd2f /ui
parent2deedfb1e1288e79341bf05704f0662c251897e7 (diff)
Define a collection of bits for different types of capture file comments.
For each capture file type, have a bitset of comment types supported by that capture file type. Add a Wiretap routine that, for a given file type, returns the bitset of comment types it supports. Have wtap_get_savable_file_types() take a bitset of comment types that need to be supported by the file types it returns. Replace cf_has_comments() with a routine that returns a bitset of capture file comment types in the capture file. Use those routines in the capture file dialogs; don't wire in the notion that pcap-NG supports all comment types and no other file formats support any comment types. (That's currently true, but we don't want to wire that in as being forever true.) svn path=/trunk/; revision=48689
Diffstat (limited to 'ui')
-rw-r--r--ui/gtk/capture_file_dlg.c99
-rw-r--r--ui/qt/capture_file_dialog.cpp58
-rw-r--r--ui/win32/file_dlg_win32.c62
3 files changed, 116 insertions, 103 deletions
diff --git a/ui/gtk/capture_file_dlg.c b/ui/gtk/capture_file_dlg.c
index 5b14d20af5..573057d6d8 100644
--- a/ui/gtk/capture_file_dlg.c
+++ b/ui/gtk/capture_file_dlg.c
@@ -80,11 +80,12 @@
#endif
static void do_file_save(capture_file *cf, gboolean dont_reopen);
-static void file_save_as_cmd(capture_file *cf, gboolean must_support_comments,
+static void file_save_as_cmd(capture_file *cf,
+ gboolean must_support_all_comments,
gboolean dont_reopen);
static void file_select_file_type_cb(GtkWidget *w, gpointer data);
static int set_file_type_list(GtkWidget *combo_box, capture_file *cf,
- gboolean must_support_comments);
+ gboolean must_support_all_comments);
static gboolean test_file_close(capture_file *cf, gboolean from_quit,
const char *before_what);
@@ -1289,31 +1290,29 @@ file_close_cmd_cb(GtkWidget *widget _U_, gpointer data _U_) {
static check_savability_t
check_save_with_comments(capture_file *cf)
{
+ guint32 comment_types;
+ GArray *savable_file_types;
GtkWidget *msg_dialog;
gint response;
- /* Do we have any comments? */
- if (!cf_has_comments(cf)) {
- /* No. Let the save happen; no comments to delete. */
- return SAVE;
- }
+ /* What types of comments do we have? */
+ comment_types = cf_comment_types(cf);
- /* OK, we have comments. Can we write them out in the file's format?
-
- XXX - for now, we "know" that pcap-ng is the only format for which
- we support comments. We should really ask Wiretap what the
- format in question supports (and handle different types of
- comments, some but not all of which some file formats might
- not support). */
- if (cf->cd_t == WTAP_FILE_PCAPNG) {
- /* Yes - the file is a pcap-ng file. Let the save happen; we can
- save the comments, so no need to delete them. */
+ /* Does the file's format support all the comments we have? */
+ if (wtap_dump_supports_comment_types(cf->cd_t, comment_types)) {
+ /* Yes. Let the save happen; we can save all the comments, so
+ there's no need to delete them. */
return SAVE;
}
- /* Is pcap-ng one of the formats in which we can write this file? */
- if (wtap_dump_can_write_encaps(WTAP_FILE_PCAPNG, cf->linktypes)) {
- /* Yes. Ooffer the user a choice of "Save in a format that
+ /* 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);
+
+ /* 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
saving the file at all". */
@@ -1511,14 +1510,23 @@ file_save_cmd_cb(GtkWidget *w _U_, gpointer data _U_) {
Returns the default file type. */
static int
set_file_type_list(GtkWidget *combo_box, capture_file *cf,
- gboolean must_support_comments)
+ gboolean must_support_all_comments)
{
+ guint32 required_comment_types;
GArray *savable_file_types;
guint i;
int ft;
int default_ft = -1;
- savable_file_types = wtap_get_savable_file_types(cf->cd_t, cf->linktypes);
+ /* What types of comments do we have to support? */
+ if (must_support_all_comments)
+ required_comment_types = cf_comment_types(cf); /* all the ones the file has */
+ else
+ required_comment_types = 0; /* none of them */
+
+ /* What types of file can we save this file as? */
+ savable_file_types = wtap_get_savable_file_types(cf->cd_t, cf->linktypes,
+ required_comment_types);
if (savable_file_types != NULL) {
/* OK, we have at least one file type we can save this file as.
@@ -1526,10 +1534,6 @@ set_file_type_list(GtkWidget *combo_box, capture_file *cf,
place.) Add them all to the combo box. */
for (i = 0; i < savable_file_types->len; i++) {
ft = g_array_index(savable_file_types, int, i);
- if (must_support_comments) {
- if (ft != WTAP_FILE_PCAPNG)
- continue;
- }
if (default_ft == -1)
default_ft = ft; /* first file type is the default */
ws_combo_box_append_text_and_pointer(GTK_COMBO_BOX(combo_box),
@@ -1572,27 +1576,28 @@ file_select_file_type_cb(GtkWidget *w, gpointer parent_arg)
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;
- /* Do we have any comments? */
- if (!cf_has_comments(cf)) {
- /* No. Let the save happen; no comments to delete. */
- return SAVE;
- }
+ /* What types of comments do we have? */
+ comment_types = cf_comment_types(cf);
- /* XXX - for now, we "know" that pcap-ng is the only format for which
- we support comments. We should really ask Wiretap what the
- format in question supports (and handle different types of
- comments, some but not all of which some file formats might
- not support). */
- if (file_type == WTAP_FILE_PCAPNG) {
- /* Yes - they selected pcap-ng. Let the save happen; we can
- save the comments, so no need to delete them. */
+ /* Does the file's format support all the comments we have? */
+ if (wtap_dump_supports_comment_types(file_type, comment_types)) {
+ /* Yes. Let the save happen; we can save all the comments, so
+ there's no need to delete them. */
return SAVE;
}
- /* No. Is pcap-ng one of the formats in which we can write this file? */
- if (wtap_dump_can_write_encaps(WTAP_FILE_PCAPNG, cf->linktypes)) {
+
+ /* 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);
+
/* 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
@@ -1693,7 +1698,7 @@ gtk_check_save_as_with_comments(GtkWidget *w, capture_file *cf, int file_type)
/* "Save as" */
static gboolean
gtk_save_as_file(GtkWidget *w _U_, capture_file *cf, GString *file_name, int *file_type,
- gboolean *compressed, gboolean must_support_comments)
+ gboolean *compressed, gboolean must_support_all_comments)
{
GtkWidget *file_save_as_w;
GtkWidget *main_vb, *ft_hb, *ft_lb, *ft_combo_box, *compressed_cb;
@@ -1731,7 +1736,7 @@ gtk_save_as_file(GtkWidget *w _U_, capture_file *cf, GString *file_name, int *fi
ft_combo_box = ws_combo_box_new_text_and_pointer();
/* Generate the list of file types we can save. */
- default_ft = set_file_type_list(ft_combo_box, cf, must_support_comments);
+ default_ft = set_file_type_list(ft_combo_box, cf, must_support_all_comments);
gtk_box_pack_start(GTK_BOX(ft_hb), ft_combo_box, FALSE, FALSE, 0);
gtk_widget_show(ft_combo_box);
g_object_set_data(G_OBJECT(file_save_as_w), E_FILE_TYPE_COMBO_BOX_KEY, ft_combo_box);
@@ -1841,7 +1846,7 @@ file_add_extension(GString *file_name, int file_type, gboolean compressed) {
*/
static void
-file_save_as_cmd(capture_file *cf, gboolean must_support_comments,
+file_save_as_cmd(capture_file *cf, gboolean must_support_all_comments,
gboolean dont_reopen)
{
GString *file_name = g_string_new("");
@@ -1857,12 +1862,12 @@ file_save_as_cmd(capture_file *cf, gboolean must_support_comments,
for (;;) {
#ifdef USE_WIN32_FILE_DIALOGS
if (win32_save_as_file(GDK_WINDOW_HWND(gtk_widget_get_window(top_level)), cf,
- file_name, &file_type, &compressed, must_support_comments)) {
+ file_name, &file_type, &compressed, must_support_all_comments)) {
/* They discarded comments, so redraw the packet details window
to reflect any packets that no longer have comments. */
packet_list_queue_draw();
#else /* USE_WIN32_FILE_DIALOGS */
- if (gtk_save_as_file(top_level, cf, file_name, &file_type, &compressed, must_support_comments)) {
+ if (gtk_save_as_file(top_level, cf, file_name, &file_type, &compressed, must_support_all_comments)) {
#endif /* USE_WIN32_FILE_DIALOGS */
/* If the file has comments, does the format the user selected
@@ -1896,7 +1901,7 @@ file_save_as_cmd(capture_file *cf, gboolean must_support_comments,
so run the dialog again, to let the user decide
whether to save in one of those formats or give up. */
discard_comments = FALSE;
- must_support_comments = TRUE;
+ must_support_all_comments = TRUE;
continue;
case CANCELLED:
diff --git a/ui/qt/capture_file_dialog.cpp b/ui/qt/capture_file_dialog.cpp
index ac15a79bc0..2e2a992263 100644
--- a/ui/qt/capture_file_dialog.cpp
+++ b/ui/qt/capture_file_dialog.cpp
@@ -135,27 +135,28 @@ check_savability_t CaptureFileDialog::checkSaveAsWithComments(QWidget *
return CANCELLED;
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;
- /* Do we have any comments? */
- if (!cf_has_comments(cf)) {
- /* No. Let the save happen; no comments to delete. */
- return SAVE;
- }
+ /* What types of comments do we have? */
+ comment_types = cf_comment_types(cf);
- /* XXX - for now, we "know" that pcap-ng is the only format for which
- we support comments. We should really ask Wiretap what the
- format in question supports (and handle different types of
- comments, some but not all of which some file formats might
- not support). */
- if (file_type == WTAP_FILE_PCAPNG) {
- /* Yes - they selected pcap-ng. Let the save happen; we can
- save the comments, so no need to delete them. */
+ /* Does the file's format support all the comments we have? */
+ if (wtap_dump_supports_comment_types(file_type, comment_types)) {
+ /* Yes. Let the save happen; we can save all the comments, so
+ there's no need to delete them. */
return SAVE;
}
- /* No. Is pcap-ng one of the formats in which we can write this file? */
- if (wtap_dump_can_write_encaps(WTAP_FILE_PCAPNG, cf->linktypes)) {
+
+ /* 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);
+
QPushButton *default_button;
/* Yes. Offer the user a choice of "Save in a format that
supports comments", "Discard comments and save in the
@@ -250,11 +251,11 @@ int CaptureFileDialog::open(QString &file_name) {
return (int) wof_status;
}
-check_savability_t CaptureFileDialog::saveAs(QString &file_name, bool must_support_comments) {
+check_savability_t CaptureFileDialog::saveAs(QString &file_name, bool must_support_all_comments) {
GString *fname = g_string_new(file_name.toUtf8().constData());
gboolean wsf_status;
- wsf_status = win32_save_as_file(parentWidget()->effectiveWinId(), cap_file_, fname, &file_type_, &compressed_, must_support_comments);
+ wsf_status = win32_save_as_file(parentWidget()->effectiveWinId(), cap_file_, fname, &file_type_, &compressed_, must_support_all_comments);
file_name = fname->str;
g_string_free(fname, TRUE);
@@ -518,12 +519,12 @@ int CaptureFileDialog::open(QString &file_name) {
}
}
-check_savability_t CaptureFileDialog::saveAs(QString &file_name, bool must_support_comments) {
+check_savability_t CaptureFileDialog::saveAs(QString &file_name, bool must_support_all_comments) {
setWindowTitle(tr("Wireshark: Save Capture File As"));
// XXX There doesn't appear to be a way to use setNameFilters without restricting
// what the user can select. We might want to use our own combobox instead and
// let the user select anything.
- setNameFilters(buildFileSaveAsTypeList(must_support_comments));
+ setNameFilters(buildFileSaveAsTypeList(must_support_all_comments));
setAcceptMode(QFileDialog::AcceptSave);
setLabelText(FileType, tr("Save as:"));
@@ -605,13 +606,24 @@ int CaptureFileDialog::merge(QString &file_name) {
}
}
-QStringList CaptureFileDialog::buildFileSaveAsTypeList(bool must_support_comments) {
+QStringList CaptureFileDialog::buildFileSaveAsTypeList(bool must_support_all_comments) {
QStringList filters;
+ guint32 required_comment_types;
GArray *savable_file_types;
guint i;
type_hash_.clear();
- savable_file_types = wtap_get_savable_file_types(cap_file_->cd_t, cap_file_->linktypes);
+
+ /* What types of comments do we have to support? */
+ if (must_support_all_comments)
+ required_comment_types = cf_comment_types(cap_file_); /* all the ones the file has */
+ else
+ required_comment_types = 0; /* none of them */
+
+ /* What types of file can we save this file as? */
+ savable_file_types = wtap_get_savable_file_types(cap_file_->cd_t,
+ cap_file_->linktypes,
+ required_comment_types);
if (savable_file_types != NULL) {
QString file_type;
@@ -621,10 +633,6 @@ QStringList CaptureFileDialog::buildFileSaveAsTypeList(bool must_support_comment
place.) Add them all to the combo box. */
for (i = 0; i < savable_file_types->len; i++) {
ft = g_array_index(savable_file_types, int, i);
- if (must_support_comments) {
- if (ft != WTAP_FILE_PCAPNG)
- continue;
- }
if (default_ft_ < 1)
default_ft_ = ft; /* first file type is the default */
file_type = fileType(ft);
diff --git a/ui/win32/file_dlg_win32.c b/ui/win32/file_dlg_win32.c
index ad1bb6478a..e1fcb8c3f6 100644
--- a/ui/win32/file_dlg_win32.c
+++ b/ui/win32/file_dlg_win32.c
@@ -110,8 +110,7 @@ static void range_handle_wm_initdialog(HWND dlg_hwnd, packet_range_t *range);
static void range_handle_wm_command(HWND dlg_hwnd, HWND ctrl, WPARAM w_param, packet_range_t *range);
static TCHAR *build_file_open_type_list(void);
-static TCHAR *build_file_save_type_list(GArray *savable_file_types,
- gboolean must_support_comments);
+static TCHAR *build_file_save_type_list(GArray *savable_file_types);
static int g_filetype;
static gboolean g_compressed;
@@ -238,29 +237,27 @@ win32_open_file (HWND h_wnd, GString *file_name, GString *display_filter) {
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;
- /* Do we have any comments? */
- if (!cf_has_comments(cf)) {
- /* No. Let the save happen; no comments to delete. */
+ /* What types of comments do we have? */
+ comment_types = cf_comment_types(cf);
+
+ /* Does the file's format support all the comments we have? */
+ if (wtap_dump_supports_comment_types(cf->cd_t, comment_types)) {
+ /* Yes. Let the save happen; we can save all the comments, so
+ there's no need to delete them. */
return SAVE;
}
- /* OK, we have comments. Can we write them out in the selected
- format?
+ /* 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);
- XXX - for now, we "know" that pcap-ng is the only format for which
- we support comments. We should really ask Wiretap what the
- format in question supports (and handle different types of
- comments, some but not all of which some file formats might
- not support). */
- if (file_type == WTAP_FILE_PCAPNG) {
- /* Yes - they selected pcap-ng. Let the save happen; we can
- save the comments, so no need to delete them. */
- return SAVE;
- }
- /* No. Is pcap-ng one of the formats in which we can write this file? */
- if (wtap_dump_can_write_encaps(WTAP_FILE_PCAPNG, cf->linktypes)) {
/* 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
@@ -335,8 +332,9 @@ win32_check_save_as_with_comments(HWND parent, capture_file *cf, int file_type)
gboolean
win32_save_as_file(HWND h_wnd, capture_file *cf, GString *file_name, int *file_type,
- gboolean *compressed, gboolean must_support_comments)
+ gboolean *compressed, gboolean must_support_all_comments)
{
+ guint32 required_comment_types;
GArray *savable_file_types;
OPENFILENAME *ofn;
TCHAR file_name16[MAX_PATH] = _T("");
@@ -354,7 +352,14 @@ win32_save_as_file(HWND h_wnd, capture_file *cf, GString *file_name, int *file_t
StringCchCopy(file_name16, MAX_PATH, utf_8to16(file_name->str));
}
- savable_file_types = wtap_get_savable_file_types(cf->cd_t, cf->linktypes);
+ /* What types of comments do we have to support? */
+ if (must_support_all_comments)
+ required_comment_types = cf_comment_types(cf); /* all the ones the file has */
+ else
+ required_comment_types = 0; /* none of them */
+
+ savable_file_types = wtap_get_savable_file_types(cf->cd_t, cf->linktypes,
+ required_comment_types);
if (savable_file_types == NULL)
return FALSE; /* shouldn't happen - the "Save As..." item should be disabled if we can't save the file */
g_compressed = FALSE;
@@ -377,8 +382,7 @@ win32_save_as_file(HWND h_wnd, capture_file *cf, GString *file_name, int *file_t
ofn->lStructSize = ofnsize;
ofn->hwndOwner = h_wnd;
ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
- ofn->lpstrFilter = build_file_save_type_list(savable_file_types,
- must_support_comments);
+ ofn->lpstrFilter = build_file_save_type_list(savable_file_types);
ofn->lpstrCustomFilter = NULL;
ofn->nMaxCustFilter = 0;
ofn->nFilterIndex = 1; /* the first entry is the best match; 1-origin indexing */
@@ -442,7 +446,8 @@ win32_export_specified_packets_file(HWND h_wnd, GString *file_name,
StringCchCopy(file_name16, MAX_PATH, utf_8to16(file_name->str));
}
- savable_file_types = wtap_get_savable_file_types(cfile.cd_t, cfile.linktypes);
+ savable_file_types = wtap_get_savable_file_types(cfile.cd_t,
+ cfile.linktypes, 0);
if (savable_file_types == NULL)
return FALSE; /* shouldn't happen - the "Save As..." item should be disabled if we can't save the file */
@@ -467,7 +472,7 @@ win32_export_specified_packets_file(HWND h_wnd, GString *file_name,
ofn->lStructSize = ofnsize;
ofn->hwndOwner = h_wnd;
ofn->hInstance = (HINSTANCE) GetWindowLongPtr(h_wnd, GWLP_HINSTANCE);
- ofn->lpstrFilter = build_file_save_type_list(savable_file_types, FALSE);
+ ofn->lpstrFilter = build_file_save_type_list(savable_file_types);
ofn->lpstrCustomFilter = NULL;
ofn->nMaxCustFilter = 0;
ofn->nFilterIndex = 1; /* the first entry is the best match; 1-origin indexing */
@@ -1522,8 +1527,7 @@ build_file_open_type_list(void) {
}
static TCHAR *
-build_file_save_type_list(GArray *savable_file_types,
- gboolean must_support_comments) {
+build_file_save_type_list(GArray *savable_file_types) {
guint i;
int ft;
GArray* sa = g_array_new(FALSE /*zero_terminated*/, FALSE /*clear_*/,2 /*element_size*/);
@@ -1532,10 +1536,6 @@ build_file_save_type_list(GArray *savable_file_types,
/* Get only the file types as which we can save this file. */
for (i = 0; i < savable_file_types->len; i++) {
ft = g_array_index(savable_file_types, int, i);
- if (must_support_comments) {
- if (ft != WTAP_FILE_PCAPNG)
- continue;
- }
append_file_type(sa, ft);
}