forked from osmocom/wireshark
Replace wtap_file_extensions_string() with a routine that returns a
GSList of extensions for a file type, including extensions for the compressed versions of those file types that we can read. svn path=/trunk/; revision=40623
This commit is contained in:
parent
020d9491da
commit
e4a193fe5e
|
@ -1433,6 +1433,7 @@ build_file_type_list(gboolean save, int *item_to_select) {
|
|||
int ft;
|
||||
guint index;
|
||||
GString* str = g_string_new("");
|
||||
GSList *extensions_list, *extension;
|
||||
TCHAR *str16;
|
||||
GArray* sa = g_array_new(FALSE /*zero_terminated*/, FALSE /*clear_*/,2 /*element_size*/);
|
||||
guint16 zero = 0;
|
||||
|
@ -1468,19 +1469,37 @@ build_file_type_list(gboolean save, int *item_to_select) {
|
|||
}
|
||||
|
||||
/* OK, we can write it out in this type. */
|
||||
if(wtap_file_type_string(ft) != NULL) {
|
||||
g_string_printf(str, "%s (%s)", wtap_file_type_string(ft), wtap_file_extensions_string(ft));
|
||||
} else {
|
||||
if(wtap_file_type_string(ft) == NULL)
|
||||
continue;
|
||||
extensions_list = wtap_get_file_extensions_list(ft);
|
||||
if (extensions_list == NULL)
|
||||
continue;
|
||||
g_string_printf(str, "%s ", wtap_file_type_string(ft));
|
||||
sep = '(';
|
||||
for (extension = extensions_list; extension != NULL;
|
||||
extension = g_slist_next(extension)) {
|
||||
g_string_append_printf(str, "%c%s", sep, (char *)extension->data);
|
||||
sep = ';';
|
||||
}
|
||||
g_string_printf(str, ")");
|
||||
str16 = utf_8to16(str->str);
|
||||
sa = g_array_append_vals(sa, str16, (guint) strlen(str->str));
|
||||
sa = g_array_append_val(sa, zero);
|
||||
|
||||
g_string_printf(str, "");
|
||||
sep = '\0';
|
||||
for (extension = extensions_list; extension != NULL;
|
||||
extension = g_slist_next(extension)) {
|
||||
if (sep != '\0')
|
||||
g_string_append_c(str, sep);
|
||||
g_string_append_printf(str, "%s", sep, (char *)extension->data);
|
||||
sep = ';';
|
||||
}
|
||||
str16 = utf_8to16(str->str);
|
||||
sa = g_array_append_vals(sa, str16, (guint) strlen(str->str));
|
||||
sa = g_array_append_val(sa, zero);
|
||||
|
||||
g_string_printf(str, "%s", wtap_file_extensions_string(ft));
|
||||
str16 = utf_8to16(str->str);
|
||||
sa = g_array_append_vals(sa, str16, (guint) strlen(str->str));
|
||||
sa = g_array_append_val(sa, zero);
|
||||
wtap_free_file_extensions_list(extensions_list);
|
||||
|
||||
if (ft == cfile.cd_t && item_to_select != NULL) {
|
||||
/* Default to the same format as the file, if it's supported. */
|
||||
|
|
|
@ -716,16 +716,85 @@ int wtap_short_string_to_file_type(const char *short_name)
|
|||
return -1; /* no such file type, or we can't write it */
|
||||
}
|
||||
|
||||
/* file extensions to use. */
|
||||
const char *wtap_file_extensions_string(int filetype)
|
||||
/* Return a list of file extensions that are used by the specified file type.
|
||||
This includes compressed extensions, e.g. not just "pcap" but also
|
||||
"pcap.gz" if we can read gzipped files.
|
||||
|
||||
All strings in the list are allocated with g_malloc() and must be freed
|
||||
with g_free(). */
|
||||
GSList *wtap_get_file_extensions_list(int filetype)
|
||||
{
|
||||
gchar **extensions_set, **extensionp;
|
||||
gchar *extension;
|
||||
GSList *compressed_file_extensions, *compressed_file_extension;
|
||||
GSList *extensions;
|
||||
|
||||
if (filetype < 0 || filetype >= wtap_num_file_types)
|
||||
return NULL;
|
||||
else
|
||||
return dump_open_table[filetype].file_extensions;
|
||||
return NULL; /* not a valid file type */
|
||||
|
||||
if (dump_open_table[filetype].file_extensions == NULL)
|
||||
return NULL; /* valid, but no extensions list */
|
||||
|
||||
/*
|
||||
* Split the extension-list string into a set of extensions.
|
||||
*/
|
||||
extensions_set = g_strsplit(dump_open_table[filetype].file_extensions,
|
||||
";", 0);
|
||||
|
||||
/*
|
||||
* Get the list of compressed-file extensions.
|
||||
*/
|
||||
compressed_file_extensions = wtap_get_compressed_file_extensions();
|
||||
|
||||
/*
|
||||
* Add each of those extensions to the list.
|
||||
*/
|
||||
extensions = NULL; /* empty list, to start with */
|
||||
for (extensionp = extensions_set; *extensionp != NULL; extensionp++) {
|
||||
extension = *extensionp;
|
||||
|
||||
/*
|
||||
* XXX - skip past the "*.".
|
||||
*/
|
||||
extension += 2;
|
||||
|
||||
/*
|
||||
* Now add the extension.
|
||||
*/
|
||||
extensions = g_slist_append(extensions, g_strdup(extension));
|
||||
|
||||
/*
|
||||
* Now add the extensions for compressed-file versions of
|
||||
* that extension.
|
||||
*/
|
||||
for (compressed_file_extension = compressed_file_extensions;
|
||||
compressed_file_extension != NULL;
|
||||
compressed_file_extension = g_slist_next(compressed_file_extension)) {
|
||||
extensions = g_slist_append(extensions,
|
||||
g_strdup_printf("%s.%s", extension,
|
||||
(gchar *)compressed_file_extension->data));
|
||||
}
|
||||
}
|
||||
g_strfreev(extensions_set);
|
||||
g_slist_free(compressed_file_extensions);
|
||||
return extensions;
|
||||
}
|
||||
|
||||
/* default file extension to use. */
|
||||
/*
|
||||
* Free a list returned by wtap_file_extensions_list().
|
||||
*/
|
||||
void wtap_free_file_extensions_list(GSList *extensions)
|
||||
{
|
||||
GSList *extension;
|
||||
|
||||
for (extension = extensions; extension != NULL;
|
||||
extension = g_slist_next(extension)) {
|
||||
g_free(extension->data);
|
||||
}
|
||||
g_slist_free(extensions);
|
||||
}
|
||||
|
||||
/* Return the default file extension to use with the specified file type. */
|
||||
const char *wtap_file_extension_default_string(int filetype)
|
||||
{
|
||||
if (filetype < 0 || filetype >= wtap_num_file_types)
|
||||
|
|
|
@ -73,6 +73,37 @@
|
|||
* Bzip2 format: http://bzip.org/
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
static const char *compressed_file_extensions[] = {
|
||||
#ifdef HAVE_LIBZ
|
||||
"gz",
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
||||
/*
|
||||
* Return a GSList of all the compressed file extensions.
|
||||
* The data pointers all point to items in compressed_file_extensions[],
|
||||
* so the GSList can just be freed with g_slist_free().
|
||||
*/
|
||||
GSList *
|
||||
wtap_get_compressed_file_extensions(void)
|
||||
{
|
||||
const char **extension;
|
||||
GSList *extensions;
|
||||
|
||||
extensions = NULL;
|
||||
for (extension = &compressed_file_extensions[0]; *extension != NULL;
|
||||
extension++)
|
||||
extensions = g_slist_append(extensions, (gpointer)(*extension));
|
||||
return extensions;
|
||||
}
|
||||
|
||||
/* #define GZBUFSIZE 8192 */
|
||||
#define GZBUFSIZE 4096
|
||||
|
||||
|
|
|
@ -342,6 +342,9 @@ extern gint wtap_num_file_types;
|
|||
#define g_ptr_array_len(a) ((a)->len)
|
||||
#endif
|
||||
|
||||
/*** get GSList of all compressed file extensions ***/
|
||||
GSList *wtap_get_compressed_file_extensions(void);
|
||||
|
||||
#endif /* __WTAP_INT_H__ */
|
||||
|
||||
/*
|
||||
|
|
|
@ -44,7 +44,8 @@ wtap_dump_set_addrinfo_list
|
|||
wtap_encap_short_string
|
||||
wtap_encap_string
|
||||
wtap_file_encap
|
||||
wtap_file_extensions_string
|
||||
wtap_get_file_extensions_list
|
||||
wtap_free_file_extensions_list
|
||||
wtap_file_extension_default_string
|
||||
wtap_file_size
|
||||
wtap_file_tsprecision
|
||||
|
|
|
@ -954,7 +954,8 @@ const char *wtap_file_type_string(int filetype);
|
|||
const char *wtap_file_type_short_string(int filetype);
|
||||
int wtap_short_string_to_file_type(const char *short_name);
|
||||
|
||||
const char *wtap_file_extensions_string(int filetype);
|
||||
GSList *wtap_get_file_extensions_list(int filetype);
|
||||
void wtap_free_file_extensions_list(GSList *extensions);
|
||||
const char *wtap_file_extension_default_string(int filetype);
|
||||
|
||||
const char *wtap_encap_string(int encap);
|
||||
|
|
Loading…
Reference in New Issue