### Bug Summary

File: | builds/wireshark/wireshark/ui/recent.c
Warning: | line 1828, column 13 Null pointer passed to 1st parameter expecting 'nonnull'

### Annotated Source Code

Press '?' to see keyboard shortcuts

Show analyzer invocation
clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name recent.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -ffloat16-excess-precision=fast -fbfloat16-excess-precision=fast -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/builds/wireshark/wireshark/build -fcoverage-compilation-dir=/builds/wireshark/wireshark/build -resource-dir /usr/lib/llvm-21/lib/clang/21 -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D WS_DEBUG -D WS_DEBUG_UTF_8 -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -I /builds/wireshark/wireshark/ui -I /builds/wireshark/wireshark/build/ui -I /builds/wireshark/wireshark/wiretap -D _GLIBCXX_ASSERTIONS -internal-isystem /usr/lib/llvm-21/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -Wno-format-nonliteral -std=gnu17 -ferror-limit 19 -fvisibility=hidden -fwrapv -fwrapv-pointer -fstrict-flex-arrays=3 -stack-protector 2 -fstack-clash-protection -fcf-protection=full -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fexceptions -fcolor-diagnostics -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /builds/wireshark/wireshark/sbout/2026-05-20-100323-3659-1 -x c /builds/wireshark/wireshark/ui/recent.c

Keyboard shortcuts:

- Use 'j/k' keys for keyboard navigation
- Use 'Shift+S' to show/hide relevant lines
- Use '?' to toggle this window

Close
Show only relevant lines Show control flow arrows

