diff options
author | Guy Harris <gharris@sonic.net> | 2021-03-11 13:56:40 -0800 |
---|---|---|
committer | Guy Harris <gharris@sonic.net> | 2021-03-11 13:56:40 -0800 |
commit | 2561f1e9f891aeb61b4d2fc16e553c870b1d6c7c (patch) | |
tree | f3134c1edba567ad499a6a2f4e3eda2315694fd3 /wiretap/file_access.c | |
parent | 98485a1c277801bbe23c6e7b873f1cb6937bd243 (diff) |
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.
Diffstat (limited to 'wiretap/file_access.c')
-rw-r--r-- | wiretap/file_access.c | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/wiretap/file_access.c b/wiretap/file_access.c index 8e43b1a9e0..cec6e0d102 100644 --- a/wiretap/file_access.c +++ b/wiretap/file_access.c @@ -1241,6 +1241,12 @@ 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; |