aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/mime_file.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2021-02-14 00:34:10 -0800
committerGuy Harris <gharris@sonic.net>2021-02-14 00:58:46 -0800
commitb8b3531883db249be80e217154c7e7fffb86f5bd (patch)
treebecde2c028097baae1b38d8c13b4a9827d0de8b0 /wiretap/mime_file.c
parent5b3c3d0682c869e6dd19a5245b1a22c90192e9ae (diff)
wiretap: register most built-in file types from its module.
Remove most of the built-in file types from the table in wiretap/file_access.c and, instead, have the file types register themselves, using wtap_register_file_type_subtypes(). This reduces the source code changes needed to add a new file type from three (add the handler, add the file type to the table in file_access.c, add a #define for the file type in wiretap/wtap.h) to one (add the handler). (It also requires adding the handler's source file to wiretap/CMakeLists.txt, but that's required in both cases.) A few remain because the WTAP_FILE_TYPE_SUBTYPE_ #define is used elsewhere; that needs to be fixed. Fix the wiretap/CMakefile.txt file to scan k12text.l, as that now contains a registration routine. In the process, avoid scanning files that don't implement a file type and won't ever have a registration routine. Add a Lua routine to fetch the total number of file types; we use that in some code to construct the wtap_filetypes table, which we need to do in order to continue to have all the values that used to come from the WTAP_FILE_TYPE_SUBTYPE_ types. While we're at it, add modelines to a file that lacked them.
Diffstat (limited to 'wiretap/mime_file.c')
-rw-r--r--wiretap/mime_file.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/wiretap/mime_file.c b/wiretap/mime_file.c
index 2096a299ef..171cd3706e 100644
--- a/wiretap/mime_file.c
+++ b/wiretap/mime_file.c
@@ -90,6 +90,10 @@ static const mime_files_t magic_files[] = {
#define N_MAGIC_TYPES (sizeof(magic_files) / sizeof(magic_files[0]))
+static int mime_file_type_subtype = -1;
+
+void register_mime(void);
+
wtap_open_return_val
mime_file_open(wtap *wth, int *err, gchar **err_info)
{
@@ -135,7 +139,7 @@ mime_file_open(wtap *wth, int *err, gchar **err_info)
if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
return WTAP_OPEN_ERROR;
- wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_MIME;
+ wth->file_type_subtype = mime_file_type_subtype;
wth->file_encap = WTAP_ENCAP_MIME;
wth->file_tsprec = WTAP_TSPREC_SEC;
wth->subtype_read = wtap_full_file_read;
@@ -145,6 +149,37 @@ mime_file_open(wtap *wth, int *err, gchar **err_info)
return WTAP_OPEN_MINE;
}
+static const struct file_type_subtype_info mime_info = {
+ "MIME File Format", "mime", NULL, NULL,
+ FALSE, FALSE, 0,
+ NULL, NULL, NULL
+};
+
+/*
+ * XXX - registered solely for the benefit of Lua scripts that
+ * look for the file type "JPEG_JFIF"; it may be removed once
+ * we get rid of wtap_filetypes.
+ */
+static const struct file_type_subtype_info jpeg_jfif_info = {
+ "JPEG/JFIF", "jpeg", "jpg", "jpeg;jfif",
+ FALSE, FALSE, 0,
+ NULL, NULL, NULL
+};
+
+void register_mime(void)
+{
+ mime_file_type_subtype =
+ wtap_register_file_type_subtypes(&mime_info,
+ WTAP_FILE_TYPE_SUBTYPE_UNKNOWN);
+
+ /*
+ * Obsoleted by "mime", so just register it; we don't
+ * need its return value.
+ */
+ wtap_register_file_type_subtypes(&jpeg_jfif_info,
+ WTAP_FILE_TYPE_SUBTYPE_UNKNOWN);
+}
+
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*