1 | /* recent.c
2 | * 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 | #include "config.h"
13 |
14 | #include <wireshark.h>
15 |
16 | #include <stdlib.h>
17 | #include <errno(*__errno_location ()).h>
18 |
19 | #include <app/application_flavor.h>
20 | #include <wsutil/filesystem.h>
21 | #include <epan/prefs.h>
22 | #include <epan/prefs-int.h>
23 | #include <epan/column.h>
24 | #include <wsutil/value_string.h>
25 |
26 | #ifdef HAVE_PCAP_REMOTE
27 | #include "ui/capture_opts.h"
28 | #endif
29 | #include "ui/util.h"
30 | #include "ui/recent.h"
31 | #include "ui/recent_utils.h"
32 | #include "ui/packet_list_utils.h"
33 | #include "ui/simple_dialog.h"
34 |
35 | #include <wsutil/file_util.h>
36 | #include <wsutil/strtoi.h>
37 |
38 | #define RECENT_KEY_MAIN_TOOLBAR_SHOW"gui.toolbar_main_show" "gui.toolbar_main_show"
39 | #define RECENT_KEY_FILTER_TOOLBAR_SHOW"gui.filter_toolbar_show" "gui.filter_toolbar_show"
40 | #define RECENT_KEY_WIRELESS_TOOLBAR_SHOW"gui.wireless_toolbar_show" "gui.wireless_toolbar_show"
41 | #define RECENT_KEY_PACKET_LIST_SHOW"gui.packet_list_show" "gui.packet_list_show"
42 | #define RECENT_KEY_TREE_VIEW_SHOW"gui.tree_view_show" "gui.tree_view_show"
43 | #define RECENT_KEY_BYTE_VIEW_SHOW"gui.byte_view_show" "gui.byte_view_show"
44 | #define RECENT_KEY_PACKET_DIAGRAM_SHOW"gui.packet_diagram_show" "gui.packet_diagram_show"
45 | #define RECENT_KEY_STATUSBAR_SHOW"gui.statusbar_show" "gui.statusbar_show"
46 | #define RECENT_KEY_PACKET_LIST_COLORIZE"gui.packet_list_colorize" "gui.packet_list_colorize"
47 | #define RECENT_KEY_CAPTURE_AUTO_SCROLL"capture.auto_scroll" "capture.auto_scroll"
48 | #define RECENT_KEY_AGGREGATION_VIEW"capture.aggregation_view" "capture.aggregation_view"
49 | #define RECENT_GUI_TIME_FORMAT"gui.time_format" "gui.time_format"
50 | #define RECENT_GUI_TIME_PRECISION"gui.time_precision" "gui.time_precision"
51 | #define RECENT_GUI_SECONDS_FORMAT"gui.seconds_format" "gui.seconds_format"
52 | #define RECENT_GUI_ZOOM_LEVEL"gui.zoom_level" "gui.zoom_level"
53 | #define RECENT_GUI_BYTES_VIEW"gui.bytes_view" "gui.bytes_view"
54 | #define RECENT_GUI_BYTES_ENCODING"gui.bytes_encoding" "gui.bytes_encoding"
55 | #define RECENT_GUI_ALLOW_HOVER_SELECTION"gui.allow_hover_selection" "gui.allow_hover_selection"
56 | #define RECENT_GUI_PACKET_DIAGRAM_FIELD_VALUES"gui.packet_diagram_field_values" "gui.packet_diagram_field_values"
57 | #define RECENT_GUI_GEOMETRY_MAIN_X"gui.geometry_main_x" "gui.geometry_main_x"
58 | #define RECENT_GUI_GEOMETRY_MAIN_Y"gui.geometry_main_y" "gui.geometry_main_y"
59 | #define RECENT_GUI_GEOMETRY_MAIN_WIDTH"gui.geometry_main_width" "gui.geometry_main_width"
60 | #define RECENT_GUI_GEOMETRY_MAIN_HEIGHT"gui.geometry_main_height" "gui.geometry_main_height"
61 | #define RECENT_GUI_GEOMETRY_MAIN_MAXIMIZED"gui.geometry_main_maximized" "gui.geometry_main_maximized"
62 | #define RECENT_GUI_GEOMETRY_MAIN"gui.geometry_main" "gui.geometry_main"
63 | #define RECENT_GUI_GEOMETRY_LEFTALIGN_ACTIONS"gui.geometry_leftalign_actions" "gui.geometry_leftalign_actions"
64 | #define RECENT_GUI_GEOMETRY_MAIN_UPPER_PANE"gui.geometry_main_upper_pane" "gui.geometry_main_upper_pane"
65 | #define RECENT_GUI_GEOMETRY_MAIN_LOWER_PANE"gui.geometry_main_lower_pane" "gui.geometry_main_lower_pane"
66 | #define RECENT_GUI_GEOMETRY_MAIN_MASTER_SPLIT"gui.geometry_main_master_split" "gui.geometry_main_master_split"
67 | #define RECENT_GUI_GEOMETRY_MAIN_EXTRA_SPLIT"gui.geometry_main_extra_split" "gui.geometry_main_extra_split"
68 | #define RECENT_LAST_USED_PROFILE"gui.last_used_profile" "gui.last_used_profile"
69 | #define RECENT_PROFILE_SWITCH_CHECK_COUNT"gui.profile_switch_check_count" "gui.profile_switch_check_count"
70 | #define RECENT_GUI_FILEOPEN_REMEMBERED_DIR"gui.fileopen_remembered_dir" "gui.fileopen_remembered_dir"
71 | #define RECENT_GUI_CONVERSATION_TABS"gui.conversation_tabs" "gui.conversation_tabs"
72 | #define RECENT_GUI_CONVERSATION_TABS_COLUMNS"gui.conversation_tabs_columns" "gui.conversation_tabs_columns"
73 | #define RECENT_GUI_ENDPOINT_TABS"gui.endpoint_tabs" "gui.endpoint_tabs"
74 | #define RECENT_GUI_ENDPOINT_TABS_COLUMNS"gui.endpoint_tabs_columns" "gui.endpoint_tabs_columns"
75 | #define RECENT_GUI_RLC_PDUS_FROM_MAC_FRAMES"gui.rlc_pdus_from_mac_frames" "gui.rlc_pdus_from_mac_frames"
76 | #define RECENT_GUI_CUSTOM_COLORS"gui.custom_colors" "gui.custom_colors"
77 | #define RECENT_GUI_TOOLBAR_SHOW"gui.additional_toolbar_show" "gui.additional_toolbar_show"
78 | #define RECENT_GUI_INTERFACE_TOOLBAR_SHOW"gui.interface_toolbar_show" "gui.interface_toolbar_show"
79 | #define RECENT_GUI_SEARCH_IN"gui.search_in" "gui.search_in"
80 | #define RECENT_GUI_SEARCH_CHAR_SET"gui.search_char_set" "gui.search_char_set"
81 | #define RECENT_GUI_SEARCH_CASE_SENSITIVE"gui.search_case_sensitive" "gui.search_case_sensitive"
82 | #define RECENT_GUI_SEARCH_REVERSE_DIR"gui.search_reverse_dir" "gui.search_reverse_dir"
83 | #define RECENT_GUI_SEARCH_MULTIPLE_OCCURS"gui.search_multiple_occurs" "gui.search_multiple_occurs"
84 | #define RECENT_GUI_SEARCH_TYPE"gui.search_type" "gui.search_type"
85 | #define RECENT_GUI_FOLLOW_SHOW"gui.follow_show" "gui.follow_show"
86 | #define RECENT_GUI_FOLLOW_DELTA"gui.follow_delta" "gui.follow_delta"
87 | #define RECENT_GUI_SHOW_BYTES_DECODE"gui.show_bytes_decode" "gui.show_bytes_decode"
88 | #define RECENT_GUI_SHOW_BYTES_SHOW"gui.show_bytes_show" "gui.show_bytes_show"
89 | #define RECENT_GUI_TSD_MA_WINDOW_SIZE"gui.tsd_ma_window_size" "gui.tsd_ma_window_size"
90 | #define RECENT_GUI_TSD_THROUGHPUT_SHOW"gui.tsd_throughput_show" "gui.tsd_throughput_show"
91 | #define RECENT_GUI_TSD_GOODPUT_SHOW"gui.tsd_goodput_show" "gui.tsd_goodput_show"
92 | #define RECENT_KEY_SIDEBAR_LEARN_VISIBLE"gui.welcome_page.sidebar.learn_visible" "gui.welcome_page.sidebar.learn_visible"
93 | #define RECENT_KEY_SIDEBAR_TIPS_VISIBLE"gui.welcome_page.sidebar.tips_visible" "gui.welcome_page.sidebar.tips_visible"
94 | #define RECENT_KEY_SIDEBAR_TIPS_EVENTS"gui.welcome_page.sidebar.tips_events" "gui.welcome_page.sidebar.tips_events"
95 | #define RECENT_KEY_SIDEBAR_TIPS_SPONSORSHIP"gui.welcome_page.sidebar.tips_sponsorship" "gui.welcome_page.sidebar.tips_sponsorship"
96 | #define RECENT_KEY_SIDEBAR_TIPS_TIPS"gui.welcome_page.sidebar.tips_tips" "gui.welcome_page.sidebar.tips_tips"
97 | #define RECENT_KEY_SIDEBAR_TIPS_AUTO_ADVANCE"gui.welcome_page.sidebar.tips_auto_advance" "gui.welcome_page.sidebar.tips_auto_advance"
98 | #define RECENT_KEY_SIDEBAR_TIPS_INTERVAL"gui.welcome_page.sidebar.tips_interval" "gui.welcome_page.sidebar.tips_interval"
99 | #define RECENT_KEY_SIDEBAR_TIPS_SLIDES_TEST"gui.welcome_page.sidebar.tips_slides_test" "gui.welcome_page.sidebar.tips_slides_test"
100 |
101 | #define RECENT_GUI_GEOMETRY"gui.geom." "gui.geom."
102 |
103 | #define RECENT_KEY_PRIVS_WARN_IF_ELEVATED"privs.warn_if_elevated" "privs.warn_if_elevated"
104 | #define RECENT_KEY_SYS_WARN_IF_NO_CAPTURE"sys.warn_if_no_capture" "sys.warn_if_no_capture"
105 |
106 | #define RECENT_FILE_NAME"recent" "recent"
107 | #define RECENT_COMMON_FILE_NAME"recent_common" "recent_common"
108 |
109 | recent_settings_t recent;
110 |
111 | static const value_string ts_type_values[] = {
112 | { TS_RELATIVE, "RELATIVE" },
113 | { TS_RELATIVE_CAP, "RELATIVE_CAP" },
114 | { TS_ABSOLUTE, "ABSOLUTE" },
115 | { TS_ABSOLUTE_WITH_YMD, "ABSOLUTE_WITH_YMD" },
116 | { TS_ABSOLUTE_WITH_YDOY, "ABSOLUTE_WITH_YDOY" },
117 | { TS_ABSOLUTE_WITH_YMD, "ABSOLUTE_WITH_DATE" }, /* Backward compatibility */
118 | { TS_DELTA, "DELTA" },
119 | { TS_DELTA_DIS, "DELTA_DIS" },
120 | { TS_EPOCH, "EPOCH" },
121 | { TS_UTC, "UTC" },
122 | { TS_UTC_WITH_YMD, "UTC_WITH_YMD" },
123 | { TS_UTC_WITH_YDOY, "UTC_WITH_YDOY" },
124 | { TS_UTC_WITH_YMD, "UTC_WITH_DATE" }, /* Backward compatibility */
125 | { 0, NULL((void*)0) }
126 | };
127 |
128 | /*
129 | * NOTE: all values other than TS_PREC_AUTO are the number of digits
130 | * of precision.
131 | *
132 | * We continue to use the old names for values where they may have
133 | * been written to the recent file by previous releases. For other
134 | * values, we just write it out numerically.
135 | */
136 | static const value_string ts_precision_values[] = {
137 | { TS_PREC_AUTO, "AUTO" },
138 | { TS_PREC_FIXED_SEC, "SEC" },
139 | { TS_PREC_FIXED_100_MSEC, "DSEC" },
140 | { TS_PREC_FIXED_10_MSEC, "CSEC" },
141 | { TS_PREC_FIXED_MSEC, "MSEC" },
142 | { TS_PREC_FIXED_USEC, "USEC" },
143 | { TS_PREC_FIXED_NSEC, "NSEC" },
144 | { 0, NULL((void*)0) }
145 | };
146 |
147 | static const value_string ts_seconds_values[] = {
148 | { TS_SECONDS_DEFAULT, "SECONDS" },
149 | { TS_SECONDS_HOUR_MIN_SEC, "HOUR_MIN_SEC" },
150 | { 0, NULL((void*)0) }
151 | };
152 |
153 | static const value_string bytes_view_type_values[] = {
154 | { BYTES_HEX, "HEX" },
155 | { BYTES_BITS, "BITS" },
156 | { BYTES_DEC, "DEC" },
157 | { BYTES_OCT, "OCT" },
158 | { 0, NULL((void*)0) }
159 | };
160 |
161 | static const value_string bytes_encoding_type_values[] = {
162 | { BYTES_ENC_FROM_PACKET, "FROM_PACKET" },
163 | { BYTES_ENC_ASCII, "ASCII" },
164 | { BYTES_ENC_EBCDIC, "EBCDIC" },
165 | { 0, NULL((void*)0) }
166 | };
167 |
168 | static const value_string search_in_values[] = {
169 | { SEARCH_IN_PACKET_LIST, "PACKET_LIST" },
170 | { SEARCH_IN_PACKET_DETAILS, "PACKET_DETAILS" },
171 | { SEARCH_IN_PACKET_BYTES, "PACKET_BYTES" },
172 | { 0, NULL((void*)0) }
173 | };
174 |
175 | static const value_string search_char_set_values[] = {
176 | { SEARCH_CHAR_SET_NARROW_AND_WIDE, "NARROW_AND_WIDE" },
177 | { SEARCH_CHAR_SET_NARROW, "NARROW" },
178 | { SEARCH_CHAR_SET_WIDE, "WIDE" },
179 | { 0, NULL((void*)0) }
180 | };
181 |
182 | static const value_string search_type_values[] = {
183 | { SEARCH_TYPE_DISPLAY_FILTER, "DISPLAY_FILTER" },
184 | { SEARCH_TYPE_HEX_VALUE, "HEX_VALUE" },
185 | { SEARCH_TYPE_STRING, "STRING" },
186 | { SEARCH_TYPE_REGEX, "REGEX" },
187 | { 0, NULL((void*)0) }
188 | };
189 |
190 | static const value_string bytes_show_values[] = {
191 | { SHOW_ASCII, "ASCII" },
192 | { SHOW_ASCII_CONTROL, "ASCII_CONTROL" },
193 | { SHOW_CARRAY, "C_ARRAYS" },
194 | { SHOW_EBCDIC, "EBCDIC" },
195 | { SHOW_HEXDUMP, "HEX_DUMP" },
196 | { SHOW_HTML, "HTML" },
197 | { SHOW_IMAGE, "IMAGE" },
198 | { SHOW_JSON, "JSON" },
199 | { SHOW_RAW, "RAW" },
200 | { SHOW_RUSTARRAY, "RUST_ARRAY" },
201 | { SHOW_CODEC, "UTF-8" },
202 | // Other codecs are generated at runtime
203 | { SHOW_YAML, "YAML"},
204 | { 0, NULL((void*)0) }
205 | };
206 |
207 | static const value_string follow_delta_values[] = {
208 | { FOLLOW_DELTA_NONE, "NONE" },
209 | { FOLLOW_DELTA_TURN, "TURN" },
210 | { FOLLOW_DELTA_ALL, "ALL" },
211 | { 0, NULL((void*)0) }
212 | };
213 |
214 | static const value_string show_bytes_decode_values[] = {
215 | { DecodeAsNone, "NONE" },
216 | { DecodeAsBASE64, "BASE64" },
217 | { DecodeAsCompressed, "COMPRESSED" },
218 | { DecodeAsHexDigits, "HEX_DIGITS" },
219 | { DecodeAsPercentEncoding, "PERCENT_ENCODING" },
220 | { DecodeAsQuotedPrintable, "QUOTED_PRINTABLE" },
221 | { DecodeAsROT13, "ROT13"},
222 | { 0, NULL((void*)0) }
223 | };
224 |
225 | static void
226 | free_col_width_data(void *data)
227 | {
228 | col_width_data *cfmt = (col_width_data *)data;
229 | g_free(cfmt);
230 | }
231 |
232 | void
233 | recent_free_column_width_info(recent_settings_t *rs)
234 | {
235 | g_list_free_full(rs->col_width_list, free_col_width_data);
236 | rs->col_width_list = NULL((void*)0);
237 | }
238 |
239 | /** Write the geometry values of a single window to the recent file.
240 | *
241 | * @param key unused
242 | * @param value the geometry values
243 | * @param rfh recent file handle (FILE)
244 | */
245 | static void
246 | write_recent_geom(void *key _U___attribute__((unused)), void *value, void *rfh)
247 | {
248 | window_geometry_t *geom = (window_geometry_t *)value;
249 | FILE *rf = (FILE *)rfh;
250 |
251 | fprintf(rf, "\n# Geometry and maximized state of %s window.\n", geom->key);
252 | fprintf(rf, "# Decimal integers.\n");
253 | fprintf(rf, RECENT_GUI_GEOMETRY"gui.geom." "%s.x: %d\n", geom->key, geom->x);
254 | fprintf(rf, RECENT_GUI_GEOMETRY"gui.geom." "%s.y: %d\n", geom->key, geom->y);
255 | fprintf(rf, RECENT_GUI_GEOMETRY"gui.geom." "%s.width: %d\n", geom->key,
256 | geom->width);
257 | fprintf(rf, RECENT_GUI_GEOMETRY"gui.geom." "%s.height: %d\n", geom->key,
258 | geom->height);
259 |
260 | fprintf(rf, "# true or false (case-insensitive).\n");
261 | fprintf(rf, RECENT_GUI_GEOMETRY"gui.geom." "%s.maximized: %s\n", geom->key,
262 | geom->maximized == true1 ? "true" : "false");
263 |
264 | fprintf(rf, "# Qt Geometry State (hex byte string).\n");
265 | fprintf(rf, RECENT_GUI_GEOMETRY"gui.geom." "%s.qt_geometry: %s\n", geom->key,
266 | geom->qt_geom);
267 | }
268 |
269 | /* the geometry hashtable for all known window classes,
270 | * the window name is the key, and the geometry struct is the value */
271 | static GHashTable *window_geom_hash;
272 |
273 | static GHashTable *window_splitter_hash;
274 |
275 | void
276 | window_geom_free(void *data)
277 | {
278 | window_geometry_t *geom = (window_geometry_t*)data;
279 | g_free(geom->key);
280 | g_free(geom->qt_geom);
281 | g_free(geom);
282 | }
283 |
284 | /* save the window and its current geometry into the geometry hashtable */
285 | void
286 | window_geom_save(const char *name, window_geometry_t *geom)
287 | {
288 | char *key;
289 | window_geometry_t *work;
290 |
291 | /* init hashtable, if not already done */
292 | if (!window_geom_hash) {
293 | window_geom_hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL((void*)0), window_geom_free);
294 | }
295 |
296 | /* g_malloc and insert the new one */
297 | work = g_new(window_geometry_t, 1)((window_geometry_t *) g_malloc_n ((1), sizeof (window_geometry_t )));
298 | *work = *geom;
299 | key = g_strdup(name)g_strdup_inline (name);
300 | work->key = key;
301 | g_hash_table_replace(window_geom_hash, key, work);
302 | }
303 |
304 | /* load the desired geometry for this window from the geometry hashtable */
305 | bool_Bool
306 | window_geom_load(const char *name,
307 | window_geometry_t *geom)
308 | {
309 | window_geometry_t *p;
310 |
311 | /* init hashtable, if not already done */
312 | if (!window_geom_hash) {
313 | window_geom_hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL((void*)0), window_geom_free);
314 | }
315 |
316 | p = (window_geometry_t *)g_hash_table_lookup(window_geom_hash, name);
317 | if (p) {
318 | *geom = *p;
319 | return true1;
320 | } else {
321 | return false0;
322 | }
323 | }
324 |
325 | /* save the window and its splitter state into the splitter hashtable */
326 | void
327 | window_splitter_save(const char *name, const char *splitter_state)
328 | {
329 | /* init hashtable, if not already done */
330 | if (!window_splitter_hash) {
331 | window_splitter_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
332 | }
333 |
334 | g_hash_table_replace(window_splitter_hash, g_strdup(name)g_strdup_inline (name), g_strdup(splitter_state)g_strdup_inline (splitter_state));
335 | }
336 |
337 | /* save the window and its splitter state into the geometry hashtable */
338 | const char*
339 | window_splitter_load(const char *name)
340 | {
341 | /* init hashtable, if not already done */
342 | if (!window_splitter_hash) {
343 | return NULL((void*)0);
344 | }
345 |
346 | return g_hash_table_lookup(window_splitter_hash, name);
347 | }
348 |
349 |
350 | /* parse values of particular types */
351 | static void
352 | parse_recent_boolean(const char *val_str, bool_Bool *valuep)
353 | {
354 | if (g_ascii_strcasecmp(val_str, "true") == 0) {
355 | *valuep = true1;
356 | }
357 | else {
358 | *valuep = false0;
359 | }
360 | }
361 |
362 | /** Read in a single geometry key value pair from the recent file.
363 | *
364 | * @param name the geom_name of the window
365 | * @param key the subkey of this pair (e.g. "x")
366 | * @param value the new value (e.g. "123")
367 | */
368 | static void
369 | window_geom_recent_read_pair(const char *name,
370 | const char *key,
371 | const char *value)
372 | {
373 | window_geometry_t geom;
374 |
375 | if (strcmp(key, "splitter") == 0) {
376 | window_splitter_save(name, value);
377 | return;
378 | }
379 |
380 | /* find window geometry maybe already in hashtable */
381 | if (!window_geom_load(name, &geom)) {
382 | /* not in table, init geom with "basic" values */
383 | geom.key = NULL((void*)0); /* Will be set in window_geom_save() */
384 | geom.set_pos = false0;
385 | geom.x = -1;
386 | geom.y = -1;
387 | geom.set_size = false0;
388 | geom.width = -1;
389 | geom.height = -1;
390 | geom.qt_geom = NULL((void*)0);
391 | }
392 |
393 | if (strcmp(key, "x") == 0) {
394 | geom.x = (int)strtol(value, NULL((void*)0), 10);
395 | geom.set_pos = true1;
396 | } else if (strcmp(key, "y") == 0) {
397 | geom.y = (int)strtol(value, NULL((void*)0), 10);
398 | geom.set_pos = true1;
399 | } else if (strcmp(key, "width") == 0) {
400 | geom.width = (int)strtol(value, NULL((void*)0), 10);
401 | geom.set_size = true1;
402 | } else if (strcmp(key, "height") == 0) {
403 | geom.height = (int)strtol(value, NULL((void*)0), 10);
404 | geom.set_size = true1;
405 | } else if (strcmp(key, "maximized") == 0) {
406 | parse_recent_boolean(value, &geom.maximized);
407 | geom.set_maximized = true1;
408 | } else if (strcmp(key, "qt_geometry") == 0) {
409 | geom.qt_geom = g_strdup(value)g_strdup_inline (value);
410 | } else {
411 | /*
412 | * Silently ignore the bogus key. We shouldn't abort here,
413 | * as this could be due to a corrupt recent file.
414 | *
415 | * XXX - should we print a message about this?
416 | */
417 | return;
418 | }
419 |
420 | /* save / replace geometry in hashtable */
421 | window_geom_save(name, &geom);
422 | }
423 |
424 | /** Write all geometry values of all windows to the recent file.
425 | * Will call write_recent_geom() for every existing window type.
426 | *
427 | * @param rf recent file handle from caller
428 | */
429 | static void
430 | window_geom_recent_write_all(FILE *rf)
431 | {
432 | /* init hashtable, if not already done */
433 | if (!window_geom_hash) {
434 | window_geom_hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL((void*)0), window_geom_free);
435 | }
436 |
437 | g_hash_table_foreach(window_geom_hash, write_recent_geom, rf);
438 | }
439 |
440 | /** Write all known window splitter states to the recent file.
441 | *
442 | * @param rf recent file handle from caller
443 | */
444 | static void
445 | window_splitter_recent_write_all(FILE *rf)
446 | {
447 | /* init hashtable, if not already done */
448 | if (!window_splitter_hash) {
449 | return;
450 | }
451 |
452 | GHashTableIter iter;
453 | void *key, *value;
454 | g_hash_table_iter_init(&iter, window_splitter_hash);
455 | while (g_hash_table_iter_next(&iter, &key, &value)) {
456 | fprintf(rf, "\n# Splitter state of %s window.\n", (char*)key);
457 | fprintf(rf, "# Qt Splitter state (hex byte string).\n");
458 | fprintf(rf, RECENT_GUI_GEOMETRY"gui.geom." "%s.splitter: %s\n", (char*)key,
459 | (char*)value);
460 | }
461 | }
462 |
463 | /* Global list of recent capture filters. */
464 | static GList *recent_cfilter_list;
465 |
466 | /*
467 | * Per-interface lists of recent capture filters; stored in a hash
468 | * table indexed by interface name.
469 | */
470 | static GHashTable *per_interface_cfilter_lists_hash;
471 |
472 | /* XXX: use a preference for this setting! */
473 | /* N.B.: If we use a pref, we will read the recent_common file
474 | * before the pref, so don't truncate the list when reading
475 | * (see the similar #16782 for the recent files.)
476 | */
477 | static unsigned cfilter_combo_max_recent = 20;
478 |
479 | /**
480 | * Returns a list of recent capture filters.
481 | *
482 | * @param ifname interface name; NULL refers to the global list.
483 | */
484 | GList *
485 | recent_get_cfilter_list(const char *ifname)
486 | {
487 | if (ifname == NULL((void*)0))
488 | return recent_cfilter_list;
489 | if (per_interface_cfilter_lists_hash == NULL((void*)0)) {
490 | /* No such lists exist. */
491 | return NULL((void*)0);
492 | }
493 | return (GList *)g_hash_table_lookup(per_interface_cfilter_lists_hash, ifname);
494 | }
495 |
496 | /**
497 | * Add a capture filter to the global recent capture filter list or
498 | * the recent capture filter list for an interface.
499 | *
500 | * @param ifname interface name; NULL refers to the global list.
501 | * @param s text of capture filter
502 | */
503 | void
504 | recent_add_cfilter(const char *ifname, const char *s)
505 | {
506 | GList *cfilter_list;
507 | GList *li;
508 | char *li_filter, *newfilter = NULL((void*)0);
509 |
510 | /* Don't add empty filters to the list. */
511 | if (s[0] == '\0')
512 | return;
513 |
514 | if (ifname == NULL((void*)0))
515 | cfilter_list = recent_cfilter_list;
516 | else {
517 | /* If we don't yet have a hash table for per-interface recent
518 | capture filter lists, create one. Have it free the new key
519 | if we're updating an entry rather than creating it below. */
520 | if (per_interface_cfilter_lists_hash == NULL((void*)0))
521 | per_interface_cfilter_lists_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL((void*)0));
522 | cfilter_list = (GList *)g_hash_table_lookup(per_interface_cfilter_lists_hash, ifname);
523 | }
524 |
525 | li = g_list_first(cfilter_list);
526 | while (li) {
527 | /* If the filter is already in the list, remove the old one and
528 | * append the new one at the latest position (at g_list_append() below) */
529 | li_filter = (char *)li->data;
530 | if (strcmp(s, li_filter) == 0) {
531 | /* No need to copy the string, we're just moving it. */
532 | newfilter = li_filter;
533 | cfilter_list = g_list_remove(cfilter_list, li->data);
534 | break;
535 | }
536 | li = li->next;
537 | }
538 | if (newfilter == NULL((void*)0)) {
539 | /* The filter wasn't already in the list; make a copy to add. */
540 | newfilter = g_strdup(s)g_strdup_inline (s);
541 | }
542 | cfilter_list = g_list_prepend(cfilter_list, newfilter);
543 |
544 | if (ifname == NULL((void*)0))
545 | recent_cfilter_list = cfilter_list;
546 | else
547 | g_hash_table_insert(per_interface_cfilter_lists_hash, g_strdup(ifname)g_strdup_inline (ifname), cfilter_list);
548 | }
549 |
550 | #ifdef HAVE_PCAP_REMOTE
551 | /* XXX: use a preference for this setting! */
552 | /* N.B.: If we use a pref, we will read the recent_common file
553 | * before the pref, so don't truncate the list when reading
554 | * (see the similar #16782 for the recent files.)
555 | */
556 | static unsigned remote_host_max_recent = 20;
557 | static GList *remote_host_list;
558 |
559 | int recent_get_remote_host_list_size(void)
560 | {
561 | if (remote_host_list == NULL((void*)0)) {
562 | /* No entries exist. */
563 | return 0;
564 | }
565 | return g_list_length(remote_host_list);
566 | }
567 |
568 | static void
569 | free_remote_host(void *value)
570 | {
571 | struct remote_host* rh = (struct remote_host*)value;
572 |
573 | g_free(rh->r_host);
574 | g_free(rh->remote_port);
575 | g_free(rh->auth_username);
576 | g_free(rh->auth_password);
577 |
578 | }
579 |
580 | static int
581 | remote_host_compare(const void *a, const void *b)
582 | {
583 | const struct remote_host* rh_a = (const struct remote_host*)a;
584 | const struct remote_host* rh_b = (const struct remote_host*)b;
585 |
586 | /* We assume only one entry per host (the GUI assumes that too.) */
587 | return g_strcmp0(rh_a->r_host, rh_b->r_host);
588 | }
589 |
590 | static void
591 | remote_host_reverse(void)
592 | {
593 | if (remote_host_list) {
594 | remote_host_list = g_list_reverse(remote_host_list);
595 | }
596 | }
597 |
598 | void recent_add_remote_host(char *host _U___attribute__((unused)), struct remote_host *rh)
599 | {
600 | GList* li = NULL((void*)0);
601 | if (remote_host_list) {
602 | li = g_list_find_custom(remote_host_list, rh, remote_host_compare);
603 | if (li != NULL((void*)0)) {
604 | free_remote_host(li->data);
605 | remote_host_list = g_list_delete_link(remote_host_list, li);
606 | }
607 | }
608 | remote_host_list = g_list_prepend(remote_host_list, rh);
609 | }
610 |
611 | void
612 | recent_remote_host_list_foreach(GFunc func, void *user_data)
613 | {
614 | if (remote_host_list != NULL((void*)0)) {
615 | g_list_foreach(remote_host_list, func, user_data);
616 | }
617 | }
618 |
619 | static void
620 | recent_print_remote_host(void *value, void *user)
621 | {
622 | FILE *rf = (FILE *)user;
623 | struct remote_host_info *ri = (struct remote_host_info *)value;
624 |
625 | fprintf (rf, RECENT_KEY_REMOTE_HOST"recent.remote_host" ": %s,%s,%d\n", ri->remote_host, ri->remote_port, ri->auth_type);
626 | }
627 |
628 | /**
629 | * Write the contents of the remote_host_list to the 'recent' file.
630 | *
631 | * @param rf File to write to.
632 | */
633 | static void
634 | capture_remote_combo_recent_write_all(FILE *rf)
635 | {
636 | unsigned max_count = 0;
637 | GList *li = g_list_first(remote_host_list);
638 |
639 | /* write all non empty remote capture hosts to the recent file (until max count) */
640 | while (li && (max_count++ <= remote_host_max_recent)) {
641 | recent_print_remote_host(li->data, rf);
642 | li = li->next;
643 | }
644 | }
645 |
646 |
647 | void recent_free_remote_host_list(void)
648 | {
649 | g_list_free_full(remote_host_list, free_remote_host);
650 | remote_host_list = NULL((void*)0);
651 | }
652 |
653 | struct remote_host *
654 | recent_get_remote_host(const char *host)
655 | {
656 | if (host == NULL((void*)0))
657 | return NULL((void*)0);
658 | for (GList* li = g_list_first(remote_host_list); li != NULL((void*)0); li = li->next) {
659 | struct remote_host *rh = (struct remote_host*)li->data;
660 | if (g_strcmp0(host, rh->r_host) == 0) {
661 | return rh;
662 | }
663 | }
664 | return NULL((void*)0);
665 | }
666 |
667 | /**
668 | * Fill the remote_host_list with the entries stored in the 'recent' file.
669 | *
670 | * @param s String to be filled from the 'recent' file.
671 | * @return True, if the list was written successfully, False otherwise.
672 | */
673 | static bool_Bool
674 | capture_remote_combo_add_recent(const char *s)
675 | {
676 | GList *vals = prefs_get_string_list (s);
677 | GList *valp = vals;
678 | capture_auth auth_type;
679 | char *p;
680 | struct remote_host *rh;
681 |
682 | if (valp == NULL((void*)0))
683 | return false0;
684 |
685 | /* First value is the host */
686 | if (recent_get_remote_host(valp->data)) {
687 | /* Don't add it, it's already in the list (shouldn't happen). */
688 | return false0; // Should this be true or false?
689 | }
690 | rh = (struct remote_host *) g_malloc (sizeof (*rh));
691 |
692 | /* First value is the host */
693 | rh->r_host = (char *)g_strdup ((const char *)valp->data)g_strdup_inline ((const char *)valp->data);
694 | if (strlen(rh->r_host) == 0) {
695 | /* Empty remote host */
696 | g_free(rh->r_host);
697 | g_free(rh);
698 | return false0;
699 | }
700 | rh->auth_type = CAPTURE_AUTH_NULL;
701 | valp = valp->next;
702 |
703 | if (valp) {
704 | /* Found value 2, this is the port number */
705 | if (!strcmp((const char*)valp->data, "0")) {
706 | /* Port 0 isn't valid, so leave port blank */
707 | rh->remote_port = (char *)g_strdup ("")g_strdup_inline ("");
708 | } else {
709 | rh->remote_port = (char *)g_strdup ((const char *)valp->data)g_strdup_inline ((const char *)valp->data);
710 | }
711 | valp = valp->next;
712 | } else {
713 | /* Did not find a port number */
714 | rh->remote_port = g_strdup ("")g_strdup_inline ("");
715 | }
716 |
717 | if (valp) {
718 | /* Found value 3, this is the authentication type */
719 | auth_type = (capture_auth)strtol((const char *)valp->data, &p, 0);
720 | if (p != valp->data && *p == '\0') {
721 | rh->auth_type = auth_type;
722 | }
723 | }
724 |
725 | /* Do not store username and password */
726 | rh->auth_username = g_strdup ("")g_strdup_inline ("");
727 | rh->auth_password = g_strdup ("")g_strdup_inline ("");
728 |
729 | prefs_clear_string_list(vals);
730 |
731 | remote_host_list = g_list_prepend(remote_host_list, rh);
732 | return true1;
733 | }
734 | #endif
735 |
736 | static void
737 | cfilter_recent_write_all_list(FILE *rf, const char *ifname, GList *cfilter_list)
738 | {
739 | unsigned max_count = 0;
740 | GList *li;
741 | char *sanitized;
742 |
743 | /* write all non empty capture filter strings to the recent file (until max count) */
744 | li = g_list_first(cfilter_list);
745 | while (li && (max_count++ <= cfilter_combo_max_recent) ) {
746 | if (li->data && strlen((const char *)li->data)) {
747 | sanitized = prefs_sanitize_string((char *)li->data);
748 | if (ifname == NULL((void*)0))
749 | fprintf (rf, RECENT_KEY_CAPTURE_FILTER"recent.capture_filter" ": %s\n", sanitized);
750 | else
751 | fprintf (rf, RECENT_KEY_CAPTURE_FILTER"recent.capture_filter" ".%s: %s\n", ifname, sanitized);
752 | g_free(sanitized);
753 | }
754 | li = li->next;
755 | }
756 | }
757 |
758 | static void
759 | cfilter_recent_write_all_hash_callback(void *key, void *value, void *user_data)
760 | {
761 | cfilter_recent_write_all_list((FILE *)user_data, (const char *)key, (GList *)value);
762 | }
763 |
764 | /** Write all capture filter values to the recent file.
765 | *
766 | * @param rf recent file handle from caller
767 | */
768 | static void
769 | cfilter_recent_write_all(FILE *rf)
770 | {
771 | /* Write out the global list. */
772 | cfilter_recent_write_all_list(rf, NULL((void*)0), recent_cfilter_list);
773 |
774 | /* Write out all the per-interface lists. */
775 | if (per_interface_cfilter_lists_hash != NULL((void*)0)) {
776 | g_hash_table_foreach(per_interface_cfilter_lists_hash, cfilter_recent_write_all_hash_callback, (void *)rf);
777 | }
778 | }
779 |
780 | /** Reverse the order of all the capture filter lists after
781 | * reading recent_common (we want the latest first).
782 | * Note this is O(N), whereas appending N items to a GList is O(N^2),
783 | * since it doesn't have a pointer to the end like a GQueue.
784 | */
785 | static void
786 | cfilter_recent_reverse_all(void)
787 | {
788 | recent_cfilter_list = g_list_reverse(recent_cfilter_list);
789 |
790 | /* Reverse all the per-interface lists. */
791 | if (per_interface_cfilter_lists_hash != NULL((void*)0)) {
792 | GHashTableIter iter;
793 | void *key, *value;
794 | g_hash_table_iter_init(&iter, per_interface_cfilter_lists_hash);
795 | GList *li;
796 | while (g_hash_table_iter_next(&iter, &key, &value)) {
797 | li = (GList *)value;
798 | li = g_list_reverse(li);
799 | /* per_interface_cfilter_lists_hash was created without a
800 | * value_destroy_func, so this is fine.
801 | */
802 | g_hash_table_iter_replace(&iter, li);
803 | }
804 | }
805 | }
806 |
807 | /* Write out recent settings of particular types. */
808 | static void
809 | write_recent_boolean(FILE *rf, const char *description, const char *name,
810 | bool_Bool value)
811 | {
812 | fprintf(rf, "\n# %s.\n", description);
813 | fprintf(rf, "# true or false (case-insensitive).\n");
814 | fprintf(rf, "%s: %s\n", name, value == true1 ? "true" : "false");
815 | }
816 |
817 | static void
818 | write_recent_double(FILE *rf, const char *description, const char *name,
819 | double value)
820 | {
821 | fprintf(rf, "\n# %s.\n", description);
822 | char buf[G_ASCII_DTOSTR_BUF_SIZE(29 + 10)];
823 | fprintf(rf, "%s: %s\n", name, g_ascii_dtostr(buf, sizeof(buf), value));
824 | }
825 |
826 | static void
827 | write_recent_enum(FILE *rf, const char *description, const char *name,
828 | const value_string *values, unsigned value)
829 | {
830 | const char *if_invalid = NULL((void*)0);
831 | const value_string *valp;
832 | const char *str_value;
833 |
834 | fprintf(rf, "\n# %s.\n", description);
835 | fprintf(rf, "# One of: ");
836 | valp = values;
837 | while (valp->strptr != NULL((void*)0)) {
838 | if (if_invalid == NULL((void*)0))
839 | if_invalid = valp->strptr;
840 | fprintf(rf, "%s", valp->strptr);
841 | valp++;
842 | if (valp->strptr != NULL((void*)0))
843 | fprintf(rf, ", ");
844 | }
845 | fprintf(rf, "\n");
846 | str_value = try_val_to_str(value, values);
847 | if (str_value != NULL((void*)0))
848 | fprintf(rf, "%s: %s\n", name, str_value);
849 | else
850 | fprintf(rf, "%s: %s\n", name, if_invalid != NULL((void*)0) ? if_invalid : "Unknown");
851 | }
852 |
853 | /* Attempt to write out "recent common" to the user's recent_common file.
854 | If we got an error report it with a dialog box and return false,
855 | otherwise return true. */
856 | bool_Bool
857 | write_recent(void)
858 | {
859 | char *pf_dir_path;
860 | char *rf_path;
861 | FILE *rf;
862 | char *string_list;
863 |
864 | /* To do:
865 | * - Split output lines longer than MAX_VAL_LEN
866 | * - Create a function for the preference directory check/creation
867 | * so that duplication can be avoided with filter.c
868 | */
869 |
870 | /* Create the directory that holds personal configuration files, if
871 | necessary. */
872 | if (create_persconffile_dir(application_configuration_environment_prefix(), &pf_dir_path) == -1) {
873 | simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK0x01,
874 | "Can't create directory\n\"%s\"\nfor recent file: %s.", pf_dir_path,
875 | g_strerror(errno(*__errno_location ())));
876 | g_free(pf_dir_path);
877 | return false0;
878 | }
879 |
880 | rf_path = get_persconffile_path(RECENT_COMMON_FILE_NAME"recent_common", false0, application_configuration_environment_prefix());
881 | if ((rf = ws_fopenfopen(rf_path, "w")) == NULL((void*)0)) {
882 | simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK0x01,
883 | "Can't open recent file\n\"%s\": %s.", rf_path,
884 | g_strerror(errno(*__errno_location ())));
885 | g_free(rf_path);
886 | return false0;
887 | }
888 | g_free(rf_path);
889 |
890 | fprintf(rf, "# Common recent settings file for %s " VERSION"4.7.0" ".\n"
891 | "#\n"
892 | "# This file is regenerated each time %s is quit\n"
893 | "# and when changing configuration profile.\n"
894 | "# So be careful, if you want to make manual changes here.\n"
895 | "\n"
896 | "######## Recent capture files (latest last), cannot be altered through command line ########\n"
897 | "\n",
898 | application_flavor_name_proper(), application_flavor_name_proper());
899 |
900 |
901 | menu_recent_file_write_all(rf);
902 |
903 | fputs("\n"
904 | "######## Recent capture filters (latest first), cannot be altered through command line ########\n"
905 | "\n", rf);
906 |
907 | cfilter_recent_write_all(rf);
908 |
909 | fputs("\n"
910 | "######## Recent display filters (latest last), cannot be altered through command line ########\n"
911 | "\n", rf);
912 |
913 | dfilter_recent_combo_write_all(rf);
914 |
915 | #ifdef HAVE_PCAP_REMOTE
916 | fputs("\n"
917 | "######## Recent remote hosts (latest first), cannot be altered through command line ########\n"
918 | "\n", rf);
919 |
920 | capture_remote_combo_recent_write_all(rf);
921 | #endif
922 |
923 | fprintf(rf, "\n# Main window geometry.\n");
924 | fprintf(rf, "# Decimal numbers.\n");
925 | fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_X"gui.geometry_main_x" ": %d\n", recent.gui_geometry_main_x);
926 | fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_Y"gui.geometry_main_y" ": %d\n", recent.gui_geometry_main_y);
927 | fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_WIDTH"gui.geometry_main_width" ": %d\n",
928 | recent.gui_geometry_main_width);
929 | fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_HEIGHT"gui.geometry_main_height" ": %d\n",
930 | recent.gui_geometry_main_height);
931 |
932 | write_recent_boolean(rf, "Main window maximized",
933 | RECENT_GUI_GEOMETRY_MAIN_MAXIMIZED"gui.geometry_main_maximized",
934 | recent.gui_geometry_main_maximized);
935 |
936 | if (recent.gui_geometry_main != NULL((void*)0)) {
937 | fprintf(rf, "\n# Main window geometry state.\n");
938 | fprintf(rf, "# Hex byte string.\n");
939 | fprintf(rf, RECENT_GUI_GEOMETRY_MAIN"gui.geometry_main" ": %s\n",
940 | recent.gui_geometry_main);
941 | }
942 |
943 | write_recent_boolean(rf, "Leftalign Action Buttons",
944 | RECENT_GUI_GEOMETRY_LEFTALIGN_ACTIONS"gui.geometry_leftalign_actions",
945 | recent.gui_geometry_leftalign_actions);
946 |
947 | fprintf(rf, "\n# Last used Configuration Profile.\n");
948 | fprintf(rf, RECENT_LAST_USED_PROFILE"gui.last_used_profile" ": %s\n", get_profile_name());
949 |
950 | fprintf(rf, "\n# Number of packets or events to check for automatic profile switching.\n");
951 | fprintf(rf, "# Decimal number. Zero disables switching.\n");
952 | const char * def_prefix = recent.gui_profile_switch_check_count == 1000 ? "#" : "";
953 | fprintf(rf, "%s" RECENT_PROFILE_SWITCH_CHECK_COUNT"gui.profile_switch_check_count" ": %d\n", def_prefix,
954 | recent.gui_profile_switch_check_count);
955 |
956 | write_recent_boolean(rf, "Warn if running with elevated permissions (e.g. as root)",
957 | RECENT_KEY_PRIVS_WARN_IF_ELEVATED"privs.warn_if_elevated",
958 | recent.privs_warn_if_elevated);
959 |
960 | write_recent_boolean(rf, "Warn if Wireshark is unable to capture",
961 | RECENT_KEY_SYS_WARN_IF_NO_CAPTURE"sys.warn_if_no_capture",
962 | recent.sys_warn_if_no_capture);
963 |
964 | write_recent_enum(rf, "Find packet search in", RECENT_GUI_SEARCH_IN"gui.search_in", search_in_values,
965 | recent.gui_search_in);
966 | write_recent_enum(rf, "Find packet character set", RECENT_GUI_SEARCH_CHAR_SET"gui.search_char_set", search_char_set_values,
967 | recent.gui_search_char_set);
968 | write_recent_boolean(rf, "Find packet case sensitive search",
969 | RECENT_GUI_SEARCH_CASE_SENSITIVE"gui.search_case_sensitive",
970 | recent.gui_search_case_sensitive);
971 | write_recent_boolean(rf, "Find packet search reverse direction",
972 | RECENT_GUI_SEARCH_REVERSE_DIR"gui.search_reverse_dir",
973 | recent.gui_search_reverse_dir);
974 | write_recent_boolean(rf, "Find packet search multiple occurrences",
975 | RECENT_GUI_SEARCH_MULTIPLE_OCCURS"gui.search_multiple_occurs",
976 | recent.gui_search_multiple_occurs);
977 | write_recent_enum(rf, "Find packet search type", RECENT_GUI_SEARCH_TYPE"gui.search_type", search_type_values,
978 | recent.gui_search_type);
979 |
980 | write_recent_boolean(rf, "Welcome page sidebar Learn section visible",
981 | RECENT_KEY_SIDEBAR_LEARN_VISIBLE"gui.welcome_page.sidebar.learn_visible",
982 | recent.gui_welcome_page_sidebar_learn_visible);
983 |
984 | write_recent_boolean(rf, "Welcome page sidebar Tips section visible",
985 | RECENT_KEY_SIDEBAR_TIPS_VISIBLE"gui.welcome_page.sidebar.tips_visible",
986 | recent.gui_welcome_page_sidebar_tips_visible);
987 |
988 | write_recent_boolean(rf, "Welcome page sidebar Tips event slides",
989 | RECENT_KEY_SIDEBAR_TIPS_EVENTS"gui.welcome_page.sidebar.tips_events",
990 | recent.gui_welcome_page_sidebar_tips_events);
991 |
992 | write_recent_boolean(rf, "Welcome page sidebar Tips sponsorship slides",
993 | RECENT_KEY_SIDEBAR_TIPS_SPONSORSHIP"gui.welcome_page.sidebar.tips_sponsorship",
994 | recent.gui_welcome_page_sidebar_tips_sponsorship);
995 |
996 | write_recent_boolean(rf, "Welcome page sidebar Tips tip-of-the-day slides",
997 | RECENT_KEY_SIDEBAR_TIPS_TIPS"gui.welcome_page.sidebar.tips_tips",
998 | recent.gui_welcome_page_sidebar_tips_tips);
999 |
1000 | write_recent_boolean(rf, "Welcome page sidebar Tips auto advance slides",
1001 | RECENT_KEY_SIDEBAR_TIPS_AUTO_ADVANCE"gui.welcome_page.sidebar.tips_auto_advance",
1002 | recent.gui_welcome_page_sidebar_tips_auto_advance);
1003 |
1004 | fprintf(rf, "\n# Welcome page sidebar Tips slide auto-advance interval in seconds.\n");
1005 | fprintf(rf, RECENT_KEY_SIDEBAR_TIPS_INTERVAL"gui.welcome_page.sidebar.tips_interval" ": %u\n",
1006 | recent.gui_welcome_page_sidebar_tips_interval);
1007 |
1008 | write_recent_boolean(rf, "Welcome page sidebar Tips slides test",
1009 | RECENT_KEY_SIDEBAR_TIPS_SLIDES_TEST"gui.welcome_page.sidebar.tips_slides_test",
1010 | recent.gui_welcome_page_sidebar_tips_slides_test);
1011 |
1012 | window_geom_recent_write_all(rf);
1013 |
1014 | fprintf(rf, "\n# Custom colors.\n");
1015 | fprintf(rf, "# List of custom colors selected in Qt color picker.\n");
1016 | string_list = join_string_list(recent.custom_colors);
1017 | fprintf(rf, RECENT_GUI_CUSTOM_COLORS"gui.custom_colors" ": %s\n", string_list);
1018 | g_free(string_list);
1019 |
1020 | fclose(rf);
1021 |
1022 | /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
1023 | an error indication, or maybe write to a new recent file and
1024 | rename that file on top of the old one only if there are not I/O
1025 | errors. */
1026 | return true1;
1027 | }
1028 |
1029 |
1030 | /* Attempt to Write out profile "recent" to the user's profile recent file.
1031 | If we got an error report it with a dialog box and return false,
1032 | otherwise return true. */
1033 | bool_Bool
1034 | write_profile_recent(void)
1035 | {
1036 | char *pf_dir_path;
1037 | char *rf_path;
1038 | char *string_list;
1039 | FILE *rf;
1040 |
1041 | /* To do:
1042 | * - Split output lines longer than MAX_VAL_LEN
1043 | * - Create a function for the preference directory check/creation
1044 | * so that duplication can be avoided with filter.c
1045 | */
1046 |
1047 | /* Create the directory that holds personal configuration files, if
1048 | necessary. */
1049 | if (create_persconffile_dir(application_configuration_environment_prefix(), &pf_dir_path) == -1) {
1050 | simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK0x01,
1051 | "Can't create directory\n\"%s\"\nfor recent file: %s.", pf_dir_path,
1052 | g_strerror(errno(*__errno_location ())));
1053 | g_free(pf_dir_path);
1054 | return false0;
1055 | }
1056 |
1057 | rf_path = get_persconffile_path(RECENT_FILE_NAME"recent", true1, application_configuration_environment_prefix());
1058 | if ((rf = ws_fopenfopen(rf_path, "w")) == NULL((void*)0)) {
1059 | simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK0x01,
1060 | "Can't open recent file\n\"%s\": %s.", rf_path,
1061 | g_strerror(errno(*__errno_location ())));
1062 | g_free(rf_path);
1063 | return false0;
1064 | }
1065 | g_free(rf_path);
1066 |
1067 | fprintf(rf, "# Recent settings file for %s " VERSION"4.7.0" ".\n"
1068 | "#\n"
1069 | "# This file is regenerated each time %s is quit\n"
1070 | "# and when changing configuration profile.\n"
1071 | "# So be careful, if you want to make manual changes here.\n"
1072 | "\n",
1073 | application_flavor_name_proper(), application_flavor_name_proper());
1074 |
1075 | write_recent_boolean(rf, "Main Toolbar show (hide)",
1076 | RECENT_KEY_MAIN_TOOLBAR_SHOW"gui.toolbar_main_show",
1077 | recent.main_toolbar_show);
1078 |
1079 | write_recent_boolean(rf, "Filter Toolbar show (hide)",
1080 | RECENT_KEY_FILTER_TOOLBAR_SHOW"gui.filter_toolbar_show",
1081 | recent.filter_toolbar_show);
1082 |
1083 | write_recent_boolean(rf, "Wireless Settings Toolbar show (hide)",
1084 | RECENT_KEY_WIRELESS_TOOLBAR_SHOW"gui.wireless_toolbar_show",
1085 | recent.wireless_toolbar_show);
1086 |
1087 | write_recent_boolean(rf, "Packet list show (hide)",
1088 | RECENT_KEY_PACKET_LIST_SHOW"gui.packet_list_show",
1089 | recent.packet_list_show);
1090 |
1091 | write_recent_boolean(rf, "Tree view show (hide)",
1092 | RECENT_KEY_TREE_VIEW_SHOW"gui.tree_view_show",
1093 | recent.tree_view_show);
1094 |
1095 | write_recent_boolean(rf, "Byte view show (hide)",
1096 | RECENT_KEY_BYTE_VIEW_SHOW"gui.byte_view_show",
1097 | recent.byte_view_show);
1098 |
1099 | write_recent_boolean(rf, "Packet diagram show (hide)",
1100 | RECENT_KEY_PACKET_DIAGRAM_SHOW"gui.packet_diagram_show",
1101 | recent.packet_diagram_show);
1102 |
1103 | write_recent_boolean(rf, "Statusbar show (hide)",
1104 | RECENT_KEY_STATUSBAR_SHOW"gui.statusbar_show",
1105 | recent.statusbar_show);
1106 |
1107 | write_recent_boolean(rf, "Packet list colorize (hide)",
1108 | RECENT_KEY_PACKET_LIST_COLORIZE"gui.packet_list_colorize",
1109 | recent.packet_list_colorize);
1110 |
1111 | write_recent_boolean(rf, "Auto scroll packet list when capturing",
1112 | RECENT_KEY_CAPTURE_AUTO_SCROLL"capture.auto_scroll",
1113 | recent.capture_auto_scroll);
1114 |
1115 | write_recent_boolean(rf, "use as aggregation view",
1116 | RECENT_KEY_AGGREGATION_VIEW"capture.aggregation_view",
1117 | recent.aggregation_view);
1118 |
1119 | write_recent_enum(rf, "Timestamp display format",
1120 | RECENT_GUI_TIME_FORMAT"gui.time_format", ts_type_values,
1121 | recent.gui_time_format);
1122 |
1123 | /*
1124 | * The value of this item is either TS_PREC_AUTO, which is a
1125 | * negative number meaning "pick the display precision based
1126 | * on the time stamp precision of the packet", or is a numerical
1127 | * value giving the number of decimal places to display, from 0
1128 | * to WS_TSPREC_MAX.
1129 | *
1130 | * It used to be that not all values between 0 and 9 (the maximum
1131 | * precision back then) were supported, and that names were
1132 | * written out to the recent file.
1133 | *
1134 | * For backwards compatibility with those older versions of
1135 | * Wireshark, write out the names for those values, and the
1136 | * raw number for other values.
1137 | */
1138 | {
1139 | const char *if_invalid = NULL((void*)0);
1140 | const value_string *valp;
1141 | const char *str_value;
1142 |
1143 | fprintf(rf, "\n# %s.\n", "Timestamp display precision");
1144 | fprintf(rf, "# One of: ");
1145 | valp = ts_precision_values;
1146 | while (valp->strptr != NULL((void*)0)) {
1147 | if (if_invalid == NULL((void*)0))
1148 | if_invalid = valp->strptr;
1149 | fprintf(rf, "%s", valp->strptr);
1150 | valp++;
1151 | if (valp->strptr != NULL((void*)0))
1152 | fprintf(rf, ", ");
1153 | }
1154 | fprintf(rf, ", or a number between 0 and %d\n", WS_TSPREC_MAX9);
1155 |
1156 | str_value = try_val_to_str(recent.gui_time_precision, ts_precision_values);
1157 | if (str_value != NULL((void*)0))
1158 | fprintf(rf, "%s: %s\n", RECENT_GUI_TIME_PRECISION"gui.time_precision", str_value);
1159 | else {
1160 | if (recent.gui_time_precision >= 0 && recent.gui_time_precision < WS_TSPREC_MAX9)
1161 | fprintf(rf, "%s: %d\n", RECENT_GUI_TIME_PRECISION"gui.time_precision", recent.gui_time_precision);
1162 | else
1163 | fprintf(rf, "%s: %s\n", RECENT_GUI_TIME_PRECISION"gui.time_precision", if_invalid != NULL((void*)0) ? if_invalid : "Unknown");
1164 | }
1165 | }
1166 |
1167 | write_recent_enum(rf, "Seconds display format",
1168 | RECENT_GUI_SECONDS_FORMAT"gui.seconds_format", ts_seconds_values,
1169 | recent.gui_seconds_format);
1170 |
1171 | fprintf(rf, "\n# Zoom level.\n");
1172 | fprintf(rf, "# A decimal number.\n");
1173 | fprintf(rf, RECENT_GUI_ZOOM_LEVEL"gui.zoom_level" ": %d\n",
1174 | recent.gui_zoom_level);
1175 |
1176 | write_recent_enum(rf, "Bytes view display type",
1177 | RECENT_GUI_BYTES_VIEW"gui.bytes_view", bytes_view_type_values,
1178 | recent.gui_bytes_view);
1179 |
1180 | write_recent_enum(rf, "Bytes view text encoding",
1181 | RECENT_GUI_BYTES_ENCODING"gui.bytes_encoding", bytes_encoding_type_values,
1182 | recent.gui_bytes_encoding);
1183 |
1184 | write_recent_boolean(rf, "Packet diagram field values show (hide)",
1185 | RECENT_GUI_PACKET_DIAGRAM_FIELD_VALUES"gui.packet_diagram_field_values",
1186 | recent.gui_packet_diagram_field_values);
1187 |
1188 | write_recent_boolean(rf, "Allow hover selection in byte view",
1189 | RECENT_GUI_ALLOW_HOVER_SELECTION"gui.allow_hover_selection",
1190 | recent.gui_allow_hover_selection);
1191 |
1192 | write_recent_enum(rf, "Follow stream show as",
1193 | RECENT_GUI_FOLLOW_SHOW"gui.follow_show", bytes_show_values,
1194 | recent.gui_follow_show);
1195 |
1196 | write_recent_enum(rf, "Follow stream delta times",
1197 | RECENT_GUI_FOLLOW_DELTA"gui.follow_delta", follow_delta_values,
1198 | recent.gui_follow_delta);
1199 |
1200 | write_recent_enum(rf, "Show packet bytes decode as",
1201 | RECENT_GUI_SHOW_BYTES_DECODE"gui.show_bytes_decode", show_bytes_decode_values,
1202 | recent.gui_show_bytes_decode);
1203 |
1204 | write_recent_enum(rf, "Show packet bytes show as",
1205 | RECENT_GUI_SHOW_BYTES_SHOW"gui.show_bytes_show", bytes_show_values,
1206 | recent.gui_show_bytes_show);
1207 |
1208 | fprintf(rf, "\n# Main window upper (or leftmost) pane size.\n");
1209 | fprintf(rf, "# Decimal number.\n");
1210 | if (recent.gui_geometry_main_upper_pane != 0) {
1211 | fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_UPPER_PANE"gui.geometry_main_upper_pane" ": %d\n",
1212 | recent.gui_geometry_main_upper_pane);
1213 | }
1214 | fprintf(rf, "\n# Main window middle pane size.\n");
1215 | fprintf(rf, "# Decimal number.\n");
1216 | if (recent.gui_geometry_main_lower_pane != 0) {
1217 | fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_LOWER_PANE"gui.geometry_main_lower_pane" ": %d\n",
1218 | recent.gui_geometry_main_lower_pane);
1219 | }
1220 |
1221 | if (recent.gui_geometry_main_master_split != NULL((void*)0)) {
1222 | fprintf(rf, "\n# Main window master splitter state.\n");
1223 | fprintf(rf, "# Hex byte string.\n");
1224 | fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_MASTER_SPLIT"gui.geometry_main_master_split" ": %s\n",
1225 | recent.gui_geometry_main_master_split);
1226 | }
1227 |
1228 | if (recent.gui_geometry_main_extra_split != NULL((void*)0)) {
1229 | fprintf(rf, "\n# Main window extra splitter state.\n");
1230 | fprintf(rf, "# Hex byte string.\n");
1231 | fprintf(rf, RECENT_GUI_GEOMETRY_MAIN_EXTRA_SPLIT"gui.geometry_main_extra_split" ": %s\n",
1232 | recent.gui_geometry_main_extra_split);
1233 | }
1234 |
1235 | window_splitter_recent_write_all(rf);
1236 |
1237 | fprintf(rf, "\n# Packet list column pixel widths.\n");
1238 | fprintf(rf, "# Each pair of strings consists of a column format and its pixel width.\n");
1239 | packet_list_recent_write_all(rf);
1240 |
1241 | fprintf(rf, "\n# Open conversation dialog tabs.\n");
1242 | fprintf(rf, "# List of conversation names, e.g. \"TCP\", \"IPv6\".\n");
1243 | string_list = join_string_list(recent.conversation_tabs);
1244 | fprintf(rf, RECENT_GUI_CONVERSATION_TABS"gui.conversation_tabs" ": %s\n", string_list);
1245 | g_free(string_list);
1246 |
1247 | fprintf(rf, "\n# Conversation dialog tabs columns.\n");
1248 | fprintf(rf, "# List of conversation columns numbers.\n");
1249 | string_list = join_string_list(recent.conversation_tabs_columns);
1250 | fprintf(rf, RECENT_GUI_CONVERSATION_TABS_COLUMNS"gui.conversation_tabs_columns" ": %s\n", string_list);
1251 | g_free(string_list);
1252 |
1253 | fprintf(rf, "\n# Open endpoint dialog tabs.\n");
1254 | fprintf(rf, "# List of endpoint names, e.g. \"TCP\", \"IPv6\".\n");
1255 | string_list = join_string_list(recent.endpoint_tabs);
1256 | fprintf(rf, RECENT_GUI_ENDPOINT_TABS"gui.endpoint_tabs" ": %s\n", string_list);
1257 | g_free(string_list);
1258 |
1259 | fprintf(rf, "\n# Endpoint dialog tabs columns.\n");
1260 | fprintf(rf, "# List of endpoint columns numbers.\n");
1261 | string_list = join_string_list(recent.endpoint_tabs_columns);
1262 | fprintf(rf, RECENT_GUI_ENDPOINT_TABS_COLUMNS"gui.endpoint_tabs_columns" ": %s\n", string_list);
1263 | g_free(string_list);
1264 |
1265 | write_recent_boolean(rf, "For RLC stats, whether to use RLC PDUs found inside MAC frames",
1266 | RECENT_GUI_RLC_PDUS_FROM_MAC_FRAMES"gui.rlc_pdus_from_mac_frames",
1267 | recent.gui_rlc_use_pdus_from_mac);
1268 |
1269 | if (get_last_open_dir() != NULL((void*)0)) {
1270 | fprintf(rf, "\n# Last directory navigated to in File Open dialog.\n");
1271 | fprintf(rf, RECENT_GUI_FILEOPEN_REMEMBERED_DIR"gui.fileopen_remembered_dir" ": %s\n", get_last_open_dir());
1272 | }
1273 |
1274 | fprintf(rf, "\n# Additional Toolbars shown\n");
1275 | fprintf(rf, "# List of additional toolbars to show.\n");
1276 | string_list = join_string_list(recent.gui_additional_toolbars);
1277 | fprintf(rf, RECENT_GUI_TOOLBAR_SHOW"gui.additional_toolbar_show" ": %s\n", string_list);
1278 | g_free(string_list);
1279 |
1280 | fprintf(rf, "\n# Interface Toolbars show.\n");
1281 | fprintf(rf, "# List of interface toolbars to show.\n");
1282 | string_list = join_string_list(recent.interface_toolbars);
1283 | fprintf(rf, RECENT_GUI_INTERFACE_TOOLBAR_SHOW"gui.interface_toolbar_show" ": %s\n", string_list);
1284 | g_free(string_list);
1285 |
1286 | write_recent_double(rf, "TCP Stream Graphs Moving Average Window Size",
1287 | RECENT_GUI_TSD_MA_WINDOW_SIZE"gui.tsd_ma_window_size",
1288 | recent.gui_tsgd_ma_window_size);
1289 | write_recent_boolean(rf, "TCP Stream Graphs Dialog Throughput show (hide)",
1290 | RECENT_GUI_TSD_THROUGHPUT_SHOW"gui.tsd_throughput_show",
1291 | recent.gui_tsgd_throughput_show);
1292 | write_recent_boolean(rf, "TCP Stream Graphs Dialog Goodput show (hide)",
1293 | RECENT_GUI_TSD_GOODPUT_SHOW"gui.tsd_goodput_show",
1294 | recent.gui_tsgd_goodput_show);
1295 |
1296 | fclose(rf);
1297 |
1298 | /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
1299 | an error indication, or maybe write to a new recent file and
1300 | rename that file on top of the old one only if there are not I/O
1301 | errors. */
1302 | return true1;
1303 | }
1304 |
1305 | /* set one user's recent common file key/value pair */
1306 | static prefs_set_pref_e
1307 | read_set_recent_common_pair_static(char *key, const char *value,
1308 | void *private_data _U___attribute__((unused)),
1309 | bool_Bool return_range_errors _U___attribute__((unused)))
1310 | {
1311 | long num;
1312 | char *p;
1313 |
1314 | if (strcmp(key, RECENT_GUI_GEOMETRY_MAIN_MAXIMIZED"gui.geometry_main_maximized") == 0) {
1315 | parse_recent_boolean(value, &recent.gui_geometry_main_maximized);
1316 | } else if (strcmp(key, RECENT_GUI_GEOMETRY_LEFTALIGN_ACTIONS"gui.geometry_leftalign_actions") == 0) {
1317 | parse_recent_boolean(value, &recent.gui_geometry_leftalign_actions);
1318 | } else if (strcmp(key, RECENT_GUI_GEOMETRY_MAIN_X"gui.geometry_main_x") == 0) {
1319 | num = strtol(value, &p, 0);
1320 | if (p == value || *p != '\0')
1321 | return PREFS_SET_SYNTAX_ERR; /* number was bad */
1322 | recent.gui_geometry_main_x = (int)num;
1323 | } else if (strcmp(key, RECENT_GUI_GEOMETRY_MAIN_Y"gui.geometry_main_y") == 0) {
1324 | num = strtol(value, &p, 0);
1325 | if (p == value || *p != '\0')
1326 | return PREFS_SET_SYNTAX_ERR; /* number was bad */
1327 | recent.gui_geometry_main_y = (int)num;
1328 | } else if (strcmp(key, RECENT_GUI_GEOMETRY_MAIN_WIDTH"gui.geometry_main_width") == 0) {
1329 | num = strtol(value, &p, 0);
1330 | if (p == value || *p != '\0')
1331 | return PREFS_SET_SYNTAX_ERR; /* number was bad */
1332 | if (num <= 0)
1333 | return PREFS_SET_SYNTAX_ERR; /* number must be positive */
1334 | recent.gui_geometry_main_width = (int)num;
1335 | } else if (strcmp(key, RECENT_GUI_GEOMETRY_MAIN_HEIGHT"gui.geometry_main_height") == 0) {
1336 | num = strtol(value, &p, 0);
1337 | if (p == value || *p != '\0')
1338 | return PREFS_SET_SYNTAX_ERR; /* number was bad */
1339 | if (num <= 0)
1340 | return PREFS_SET_SYNTAX_ERR; /* number must be positive */
1341 | recent.gui_geometry_main_height = (int)num;
1342 | } else if (strcmp(key, RECENT_GUI_GEOMETRY_MAIN"gui.geometry_main") == 0) {
1343 | g_free(recent.gui_geometry_main);
1344 | recent.gui_geometry_main = g_strdup(value)g_strdup_inline (value);
1345 | } else if (strcmp(key, RECENT_LAST_USED_PROFILE"gui.last_used_profile") == 0) {
1346 | if ((strcmp(value, DEFAULT_PROFILE"Default") != 0) && profile_exists(application_configuration_environment_prefix(), value, false0)) {
1347 | set_profile_name (value);
1348 | }
1349 | } else if (strcmp(key, RECENT_PROFILE_SWITCH_CHECK_COUNT"gui.profile_switch_check_count") == 0) {
1350 | num = strtol(value, &p, 0);
1351 | if (p == value || *p != '\0')
1352 | return PREFS_SET_SYNTAX_ERR; /* number was bad */
1353 | if (num <= 0)
1354 | return PREFS_SET_SYNTAX_ERR; /* number must be positive */
1355 | recent.gui_profile_switch_check_count = (int)num;
1356 | } else if (strncmp(key, RECENT_GUI_GEOMETRY"gui.geom.", sizeof(RECENT_GUI_GEOMETRY"gui.geom.")-1) == 0) {
1357 | /* now have something like "gui.geom.main.x", split it into win and sub_key */
1358 | char *win = &key[sizeof(RECENT_GUI_GEOMETRY"gui.geom.")-1];
1359 | char *sub_key = strchr(win, '.');
1360 | if (sub_key) {
1361 | *sub_key = '\0';
1362 | sub_key++;
1363 | window_geom_recent_read_pair(win, sub_key, value);
1364 | }
1365 | } else if (strcmp(key, RECENT_KEY_PRIVS_WARN_IF_ELEVATED"privs.warn_if_elevated") == 0) {
1366 | parse_recent_boolean(value, &recent.privs_warn_if_elevated);
1367 | } else if (strcmp(key, RECENT_KEY_SYS_WARN_IF_NO_CAPTURE"sys.warn_if_no_capture") == 0) {
1368 | parse_recent_boolean(value, &recent.sys_warn_if_no_capture);
1369 | } else if (strcmp(key, RECENT_GUI_SEARCH_IN"gui.search_in") == 0) {
1370 | recent.gui_search_in = (search_in_type)str_to_val(value, search_in_values, SEARCH_IN_PACKET_LIST);
1371 | } else if (strcmp(key, RECENT_GUI_SEARCH_CHAR_SET"gui.search_char_set") == 0) {
1372 | recent.gui_search_char_set = (search_char_set_type)str_to_val(value, search_char_set_values, SEARCH_CHAR_SET_NARROW_AND_WIDE);
1373 | } else if (strcmp(key, RECENT_GUI_SEARCH_CASE_SENSITIVE"gui.search_case_sensitive") == 0) {
1374 | parse_recent_boolean(value, &recent.gui_search_case_sensitive);
1375 | } else if (strcmp(key, RECENT_GUI_SEARCH_REVERSE_DIR"gui.search_reverse_dir") == 0) {
1376 | parse_recent_boolean(value, &recent.gui_search_reverse_dir);
1377 | } else if (strcmp(key, RECENT_GUI_SEARCH_MULTIPLE_OCCURS"gui.search_multiple_occurs") == 0) {
1378 | parse_recent_boolean(value, &recent.gui_search_multiple_occurs);
1379 | } else if (strcmp(key, RECENT_GUI_SEARCH_TYPE"gui.search_type") == 0) {
1380 | recent.gui_search_type = (search_type_type)str_to_val(value, search_type_values, SEARCH_TYPE_DISPLAY_FILTER);
1381 | } else if (strcmp(key, RECENT_GUI_CUSTOM_COLORS"gui.custom_colors") == 0) {
1382 | recent.custom_colors = prefs_get_string_list(value);
1383 | } else if (strcmp(key, RECENT_KEY_SIDEBAR_LEARN_VISIBLE"gui.welcome_page.sidebar.learn_visible") == 0) {
1384 | parse_recent_boolean(value, &recent.gui_welcome_page_sidebar_learn_visible);
1385 | } else if (strcmp(key, RECENT_KEY_SIDEBAR_TIPS_VISIBLE"gui.welcome_page.sidebar.tips_visible") == 0) {
1386 | parse_recent_boolean(value, &recent.gui_welcome_page_sidebar_tips_visible);
1387 | } else if (strcmp(key, RECENT_KEY_SIDEBAR_TIPS_EVENTS"gui.welcome_page.sidebar.tips_events") == 0) {
1388 | parse_recent_boolean(value, &recent.gui_welcome_page_sidebar_tips_events);
1389 | } else if (strcmp(key, RECENT_KEY_SIDEBAR_TIPS_SPONSORSHIP"gui.welcome_page.sidebar.tips_sponsorship") == 0) {
1390 | parse_recent_boolean(value, &recent.gui_welcome_page_sidebar_tips_sponsorship);
1391 | } else if (strcmp(key, RECENT_KEY_SIDEBAR_TIPS_TIPS"gui.welcome_page.sidebar.tips_tips") == 0) {
1392 | parse_recent_boolean(value, &recent.gui_welcome_page_sidebar_tips_tips);
1393 | } else if (strcmp(key, RECENT_KEY_SIDEBAR_TIPS_AUTO_ADVANCE"gui.welcome_page.sidebar.tips_auto_advance") == 0) {
1394 | parse_recent_boolean(value, &recent.gui_welcome_page_sidebar_tips_auto_advance);
1395 | } else if (strcmp(key, RECENT_KEY_SIDEBAR_TIPS_INTERVAL"gui.welcome_page.sidebar.tips_interval") == 0) {
1396 | num = strtol(value, &p, 0);
1397 | if (p == value || *p != '\0')
1398 | return PREFS_SET_SYNTAX_ERR;
1399 | if (num < 1)
1400 | num = 8; // Default value
1401 | recent.gui_welcome_page_sidebar_tips_interval = (unsigned)num;
1402 | } else if (strcmp(key, RECENT_KEY_SIDEBAR_TIPS_SLIDES_TEST"gui.welcome_page.sidebar.tips_slides_test") == 0) {
1403 | parse_recent_boolean(value, &recent.gui_welcome_page_sidebar_tips_slides_test);
1404 | }
1405 |
1406 | return PREFS_SET_OK;
1407 | }
1408 |
1409 | /* set one user's recent file key/value pair */
1410 | static prefs_set_pref_e
1411 | read_set_recent_pair_static(char *key, const char *value,
1412 | void *private_data _U___attribute__((unused)),
1413 | bool_Bool return_range_errors _U___attribute__((unused)))
1414 | {
1415 | long num;
1416 | int32_t num_int32;
1417 | double val_as_dbl;
1418 | char *p;
1419 | GList *col_l, *col_l_elt;
1420 | col_width_data *cfmt;
1421 |
1422 | if (strcmp(key, RECENT_KEY_MAIN_TOOLBAR_SHOW"gui.toolbar_main_show") == 0) {
1423 | parse_recent_boolean(value, &recent.main_toolbar_show);
1424 | } else if (strcmp(key, RECENT_KEY_FILTER_TOOLBAR_SHOW"gui.filter_toolbar_show") == 0) {
1425 | parse_recent_boolean(value, &recent.filter_toolbar_show);
1426 | /* check both the old and the new keyword */
1427 | } else if (strcmp(key, RECENT_KEY_WIRELESS_TOOLBAR_SHOW"gui.wireless_toolbar_show") == 0 || (strcmp(key, "gui.airpcap_toolbar_show") == 0)) {
1428 | parse_recent_boolean(value, &recent.wireless_toolbar_show);
1429 | } else if (strcmp(key, RECENT_KEY_PACKET_LIST_SHOW"gui.packet_list_show") == 0) {
1430 | parse_recent_boolean(value, &recent.packet_list_show);
1431 | } else if (strcmp(key, RECENT_KEY_TREE_VIEW_SHOW"gui.tree_view_show") == 0) {
1432 | parse_recent_boolean(value, &recent.tree_view_show);
1433 | } else if (strcmp(key, RECENT_KEY_BYTE_VIEW_SHOW"gui.byte_view_show") == 0) {
1434 | parse_recent_boolean(value, &recent.byte_view_show);
1435 | } else if (strcmp(key, RECENT_KEY_PACKET_DIAGRAM_SHOW"gui.packet_diagram_show") == 0) {
1436 | parse_recent_boolean(value, &recent.packet_diagram_show);
1437 | } else if (strcmp(key, RECENT_KEY_STATUSBAR_SHOW"gui.statusbar_show") == 0) {
1438 | parse_recent_boolean(value, &recent.statusbar_show);
1439 | } else if (strcmp(key, RECENT_KEY_PACKET_LIST_COLORIZE"gui.packet_list_colorize") == 0) {
1440 | parse_recent_boolean(value, &recent.packet_list_colorize);
1441 | } else if (strcmp(key, RECENT_KEY_CAPTURE_AUTO_SCROLL"capture.auto_scroll") == 0) {
1442 | parse_recent_boolean(value, &recent.capture_auto_scroll);
1443 | } else if (strcmp(key, RECENT_KEY_AGGREGATION_VIEW"capture.aggregation_view") == 0) {
1444 | parse_recent_boolean(value, &recent.aggregation_view);
1445 | } else if (strcmp(key, RECENT_GUI_TIME_FORMAT"gui.time_format") == 0) {
1446 | recent.gui_time_format = (ts_type)str_to_val(value, ts_type_values,
1447 | application_flavor_is_wireshark() ? TS_RELATIVE : TS_ABSOLUTE);
1448 | } else if (strcmp(key, RECENT_GUI_TIME_PRECISION"gui.time_precision") == 0) {
1449 | /*
1450 | * The value of this item is either TS_PREC_AUTO, which is a
1451 | * negative number meaning "pick the display precision based
1452 | * on the time stamp precision of the packet", or is a numerical
1453 | * value giving the number of decimal places to display, from 0
1454 | * to WS_TSPREC_MAX.
1455 | *
1456 | * It used to be that not all values between 0 and 9 (the maximum
1457 | * precision back then) were supported, and that names were
1458 | * written out to the recent file.
1459 | *
1460 | * If the string value is a valid number in that range, use
1461 | * that number, otherwise look it up in the table of names,
1462 | * and, if that fails, set it to TS_PREC_AUTO.
1463 | */
1464 | if (ws_strtoi32(value, NULL((void*)0), &num_int32) && num_int32 >= 0 &&
1465 | num_int32 <= WS_TSPREC_MAX9) {
1466 | recent.gui_time_precision = num_int32;
1467 | } else {
1468 | recent.gui_time_precision =
1469 | (ts_precision)str_to_val(value, ts_precision_values, TS_PREC_AUTO);
1470 | }
1471 | } else if (strcmp(key, RECENT_GUI_SECONDS_FORMAT"gui.seconds_format") == 0) {
1472 | recent.gui_seconds_format =
1473 | (ts_seconds_type)str_to_val(value, ts_seconds_values, TS_SECONDS_DEFAULT);
1474 | } else if (strcmp(key, RECENT_GUI_ZOOM_LEVEL"gui.zoom_level") == 0) {
1475 | num = strtol(value, &p, 0);
1476 | if (p == value || *p != '\0')
1477 | return PREFS_SET_SYNTAX_ERR; /* number was bad */
1478 | recent.gui_zoom_level = (int)num;
1479 | } else if (strcmp(key, RECENT_GUI_BYTES_VIEW"gui.bytes_view") == 0) {
1480 | recent.gui_bytes_view =
1481 | (bytes_view_type)str_to_val(value, bytes_view_type_values, BYTES_HEX);
1482 | } else if (strcmp(key, RECENT_GUI_BYTES_ENCODING"gui.bytes_encoding") == 0) {
1483 | recent.gui_bytes_encoding =
1484 | (bytes_encoding_type)str_to_val(value, bytes_encoding_type_values, BYTES_ENC_FROM_PACKET);
1485 | } else if (strcmp(key, RECENT_GUI_PACKET_DIAGRAM_FIELD_VALUES"gui.packet_diagram_field_values") == 0) {
1486 | parse_recent_boolean(value, &recent.gui_packet_diagram_field_values);
1487 | } else if (strcmp(key, RECENT_GUI_ALLOW_HOVER_SELECTION"gui.allow_hover_selection") == 0) {
1488 | parse_recent_boolean(value, &recent.gui_allow_hover_selection);
1489 | } else if (strcmp(key, RECENT_GUI_FOLLOW_SHOW"gui.follow_show") == 0) {
1490 | recent.gui_follow_show = (bytes_show_type)str_to_val(value, bytes_show_values, SHOW_ASCII);
1491 | } else if (strcmp(key, RECENT_GUI_FOLLOW_DELTA"gui.follow_delta") == 0) {
1492 | recent.gui_follow_delta = (follow_delta_type)str_to_val(value, follow_delta_values, FOLLOW_DELTA_NONE);
1493 | } else if (strcmp(key, RECENT_GUI_SHOW_BYTES_DECODE"gui.show_bytes_decode") == 0) {
1494 | recent.gui_show_bytes_decode = (bytes_decode_type)str_to_val(value, show_bytes_decode_values, DecodeAsNone);
1495 | } else if (strcmp(key, RECENT_GUI_SHOW_BYTES_SHOW"gui.show_bytes_show") == 0) {
1496 | recent.gui_show_bytes_show = (bytes_show_type)str_to_val(value, bytes_show_values, SHOW_ASCII);
1497 | } else if (strcmp(key, RECENT_GUI_GEOMETRY_MAIN_UPPER_PANE"gui.geometry_main_upper_pane") == 0) {
1498 | num = strtol(value, &p, 0);
1499 | if (p == value || *p != '\0')
1500 | return PREFS_SET_SYNTAX_ERR; /* number was bad */
1501 | if (num <= 0)
1502 | return PREFS_SET_SYNTAX_ERR; /* number must be positive */
1503 | recent.gui_geometry_main_upper_pane = (int)num;
1504 | } else if (strcmp(key, RECENT_GUI_GEOMETRY_MAIN_LOWER_PANE"gui.geometry_main_lower_pane") == 0) {
1505 | num = strtol(value, &p, 0);
1506 | if (p == value || *p != '\0')
1507 | return PREFS_SET_SYNTAX_ERR; /* number was bad */
1508 | if (num <= 0)
1509 | return PREFS_SET_SYNTAX_ERR; /* number must be positive */
1510 | recent.gui_geometry_main_lower_pane = (int)num;
1511 | } else if (strcmp(key, RECENT_GUI_GEOMETRY_MAIN_MASTER_SPLIT"gui.geometry_main_master_split") == 0) {
1512 | g_free(recent.gui_geometry_main_master_split);
1513 | recent.gui_geometry_main_master_split = g_strdup(value)g_strdup_inline (value);
1514 | } else if (strcmp(key, RECENT_GUI_GEOMETRY_MAIN_EXTRA_SPLIT"gui.geometry_main_extra_split") == 0) {
1515 | g_free(recent.gui_geometry_main_extra_split);
1516 | recent.gui_geometry_main_extra_split = g_strdup(value)g_strdup_inline (value);
1517 | } else if (strncmp(key, RECENT_GUI_GEOMETRY"gui.geom.", sizeof(RECENT_GUI_GEOMETRY"gui.geom.")-1) == 0) {
1518 | /* now have something like "gui.geom.win.sub_key", split it into win and sub_key */
1519 | char *win = &key[sizeof(RECENT_GUI_GEOMETRY"gui.geom.")-1];
1520 | char *sub_key = strchr(win, '.');
1521 | if (sub_key) {
1522 | *sub_key = '\0';
1523 | sub_key++;
1524 | window_geom_recent_read_pair(win, sub_key, value);
1525 | }
1526 | } else if (strcmp(key, RECENT_GUI_CONVERSATION_TABS"gui.conversation_tabs") == 0) {
1527 | g_list_free_full(recent.conversation_tabs, g_free);
1528 | recent.conversation_tabs = prefs_get_string_list(value);
1529 | } else if (strcmp(key, RECENT_GUI_CONVERSATION_TABS_COLUMNS"gui.conversation_tabs_columns") == 0) {
1530 | g_list_free_full(recent.conversation_tabs_columns, g_free);
1531 | recent.conversation_tabs_columns = prefs_get_string_list(value);
1532 | } else if (strcmp(key, RECENT_GUI_ENDPOINT_TABS"gui.endpoint_tabs") == 0) {
1533 | g_list_free_full(recent.endpoint_tabs, g_free);
1534 | recent.endpoint_tabs = prefs_get_string_list(value);
1535 | } else if (strcmp(key, RECENT_GUI_ENDPOINT_TABS_COLUMNS"gui.endpoint_tabs_columns") == 0) {
1536 | g_list_free_full(recent.endpoint_tabs_columns, g_free);
1537 | recent.endpoint_tabs_columns = prefs_get_string_list(value);
1538 | } else if (strcmp(key, RECENT_GUI_RLC_PDUS_FROM_MAC_FRAMES"gui.rlc_pdus_from_mac_frames") == 0) {
1539 | parse_recent_boolean(value, &recent.gui_rlc_use_pdus_from_mac);
1540 | } else if (strcmp(key, RECENT_KEY_COL_WIDTH"column.width") == 0) {
1541 | col_l = prefs_get_string_list(value);
1542 | if (col_l == NULL((void*)0))
1543 | return PREFS_SET_SYNTAX_ERR;
1544 | if ((g_list_length(col_l) % 2) != 0) {
1545 | /* A title didn't have a matching width. */
1546 | prefs_clear_string_list(col_l);
1547 | return PREFS_SET_SYNTAX_ERR;
1548 | }
1549 | recent_free_column_width_info(&recent);
1550 | recent.col_width_list = NULL((void*)0);
1551 | col_l_elt = g_list_first(col_l);
1552 | while (col_l_elt) {
1553 | cfmt = g_new(col_width_data, 1)((col_width_data *) g_malloc_n ((1), sizeof (col_width_data)) );
1554 | /* Skip the column format, we don't use it anymore because the
1555 | * column indices are in sync and the key since 4.4. Format is
1556 | * still written for backwards compatibility.
1557 | */
1558 | col_l_elt = col_l_elt->next;
1559 | cfmt->width = (int)strtol((const char *)col_l_elt->data, &p, 0);
1560 | if (p == col_l_elt->data || (*p != '\0' && *p != ':')) {
1561 | g_free(cfmt);
1562 | return PREFS_SET_SYNTAX_ERR; /* number was bad */
1563 | }
1564 |
1565 | if (*p == ':') {
1566 | cfmt->xalign = *(++p);
1567 | } else {
1568 | cfmt->xalign = COLUMN_XALIGN_DEFAULT0;
1569 | }
1570 |
1571 | col_l_elt = col_l_elt->next;
1572 | recent.col_width_list = g_list_append(recent.col_width_list, cfmt);
1573 | }
1574 | prefs_clear_string_list(col_l);
1575 | } else if (strcmp(key, RECENT_GUI_FILEOPEN_REMEMBERED_DIR"gui.fileopen_remembered_dir") == 0) {
1576 | g_free(recent.gui_fileopen_remembered_dir);
1577 | recent.gui_fileopen_remembered_dir = g_strdup(value)g_strdup_inline (value);
1578 | } else if (strcmp(key, RECENT_GUI_TOOLBAR_SHOW"gui.additional_toolbar_show") == 0) {
1579 | recent.gui_additional_toolbars = prefs_get_string_list(value);
1580 | } else if (strcmp(key, RECENT_GUI_INTERFACE_TOOLBAR_SHOW"gui.interface_toolbar_show") == 0) {
1581 | recent.interface_toolbars = prefs_get_string_list(value);
1582 | } else if (strcmp(key, RECENT_GUI_TSD_THROUGHPUT_SHOW"gui.tsd_throughput_show") == 0) {
1583 | parse_recent_boolean(value, &recent.gui_tsgd_throughput_show);
1584 | } else if (strcmp(key, RECENT_GUI_TSD_GOODPUT_SHOW"gui.tsd_goodput_show") == 0) {
1585 | parse_recent_boolean(value, &recent.gui_tsgd_goodput_show);
1586 | } else if (strcmp(key, RECENT_GUI_TSD_MA_WINDOW_SIZE"gui.tsd_ma_window_size") == 0) {
1587 | val_as_dbl = g_ascii_strtod(value, &p);
1588 | if (p == value || *p != '\0') {
1589 | return PREFS_SET_SYNTAX_ERR; /* number was bad */
1590 | }
1591 | if (val_as_dbl <= 0) {
1592 | return PREFS_SET_SYNTAX_ERR; /* number must be positive */
1593 | }
1594 | recent.gui_tsgd_ma_window_size = val_as_dbl;
1595 | } else {
1596 | return PREFS_SET_NO_SUCH_PREF;
1597 | }
1598 |
1599 | return PREFS_SET_OK;
1600 | }
1601 |
1602 |
1603 | /* set one user's recent file key/value pair */
1604 | static prefs_set_pref_e
1605 | read_set_recent_pair_dynamic(char *key, const char *value,
1606 | void *private_data _U___attribute__((unused)),
1607 | bool_Bool return_range_errors _U___attribute__((unused)))
1608 | {
1609 | if (!g_utf8_validate(value, -1, NULL((void*)0))) {
1610 | return PREFS_SET_SYNTAX_ERR;
1611 | }
1612 | if (strcmp(key, RECENT_KEY_DISPLAY_FILTER"recent.display_filter") == 0) {
1613 | dfilter_combo_add_recent(value);
1614 | } else if (strcmp(key, RECENT_KEY_CAPTURE_FILTER"recent.capture_filter") == 0) {
1615 | recent_add_cfilter(NULL((void*)0), value);
1616 | } else if (g_str_has_prefix(key, RECENT_KEY_CAPTURE_FILTER ".")(__builtin_constant_p ("recent.capture_filter" ".")? __extension__ ({ const char * const __str = (key); const char * const __prefix = ("recent.capture_filter" "."); gboolean __result = (0); if (__str == ((void*)0) || __prefix == ((void*)0)) __result = ( g_str_has_prefix) (__str, __prefix); else { const size_t __str_len = strlen (((__str) + !(__str))); const size_t __prefix_len = strlen (((__prefix) + !(__prefix))); if (__str_len >= __prefix_len ) __result = memcmp (((__str) + !(__str)), ((__prefix) + !(__prefix )), __prefix_len) == 0; } __result; }) : (g_str_has_prefix) ( key, "recent.capture_filter" ".") )) {
1617 | /* strrchr() can't fail - string has a prefix that ends with a "." */
1618 | recent_add_cfilter(strrchr(key, '.') + 1, value);
1619 | #ifdef HAVE_PCAP_REMOTE
1620 | } else if (strcmp(key, RECENT_KEY_REMOTE_HOST"recent.remote_host") == 0) {
1621 | capture_remote_combo_add_recent(value);
1622 | #endif
1623 | }
1624 |
1625 | return PREFS_SET_OK;
1626 | }
1627 |
1628 |
1629 | /*
1630 | * Given a string of the form "<recent name>:<recent value>", as might appear
1631 | * as an argument to a "-o" option, parse it and set the recent value in
1632 | * question. Return an indication of whether it succeeded or failed
1633 | * in some fashion.
1634 | */
1635 | int
1636 | recent_set_arg(char *prefarg)
1637 | {
1638 | char *p, *colonp;
1639 | int ret;
1640 |
1641 | colonp = strchr(prefarg, ':');
1642 | if (colonp == NULL((void*)0))
1643 | return PREFS_SET_SYNTAX_ERR;
1644 |
1645 | p = colonp;
1646 | *p++ = '\0';
1647 |
1648 | /*
1649 | * Skip over any white space (there probably won't be any, but
1650 | * as we allow it in the preferences file, we might as well
1651 | * allow it here).
1652 | */
1653 | while (g_ascii_isspace(*p)((g_ascii_table[(guchar) (*p)] & G_ASCII_SPACE) != 0))
1654 | p++;
1655 | if (*p == '\0') {
1656 | /*
1657 | * Put the colon back, so if our caller uses, in an
1658 | * error message, the string they passed us, the message
1659 | * looks correct.
1660 | */
1661 | *colonp = ':';
1662 | return PREFS_SET_SYNTAX_ERR;
1663 | }
1664 |
1665 | ret = read_set_recent_pair_static(prefarg, p, NULL((void*)0), true1);
1666 | *colonp = ':'; /* put the colon back */
1667 | return ret;
1668 | }
1669 |
1670 |
1671 | /* opens the user's recent common file and read the first part */
1672 | bool_Bool
1673 | recent_read_static(char **rf_path_return, int *rf_errno_return)
1674 | {
1675 | char *rf_path;
1676 | FILE *rf;
1677 |
1678 | /* set defaults */
1679 | recent.gui_geometry_main_x = 20;
1680 | recent.gui_geometry_main_y = 20;
1681 | recent.gui_geometry_main_width = DEF_WIDTH750;
1682 | recent.gui_geometry_main_height = DEF_HEIGHT550;
1683 | recent.gui_geometry_main_maximized= false0;
1684 |
1685 | recent.gui_geometry_leftalign_actions = false0;
1686 |
1687 | recent.privs_warn_if_elevated = true1;
1688 | recent.sys_warn_if_no_capture = true1;
1689 |
1690 | recent.col_width_list = NULL((void*)0);
1691 | recent.gui_geometry_main = NULL((void*)0);
1692 | recent.gui_geometry_main_master_split = NULL((void*)0);
1693 | recent.gui_geometry_main_extra_split = NULL((void*)0);
1694 | recent.gui_profile_switch_check_count = 1000;
1695 | recent.gui_fileopen_remembered_dir = NULL((void*)0);
1696 |
1697 | /* defaults for the welcome page sidebar */
1698 | recent.gui_welcome_page_sidebar_learn_visible = true1;
1699 | recent.gui_welcome_page_sidebar_tips_visible = true1;
1700 | recent.gui_welcome_page_sidebar_tips_events = true1;
1701 | recent.gui_welcome_page_sidebar_tips_sponsorship = true1;
1702 | recent.gui_welcome_page_sidebar_tips_tips = true1;
1703 | recent.gui_welcome_page_sidebar_tips_auto_advance = true1;
1704 | recent.gui_welcome_page_sidebar_tips_interval = 8;
1705 | recent.gui_welcome_page_sidebar_tips_slides_test = false0;
1706 |
1707 | /* Construct the pathname of the user's recent common file. */
1708 | rf_path = get_persconffile_path(RECENT_COMMON_FILE_NAME"recent_common", false0, application_configuration_environment_prefix());
1709 |
1710 | /* Read the user's recent common file, if it exists. */
1711 | *rf_path_return = NULL((void*)0);
1712 | if ((rf = ws_fopenfopen(rf_path, "r")) != NULL((void*)0)) {
1713 | /* We succeeded in opening it; read it. */
1714 | read_prefs_file(rf_path, rf, read_set_recent_common_pair_static, NULL((void*)0));
1715 |
1716 | fclose(rf);
1717 | } else {
1718 | /* We failed to open it. If we failed for some reason other than
1719 | "it doesn't exist", return the errno and the pathname, so our
1720 | caller can report the error. */
1721 | if (errno(*__errno_location ()) != ENOENT2) {
1722 | *rf_errno_return = errno(*__errno_location ());
1723 | *rf_path_return = rf_path;
1724 | return false0;
1725 | }
1726 | }
1727 | g_free(rf_path);
1728 | return true1;
1729 | }
1730 |
1731 |
1732 |
1733 | /* opens the user's recent file and read the first part */
1734 | bool_Bool
1735 | recent_read_profile_static(char **rf_path_return, int *rf_errno_return)
1736 | {
1737 | char *rf_path, *rf_common_path;
1738 | FILE *rf;
1739 |
1740 | /* set defaults */
1741 | recent.main_toolbar_show = true1;
1742 | recent.filter_toolbar_show = true1;
1743 | recent.wireless_toolbar_show = false0;
1744 | recent.packet_list_show = true1;
1745 | recent.tree_view_show = true1;
1746 | recent.byte_view_show = true1;
1747 | recent.packet_diagram_show = true1;
1748 | recent.statusbar_show = true1;
1749 | recent.packet_list_colorize = true1;
1750 | recent.capture_auto_scroll = true1;
1751 | recent.gui_time_format = TS_RELATIVE;
1752 | recent.gui_time_precision = TS_PREC_AUTO;
1753 | recent.gui_seconds_format = TS_SECONDS_DEFAULT;
1754 | recent.gui_zoom_level = 0;
1755 | recent.gui_bytes_view = BYTES_HEX;
1756 | recent.gui_bytes_encoding = BYTES_ENC_FROM_PACKET;
1757 | recent.gui_allow_hover_selection = true1;
1758 | recent.gui_follow_show = SHOW_ASCII;
1759 | recent.gui_follow_delta = FOLLOW_DELTA_NONE;
1760 | recent.gui_show_bytes_decode = DecodeAsNone;
1761 | recent.gui_show_bytes_show = SHOW_ASCII;
1762 |
1763 | /* defaults for the TCP Stream Graph Dialog */
1764 | recent.gui_tsgd_ma_window_size = 1.0;
1765 | recent.gui_tsgd_throughput_show = true1;
1766 | recent.gui_tsgd_goodput_show = false0;
1767 |
1768 | /* pane size of zero will autodetect */
1769 | recent.gui_geometry_main_upper_pane = 0;
1770 | recent.gui_geometry_main_lower_pane = 0;
1771 |
1772 | if (recent.gui_geometry_main) {
1 | Assuming field 'gui_geometry_main' is null | →
2 | ← | Taking false branch | →
1773 | g_free(recent.gui_geometry_main);
1774 | recent.gui_geometry_main = NULL((void*)0);
1775 | }
1776 |
1777 | if (recent.gui_geometry_main_master_split) {
3 | ← | Assuming field 'gui_geometry_main_master_split' is null | →
4 | ← | Taking false branch | →
1778 | g_free(recent.gui_geometry_main_master_split);
1779 | recent.gui_geometry_main_master_split = NULL((void*)0);
1780 | }
1781 | if (recent.gui_geometry_main_extra_split) {
5 | ← | Assuming field 'gui_geometry_main_extra_split' is null | →
6 | ← | Taking false branch | →
1782 | g_free(recent.gui_geometry_main_extra_split);
1783 | recent.gui_geometry_main_extra_split = NULL((void*)0);
1784 | }
1785 |
1786 | if (recent.col_width_list) {
7 | ← | Assuming field 'col_width_list' is null | →
8 | ← | Taking false branch | →
1787 | recent_free_column_width_info(&recent);
1788 | }
1789 |
1790 | if (recent.gui_fileopen_remembered_dir) {
9 | ← | Assuming field 'gui_fileopen_remembered_dir' is null | →
10 | ← | Taking false branch | →
1791 | g_free (recent.gui_fileopen_remembered_dir);
1792 | recent.gui_fileopen_remembered_dir = NULL((void*)0);
1793 | }
1794 |
1795 | if (recent.gui_additional_toolbars) {
11 | ← | Assuming field 'gui_additional_toolbars' is null | →
12 | ← | Taking false branch | →
1796 | g_list_free_full (recent.gui_additional_toolbars, g_free);
1797 | recent.gui_additional_toolbars = NULL((void*)0);
1798 | }
1799 |
1800 | if (recent.interface_toolbars) {
13 | ← | Assuming field 'interface_toolbars' is null | →
14 | ← | Taking false branch | →
1801 | g_list_free_full (recent.interface_toolbars, g_free);
1802 | recent.interface_toolbars = NULL((void*)0);
1803 | }
1804 |
1805 | /* Construct the pathname of the user's profile recent file. */
1806 | rf_path = get_persconffile_path(RECENT_FILE_NAME"recent", true1, application_configuration_environment_prefix());
1807 |
1808 | /* Read the user's recent file, if it exists. */
1809 | *rf_path_return = NULL((void*)0);
1810 | if ((rf = ws_fopenfopen(rf_path, "r")) != NULL((void*)0)) {
15 | ← | Taking true branch | →
1811 | /* We succeeded in opening it; read it. */
1812 | read_prefs_file(rf_path, rf, read_set_recent_pair_static, NULL((void*)0));
1813 | fclose(rf);
1814 |
1815 | /* XXX: The following code doesn't actually do anything since
1816 | * the "recent common file" always exists. Presumably the
1817 | * "if (!file_exists())" should actually be "if (file_exists())".
1818 | * However, I've left the code as is because this
1819 | * behaviour has existed for quite some time and I don't
1820 | * know what's supposed to happen at this point.
1821 | * ToDo: Determine if the "recent common file" should be read at this point
1822 | */
1823 | rf_common_path = get_persconffile_path(RECENT_COMMON_FILE_NAME"recent_common", false0, application_configuration_environment_prefix());
1824 | if (!file_exists(rf_common_path)) {
16 | ← | Assuming the condition is true | →
17 | ← | Taking true branch | →
1825 | /* Read older common settings from recent file */
1826 | rf = ws_fopenfopen(rf_path, "r");
18 | ← | Assuming pointer value is null | →
19 | ← | Assuming that 'fopen' fails | →
20 | ← | Value assigned to 'rf' | →
1827 | read_prefs_file(rf_path, rf, read_set_recent_common_pair_static, NULL((void*)0));
1828 | fclose(rf);
21 | ← | Null pointer passed to 1st parameter expecting 'nonnull'
1829 | }
1830 | g_free(rf_common_path);
1831 | } else {
1832 | /* We failed to open it. If we failed for some reason other than
1833 | "it doesn't exist", return the errno and the pathname, so our
1834 | caller can report the error. */
1835 | if (errno(*__errno_location ()) != ENOENT2) {
1836 | *rf_errno_return = errno(*__errno_location ());
1837 | *rf_path_return = rf_path;
1838 | return false0;
1839 | }
1840 | }
1841 | g_free(rf_path);
1842 | return true1;
1843 | }
1844 |
1845 | /* opens the user's recent file and read it out */
1846 | bool_Bool
1847 | recent_read_dynamic(char **rf_path_return, int *rf_errno_return)
1848 | {
1849 | char *rf_path;
1850 | FILE *rf;
1851 |
1852 |
1853 | /* Construct the pathname of the user's recent common file. */
1854 | rf_path = get_persconffile_path(RECENT_COMMON_FILE_NAME"recent_common", false0, application_configuration_environment_prefix());
1855 | if (!file_exists (rf_path)) {
1856 | /* Recent common file does not exist, read from default recent */
1857 | g_free (rf_path);
1858 | rf_path = get_persconffile_path(RECENT_FILE_NAME"recent", false0, application_configuration_environment_prefix());
1859 | }
1860 |
1861 | /* Read the user's recent file, if it exists. */
1862 | *rf_path_return = NULL((void*)0);
1863 | if ((rf = ws_fopenfopen(rf_path, "r")) != NULL((void*)0)) {
1864 | /* We succeeded in opening it; read it. */
1865 | read_prefs_file(rf_path, rf, read_set_recent_pair_dynamic, NULL((void*)0));
1866 | #if 0
1867 | /* set dfilter combobox to have an empty line */
1868 | dfilter_combo_add_empty();
1869 | #endif
1870 | /* We prepend new capture filters, so reverse them after adding
1871 | * all to keep the latest first.
1872 | */
1873 | cfilter_recent_reverse_all();
1874 | #ifdef HAVE_PCAP_REMOTE
1875 | remote_host_reverse();
1876 | #endif
1877 | fclose(rf);
1878 | } else {
1879 | /* We failed to open it. If we failed for some reason other than
1880 | "it doesn't exist", return the errno and the pathname, so our
1881 | caller can report the error. */
1882 | if (errno(*__errno_location ()) != ENOENT2) {
1883 | *rf_errno_return = errno(*__errno_location ());
1884 | *rf_path_return = rf_path;
1885 | return false0;
1886 | }
1887 | }
1888 | g_free(rf_path);
1889 | return true1;
1890 | }
1891 |
1892 | void
1893 | recent_insert_column(int col)
1894 | {
1895 | col_width_data *col_w;
1896 |
1897 | col_w = g_new(col_width_data, 1)((col_width_data *) g_malloc_n ((1), sizeof (col_width_data)) );
1898 | col_w->width = -1;
1899 | col_w->xalign = COLUMN_XALIGN_DEFAULT0;
1900 | recent.col_width_list = g_list_insert(recent.col_width_list, col_w, col);
1901 | }
1902 |
1903 | void
1904 | recent_remove_column(int col)
1905 | {
1906 | GList *col_l = g_list_nth(recent.col_width_list, col);
1907 | col_width_data *col_w;
1908 |
1909 | if (!col_l) return;
1910 |
1911 | col_w = (col_width_data*)col_l->data;
1912 |
1913 | if (col_w) {
1914 | free_col_width_data(col_w);
1915 | }
1916 |
1917 | recent.col_width_list = g_list_delete_link(recent.col_width_list, col_l);
1918 | }
1919 |
1920 | int
1921 | recent_get_column_width(int col)
1922 | {
1923 | col_width_data *col_w;
1924 |
1925 | col_w = g_list_nth_data(recent.col_width_list, col);
1926 | if (col_w) {
1927 | return col_w->width;
1928 | } else {
1929 | /* Make sure the recent column list isn't out of sync with the
1930 | * number of columns (e.g., for a brand new profile.)
1931 | */
1932 | for (unsigned colnr = g_list_length(recent.col_width_list); colnr < g_list_length(prefs.col_list); colnr++) {
1933 | recent_insert_column(colnr);
1934 | }
1935 | }
1936 |
1937 | return -1;
1938 | }
1939 |
1940 | void
1941 | recent_set_column_width(int col, int width)
1942 | {
1943 | col_width_data *col_w;
1944 |
1945 | col_w = g_list_nth_data(recent.col_width_list, col);
1946 | if (col_w) {
1947 | col_w->width = width;
1948 | } else {
1949 | /* Make sure the recent column list isn't out of sync with the
1950 | * number of columns (e.g., for a brand new profile.)
1951 | */
1952 | for (unsigned colnr = g_list_length(recent.col_width_list); colnr < g_list_length(prefs.col_list); colnr++) {
1953 | recent_insert_column(colnr);
1954 | }
1955 | col_w = g_list_nth_data(recent.col_width_list, col);
1956 | if (col_w) {
1957 | col_w->width = width;
1958 | }
1959 | }
1960 | }
1961 |
1962 | char
1963 | recent_get_column_xalign(int col)
1964 | {
1965 | col_width_data *col_w;
1966 |
1967 | col_w = g_list_nth_data(recent.col_width_list, col);
1968 | if (col_w) {
1969 | return col_w->xalign;
1970 | } else {
1971 | /* Make sure the recent column list isn't out of sync with the
1972 | * number of columns (e.g., for a brand new profile.)
1973 | */
1974 | for (unsigned colnr = g_list_length(recent.col_width_list); colnr < g_list_length(prefs.col_list); colnr++) {
1975 | recent_insert_column(colnr);
1976 | }
1977 | }
1978 |
1979 | return COLUMN_XALIGN_DEFAULT0;
1980 | }
1981 |
1982 | void
1983 | recent_set_column_xalign(int col, char xalign)
1984 | {
1985 | col_width_data *col_w;
1986 |
1987 | col_w = g_list_nth_data(recent.col_width_list, col);
1988 | if (col_w) {
1989 | col_w->xalign = xalign;
1990 | } else {
1991 | /* Make sure the recent column list isn't out of sync with the
1992 | * number of columns (e.g., for a brand new profile.)
1993 | */
1994 | for (unsigned colnr = g_list_length(recent.col_width_list); colnr < g_list_length(prefs.col_list); colnr++) {
1995 | recent_insert_column(colnr);
1996 | }
1997 | col_w = g_list_nth_data(recent.col_width_list, col);
1998 | if (col_w) {
1999 | col_w->xalign = xalign;
2000 | }
2001 | }
2002 | }
2003 |
2004 | void
2005 | recent_init(void)
2006 | {
2007 | memset(&recent, 0, sizeof(recent_settings_t));
2008 | }
2009 |
2010 | void
2011 | recent_cleanup(void)
2012 | {
2013 | recent_free_column_width_info(&recent);
2014 | g_free(recent.gui_geometry_main);
2015 | g_free(recent.gui_geometry_main_master_split);
2016 | g_free(recent.gui_geometry_main_extra_split);
2017 | g_free(recent.gui_fileopen_remembered_dir);
2018 | g_list_free_full(recent.gui_additional_toolbars, g_free);
2019 | g_list_free_full(recent.interface_toolbars, g_free);
2020 | prefs_clear_string_list(recent.conversation_tabs);
2021 | prefs_clear_string_list(recent.conversation_tabs_columns);
2022 | prefs_clear_string_list(recent.endpoint_tabs);
2023 | prefs_clear_string_list(recent.endpoint_tabs_columns);
2024 | prefs_clear_string_list(recent.custom_colors);
2025 | }