### Bug Summary

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