aboutsummaryrefslogtreecommitdiffstats
path: root/ui/logray
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2022-11-19 19:21:19 +0000
committerJoão Valverde <j@v6e.pt>2022-11-28 15:46:44 +0000
commita0d77e93298ab2e62600ec835099691b37fce69b (patch)
treec364f785b543b432a906d9d0779362114026ec2e /ui/logray
parentb4196ab772bd80f0bd95981fa4e70e884bfb8937 (diff)
dfilter: Return an error object instead of string
Return an struct containing error information. This simplifies the interface to more easily provide richer diagnostics in the future. Add an error code besides a human-readable error string to allow checking programmatically for errors in a robust manner. Currently there is only a generic error code, it is expected to increase in the future. Move error location information to the struct. Change callers and implementation to use the new interface.
Diffstat (limited to 'ui/logray')
-rw-r--r--ui/logray/logray_main.cpp7
-rw-r--r--ui/logray/logray_main_window.cpp8
-rw-r--r--ui/logray/logray_main_window_slots.cpp7
3 files changed, 12 insertions, 10 deletions
diff --git a/ui/logray/logray_main.cpp b/ui/logray/logray_main.cpp
index db2a044614..774840593c 100644
--- a/ui/logray/logray_main.cpp
+++ b/ui/logray/logray_main.cpp
@@ -428,6 +428,7 @@ int main(int argc, char *qt_argv[])
#endif
#endif
gchar *err_msg = NULL;
+ df_error_t *df_err = NULL;
QString dfilter, read_filter;
#ifdef HAVE_LIBPCAP
@@ -960,13 +961,13 @@ int main(int argc, char *qt_argv[])
} else if (global_commandline_info.jfilter != NULL) {
dfilter_t *jump_to_filter = NULL;
/* try to compile given filter */
- if (!dfilter_compile(global_commandline_info.jfilter, &jump_to_filter, &err_msg)) {
+ if (!dfilter_compile(global_commandline_info.jfilter, &jump_to_filter, &df_err)) {
// Similar code in MainWindow::mergeCaptureFile().
QMessageBox::warning(main_w, QObject::tr("Invalid Display Filter"),
QObject::tr("The filter expression %1 isn't a valid display filter. (%2).")
- .arg(global_commandline_info.jfilter, err_msg),
+ .arg(global_commandline_info.jfilter, df_err->msg),
QMessageBox::Ok);
- g_free(err_msg);
+ dfilter_error_free(df_err);
} else {
/* Filter ok, jump to the first packet matching the filter
conditions. Default search direction is forward, but if
diff --git a/ui/logray/logray_main_window.cpp b/ui/logray/logray_main_window.cpp
index 6c1dd3973a..8151f07b27 100644
--- a/ui/logray/logray_main_window.cpp
+++ b/ui/logray/logray_main_window.cpp
@@ -1164,16 +1164,16 @@ void LograyMainWindow::mergeCaptureFile()
char *tmpname;
if (merge_dlg.merge(file_name, read_filter)) {
- gchar *err_msg;
+ df_error_t *df_err = NULL;
- if (!dfilter_compile(qUtf8Printable(read_filter), &rfcode, &err_msg)) {
+ if (!dfilter_compile(qUtf8Printable(read_filter), &rfcode, &df_err)) {
/* Not valid. Tell the user, and go back and run the file
selection box again once they dismiss the alert. */
// Similar to commandline_info.jfilter section in main().
QMessageBox::warning(this, tr("Invalid Read Filter"),
- QString(tr("The filter expression %1 isn't a valid read filter. (%2).").arg(read_filter, err_msg)),
+ QString(tr("The filter expression %1 isn't a valid read filter. (%2).").arg(read_filter, df_err->msg)),
QMessageBox::Ok);
- g_free(err_msg);
+ dfilter_error_free(df_err);
continue;
}
} else {
diff --git a/ui/logray/logray_main_window_slots.cpp b/ui/logray/logray_main_window_slots.cpp
index d8465aca6d..70fd5b003c 100644
--- a/ui/logray/logray_main_window_slots.cpp
+++ b/ui/logray/logray_main_window_slots.cpp
@@ -161,7 +161,7 @@ bool LograyMainWindow::openCaptureFile(QString cf_path, QString read_filter, uns
{
QString file_name = "";
dfilter_t *rfcode = NULL;
- gchar *err_msg;
+ df_error_t *df_err = NULL;
int err;
gboolean name_param;
gboolean ret = true;
@@ -194,7 +194,7 @@ bool LograyMainWindow::openCaptureFile(QString cf_path, QString read_filter, uns
goto finish;
}
- if (dfilter_compile(qUtf8Printable(read_filter), &rfcode, &err_msg)) {
+ if (dfilter_compile(qUtf8Printable(read_filter), &rfcode, &df_err)) {
cf_set_rfcode(CaptureFile::globalCapFile(), rfcode);
} else {
/* Not valid. Tell the user, and go back and run the file
@@ -204,8 +204,9 @@ bool LograyMainWindow::openCaptureFile(QString cf_path, QString read_filter, uns
QString("The filter expression ") +
read_filter +
QString(" isn't a valid display filter. (") +
- err_msg + QString(")."),
+ df_err->msg + QString(")."),
QMessageBox::Ok);
+ dfilter_error_free(df_err);
if (!name_param) {
// go back to the selection dialogue only if the file