diff options
author | Guy Harris <guy@alum.mit.edu> | 2013-04-01 21:17:50 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2013-04-01 21:17:50 +0000 |
commit | b1ecd8d217502b6223ffed2ea0d0edabb5a9f81f (patch) | |
tree | 26c9b757d7e493fc8a2bc455062bdae3db75df34 /wiretap/file_access.c | |
parent | 82a602d697b03314a11b3fd914dc7173fe18b293 (diff) |
Add a wtap_dump_can_write() routine that indicates whether Wiretap
supports writing files with a given set of encapsulations and comment
types. Use it, rather than asking for a list of file formats that
support the given set of encapsulation and comment types and checking
whether we got back such a list, or duplicating its logic.
Having file.c use it means that nobody's using
wtap_dump_can_write_encaps() any more; get rid of it. Instead, have a
private routine that checks whether a given file format supports a given
set of encapsulations *and* comment types, and use that internally.
svn path=/trunk/; revision=48690
Diffstat (limited to 'wiretap/file_access.c')
-rw-r--r-- | wiretap/file_access.c | 70 |
1 files changed, 53 insertions, 17 deletions
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); } |