Fixes crashing when opening color filters and pressing OK
[metze/wireshark/wip.git] / color_filters.h
1 /* color_filters.h
2  * Definitions for color filters
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24 #ifndef  __COLOR_FILTERS_H__
25 #define  __COLOR_FILTERS_H__
26
27 #define TEMP_COLOR_PREFIX       "___tmp_color_filter___"
28 /** @file
29  *  Color filters.
30  */
31
32 /* Data for a color filter. */
33 typedef struct _color_filter {
34         gchar     *filter_name;   /* name of the filter */
35         gchar     *filter_text;   /* text of the filter expression */
36         color_t    bg_color;      /* background color for packets that match */
37         color_t    fg_color;      /* foreground color for packets that match */
38         gboolean   disabled;      /* set if the filter is disabled */
39         gboolean   selected;      /* set if the filter is selected in the color dialog box */
40
41         /* only used inside of color_filters.c */
42         dfilter_t *c_colorfilter; /* compiled filter expression */
43
44         /* only used outside of color_filters.c (beside init) */
45         void      *edit_dialog;   /* if filter is being edited, dialog
46                                    * box for it */
47 } color_filter_t;
48
49
50 /** Init the color filters (incl. initial read from file). */
51 void color_filters_init(void);
52
53 /** Cleanup remaining color filter zombies */
54 void color_filters_cleanup(void);
55
56 /** Color filters currently used?
57  *
58  * @return TRUE, if filters are used
59  */
60 gboolean color_filters_used(void);
61
62 /** En-/disable color filters
63  *
64  * @param enable TRUE to enable (default)
65  */
66 void
67 color_filters_enable(gboolean enable);
68
69 /** Set the filter string of a temporary color filter
70  *
71  * @param filt_nr a number 1-10 pointing to a temporary color
72  * @param filter the new filter-string
73  */
74 void
75 color_filters_set_tmp(guint8 filt_nr, gchar *filter);
76
77 /* Prime the epan_dissect_t with all the compiler
78  * color filters of the current filter list. 
79  *
80  * @param the epan dissector details
81  */
82 void color_filters_prime_edt(epan_dissect_t *edt);
83
84 /** Colorize a specific packet.
85  *
86  * @param row the row in the packet list
87  * @param edt the dissected packet
88  * @return the matching color filter or NULL
89  */
90 color_filter_t *
91 color_filters_colorize_packet(gint row, epan_dissect_t *edt);
92
93
94
95 /** Clone the currently active filter list.
96  *
97  * @param user_data will be returned by each call to to color_filter_add_cb()
98  */
99 void color_filters_clone(gpointer user_data);
100
101 /** Load filters (import) from some other filter file.
102  *
103  * @param path the path to the import file
104  * @param user_data will be returned by each call to to color_filter_add_cb()
105  * @return TRUE, if read succeeded
106  */
107 gboolean color_filters_import(gchar *path, gpointer user_data);
108
109 /** Read filters from the global filter file (not the users file).
110  *
111  * @param user_data will be returned by each call to to color_filter_add_cb()
112  * @return TRUE, if read succeeded
113  */
114 gboolean color_filters_read_globals(gpointer user_data);
115
116 /** A color filter was added (while importing).
117  * (color_filters.c calls this for every filter coming in)
118  *
119  * @param colorf the new color filter
120  * @param user_data from caller
121  */
122 void color_filter_add_cb (color_filter_t *colorf, gpointer user_data);
123
124
125
126 /** Apply a changed filter list.
127  *
128  * @param tmp_cfl the temporary color filter list to apply
129  * @param edit_cfl the edited permanent color filter list to apply
130  */
131 void color_filters_apply(GSList *tmp_cfl, GSList *edit_cfl);
132
133 /** Save filters in users filter file.
134  *
135  * @param cfl the filter list to write
136  * @return TRUE if write succeeded
137  */
138 gboolean color_filters_write(GSList *cfl);
139
140 /** Save filters (export) to some other filter file.
141  *
142  * @param path the path to the filter file
143  * @param cfl the filter list to write
144  * @param only_selected TRUE if only the selected filters should be saved
145  * @return TRUE, if write succeeded
146  */
147 gboolean color_filters_export(gchar *path, GSList *cfl, gboolean only_selected);
148
149
150
151 /** Create a new color filter (g_malloc'ed).
152  *
153  * @param name the name of the filter
154  * @param filter_string the filter string
155  * @param bg_color background color
156  * @param fg_color foreground color
157  * @return the new color filter
158  */
159 color_filter_t *color_filter_new(
160     const gchar *name, const gchar *filter_string,
161     color_t *bg_color, color_t *fg_color, gboolean disabled);
162
163 /** Delete a single color filter (g_free'ed).
164  *
165  * @param colorf the color filter to be removed
166  */
167 void color_filter_delete(color_filter_t *colorf);
168
169
170
171
172 /** Delete a filter list including all entries.
173  *
174  * @param cfl the filter list to delete
175  */
176 void color_filter_list_delete(GSList **cfl);
177
178
179
180 #endif