From 2bd813507a5a42c298d09ac8d83ca1eebd8db277 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Sun, 17 Jun 2012 16:44:09 +0000 Subject: Export a wtap_dump_can_write_encaps() routine from Wiretap; it takes a file type and a GArray of encapsulation types and returns TRUE if a capture with all those encapsulation types can be written to a file in that file type and FALSE otherwise. Use it where appropriate. svn path=/trunk/; revision=43315 --- file.c | 4 ++-- ui/win32/file_dlg_win32.c | 19 +++---------------- wiretap/file_access.c | 25 +++++++++++++++---------- wiretap/wtap.def | 1 + wiretap/wtap.h | 7 +++++++ 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/file.c b/file.c index f1ceba02ce..97152e49f5 100644 --- a/file.c +++ b/file.c @@ -3843,8 +3843,8 @@ cf_can_save_as(capture_file *cf) 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 type. */ - if (wtap_dump_can_open(ft) && wtap_dump_can_write_encap(ft, cf->lnk_t)) { + 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; } diff --git a/ui/win32/file_dlg_win32.c b/ui/win32/file_dlg_win32.c index 7b17b1792f..a1093b985d 100644 --- a/ui/win32/file_dlg_win32.c +++ b/ui/win32/file_dlg_win32.c @@ -1503,19 +1503,6 @@ open_file_hook_proc(HWND of_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) { return 0; } -/* XXX - Copied verbatim from ui/gtk/capture_file_dlg.c. Perhaps it - * should be in wiretap instead? - */ - -static gboolean -can_save_with_wiretap(int 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 type. */ - return wtap_dump_can_open(ft) && wtap_dump_can_write_encap(ft, cfile.lnk_t); -} - /* Generate a list of the file types we can save this file as. "filetype" is the type it has now. @@ -1651,7 +1638,7 @@ build_file_format_list(HWND sf_hwnd) { if (!packet_range_process_all(&g_range) || ft != cfile.cd_t) { /* not all unfiltered packets or a different file type. We have to use Wiretap. */ - if (!can_save_with_wiretap(ft)) + if (!wtap_can_save_with_wiretap(ft, cfile.linktypes)) continue; /* We can't. */ } @@ -1707,7 +1694,7 @@ save_as_file_hook_proc(HWND sf_hwnd, UINT msg, WPARAM w_param, LPARAM l_param) { new_filetype = SendMessage(cur_ctrl, CB_GETITEMDATA, (WPARAM) index, 0); if (new_filetype != CB_ERR) { if (filetype != new_filetype) { - if (can_save_with_wiretap(new_filetype)) { + if (wtap_can_save_with_wiretap(new_filetype, cfile.linktypes)) { cur_ctrl = GetDlgItem(sf_hwnd, EWFD_CAPTURED_BTN); EnableWindow(cur_ctrl, TRUE); cur_ctrl = GetDlgItem(sf_hwnd, EWFD_DISPLAYED_BTN); @@ -1810,7 +1797,7 @@ export_specified_packets_file_hook_proc(HWND sf_hwnd, UINT msg, WPARAM w_param, new_filetype = SendMessage(cur_ctrl, CB_GETITEMDATA, (WPARAM) index, 0); if (new_filetype != CB_ERR) { if (filetype != new_filetype) { - if (can_save_with_wiretap(new_filetype)) { + if (wtap_can_save_with_wiretap(new_filetype, cfile.linktypes)) { cur_ctrl = GetDlgItem(sf_hwnd, EWFD_CAPTURED_BTN); EnableWindow(cur_ctrl, TRUE); cur_ctrl = GetDlgItem(sf_hwnd, EWFD_DISPLAYED_BTN); diff --git a/wiretap/file_access.c b/wiretap/file_access.c index 8255cff423..17a2e3cae6 100644 --- a/wiretap/file_access.c +++ b/wiretap/file_access.c @@ -762,11 +762,11 @@ int wtap_get_num_file_types(void) } /* - * 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 WTAP_ENCAP_ type. + * 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. */ -static gboolean -can_save_with_wiretap(int ft, const GArray *file_encaps) +gboolean +wtap_dump_can_write_encaps(int ft, const GArray *file_encaps) { guint i; @@ -800,6 +800,11 @@ can_save_with_wiretap(int ft, const GArray *file_encaps) return TRUE; } +/* + * 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. + */ GArray * wtap_get_savable_file_types(int file_type, const GArray *file_encaps) { @@ -809,19 +814,19 @@ 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 (can_save_with_wiretap(file_type, file_encaps)) { + if (wtap_dump_can_write(file_type, file_encaps)) { /* Yes - make that the default file type. */ default_file_type = file_type; } else { /* No - can we save it as a pcap-NG file? */ - if (can_save_with_wiretap(WTAP_FILE_PCAPNG, file_encaps)) { + if (wtap_dump_can_write(WTAP_FILE_PCAPNG, file_encaps)) { /* Yes - default to pcap-NG, instead. */ default_file_type = WTAP_FILE_PCAPNG; } 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 (can_save_with_wiretap(ft, file_encaps)) { + if (wtap_dump_can_write(ft, file_encaps)) { /* OK, got it. */ default_file_type = ft; } @@ -843,10 +848,10 @@ wtap_get_savable_file_types(int file_type, const GArray *file_encaps) /* If it's pcap, put pcap-NG right after it; otherwise, if it's pcap-NG, put pcap right after it. */ if (default_file_type == WTAP_FILE_PCAP) { - if (can_save_with_wiretap(WTAP_FILE_PCAPNG, file_encaps)) + if (wtap_dump_can_write(WTAP_FILE_PCAPNG, file_encaps)) other_file_type = WTAP_FILE_PCAPNG; } else if (default_file_type == WTAP_FILE_PCAPNG) { - if (can_save_with_wiretap(WTAP_FILE_PCAP, file_encaps)) + if (wtap_dump_can_write(WTAP_FILE_PCAP, file_encaps)) other_file_type = WTAP_FILE_PCAP; } if (other_file_type != -1) @@ -858,7 +863,7 @@ 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 (can_save_with_wiretap(ft, file_encaps)) { + if (wtap_dump_can_write(ft, file_encaps)) { /* OK, we can write it out in this type. */ g_array_append_val(savable_file_types, ft); } diff --git a/wiretap/wtap.def b/wiretap/wtap.def index 143e25f554..7da50417a2 100644 --- a/wiretap/wtap.def +++ b/wiretap/wtap.def @@ -30,6 +30,7 @@ wtap_default_file_extension wtap_dump wtap_dump_can_open wtap_dump_can_write_encap +wtap_dump_can_write_encaps wtap_dump_can_compress wtap_dump_close wtap_dump_fdopen diff --git a/wiretap/wtap.h b/wiretap/wtap.h index 7ef23fb308..f5cb8e4b1c 100644 --- a/wiretap/wtap.h +++ b/wiretap/wtap.h @@ -1097,6 +1097,13 @@ void wtap_close(wtap *wth); /*** dump packets into a capture file ***/ gboolean wtap_dump_can_open(int filetype); gboolean wtap_dump_can_write_encap(int filetype, int encap); + +/** + * 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. + */ +gboolean wtap_dump_can_write_encaps(int ft, const GArray *file_encaps); + gboolean wtap_dump_can_compress(int filetype); gboolean wtap_dump_has_name_resolution(int filetype); -- cgit v1.2.1