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>
This commit is contained in:
parent
189f1ceec2
commit
bf9286e554
|
@ -1665,7 +1665,7 @@ void MainWindow::fileAddExtension(QString &file_name, int file_type, wtap_compre
|
||||||
/* Get the extension for the compression type we'll be using, or
|
/* Get the extension for the compression type we'll be using, or
|
||||||
NULL if we won't be compressing it. */
|
NULL if we won't be compressing it. */
|
||||||
compressed_file_extension =
|
compressed_file_extension =
|
||||||
(compression_type == WTAP_UNCOMPRESSED) ? NULL : "gz";
|
(compression_type == WTAP_UNCOMPRESSED) ? NULL : wtap_compressed_file_extension(compression_type);
|
||||||
|
|
||||||
if (extensions_list != NULL) {
|
if (extensions_list != NULL) {
|
||||||
GSList *extension;
|
GSList *extension;
|
||||||
|
|
|
@ -78,30 +78,50 @@
|
||||||
#include "systemd_journal.h"
|
#include "systemd_journal.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add an extension, and all compressed versions thereof, to a GSList
|
* Add an extension, and all compressed versions thereof if requested,
|
||||||
* of extensions.
|
* to a GSList of extensions.
|
||||||
*/
|
*/
|
||||||
static GSList *
|
static GSList *
|
||||||
add_extensions(GSList *extensions, const gchar *extension,
|
add_extensions(GSList *extensions, const gchar *extension,
|
||||||
const char **compressed_file_extensions)
|
gboolean include_compressed)
|
||||||
{
|
{
|
||||||
const char **compressed_file_extensionp;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add the specified extension.
|
* Add the specified extension.
|
||||||
*/
|
*/
|
||||||
extensions = g_slist_prepend(extensions, g_strdup(extension));
|
extensions = g_slist_prepend(extensions, g_strdup(extension));
|
||||||
|
|
||||||
/*
|
if (include_compressed) {
|
||||||
* Now add the extensions for compressed-file versions of
|
/*
|
||||||
* that extension.
|
* We were asked to include the extensions for
|
||||||
*/
|
* compressed-file versions of that extension; do so.
|
||||||
for (compressed_file_extensionp = compressed_file_extensions;
|
*/
|
||||||
*compressed_file_extensionp != NULL;
|
for (wtap_compression_type compression_type = WTAP_UNCOMPRESSED;
|
||||||
compressed_file_extensionp++) {
|
compression_type < WTAP_NUM_COMPRESSION_TYPES;
|
||||||
extensions = g_slist_prepend(extensions,
|
compression_type++) {
|
||||||
g_strdup_printf("%s.%s", extension,
|
if (compression_type == WTAP_UNCOMPRESSED) {
|
||||||
*compressed_file_extensionp));
|
/*
|
||||||
|
* This isn't a compression type, so it has
|
||||||
|
* no extension.
|
||||||
|
*/
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!wtap_compression_type_supported(compression_type)) {
|
||||||
|
/*
|
||||||
|
* We don't support this compression type,
|
||||||
|
* so don't include its extension.
|
||||||
|
*/
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* It's a supported compression type, so append its
|
||||||
|
* extension to the extension we were handed, and
|
||||||
|
* include that as an extension pair.
|
||||||
|
*/
|
||||||
|
extensions = g_slist_prepend(extensions,
|
||||||
|
g_strdup_printf("%s.%s", extension,
|
||||||
|
wtap_compressed_file_extension(compression_type)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return extensions;
|
return extensions;
|
||||||
|
@ -192,8 +212,7 @@ wtap_get_file_extension_type_name(int extension_type)
|
||||||
}
|
}
|
||||||
|
|
||||||
static GSList *
|
static GSList *
|
||||||
add_extensions_for_file_extensions_type(int extension_type,
|
add_extensions_for_file_extensions_type(int extension_type, GSList *extensions)
|
||||||
GSList *extensions, const char **compressed_file_extensions)
|
|
||||||
{
|
{
|
||||||
gchar **extensions_set, **extensionp, *extension;
|
gchar **extensions_set, **extensionp, *extension;
|
||||||
|
|
||||||
|
@ -213,8 +232,7 @@ add_extensions_for_file_extensions_type(int extension_type,
|
||||||
* Add the extension, and all compressed variants
|
* Add the extension, and all compressed variants
|
||||||
* of it.
|
* of it.
|
||||||
*/
|
*/
|
||||||
extensions = add_extensions(extensions, extension,
|
extensions = add_extensions(extensions, extension, TRUE);
|
||||||
compressed_file_extensions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_strfreev(extensions_set);
|
g_strfreev(extensions_set);
|
||||||
|
@ -241,7 +259,7 @@ wtap_get_file_extension_type_extensions(guint extension_type)
|
||||||
* variants.
|
* variants.
|
||||||
*/
|
*/
|
||||||
extensions = add_extensions_for_file_extensions_type(extension_type,
|
extensions = add_extensions_for_file_extensions_type(extension_type,
|
||||||
extensions, compressed_file_extension_table);
|
extensions);
|
||||||
|
|
||||||
return extensions;
|
return extensions;
|
||||||
}
|
}
|
||||||
|
@ -283,7 +301,7 @@ wtap_get_all_capture_file_extensions_list(void)
|
||||||
* extensions, with compressed variants.
|
* extensions, with compressed variants.
|
||||||
*/
|
*/
|
||||||
extensions = add_extensions_for_file_extensions_type(i,
|
extensions = add_extensions_for_file_extensions_type(i,
|
||||||
extensions, compressed_file_extension_table);
|
extensions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -598,7 +616,6 @@ get_file_extension(const char *pathname)
|
||||||
gchar *filename;
|
gchar *filename;
|
||||||
gchar **components;
|
gchar **components;
|
||||||
size_t ncomponents;
|
size_t ncomponents;
|
||||||
const char **compressed_file_extensionp;
|
|
||||||
gchar *extensionp;
|
gchar *extensionp;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -646,12 +663,31 @@ get_file_extension(const char *pathname)
|
||||||
* files?
|
* files?
|
||||||
*/
|
*/
|
||||||
extensionp = components[ncomponents - 1];
|
extensionp = components[ncomponents - 1];
|
||||||
for (compressed_file_extensionp = compressed_file_extension_table;
|
for (wtap_compression_type compression_type = WTAP_UNCOMPRESSED;
|
||||||
*compressed_file_extensionp != NULL;
|
compression_type < WTAP_NUM_COMPRESSION_TYPES;
|
||||||
compressed_file_extensionp++) {
|
compression_type++) {
|
||||||
if (strcmp(extensionp, *compressed_file_extensionp) == 0) {
|
if (compression_type == WTAP_UNCOMPRESSED) {
|
||||||
/*
|
/*
|
||||||
* Yes, it's one of the compressed-file extensions.
|
* This isn't a compression type, so it has no
|
||||||
|
* extension.
|
||||||
|
*/
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!wtap_compression_type_supported(compression_type)) {
|
||||||
|
/*
|
||||||
|
* We don't support this compression type, so don't
|
||||||
|
* include its extension.
|
||||||
|
*/
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Is the extension the extension corresponding to this
|
||||||
|
* compression type?
|
||||||
|
*/
|
||||||
|
if (strcmp(extensionp, wtap_compressed_file_extension(compression_type)) == 0) {
|
||||||
|
/*
|
||||||
|
* Yes, so it's one of the compressed-file extensions.
|
||||||
* Is there an extension before that?
|
* Is there an extension before that?
|
||||||
*/
|
*/
|
||||||
if (ncomponents == 2) {
|
if (ncomponents == 2) {
|
||||||
|
@ -2030,19 +2066,19 @@ wtap_short_string_to_file_type_subtype(const char *short_name)
|
||||||
|
|
||||||
static GSList *
|
static GSList *
|
||||||
add_extensions_for_file_type_subtype(int file_type_subtype, GSList *extensions,
|
add_extensions_for_file_type_subtype(int file_type_subtype, GSList *extensions,
|
||||||
const char **compressed_file_extensions)
|
gboolean include_compressed)
|
||||||
{
|
{
|
||||||
gchar **extensions_set, **extensionp;
|
gchar **extensions_set, **extensionp;
|
||||||
gchar *extension;
|
gchar *extension;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add the default extension, and all compressed variants of
|
* Add the default extension, and all compressed variants of
|
||||||
* it, if there is a default extension.
|
* it if requested, if there is a default extension.
|
||||||
*/
|
*/
|
||||||
if (dump_open_table[file_type_subtype].default_file_extension != NULL) {
|
if (dump_open_table[file_type_subtype].default_file_extension != NULL) {
|
||||||
extensions = add_extensions(extensions,
|
extensions = add_extensions(extensions,
|
||||||
dump_open_table[file_type_subtype].default_file_extension,
|
dump_open_table[file_type_subtype].default_file_extension,
|
||||||
compressed_file_extensions);
|
include_compressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dump_open_table[file_type_subtype].additional_file_extensions != NULL) {
|
if (dump_open_table[file_type_subtype].additional_file_extensions != NULL) {
|
||||||
|
@ -2064,10 +2100,10 @@ add_extensions_for_file_type_subtype(int file_type_subtype, GSList *extensions,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add the extension, and all compressed variants
|
* Add the extension, and all compressed variants
|
||||||
* of it.
|
* of it if requested.
|
||||||
*/
|
*/
|
||||||
extensions = add_extensions(extensions, extension,
|
extensions = add_extensions(extensions, extension,
|
||||||
compressed_file_extensions);
|
include_compressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_strfreev(extensions_set);
|
g_strfreev(extensions_set);
|
||||||
|
@ -2087,9 +2123,6 @@ GSList *
|
||||||
wtap_get_file_extensions_list(int file_type_subtype, gboolean include_compressed)
|
wtap_get_file_extensions_list(int file_type_subtype, gboolean include_compressed)
|
||||||
{
|
{
|
||||||
GSList *extensions;
|
GSList *extensions;
|
||||||
static const char *no_compressed_extensions[] = {
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
if (file_type_subtype < 0 || file_type_subtype >= wtap_num_file_types_subtypes)
|
if (file_type_subtype < 0 || file_type_subtype >= wtap_num_file_types_subtypes)
|
||||||
return NULL; /* not a valid file type */
|
return NULL; /* not a valid file type */
|
||||||
|
@ -2104,7 +2137,7 @@ wtap_get_file_extensions_list(int file_type_subtype, gboolean include_compressed
|
||||||
* variants if include_compressed is true.
|
* variants if include_compressed is true.
|
||||||
*/
|
*/
|
||||||
extensions = add_extensions_for_file_type_subtype(file_type_subtype, extensions,
|
extensions = add_extensions_for_file_type_subtype(file_type_subtype, extensions,
|
||||||
include_compressed ? compressed_file_extension_table : no_compressed_extensions);
|
include_compressed);
|
||||||
|
|
||||||
return extensions;
|
return extensions;
|
||||||
}
|
}
|
||||||
|
@ -2130,7 +2163,7 @@ wtap_get_all_file_extensions_list(void)
|
||||||
|
|
||||||
for (i = 0; i < WTAP_NUM_FILE_TYPES_SUBTYPES; i++) {
|
for (i = 0; i < WTAP_NUM_FILE_TYPES_SUBTYPES; i++) {
|
||||||
extensions = add_extensions_for_file_type_subtype(i, extensions,
|
extensions = add_extensions_for_file_type_subtype(i, extensions,
|
||||||
compressed_file_extension_table);
|
TRUE); /* include compressed-file extensions */
|
||||||
}
|
}
|
||||||
|
|
||||||
return extensions;
|
return extensions;
|
||||||
|
|
|
@ -43,19 +43,6 @@
|
||||||
* Lzip format: http://www.nongnu.org/lzip/
|
* Lzip format: http://www.nongnu.org/lzip/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
const char *compressed_file_extension_table[] = {
|
|
||||||
#ifdef HAVE_ZLIB
|
|
||||||
"gz",
|
|
||||||
#endif
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
/* #define GZBUFSIZE 8192 */
|
/* #define GZBUFSIZE 8192 */
|
||||||
#define GZBUFSIZE 4096
|
#define GZBUFSIZE 4096
|
||||||
|
|
||||||
|
|
|
@ -250,12 +250,6 @@ extern gint wtap_num_file_types;
|
||||||
#define g_ptr_array_len(a) ((a)->len)
|
#define g_ptr_array_len(a) ((a)->len)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
* Table of extensions for compressed file types we support.
|
|
||||||
* Last pointer in the list is null.
|
|
||||||
*/
|
|
||||||
extern const char *compressed_file_extension_table[];
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read a given number of bytes from a file into a buffer or, if
|
* Read a given number of bytes from a file into a buffer or, if
|
||||||
* buf is NULL, just discard them.
|
* buf is NULL, just discard them.
|
||||||
|
|
|
@ -86,6 +86,25 @@ wtap_get_compression_type(wtap *wth)
|
||||||
return is_compressed ? WTAP_GZIP_COMPRESSED : WTAP_UNCOMPRESSED;
|
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] = {
|
static const char *compression_type_descriptions[WTAP_NUM_COMPRESSION_TYPES] = {
|
||||||
NULL, /* uncompressed */
|
NULL, /* uncompressed */
|
||||||
"gzip compressed"
|
"gzip compressed"
|
||||||
|
@ -98,6 +117,27 @@ wtap_compression_type_description(wtap_compression_type compression_type)
|
||||||
return compression_type_descriptions[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
|
guint
|
||||||
wtap_snapshot_length(wtap *wth)
|
wtap_snapshot_length(wtap *wth)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1710,8 +1710,12 @@ gint64 wtap_file_size(wtap *wth, int *err);
|
||||||
WS_DLL_PUBLIC
|
WS_DLL_PUBLIC
|
||||||
wtap_compression_type wtap_get_compression_type(wtap *wth);
|
wtap_compression_type wtap_get_compression_type(wtap *wth);
|
||||||
WS_DLL_PUBLIC
|
WS_DLL_PUBLIC
|
||||||
|
gboolean wtap_compression_type_supported(wtap_compression_type compression_type);
|
||||||
|
WS_DLL_PUBLIC
|
||||||
const char *wtap_compression_type_description(wtap_compression_type compression_type);
|
const char *wtap_compression_type_description(wtap_compression_type compression_type);
|
||||||
WS_DLL_PUBLIC
|
WS_DLL_PUBLIC
|
||||||
|
const char *wtap_compressed_file_extension(wtap_compression_type compression_type);
|
||||||
|
WS_DLL_PUBLIC
|
||||||
guint wtap_snapshot_length(wtap *wth); /* per file */
|
guint wtap_snapshot_length(wtap *wth); /* per file */
|
||||||
WS_DLL_PUBLIC
|
WS_DLL_PUBLIC
|
||||||
int wtap_file_type_subtype(wtap *wth);
|
int wtap_file_type_subtype(wtap *wth);
|
||||||
|
|
Loading…
Reference in New Issue