diff options
author | Guy Harris <guy@alum.mit.edu> | 2018-11-19 16:06:38 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2018-11-20 03:11:10 +0000 |
commit | ba3454529302a64e11c498a2185f4b5ddc1ccf3a (patch) | |
tree | 1b61241755cc2d95a3f0f7a47b29dab630c9b116 /wiretap/file_wrappers.c | |
parent | 2f17546932707dd2e6b02681fd8ff1f395f48aaf (diff) |
Add an API to get a list of compressed-file extensions, and use it.
Move all the compressed-file type stuff to wiretap/file_wrappers.c.
Rename wtap_compressed_file_extension() to
wtap_compression_type_extension() for consistency with the other
compression-type-extension routine names.
Move the declarations of the compression-type-extension routines in the
header file.
wtap_compression_type_extension() now returns NULL for
WTAP_UNCOMPRESSED; there's no need to special-case it.
Get rid of the now-unused wtap_compression_type_supported() and
WTAP_NUM_COMPRESSION_TYPES.
Change-Id: Ib93874079bea669a0c87104513dba0d21390455a
Reviewed-on: https://code.wireshark.org/review/30729
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wiretap/file_wrappers.c')
-rw-r--r-- | wiretap/file_wrappers.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/wiretap/file_wrappers.c b/wiretap/file_wrappers.c index c1ea1b9040..4788dccfb7 100644 --- a/wiretap/file_wrappers.c +++ b/wiretap/file_wrappers.c @@ -43,6 +43,65 @@ * Lzip format: http://www.nongnu.org/lzip/ */ +/* + * List of compression types supported. + */ +static struct compression_type { + wtap_compression_type type; + const char *extension; + const char *description; +} compression_types[] = { +#ifdef HAVE_ZLIB + { WTAP_GZIP_COMPRESSED, "gz", "gzip compressed" }, +#endif + { WTAP_UNCOMPRESSED, NULL, NULL } +}; + +wtap_compression_type +wtap_get_compression_type(wtap *wth) +{ + gboolean is_compressed; + + is_compressed = file_iscompressed((wth->fh == NULL) ? wth->random_fh : wth->fh); + return is_compressed ? WTAP_GZIP_COMPRESSED : WTAP_UNCOMPRESSED; +} + +const char * +wtap_compression_type_description(wtap_compression_type compression_type) +{ + for (struct compression_type *p = compression_types; + p->type != WTAP_UNCOMPRESSED; p++) { + if (p->type == compression_type) + return p->description; + } + return NULL; +} + +const char * +wtap_compression_type_extension(wtap_compression_type compression_type) +{ + for (struct compression_type *p = compression_types; + p->type != WTAP_UNCOMPRESSED; p++) { + if (p->type == compression_type) + return p->extension; + } + return NULL; +} + +GSList * +wtap_get_all_compression_type_extensions_list(void) +{ + GSList *extensions; + + extensions = NULL; /* empty list, to start with */ + + for (struct compression_type *p = compression_types; + p->type != WTAP_UNCOMPRESSED; p++) + extensions = g_slist_prepend(extensions, (gpointer)p->extension); + + return extensions; +} + /* #define GZBUFSIZE 8192 */ #define GZBUFSIZE 4096 |