GString *runtime_info_str;
char *init_progfile_dir_error;
- char *cf_path;
char *err_msg = NULL;
- int cf_open_errno;
e_prefs *prefs_p;
int ret = EXIT_SUCCESS;
prefs_p = read_prefs();
- read_filter_list(CFILTER_LIST, &cf_path, &cf_open_errno);
- if (cf_path != NULL) {
- cmdarg_err("Could not open your capture filter file\n\"%s\": %s.",
- cf_path, g_strerror(cf_open_errno));
- g_free(cf_path);
- }
+ read_filter_list(CFILTER_LIST);
if (!color_filters_init(&err_msg, NULL)) {
fprintf(stderr, "color_filters_init() failed %s\n", err_msg);
WSADATA wsaData;
#endif /* _WIN32 */
- char *cf_path;
- int cf_open_errno;
int err;
volatile int exit_status = EXIT_SUCCESS;
#ifdef HAVE_LIBPCAP
prefs_p = read_prefs();
- read_filter_list(CFILTER_LIST, &cf_path, &cf_open_errno);
- if (cf_path != NULL) {
- cmdarg_err("Could not open your capture filter file\n\"%s\": %s.",
- cf_path, g_strerror(cf_open_errno));
- g_free(cf_path);
- }
+ read_filter_list(CFILTER_LIST);
/*
* Read the files that enable and disable protocols and heuristic
#include <wsutil/file_util.h>
#include <wsutil/filesystem.h>
#include <wsutil/glib-compat.h>
+#include <wsutil/report_message.h>
#include "ui/filter_files.h"
/*
* Read in a list of filters.
*
- * On success, "*pref_path_return" is set to NULL.
- * On error, "*pref_path_return" is set to point to the pathname of
- * the file we tried to read - it should be freed by our caller -
- * and "*errno_return" is set to the error.
+ * On error, report the error via the UI.
*/
#define INIT_BUF_SIZE 128
}
void
-read_filter_list(filter_list_type_t list_type, char **pref_path_return,
- int *errno_return)
+read_filter_list(filter_list_type_t list_type)
{
- const char *ff_name;
+ const char *ff_name, *ff_description;
char *ff_path;
FILE *ff;
GList **flpp;
int filt_name_index, filt_expr_index;
int line = 1;
- *pref_path_return = NULL; /* assume no error */
-
switch (list_type) {
case CFILTER_LIST:
ff_name = CFILTER_FILE_NAME;
+ ff_description = "capture";
flpp = &capture_filters;
break;
case DFILTER_LIST:
ff_name = DFILTER_FILE_NAME;
+ ff_description = "display";
flpp = &display_filters;
break;
/*
* No. Just give up.
*/
- *pref_path_return = ff_path;
- *errno_return = errno;
+ report_warning("Could not open your %s filter file\n\"%s\": %s.",
+ ff_description, ff_path, g_strerror(errno));
+ g_free(ff_path);
return;
}
/*
* Did that fail because the file didn't exist?
*/
- if (errno != ENOENT) {
+ if (errno != ENOENT) {
/*
* No. Just give up.
*/
- *pref_path_return = ff_path;
- *errno_return = errno;
- return;
- }
+ report_warning("Could not open your %s filter file\n\"%s\": %s.",
+ ff_description, ff_path, g_strerror(errno));
+ g_free(ff_path);
+ return;
+ }
/*
* Try to open the global "cfilters/dfilters" file */
g_free(ff_path);
ff_path = get_datafile_path(ff_name);
if ((ff = ws_fopen(ff_path, "r")) == NULL) {
-
/*
* Well, that didn't work, either. Just give up.
- * Return an error if the file existed but we couldn't open it.
+ * Report an error if the file existed but we couldn't open it.
*/
if (errno != ENOENT) {
- *pref_path_return = ff_path;
- *errno_return = errno;
- } else {
- g_free(ff_path);
+ report_warning("Could not open your %s filter file\n\"%s\": %s.",
+ ff_description, ff_path, g_strerror(errno));
}
+ g_free(ff_path);
return;
}
}
*flpp = add_filter_entry(*flpp, filt_name, filt_expr);
}
if (ferror(ff)) {
- *pref_path_return = ff_path;
- *errno_return = errno;
- } else
- g_free(ff_path);
+ report_warning("Error reading your %s filter file\n\"%s\": %s.",
+ ff_description, ff_path, g_strerror(errno));
+ }
+ g_free(ff_path);
fclose(ff);
g_free(filt_name);
g_free(filt_expr);
/*
* Write out a list of filters.
*
- * On success, "*pref_path_return" is set to NULL.
- * On error, "*pref_path_return" is set to point to the pathname of
- * the file we tried to read - it should be freed by our caller -
- * and "*errno_return" is set to the error.
+ * On error, report the error via the UI.
*/
void
-save_filter_list(filter_list_type_t list_type, char **pref_path_return,
- int *errno_return)
+save_filter_list(filter_list_type_t list_type)
{
- const gchar *ff_name;
+ char *pf_dir_path;
+ const gchar *ff_name, *ff_description;
gchar *ff_path, *ff_path_new;
GList *fl;
GList *flpp;
FILE *ff;
guchar *p, c;
- *pref_path_return = NULL; /* assume no error */
-
switch (list_type) {
case CFILTER_LIST:
ff_name = CFILTER_FILE_NAME;
+ ff_description = "capture";
fl = capture_filters;
break;
case DFILTER_LIST:
ff_name = DFILTER_FILE_NAME;
+ ff_description = "display";
fl = display_filters;
break;
return;
}
+ /* Create the directory that holds personal configuration files,
+ if necessary. */
+ if (create_persconffile_dir(&pf_dir_path) == -1) {
+ report_failure("Can't create directory\n\"%s\"\nfor filter files: %s.",
+ pf_dir_path, g_strerror(errno));
+ g_free(pf_dir_path);
+ return;
+ }
+
ff_path = get_persconffile_path(ff_name, TRUE);
/* Write to "XXX.new", and rename if that succeeds.
ff_path_new = g_strdup_printf("%s.new", ff_path);
if ((ff = ws_fopen(ff_path_new, "w")) == NULL) {
- *pref_path_return = ff_path;
- *errno_return = errno;
+ /* We had an error saving the filter. */
+ report_failure("Error saving your %s filter file\nCouldn't open \"%s\": %s.",
+ ff_description, ff_path_new, g_strerror(errno));
g_free(ff_path_new);
+ g_free(ff_path);
return;
}
flpp = g_list_first(fl);
/* Write out the filter expression and a newline. */
fprintf(ff, "%s\n", filt->strval);
if (ferror(ff)) {
- *pref_path_return = ff_path;
- *errno_return = errno;
+ report_failure("Error saving your %s filter file\nWrite to \"%s\" failed: %s.",
+ ff_description, ff_path_new, g_strerror(errno));
fclose(ff);
ws_unlink(ff_path_new);
g_free(ff_path_new);
+ g_free(ff_path);
return;
}
flpp = flpp->next;
}
if (fclose(ff) == EOF) {
- *pref_path_return = ff_path;
- *errno_return = errno;
+ report_failure("Error saving your %s filter file\nWrite to \"%s\" failed: %s.",
+ ff_description, ff_path_new, g_strerror(errno));
ws_unlink(ff_path_new);
g_free(ff_path_new);
+ g_free(ff_path);
return;
}
/* It failed for some reason other than "it's not there"; if
it's not there, we don't need to remove it, so we just
drive on. */
- *pref_path_return = ff_path;
- *errno_return = errno;
+ report_failure("Error saving your %s filter file\nCouldn't remove \"%s\": %s.",
+ ff_description, ff_path, g_strerror(errno));
ws_unlink(ff_path_new);
g_free(ff_path_new);
+ g_free(ff_path);
return;
}
#endif
if (ws_rename(ff_path_new, ff_path) < 0) {
- *pref_path_return = ff_path;
- *errno_return = errno;
+ report_failure("Error saving your %s filter file\nCouldn't rename \"%s\" to \"%s\": %s.",
+ ff_description, ff_path_new, ff_path, g_strerror(errno));
ws_unlink(ff_path_new);
g_free(ff_path_new);
+ g_free(ff_path);
return;
}
g_free(ff_path_new);
/*
* Read in a list of filters.
*
- * On success, "*pref_path_return" is set to NULL.
- * On error, "*pref_path_return" is set to point to the pathname of
- * the file we tried to read - it should be freed by our caller -
- * and "*errno_return" is set to the error.
+ * On error, report the error via the UI.
*/
-void read_filter_list(filter_list_type_t list_type, char **pref_path_return,
- int *errno_return);
+void read_filter_list(filter_list_type_t list_type);
/*
* Get a pointer to the first entry in a filter list.
/*
* Write out a list of filters.
*
- * On success, "*pref_path_return" is set to NULL.
- * On error, "*pref_path_return" is set to point to the pathname of
- * the file we tried to read - it should be freed by our caller -
- * and "*errno_return" is set to the error.
+ * On error, report the error via the UI.
*/
-void save_filter_list(filter_list_type_t list_type, char **pref_path_return,
- int *errno_return);
+void save_filter_list(filter_list_type_t list_type);
/*
* Clone the filter list so it can be edited. GTK+ only.
static void
filter_dlg_save(filter_list_type_t list_type)
{
- char *pf_dir_path;
- char *f_path;
- int f_save_errno;
- const char *filter_type;
-
switch (list_type) {
case CFILTER_EDITED_LIST:
- filter_type = "capture";
- list_type = CFILTER_LIST;
- copy_filter_list(CFILTER_LIST, CFILTER_EDITED_LIST);
+ list_type = CFILTER_LIST;
+ copy_filter_list(CFILTER_LIST, CFILTER_EDITED_LIST);
break;
case DFILTER_EDITED_LIST:
- filter_type = "display";
- list_type = DFILTER_LIST;
- copy_filter_list(DFILTER_LIST, DFILTER_EDITED_LIST);
+ list_type = DFILTER_LIST;
+ copy_filter_list(DFILTER_LIST, DFILTER_EDITED_LIST);
break;
default:
g_assert_not_reached();
- filter_type = NULL;
break;
}
- /* Create the directory that holds personal configuration files,
- if necessary. */
- if (create_persconffile_dir(&pf_dir_path) == -1) {
- simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
- "Can't create directory\n\"%s\"\nfor filter files: %s.",
- pf_dir_path, g_strerror(errno));
- g_free(pf_dir_path);
- return;
- }
-
- save_filter_list(list_type, &f_path, &f_save_errno);
- if (f_path != NULL) {
- /* We had an error saving the filter. */
- simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
- "Could not save to your %s filter file\n\"%s\": %s.",
- filter_type, f_path, g_strerror(f_save_errno));
- g_free(f_path);
- }
+ save_filter_list(list_type);
}
static e_prefs *
read_configuration_files(void)
{
- int cf_open_errno, df_open_errno;
- char *cf_path, *df_path;
e_prefs *prefs_p;
/* load the decode as entries of this profile */
#endif
/* Read the capture filter file. */
- read_filter_list(CFILTER_LIST, &cf_path, &cf_open_errno);
- if (cf_path != NULL) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "Could not open your capture filter file\n\"%s\": %s.",
- cf_path, g_strerror(cf_open_errno));
- g_free(cf_path);
- }
+ read_filter_list(CFILTER_LIST);
/* Read the display filter file. */
- read_filter_list(DFILTER_LIST, &df_path, &df_open_errno);
- if (df_path != NULL) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "Could not open your display filter file\n\"%s\": %s.",
- df_path, g_strerror(df_open_errno));
- g_free(df_path);
- }
+ read_filter_list(DFILTER_LIST);
/*
* Read the files that enable and disable protocols and heuristic
}
}
- char *f_path;
- int f_save_errno;
-
- save_filter_list(CFILTER_LIST, &f_path, &f_save_errno);
- if (f_path != NULL) {
- // We had an error saving the filter.
- QString warning_title = tr("Unable to save capture filter settings.");
- QString warning_msg = tr("Could not save to your capture filter file\n\"%1\": %2.").arg(f_path).arg(g_strerror(f_save_errno));
-
- QMessageBox::warning(this, warning_title, warning_msg, QMessageBox::Ok);
- g_free(f_path);
- }
+ save_filter_list(CFILTER_LIST);
updateBookmarkMenu();
}
}
}
- char *f_path;
- int f_save_errno;
-
- save_filter_list(DFILTER_LIST, &f_path, &f_save_errno);
- if (f_path != NULL) {
- // We had an error saving the filter.
- QString warning_title = tr("Unable to save display filter settings.");
- QString warning_msg = tr("Could not save to your display filter file\n\"%1\": %2.").arg(f_path).arg(g_strerror(f_save_errno));
-
- QMessageBox::warning(this, warning_title, warning_msg, QMessageBox::Ok);
- g_free(f_path);
- }
+ save_filter_list(DFILTER_LIST);
updateBookmarkMenu();
}
++it;
}
- char *pf_dir_path;
- char *f_path;
- int f_save_errno;
-
- /* Create the directory that holds personal configuration files,
- if necessary. */
- if (create_persconffile_dir(&pf_dir_path) == -1) {
- QMessageBox::warning(this, tr("Unable to create profile directory."),
- tr("Unable to create directory\n\"%1\"\nfor filter files: %2.")
- .arg(pf_dir_path)
- .arg(g_strerror(errno)),
- QMessageBox::Ok);
- g_free(pf_dir_path);
- return;
- }
-
- save_filter_list(fl_type, &f_path, &f_save_errno);
- if (f_path != NULL) {
- /* We had an error saving the filter. */
- QString warning_title;
- QString warning_msg;
- if (fl_type == CFILTER_LIST) {
- warning_title = tr("Unable to save capture filter settings.");
- warning_msg = tr("Could not save to your capture filter file\n\"%1\": %2.")
- .arg(f_path).arg(g_strerror(f_save_errno));
- } else {
- warning_title = tr("Unable to save display filter settings.");
- warning_msg = tr("Could not save to your display filter file\n\"%1\": %2.")
- .arg(f_path).arg(g_strerror(f_save_errno));
- }
- QMessageBox::warning(this, warning_title, warning_msg, QMessageBox::Ok);
- g_free(f_path);
- }
+ save_filter_list(fl_type);
if (filter_type_ == CaptureFilter) {
wsApp->emitAppSignal(WiresharkApplication::CaptureFilterListChanged);
_e_prefs *WiresharkApplication::readConfigurationFiles(bool reset)
{
- int cf_open_errno, df_open_errno;
- char *cf_path, *df_path;
e_prefs *prefs_p;
if (reset) {
#endif
/* Read the capture filter file. */
- read_filter_list(CFILTER_LIST, &cf_path, &cf_open_errno);
- if (cf_path != NULL) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "Could not open your capture filter file\n\"%s\": %s.", cf_path,
- g_strerror(cf_open_errno));
- g_free(cf_path);
- }
+ read_filter_list(CFILTER_LIST);
/* Read the display filter file. */
- read_filter_list(DFILTER_LIST, &df_path, &df_open_errno);
- if (df_path != NULL) {
- simple_dialog(ESD_TYPE_WARN, ESD_BTN_OK,
- "Could not open your display filter file\n\"%s\": %s.", df_path,
- g_strerror(df_open_errno));
- g_free(df_path);
- }
+ read_filter_list(DFILTER_LIST);
/*
* Read the files that enable and disable protocols and heuristic