aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2021-03-11 13:56:40 -0800
committerGuy Harris <gharris@sonic.net>2021-03-11 13:56:40 -0800
commit2561f1e9f891aeb61b4d2fc16e553c870b1d6c7c (patch)
treef3134c1edba567ad499a6a2f4e3eda2315694fd3 /wiretap
parent98485a1c277801bbe23c6e7b873f1cb6937bd243 (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')
-rw-r--r--wiretap/file_access.c57
-rw-r--r--wiretap/libpcap.c18
-rw-r--r--wiretap/wtap-int.h4
3 files changed, 55 insertions, 24 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;
diff --git a/wiretap/libpcap.c b/wiretap/libpcap.c
index a7d3a125ac..c86b0e8966 100644
--- a/wiretap/libpcap.c
+++ b/wiretap/libpcap.c
@@ -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",
diff --git a/wiretap/wtap-int.h b/wiretap/wtap-int.h
index 43d612f1be..341be83b4d 100644
--- a/wiretap/wtap-int.h
+++ b/wiretap/wtap-int.h
@@ -351,6 +351,10 @@ 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);
struct backwards_compatibiliity_lua_name {