aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/logcat_text.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/logcat_text.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/logcat_text.c')
-rw-r--r--wiretap/logcat_text.c122
1 files changed, 96 insertions, 26 deletions
diff --git a/wiretap/logcat_text.c b/wiretap/logcat_text.c
index 0b61cb362c..de3cf22c8c 100644
--- a/wiretap/logcat_text.c
+++ b/wiretap/logcat_text.c
@@ -20,6 +20,16 @@ struct dumper_t {
int type;
};
+static int logcat_text_brief_file_type_subtype = -1;
+static int logcat_text_process_file_type_subtype = -1;
+static int logcat_text_tag_file_type_subtype = -1;
+static int logcat_text_thread_file_type_subtype = -1;
+static int logcat_text_time_file_type_subtype = -1;
+static int logcat_text_threadtime_file_type_subtype = -1;
+static int logcat_text_long_file_type_subtype = -1;
+
+void register_logcat_text(void);
+
/* Returns '?' for invalid priorities */
static gchar get_priority(const guint8 priority) {
static gchar priorities[] = "??VDIWEFS";
@@ -187,7 +197,7 @@ static gboolean logcat_text_read_packet(FILE_T fh, wtap_rec *rec,
return FALSE;
}
- if (WTAP_FILE_TYPE_SUBTYPE_LOGCAT_LONG == file_type &&
+ if (logcat_text_long_file_type_subtype == file_type &&
!g_regex_match_simple(SPECIAL_STRING, cbuff, (GRegexCompileFlags)(G_REGEX_ANCHORED | G_REGEX_RAW), G_REGEX_MATCH_NOTEMPTY)) {
gint64 file_off = 0;
gchar *lbuff;
@@ -219,11 +229,11 @@ static gboolean logcat_text_read_packet(FILE_T fh, wtap_rec *rec,
ws_buffer_assure_space(buf, rec->rec_header.packet_header.caplen + 1);
pd = ws_buffer_start_ptr(buf);
- if ((WTAP_FILE_TYPE_SUBTYPE_LOGCAT_TIME == file_type
- || WTAP_FILE_TYPE_SUBTYPE_LOGCAT_THREADTIME == file_type
- || WTAP_FILE_TYPE_SUBTYPE_LOGCAT_LONG == file_type)
+ if ((logcat_text_time_file_type_subtype == file_type
+ || logcat_text_threadtime_file_type_subtype == file_type
+ || logcat_text_long_file_type_subtype == file_type)
&& '-' != cbuff[0]) { /* the last part filters out the -- beginning of... lines */
- if (WTAP_FILE_TYPE_SUBTYPE_LOGCAT_LONG == file_type) {
+ if (logcat_text_long_file_type_subtype == file_type) {
get_time(cbuff+2, rec);
} else {
get_time(cbuff, rec);
@@ -276,31 +286,31 @@ wtap_open_return_val logcat_text_open(wtap *wth, int *err, gchar **err_info _U_)
if (g_regex_match_simple(BRIEF_STRING, cbuff, (GRegexCompileFlags)(G_REGEX_ANCHORED | G_REGEX_RAW),
G_REGEX_MATCH_NOTEMPTY)) {
- wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_LOGCAT_BRIEF;
+ wth->file_type_subtype = logcat_text_brief_file_type_subtype;
wth->file_encap = WTAP_ENCAP_LOGCAT_BRIEF;
} else if (g_regex_match_simple(TAG_STRING, cbuff, (GRegexCompileFlags)(G_REGEX_ANCHORED | G_REGEX_RAW),
G_REGEX_MATCH_NOTEMPTY)) {
- wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_LOGCAT_TAG;
+ wth->file_type_subtype = logcat_text_tag_file_type_subtype;
wth->file_encap = WTAP_ENCAP_LOGCAT_TAG;
} else if (g_regex_match_simple(PROCESS_STRING, cbuff, (GRegexCompileFlags)(G_REGEX_ANCHORED | G_REGEX_RAW),
G_REGEX_MATCH_NOTEMPTY)) {
- wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_LOGCAT_PROCESS;
+ wth->file_type_subtype = logcat_text_process_file_type_subtype;
wth->file_encap = WTAP_ENCAP_LOGCAT_PROCESS;
} else if (g_regex_match_simple(TIME_STRING, cbuff, (GRegexCompileFlags)(G_REGEX_ANCHORED | G_REGEX_RAW),
G_REGEX_MATCH_NOTEMPTY)) {
- wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_LOGCAT_TIME;
+ wth->file_type_subtype = logcat_text_time_file_type_subtype;
wth->file_encap = WTAP_ENCAP_LOGCAT_TIME;
} else if (g_regex_match_simple(THREAD_STRING, cbuff, (GRegexCompileFlags)(G_REGEX_ANCHORED | G_REGEX_RAW),
G_REGEX_MATCH_NOTEMPTY)) {
- wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_LOGCAT_THREAD;
+ wth->file_type_subtype = logcat_text_thread_file_type_subtype;
wth->file_encap = WTAP_ENCAP_LOGCAT_THREAD;
} else if (g_regex_match_simple(THREADTIME_STRING, cbuff, (GRegexCompileFlags)(G_REGEX_ANCHORED | G_REGEX_RAW),
G_REGEX_MATCH_NOTEMPTY)) {
- wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_LOGCAT_THREADTIME;
+ wth->file_type_subtype = logcat_text_threadtime_file_type_subtype;
wth->file_encap = WTAP_ENCAP_LOGCAT_THREADTIME;
} else if (g_regex_match_simple(LONG_STRING, cbuff, (GRegexCompileFlags)(G_REGEX_ANCHORED | G_REGEX_RAW),
G_REGEX_MATCH_NOTEMPTY)) {
- wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_LOGCAT_LONG;
+ wth->file_type_subtype = logcat_text_long_file_type_subtype;
wth->file_encap = WTAP_ENCAP_LOGCAT_LONG;
} else {
g_free(cbuff);
@@ -320,7 +330,7 @@ wtap_open_return_val logcat_text_open(wtap *wth, int *err, gchar **err_info _U_)
return WTAP_OPEN_MINE;
}
-int logcat_text_brief_dump_can_write_encap(int encap) {
+static int logcat_text_brief_dump_can_write_encap(int encap) {
if (encap == WTAP_ENCAP_PER_PACKET)
return WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED;
@@ -334,7 +344,7 @@ int logcat_text_brief_dump_can_write_encap(int encap) {
}
}
-int logcat_text_process_dump_can_write_encap(int encap) {
+static int logcat_text_process_dump_can_write_encap(int encap) {
if (encap == WTAP_ENCAP_PER_PACKET)
return WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED;
@@ -348,7 +358,7 @@ int logcat_text_process_dump_can_write_encap(int encap) {
}
}
-int logcat_text_tag_dump_can_write_encap(int encap) {
+static int logcat_text_tag_dump_can_write_encap(int encap) {
if (encap == WTAP_ENCAP_PER_PACKET)
return WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED;
@@ -362,7 +372,7 @@ int logcat_text_tag_dump_can_write_encap(int encap) {
}
}
-int logcat_text_time_dump_can_write_encap(int encap) {
+static int logcat_text_time_dump_can_write_encap(int encap) {
if (encap == WTAP_ENCAP_PER_PACKET)
return WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED;
@@ -376,7 +386,7 @@ int logcat_text_time_dump_can_write_encap(int encap) {
}
}
-int logcat_text_thread_dump_can_write_encap(int encap) {
+static int logcat_text_thread_dump_can_write_encap(int encap) {
if (encap == WTAP_ENCAP_PER_PACKET)
return WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED;
@@ -390,7 +400,7 @@ int logcat_text_thread_dump_can_write_encap(int encap) {
}
}
-int logcat_text_threadtime_dump_can_write_encap(int encap) {
+static int logcat_text_threadtime_dump_can_write_encap(int encap) {
if (encap == WTAP_ENCAP_PER_PACKET)
return WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED;
@@ -404,7 +414,7 @@ int logcat_text_threadtime_dump_can_write_encap(int encap) {
}
}
-int logcat_text_long_dump_can_write_encap(int encap) {
+static int logcat_text_long_dump_can_write_encap(int encap) {
if (encap == WTAP_ENCAP_PER_PACKET)
return WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED;
@@ -590,34 +600,94 @@ static gboolean logcat_text_dump_open(wtap_dumper *wdh, guint dump_type) {
return TRUE;
}
-gboolean logcat_text_brief_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) {
+static gboolean logcat_text_brief_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) {
return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_BRIEF);
}
-gboolean logcat_text_process_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) {
+static gboolean logcat_text_process_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) {
return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_PROCESS);
}
-gboolean logcat_text_tag_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) {
+static gboolean logcat_text_tag_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) {
return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_TAG);
}
-gboolean logcat_text_time_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) {
+static gboolean logcat_text_time_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) {
return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_TIME);
}
-gboolean logcat_text_thread_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) {
+static gboolean logcat_text_thread_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) {
return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_THREAD);
}
-gboolean logcat_text_threadtime_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) {
+static gboolean logcat_text_threadtime_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) {
return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_THREADTIME);
}
-gboolean logcat_text_long_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) {
+static gboolean logcat_text_long_dump_open(wtap_dumper *wdh, int *err _U_, gchar **err_info _U_) {
return logcat_text_dump_open(wdh, WTAP_ENCAP_LOGCAT_LONG);
}
+static const struct file_type_subtype_info logcat_text_brief_info = {
+ "Android Logcat Brief text format", "logcat-brief", NULL, NULL,
+ FALSE, FALSE, 0,
+ logcat_text_brief_dump_can_write_encap, logcat_text_brief_dump_open, NULL
+};
+
+static const struct file_type_subtype_info logcat_text_process_info = {
+ "Android Logcat Process text format", "logcat-process", NULL, NULL,
+ FALSE, FALSE, 0,
+ logcat_text_process_dump_can_write_encap, logcat_text_process_dump_open, NULL
+};
+
+static const struct file_type_subtype_info logcat_text_tag_info = {
+ "Android Logcat Tag text format", "logcat-tag", NULL, NULL,
+ FALSE, FALSE, 0,
+ logcat_text_tag_dump_can_write_encap, logcat_text_tag_dump_open, NULL
+};
+
+static const struct file_type_subtype_info logcat_text_thread_info = {
+ "Android Logcat Thread text format", "logcat-thread", NULL, NULL,
+ FALSE, FALSE, 0,
+ logcat_text_thread_dump_can_write_encap, logcat_text_thread_dump_open, NULL
+};
+
+static const struct file_type_subtype_info logcat_text_time_info = {
+ "Android Logcat Time text format", "logcat-time", NULL, NULL,
+ FALSE, FALSE, 0,
+ logcat_text_time_dump_can_write_encap, logcat_text_time_dump_open, NULL
+};
+
+static const struct file_type_subtype_info logcat_text_threadtime_info = {
+ "Android Logcat Threadtime text format", "logcat-threadtime", NULL, NULL,
+ FALSE, FALSE, 0,
+ logcat_text_threadtime_dump_can_write_encap, logcat_text_threadtime_dump_open, NULL
+};
+
+static const struct file_type_subtype_info logcat_text_long_info = {
+ "Android Logcat Long text format", "logcat-long", NULL, NULL,
+ FALSE, FALSE, 0,
+ logcat_text_long_dump_can_write_encap, logcat_text_long_dump_open, NULL
+};
+
+void register_logcat_text(void)
+{
+ logcat_text_brief_file_type_subtype = wtap_register_file_type_subtypes(&logcat_text_brief_info,
+ WTAP_FILE_TYPE_SUBTYPE_UNKNOWN);
+ logcat_text_process_file_type_subtype = wtap_register_file_type_subtypes(&logcat_text_process_info,
+ WTAP_FILE_TYPE_SUBTYPE_UNKNOWN);
+ logcat_text_tag_file_type_subtype = wtap_register_file_type_subtypes(&logcat_text_tag_info,
+ WTAP_FILE_TYPE_SUBTYPE_UNKNOWN);
+ logcat_text_thread_file_type_subtype = wtap_register_file_type_subtypes(&logcat_text_thread_info,
+ WTAP_FILE_TYPE_SUBTYPE_UNKNOWN);
+ logcat_text_time_file_type_subtype = wtap_register_file_type_subtypes(&logcat_text_time_info,
+ WTAP_FILE_TYPE_SUBTYPE_UNKNOWN);
+ logcat_text_threadtime_file_type_subtype = wtap_register_file_type_subtypes(&logcat_text_threadtime_info,
+ WTAP_FILE_TYPE_SUBTYPE_UNKNOWN);
+ logcat_text_long_file_type_subtype = wtap_register_file_type_subtypes(&logcat_text_long_info,
+ WTAP_FILE_TYPE_SUBTYPE_UNKNOWN);
+}
+
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*