forked from osmocom/wireshark
libwiretap: don't have a central table of file type/subtype name mappings.
Let individual file type/subtype modules register their backwards-compatibility names, rather than having a centralized table that would need to be updated along with the module.
This commit is contained in:
parent
98485a1c27
commit
2561f1e9f8
|
@ -1240,6 +1240,12 @@ int pcap_file_type_subtype = -1;
|
|||
int pcap_nsec_file_type_subtype = -1;
|
||||
int pcapng_file_type_subtype = -1;
|
||||
|
||||
/*
|
||||
* Table for mapping old file type/subtype names to new ones for
|
||||
* backwards compatibility.
|
||||
*/
|
||||
static GHashTable *type_subtype_name_map;
|
||||
|
||||
/*
|
||||
* Initialize the table of file types/subtypes with all the builtin
|
||||
* types/subtypes.
|
||||
|
@ -1264,6 +1270,13 @@ wtap_init_file_type_subtypes(void)
|
|||
sizeof(struct file_type_subtype_info), wtap_module_count*2 + 7);
|
||||
file_type_subtype_table = (const struct file_type_subtype_info*)(void *)file_type_subtype_table_arr->data;
|
||||
|
||||
/*
|
||||
* Initialize the hash table for mapping old file type/subtype
|
||||
* names to the corresponding new names.
|
||||
*/
|
||||
type_subtype_name_map = g_hash_table_new_full(g_str_hash,
|
||||
g_str_equal, g_free, g_free);
|
||||
|
||||
/* No entries yet, so no builtin entries yet. */
|
||||
wtap_num_builtin_file_types_subtypes = 0;
|
||||
|
||||
|
@ -1767,37 +1780,35 @@ wtap_file_type_subtype_name(int file_type_subtype)
|
|||
return file_type_subtype_table[file_type_subtype].name;
|
||||
}
|
||||
|
||||
/*
|
||||
* Register a backwards-compatibility name.
|
||||
*/
|
||||
void
|
||||
wtap_register_compatibility_file_subtype_name(const char *old_name,
|
||||
const char *new_name)
|
||||
{
|
||||
g_hash_table_insert(type_subtype_name_map, g_strdup(old_name),
|
||||
g_strdup(new_name));
|
||||
}
|
||||
|
||||
/* Translate a name to a capture file type/subtype. */
|
||||
int
|
||||
wtap_name_to_file_type_subtype(const char *name)
|
||||
{
|
||||
char *new_name;
|
||||
int file_type_subtype;
|
||||
|
||||
/*
|
||||
* We now call the libpcap file format just pcap, but we allow
|
||||
* the various variants of it to be specified using names
|
||||
* containing "libpcap" as well as "pcap", for backwards
|
||||
* compatibility.
|
||||
* Is this name a backwards-compatibility name?
|
||||
*/
|
||||
static const struct name_map {
|
||||
const char *oldname;
|
||||
const char *name;
|
||||
} name_map[] = {
|
||||
{ "libpcap", "pcap" },
|
||||
{ "nseclibpcap", "nsecpcap" },
|
||||
{ "aixlibpcap", "aixpcap" },
|
||||
{ "modlibpcap", "modpcap" },
|
||||
{ "nokialibpcap", "nokiapcap" },
|
||||
{ "rh6_1libpcap", "rh6_1pcap" },
|
||||
{ "suse6_3libpcap", "suse6_3pcap" }
|
||||
};
|
||||
#define N_NAME_MAP_ENTRIES (sizeof name_map / sizeof name_map[0])
|
||||
|
||||
for (size_t i = 0; i < N_NAME_MAP_ENTRIES; i++) {
|
||||
if (strcmp(name_map[i].oldname, name) == 0) {
|
||||
name = name_map[i].name;
|
||||
break;
|
||||
}
|
||||
new_name = (char *)g_hash_table_lookup(type_subtype_name_map,
|
||||
(gpointer)name);
|
||||
if (new_name != NULL) {
|
||||
/*
|
||||
* Yes, and new_name is the name to which it should
|
||||
* be mapped.
|
||||
*/
|
||||
name = new_name;
|
||||
}
|
||||
for (file_type_subtype = 0;
|
||||
file_type_subtype < (int)file_type_subtype_table_arr->len;
|
||||
|
|
|
@ -1414,7 +1414,23 @@ void register_pcap(void)
|
|||
pcap_nokia_file_type_subtype = wtap_register_file_type_subtype(&pcap_nokia_info);
|
||||
|
||||
/*
|
||||
* Register name for backwards compatibility with the
|
||||
* We now call the libpcap file format just pcap, but we allow
|
||||
* the various variants of it to be specified using names
|
||||
* containing "libpcap" as well as "pcap", for backwards
|
||||
* compatibility.
|
||||
*
|
||||
* Register names for that purpose.
|
||||
*/
|
||||
wtap_register_compatibility_file_subtype_name("libpcap", "pcap");
|
||||
wtap_register_compatibility_file_subtype_name("nseclibpcap", "nsecpcap");
|
||||
wtap_register_compatibility_file_subtype_name("aixlibpcap", "aixpcap");
|
||||
wtap_register_compatibility_file_subtype_name("modlibpcap", "modpcap");
|
||||
wtap_register_compatibility_file_subtype_name("nokialibpcap", "nokiapcap");
|
||||
wtap_register_compatibility_file_subtype_name("rh6_1libpcap", "rh6_1pcap");
|
||||
wtap_register_compatibility_file_subtype_name("suse6_3libpcap", "suse6_3pcap");
|
||||
|
||||
/*
|
||||
* Register names for backwards compatibility with the
|
||||
* wtap_filetypes table in Lua.
|
||||
*/
|
||||
wtap_register_backwards_compatibility_lua_name("PCAP",
|
||||
|
|
|
@ -350,6 +350,10 @@ wtap_add_idb(wtap *wth, wtap_block_t idb);
|
|||
void
|
||||
wtapng_process_dsb(wtap *wth, wtap_block_t dsb);
|
||||
|
||||
void
|
||||
wtap_register_compatibility_file_subtype_name(const char *old_name,
|
||||
const char *new_name);
|
||||
|
||||
void
|
||||
wtap_register_backwards_compatibility_lua_name(const char *name, int ft);
|
||||
|
||||
|
|
Loading…
Reference in New Issue