aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/wtap.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-11-18 14:10:00 -0800
committerGuy Harris <guy@alum.mit.edu>2018-11-18 22:10:42 +0000
commitbf9286e554c8d2b9e506b62dc7c0ed8f6e830160 (patch)
tree7057b13cf88f642626c5cc0272a52d0a389d3c61 /wiretap/wtap.c
parent189f1ceec25f4900e25b6faea5f15aeb27a08c7e (diff)
Add an API to get the file extension for a compression type, and use it.
Add wtap_compressed_file_extension(), which returns NULL for WTAP_UNCOMPRESSED and the appropriate file extension for other compression types. Add wtap_compression_type_supported(), which returns TRUE for WTAP_UNCOMPRESSED and all supported compression types and FALSE otherwise. ("Supported" means "the code can decompmress files in that compression format and can write files in that compression format", so WTAP_GAIP_COMPRESSED is supported iff libwiretap is built with zlib.) In MainWindow::fileAddExtension, instead of checking for WTAP_GZIP_COMPRESSED and using ".gz" as the extension, use the extension returned by wtap_compressed_file_extension() for the compression type. Change-Id: I47cb0eca8c887ada3562df30b54e76509008180f Reviewed-on: https://code.wireshark.org/review/30707 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wiretap/wtap.c')
-rw-r--r--wiretap/wtap.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/wiretap/wtap.c b/wiretap/wtap.c
index a9ee84c3eb..5d32180d56 100644
--- a/wiretap/wtap.c
+++ b/wiretap/wtap.c
@@ -86,6 +86,25 @@ wtap_get_compression_type(wtap *wth)
return is_compressed ? WTAP_GZIP_COMPRESSED : WTAP_UNCOMPRESSED;
}
+/*
+ * Indicate whether a given compression type is supported.
+ */
+static const gboolean compression_type_supported[WTAP_NUM_COMPRESSION_TYPES] = {
+ TRUE,
+#ifdef HAVE_ZLIB
+ TRUE
+#else
+ FALSE
+#endif
+};
+
+gboolean
+wtap_compression_type_supported(wtap_compression_type compression_type)
+{
+ g_assert(compression_type >= 0 && compression_type < WTAP_NUM_COMPRESSION_TYPES);
+ return compression_type_supported[compression_type];
+}
+
static const char *compression_type_descriptions[WTAP_NUM_COMPRESSION_TYPES] = {
NULL, /* uncompressed */
"gzip compressed"
@@ -98,6 +117,27 @@ wtap_compression_type_description(wtap_compression_type compression_type)
return compression_type_descriptions[compression_type];
}
+/*
+ * List of extensions for compressed files.
+ * If we add support for more compressed file types, this table
+ * might be expanded to include routines to handle the various
+ * compression types.
+ *
+ * The entry is NULL for WTAP_UNCOMPRESSED, as it's not a compression type,
+ * and thus has no suffix to indicate the compression type.
+ */
+static const char *compressed_file_extensions[WTAP_NUM_COMPRESSION_TYPES] = {
+ NULL,
+ "gz"
+};
+
+const char *
+wtap_compressed_file_extension(wtap_compression_type compression_type)
+{
+ g_assert(compression_type >= 0 && compression_type < WTAP_NUM_COMPRESSION_TYPES);
+ return compressed_file_extensions[compression_type];
+}
+
guint
wtap_snapshot_length(wtap *wth)
{