2001-01-28 04:43:26 +00:00
|
|
|
/* filters.c
|
|
|
|
* Code for reading and writing the filters file.
|
|
|
|
*
|
2006-05-21 05:12:17 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2001-01-28 04:43:26 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2001-01-28 04:43:26 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2001-01-28 04:43:26 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2001-01-28 04:43:26 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2001-01-28 04:43:26 +00:00
|
|
|
*/
|
|
|
|
|
2016-06-12 23:31:57 +00:00
|
|
|
#include <config.h>
|
2001-01-28 04:43:26 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
#include <errno.h>
|
2001-01-28 04:43:26 +00:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
2013-11-17 02:55:14 +00:00
|
|
|
#include <wsutil/file_util.h>
|
|
|
|
#include <wsutil/filesystem.h>
|
2001-01-28 04:43:26 +00:00
|
|
|
|
2014-12-20 22:13:05 +00:00
|
|
|
#include "filter_files.h"
|
2001-01-28 04:43:26 +00:00
|
|
|
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
/*
|
|
|
|
* Old filter file name.
|
|
|
|
*/
|
2015-02-13 17:05:26 +00:00
|
|
|
#define FILTER_FILE_NAME "filters"
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Capture filter file name.
|
|
|
|
*/
|
2015-02-13 17:05:26 +00:00
|
|
|
#define CFILTER_FILE_NAME "cfilters"
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Display filter file name.
|
|
|
|
*/
|
2015-02-13 17:05:26 +00:00
|
|
|
#define DFILTER_FILE_NAME "dfilters"
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
|
2001-01-28 04:43:26 +00:00
|
|
|
/*
|
2006-10-01 17:59:30 +00:00
|
|
|
* List of capture filters - saved.
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
*/
|
|
|
|
static GList *capture_filters = NULL;
|
|
|
|
|
|
|
|
/*
|
2006-10-01 17:59:30 +00:00
|
|
|
* List of display filters - saved.
|
2001-01-28 04:43:26 +00:00
|
|
|
*/
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
static GList *display_filters = NULL;
|
2001-01-28 04:43:26 +00:00
|
|
|
|
2006-10-01 17:59:30 +00:00
|
|
|
/*
|
|
|
|
* List of capture filters - currently edited.
|
|
|
|
*/
|
|
|
|
static GList *capture_edited_filters = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* List of display filters - currently edited.
|
|
|
|
*/
|
|
|
|
static GList *display_edited_filters = NULL;
|
|
|
|
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2001-02-03 06:03:42 +00:00
|
|
|
|
2015-02-13 17:05:26 +00:00
|
|
|
#define INIT_BUF_SIZE 128
|
2001-02-03 06:03:42 +00:00
|
|
|
|
2009-10-19 14:21:11 +00:00
|
|
|
static GList *
|
2006-10-01 17:59:30 +00:00
|
|
|
add_filter_entry(GList *fl, const char *filt_name, const char *filt_expr)
|
|
|
|
{
|
|
|
|
filter_def *filt;
|
|
|
|
|
|
|
|
filt = (filter_def *) g_malloc(sizeof(filter_def));
|
|
|
|
filt->name = g_strdup(filt_name);
|
|
|
|
filt->strval = g_strdup(filt_expr);
|
|
|
|
return g_list_append(fl, filt);
|
|
|
|
}
|
|
|
|
|
2017-02-03 22:15:56 +00:00
|
|
|
static void
|
|
|
|
free_filter_entry(gpointer data)
|
|
|
|
{
|
|
|
|
filter_def *filt = (filter_def*)data;
|
|
|
|
g_free(filt->name);
|
|
|
|
g_free(filt->strval);
|
|
|
|
g_free(filt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_filter_lists(void)
|
|
|
|
{
|
2017-02-04 15:26:34 +00:00
|
|
|
if (capture_filters) {
|
2017-02-15 15:46:05 +00:00
|
|
|
#if GLIB_CHECK_VERSION(2, 28, 0)
|
2017-02-03 22:15:56 +00:00
|
|
|
g_list_free_full(capture_filters, free_filter_entry);
|
2017-02-15 15:46:05 +00:00
|
|
|
#else
|
|
|
|
g_list_foreach(capture_filters, (GFunc)free_filter_entry, NULL);
|
|
|
|
g_list_free(capture_filters);
|
|
|
|
#endif
|
2017-02-04 15:26:34 +00:00
|
|
|
capture_filters = NULL;
|
|
|
|
}
|
|
|
|
if (display_filters) {
|
2017-02-15 15:46:05 +00:00
|
|
|
#if GLIB_CHECK_VERSION(2, 28, 0)
|
2017-02-03 22:15:56 +00:00
|
|
|
g_list_free_full(display_filters, free_filter_entry);
|
2017-02-15 15:46:05 +00:00
|
|
|
#else
|
|
|
|
g_list_foreach(display_filters, (GFunc)free_filter_entry, NULL);
|
|
|
|
g_list_free(display_filters);
|
|
|
|
#endif
|
|
|
|
display_filters = NULL;
|
2017-02-04 15:26:34 +00:00
|
|
|
}
|
|
|
|
if (capture_edited_filters) {
|
2017-02-15 15:46:05 +00:00
|
|
|
#if GLIB_CHECK_VERSION(2, 28, 0)
|
|
|
|
g_list_free_full(capture_edited_filters, free_filter_entry);
|
|
|
|
#else
|
|
|
|
g_list_foreach(capture_edited_filters, (GFunc)free_filter_entry, NULL);
|
|
|
|
g_list_free(capture_edited_filters);
|
|
|
|
#endif
|
|
|
|
capture_edited_filters = NULL;
|
2017-02-04 15:26:34 +00:00
|
|
|
}
|
|
|
|
if (display_edited_filters) {
|
2017-02-15 15:46:05 +00:00
|
|
|
#if GLIB_CHECK_VERSION(2, 28, 0)
|
|
|
|
g_list_free_full(display_edited_filters, free_filter_entry);
|
|
|
|
#else
|
|
|
|
g_list_foreach(display_edited_filters, (GFunc)free_filter_entry, NULL);
|
|
|
|
g_list_free(display_edited_filters);
|
|
|
|
#endif
|
|
|
|
display_edited_filters = NULL;
|
2017-02-04 15:26:34 +00:00
|
|
|
}
|
2017-02-03 22:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-10-19 14:21:11 +00:00
|
|
|
static GList *
|
2006-10-01 17:59:30 +00:00
|
|
|
remove_filter_entry(GList *fl, GList *fl_entry)
|
|
|
|
{
|
|
|
|
filter_def *filt;
|
|
|
|
|
|
|
|
filt = (filter_def *) fl_entry->data;
|
|
|
|
g_free(filt->name);
|
|
|
|
g_free(filt->strval);
|
|
|
|
g_free(filt);
|
|
|
|
return g_list_remove_link(fl, fl_entry);
|
|
|
|
}
|
|
|
|
|
2014-07-14 19:14:46 +00:00
|
|
|
static int
|
|
|
|
skip_whitespace(FILE *ff)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
2014-10-17 06:53:21 +00:00
|
|
|
while ((c = getc(ff)) != EOF && c != '\n' && g_ascii_isspace(c))
|
2014-07-14 19:14:46 +00:00
|
|
|
;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
getc_crlf(FILE *ff)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
c = getc(ff);
|
|
|
|
if (c == '\r') {
|
|
|
|
/* Treat CR-LF at the end of a line like LF, so that if we're reading
|
|
|
|
* a Windows-format file on UN*X, we handle it the same way we'd handle
|
|
|
|
* a UN*X-format file. */
|
|
|
|
c = getc(ff);
|
|
|
|
if (c != EOF && c != '\n') {
|
|
|
|
/* Put back the character after the CR, and process the CR normally. */
|
|
|
|
ungetc(c, ff);
|
|
|
|
c = '\r';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2001-01-28 04:43:26 +00:00
|
|
|
void
|
2006-10-01 17:59:30 +00:00
|
|
|
read_filter_list(filter_list_type_t list_type, char **pref_path_return,
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
int *errno_return)
|
2001-01-28 04:43:26 +00:00
|
|
|
{
|
2005-08-06 14:03:14 +00:00
|
|
|
const char *ff_name;
|
|
|
|
char *ff_path;
|
2001-01-28 04:43:26 +00:00
|
|
|
FILE *ff;
|
2006-10-01 17:59:30 +00:00
|
|
|
GList **flpp;
|
2001-02-03 06:03:42 +00:00
|
|
|
int c;
|
|
|
|
char *filt_name, *filt_expr;
|
|
|
|
int filt_name_len, filt_expr_len;
|
|
|
|
int filt_name_index, filt_expr_index;
|
|
|
|
int line = 1;
|
2001-01-28 04:43:26 +00:00
|
|
|
|
2015-02-13 17:05:26 +00:00
|
|
|
*pref_path_return = NULL; /* assume no error */
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
|
2006-10-01 17:59:30 +00:00
|
|
|
switch (list_type) {
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
|
|
|
|
case CFILTER_LIST:
|
|
|
|
ff_name = CFILTER_FILE_NAME;
|
2006-10-01 17:59:30 +00:00
|
|
|
flpp = &capture_filters;
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DFILTER_LIST:
|
|
|
|
ff_name = DFILTER_FILE_NAME;
|
2006-10-01 17:59:30 +00:00
|
|
|
flpp = &display_filters;
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
return;
|
2001-01-28 04:52:29 +00:00
|
|
|
}
|
|
|
|
|
2005-06-09 06:58:03 +00:00
|
|
|
/* try to open personal "cfilters"/"dfilters" file */
|
2013-04-09 02:48:03 +00:00
|
|
|
ff_path = get_persconffile_path(ff_name, TRUE);
|
2008-05-22 15:46:27 +00:00
|
|
|
if ((ff = ws_fopen(ff_path, "r")) == NULL) {
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
/*
|
2005-06-09 06:58:03 +00:00
|
|
|
* Did that fail because the file didn't exist?
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
*/
|
|
|
|
if (errno != ENOENT) {
|
|
|
|
/*
|
|
|
|
* No. Just give up.
|
|
|
|
*/
|
|
|
|
*pref_path_return = ff_path;
|
|
|
|
*errno_return = errno;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-06-09 06:58:03 +00:00
|
|
|
* Yes. See if there's an "old style" personal "filters" file; if so, read it.
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
* This means that a user will start out with their capture and
|
|
|
|
* display filter lists being identical; each list may contain
|
|
|
|
* filters that don't belong in that list. The user can edit
|
|
|
|
* the filter lists, and delete the ones that don't belong in
|
|
|
|
* a particular list.
|
|
|
|
*/
|
2001-10-24 07:18:39 +00:00
|
|
|
g_free(ff_path);
|
2013-04-09 02:48:03 +00:00
|
|
|
ff_path = get_persconffile_path(FILTER_FILE_NAME, FALSE);
|
2008-05-22 15:46:27 +00:00
|
|
|
if ((ff = ws_fopen(ff_path, "r")) == NULL) {
|
2005-06-09 06:58:03 +00:00
|
|
|
/*
|
2008-02-26 19:13:43 +00:00
|
|
|
* Did that fail because the file didn't exist?
|
2005-06-09 06:58:03 +00:00
|
|
|
*/
|
2015-02-13 17:05:26 +00:00
|
|
|
if (errno != ENOENT) {
|
|
|
|
/*
|
|
|
|
* No. Just give up.
|
|
|
|
*/
|
|
|
|
*pref_path_return = ff_path;
|
|
|
|
*errno_return = errno;
|
|
|
|
return;
|
|
|
|
}
|
2005-06-09 06:58:03 +00:00
|
|
|
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
/*
|
2008-02-26 19:13:43 +00:00
|
|
|
* Try to open the global "cfilters/dfilters" file */
|
|
|
|
g_free(ff_path);
|
|
|
|
ff_path = get_datafile_path(ff_name);
|
2008-05-22 15:46:27 +00:00
|
|
|
if ((ff = ws_fopen(ff_path, "r")) == NULL) {
|
2008-02-26 19:13:43 +00:00
|
|
|
|
2015-02-13 17:05:26 +00:00
|
|
|
/*
|
|
|
|
* Well, that didn't work, either. Just give up.
|
|
|
|
* Return 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);
|
|
|
|
}
|
|
|
|
return;
|
2008-02-26 19:13:43 +00:00
|
|
|
}
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we already have a list of filters, discard it. */
|
2006-10-01 17:59:30 +00:00
|
|
|
/* this should never happen - this function is called only once for each list! */
|
|
|
|
while(*flpp) {
|
2008-05-22 15:46:27 +00:00
|
|
|
*flpp = remove_filter_entry(*flpp, g_list_first(*flpp));
|
2001-01-28 04:43:26 +00:00
|
|
|
}
|
|
|
|
|
2001-02-03 06:03:42 +00:00
|
|
|
/* Allocate the filter name buffer. */
|
|
|
|
filt_name_len = INIT_BUF_SIZE;
|
2010-03-27 18:27:17 +00:00
|
|
|
filt_name = (char *)g_malloc(filt_name_len + 1);
|
2001-02-03 06:03:42 +00:00
|
|
|
filt_expr_len = INIT_BUF_SIZE;
|
2010-03-27 18:27:17 +00:00
|
|
|
filt_expr = (char *)g_malloc(filt_expr_len + 1);
|
2001-02-03 06:03:42 +00:00
|
|
|
|
2001-02-03 06:10:11 +00:00
|
|
|
for (line = 1; ; line++) {
|
2001-02-03 06:03:42 +00:00
|
|
|
/* Lines in a filter file are of the form
|
|
|
|
|
2015-02-13 17:05:26 +00:00
|
|
|
"name" expression
|
2001-02-03 06:03:42 +00:00
|
|
|
|
|
|
|
where "name" is a name, in quotes - backslashes in the name
|
|
|
|
escape the next character, so quotes and backslashes can appear
|
|
|
|
in the name - and "expression" is a filter expression, not in
|
|
|
|
quotes, running to the end of the line. */
|
|
|
|
|
|
|
|
/* Skip over leading white space, if any. */
|
2014-07-14 19:14:46 +00:00
|
|
|
c = skip_whitespace(ff);
|
2001-02-03 06:03:42 +00:00
|
|
|
|
|
|
|
if (c == EOF)
|
2015-02-13 17:05:26 +00:00
|
|
|
break; /* Nothing more to read */
|
2014-07-14 19:14:46 +00:00
|
|
|
if (c == '\n')
|
|
|
|
continue; /* Blank line. */
|
2001-02-03 06:03:42 +00:00
|
|
|
|
|
|
|
/* "c" is the first non-white-space character.
|
|
|
|
If it's not a quote, it's an error. */
|
|
|
|
if (c != '"') {
|
|
|
|
g_warning("'%s' line %d doesn't have a quoted filter name.", ff_path,
|
2015-02-13 17:05:26 +00:00
|
|
|
line);
|
2001-02-03 06:03:42 +00:00
|
|
|
while (c != '\n')
|
2015-02-13 17:05:26 +00:00
|
|
|
c = getc(ff); /* skip to the end of the line */
|
2001-01-28 04:43:26 +00:00
|
|
|
continue;
|
|
|
|
}
|
2001-02-03 06:03:42 +00:00
|
|
|
|
|
|
|
/* Get the name of the filter. */
|
|
|
|
filt_name_index = 0;
|
|
|
|
for (;;) {
|
2014-07-14 19:14:46 +00:00
|
|
|
c = getc_crlf(ff);
|
2001-02-03 06:03:42 +00:00
|
|
|
if (c == EOF || c == '\n')
|
2015-02-13 17:05:26 +00:00
|
|
|
break; /* End of line - or end of file */
|
2001-02-03 06:03:42 +00:00
|
|
|
if (c == '"') {
|
2015-02-13 17:05:26 +00:00
|
|
|
/* Closing quote. */
|
|
|
|
if (filt_name_index >= filt_name_len) {
|
|
|
|
/* Filter name buffer isn't long enough; double its length. */
|
|
|
|
filt_name_len *= 2;
|
|
|
|
filt_name = (char *)g_realloc(filt_name, filt_name_len + 1);
|
|
|
|
}
|
|
|
|
filt_name[filt_name_index] = '\0';
|
|
|
|
break;
|
2001-02-03 06:03:42 +00:00
|
|
|
}
|
|
|
|
if (c == '\\') {
|
2015-02-13 17:05:26 +00:00
|
|
|
/* Next character is escaped */
|
|
|
|
c = getc_crlf(ff);
|
|
|
|
if (c == EOF || c == '\n')
|
|
|
|
break; /* End of line - or end of file */
|
2001-02-03 06:03:42 +00:00
|
|
|
}
|
|
|
|
/* Add this character to the filter name string. */
|
|
|
|
if (filt_name_index >= filt_name_len) {
|
2015-02-13 17:05:26 +00:00
|
|
|
/* Filter name buffer isn't long enough; double its length. */
|
|
|
|
filt_name_len *= 2;
|
|
|
|
filt_name = (char *)g_realloc(filt_name, filt_name_len + 1);
|
2001-02-03 06:03:42 +00:00
|
|
|
}
|
|
|
|
filt_name[filt_name_index] = c;
|
|
|
|
filt_name_index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == EOF) {
|
|
|
|
if (!ferror(ff)) {
|
2015-02-13 17:05:26 +00:00
|
|
|
/* EOF, not error; no newline seen before EOF */
|
|
|
|
g_warning("'%s' line %d doesn't have a newline.", ff_path,
|
|
|
|
line);
|
2001-02-03 06:03:42 +00:00
|
|
|
}
|
2015-02-13 17:05:26 +00:00
|
|
|
break; /* nothing more to read */
|
2001-02-03 06:03:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (c != '"') {
|
|
|
|
/* No newline seen before end-of-line */
|
|
|
|
g_warning("'%s' line %d doesn't have a closing quote.", ff_path,
|
2015-02-13 17:05:26 +00:00
|
|
|
line);
|
2001-01-28 04:43:26 +00:00
|
|
|
continue;
|
|
|
|
}
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2001-02-03 06:03:42 +00:00
|
|
|
/* Skip over separating white space, if any. */
|
2014-07-14 19:14:46 +00:00
|
|
|
c = skip_whitespace(ff);
|
2001-02-03 06:03:42 +00:00
|
|
|
|
|
|
|
if (c == EOF) {
|
|
|
|
if (!ferror(ff)) {
|
2015-02-13 17:05:26 +00:00
|
|
|
/* EOF, not error; no newline seen before EOF */
|
|
|
|
g_warning("'%s' line %d doesn't have a newline.", ff_path,
|
|
|
|
line);
|
2001-02-03 06:03:42 +00:00
|
|
|
}
|
2015-02-13 17:05:26 +00:00
|
|
|
break; /* nothing more to read */
|
2001-02-03 06:03:42 +00:00
|
|
|
}
|
|
|
|
|
2001-02-03 06:10:11 +00:00
|
|
|
if (c == '\n') {
|
|
|
|
/* No filter expression */
|
|
|
|
g_warning("'%s' line %d doesn't have a filter expression.", ff_path,
|
2015-02-13 17:05:26 +00:00
|
|
|
line);
|
2001-02-03 06:10:11 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2001-02-03 06:03:42 +00:00
|
|
|
/* "c" is the first non-white-space character; it's the first
|
|
|
|
character of the filter expression. */
|
|
|
|
filt_expr_index = 0;
|
|
|
|
for (;;) {
|
|
|
|
/* Add this character to the filter expression string. */
|
|
|
|
if (filt_expr_index >= filt_expr_len) {
|
2015-02-13 17:05:26 +00:00
|
|
|
/* Filter expressioin buffer isn't long enough; double its length. */
|
|
|
|
filt_expr_len *= 2;
|
|
|
|
filt_expr = (char *)g_realloc(filt_expr, filt_expr_len + 1);
|
2001-02-03 06:03:42 +00:00
|
|
|
}
|
|
|
|
filt_expr[filt_expr_index] = c;
|
|
|
|
filt_expr_index++;
|
|
|
|
|
|
|
|
/* Get the next character. */
|
2014-07-14 19:14:46 +00:00
|
|
|
c = getc_crlf(ff);
|
2001-02-03 06:03:42 +00:00
|
|
|
if (c == EOF || c == '\n')
|
2015-02-13 17:05:26 +00:00
|
|
|
break;
|
2001-02-03 06:03:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (c == EOF) {
|
|
|
|
if (!ferror(ff)) {
|
2015-02-13 17:05:26 +00:00
|
|
|
/* EOF, not error; no newline seen before EOF */
|
|
|
|
g_warning("'%s' line %d doesn't have a newline.", ff_path,
|
|
|
|
line);
|
2001-02-03 06:03:42 +00:00
|
|
|
}
|
2015-02-13 17:05:26 +00:00
|
|
|
break; /* nothing more to read */
|
2001-02-03 06:03:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We saw the ending newline; terminate the filter expression string */
|
|
|
|
if (filt_expr_index >= filt_expr_len) {
|
|
|
|
/* Filter expressioin buffer isn't long enough; double its length. */
|
|
|
|
filt_expr_len *= 2;
|
2010-03-27 18:27:17 +00:00
|
|
|
filt_expr = (char *)g_realloc(filt_expr, filt_expr_len + 1);
|
2001-02-03 06:03:42 +00:00
|
|
|
}
|
|
|
|
filt_expr[filt_expr_index] = '\0';
|
|
|
|
|
|
|
|
/* Add the new filter to the list of filters */
|
2006-10-01 17:59:30 +00:00
|
|
|
*flpp = add_filter_entry(*flpp, filt_name, filt_expr);
|
2001-01-28 04:43:26 +00:00
|
|
|
}
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
if (ferror(ff)) {
|
|
|
|
*pref_path_return = ff_path;
|
|
|
|
*errno_return = errno;
|
|
|
|
} else
|
|
|
|
g_free(ff_path);
|
2001-01-28 04:43:26 +00:00
|
|
|
fclose(ff);
|
2001-02-03 06:03:42 +00:00
|
|
|
g_free(filt_name);
|
|
|
|
g_free(filt_expr);
|
2008-05-22 15:46:27 +00:00
|
|
|
|
2006-10-01 17:59:30 +00:00
|
|
|
/* init the corresponding edited list */
|
|
|
|
switch (list_type) {
|
|
|
|
case CFILTER_LIST:
|
|
|
|
copy_filter_list(CFILTER_EDITED_LIST, CFILTER_LIST);
|
|
|
|
break;
|
|
|
|
case DFILTER_LIST:
|
|
|
|
copy_filter_list(DFILTER_EDITED_LIST, DFILTER_LIST);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
return;
|
|
|
|
}
|
2001-01-28 04:43:26 +00:00
|
|
|
}
|
|
|
|
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
/*
|
|
|
|
* Get a pointer to a list of filters.
|
|
|
|
*/
|
|
|
|
static GList **
|
2006-10-01 17:59:30 +00:00
|
|
|
get_filter_list(filter_list_type_t list_type)
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
{
|
2006-10-01 17:59:30 +00:00
|
|
|
GList **flpp;
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
|
2006-10-01 17:59:30 +00:00
|
|
|
switch (list_type) {
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
|
|
|
|
case CFILTER_LIST:
|
2006-10-01 17:59:30 +00:00
|
|
|
flpp = &capture_filters;
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DFILTER_LIST:
|
2006-10-01 17:59:30 +00:00
|
|
|
flpp = &display_filters;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CFILTER_EDITED_LIST:
|
|
|
|
flpp = &capture_edited_filters;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DFILTER_EDITED_LIST:
|
|
|
|
flpp = &display_edited_filters;
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
2006-10-01 17:59:30 +00:00
|
|
|
flpp = NULL;
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
}
|
2006-10-01 17:59:30 +00:00
|
|
|
return flpp;
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a pointer to the first entry in a filter list.
|
|
|
|
*/
|
|
|
|
GList *
|
2006-10-01 17:59:30 +00:00
|
|
|
get_filter_list_first(filter_list_type_t list_type)
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
{
|
2006-10-01 17:59:30 +00:00
|
|
|
GList **flpp;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2006-10-01 17:59:30 +00:00
|
|
|
flpp = get_filter_list(list_type);
|
|
|
|
return g_list_first(*flpp);
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a new filter to the end of a list.
|
|
|
|
* Returns a pointer to the newly-added entry.
|
|
|
|
*/
|
|
|
|
GList *
|
2006-10-01 17:59:30 +00:00
|
|
|
add_to_filter_list(filter_list_type_t list_type, const char *name,
|
2003-12-04 00:45:39 +00:00
|
|
|
const char *expression)
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
{
|
2006-10-01 17:59:30 +00:00
|
|
|
GList **flpp;
|
|
|
|
|
2015-02-13 17:05:26 +00:00
|
|
|
flpp = get_filter_list(list_type);
|
2006-10-01 17:59:30 +00:00
|
|
|
*flpp = add_filter_entry(*flpp, name, expression);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2006-10-01 17:59:30 +00:00
|
|
|
return g_list_last(*flpp);
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove a filter from a list.
|
|
|
|
*/
|
|
|
|
void
|
2006-10-01 17:59:30 +00:00
|
|
|
remove_from_filter_list(filter_list_type_t list_type, GList *fl_entry)
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
{
|
2006-10-01 17:59:30 +00:00
|
|
|
GList **flpp;
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2015-02-13 17:05:26 +00:00
|
|
|
flpp = get_filter_list(list_type);
|
2006-10-01 17:59:30 +00:00
|
|
|
*flpp = remove_filter_entry(*flpp, fl_entry);
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2001-01-28 04:43:26 +00:00
|
|
|
void
|
2006-10-01 17:59:30 +00:00
|
|
|
save_filter_list(filter_list_type_t list_type, char **pref_path_return,
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
int *errno_return)
|
2001-01-28 04:43:26 +00:00
|
|
|
{
|
2005-08-06 14:03:14 +00:00
|
|
|
const gchar *ff_name;
|
2015-02-13 17:05:26 +00:00
|
|
|
gchar *ff_path, *ff_path_new;
|
|
|
|
GList *fl;
|
|
|
|
GList *flpp;
|
|
|
|
filter_def *filt;
|
|
|
|
FILE *ff;
|
|
|
|
guchar *p, c;
|
|
|
|
|
|
|
|
*pref_path_return = NULL; /* assume no error */
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
|
2006-10-01 17:59:30 +00:00
|
|
|
switch (list_type) {
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
|
|
|
|
case CFILTER_LIST:
|
|
|
|
ff_name = CFILTER_FILE_NAME;
|
|
|
|
fl = capture_filters;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DFILTER_LIST:
|
|
|
|
ff_name = DFILTER_FILE_NAME;
|
|
|
|
fl = display_filters;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-09 02:48:03 +00:00
|
|
|
ff_path = get_persconffile_path(ff_name, TRUE);
|
2001-01-28 04:43:26 +00:00
|
|
|
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
/* Write to "XXX.new", and rename if that succeeds.
|
|
|
|
That means we don't trash the file if we fail to write it out
|
|
|
|
completely. */
|
2005-08-08 18:50:39 +00:00
|
|
|
ff_path_new = g_strdup_printf("%s.new", ff_path);
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
|
2008-05-22 15:46:27 +00:00
|
|
|
if ((ff = ws_fopen(ff_path_new, "w")) == NULL) {
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
*pref_path_return = ff_path;
|
|
|
|
*errno_return = errno;
|
|
|
|
g_free(ff_path_new);
|
|
|
|
return;
|
|
|
|
}
|
2006-10-01 17:59:30 +00:00
|
|
|
flpp = g_list_first(fl);
|
|
|
|
while (flpp) {
|
|
|
|
filt = (filter_def *) flpp->data;
|
2001-02-03 06:03:42 +00:00
|
|
|
|
|
|
|
/* Write out the filter name as a quoted string; escape any quotes
|
|
|
|
or backslashes. */
|
|
|
|
putc('"', ff);
|
|
|
|
for (p = (guchar *)filt->name; (c = *p) != '\0'; p++) {
|
|
|
|
if (c == '"' || c == '\\')
|
|
|
|
putc('\\', ff);
|
|
|
|
putc(c, ff);
|
|
|
|
}
|
|
|
|
putc('"', ff);
|
|
|
|
|
|
|
|
/* Separate the filter name and value with a space. */
|
|
|
|
putc(' ', ff);
|
|
|
|
|
|
|
|
/* Write out the filter expression and a newline. */
|
|
|
|
fprintf(ff, "%s\n", filt->strval);
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
if (ferror(ff)) {
|
|
|
|
*pref_path_return = ff_path;
|
|
|
|
*errno_return = errno;
|
|
|
|
fclose(ff);
|
2008-05-22 15:46:27 +00:00
|
|
|
ws_unlink(ff_path_new);
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
g_free(ff_path_new);
|
|
|
|
return;
|
2001-01-28 04:43:26 +00:00
|
|
|
}
|
2006-10-01 17:59:30 +00:00
|
|
|
flpp = flpp->next;
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
}
|
|
|
|
if (fclose(ff) == EOF) {
|
|
|
|
*pref_path_return = ff_path;
|
|
|
|
*errno_return = errno;
|
2008-05-22 15:46:27 +00:00
|
|
|
ws_unlink(ff_path_new);
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
g_free(ff_path_new);
|
|
|
|
return;
|
2001-01-28 04:43:26 +00:00
|
|
|
}
|
|
|
|
|
2004-09-11 23:03:36 +00:00
|
|
|
#ifdef _WIN32
|
2001-03-15 09:50:39 +00:00
|
|
|
/* ANSI C doesn't say whether "rename()" removes the target if it
|
|
|
|
exists; the Win32 call to rename files doesn't do so, which I
|
|
|
|
infer is the reason why the MSVC++ "rename()" doesn't do so.
|
2012-05-22 10:05:01 +00:00
|
|
|
We must therefore remove the target file first, on Windows.
|
|
|
|
|
|
|
|
XXX - ws_rename() should be ws_stdio_rename() on Windows,
|
|
|
|
and ws_stdio_rename() uses MoveFileEx() with MOVEFILE_REPLACE_EXISTING,
|
|
|
|
so it should remove the target if it exists, so this stuff
|
|
|
|
shouldn't be necessary. Perhaps it dates back to when we were
|
|
|
|
calling rename(), with that being a wrapper around Microsoft's
|
|
|
|
_rename(), which didn't remove the target. */
|
2008-05-22 15:46:27 +00:00
|
|
|
if (ws_remove(ff_path) < 0 && errno != ENOENT) {
|
2001-03-15 09:50:39 +00:00
|
|
|
/* 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;
|
2008-05-22 15:46:27 +00:00
|
|
|
ws_unlink(ff_path_new);
|
2001-03-15 09:50:39 +00:00
|
|
|
g_free(ff_path_new);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-05-22 15:46:27 +00:00
|
|
|
if (ws_rename(ff_path_new, ff_path) < 0) {
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
*pref_path_return = ff_path;
|
|
|
|
*errno_return = errno;
|
2008-05-22 15:46:27 +00:00
|
|
|
ws_unlink(ff_path_new);
|
Have separate capture and display filter lists; some filter dialog boxes
use the capture filter lists, and others use the display filter list, as
appropriate.
Have separate menu items for editing the capture and display filter
lists.
Have separate "~/.ethereal/cfilters" and "~/.ethereal/dfilters" files
for the two lists; if either of those files isn't found, we try
"~/.ethereal/filters", which means that you will start out with two
identical lists holding all your filters - if certain filters belong
only in one list, you'll have to delete them by hand from the other
list.
Do I/O error checking when reading and writing filter lists; when
writing a filter list, write it to a new file, and then rename the new
file on top of the old file, so that you don't lose your old filter list
if, for example, you run out of disk space or disk quota.
svn path=/trunk/; revision=2948
2001-01-28 09:13:10 +00:00
|
|
|
g_free(ff_path_new);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
g_free(ff_path_new);
|
2001-01-28 04:43:26 +00:00
|
|
|
g_free(ff_path);
|
|
|
|
}
|
2006-10-01 17:59:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy a filter list into another.
|
|
|
|
*/
|
|
|
|
void copy_filter_list(filter_list_type_t dest_type, filter_list_type_t src_type)
|
|
|
|
{
|
2014-10-12 18:56:12 +00:00
|
|
|
GList **flpp_dest;
|
|
|
|
GList **flpp_src;
|
|
|
|
GList *flp_src;
|
|
|
|
filter_def *filt;
|
2006-10-01 17:59:30 +00:00
|
|
|
|
2014-10-12 18:56:12 +00:00
|
|
|
g_assert(dest_type != src_type);
|
2006-10-01 17:59:30 +00:00
|
|
|
|
2014-10-12 18:56:12 +00:00
|
|
|
flpp_dest = get_filter_list(dest_type);
|
|
|
|
flpp_src = get_filter_list(src_type);
|
|
|
|
/* throw away the "old" destination list - a NULL list is ok here */
|
|
|
|
while(*flpp_dest) {
|
|
|
|
*flpp_dest = remove_filter_entry(*flpp_dest, g_list_first(*flpp_dest));
|
|
|
|
}
|
|
|
|
g_assert(g_list_length(*flpp_dest) == 0);
|
2006-10-01 17:59:30 +00:00
|
|
|
|
2014-10-12 18:56:12 +00:00
|
|
|
/* copy the list entries */
|
|
|
|
for(flp_src = g_list_first(*flpp_src); flp_src; flp_src = g_list_next(flp_src)) {
|
|
|
|
filt = (filter_def *)(flp_src->data);
|
2006-10-01 17:59:30 +00:00
|
|
|
|
2014-10-12 18:56:12 +00:00
|
|
|
*flpp_dest = add_filter_entry(*flpp_dest, filt->name, filt->strval);
|
|
|
|
}
|
2006-10-01 17:59:30 +00:00
|
|
|
}
|
2014-10-12 18:56:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 2
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* ex: set shiftwidth=2 tabstop=8 expandtab:
|
|
|
|
* :indentSize=2:tabSize=8:noTabs=true:
|
|
|
|
*/
|