1 /* recent.h
2  * Definitions for recent "preference" handling routines
3  * Copyright 2004, Ulf Lamping <ulf.lamping@web.de>
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * SPDX-License-Identifier: GPL-2.0-or-later
10  */
11 
12 #ifndef __RECENT_H__
13 #define __RECENT_H__
14 
15 #include <glib.h>
16 
17 #include <stdio.h>
18 #include "epan/timestamp.h"
19 #include "ui/ws_ui_util.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif /* __cplusplus */
24 
25 /** @file
26  *  Recent user interface settings.
27  *  @ingroup main_window_group
28  */
29 
30 /** ???. */
31 #define RECENT_KEY_CAPTURE_FILE         "recent.capture_file"
32 
33 /** ???. */
34 #define RECENT_KEY_DISPLAY_FILTER       "recent.display_filter"
35 
36 #define RECENT_KEY_COL_WIDTH            "column.width"
37 
38 #define RECENT_KEY_CAPTURE_FILTER       "recent.capture_filter"
39 
40 #define RECENT_KEY_REMOTE_HOST          "recent.remote_host"
41 
42 typedef struct _col_width_data {
43     gint   cfmt;
44     gchar *cfield;
45     gint   width;
46     gchar  xalign;
47 } col_width_data;
48 
49 /** Defines used in col_width_data.xalign */
50 #define COLUMN_XALIGN_DEFAULT  0
51 #define COLUMN_XALIGN_LEFT    'L'
52 #define COLUMN_XALIGN_CENTER  'C'
53 #define COLUMN_XALIGN_RIGHT   'R'
54 
55 typedef enum {
56     BYTES_HEX,
57     BYTES_BITS
58 } bytes_view_type;
59 
60 typedef enum {
61     BYTES_ENC_FROM_PACKET, // frame_data packet_char_enc
62     BYTES_ENC_ASCII,
63     BYTES_ENC_EBCDIC
64 } bytes_encoding_type;
65 
66 typedef enum {
67     SEARCH_IN_PACKET_LIST,
68     SEARCH_IN_PACKET_DETAILS,
69     SEARCH_IN_PACKET_BYTES
70 } search_in_type;
71 
72 typedef enum {
73     SEARCH_CHAR_SET_NARROW_AND_WIDE,
74     SEARCH_CHAR_SET_NARROW,
75     SEARCH_CHAR_SET_WIDE
76 } search_char_set_type;
77 
78 typedef enum {
79     SEARCH_TYPE_DISPLAY_FILTER,
80     SEARCH_TYPE_HEX_VALUE,
81     SEARCH_TYPE_STRING,
82     SEARCH_TYPE_REGEX
83 } search_type_type;
84 
85 /** Recent settings. */
86 typedef struct recent_settings_tag {
87     gboolean    main_toolbar_show;
88     gboolean    filter_toolbar_show;
89     gboolean    wireless_toolbar_show;
90     gboolean    packet_list_show;
91     gboolean    tree_view_show;
92     gboolean    byte_view_show;
93     gboolean    packet_diagram_show;
94     gboolean    statusbar_show;
95     gboolean    packet_list_colorize;
96     ts_type     gui_time_format;
97     gint        gui_time_precision;
98     ts_seconds_type gui_seconds_format;
99     gint        gui_zoom_level;
100     bytes_view_type gui_bytes_view;
101     bytes_encoding_type gui_bytes_encoding;
102     gboolean    gui_packet_diagram_field_values;
103     gboolean    gui_allow_hover_selection;
104 
105     search_in_type  gui_search_in;
106     search_char_set_type gui_search_char_set;
107     gboolean    gui_search_case_sensitive;
108     search_type_type gui_search_type;
109 
110     gint        gui_geometry_main_x;
111     gint        gui_geometry_main_y;
112     gint        gui_geometry_main_width;
113     gint        gui_geometry_main_height;
114 
115     gboolean    gui_geometry_main_maximized;
116     gboolean    gui_geometry_leftalign_actions;
117 
118     gboolean    has_gui_geometry_main_upper_pane;   /* gui_geometry_main_upper_pane is valid */
119     gint        gui_geometry_main_upper_pane;
120     gboolean    has_gui_geometry_main_lower_pane;   /* gui_geometry_main_lower_pane is valid */
121     gint        gui_geometry_main_lower_pane;
122     gboolean    has_gui_geometry_status_pane;       /* gui_geometry_status_pane is valid */
123     gint        gui_geometry_status_pane_left;
124     gint        gui_geometry_status_pane_right;
125     gint        gui_geometry_wlan_stats_pane;
126     gboolean    privs_warn_if_elevated;
127     gboolean    sys_warn_if_no_capture;
128     GList      *col_width_list;                     /* column widths */
129     GList      *conversation_tabs;                  /* enabled conversation dialog tabs */
130     GList      *endpoint_tabs;                      /* enabled endpoint dialog tabs */
131     gchar      *gui_fileopen_remembered_dir;        /* folder of last capture loaded in File Open dialog */
132     gboolean    gui_rlc_use_pdus_from_mac;
133     GList      *custom_colors;
134     GList      *gui_additional_toolbars;
135     GList      *interface_toolbars;
136 } recent_settings_t;
137 
138 /** Global recent settings. */
139 extern recent_settings_t recent;
140 
141 /** Initialize recent settings module (done at startup) */
142 extern void recent_init(void);
143 
144 /** Cleanup/Frees recent settings (done at shutdown) */
145 extern void recent_cleanup(void);
146 
147 /** Write recent_common settings file.
148  *
149  * @return TRUE if succeeded, FALSE if failed
150  */
151 extern gboolean write_recent(void);
152 
153 /** Write profile recent settings file.
154  *
155  * @return TRUE if succeeded, FALSE if failed
156  */
157 extern gboolean write_profile_recent(void);
158 
159 /** Read recent settings file (static part).
160  *
161  * @param rf_path_return path to recent file if function failed
162  * @param rf_errno_return if failed
163  * @return TRUE if succeeded, FALSE if failed (check parameters for reason).
164  */
165 extern gboolean recent_read_static(char **rf_path_return, int *rf_errno_return);
166 
167 /** Read profile recent settings file (static part).
168  *
169  * @param rf_path_return path to recent file if function failed
170  * @param rf_errno_return if failed
171  * @return TRUE if succeeded, FALSE if failed (check parameters for reason).
172  */
173 extern gboolean recent_read_profile_static(char **rf_path_return, int *rf_errno_return);
174 
175 /** Read recent settings file (dynamic part).
176  *
177  * @param rf_path_return path to recent file if function failed
178  * @param rf_errno_return if failed
179  * @return TRUE if succeeded, FALSE if failed (check parameters for reason).
180  */
181 extern gboolean recent_read_dynamic(char **rf_path_return, int *rf_errno_return);
182 
183 /**
184  * Given a -o command line string, parse it and set the recent value in
185  * question.  Return an indication of whether it succeeded or failed
186  * in some fashion.
187  *
188  * @param prefarg a string of the form "<recent name>:<recent value>", as might appear
189  * as an argument to a "-o" command line option
190  * @return PREFS_SET_OK or PREFS_SET_SYNTAX_ERR
191  */
192 extern int recent_set_arg(char *prefarg);
193 
194 /** Get the column width for the given column
195  *
196  * @param col column number
197  */
198 extern gint recent_get_column_width(gint col);
199 
200 /** Set the column width for the given column
201  *
202  * @param col column number
203  * @param width column width
204  */
205 extern void recent_set_column_width(gint col, gint width);
206 
207 /** Get the column xalign for the given column
208  *
209  * @param col column number
210  */
211 extern gchar recent_get_column_xalign(gint col);
212 
213 /** Set the column xalign for the given column
214  *
215  * @param col column number
216  * @param xalign column alignment
217  */
218 extern void recent_set_column_xalign(gint col, gchar xalign);
219 
220 /* save the window and its current geometry into the geometry hashtable */
221 extern void window_geom_save(const gchar *name, window_geometry_t *geom);
222 
223 /* load the desired geometry for this window from the geometry hashtable */
224 extern gboolean window_geom_load(const gchar *name, window_geometry_t *geom);
225 
226 /**
227  * Returns a list of recent capture filters.
228  *
229  * @param ifname interface name; NULL refers to the global list.
230  */
231 extern GList *recent_get_cfilter_list(const gchar *ifname);
232 
233 /**
234  * Add a capture filter to the global recent capture filter list or
235  * the recent capture filter list for an interface.
236  *
237  * @param ifname interface name; NULL refers to the global list.
238  * @param s text of capture filter
239  */
240 extern void recent_add_cfilter(const gchar *ifname, const gchar *s);
241 
242 /**
243  * Get the value of an entry for a remote host from the remote host list.
244  *
245  * @param host host name for the remote host.
246  *
247  * @return pointer to the entry for the remote host.
248  */
249 extern struct remote_host *recent_get_remote_host(const gchar *host);
250 
251 /**
252  * Get the number of entries of the remote host list.
253  *
254  * @return number of entries in the list.
255  */
256 extern int recent_get_remote_host_list_size(void);
257 
258 /**
259  * Iterate over all items in the remote host list, calling a
260  * function for each member
261  *
262  * @param func function to be called
263  * @param user_data argument to pass as user data to the function
264  */
265 extern void recent_remote_host_list_foreach(GHFunc func, gpointer user_data);
266 
267 /**
268  * Free all entries of the remote host list.
269  */
270 extern void recent_free_remote_host_list(void);
271 
272 /**
273  * Add an entry to the remote_host_list.
274  *
275  * @param host Key of the entry
276  * @param rh Value of the entry
277  */
278 extern void recent_add_remote_host(gchar *host, struct remote_host *rh);
279 
280 #ifdef __cplusplus
281 }
282 #endif /* __cplusplus */
283 
284 #endif /* recent.h */
285