### Bug Summary

File: | builds/wireshark/wireshark/epan/prefs.c
Warning: | line 4927, column 21 Value of 'errno' was not checked and may be overwritten by function 'getc_unlocked'

### 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 prefs.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 -isystem /builds/wireshark/wireshark/epan -isystem /builds/wireshark/wireshark/build/epan -isystem /usr/include/mit-krb5 -isystem /usr/include/libxml2 -isystem /usr/include/lua5.4 -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D WS_BUILD_DLL -D WS_DEBUG -D WS_DEBUG_UTF_8 -D epan_EXPORTS -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -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-03-28-100342-3641-1 -x c /builds/wireshark/wireshark/epan/prefs.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 | /* prefs.c
2 | * Routines for handling preferences
3 | *
4 | * Wireshark - Network traffic analyzer
5 | * By Gerald Combs <gerald@wireshark.org>
6 | * Copyright 1998 Gerald Combs
7 | *
8 | * SPDX-License-Identifier: GPL-2.0-or-later
9 | */
10 |
11 | #include "config.h"
12 | #define WS_LOG_DOMAIN"Epan" LOG_DOMAIN_EPAN"Epan"
13 |
14 | #include "ws_diag_control.h"
15 |
16 | #include <stdlib.h>
17 | #include <string.h>
18 | #include <errno(*__errno_location ()).h>
19 | #ifdef _WIN32
20 | #include <windows.h>
21 | #endif
22 |
23 | #include <glib.h>
24 |
25 | #include <stdio.h>
26 | #include <wsutil/filesystem.h>
27 | #include <epan/addr_resolv.h>
28 | #include <epan/oids.h>
29 | #include <epan/maxmind_db.h>
30 | #include <epan/packet.h>
31 | #include <epan/prefs.h>
32 | #include <epan/proto.h>
33 | #include <epan/strutil.h>
34 | #include <epan/column.h>
35 | #include <epan/decode_as.h>
36 | #include <ui/capture_opts.h>
37 | #include <wsutil/file_util.h>
38 | #include <wsutil/report_message.h>
39 | #include <wsutil/wslog.h>
40 | #include <wsutil/ws_assert.h>
41 | #include <wsutil/array.h>
42 |
43 | #include <epan/prefs-int.h>
44 | #include <epan/uat-int.h>
45 |
46 | #include "epan/filter_expressions.h"
47 | #include "epan/aggregation_fields.h"
48 |
49 | #include "epan/wmem_scopes.h"
50 | #include <epan/stats_tree.h>
51 |
52 | #define REG_HKCU_WIRESHARK_KEY"Software\\Wireshark" "Software\\Wireshark"
53 |
54 | /*
55 | * Module alias.
56 | */
57 | typedef struct pref_module_alias {
58 | const char *name; /**< name of module alias */
59 | module_t *module; /**< module for which it's an alias */
60 | } module_alias_t;
61 |
62 | /* Internal functions */
63 | static void prefs_register_modules(void);
64 | static module_t *prefs_find_module_alias(const char *name);
65 | static prefs_set_pref_e set_pref(char*, const char*, void *, bool_Bool);
66 | static void free_col_info(GList *);
67 | static void prefs_set_global_defaults(wmem_allocator_t* pref_scope, const char** col_fmt, int num_cols);
68 | static bool_Bool prefs_is_column_visible(const char *cols_hidden, int col);
69 | static bool_Bool prefs_is_column_fmt_visible(const char *cols_hidden, fmt_data *cfmt);
70 | static int find_val_for_string(const char *needle, const enum_val_t *haystack, int default_value);
71 |
72 | #define PF_NAME"preferences" "preferences"
73 | #define OLD_GPF_NAME"wireshark.conf" "wireshark.conf" /* old name for global preferences file */
74 |
75 | static char *gpf_path;
76 | static char *cols_hidden_list;
77 | static char *cols_hidden_fmt_list;
78 | static bool_Bool gui_theme_is_dark;
79 |
80 | e_prefs prefs;
81 |
82 | static const enum_val_t gui_console_open_type[] = {
83 | {"NEVER", "NEVER", LOG_CONSOLE_OPEN_NEVER},
84 | {"AUTOMATIC", "AUTOMATIC", LOG_CONSOLE_OPEN_AUTO},
85 | {"ALWAYS", "ALWAYS", LOG_CONSOLE_OPEN_ALWAYS},
86 | {NULL((void*)0), NULL((void*)0), -1}
87 | };
88 |
89 | static const enum_val_t gui_version_placement_type[] = {
90 | {"WELCOME", "WELCOME", version_welcome_only},
91 | {"TITLE", "TITLE", version_title_only},
92 | {"BOTH", "BOTH", version_both},
93 | {"NEITHER", "NEITHER", version_neither},
94 | {NULL((void*)0), NULL((void*)0), -1}
95 | };
96 |
97 | static const enum_val_t gui_fileopen_style[] = {
98 | {"LAST_OPENED", "LAST_OPENED", FO_STYLE_LAST_OPENED0},
99 | {"SPECIFIED", "SPECIFIED", FO_STYLE_SPECIFIED1},
100 | {"CWD", "CWD", FO_STYLE_CWD2},
101 | {NULL((void*)0), NULL((void*)0), -1}
102 | };
103 |
104 | static const enum_val_t gui_toolbar_style[] = {
105 | {"ICONS", "ICONS", 0},
106 | {"TEXT", "TEXT", 1},
107 | {"BOTH", "BOTH", 2},
108 | {NULL((void*)0), NULL((void*)0), -1}
109 | };
110 |
111 | static const enum_val_t gui_layout_content[] = {
112 | {"NONE", "NONE", 0},
113 | {"PLIST", "PLIST", 1},
114 | {"PDETAILS", "PDETAILS", 2},
115 | {"PBYTES", "PBYTES", 3},
116 | {"PDIAGRAM", "PDIAGRAM", 4},
117 | {NULL((void*)0), NULL((void*)0), -1}
118 | };
119 |
120 | static const enum_val_t gui_packet_dialog_layout[] = {
121 | {"vertical", "Vertical (Stacked)", layout_vertical},
122 | {"horizontal", "Horizontal (Side-by-side)", layout_horizontal},
123 | {NULL((void*)0), NULL((void*)0), -1}
124 | };
125 |
126 | static const enum_val_t gui_update_channel[] = {
127 | {"DEVELOPMENT", "DEVELOPMENT", UPDATE_CHANNEL_DEVELOPMENT},
128 | {"STABLE", "STABLE", UPDATE_CHANNEL_STABLE},
129 | {NULL((void*)0), NULL((void*)0), -1}
130 | };
131 |
132 | static const enum_val_t gui_selection_style[] = {
133 | {"DEFAULT", "DEFAULT", COLOR_STYLE_DEFAULT0},
134 | {"FLAT", "FLAT", COLOR_STYLE_FLAT1},
135 | {"GRADIENT", "GRADIENT", COLOR_STYLE_GRADIENT2},
136 | {NULL((void*)0), NULL((void*)0), -1}
137 | };
138 |
139 | static const enum_val_t gui_packet_list_multi_color_modes[] = {
140 | {"off", "Off", PACKET_LIST_MULTI_COLOR_MODE_OFF},
141 | {"scrollbar_only", "Scrollbar Only", PACKET_LIST_MULTI_COLOR_MODE_SCROLLBAR_ONLY},
142 | {"full_stripes", "Full Stripes", PACKET_LIST_MULTI_COLOR_MODE_FULL},
143 | {"shift_right", "Shift Right", PACKET_LIST_MULTI_COLOR_MODE_SHIFT_RIGHT},
144 | {NULL((void*)0), NULL((void*)0), -1}
145 | };
146 |
147 | static const enum_val_t gui_packet_list_multi_color_separators[] = {
148 | {"vertical", "Vertical", PACKET_LIST_MULTI_COLOR_SEPARATOR_VERTICAL},
149 | {"diagonal", "Diagonal", PACKET_LIST_MULTI_COLOR_SEPARATOR_DIAGONAL},
150 | {"bubble", "Bubble", PACKET_LIST_MULTI_COLOR_SEPARATOR_BUBBLE},
151 | {NULL((void*)0), NULL((void*)0), -1}
152 | };
153 |
154 | static const enum_val_t gui_color_scheme[] = {
155 | {"system", "System Default", COLOR_SCHEME_DEFAULT0},
156 | {"light", "Light Mode", COLOR_SCHEME_LIGHT1},
157 | {"dark", "Dark Mode", COLOR_SCHEME_DARK2},
158 | {NULL((void*)0), NULL((void*)0), -1}
159 | };
160 |
161 | static const enum_val_t gui_packet_list_copy_format_options_for_keyboard_shortcut[] = {
162 | {"TEXT", "Text", COPY_FORMAT_TEXT},
163 | {"CSV", "CSV", COPY_FORMAT_CSV},
164 | {"YAML", "YAML", COPY_FORMAT_YAML},
165 | {"HTML", "HTML", COPY_FORMAT_HTML},
166 | {NULL((void*)0), NULL((void*)0), -1}
167 | };
168 |
169 | /* None : Historical behavior, no deinterlacing */
170 | #define CONV_DEINT_CHOICE_NONE0 0
171 | /* MI : MAC & Interface */
172 | #define CONV_DEINT_CHOICE_MI0x04 + 0x02 CONV_DEINT_KEY_MAC0x04 + CONV_DEINT_KEY_INTERFACE0x02
173 | /* VM : VLAN & MAC */
174 | #define CONV_DEINT_CHOICE_VM0x08 + 0x04 CONV_DEINT_KEY_VLAN0x08 + CONV_DEINT_KEY_MAC0x04
175 | /* VMI : VLAN & MAC & Interface */
176 | #define CONV_DEINT_CHOICE_VMI0x08 + 0x04 + 0x02 CONV_DEINT_KEY_VLAN0x08 + CONV_DEINT_KEY_MAC0x04 + CONV_DEINT_KEY_INTERFACE0x02
177 |
178 | static const enum_val_t conv_deint_options[] = {
179 | {"NONE", "NONE", CONV_DEINT_CHOICE_NONE0},
180 | {".MI", ".MI", CONV_DEINT_CHOICE_MI0x04 + 0x02 },
181 | {"VM.", "VM.", CONV_DEINT_CHOICE_VM0x08 + 0x04 },
182 | {"VMI", "VMI", CONV_DEINT_CHOICE_VMI0x08 + 0x04 + 0x02 },
183 | {NULL((void*)0), NULL((void*)0), -1}
184 | };
185 |
186 | static const enum_val_t abs_time_format_options[] = {
187 | {"NEVER", "Never", ABS_TIME_ASCII_NEVER},
188 | {"TREE", "Protocol tree only", ABS_TIME_ASCII_TREE},
189 | {"COLUMN", "Protocol tree and columns", ABS_TIME_ASCII_COLUMN},
190 | {"ALWAYS", "Always", ABS_TIME_ASCII_ALWAYS},
191 | {NULL((void*)0), NULL((void*)0), -1}
192 | };
193 |
194 | static int num_capture_cols = 7;
195 | static const char *capture_cols[7] = {
196 | "INTERFACE",
197 | "LINK",
198 | "PMODE",
199 | "SNAPLEN",
200 | "MONITOR",
201 | "BUFFER",
202 | "FILTER"
203 | };
204 | #define CAPTURE_COL_TYPE_DESCRIPTION"Possible values: INTERFACE, LINK, PMODE, SNAPLEN, MONITOR, BUFFER, FILTER\n" \
205 | "Possible values: INTERFACE, LINK, PMODE, SNAPLEN, MONITOR, BUFFER, FILTER\n"
206 |
207 | static const enum_val_t gui_packet_list_elide_mode[] = {
208 | {"LEFT", "LEFT", ELIDE_LEFT},
209 | {"RIGHT", "RIGHT", ELIDE_RIGHT},
210 | {"MIDDLE", "MIDDLE", ELIDE_MIDDLE},
211 | {"NONE", "NONE", ELIDE_NONE},
212 | {NULL((void*)0), NULL((void*)0), -1}
213 | };
214 |
215 | /** Struct to hold preference data */
216 | struct preference {
217 | const char *name; /**< name of preference */
218 | const char *title; /**< title to use in GUI */
219 | const char *description; /**< human-readable description of preference */
220 | wmem_allocator_t* scope; /**< memory scope allocator for this preference */
221 | int ordinal; /**< ordinal number of this preference */
222 | pref_type_e type; /**< type of that preference */
223 | bool_Bool obsolete; /**< obsolete preference flag */
224 | unsigned int effect_flags; /**< Flags of types effected by preference (PREF_EFFECT_DISSECTION, PREF_EFFECT_CAPTURE, etc).
225 | Flags must be non-zero to ensure saving to disk */
226 | union { /* The Qt preference code assumes that these will all be pointers (and unique) */
227 | unsigned *uint;
228 | bool_Bool *boolp;
229 | int *enump;
230 | int* intp;
231 | double* floatp;
232 | char **string;
233 | range_t **range;
234 | struct epan_uat* uat;
235 | color_t *colorp;
236 | GList** list;
237 | } varp; /**< pointer to variable storing the value */
238 | union {
239 | unsigned uint;
240 | bool_Bool boolval;
241 | int enumval;
242 | int intval;
243 | double floatval;
244 | char *string;
245 | range_t *range;
246 | color_t color;
247 | GList* list;
248 | } stashed_val; /**< original value, when editing from the GUI */
249 | union {
250 | unsigned uint;
251 | bool_Bool boolval;
252 | int enumval;
253 | int intval;
254 | double floatval;
255 | char *string;
256 | range_t *range;
257 | color_t color;
258 | GList* list;
259 | } default_val; /**< the default value of the preference */
260 | union {
261 | unsigned base; /**< input/output base, for PREF_UINT */
262 | uint32_t max_value; /**< maximum value of a range */
263 | struct {
264 | const enum_val_t *enumvals; /**< list of name & values */
265 | bool_Bool radio_buttons; /**< true if it should be shown as
266 | radio buttons rather than as an
267 | option menu or combo box in
268 | the preferences tab */
269 | } enum_info; /**< for PREF_ENUM */
270 | } info; /**< display/text file information */
271 | struct pref_custom_cbs custom_cbs; /**< for PREF_CUSTOM */
272 | const char *dissector_table; /**< for PREF_DECODE_AS_RANGE */
273 | const char *dissector_desc; /**< for PREF_DECODE_AS_RANGE */
274 | };
275 |
276 | const char* prefs_get_description(pref_t *pref)
277 | {
278 | return pref->description;
279 | }
280 |
281 | const char* prefs_get_title(pref_t *pref)
282 | {
283 | return pref->title;
284 | }
285 |
286 | int prefs_get_type(pref_t *pref)
287 | {
288 | return pref->type;
289 | }
290 |
291 | const char* prefs_get_name(pref_t *pref)
292 | {
293 | return pref->name;
294 | }
295 |
296 | uint32_t prefs_get_max_value(pref_t *pref)
297 | {
298 | return pref->info.max_value;
299 | }
300 |
301 | const char* prefs_get_dissector_table(pref_t *pref)
302 | {
303 | return pref->dissector_table;
304 | }
305 |
306 | static const char* prefs_get_dissector_description(pref_t *pref)
307 | {
308 | return pref->dissector_desc;
309 | }
310 |
311 | /*
312 | * List of all modules with preference settings.
313 | */
314 | static wmem_tree_t *prefs_modules;
315 |
316 | /*
317 | * List of all modules that should show up at the top level of the
318 | * tree in the preference dialog box.
319 | */
320 | static wmem_tree_t *prefs_top_level_modules;
321 |
322 | /*
323 | * List of aliases for modules.
324 | */
325 | static wmem_tree_t *prefs_module_aliases;
326 |
327 | /*
328 | * Regex to match line terminators. Prefs are written and read to file line by
329 | * line, so unescaped line terminators cause unexpected behavior.
330 | */
331 | static GRegex *prefs_regex;
332 |
333 | /** Sets up memory used by proto routines. Called at program startup */
334 | void
335 | prefs_init(const char** col_fmt, int num_cols)
336 | {
337 | memset(&prefs, 0, sizeof(prefs));
338 | prefs_modules = wmem_tree_new(wmem_epan_scope());
339 | prefs_top_level_modules = wmem_tree_new(wmem_epan_scope());
340 | prefs_module_aliases = wmem_tree_new(wmem_epan_scope());
341 | if (!prefs_regex)
342 | prefs_regex = g_regex_new("\\s*\\R\\s*", (GRegexCompileFlags)G_REGEX_OPTIMIZE,
343 | (GRegexMatchFlags)G_REGEX_MATCH_BSR_ANYCRLF, NULL((void*)0));
344 |
345 | prefs_set_global_defaults(wmem_epan_scope(), col_fmt, num_cols);
346 | prefs_register_modules();
347 | }
348 |
349 | const wmem_tree_t* prefs_get_module_tree(void)
350 | {
351 | return prefs_modules;
352 | }
353 |
354 | /*
355 | * Free the strings for a string-like preference.
356 | */
357 | static void
358 | free_string_like_preference(pref_t *pref)
359 | {
360 | wmem_free(pref->scope, *pref->varp.string);
361 | *pref->varp.string = NULL((void*)0);
362 | wmem_free(pref->scope, pref->default_val.string);
363 | pref->default_val.string = NULL((void*)0);
364 | }
365 |
366 | void
367 | pref_free_individual(void *data, void *user_data _U___attribute__((unused)))
368 | {
369 | pref_t *pref = (pref_t *)data;
370 |
371 | switch (pref->type) {
372 | case PREF_BOOL:
373 | case PREF_ENUM:
374 | case PREF_UINT:
375 | case PREF_INT:
376 | case PREF_FLOAT:
377 | case PREF_STATIC_TEXT:
378 | case PREF_UAT:
379 | case PREF_COLOR:
380 | break;
381 | case PREF_STRING:
382 | case PREF_SAVE_FILENAME:
383 | case PREF_OPEN_FILENAME:
384 | case PREF_DIRNAME:
385 | case PREF_PASSWORD:
386 | case PREF_DISSECTOR:
387 | free_string_like_preference(pref);
388 | break;
389 | case PREF_RANGE:
390 | case PREF_DECODE_AS_RANGE:
391 | wmem_free(pref->scope, *pref->varp.range);
392 | *pref->varp.range = NULL((void*)0);
393 | wmem_free(pref->scope, pref->default_val.range);
394 | pref->default_val.range = NULL((void*)0);
395 | break;
396 | case PREF_CUSTOM:
397 | if (strcmp(pref->name, "columns") == 0)
398 | pref->stashed_val.boolval = true1;
399 | pref->custom_cbs.free_cb(pref);
400 | break;
401 | /* non-generic preferences */
402 | case PREF_PROTO_TCP_SNDAMB_ENUM:
403 | break;
404 | }
405 |
406 | wmem_free(pref->scope, pref);
407 | }
408 |
409 | static unsigned
410 | free_module_prefs(module_t *module, void *data _U___attribute__((unused)))
411 | {
412 | if (module->prefs) {
413 | g_list_foreach(module->prefs, pref_free_individual, NULL((void*)0));
414 | g_list_free(module->prefs);
415 | }
416 | module->prefs = NULL((void*)0);
417 | module->numprefs = 0;
418 | if (module->submodules) {
419 | prefs_module_list_foreach(module->submodules, free_module_prefs, NULL((void*)0), false0);
420 | }
421 | /* We don't free the actual module: its submodules pointer points to
422 | a wmem_tree and the module itself is stored in a wmem_tree
423 | */
424 |
425 | return 0;
426 | }
427 |
428 | /** Frees memory used by proto routines. Called at program shutdown */
429 | void
430 | prefs_cleanup(void)
431 | {
432 | /* This isn't strictly necessary since we're exiting anyway, but let's
433 | * do what clean up we can.
434 | */
435 | prefs_module_list_foreach(prefs_modules, free_module_prefs, NULL((void*)0), false0);
436 |
437 | /* Clean the uats */
438 | uat_cleanup();
439 |
440 | /* Shut down mmdbresolve */
441 | maxmind_db_pref_cleanup();
442 |
443 | g_free(prefs.saved_at_version);
444 | g_free(gpf_path);
445 | gpf_path = NULL((void*)0);
446 | g_regex_unref(prefs_regex);
447 | prefs_regex = NULL((void*)0);
448 | }
449 |
450 | void prefs_set_gui_theme_is_dark(bool_Bool is_dark)
451 | {
452 | gui_theme_is_dark = is_dark;
453 | }
454 |
455 | static void
456 | prefs_deregister_module(wmem_tree_t* pref_tree, const char *name, const char *title, wmem_tree_t *all_modules)
457 | {
458 | /* Remove this module from the list of all modules */
459 | module_t *module = (module_t *)wmem_tree_remove_string(all_modules, name, WMEM_TREE_STRING_NOCASE0x00000001);
460 |
461 | if (!module)
462 | return;
463 |
464 | wmem_tree_remove_string(pref_tree, title, WMEM_TREE_STRING_NOCASE0x00000001);
465 | free_module_prefs(module, NULL((void*)0));
466 | wmem_free(module->scope, module);
467 | }
468 |
469 | static void
470 | prefs_update_existing_subtree(module_t* module, const char* name, const char* description,
471 | const char* help, void (*apply_cb)(void), wmem_tree_t* master_pref_tree)
472 | {
473 | module->name = name;
474 | module->apply_cb = apply_cb;
475 | module->description = description;
476 | module->help = help;
477 |
478 | /* Registering it as a module (not just as a subtree) twice is an
479 | * error in the code for the same reason as below. */
480 | if (prefs_find_module(name) != NULL((void*)0)) {
481 | ws_error("Preference module \"%s\" is being registered twice", name)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 481 , __func__, "Preference module \"%s\" is being registered twice" , name);
482 | }
483 | wmem_tree_insert_string(master_pref_tree, name, module,
484 | WMEM_TREE_STRING_NOCASE0x00000001);
485 | }
486 |
487 | static module_t*
488 | prefs_create_module(wmem_allocator_t* scope, module_t* parent, const char* name,
489 | const char* title, const char* description,
490 | const char* help, void (*apply_cb)(void),
491 | bool_Bool use_gui)
492 | {
493 | module_t* module = wmem_new(scope, module_t)((module_t*)wmem_alloc((scope), sizeof(module_t)));
494 | module->name = name;
495 | module->title = title;
496 | module->description = description;
497 | module->help = help;
498 | module->apply_cb = apply_cb;
499 | module->scope = scope;
500 | module->prefs = NULL((void*)0); /* no preferences, to start */
501 | module->parent = parent;
502 | module->submodules = NULL((void*)0); /* no submodules, to start */
503 | module->numprefs = 0;
504 | module->prefs_changed_flags = 0;
505 | module->obsolete = false0;
506 | module->use_gui = use_gui;
507 | /* A module's preferences affects dissection unless otherwise told */
508 | module->effect_flags = PREF_EFFECT_DISSECTION(1u << 0);
509 |
510 | return module;
511 | }
512 |
513 | /*
514 | * Register a module that will have preferences.
515 | * Specify the module under which to register it, the name used for the
516 | * module in the preferences file, the title used in the tab for it
517 | * in a preferences dialog box, and a routine to call back when the
518 | * preferences are applied.
519 | */
520 | module_t*
521 | prefs_register_module(wmem_tree_t* pref_tree, wmem_tree_t* master_pref_tree, const char* name, const char* title,
522 | const char* description, const char* help, void (*apply_cb)(void),
523 | const bool_Bool use_gui)
524 | {
525 | module_t* module;
526 |
527 | /* this module may have been created as a subtree item previously */
528 | if ((module = (module_t*)wmem_tree_lookup_string(pref_tree, title, WMEM_TREE_STRING_NOCASE0x00000001))) {
529 | /* the module is currently a subtree */
530 | prefs_update_existing_subtree(module, name, description, help, apply_cb, master_pref_tree);
531 | return module;
532 | }
533 |
534 | module = prefs_create_module(wmem_tree_get_data_scope(master_pref_tree), NULL((void*)0), name, title, description, help, apply_cb, use_gui);
535 |
536 | /* Accept any letter case to conform with protocol names. ASN1 protocols
537 | * don't use lower case names, so we can't require lower case.
538 | */
539 | if (module_check_valid_name(name, false0) != '\0') {
540 | ws_error("Preference module \"%s\" contains invalid characters", name)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 540 , __func__, "Preference module \"%s\" contains invalid characters" , name);
541 | }
542 |
543 | /*
544 | * Make sure there's not already a module with that
545 | * name. Crash if there is, as that's an error in the
546 | * code, and the code has to be fixed not to register
547 | * more than one module with the same name.
548 | *
549 | * We search the list of all modules; the subtree stuff
550 | * doesn't require preferences in subtrees to have names
551 | * that reflect the subtree they're in (that would require
552 | * protocol preferences to have a bogus "protocol.", or
553 | * something such as that, to be added to all their names).
554 | */
555 | if (wmem_tree_lookup_string(master_pref_tree, name, WMEM_TREE_STRING_NOCASE0x00000001) != NULL((void*)0))
556 | ws_error("Preference module \"%s\" is being registered twice", name)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 556 , __func__, "Preference module \"%s\" is being registered twice" , name);
557 |
558 | /*
559 | * Insert this module in the list of all modules.
560 | */
561 | wmem_tree_insert_string(master_pref_tree, name, module, WMEM_TREE_STRING_NOCASE0x00000001);
562 |
563 | /*
564 | * It goes at the top.
565 | */
566 | wmem_tree_insert_string(pref_tree, title, module, WMEM_TREE_STRING_NOCASE0x00000001);
567 |
568 | return module;
569 | }
570 |
571 | static module_t*
572 | prefs_register_submodule(module_t* parent, wmem_tree_t* master_pref_tree, const char* name, const char* title,
573 | const char* description, const char* help, void (*apply_cb)(void),
574 | const bool_Bool use_gui)
575 | {
576 | module_t* module;
577 |
578 | /* this module may have been created as a subtree item previously */
579 | if ((module = (module_t*)wmem_tree_lookup_string(parent->submodules, title, WMEM_TREE_STRING_NOCASE0x00000001))) {
580 | /* the module is currently a subtree */
581 | prefs_update_existing_subtree(module, name, description, help, apply_cb, master_pref_tree);
582 | return module;
583 | }
584 |
585 | module = prefs_create_module(wmem_tree_get_data_scope(master_pref_tree), parent, name, title, description, help, apply_cb, use_gui);
586 |
587 | /* Accept any letter case to conform with protocol names. ASN1 protocols
588 | * don't use lower case names, so we can't require lower case. */
589 | if (module_check_valid_name(name, false0) != '\0') {
590 | ws_error("Preference module \"%s\" contains invalid characters", name)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 590 , __func__, "Preference module \"%s\" contains invalid characters" , name);
591 | }
592 |
593 | /*
594 | * Make sure there's not already a module with that
595 | * name. Crash if there is, as that's an error in the
596 | * code, and the code has to be fixed not to register
597 | * more than one module with the same name.
598 | *
599 | * We search the list of all modules; the subtree stuff
600 | * doesn't require preferences in subtrees to have names
601 | * that reflect the subtree they're in (that would require
602 | * protocol preferences to have a bogus "protocol.", or
603 | * something such as that, to be added to all their names).
604 | */
605 | if (wmem_tree_lookup_string(master_pref_tree, name, WMEM_TREE_STRING_NOCASE0x00000001) != NULL((void*)0))
606 | ws_error("Preference module \"%s\" is being registered twice", name)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 606 , __func__, "Preference module \"%s\" is being registered twice" , name);
607 |
608 | /*
609 | * Insert this module in the list of all modules.
610 | */
611 | wmem_tree_insert_string(master_pref_tree, name, module, WMEM_TREE_STRING_NOCASE0x00000001);
612 |
613 | /*
614 | * It goes into the list for this module.
615 | */
616 |
617 | if (parent->submodules == NULL((void*)0))
618 | parent->submodules = wmem_tree_new(parent->scope);
619 |
620 | wmem_tree_insert_string(parent->submodules, title, module, WMEM_TREE_STRING_NOCASE0x00000001);
621 |
622 | return module;
623 | }
624 |
625 | /*
626 | * Register a subtree that will have modules under it.
627 | * Specify the module under which to register it or NULL to register it
628 | * at the top level and the title used in the tab for it in a preferences
629 | * dialog box.
630 | */
631 | static module_t*
632 | prefs_register_subtree(module_t* parent, wmem_tree_t* master_pref_tree, const char* title, const char* description,
633 | void (*apply_cb)(void))
634 | {
635 | module_t* module;
636 |
637 | /* this module may have been created as a subtree item previously */
638 | if ((module = (module_t*)wmem_tree_lookup_string(parent->submodules, title, WMEM_TREE_STRING_NOCASE0x00000001))) {
639 | /* the module is currently a subtree */
640 | prefs_update_existing_subtree(module, NULL((void*)0), description, NULL((void*)0), apply_cb, master_pref_tree);
641 | return module;
642 | }
643 |
644 | module = prefs_create_module(wmem_tree_get_data_scope(master_pref_tree), parent, NULL((void*)0), title, description, NULL((void*)0), apply_cb, parent->use_gui);
645 |
646 |
647 | /*
648 | * It goes into the list for this module.
649 | */
650 | if (parent->submodules == NULL((void*)0))
651 | parent->submodules = wmem_tree_new(parent->scope);
652 |
653 | wmem_tree_insert_string(parent->submodules, title, module, WMEM_TREE_STRING_NOCASE0x00000001);
654 |
655 | return module;
656 | }
657 |
658 | void
659 | prefs_register_module_alias(const char *name, module_t *module)
660 | {
661 | module_alias_t *alias;
662 |
663 | /*
664 | * Accept any name that can occur in protocol names. We allow upper-case
665 | * letters, to handle the Diameter dissector having used "Diameter" rather
666 | * than "diameter" as its preference module name in the past.
667 | *
668 | * Crash if the name is invalid, as that's an error in the code, but the name
669 | * can be used on the command line, and shouldn't require quoting, etc.
670 | */
671 | if (module_check_valid_name(name, false0) != '\0') {
672 | ws_error("Preference module alias \"%s\" contains invalid characters", name)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 672 , __func__, "Preference module alias \"%s\" contains invalid characters" , name);
673 | }
674 |
675 | /*
676 | * Make sure there's not already an alias with that
677 | * name. Crash if there is, as that's an error in the
678 | * code, and the code has to be fixed not to register
679 | * more than one alias with the same name.
680 | *
681 | * We search the list of all aliases.
682 | */
683 | if (prefs_find_module_alias(name) != NULL((void*)0))
684 | ws_error("Preference module alias \"%s\" is being registered twice", name)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 684 , __func__, "Preference module alias \"%s\" is being registered twice" , name);
685 |
686 | alias = wmem_new(wmem_tree_get_data_scope(prefs_module_aliases), module_alias_t)((module_alias_t*)wmem_alloc((wmem_tree_get_data_scope(prefs_module_aliases )), sizeof(module_alias_t)));
687 | alias->name = name;
688 | alias->module = module;
689 |
690 | /*
691 | * Insert this module in the list of all modules.
692 | */
693 | wmem_tree_insert_string(prefs_module_aliases, name, alias, WMEM_TREE_STRING_NOCASE0x00000001);
694 | }
695 |
696 | /*
697 | * Register that a protocol has preferences.
698 | */
699 | static module_t *protocols_module;
700 |
701 | module_t *
702 | prefs_register_protocol(int id, void (*apply_cb)(void))
703 | {
704 | protocol_t *protocol = find_protocol_by_id(id);
705 | if (protocol == NULL((void*)0))
706 | ws_error("Protocol preferences being registered with an invalid protocol ID")ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 706 , __func__, "Protocol preferences being registered with an invalid protocol ID" );
707 | return prefs_register_submodule(protocols_module, prefs_modules,
708 | proto_get_protocol_filter_name(id),
709 | proto_get_protocol_short_name(protocol),
710 | proto_get_protocol_name(id), NULL((void*)0), apply_cb, true1);
711 | }
712 |
713 | void
714 | prefs_deregister_protocol (int id)
715 | {
716 | protocol_t *protocol = find_protocol_by_id(id);
717 | if (protocol == NULL((void*)0))
718 | ws_error("Protocol preferences being de-registered with an invalid protocol ID")ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 718 , __func__, "Protocol preferences being de-registered with an invalid protocol ID" );
719 | prefs_deregister_module (protocols_module->submodules,
720 | proto_get_protocol_filter_name(id),
721 | proto_get_protocol_short_name(protocol),
722 | prefs_modules);
723 | }
724 |
725 | module_t *
726 | prefs_register_protocol_subtree(const char *subtree, int id, void (*apply_cb)(void))
727 | {
728 | protocol_t *protocol;
729 | module_t *subtree_module;
730 | module_t *new_module;
731 | char *sep = NULL((void*)0), *ptr = NULL((void*)0), *orig = NULL((void*)0);
732 |
733 | subtree_module = protocols_module;
734 |
735 | if (subtree) {
736 | /* take a copy of the buffer, orig keeps a base pointer while ptr
737 | * walks through the string */
738 | orig = ptr = wmem_strdup(subtree_module->scope, subtree);
739 |
740 | while (ptr && *ptr) {
741 |
742 | if ((sep = strchr(ptr, '/')))
743 | *sep++ = '\0';
744 |
745 | if (!(new_module = (module_t*)wmem_tree_lookup_string(subtree_module->submodules, ptr, WMEM_TREE_STRING_NOCASE0x00000001))) {
746 | /*
747 | * There's no such module; create it, with the description
748 | * being the name (if it's later registered explicitly
749 | * with a description, that will override it).
750 | */
751 | ptr = wmem_strdup(wmem_tree_get_data_scope(prefs_modules), ptr);
752 | new_module = prefs_register_subtree(subtree_module, prefs_modules, ptr, ptr, NULL((void*)0));
753 | }
754 |
755 | subtree_module = new_module;
756 | ptr = sep;
757 |
758 | }
759 |
760 | wmem_free(subtree_module->scope, orig);
761 | }
762 |
763 | protocol = find_protocol_by_id(id);
764 | if (protocol == NULL((void*)0))
765 | ws_error("Protocol subtree being registered with an invalid protocol ID")ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 765 , __func__, "Protocol subtree being registered with an invalid protocol ID" );
766 | return prefs_register_submodule(subtree_module, prefs_modules,
767 | proto_get_protocol_filter_name(id),
768 | proto_get_protocol_short_name(protocol),
769 | proto_get_protocol_name(id), NULL((void*)0), apply_cb, true1);
770 | }
771 |
772 |
773 | /*
774 | * Register that a protocol used to have preferences but no longer does,
775 | * by creating an "obsolete" module for it.
776 | */
777 | module_t *
778 | prefs_register_protocol_obsolete(int id)
779 | {
780 | module_t *module;
781 | protocol_t *protocol = find_protocol_by_id(id);
782 | if (protocol == NULL((void*)0))
783 | ws_error("Protocol being registered with an invalid protocol ID")ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 783 , __func__, "Protocol being registered with an invalid protocol ID" );
784 | module = prefs_register_submodule(protocols_module, prefs_modules,
785 | proto_get_protocol_filter_name(id),
786 | proto_get_protocol_short_name(protocol),
787 | proto_get_protocol_name(id), NULL((void*)0), NULL((void*)0), true1);
788 | module->obsolete = true1;
789 | return module;
790 | }
791 |
792 | /*
793 | * Register that a statistical tap has preferences.
794 | *
795 | * "name" is a name for the tap to use on the command line with "-o"
796 | * and in preference files.
797 | *
798 | * "title" is a short human-readable name for the tap.
799 | *
800 | * "description" is a longer human-readable description of the tap.
801 | */
802 | module_t *stats_module;
803 |
804 | module_t *
805 | prefs_register_stat(const char *name, const char *title,
806 | const char *description, void (*apply_cb)(void))
807 | {
808 | return prefs_register_submodule(stats_module, prefs_modules, name, title, description, NULL((void*)0),
809 | apply_cb, true1);
810 | }
811 |
812 | /*
813 | * Register that a codec has preferences.
814 | *
815 | * "name" is a name for the codec to use on the command line with "-o"
816 | * and in preference files.
817 | *
818 | * "title" is a short human-readable name for the codec.
819 | *
820 | * "description" is a longer human-readable description of the codec.
821 | */
822 | module_t *codecs_module;
823 |
824 | module_t *
825 | prefs_register_codec(const char *name, const char *title,
826 | const char *description, void (*apply_cb)(void))
827 | {
828 | return prefs_register_submodule(codecs_module, prefs_modules, name, title, description, NULL((void*)0),
829 | apply_cb, true1);
830 | }
831 |
832 | module_t *
833 | prefs_find_module(const char *name)
834 | {
835 | return (module_t *)wmem_tree_lookup_string(prefs_modules, name, WMEM_TREE_STRING_NOCASE0x00000001);
836 | }
837 |
838 | /*
839 | * Call a callback function, with a specified argument, for each module
840 | * in a list of modules. If the list is NULL, searches the top-level
841 | * list in the display tree of modules. If any callback returns a
842 | * non-zero value, we stop and return that value, otherwise we
843 | * return 0.
844 | *
845 | * Normally "obsolete" modules are ignored; their sole purpose is to allow old
846 | * preferences for dissectors that no longer have preferences to be
847 | * silently ignored in preference files. Does not ignore subtrees,
848 | * as this can be used when walking the display tree of modules.
849 | */
850 |
851 | typedef struct {
852 | module_cb callback;
853 | void *user_data;
854 | unsigned ret;
855 | bool_Bool skip_obsolete;
856 | } call_foreach_t;
857 |
858 | static bool_Bool
859 | call_foreach_cb(const void *key _U___attribute__((unused)), void *value, void *data)
860 | {
861 | module_t *module = (module_t*)value;
862 | call_foreach_t *call_data = (call_foreach_t*)data;
863 |
864 | if (!call_data->skip_obsolete || !module->obsolete)
865 | call_data->ret = (*call_data->callback)(module, call_data->user_data);
866 |
867 | return (call_data->ret != 0);
868 | }
869 |
870 | unsigned
871 | prefs_module_list_foreach(const wmem_tree_t *module_list, module_cb callback,
872 | void *user_data, bool_Bool skip_obsolete)
873 | {
874 | call_foreach_t call_data;
875 |
876 | call_data.callback = callback;
877 | call_data.user_data = user_data;
878 | call_data.ret = 0;
879 | call_data.skip_obsolete = skip_obsolete;
880 | wmem_tree_foreach(module_list, call_foreach_cb, &call_data);
881 | return call_data.ret;
882 | }
883 |
884 | /*
885 | * Returns true if module has any submodules
886 | */
887 | bool_Bool
888 | prefs_module_has_submodules(module_t *module)
889 | {
890 | if (module->submodules == NULL((void*)0)) {
891 | return false0;
892 | }
893 |
894 | if (wmem_tree_is_empty(module->submodules)) {
895 | return false0;
896 | }
897 |
898 | return true1;
899 | }
900 |
901 | /*
902 | * Call a callback function, with a specified argument, for each module
903 | * in the list of all modules. (This list does not include subtrees.)
904 | *
905 | * Ignores "obsolete" modules; their sole purpose is to allow old
906 | * preferences for dissectors that no longer have preferences to be
907 | * silently ignored in preference files.
908 | */
909 | unsigned
910 | prefs_modules_foreach(const wmem_tree_t* module, module_cb callback, void *user_data)
911 | {
912 | return prefs_module_list_foreach(module, callback, user_data, true1);
913 | }
914 |
915 | /*
916 | * Call a callback function, with a specified argument, for each submodule
917 | * of specified modules. If the module is NULL, goes through the top-level
918 | * list in the display tree of modules.
919 | *
920 | * Ignores "obsolete" modules; their sole purpose is to allow old
921 | * preferences for dissectors that no longer have preferences to be
922 | * silently ignored in preference files. Does not ignore subtrees,
923 | * as this can be used when walking the display tree of modules.
924 | */
925 | unsigned
926 | prefs_modules_foreach_submodules(const wmem_tree_t* module, module_cb callback,
927 | void *user_data)
928 | {
929 | return prefs_module_list_foreach(module, callback, user_data, true1);
930 | }
931 |
932 | unsigned prefs_modules_for_all_modules(module_cb callback, void* user_data)
933 | {
934 | return prefs_module_list_foreach(prefs_top_level_modules, callback, user_data, true1);
935 | }
936 |
937 | static bool_Bool
938 | call_apply_cb(const void *key _U___attribute__((unused)), void *value, void *data _U___attribute__((unused)))
939 | {
940 | module_t *module = (module_t *)value;
941 |
942 | if (module->obsolete)
943 | return false0;
944 | if (module->prefs_changed_flags) {
945 | if (module->apply_cb != NULL((void*)0))
946 | (*module->apply_cb)();
947 | module->prefs_changed_flags = 0;
948 | }
949 | if (module->submodules)
950 | wmem_tree_foreach(module->submodules, call_apply_cb, NULL((void*)0));
951 | return false0;
952 | }
953 |
954 | /*
955 | * Call the "apply" callback function for each module if any of its
956 | * preferences have changed, and then clear the flag saying its
957 | * preferences have changed, as the module has been notified of that
958 | * fact.
959 | */
960 | void
961 | prefs_apply_all(void)
962 | {
963 | wmem_tree_foreach(prefs_modules, call_apply_cb, NULL((void*)0));
964 | }
965 |
966 | /*
967 | * Call the "apply" callback function for a specific module if any of
968 | * its preferences have changed, and then clear the flag saying its
969 | * preferences have changed, as the module has been notified of that
970 | * fact.
971 | */
972 | void
973 | prefs_apply(module_t *module)
974 | {
975 | if (module && module->prefs_changed_flags)
976 | call_apply_cb(NULL((void*)0), module, NULL((void*)0));
977 | }
978 |
979 | static module_t *
980 | prefs_find_module_alias(const char *name)
981 | {
982 | module_alias_t *alias;
983 |
984 | alias = (module_alias_t *)wmem_tree_lookup_string(prefs_module_aliases, name, WMEM_TREE_STRING_NOCASE0x00000001);
985 | if (alias == NULL((void*)0))
986 | return NULL((void*)0);
987 | return alias->module;
988 | }
989 |
990 | /*
991 | * Register a preference in a module's list of preferences.
992 | * If it has a title, give it an ordinal number; otherwise, it's a
993 | * preference that won't show up in the UI, so it shouldn't get an
994 | * ordinal number (the ordinal should be the ordinal in the set of
995 | * *visible* preferences).
996 | */
997 | static pref_t *
998 | register_preference(module_t *module, const char *name, const char *title,
999 | const char *description, pref_type_e type, bool_Bool obsolete)
1000 | {
1001 | pref_t *preference;
1002 | const char *p;
1003 | const char *name_prefix = (module->name != NULL((void*)0)) ? module->name : module->parent->name;
1004 |
1005 | preference = wmem_new(module->scope, pref_t)((pref_t*)wmem_alloc((module->scope), sizeof(pref_t)));
1006 | preference->name = name;
1007 | preference->title = title;
1008 | preference->scope = module->scope;
1009 | preference->description = description;
1010 | preference->type = type;
1011 | preference->obsolete = obsolete;
1012 | /* Default to module's preference effects */
1013 | preference->effect_flags = module->effect_flags;
1014 |
1015 | if (title != NULL((void*)0))
1016 | preference->ordinal = module->numprefs;
1017 | else
1018 | preference->ordinal = -1; /* no ordinal for you */
1019 |
1020 | /*
1021 | * Make sure that only lower-case ASCII letters, numbers,
1022 | * underscores, and dots appear in the preference name.
1023 | *
1024 | * Crash if there is, as that's an error in the code;
1025 | * you can make the title and description nice strings
1026 | * with capitalization, white space, punctuation, etc.,
1027 | * but the name can be used on the command line,
1028 | * and shouldn't require quoting, shifting, etc.
1029 | */
1030 | for (p = name; *p != '\0'; p++)
1031 | if (!(g_ascii_islower(*p)((g_ascii_table[(guchar) (*p)] & G_ASCII_LOWER) != 0) || g_ascii_isdigit(*p)((g_ascii_table[(guchar) (*p)] & G_ASCII_DIGIT) != 0) || *p == '_' || *p == '.'))
1032 | ws_error("Preference \"%s.%s\" contains invalid characters", module->name, name)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1032 , __func__, "Preference \"%s.%s\" contains invalid characters" , module->name, name);
1033 |
1034 | /*
1035 | * Make sure there's not already a preference with that
1036 | * name. Crash if there is, as that's an error in the
1037 | * code, and the code has to be fixed not to register
1038 | * more than one preference with the same name.
1039 | */
1040 | if (prefs_find_preference(module, name) != NULL((void*)0))
1041 | ws_error("Preference %s has already been registered", name)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1041 , __func__, "Preference %s has already been registered", name );
1042 |
1043 | if ((!preference->obsolete) &&
1044 | /* Don't compare if it's a subtree */
1045 | (module->name != NULL((void*)0))) {
1046 | /*
1047 | * Make sure the preference name doesn't begin with the
1048 | * module name, as that's redundant and Just Silly.
1049 | */
1050 | if (!((strncmp(name, module->name, strlen(module->name)) != 0) ||
1051 | (((name[strlen(module->name)]) != '.') && ((name[strlen(module->name)]) != '_'))))
1052 | ws_error("Preference %s begins with the module name", name)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1052 , __func__, "Preference %s begins with the module name", name );
1053 | }
1054 |
1055 | /* The title shows up in the preferences dialog. Make sure it's UI-friendly. */
1056 | if (preference->title) {
1057 | const char *cur_char;
1058 | if (preference->type != PREF_STATIC_TEXT && g_utf8_strlen(preference->title, -1) > 80) { // Arbitrary.
1059 | ws_error("Title for preference %s.%s is too long: %s", name_prefix, preference->name, preference->title)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1059 , __func__, "Title for preference %s.%s is too long: %s", name_prefix , preference->name, preference->title);
1060 | }
1061 |
1062 | if (!g_utf8_validate(preference->title, -1, NULL((void*)0))) {
1063 | ws_error("Title for preference %s.%s isn't valid UTF-8.", name_prefix, preference->name)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1063 , __func__, "Title for preference %s.%s isn't valid UTF-8.", name_prefix , preference->name);
1064 | }
1065 |
1066 | for (cur_char = preference->title; *cur_char; cur_char = g_utf8_next_char(cur_char)(char *)((cur_char) + g_utf8_skip[*(const guchar *)(cur_char) ])) {
1067 | if (!g_unichar_isprint(g_utf8_get_char(cur_char))) {
1068 | ws_error("Title for preference %s.%s isn't printable UTF-8.", name_prefix, preference->name)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1068 , __func__, "Title for preference %s.%s isn't printable UTF-8." , name_prefix, preference->name);
1069 | }
1070 | }
1071 | }
1072 |
1073 | if (preference->description) {
1074 | if (!g_utf8_validate(preference->description, -1, NULL((void*)0))) {
1075 | ws_error("Description for preference %s.%s isn't valid UTF-8.", name_prefix, preference->name)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1075 , __func__, "Description for preference %s.%s isn't valid UTF-8." , name_prefix, preference->name);
1076 | }
1077 | }
1078 |
1079 | /*
1080 | * We passed all of our checks. Add the preference.
1081 | */
1082 | module->prefs = g_list_append(module->prefs, preference);
1083 | if (title != NULL((void*)0))
1084 | module->numprefs++;
1085 |
1086 | return preference;
1087 | }
1088 |
1089 | /*
1090 | * Find a preference in a module's list of preferences, given the module
1091 | * and the preference's name.
1092 | */
1093 | typedef struct {
1094 | GList *list_entry;
1095 | const char *name;
1096 | module_t *submodule;
1097 | } find_pref_arg_t;
1098 |
1099 | static int
1100 | preference_match(const void *a, const void *b)
1101 | {
1102 | const pref_t *pref = (const pref_t *)a;
1103 | const char *name = (const char *)b;
1104 |
1105 | return strcmp(name, pref->name);
1106 | }
1107 |
1108 | static bool_Bool
1109 | module_find_pref_cb(const void *key _U___attribute__((unused)), void *value, void *data)
1110 | {
1111 | find_pref_arg_t* arg = (find_pref_arg_t*)data;
1112 | GList *list_entry;
1113 | module_t *module = (module_t *)value;
1114 |
1115 | if (module == NULL((void*)0))
1116 | return false0;
1117 |
1118 | list_entry = g_list_find_custom(module->prefs, arg->name,
1119 | preference_match);
1120 |
1121 | if (list_entry == NULL((void*)0))
1122 | return false0;
1123 |
1124 | arg->list_entry = list_entry;
1125 | arg->submodule = module;
1126 | return true1;
1127 | }
1128 |
1129 | /* Tries to find a preference, setting containing_module to the (sub)module
1130 | * holding this preference. */
1131 | static pref_t *
1132 | prefs_find_preference_with_submodule(module_t *module, const char *name,
1133 | module_t **containing_module)
1134 | {
1135 | find_pref_arg_t arg;
1136 | GList *list_entry;
1137 |
1138 | if (module == NULL((void*)0))
1139 | return NULL((void*)0); /* invalid parameters */
1140 |
1141 | list_entry = g_list_find_custom(module->prefs, name,
1142 | preference_match);
1143 | arg.submodule = NULL((void*)0);
1144 |
1145 | if (list_entry == NULL((void*)0))
1146 | {
1147 | arg.list_entry = NULL((void*)0);
1148 | if (module->submodules != NULL((void*)0))
1149 | {
1150 | arg.name = name;
1151 | wmem_tree_foreach(module->submodules, module_find_pref_cb, &arg);
1152 | }
1153 |
1154 | list_entry = arg.list_entry;
1155 | }
1156 |
1157 | if (list_entry == NULL((void*)0))
1158 | return NULL((void*)0); /* no such preference */
1159 |
1160 | if (containing_module)
1161 | *containing_module = arg.submodule ? arg.submodule : module;
1162 |
1163 | return (pref_t *) list_entry->data;
1164 | }
1165 |
1166 | pref_t *
1167 | prefs_find_preference(module_t *module, const char *name)
1168 | {
1169 | return prefs_find_preference_with_submodule(module, name, NULL((void*)0));
1170 | }
1171 |
1172 | /*
1173 | * Returns true if the given protocol has registered preferences
1174 | */
1175 | bool_Bool
1176 | prefs_is_registered_protocol(const char *name)
1177 | {
1178 | module_t *m = prefs_find_module(name);
1179 |
1180 | return (m != NULL((void*)0) && !m->obsolete);
1181 | }
1182 |
1183 | /*
1184 | * Returns the module title of a registered protocol
1185 | */
1186 | const char *
1187 | prefs_get_title_by_name(const char *name)
1188 | {
1189 | module_t *m = prefs_find_module(name);
1190 |
1191 | return (m != NULL((void*)0) && !m->obsolete) ? m->title : NULL((void*)0);
1192 | }
1193 |
1194 | /*
1195 | * Register a preference with an unsigned integral value.
1196 | */
1197 | void
1198 | prefs_register_uint_preference(module_t *module, const char *name,
1199 | const char *title, const char *description,
1200 | unsigned base, unsigned *var)
1201 | {
1202 | pref_t *preference;
1203 |
1204 | preference = register_preference(module, name, title, description,
1205 | PREF_UINT, false0);
1206 | preference->varp.uint = var;
1207 | preference->default_val.uint = *var;
1208 | ws_assert(base > 0 && base != 1 && base < 37)do { if ((1) && !(base > 0 && base != 1 && base < 37)) ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c" , 1208, __func__, "assertion failed: %s", "base > 0 && base != 1 && base < 37" ); } while (0);
1209 | preference->info.base = base;
1210 | }
1211 |
1212 | /*
1213 | * XXX Add a prefs_register_{uint16|port}_preference which sets max_value?
1214 | */
1215 |
1216 |
1217 | /*
1218 | * Register a preference with an integer value.
1219 | */
1220 | void
1221 | prefs_register_int_preference(module_t* module, const char* name,
1222 | const char* title, const char* description, int* var)
1223 | {
1224 | pref_t* preference;
1225 |
1226 | preference = register_preference(module, name, title, description,
1227 | PREF_INT, false0);
1228 | preference->varp.intp = var;
1229 | preference->default_val.intval = *var;
1230 | }
1231 |
1232 | /*
1233 | * Register a preference with a float (double) value.
1234 | */
1235 | void prefs_register_float_preference(module_t* module, const char* name,
1236 | const char* title, const char* description, unsigned num_decimal, double* var)
1237 | {
1238 | pref_t* preference;
1239 |
1240 | preference = register_preference(module, name, title, description,
1241 | PREF_FLOAT, false0);
1242 | preference->varp.floatp = var;
1243 | preference->default_val.floatval = *var;
1244 | ws_assert(num_decimal <= 10)do { if ((1) && !(num_decimal <= 10)) ws_log_fatal_full ("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1244, __func__, "assertion failed: %s" , "num_decimal <= 10"); } while (0);
1245 | preference->info.base = num_decimal;
1246 | }
1247 |
1248 | /*
1249 | * Register a "custom" preference with a unsigned integral value.
1250 | * XXX - This should be temporary until we can find a better way
1251 | * to do "custom" preferences
1252 | */
1253 | static void
1254 | prefs_register_uint_custom_preference(module_t *module, const char *name,
1255 | const char *title, const char *description,
1256 | struct pref_custom_cbs* custom_cbs, unsigned *var)
1257 | {
1258 | pref_t *preference;
1259 |
1260 | preference = register_preference(module, name, title, description,
1261 | PREF_CUSTOM, false0);
1262 |
1263 | preference->custom_cbs = *custom_cbs;
1264 | preference->varp.uint = var;
1265 | preference->default_val.uint = *var;
1266 | }
1267 |
1268 | /*
1269 | * Register a preference with an Boolean value.
1270 | */
1271 | void
1272 | prefs_register_bool_preference(module_t *module, const char *name,
1273 | const char *title, const char *description,
1274 | bool_Bool *var)
1275 | {
1276 | pref_t *preference;
1277 |
1278 | preference = register_preference(module, name, title, description,
1279 | PREF_BOOL, false0);
1280 | preference->varp.boolp = var;
1281 | preference->default_val.boolval = *var;
1282 | }
1283 |
1284 | unsigned int prefs_set_bool_value(pref_t *pref, bool_Bool value, pref_source_t source)
1285 | {
1286 | unsigned int changed = 0;
1287 |
1288 | switch (source)
1289 | {
1290 | case pref_default:
1291 | if (pref->default_val.boolval != value) {
1292 | pref->default_val.boolval = value;
1293 | changed = prefs_get_effect_flags(pref);
1294 | }
1295 | break;
1296 | case pref_stashed:
1297 | if (pref->stashed_val.boolval != value) {
1298 | pref->stashed_val.boolval = value;
1299 | changed = prefs_get_effect_flags(pref);
1300 | }
1301 | break;
1302 | case pref_current:
1303 | if (*pref->varp.boolp != value) {
1304 | *pref->varp.boolp = value;
1305 | changed = prefs_get_effect_flags(pref);
1306 | }
1307 | break;
1308 | default:
1309 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1309 , __func__, "assertion \"not reached\" failed");
1310 | break;
1311 | }
1312 |
1313 | return changed;
1314 | }
1315 |
1316 | void prefs_invert_bool_value(pref_t *pref, pref_source_t source)
1317 | {
1318 | switch (source)
1319 | {
1320 | case pref_default:
1321 | pref->default_val.boolval = !pref->default_val.boolval;
1322 | break;
1323 | case pref_stashed:
1324 | pref->stashed_val.boolval = !pref->stashed_val.boolval;
1325 | break;
1326 | case pref_current:
1327 | *pref->varp.boolp = !(*pref->varp.boolp);
1328 | break;
1329 | default:
1330 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1330 , __func__, "assertion \"not reached\" failed");
1331 | break;
1332 | }
1333 | }
1334 |
1335 | bool_Bool prefs_get_bool_value(pref_t *pref, pref_source_t source)
1336 | {
1337 | switch (source)
1338 | {
1339 | case pref_default:
1340 | return pref->default_val.boolval;
1341 | case pref_stashed:
1342 | return pref->stashed_val.boolval;
1343 | case pref_current:
1344 | return *pref->varp.boolp;
1345 | default:
1346 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1346 , __func__, "assertion \"not reached\" failed");
1347 | break;
1348 | }
1349 |
1350 | return false0;
1351 | }
1352 |
1353 | /*
1354 | * Register a preference with an enumerated value.
1355 | */
1356 | /*
1357 | * XXX Should we get rid of the radio_buttons parameter and make that
1358 | * behavior automatic depending on the number of items?
1359 | */
1360 | void
1361 | prefs_register_enum_preference(module_t *module, const char *name,
1362 | const char *title, const char *description,
1363 | int *var, const enum_val_t *enumvals,
1364 | bool_Bool radio_buttons)
1365 | {
1366 | pref_t *preference;
1367 |
1368 | /* Validate that the "name one would use on the command line for the value"
1369 | * doesn't require quoting, etc. It's all treated case-insensitively so we
1370 | * don't care about upper vs lower case.
1371 | */
1372 | for (size_t i = 0; enumvals[i].name != NULL((void*)0); i++) {
1373 | for (const char *p = enumvals[i].name; *p != '\0'; p++)
1374 | if (!(g_ascii_isalnum(*p)((g_ascii_table[(guchar) (*p)] & G_ASCII_ALNUM) != 0) || *p == '_' || *p == '.' || *p == '-'))
1375 | ws_error("Preference \"%s.%s\" enum value name \"%s\" contains invalid characters",ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1376 , __func__, "Preference \"%s.%s\" enum value name \"%s\" contains invalid characters" , module->name, name, enumvals[i].name)
1376 | module->name, name, enumvals[i].name)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1376 , __func__, "Preference \"%s.%s\" enum value name \"%s\" contains invalid characters" , module->name, name, enumvals[i].name);
1377 | }
1378 |
1379 |
1380 | preference = register_preference(module, name, title, description,
1381 | PREF_ENUM, false0);
1382 | preference->varp.enump = var;
1383 | preference->default_val.enumval = *var;
1384 | preference->info.enum_info.enumvals = enumvals;
1385 | preference->info.enum_info.radio_buttons = radio_buttons;
1386 | }
1387 |
1388 | unsigned int prefs_set_enum_value(pref_t *pref, int value, pref_source_t source)
1389 | {
1390 | unsigned int changed = 0;
1391 |
1392 | switch (source)
1393 | {
1394 | case pref_default:
1395 | if (pref->default_val.enumval != value) {
1396 | pref->default_val.enumval = value;
1397 | changed = prefs_get_effect_flags(pref);
1398 | }
1399 | break;
1400 | case pref_stashed:
1401 | if (pref->stashed_val.enumval != value) {
1402 | pref->stashed_val.enumval = value;
1403 | changed = prefs_get_effect_flags(pref);
1404 | }
1405 | break;
1406 | case pref_current:
1407 | if (*pref->varp.enump != value) {
1408 | *pref->varp.enump = value;
1409 | changed = prefs_get_effect_flags(pref);
1410 | }
1411 | break;
1412 | default:
1413 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1413 , __func__, "assertion \"not reached\" failed");
1414 | break;
1415 | }
1416 |
1417 | return changed;
1418 | }
1419 |
1420 | unsigned int prefs_set_enum_string_value(pref_t *pref, const char *value, pref_source_t source)
1421 | {
1422 | int enum_val = find_val_for_string(value, pref->info.enum_info.enumvals, *pref->varp.enump);
1423 |
1424 | return prefs_set_enum_value(pref, enum_val, source);
1425 | }
1426 |
1427 | int prefs_get_enum_value(pref_t *pref, pref_source_t source)
1428 | {
1429 | switch (source)
1430 | {
1431 | case pref_default:
1432 | return pref->default_val.enumval;
1433 | case pref_stashed:
1434 | return pref->stashed_val.enumval;
1435 | case pref_current:
1436 | return *pref->varp.enump;
1437 | default:
1438 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1438 , __func__, "assertion \"not reached\" failed");
1439 | break;
1440 | }
1441 |
1442 | return 0;
1443 | }
1444 |
1445 | const enum_val_t* prefs_get_enumvals(pref_t *pref)
1446 | {
1447 | return pref->info.enum_info.enumvals;
1448 | }
1449 |
1450 | bool_Bool prefs_get_enum_radiobuttons(pref_t *pref)
1451 | {
1452 | return pref->info.enum_info.radio_buttons;
1453 | }
1454 |
1455 | /*
1456 | * For use by UI code that sets preferences.
1457 | */
1458 | unsigned int
1459 | prefs_set_custom_value(pref_t *pref, const char *value, pref_source_t source _U___attribute__((unused)))
1460 | {
1461 | /* XXX - support pref source for custom preferences */
1462 | unsigned int changed = 0;
1463 | pref->custom_cbs.set_cb(pref, value, &changed);
1464 | return changed;
1465 | }
1466 |
1467 | static void
1468 | register_string_like_preference(module_t *module, const char *name,
1469 | const char *title, const char *description,
1470 | char **var, pref_type_e type,
1471 | struct pref_custom_cbs* custom_cbs,
1472 | bool_Bool free_tmp)
1473 | {
1474 | pref_t *pref;
1475 | char *tmp;
1476 |
1477 | pref = register_preference(module, name, title, description, type, false0);
1478 |
1479 | /*
1480 | * String preference values should be non-null (as you can't
1481 | * keep them null after using the preferences GUI, you can at best
1482 | * have them be null strings) and freeable (as we free them
1483 | * if we change them).
1484 | *
1485 | * If the value is a null pointer, make it a copy of a null
1486 | * string, otherwise make it a copy of the value.
1487 | */
1488 | tmp = *var;
1489 | if (*var == NULL((void*)0)) {
1490 | *var = wmem_strdup(pref->scope, "");
1491 | } else {
1492 | *var = wmem_strdup(pref->scope, *var);
1493 | }
1494 | if (free_tmp) {
1495 | wmem_free(pref->scope, tmp);
1496 | }
1497 | pref->varp.string = var;
1498 | pref->default_val.string = wmem_strdup(pref->scope, *var);
1499 | pref->stashed_val.string = NULL((void*)0);
1500 | if (type == PREF_CUSTOM) {
1501 | ws_assert(custom_cbs)do { if ((1) && !(custom_cbs)) ws_log_fatal_full("Epan" , LOG_LEVEL_ERROR, "epan/prefs.c", 1501, __func__, "assertion failed: %s" , "custom_cbs"); } while (0);
1502 | pref->custom_cbs = *custom_cbs;
1503 | }
1504 | }
1505 |
1506 | /*
1507 | * Assign to a string preference.
1508 | */
1509 | static void
1510 | pref_set_string_like_pref_value(pref_t *pref, const char *value)
1511 | {
1512 | wmem_free(pref->scope, *pref->varp.string);
1513 | *pref->varp.string = wmem_strdup(pref->scope, value);
1514 | }
1515 |
1516 | /*
1517 | * For use by UI code that sets preferences.
1518 | */
1519 | unsigned int
1520 | prefs_set_string_value(pref_t *pref, const char* value, pref_source_t source)
1521 | {
1522 | unsigned int changed = 0;
1523 |
1524 | switch (source)
1525 | {
1526 | case pref_default:
1527 | if (*pref->default_val.string) {
1528 | if (strcmp(pref->default_val.string, value) != 0) {
1529 | changed = prefs_get_effect_flags(pref);
1530 | wmem_free(pref->scope, pref->default_val.string);
1531 | pref->default_val.string = wmem_strdup(pref->scope, value);
1532 | }
1533 | } else if (value) {
1534 | pref->default_val.string = wmem_strdup(pref->scope, value);
1535 | }
1536 | break;
1537 | case pref_stashed:
1538 | if (pref->stashed_val.string) {
1539 | if (strcmp(pref->stashed_val.string, value) != 0) {
1540 | changed = prefs_get_effect_flags(pref);
1541 | wmem_free(pref->scope, pref->stashed_val.string);
1542 | pref->stashed_val.string = wmem_strdup(pref->scope, value);
1543 | }
1544 | } else if (value) {
1545 | pref->stashed_val.string = wmem_strdup(pref->scope, value);
1546 | }
1547 | break;
1548 | case pref_current:
1549 | if (*pref->varp.string) {
1550 | if (strcmp(*pref->varp.string, value) != 0) {
1551 | changed = prefs_get_effect_flags(pref);
1552 | pref_set_string_like_pref_value(pref, value);
1553 | }
1554 | } else if (value) {
1555 | pref_set_string_like_pref_value(pref, value);
1556 | }
1557 | break;
1558 | default:
1559 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1559 , __func__, "assertion \"not reached\" failed");
1560 | break;
1561 | }
1562 |
1563 | return changed;
1564 | }
1565 |
1566 | const char *prefs_get_string_value(pref_t *pref, pref_source_t source)
1567 | {
1568 | switch (source)
1569 | {
1570 | case pref_default:
1571 | return pref->default_val.string;
1572 | case pref_stashed:
1573 | return pref->stashed_val.string;
1574 | case pref_current:
1575 | return *pref->varp.string;
1576 | default:
1577 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1577 , __func__, "assertion \"not reached\" failed");
1578 | break;
1579 | }
1580 |
1581 | return NULL((void*)0);
1582 | }
1583 |
1584 | /*
1585 | * Reset the value of a string-like preference.
1586 | */
1587 | static void
1588 | reset_string_like_preference(pref_t *pref)
1589 | {
1590 | wmem_free(pref->scope, *pref->varp.string);
1591 | *pref->varp.string = wmem_strdup(pref->scope, pref->default_val.string);
1592 | }
1593 |
1594 | /*
1595 | * Register a preference with a character-string value.
1596 | */
1597 | void
1598 | prefs_register_string_preference(module_t *module, const char *name,
1599 | const char *title, const char *description,
1600 | const char **var)
1601 | {
1602 | DIAG_OFF(cast-qual)clang diagnostic push clang diagnostic ignored "-Wcast-qual"
1603 | register_string_like_preference(module, name, title, description,
1604 | (char **)var, PREF_STRING, NULL((void*)0), false0);
1605 | DIAG_ON(cast-qual)clang diagnostic pop
1606 | }
1607 |
1608 | /*
1609 | * Register a preference with a file name (string) value.
1610 | */
1611 | void
1612 | prefs_register_filename_preference(module_t *module, const char *name,
1613 | const char *title, const char *description,
1614 | const char **var, bool_Bool for_writing)
1615 | {
1616 | DIAG_OFF(cast-qual)clang diagnostic push clang diagnostic ignored "-Wcast-qual"
1617 | register_string_like_preference(module, name, title, description, (char **)var,
1618 | for_writing ? PREF_SAVE_FILENAME : PREF_OPEN_FILENAME, NULL((void*)0), false0);
1619 | DIAG_ON(cast-qual)clang diagnostic pop
1620 | }
1621 |
1622 | /*
1623 | * Register a preference with a directory name (string) value.
1624 | */
1625 | void
1626 | prefs_register_directory_preference(module_t *module, const char *name,
1627 | const char *title, const char *description,
1628 | const char **var)
1629 | {
1630 | DIAG_OFF(cast-qual)clang diagnostic push clang diagnostic ignored "-Wcast-qual"
1631 | register_string_like_preference(module, name, title, description,
1632 | (char **)var, PREF_DIRNAME, NULL((void*)0), false0);
1633 | DIAG_ON(cast-qual)clang diagnostic pop
1634 | }
1635 |
1636 | /* Refactoring to handle both PREF_RANGE and PREF_DECODE_AS_RANGE */
1637 | static pref_t*
1638 | prefs_register_range_preference_common(module_t *module, const char *name,
1639 | const char *title, const char *description,
1640 | range_t **var, uint32_t max_value, pref_type_e type)
1641 | {
1642 | pref_t *preference;
1643 |
1644 | preference = register_preference(module, name, title, description, type, false0);
1645 | preference->info.max_value = max_value;
1646 |
1647 | /*
1648 | * Range preference values should be non-null (as you can't
1649 | * keep them null after using the preferences GUI, you can at best
1650 | * have them be empty ranges) and freeable (as we free them
1651 | * if we change them).
1652 | *
1653 | * If the value is a null pointer, make it an empty range.
1654 | */
1655 | if (*var == NULL((void*)0))
1656 | *var = range_empty(preference->scope);
1657 | preference->varp.range = var;
1658 | preference->default_val.range = range_copy(preference->scope, *var);
1659 | preference->stashed_val.range = NULL((void*)0);
1660 |
1661 | return preference;
1662 | }
1663 |
1664 | /*
1665 | * Register a preference with a ranged value.
1666 | */
1667 | void
1668 | prefs_register_range_preference(module_t *module, const char *name,
1669 | const char *title, const char *description,
1670 | range_t **var, uint32_t max_value)
1671 | {
1672 | prefs_register_range_preference_common(module, name, title,
1673 | description, var, max_value, PREF_RANGE);
1674 | }
1675 |
1676 | bool_Bool
1677 | prefs_set_range_value_work(pref_t *pref, const char *value,
1678 | bool_Bool return_range_errors, unsigned int *changed_flags)
1679 | {
1680 | range_t *newrange;
1681 |
1682 | if (range_convert_str_work(pref->scope, &newrange, value, pref->info.max_value,
1683 | return_range_errors) != CVT_NO_ERROR) {
1684 | return false0; /* number was bad */
1685 | }
1686 |
1687 | if (!ranges_are_equal(*pref->varp.range, newrange)) {
1688 | *changed_flags |= prefs_get_effect_flags(pref);
1689 | wmem_free(pref->scope, *pref->varp.range);
1690 | *pref->varp.range = newrange;
1691 | } else {
1692 | wmem_free(pref->scope, newrange);
1693 | }
1694 | return true1;
1695 | }
1696 |
1697 | /*
1698 | * For use by UI code that sets preferences.
1699 | */
1700 | unsigned int
1701 | prefs_set_stashed_range_value(pref_t *pref, const char *value)
1702 | {
1703 | range_t *newrange;
1704 |
1705 | if (range_convert_str_work(pref->scope, &newrange, value, pref->info.max_value,
1706 | true1) != CVT_NO_ERROR) {
1707 | return 0; /* number was bad */
1708 | }
1709 |
1710 | if (!ranges_are_equal(pref->stashed_val.range, newrange)) {
1711 | wmem_free(pref->scope, pref->stashed_val.range);
1712 | pref->stashed_val.range = newrange;
1713 | } else {
1714 | wmem_free(pref->scope, newrange);
1715 | }
1716 | return prefs_get_effect_flags(pref);
1717 |
1718 | }
1719 |
1720 | bool_Bool prefs_add_list_value(pref_t *pref, void* value, pref_source_t source)
1721 | {
1722 | switch (source)
1723 | {
1724 | case pref_default:
1725 | pref->default_val.list = g_list_prepend(pref->default_val.list, value);
1726 | break;
1727 | case pref_stashed:
1728 | pref->stashed_val.list = g_list_prepend(pref->stashed_val.list, value);
1729 | break;
1730 | case pref_current:
1731 | *pref->varp.list = g_list_prepend(*pref->varp.list, value);
1732 | break;
1733 | default:
1734 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1734 , __func__, "assertion \"not reached\" failed");
1735 | break;
1736 | }
1737 |
1738 | return true1;
1739 | }
1740 |
1741 | GList* prefs_get_list_value(pref_t *pref, pref_source_t source)
1742 | {
1743 | switch (source)
1744 | {
1745 | case pref_default:
1746 | return pref->default_val.list;
1747 | case pref_stashed:
1748 | return pref->stashed_val.list;
1749 | case pref_current:
1750 | return *pref->varp.list;
1751 | default:
1752 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1752 , __func__, "assertion \"not reached\" failed");
1753 | break;
1754 | }
1755 |
1756 | return NULL((void*)0);
1757 | }
1758 |
1759 | bool_Bool prefs_set_range_value(pref_t *pref, range_t *value, pref_source_t source)
1760 | {
1761 | bool_Bool changed = false0;
1762 |
1763 | switch (source)
1764 | {
1765 | case pref_default:
1766 | if (!ranges_are_equal(pref->default_val.range, value)) {
1767 | wmem_free(pref->scope, pref->default_val.range);
1768 | pref->default_val.range = range_copy(pref->scope, value);
1769 | changed = true1;
1770 | }
1771 | break;
1772 | case pref_stashed:
1773 | if (!ranges_are_equal(pref->stashed_val.range, value)) {
1774 | wmem_free(pref->scope, pref->stashed_val.range);
1775 | pref->stashed_val.range = range_copy(pref->scope, value);
1776 | changed = true1;
1777 | }
1778 | break;
1779 | case pref_current:
1780 | if (!ranges_are_equal(*pref->varp.range, value)) {
1781 | wmem_free(pref->scope, *pref->varp.range);
1782 | *pref->varp.range = range_copy(pref->scope, value);
1783 | changed = true1;
1784 | }
1785 | break;
1786 | default:
1787 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1787 , __func__, "assertion \"not reached\" failed");
1788 | break;
1789 | }
1790 |
1791 | return changed;
1792 | }
1793 |
1794 | range_t* prefs_get_range_value_real(pref_t *pref, pref_source_t source)
1795 | {
1796 | switch (source)
1797 | {
1798 | case pref_default:
1799 | return pref->default_val.range;
1800 | case pref_stashed:
1801 | return pref->stashed_val.range;
1802 | case pref_current:
1803 | return *pref->varp.range;
1804 | default:
1805 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1805 , __func__, "assertion \"not reached\" failed");
1806 | break;
1807 | }
1808 |
1809 | return NULL((void*)0);
1810 | }
1811 |
1812 | range_t* prefs_get_range_value(const char *module_name, const char* pref_name)
1813 | {
1814 | pref_t *pref = prefs_find_preference(prefs_find_module(module_name), pref_name);
1815 | if (pref == NULL((void*)0)) {
1816 | return NULL((void*)0);
1817 | }
1818 | return prefs_get_range_value_real(pref, pref_current);
1819 | }
1820 |
1821 | void
1822 | prefs_range_add_value(pref_t *pref, uint32_t val)
1823 | {
1824 | range_add_value(pref->scope, pref->varp.range, val);
1825 | }
1826 |
1827 | void
1828 | prefs_range_remove_value(pref_t *pref, uint32_t val)
1829 | {
1830 | range_remove_value(pref->scope, pref->varp.range, val);
1831 | }
1832 |
1833 | /*
1834 | * Register a static text 'preference'. It can be used to add explanatory
1835 | * text inline with other preferences in the GUI.
1836 | * Note: Static preferences are not saved to the preferences file.
1837 | */
1838 | void
1839 | prefs_register_static_text_preference(module_t *module, const char *name,
1840 | const char *title,
1841 | const char *description)
1842 | {
1843 | register_preference(module, name, title, description, PREF_STATIC_TEXT, false0);
1844 | }
1845 |
1846 | /*
1847 | * Register a uat 'preference'. It adds a button that opens the uat's window in the
1848 | * preferences tab of the module.
1849 | */
1850 | extern void
1851 | prefs_register_uat_preference(module_t *module, const char *name,
1852 | const char *title, const char *description,
1853 | uat_t* uat)
1854 | {
1855 | pref_t* preference = register_preference(module, name, title, description, PREF_UAT, false0);
1856 |
1857 | preference->varp.uat = uat;
1858 | }
1859 |
1860 | struct epan_uat* prefs_get_uat_value(pref_t *pref)
1861 | {
1862 | return pref->varp.uat;
1863 | }
1864 |
1865 | /*
1866 | * Register a color preference.
1867 | */
1868 | void
1869 | prefs_register_color_preference(module_t *module, const char *name,
1870 | const char *title, const char *description,
1871 | color_t *color)
1872 | {
1873 | pref_t* preference = register_preference(module, name, title, description, PREF_COLOR, false0);
1874 |
1875 | preference->varp.colorp = color;
1876 | preference->default_val.color = *color;
1877 | }
1878 |
1879 | bool_Bool prefs_set_color_value(pref_t *pref, color_t value, pref_source_t source)
1880 | {
1881 | bool_Bool changed = false0;
1882 |
1883 | switch (source)
1884 | {
1885 | case pref_default:
1886 | if ((pref->default_val.color.red != value.red) ||
1887 | (pref->default_val.color.green != value.green) ||
1888 | (pref->default_val.color.blue != value.blue)) {
1889 | changed = true1;
1890 | pref->default_val.color = value;
1891 | }
1892 | break;
1893 | case pref_stashed:
1894 | if ((pref->stashed_val.color.red != value.red) ||
1895 | (pref->stashed_val.color.green != value.green) ||
1896 | (pref->stashed_val.color.blue != value.blue)) {
1897 | changed = true1;
1898 | pref->stashed_val.color = value;
1899 | }
1900 | break;
1901 | case pref_current:
1902 | if ((pref->varp.colorp->red != value.red) ||
1903 | (pref->varp.colorp->green != value.green) ||
1904 | (pref->varp.colorp->blue != value.blue)) {
1905 | changed = true1;
1906 | *pref->varp.colorp = value;
1907 | }
1908 | break;
1909 | default:
1910 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1910 , __func__, "assertion \"not reached\" failed");
1911 | break;
1912 | }
1913 |
1914 | return changed;
1915 | }
1916 |
1917 | color_t* prefs_get_color_value(pref_t *pref, pref_source_t source)
1918 | {
1919 | switch (source)
1920 | {
1921 | case pref_default:
1922 | return &pref->default_val.color;
1923 | case pref_stashed:
1924 | return &pref->stashed_val.color;
1925 | case pref_current:
1926 | return pref->varp.colorp;
1927 | default:
1928 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 1928 , __func__, "assertion \"not reached\" failed");
1929 | break;
1930 | }
1931 |
1932 | return NULL((void*)0);
1933 | }
1934 |
1935 | /*
1936 | * Register a "custom" preference with a list.
1937 | * XXX - This should be temporary until we can find a better way
1938 | * to do "custom" preferences
1939 | */
1940 | typedef void (*pref_custom_list_init_cb) (pref_t* pref, GList** value);
1941 |
1942 | static void
1943 | prefs_register_list_custom_preference(module_t *module, const char *name,
1944 | const char *title, const char *description,
1945 | struct pref_custom_cbs* custom_cbs,
1946 | pref_custom_list_init_cb init_cb,
1947 | GList** list)
1948 | {
1949 | pref_t* preference = register_preference(module, name, title, description, PREF_CUSTOM, false0);
1950 |
1951 | preference->custom_cbs = *custom_cbs;
1952 | init_cb(preference, list);
1953 | }
1954 |
1955 | /*
1956 | * Register a custom preference.
1957 | */
1958 | void
1959 | prefs_register_custom_preference(module_t *module, const char *name,
1960 | const char *title, const char *description,
1961 | struct pref_custom_cbs* custom_cbs,
1962 | void **custom_data _U___attribute__((unused)))
1963 | {
1964 | pref_t* preference = register_preference(module, name, title, description, PREF_CUSTOM, false0);
1965 |
1966 | preference->custom_cbs = *custom_cbs;
1967 | /* XXX - wait until we can handle void** pointers
1968 | preference->custom_cbs.init_cb(preference, custom_data);
1969 | */
1970 | }
1971 |
1972 | /*
1973 | * Register a dedicated TCP preference for SEQ analysis overriding.
1974 | * This is similar to the data structure from enum preference, except
1975 | * that when a preference dialog is used, the stashed value is the list
1976 | * of frame data pointers whose sequence analysis override will be set
1977 | * to the current value if the dialog is accepted.
1978 | *
1979 | * We don't need to read or write the value from the preferences file
1980 | * (or command line), because the override is reset to the default (0)
1981 | * for each frame when a new capture file is loaded.
1982 | */
1983 | void
1984 | prefs_register_custom_preference_TCP_Analysis(module_t *module, const char *name,
1985 | const char *title, const char *description,
1986 | int *var, const enum_val_t *enumvals,
1987 | bool_Bool radio_buttons)
1988 | {
1989 | pref_t *preference;
1990 |
1991 | preference = register_preference(module, name, title, description,
1992 | PREF_PROTO_TCP_SNDAMB_ENUM, false0);
1993 | preference->varp.enump = var;
1994 | preference->default_val.enumval = *var;
1995 | preference->stashed_val.list = NULL((void*)0);
1996 | preference->info.enum_info.enumvals = enumvals;
1997 | preference->info.enum_info.radio_buttons = radio_buttons;
1998 | }
1999 |
2000 | /*
2001 | * Register a (internal) "Decode As" preference with a ranged value.
2002 | */
2003 | void prefs_register_decode_as_range_preference(module_t *module, const char *name,
2004 | const char *title, const char *description, range_t **var,
2005 | uint32_t max_value, const char *dissector_table, const char *dissector_description)
2006 | {
2007 | pref_t *preference;
2008 |
2009 | preference = prefs_register_range_preference_common(module, name, title,
2010 | description, var, max_value, PREF_DECODE_AS_RANGE);
2011 | preference->dissector_desc = dissector_description;
2012 | preference->dissector_table = dissector_table;
2013 | }
2014 |
2015 | /*
2016 | * Register a preference with password value.
2017 | */
2018 | void
2019 | prefs_register_password_preference(module_t *module, const char *name,
2020 | const char *title, const char *description,
2021 | const char **var)
2022 | {
2023 | DIAG_OFF(cast-qual)clang diagnostic push clang diagnostic ignored "-Wcast-qual"
2024 | register_string_like_preference(module, name, title, description,
2025 | (char **)var, PREF_PASSWORD, NULL((void*)0), false0);
2026 | DIAG_ON(cast-qual)clang diagnostic pop
2027 | }
2028 |
2029 | /*
2030 | * Register a preference with a dissector name.
2031 | */
2032 | void
2033 | prefs_register_dissector_preference(module_t *module, const char *name,
2034 | const char *title, const char *description,
2035 | const char **var)
2036 | {
2037 | DIAG_OFF(cast-qual)clang diagnostic push clang diagnostic ignored "-Wcast-qual"
2038 | register_string_like_preference(module, name, title, description,
2039 | (char **)var, PREF_DISSECTOR, NULL((void*)0), false0);
2040 | DIAG_ON(cast-qual)clang diagnostic pop
2041 | }
2042 |
2043 | bool_Bool prefs_add_decode_as_value(pref_t *pref, unsigned value, bool_Bool replace)
2044 | {
2045 | switch(pref->type)
2046 | {
2047 | case PREF_DECODE_AS_RANGE:
2048 | if (replace)
2049 | {
2050 | /* If range has single value, replace it */
2051 | if (((*pref->varp.range)->nranges == 1) &&
2052 | ((*pref->varp.range)->ranges[0].low == (*pref->varp.range)->ranges[0].high)) {
2053 | wmem_free(pref->scope, *pref->varp.range);
2054 | *pref->varp.range = range_empty(pref->scope);
2055 | }
2056 | }
2057 |
2058 | prefs_range_add_value(pref, value);
2059 | break;
2060 | default:
2061 | /* XXX - Worth asserting over? */
2062 | break;
2063 | }
2064 |
2065 | return true1;
2066 | }
2067 |
2068 | bool_Bool prefs_remove_decode_as_value(pref_t *pref, unsigned value, bool_Bool set_default _U___attribute__((unused)))
2069 | {
2070 | switch(pref->type)
2071 | {
2072 | case PREF_DECODE_AS_RANGE:
2073 | /* XXX - We could set to the default if the value is the only one
2074 | * in the range.
2075 | */
2076 | prefs_range_remove_value(pref, value);
2077 | break;
2078 | default:
2079 | break;
2080 | }
2081 |
2082 | return true1;
2083 | }
2084 |
2085 | /*
2086 | * Register a preference that used to be supported but no longer is.
2087 | */
2088 | void
2089 | prefs_register_obsolete_preference(module_t *module, const char *name)
2090 | {
2091 | register_preference(module, name, NULL((void*)0), NULL((void*)0), PREF_STATIC_TEXT, true1);
2092 | }
2093 |
2094 | bool_Bool
2095 | prefs_is_preference_obsolete(pref_t *pref)
2096 | {
2097 | return pref->obsolete;
2098 | }
2099 |
2100 | void
2101 | prefs_set_preference_effect_fields(module_t *module, const char *name)
2102 | {
2103 | prefs_set_preference_effect(module, name, PREF_EFFECT_FIELDS(1u << 3));
2104 | }
2105 |
2106 | void prefs_set_preference_effect(module_t* module, const char* name, unsigned flags) {
2107 | pref_t* pref = prefs_find_preference(module, name);
2108 | if (pref) {
2109 | prefs_set_effect_flags(pref, prefs_get_effect_flags(pref) | flags);
2110 | }
2111 | }
2112 |
2113 | unsigned
2114 | pref_stash(pref_t *pref, void *unused _U___attribute__((unused)))
2115 | {
2116 | ws_assert(!pref->obsolete)do { if ((1) && !(!pref->obsolete)) ws_log_fatal_full ("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 2116, __func__, "assertion failed: %s" , "!pref->obsolete"); } while (0);
2117 |
2118 | switch (pref->type) {
2119 |
2120 | case PREF_UINT:
2121 | pref->stashed_val.uint = *pref->varp.uint;
2122 | break;
2123 |
2124 | case PREF_BOOL:
2125 | pref->stashed_val.boolval = *pref->varp.boolp;
2126 | break;
2127 |
2128 | case PREF_ENUM:
2129 | pref->stashed_val.enumval = *pref->varp.enump;
2130 | break;
2131 |
2132 | case PREF_INT:
2133 | pref->stashed_val.intval = *pref->varp.intp;
2134 | break;
2135 |
2136 | case PREF_FLOAT:
2137 | pref->stashed_val.floatval = *pref->varp.floatp;
2138 | break;
2139 |
2140 | case PREF_STRING:
2141 | case PREF_SAVE_FILENAME:
2142 | case PREF_OPEN_FILENAME:
2143 | case PREF_DIRNAME:
2144 | case PREF_PASSWORD:
2145 | case PREF_DISSECTOR:
2146 | wmem_free(pref->scope, pref->stashed_val.string);
2147 | pref->stashed_val.string = wmem_strdup(pref->scope, *pref->varp.string);
2148 | break;
2149 |
2150 | case PREF_DECODE_AS_RANGE:
2151 | case PREF_RANGE:
2152 | wmem_free(pref->scope, pref->stashed_val.range);
2153 | pref->stashed_val.range = range_copy(pref->scope, *pref->varp.range);
2154 | break;
2155 |
2156 | case PREF_COLOR:
2157 | pref->stashed_val.color = *pref->varp.colorp;
2158 | break;
2159 |
2160 | case PREF_STATIC_TEXT:
2161 | case PREF_UAT:
2162 | case PREF_CUSTOM:
2163 | case PREF_PROTO_TCP_SNDAMB_ENUM:
2164 | break;
2165 |
2166 | default:
2167 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 2167 , __func__, "assertion \"not reached\" failed");
2168 | break;
2169 | }
2170 | return 0;
2171 | }
2172 |
2173 | unsigned
2174 | pref_unstash(pref_t *pref, void *unstash_data_p)
2175 | {
2176 | pref_unstash_data_t *unstash_data = (pref_unstash_data_t *)unstash_data_p;
2177 | dissector_table_t sub_dissectors = NULL((void*)0);
2178 | dissector_handle_t handle = NULL((void*)0);
2179 |
2180 | ws_assert(!pref->obsolete)do { if ((1) && !(!pref->obsolete)) ws_log_fatal_full ("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 2180, __func__, "assertion failed: %s" , "!pref->obsolete"); } while (0);
2181 |
2182 | /* Revert the preference to its saved value. */
2183 | switch (pref->type) {
2184 |
2185 | case PREF_UINT:
2186 | if (*pref->varp.uint != pref->stashed_val.uint) {
2187 | unstash_data->module->prefs_changed_flags |= prefs_get_effect_flags(pref);
2188 | *pref->varp.uint = pref->stashed_val.uint;
2189 | }
2190 | break;
2191 |
2192 | case PREF_INT:
2193 | if (*pref->varp.intp != pref->stashed_val.intval) {
2194 | unstash_data->module->prefs_changed_flags |= prefs_get_effect_flags(pref);
2195 | *pref->varp.intp = pref->stashed_val.intval;
2196 | }
2197 | break;
2198 |
2199 | case PREF_FLOAT:
2200 | if (*pref->varp.floatp != pref->stashed_val.floatval) {
2201 | unstash_data->module->prefs_changed_flags |= prefs_get_effect_flags(pref);
2202 | *pref->varp.floatp = pref->stashed_val.floatval;
2203 | }
2204 | break;
2205 |
2206 | case PREF_BOOL:
2207 | if (*pref->varp.boolp != pref->stashed_val.boolval) {
2208 | unstash_data->module->prefs_changed_flags |= prefs_get_effect_flags(pref);
2209 | *pref->varp.boolp = pref->stashed_val.boolval;
2210 | }
2211 | break;
2212 |
2213 | case PREF_ENUM:
2214 | if (*pref->varp.enump != pref->stashed_val.enumval) {
2215 | unstash_data->module->prefs_changed_flags |= prefs_get_effect_flags(pref);
2216 | *pref->varp.enump = pref->stashed_val.enumval;
2217 | }
2218 | break;
2219 |
2220 | case PREF_PROTO_TCP_SNDAMB_ENUM:
2221 | {
2222 | /* The preference dialogs are modal so the frame_data pointers should
2223 | * still be valid; otherwise we could store the frame numbers to
2224 | * change.
2225 | */
2226 | frame_data *fdata;
2227 | for (GList* elem = pref->stashed_val.list; elem != NULL((void*)0); elem = elem->next) {
2228 | fdata = (frame_data*)elem->data;
2229 | if (fdata->tcp_snd_manual_analysis != *pref->varp.enump) {
2230 | unstash_data->module->prefs_changed_flags |= prefs_get_effect_flags(pref);
2231 | fdata->tcp_snd_manual_analysis = *pref->varp.enump;
2232 | }
2233 | }
2234 | break;
2235 | }
2236 | case PREF_STRING:
2237 | case PREF_SAVE_FILENAME:
2238 | case PREF_OPEN_FILENAME:
2239 | case PREF_DIRNAME:
2240 | case PREF_PASSWORD:
2241 | case PREF_DISSECTOR:
2242 | if (strcmp(*pref->varp.string, pref->stashed_val.string) != 0) {
2243 | unstash_data->module->prefs_changed_flags |= prefs_get_effect_flags(pref);
2244 | wmem_free(pref->scope, *pref->varp.string);
2245 | *pref->varp.string = wmem_strdup(pref->scope, pref->stashed_val.string);
2246 | }
2247 | break;
2248 |
2249 | case PREF_DECODE_AS_RANGE:
2250 | {
2251 | const char* table_name = prefs_get_dissector_table(pref);
2252 | if (!ranges_are_equal(*pref->varp.range, pref->stashed_val.range)) {
2253 | uint32_t i, j;
2254 | unstash_data->module->prefs_changed_flags |= prefs_get_effect_flags(pref);
2255 |
2256 | if (unstash_data->handle_decode_as) {
2257 | sub_dissectors = find_dissector_table(table_name);
2258 | if (sub_dissectors != NULL((void*)0)) {
2259 | const char *handle_desc = prefs_get_dissector_description(pref);
2260 | // It should perhaps be possible to get this via dissector name.
2261 | handle = dissector_table_get_dissector_handle(sub_dissectors, handle_desc);
2262 | if (handle != NULL((void*)0)) {
2263 | /* Set the current handle to NULL for all the old values
2264 | * in the dissector table. If there isn't an initial
2265 | * handle, this actually deletes the entry. (If there
2266 | * is an initial entry, keep it around so that the
2267 | * user can see the original value.)
2268 | *
2269 | * XXX - If there's an initial handle which is not this,
2270 | * reset it instead? At least this leaves the initial
2271 | * handle visible in the Decode As table.
2272 | */
2273 | for (i = 0; i < (*pref->varp.range)->nranges; i++) {
2274 | for (j = (*pref->varp.range)->ranges[i].low; j < (*pref->varp.range)->ranges[i].high; j++) {
2275 | dissector_change_uint(table_name, j, NULL((void*)0));
2276 | decode_build_reset_list(table_name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(j)((gpointer) (gulong) (j)), NULL((void*)0), NULL((void*)0));
2277 | }
2278 |
2279 | dissector_change_uint(table_name, (*pref->varp.range)->ranges[i].high, NULL((void*)0));
2280 | decode_build_reset_list(table_name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER((*pref->varp.range)->ranges[i].high)((gpointer) (gulong) ((*pref->varp.range)->ranges[i].high )), NULL((void*)0), NULL((void*)0));
2281 | }
2282 | }
2283 | }
2284 | }
2285 |
2286 | wmem_free(pref->scope, *pref->varp.range);
2287 | *pref->varp.range = range_copy(pref->scope, pref->stashed_val.range);
2288 |
2289 | if (unstash_data->handle_decode_as) {
2290 | if ((sub_dissectors != NULL((void*)0)) && (handle != NULL((void*)0))) {
2291 |
2292 | /* Add new values to the dissector table */
2293 | for (i = 0; i < (*pref->varp.range)->nranges; i++) {
2294 |
2295 | for (j = (*pref->varp.range)->ranges[i].low; j < (*pref->varp.range)->ranges[i].high; j++) {
2296 | dissector_change_uint(table_name, j, handle);
2297 | decode_build_reset_list(table_name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(j)((gpointer) (gulong) (j)), NULL((void*)0), NULL((void*)0));
2298 | }
2299 |
2300 | dissector_change_uint(table_name, (*pref->varp.range)->ranges[i].high, handle);
2301 | decode_build_reset_list(table_name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER((*pref->varp.range)->ranges[i].high)((gpointer) (gulong) ((*pref->varp.range)->ranges[i].high )), NULL((void*)0), NULL((void*)0));
2302 | }
2303 | }
2304 | }
2305 | }
2306 | break;
2307 | }
2308 | case PREF_RANGE:
2309 | if (!ranges_are_equal(*pref->varp.range, pref->stashed_val.range)) {
2310 | unstash_data->module->prefs_changed_flags |= prefs_get_effect_flags(pref);
2311 | wmem_free(pref->scope, *pref->varp.range);
2312 | *pref->varp.range = range_copy(pref->scope, pref->stashed_val.range);
2313 | }
2314 | break;
2315 |
2316 | case PREF_COLOR:
2317 | if ((pref->varp.colorp->blue != pref->stashed_val.color.blue) ||
2318 | (pref->varp.colorp->red != pref->stashed_val.color.red) ||
2319 | (pref->varp.colorp->green != pref->stashed_val.color.green)) {
2320 | unstash_data->module->prefs_changed_flags |= prefs_get_effect_flags(pref);
2321 | *pref->varp.colorp = pref->stashed_val.color;
2322 | }
2323 | break;
2324 | case PREF_UAT:
2325 | if (pref->varp.uat && pref->varp.uat->changed) {
2326 | unstash_data->module->prefs_changed_flags |= prefs_get_effect_flags(pref);
2327 | }
2328 | break;
2329 | case PREF_STATIC_TEXT:
2330 | case PREF_CUSTOM:
2331 | break;
2332 |
2333 | default:
2334 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 2334 , __func__, "assertion \"not reached\" failed");
2335 | break;
2336 | }
2337 | return 0;
2338 | }
2339 |
2340 | void
2341 | reset_stashed_pref(pref_t *pref) {
2342 |
2343 | ws_assert(!pref->obsolete)do { if ((1) && !(!pref->obsolete)) ws_log_fatal_full ("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 2343, __func__, "assertion failed: %s" , "!pref->obsolete"); } while (0);
2344 |
2345 | switch (pref->type) {
2346 |
2347 | case PREF_UINT:
2348 | pref->stashed_val.uint = pref->default_val.uint;
2349 | break;
2350 |
2351 | case PREF_INT:
2352 | pref->stashed_val.intval = pref->default_val.intval;
2353 | break;
2354 |
2355 | case PREF_FLOAT:
2356 | pref->stashed_val.floatval = pref->default_val.floatval;
2357 | break;
2358 |
2359 | case PREF_BOOL:
2360 | pref->stashed_val.boolval = pref->default_val.boolval;
2361 | break;
2362 |
2363 | case PREF_ENUM:
2364 | pref->stashed_val.enumval = pref->default_val.enumval;
2365 | break;
2366 |
2367 | case PREF_STRING:
2368 | case PREF_SAVE_FILENAME:
2369 | case PREF_OPEN_FILENAME:
2370 | case PREF_DIRNAME:
2371 | case PREF_PASSWORD:
2372 | case PREF_DISSECTOR:
2373 | wmem_free(pref->scope, pref->stashed_val.string);
2374 | pref->stashed_val.string = wmem_strdup(pref->scope, pref->default_val.string);
2375 | break;
2376 |
2377 | case PREF_DECODE_AS_RANGE:
2378 | case PREF_RANGE:
2379 | wmem_free(pref->scope, pref->stashed_val.range);
2380 | pref->stashed_val.range = range_copy(pref->scope, pref->default_val.range);
2381 | break;
2382 |
2383 | case PREF_PROTO_TCP_SNDAMB_ENUM:
2384 | if (pref->stashed_val.list != NULL((void*)0)) {
2385 | g_list_free(pref->stashed_val.list);
2386 | pref->stashed_val.list = NULL((void*)0);
2387 | }
2388 | break;
2389 |
2390 | case PREF_COLOR:
2391 | memcpy(&pref->stashed_val.color, &pref->default_val.color, sizeof(color_t));
2392 | break;
2393 |
2394 | case PREF_STATIC_TEXT:
2395 | case PREF_UAT:
2396 | case PREF_CUSTOM:
2397 | break;
2398 |
2399 | default:
2400 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 2400 , __func__, "assertion \"not reached\" failed");
2401 | break;
2402 | }
2403 | }
2404 |
2405 | unsigned
2406 | pref_clean_stash(pref_t *pref, void *unused _U___attribute__((unused)))
2407 | {
2408 | ws_assert(!pref->obsolete)do { if ((1) && !(!pref->obsolete)) ws_log_fatal_full ("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 2408, __func__, "assertion failed: %s" , "!pref->obsolete"); } while (0);
2409 |
2410 | switch (pref->type) {
2411 |
2412 | case PREF_UINT:
2413 | case PREF_INT:
2414 | case PREF_FLOAT:
2415 | case PREF_BOOL:
2416 | case PREF_ENUM:
2417 | break;
2418 |
2419 | case PREF_STRING:
2420 | case PREF_SAVE_FILENAME:
2421 | case PREF_OPEN_FILENAME:
2422 | case PREF_DIRNAME:
2423 | case PREF_PASSWORD:
2424 | case PREF_DISSECTOR:
2425 | if (pref->stashed_val.string != NULL((void*)0)) {
2426 | wmem_free(pref->scope, pref->stashed_val.string);
2427 | pref->stashed_val.string = NULL((void*)0);
2428 | }
2429 | break;
2430 |
2431 | case PREF_DECODE_AS_RANGE:
2432 | case PREF_RANGE:
2433 | if (pref->stashed_val.range != NULL((void*)0)) {
2434 | wmem_free(pref->scope, pref->stashed_val.range);
2435 | pref->stashed_val.range = NULL((void*)0);
2436 | }
2437 | break;
2438 |
2439 | case PREF_STATIC_TEXT:
2440 | case PREF_UAT:
2441 | case PREF_COLOR:
2442 | case PREF_CUSTOM:
2443 | break;
2444 |
2445 | case PREF_PROTO_TCP_SNDAMB_ENUM:
2446 | if (pref->stashed_val.list != NULL((void*)0)) {
2447 | g_list_free(pref->stashed_val.list);
2448 | pref->stashed_val.list = NULL((void*)0);
2449 | }
2450 | break;
2451 |
2452 | default:
2453 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 2453 , __func__, "assertion \"not reached\" failed");
2454 | break;
2455 | }
2456 | return 0;
2457 | }
2458 |
2459 | /*
2460 | * Call a callback function, with a specified argument, for each preference
2461 | * in a given module.
2462 | *
2463 | * If any of the callbacks return a non-zero value, stop and return that
2464 | * value, otherwise return 0.
2465 | */
2466 | unsigned
2467 | prefs_pref_foreach(module_t *module, pref_cb callback, void *user_data)
2468 | {
2469 | GList *elem;
2470 | pref_t *pref;
2471 | unsigned ret;
2472 |
2473 | for (elem = g_list_first(module->prefs); elem != NULL((void*)0); elem = g_list_next(elem)((elem) ? (((GList *)(elem))->next) : ((void*)0))) {
2474 | pref = (pref_t *)elem->data;
2475 | if (!pref || pref->obsolete) {
2476 | /*
2477 | * This preference is no longer supported; it's
2478 | * not a real preference, so we don't call the
2479 | * callback for it (i.e., we treat it as if it
2480 | * weren't found in the list of preferences,
2481 | * and we weren't called in the first place).
2482 | */
2483 | continue;
2484 | }
2485 |
2486 | ret = (*callback)(pref, user_data);
2487 | if (ret != 0)
2488 | return ret;
2489 | }
2490 | return 0;
2491 | }
2492 |
2493 | static const enum_val_t st_sort_col_vals[] = {
2494 | { "name", "Node name (topic/item)", ST_SORT_COL_NAME1 },
2495 | { "count", "Item count", ST_SORT_COL_COUNT2 },
2496 | { "average", "Average value of the node", ST_SORT_COL_AVG3 },
2497 | { "min", "Minimum value of the node", ST_SORT_COL_MIN4 },
2498 | { "max", "Maximum value of the node", ST_SORT_COL_MAX5 },
2499 | { "burst", "Burst rate of the node", ST_SORT_COL_BURSTRATE6 },
2500 | { NULL((void*)0), NULL((void*)0), 0 }
2501 | };
2502 |
2503 | static const enum_val_t st_format_vals[] = {
2504 | { "text", "Plain text", ST_FORMAT_PLAIN },
2505 | { "csv", "Comma separated values", ST_FORMAT_CSV },
2506 | { "xml", "XML document", ST_FORMAT_XML },
2507 | { "yaml", "YAML document", ST_FORMAT_YAML },
2508 | { NULL((void*)0), NULL((void*)0), 0 }
2509 | };
2510 |
2511 | static void
2512 | stats_callback(void)
2513 | {
2514 | /* Test for a sane tap update interval */
2515 | if (prefs.tap_update_interval < 100 || prefs.tap_update_interval > 10000)
2516 | prefs.tap_update_interval = TAP_UPDATE_DEFAULT_INTERVAL3000;
2517 |
2518 | /* burst resolution can't be less than 1 (ms) */
2519 | if (prefs.st_burst_resolution < 1) {
2520 | prefs.st_burst_resolution = 1;
2521 | }
2522 | else if (prefs.st_burst_resolution > ST_MAX_BURSTRES600000) {
2523 | prefs.st_burst_resolution = ST_MAX_BURSTRES600000;
2524 | }
2525 | /* make sure burst window value makes sense */
2526 | if (prefs.st_burst_windowlen < prefs.st_burst_resolution) {
2527 | prefs.st_burst_windowlen = prefs.st_burst_resolution;
2528 | }
2529 | /* round burst window down to multiple of resolution */
2530 | prefs.st_burst_windowlen -= prefs.st_burst_windowlen%prefs.st_burst_resolution;
2531 | if ((prefs.st_burst_windowlen/prefs.st_burst_resolution) > ST_MAX_BURSTBUCKETS100) {
2532 | prefs.st_burst_windowlen = prefs.st_burst_resolution*ST_MAX_BURSTBUCKETS100;
2533 | }
2534 | }
2535 |
2536 | static void
2537 | gui_callback(void)
2538 | {
2539 | /* Ensure there is at least one file count */
2540 | if (prefs.gui_recent_files_count_max == 0)
2541 | prefs.gui_recent_files_count_max = 10;
2542 |
2543 | /* Ensure there is at least one display filter entry */
2544 | if (prefs.gui_recent_df_entries_max == 0)
2545 | prefs.gui_recent_df_entries_max = 10;
2546 |
2547 | /* number of decimal places should be between 2 and 10 */
2548 | if (prefs.gui_decimal_places1 < 2) {
2549 | prefs.gui_decimal_places1 = 2;
2550 | } else if (prefs.gui_decimal_places1 > 10) {
2551 | prefs.gui_decimal_places1 = 10;
2552 | }
2553 | /* number of decimal places should be between 2 and 10 */
2554 | if (prefs.gui_decimal_places2 < 2) {
2555 | prefs.gui_decimal_places2 = 2;
2556 | } else if (prefs.gui_decimal_places2 > 10) {
2557 | prefs.gui_decimal_places2 = 10;
2558 | }
2559 | /* number of decimal places should be between 2 and 10 */
2560 | if (prefs.gui_decimal_places3 < 2) {
2561 | prefs.gui_decimal_places3 = 2;
2562 | } else if (prefs.gui_decimal_places3 > 10) {
2563 | prefs.gui_decimal_places3 = 10;
2564 | }
2565 | }
2566 |
2567 | static void
2568 | gui_layout_callback(void)
2569 | {
2570 | if (prefs.gui_layout_type == layout_unused ||
2571 | prefs.gui_layout_type >= layout_type_max) {
2572 | /* XXX - report an error? It's not a syntax error - we'd need to
2573 | add a way of reporting a *semantic* error. */
2574 | prefs.gui_layout_type = layout_type_2;
2575 | }
2576 | }
2577 |
2578 | /******************************************************
2579 | * All custom preference function callbacks
2580 | ******************************************************/
2581 | static void custom_pref_no_cb(pref_t* pref _U___attribute__((unused))) {}
2582 |
2583 | /*
2584 | * Column preference functions
2585 | */
2586 | #define PRS_COL_HIDDEN_FMT"column.hidden" "column.hidden"
2587 | #define PRS_COL_HIDDEN"column.hide" "column.hide"
2588 | #define PRS_COL_FMT"column.format" "column.format"
2589 | #define PRS_COL_NUM"column.number" "column.number"
2590 | static module_t *gui_column_module;
2591 |
2592 | static prefs_set_pref_e
2593 | column_hidden_set_cb(pref_t* pref, const char* value, unsigned int* changed_flags)
2594 | {
2595 | GList *clp;
2596 | fmt_data *cfmt;
2597 | pref_t *format_pref;
2598 |
2599 | /*
2600 | * Prefer the new preference to the old format-based preference if we've
2601 | * read it. (We probably could just compare the string to NULL and "".)
2602 | */
2603 | prefs.cols_hide_new = true1;
2604 |
2605 | (*changed_flags) |= prefs_set_string_value(pref, value, pref_current);
2606 |
2607 | /*
2608 | * Set the "visible" flag for the existing columns; we need to
2609 | * do this if we set PRS_COL_HIDDEN but don't set PRS_COL_FMT
2610 | * after setting it (which might be the case if, for example, we
2611 | * set PRS_COL_HIDDEN on the command line).
2612 | */
2613 | format_pref = prefs_find_preference(gui_column_module, PRS_COL_FMT"column.format");
2614 | clp = (format_pref) ? *format_pref->varp.list : NULL((void*)0);
2615 | int cidx = 1;
2616 | while (clp) {
2617 | cfmt = (fmt_data *)clp->data;
2618 | cfmt->visible = prefs_is_column_visible(*pref->varp.string, cidx);
2619 | cidx++;
2620 | clp = clp->next;
2621 | }
2622 |
2623 | return PREFS_SET_OK;
2624 | }
2625 |
2626 | static const char *
2627 | column_hidden_type_name_cb(void)
2628 | {
2629 | return "Packet list hidden columns";
2630 | }
2631 |
2632 | static char *
2633 | column_hidden_type_description_cb(void)
2634 | {
2635 | return g_strdup("List all column indices (1-indexed) to hide in the packet list.")g_strdup_inline ("List all column indices (1-indexed) to hide in the packet list." );
2636 | }
2637 |
2638 | static char *
2639 | column_hidden_to_str_cb(pref_t* pref, bool_Bool default_val)
2640 | {
2641 | GString *cols_hidden;
2642 | GList *clp;
2643 | fmt_data *cfmt;
2644 | pref_t *format_pref;
2645 | int cidx = 1;
2646 |
2647 | if (default_val)
2648 | return g_strdup(pref->default_val.string)g_strdup_inline (pref->default_val.string);
2649 |
2650 | cols_hidden = g_string_new("");
2651 | format_pref = prefs_find_preference(gui_column_module, PRS_COL_FMT"column.format");
2652 | clp = (format_pref) ? *format_pref->varp.list : NULL((void*)0);
2653 | while (clp) {
2654 | cfmt = (fmt_data *) clp->data;
2655 | if (!cfmt->visible) {
2656 | if (cols_hidden->len)
2657 | g_string_append (cols_hidden, ",")(__builtin_constant_p (",") ? __extension__ ({ const char * const __val = (","); g_string_append_len_inline (cols_hidden, __val , (__val != ((void*)0)) ? (gssize) strlen (((__val) + !(__val ))) : (gssize) -1); }) : g_string_append_len_inline (cols_hidden , ",", (gssize) -1));
2658 | g_string_append_printf (cols_hidden, "%i", cidx);
2659 | }
2660 | clp = clp->next;
2661 | cidx++;
2662 | }
2663 |
2664 | return g_string_free (cols_hidden, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((cols_hidden ), ((0))) : g_string_free_and_steal (cols_hidden)) : (g_string_free ) ((cols_hidden), ((0))));
2665 | }
2666 |
2667 | static bool_Bool
2668 | column_hidden_is_default_cb(pref_t* pref)
2669 | {
2670 | char *cur_hidden_str = column_hidden_to_str_cb(pref, false0);
2671 | bool_Bool is_default = g_strcmp0(cur_hidden_str, pref->default_val.string) == 0;
2672 |
2673 | g_free(cur_hidden_str);
2674 | return is_default;
2675 | }
2676 |
2677 | static prefs_set_pref_e
2678 | column_hidden_fmt_set_cb(pref_t* pref, const char* value, unsigned int* changed_flags)
2679 | {
2680 | GList *clp;
2681 | fmt_data *cfmt;
2682 | pref_t *format_pref;
2683 |
2684 | (*changed_flags) |= prefs_set_string_value(pref, value, pref_current);
2685 |
2686 | /*
2687 | * Set the "visible" flag for the existing columns; we need to
2688 | * do this if we set PRS_COL_HIDDEN_FMT but don't set PRS_COL_FMT
2689 | * after setting it (which might be the case if, for example, we
2690 | * set PRS_COL_HIDDEN_FMT on the command line; it shouldn't happen
2691 | * when reading the configuration file because we write (both of)
2692 | * the hidden column prefs before the column format prefs.)
2693 | */
2694 | format_pref = prefs_find_preference(gui_column_module, PRS_COL_FMT"column.format");
2695 | clp = (format_pref) ? *format_pref->varp.list : NULL((void*)0);
2696 | while (clp) {
2697 | cfmt = (fmt_data *)clp->data;
2698 | cfmt->visible = prefs_is_column_fmt_visible(*pref->varp.string, cfmt);
2699 | clp = clp->next;
2700 | }
2701 |
2702 | return PREFS_SET_OK;
2703 | }
2704 |
2705 | static const char *
2706 | column_hidden_fmt_type_name_cb(void)
2707 | {
2708 | return "Packet list hidden column formats (deprecated)";
2709 | }
2710 |
2711 | static char *
2712 | column_hidden_fmt_type_description_cb(void)
2713 | {
2714 | return g_strdup("List all column formats to hide in the packet list. Deprecated in favor of the index-based preference.")g_strdup_inline ("List all column formats to hide in the packet list. Deprecated in favor of the index-based preference." );
2715 | }
2716 |
2717 | static char *
2718 | column_hidden_fmt_to_str_cb(pref_t* pref, bool_Bool default_val)
2719 | {
2720 | GString *cols_hidden;
2721 | GList *clp;
2722 | fmt_data *cfmt;
2723 | pref_t *format_pref;
2724 |
2725 | if (default_val)
2726 | return g_strdup(pref->default_val.string)g_strdup_inline (pref->default_val.string);
2727 |
2728 | cols_hidden = g_string_new("");
2729 | format_pref = prefs_find_preference(gui_column_module, PRS_COL_FMT"column.format");
2730 | clp = (format_pref) ? *format_pref->varp.list : NULL((void*)0);
2731 | while (clp) {
2732 | char *prefs_fmt;
2733 | cfmt = (fmt_data *) clp->data;
2734 | if (!cfmt->visible) {
2735 | if (cols_hidden->len)
2736 | g_string_append (cols_hidden, ",")(__builtin_constant_p (",") ? __extension__ ({ const char * const __val = (","); g_string_append_len_inline (cols_hidden, __val , (__val != ((void*)0)) ? (gssize) strlen (((__val) + !(__val ))) : (gssize) -1); }) : g_string_append_len_inline (cols_hidden , ",", (gssize) -1));
2737 | prefs_fmt = column_fmt_data_to_str(cfmt);
2738 | g_string_append(cols_hidden, prefs_fmt)(__builtin_constant_p (prefs_fmt) ? __extension__ ({ const char * const __val = (prefs_fmt); g_string_append_len_inline (cols_hidden , __val, (__val != ((void*)0)) ? (gssize) strlen (((__val) + ! (__val))) : (gssize) -1); }) : g_string_append_len_inline (cols_hidden , prefs_fmt, (gssize) -1));
2739 | g_free(prefs_fmt);
2740 | }
2741 | clp = clp->next;
2742 | }
2743 |
2744 | return g_string_free (cols_hidden, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((cols_hidden ), ((0))) : g_string_free_and_steal (cols_hidden)) : (g_string_free ) ((cols_hidden), ((0))));
2745 | }
2746 |
2747 | static bool_Bool
2748 | column_hidden_fmt_is_default_cb(pref_t* pref)
2749 | {
2750 | char *cur_hidden_str = column_hidden_fmt_to_str_cb(pref, false0);
2751 | bool_Bool is_default = g_strcmp0(cur_hidden_str, pref->default_val.string) == 0;
2752 |
2753 | g_free(cur_hidden_str);
2754 | return is_default;
2755 | }
2756 |
2757 | /* Number of columns "preference". This is only used internally and is not written to the
2758 | * preference file
2759 | */
2760 | static void
2761 | column_num_reset_cb(pref_t* pref)
2762 | {
2763 | *pref->varp.uint = pref->default_val.uint;
2764 | }
2765 |
2766 | static prefs_set_pref_e
2767 | column_num_set_cb(pref_t* pref _U___attribute__((unused)), const char* value _U___attribute__((unused)), unsigned int* changed_flags _U___attribute__((unused)))
2768 | {
2769 | /* Don't write this to the preferences file */
2770 | return PREFS_SET_OK;
2771 | }
2772 |
2773 | static const char *
2774 | column_num_type_name_cb(void)
2775 | {
2776 | return NULL((void*)0);
2777 | }
2778 |
2779 | static char *
2780 | column_num_type_description_cb(void)
2781 | {
2782 | return g_strdup("")g_strdup_inline ("");
2783 | }
2784 |
2785 | static bool_Bool
2786 | column_num_is_default_cb(pref_t* pref _U___attribute__((unused)))
2787 | {
2788 | return true1;
2789 | }
2790 |
2791 | static char *
2792 | column_num_to_str_cb(pref_t* pref _U___attribute__((unused)), bool_Bool default_val _U___attribute__((unused)))
2793 | {
2794 | return g_strdup("")g_strdup_inline ("");
2795 | }
2796 |
2797 | /*
2798 | * Column format custom preference functions
2799 | */
2800 | static void
2801 | column_format_init_cb(pref_t* pref, GList** value)
2802 | {
2803 | fmt_data *src_cfmt, *dest_cfmt;
2804 | GList *entry;
2805 |
2806 | pref->varp.list = value;
2807 |
2808 | pref->default_val.list = NULL((void*)0);
2809 | for (entry = *pref->varp.list; entry != NULL((void*)0); entry = g_list_next(entry)((entry) ? (((GList *)(entry))->next) : ((void*)0))) {
2810 | src_cfmt = (fmt_data *)entry->data;
2811 | dest_cfmt = g_new(fmt_data,1)((fmt_data *) g_malloc_n ((1), sizeof (fmt_data)));
2812 | dest_cfmt->title = g_strdup(src_cfmt->title)g_strdup_inline (src_cfmt->title);
2813 | dest_cfmt->fmt = src_cfmt->fmt;
2814 | if (src_cfmt->custom_fields) {
2815 | dest_cfmt->custom_fields = g_strdup(src_cfmt->custom_fields)g_strdup_inline (src_cfmt->custom_fields);
2816 | dest_cfmt->custom_occurrence = src_cfmt->custom_occurrence;
2817 | } else {
2818 | dest_cfmt->custom_fields = NULL((void*)0);
2819 | dest_cfmt->custom_occurrence = 0;
2820 | }
2821 | dest_cfmt->visible = src_cfmt->visible;
2822 | dest_cfmt->display = src_cfmt->display;
2823 | pref->default_val.list = g_list_append(pref->default_val.list, dest_cfmt);
2824 | }
2825 |
2826 | column_register_fields();
2827 | }
2828 |
2829 | static void
2830 | column_format_free_cb(pref_t* pref)
2831 | {
2832 | free_col_info(*pref->varp.list);
2833 | free_col_info(pref->default_val.list);
2834 | }
2835 |
2836 | static void
2837 | column_format_reset_cb(pref_t* pref)
2838 | {
2839 | fmt_data *src_cfmt, *dest_cfmt;
2840 | GList *entry;
2841 | pref_t *col_num_pref;
2842 |
2843 | free_col_info(*pref->varp.list);
2844 | *pref->varp.list = NULL((void*)0);
2845 |
2846 | for (entry = pref->default_val.list; entry != NULL((void*)0); entry = g_list_next(entry)((entry) ? (((GList *)(entry))->next) : ((void*)0))) {
2847 | src_cfmt = (fmt_data *)entry->data;
2848 | dest_cfmt = g_new(fmt_data,1)((fmt_data *) g_malloc_n ((1), sizeof (fmt_data)));
2849 | dest_cfmt->title = g_strdup(src_cfmt->title)g_strdup_inline (src_cfmt->title);
2850 | dest_cfmt->fmt = src_cfmt->fmt;
2851 | if (src_cfmt->custom_fields) {
2852 | dest_cfmt->custom_fields = g_strdup(src_cfmt->custom_fields)g_strdup_inline (src_cfmt->custom_fields);
2853 | dest_cfmt->custom_occurrence = src_cfmt->custom_occurrence;
2854 | } else {
2855 | dest_cfmt->custom_fields = NULL((void*)0);
2856 | dest_cfmt->custom_occurrence = 0;
2857 | }
2858 | dest_cfmt->visible = src_cfmt->visible;
2859 | dest_cfmt->display = src_cfmt->display;
2860 | *pref->varp.list = g_list_append(*pref->varp.list, dest_cfmt);
2861 | }
2862 |
2863 | col_num_pref = prefs_find_preference(gui_column_module, PRS_COL_NUM"column.number");
2864 | ws_assert(col_num_pref != NULL)do { if ((1) && !(col_num_pref != ((void*)0))) ws_log_fatal_full ("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 2864, __func__, "assertion failed: %s" , "col_num_pref != ((void*)0)"); } while (0); /* Should never happen */
2865 | column_num_reset_cb(col_num_pref);
2866 | }
2867 |
2868 | static prefs_set_pref_e
2869 | column_format_set_cb(pref_t* pref, const char* value, unsigned int* changed_flags _U___attribute__((unused)))
2870 | {
2871 | GList *col_l, *col_l_elt;
2872 | fmt_data *cfmt;
2873 | int llen;
2874 | pref_t *hidden_pref, *col_num_pref;
2875 |
2876 | col_l = prefs_get_string_list(value);
2877 | if (col_l == NULL((void*)0))
2878 | return PREFS_SET_SYNTAX_ERR;
2879 | if ((g_list_length(col_l) % 2) != 0) {
2880 | /* A title didn't have a matching format. */
2881 | prefs_clear_string_list(col_l);
2882 | return PREFS_SET_SYNTAX_ERR;
2883 | }
2884 | /* Check to make sure all column formats are valid. */
2885 | col_l_elt = g_list_first(col_l);
2886 | while (col_l_elt) {
2887 | fmt_data cfmt_check;
2888 |
2889 | /* Go past the title. */
2890 | col_l_elt = col_l_elt->next;
2891 |
2892 | /* Some predefined columns have been migrated to use custom columns.
2893 | * We'll convert these silently here */
2894 | try_convert_to_custom_column((char **)&col_l_elt->data);
2895 |
2896 | /* Parse the format to see if it's valid. */
2897 | if (!parse_column_format(&cfmt_check, (char *)col_l_elt->data)) {
2898 | /* It's not a valid column format. */
2899 | prefs_clear_string_list(col_l);
2900 | return PREFS_SET_SYNTAX_ERR;
2901 | }
2902 | if (cfmt_check.fmt == COL_CUSTOM) {
2903 | /* We don't need the custom column field on this pass. */
2904 | g_free(cfmt_check.custom_fields);
2905 | }
2906 |
2907 | /* Go past the format. */
2908 | col_l_elt = col_l_elt->next;
2909 | }
2910 |
2911 | /* They're all valid; process them. */
2912 | free_col_info(*pref->varp.list);
2913 | *pref->varp.list = NULL((void*)0);
2914 | if (prefs.cols_hide_new) {
2915 | hidden_pref = prefs_find_preference(gui_column_module, PRS_COL_HIDDEN"column.hide");
2916 | } else {
2917 | hidden_pref = prefs_find_preference(gui_column_module, PRS_COL_HIDDEN_FMT"column.hidden");
2918 | }
2919 | ws_assert(hidden_pref != NULL)do { if ((1) && !(hidden_pref != ((void*)0))) ws_log_fatal_full ("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 2919, __func__, "assertion failed: %s" , "hidden_pref != ((void*)0)"); } while (0); /* Should never happen */
2920 | col_num_pref = prefs_find_preference(gui_column_module, PRS_COL_NUM"column.number");
2921 | ws_assert(col_num_pref != NULL)do { if ((1) && !(col_num_pref != ((void*)0))) ws_log_fatal_full ("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 2921, __func__, "assertion failed: %s" , "col_num_pref != ((void*)0)"); } while (0); /* Should never happen */
2922 | llen = g_list_length(col_l);
2923 | *col_num_pref->varp.uint = llen / 2;
2924 | col_l_elt = g_list_first(col_l);
2925 | int cidx = 1;
2926 | while (col_l_elt) {
2927 | cfmt = g_new(fmt_data,1)((fmt_data *) g_malloc_n ((1), sizeof (fmt_data)));
2928 | cfmt->title = g_strdup((char *)col_l_elt->data)g_strdup_inline ((char *)col_l_elt->data);
2929 | col_l_elt = col_l_elt->next;
2930 | parse_column_format(cfmt, (char *)col_l_elt->data);
2931 | if (prefs.cols_hide_new) {
2932 | cfmt->visible = prefs_is_column_visible(*hidden_pref->varp.string, cidx);
2933 | } else {
2934 | cfmt->visible = prefs_is_column_fmt_visible(*hidden_pref->varp.string, cfmt);
2935 | }
2936 | col_l_elt = col_l_elt->next;
2937 | *pref->varp.list = g_list_append(*pref->varp.list, cfmt);
2938 | cidx++;
2939 | }
2940 |
2941 | prefs_clear_string_list(col_l);
2942 | free_string_like_preference(hidden_pref);
2943 | column_register_fields();
2944 | return PREFS_SET_OK;
2945 | }
2946 |
2947 |
2948 | static const char *
2949 | column_format_type_name_cb(void)
2950 | {
2951 | return "Packet list column format";
2952 | }
2953 |
2954 | static char *
2955 | column_format_type_description_cb(void)
2956 | {
2957 | return g_strdup("Each pair of strings consists of a column title and its format")g_strdup_inline ("Each pair of strings consists of a column title and its format" );
2958 | }
2959 |
2960 | static bool_Bool
2961 | column_format_is_default_cb(pref_t* pref)
2962 | {
2963 | GList *clp = *pref->varp.list,
2964 | *pref_col = g_list_first(clp),
2965 | *def_col = g_list_first(pref->default_val.list);
2966 | fmt_data *cfmt, *def_cfmt;
2967 | bool_Bool is_default = true1;
2968 | pref_t *col_num_pref;
2969 |
2970 | /* See if the column data has changed from the default */
2971 | col_num_pref = prefs_find_preference(gui_column_module, PRS_COL_NUM"column.number");
2972 | if (col_num_pref && *col_num_pref->varp.uint != col_num_pref->default_val.uint) {
2973 | is_default = false0;
2974 | } else {
2975 | while (pref_col && def_col) {
2976 | cfmt = (fmt_data *) pref_col->data;
2977 | def_cfmt = (fmt_data *) def_col->data;
2978 | if ((g_strcmp0(cfmt->title, def_cfmt->title) != 0) ||
2979 | (cfmt->fmt != def_cfmt->fmt) ||
2980 | (((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_fields)) &&
2981 | ((g_strcmp0(cfmt->custom_fields, def_cfmt->custom_fields) != 0) ||
2982 | (cfmt->display != def_cfmt->display)))) {
2983 | is_default = false0;
2984 | break;
2985 | }
2986 |
2987 | pref_col = pref_col->next;
2988 | def_col = def_col->next;
2989 | }
2990 | }
2991 |
2992 | return is_default;
2993 | }
2994 |
2995 | static char *
2996 | column_format_to_str_cb(pref_t* pref, bool_Bool default_val)
2997 | {
2998 | GList *pref_l = default_val ? pref->default_val.list : *pref->varp.list;
2999 | GList *clp = g_list_first(pref_l);
3000 | GList *col_l;
3001 | fmt_data *cfmt;
3002 | char *column_format_str;
3003 |
3004 | col_l = NULL((void*)0);
3005 | while (clp) {
3006 | cfmt = (fmt_data *) clp->data;
3007 | col_l = g_list_append(col_l, g_strdup(cfmt->title)g_strdup_inline (cfmt->title));
3008 | col_l = g_list_append(col_l, column_fmt_data_to_str(cfmt));
3009 | clp = clp->next;
3010 | }
3011 |
3012 | column_format_str = join_string_list(col_l);
3013 | prefs_clear_string_list(col_l);
3014 | return column_format_str;
3015 | }
3016 |
3017 |
3018 | /****** Capture column custom preference functions ******/
3019 |
3020 | /* This routine is only called when Wireshark is started, NOT when another profile is selected.
3021 | Copy the pref->capture_columns list (just loaded with the capture_cols[] struct values)
3022 | to prefs->default_val.list.
3023 | */
3024 | static void
3025 | capture_column_init_cb(pref_t* pref, GList** capture_cols_values)
3026 | {
3027 | GList *ccv_list = *capture_cols_values,
3028 | *dlist = NULL((void*)0);
3029 |
3030 | /* */
3031 | while (ccv_list) {
3032 | dlist = g_list_append(dlist, g_strdup((char *)ccv_list->data)g_strdup_inline ((char *)ccv_list->data));
3033 | ccv_list = ccv_list->next;
3034 | }
3035 |
3036 | pref->default_val.list = dlist;
3037 | pref->varp.list = &prefs.capture_columns;
3038 | pref->stashed_val.boolval = false0;
3039 | }
3040 |
3041 | /* Free the prefs->capture_columns list strings and remove the list entries.
3042 | Note that since pref->varp.list points to &prefs.capture_columns, it is
3043 | also freed.
3044 | */
3045 | static void
3046 | capture_column_free_cb(pref_t* pref)
3047 | {
3048 | prefs_clear_string_list(prefs.capture_columns);
3049 | prefs.capture_columns = NULL((void*)0);
3050 |
3051 | if (pref->stashed_val.boolval == true1) {
3052 | prefs_clear_string_list(pref->default_val.list);
3053 | pref->default_val.list = NULL((void*)0);
3054 | }
3055 | }
3056 |
3057 | /* Copy pref->default_val.list to *pref->varp.list.
3058 | */
3059 | static void
3060 | capture_column_reset_cb(pref_t* pref)
3061 | {
3062 | GList *vlist = NULL((void*)0), *dlist;
3063 |
3064 | /* Free the column name strings and remove the links from *pref->varp.list */
3065 | prefs_clear_string_list(*pref->varp.list);
3066 |
3067 | for (dlist = pref->default_val.list; dlist != NULL((void*)0); dlist = g_list_next(dlist)((dlist) ? (((GList *)(dlist))->next) : ((void*)0))) {
3068 | vlist = g_list_append(vlist, g_strdup((char *)dlist->data)g_strdup_inline ((char *)dlist->data));
3069 | }
3070 | *pref->varp.list = vlist;
3071 | }
3072 |
3073 | static prefs_set_pref_e
3074 | capture_column_set_cb(pref_t* pref, const char* value, unsigned int* changed_flags _U___attribute__((unused)))
3075 | {
3076 | GList *col_l = prefs_get_string_list(value);
3077 | GList *col_l_elt;
3078 | char *col_name;
3079 | int i;
3080 |
3081 | if (col_l == NULL((void*)0))
3082 | return PREFS_SET_SYNTAX_ERR;
3083 |
3084 | capture_column_free_cb(pref);
3085 |
3086 | /* If value (the list of capture.columns read from preferences) is empty, set capture.columns
3087 | to the full list of valid capture column names. */
3088 | col_l_elt = g_list_first(col_l);
3089 | if (!(*(char *)col_l_elt->data)) {
3090 | for (i = 0; i < num_capture_cols; i++) {
3091 | col_name = g_strdup(capture_cols[i])g_strdup_inline (capture_cols[i]);
3092 | prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
3093 | }
3094 | }
3095 |
3096 | /* Verify that all the column names are valid. If not, use the entire list of valid columns.
3097 | */
3098 | while (col_l_elt) {
3099 | bool_Bool found_match = false0;
3100 | col_name = (char *)col_l_elt->data;
3101 |
3102 | for (i = 0; i < num_capture_cols; i++) {
3103 | if (strcmp(col_name, capture_cols[i])==0) {
3104 | found_match = true1;
3105 | break;
3106 | }
3107 | }
3108 | if (!found_match) {
3109 | /* One or more cols are invalid so use the entire list of valid cols. */
3110 | for (i = 0; i < num_capture_cols; i++) {
3111 | col_name = g_strdup(capture_cols[i])g_strdup_inline (capture_cols[i]);
3112 | prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
3113 | }
3114 | pref->varp.list = &prefs.capture_columns;
3115 | prefs_clear_string_list(col_l);
3116 | return PREFS_SET_SYNTAX_ERR;
3117 | }
3118 | col_l_elt = col_l_elt->next;
3119 | }
3120 |
3121 | col_l_elt = g_list_first(col_l);
3122 | while (col_l_elt) {
3123 | col_name = (char *)col_l_elt->data;
3124 | prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
3125 | col_l_elt = col_l_elt->next;
3126 | }
3127 | pref->varp.list = &prefs.capture_columns;
3128 | g_list_free(col_l);
3129 | return PREFS_SET_OK;
3130 | }
3131 |
3132 |
3133 | static const char *
3134 | capture_column_type_name_cb(void)
3135 | {
3136 | return "Column list";
3137 | }
3138 |
3139 | static char *
3140 | capture_column_type_description_cb(void)
3141 | {
3142 | return g_strdup(g_strdup_inline ("List of columns to be displayed in the capture options dialog.\n" "Possible values: INTERFACE, LINK, PMODE, SNAPLEN, MONITOR, BUFFER, FILTER\n" )
3143 | "List of columns to be displayed in the capture options dialog.\n"g_strdup_inline ("List of columns to be displayed in the capture options dialog.\n" "Possible values: INTERFACE, LINK, PMODE, SNAPLEN, MONITOR, BUFFER, FILTER\n" )
3144 | CAPTURE_COL_TYPE_DESCRIPTION)g_strdup_inline ("List of columns to be displayed in the capture options dialog.\n" "Possible values: INTERFACE, LINK, PMODE, SNAPLEN, MONITOR, BUFFER, FILTER\n" );
3145 | }
3146 |
3147 | static bool_Bool
3148 | capture_column_is_default_cb(pref_t* pref)
3149 | {
3150 | GList *pref_col = g_list_first(prefs.capture_columns),
3151 | *def_col = g_list_first(pref->default_val.list);
3152 | bool_Bool is_default = true1;
3153 |
3154 | /* See if the column data has changed from the default */
3155 | while (pref_col && def_col) {
3156 | if (strcmp((char *)pref_col->data, (char *)def_col->data) != 0) {
3157 | is_default = false0;
3158 | break;
3159 | }
3160 | pref_col = pref_col->next;
3161 | def_col = def_col->next;
3162 | }
3163 |
3164 | /* Ensure the same column count */
3165 | if (((pref_col == NULL((void*)0)) && (def_col != NULL((void*)0))) ||
3166 | ((pref_col != NULL((void*)0)) && (def_col == NULL((void*)0))))
3167 | is_default = false0;
3168 |
3169 | return is_default;
3170 | }
3171 |
3172 | static char *
3173 | capture_column_to_str_cb(pref_t* pref, bool_Bool default_val)
3174 | {
3175 |
3176 | GList *pref_l = default_val ? pref->default_val.list : prefs.capture_columns;
3177 | GList *clp = g_list_first(pref_l);
3178 | GList *col_l = NULL((void*)0);
3179 | char *col;
3180 | char *capture_column_str;
3181 |
3182 | while (clp) {
3183 | col = (char *) clp->data;
3184 | col_l = g_list_append(col_l, g_strdup(col)g_strdup_inline (col));
3185 | clp = clp->next;
3186 | }
3187 |
3188 | capture_column_str = join_string_list(col_l);
3189 | prefs_clear_string_list(col_l);
3190 | return capture_column_str;
3191 | }
3192 |
3193 | static prefs_set_pref_e
3194 | colorized_frame_set_cb(pref_t* pref, const char* value, unsigned int* changed_flags)
3195 | {
3196 | (*changed_flags) |= prefs_set_string_value(pref, value, pref_current);
3197 | return PREFS_SET_OK;
3198 | }
3199 |
3200 | static const char *
3201 | colorized_frame_type_name_cb(void)
3202 | {
3203 | /* Don't write the colors of the 10 easy-access-colorfilters to the preferences
3204 | * file until the colors can be changed in the GUI. Currently this is not really
3205 | * possible since the STOCK-icons for these colors are hardcoded.
3206 | *
3207 | * XXX Find a way to change the colors of the STOCK-icons on the fly and then
3208 | * add these 10 colors to the list of colors that can be changed through
3209 | * the preferences.
3210 | *
3211 | */
3212 | return NULL((void*)0);
3213 | }
3214 |
3215 | static char *
3216 | colorized_frame_type_description_cb(void)
3217 | {
3218 | return g_strdup("")g_strdup_inline ("");
3219 | }
3220 |
3221 | static bool_Bool
3222 | colorized_frame_is_default_cb(pref_t* pref _U___attribute__((unused)))
3223 | {
3224 | return true1;
3225 | }
3226 |
3227 | static char *
3228 | colorized_frame_to_str_cb(pref_t* pref _U___attribute__((unused)), bool_Bool default_val _U___attribute__((unused)))
3229 | {
3230 | return g_strdup("")g_strdup_inline ("");
3231 | }
3232 |
3233 | /*
3234 | * Register all non-dissector modules' preferences.
3235 | */
3236 | static module_t *gui_module;
3237 | static module_t *gui_color_module;
3238 | static module_t *nameres_module;
3239 |
3240 | static void
3241 | prefs_register_modules(void)
3242 | {
3243 | module_t *printing, *capture_module, *console_module,
3244 | *gui_layout_module, *gui_font_module;
3245 | module_t *extcap_module;
3246 | unsigned int layout_gui_flags;
3247 | struct pref_custom_cbs custom_cbs;
3248 |
3249 | if (protocols_module != NULL((void*)0)) {
3250 | /* Already setup preferences */
3251 | return;
3252 | }
3253 |
3254 | /* GUI
3255 | * These are "simple" GUI preferences that can be read/written using the
3256 | * preference module API. These preferences still use their own
3257 | * configuration screens for access, but this cuts down on the
3258 | * preference "string compare list" in set_pref()
3259 | */
3260 | extcap_module = prefs_register_module(prefs_top_level_modules, prefs_modules, "extcap", "Extcap Utilities",
3261 | "Extcap Utilities", NULL((void*)0), NULL((void*)0), false0);
3262 |
3263 | /* Setting default value to true */
3264 | prefs.extcap_save_on_start = true1;
3265 | prefs_register_bool_preference(extcap_module, "gui_save_on_start",
3266 | "Save arguments on start of capture",
3267 | "Save arguments on start of capture",
3268 | &prefs.extcap_save_on_start);
3269 |
3270 | /* GUI
3271 | * These are "simple" GUI preferences that can be read/written using the
3272 | * preference module API. These preferences still use their own
3273 | * configuration screens for access, but this cuts down on the
3274 | * preference "string compare list" in set_pref()
3275 | */
3276 | gui_module = prefs_register_module(prefs_top_level_modules, prefs_modules, "gui", "User Interface",
3277 | "User Interface", NULL((void*)0), &gui_callback, false0);
3278 | /*
3279 | * The GUI preferences don't affect dissection in general.
3280 | * Any changes are signaled in other ways, so PREF_EFFECT_GUI doesn't
3281 | * explicitly do anything, but wslua_set_preference expects *some*
3282 | * effect flag to be set if the preference was changed.
3283 | * We have to do this again for all the submodules (except for the
3284 | * layout submodule, which has its own effect flag).
3285 | */
3286 | unsigned gui_effect_flags = prefs_get_module_effect_flags(gui_module);
3287 | gui_effect_flags |= PREF_EFFECT_GUI(1u << 4);
3288 | gui_effect_flags &= (~PREF_EFFECT_DISSECTION(1u << 0));
3289 | prefs_set_module_effect_flags(gui_module, gui_effect_flags);
3290 |
3291 | /*
3292 | * gui.console_open is stored in the registry in addition to the
3293 | * preferences file. It is also read independently by ws_log_init()
3294 | * for early log initialization of the console.
3295 | */
3296 | prefs_register_enum_preference(gui_module, "console_open",
3297 | "Open a console window",
3298 | "Open a console window (Windows only)",
3299 | (int *)&ws_log_console_open, gui_console_open_type, false0);
3300 |
3301 | prefs_register_obsolete_preference(gui_module, "scrollbar_on_right");
3302 | prefs_register_obsolete_preference(gui_module, "packet_list_sel_browse");
3303 | prefs_register_obsolete_preference(gui_module, "protocol_tree_sel_browse");
3304 | prefs_register_obsolete_preference(gui_module, "tree_view_altern_colors");
3305 | prefs_register_obsolete_preference(gui_module, "expert_composite_eyecandy");
3306 | prefs_register_obsolete_preference(gui_module, "filter_toolbar_show_in_statusbar");
3307 |
3308 | prefs_register_bool_preference(gui_module, "restore_filter_after_following_stream",
3309 | "Restore current display filter after following a stream",
3310 | "Restore current display filter after following a stream?",
3311 | &prefs.restore_filter_after_following_stream);
3312 |
3313 | prefs_register_obsolete_preference(gui_module, "protocol_tree_line_style");
3314 |
3315 | prefs_register_obsolete_preference(gui_module, "protocol_tree_expander_style");
3316 |
3317 | prefs_register_obsolete_preference(gui_module, "hex_dump_highlight_style");
3318 |
3319 | prefs_register_obsolete_preference(gui_module, "packet_editor.enabled");
3320 |
3321 | gui_column_module = prefs_register_subtree(gui_module, prefs_modules, "Columns", "Columns", NULL((void*)0));
3322 | prefs_set_module_effect_flags(gui_column_module, gui_effect_flags);
3323 | /* For reading older preference files with "column." preferences */
3324 | prefs_register_module_alias("column", gui_column_module);
3325 |
3326 |
3327 | custom_cbs.free_cb = free_string_like_preference;
3328 | custom_cbs.reset_cb = reset_string_like_preference;
3329 | custom_cbs.set_cb = column_hidden_set_cb;
3330 | custom_cbs.type_name_cb = column_hidden_type_name_cb;
3331 | custom_cbs.type_description_cb = column_hidden_type_description_cb;
3332 | custom_cbs.is_default_cb = column_hidden_is_default_cb;
3333 | custom_cbs.to_str_cb = column_hidden_to_str_cb;
3334 | register_string_like_preference(gui_column_module, PRS_COL_HIDDEN"column.hide", "Packet list hidden columns",
3335 | "List all column indices (1-indexed) to hide in the packet list",
3336 | &cols_hidden_list, PREF_CUSTOM, &custom_cbs, false0);
3337 |
3338 | custom_cbs.set_cb = column_hidden_fmt_set_cb;
3339 | custom_cbs.type_name_cb = column_hidden_fmt_type_name_cb;
3340 | custom_cbs.type_description_cb = column_hidden_fmt_type_description_cb;
3341 | custom_cbs.is_default_cb = column_hidden_fmt_is_default_cb;
3342 | custom_cbs.to_str_cb = column_hidden_fmt_to_str_cb;
3343 |
3344 | register_string_like_preference(gui_column_module, PRS_COL_HIDDEN_FMT"column.hidden", "Packet list hidden column formats (deprecated)",
3345 | "List all column formats to hide in the packet list; deprecated in favor of the index-based preference",
3346 | &cols_hidden_fmt_list, PREF_CUSTOM, &custom_cbs, false0);
3347 |
3348 | custom_cbs.free_cb = column_format_free_cb;
3349 | custom_cbs.reset_cb = column_format_reset_cb;
3350 | custom_cbs.set_cb = column_format_set_cb;
3351 | custom_cbs.type_name_cb = column_format_type_name_cb;
3352 | custom_cbs.type_description_cb = column_format_type_description_cb;
3353 | custom_cbs.is_default_cb = column_format_is_default_cb;
3354 | custom_cbs.to_str_cb = column_format_to_str_cb;
3355 |
3356 | prefs_register_list_custom_preference(gui_column_module, PRS_COL_FMT"column.format", "Packet list column format",
3357 | "Each pair of strings consists of a column title and its format", &custom_cbs,
3358 | column_format_init_cb, &prefs.col_list);
3359 |
3360 | /* Number of columns. This is only used internally and is not written to the
3361 | * preference file
3362 | */
3363 | custom_cbs.free_cb = custom_pref_no_cb;
3364 | custom_cbs.reset_cb = column_num_reset_cb;
3365 | custom_cbs.set_cb = column_num_set_cb;
3366 | custom_cbs.type_name_cb = column_num_type_name_cb;
3367 | custom_cbs.type_description_cb = column_num_type_description_cb;
3368 | custom_cbs.is_default_cb = column_num_is_default_cb;
3369 | custom_cbs.to_str_cb = column_num_to_str_cb;
3370 | prefs_register_uint_custom_preference(gui_column_module, PRS_COL_NUM"column.number", "Number of columns",
3371 | "Number of columns in col_list", &custom_cbs, &prefs.num_cols);
3372 |
3373 | /* User Interface : Font */
3374 | gui_font_module = prefs_register_subtree(gui_module, prefs_modules, "Font", "Font", NULL((void*)0));
3375 | prefs_set_module_effect_flags(gui_font_module, gui_effect_flags);
3376 |
3377 | prefs_register_obsolete_preference(gui_font_module, "font_name");
3378 |
3379 | prefs_register_obsolete_preference(gui_font_module, "gtk2.font_name");
3380 |
3381 | register_string_like_preference(gui_font_module, "qt.font_name", "Font name",
3382 | "Font name for packet list, protocol tree, and hex dump panes. (Qt)",
3383 | &prefs.gui_font_name, PREF_STRING, NULL((void*)0), true1);
3384 |
3385 | /* User Interface : Colors */
3386 | gui_color_module = prefs_register_subtree(gui_module, prefs_modules, "Colors", "Colors", NULL((void*)0));
3387 | unsigned gui_color_effect_flags = gui_effect_flags | PREF_EFFECT_GUI_COLOR(1u << 5);
3388 | prefs_set_module_effect_flags(gui_color_module, gui_color_effect_flags);
3389 |
3390 | prefs_register_enum_preference(gui_color_module, "color_scheme", "Color scheme", "Color scheme",
3391 | &prefs.gui_color_scheme, gui_color_scheme, false0);
3392 |
3393 | prefs_register_color_preference(gui_color_module, "active_frame.fg", "Foreground color for an active selected item",
3394 | "Foreground color for an active selected item", &prefs.gui_active_fg);
3395 |
3396 | prefs_register_color_preference(gui_color_module, "active_frame.bg", "Background color for an active selected item",
3397 | "Background color for an active selected item", &prefs.gui_active_bg);
3398 |
3399 | prefs_register_enum_preference(gui_color_module, "active_frame.style", "Color style for an active selected item",
3400 | "Color style for an active selected item", &prefs.gui_active_style, gui_selection_style, false0);
3401 |
3402 | prefs_register_color_preference(gui_color_module, "inactive_frame.fg", "Foreground color for an inactive selected item",
3403 | "Foreground color for an inactive selected item", &prefs.gui_inactive_fg);
3404 |
3405 | prefs_register_color_preference(gui_color_module, "inactive_frame.bg", "Background color for an inactive selected item",
3406 | "Background color for an inactive selected item", &prefs.gui_inactive_bg);
3407 |
3408 | prefs_register_enum_preference(gui_color_module, "inactive_frame.style", "Color style for an inactive selected item",
3409 | "Color style for an inactive selected item", &prefs.gui_inactive_style, gui_selection_style, false0);
3410 |
3411 | prefs_register_color_preference(gui_color_module, "marked_frame.fg", "Color preferences for a marked frame",
3412 | "Color preferences for a marked frame", &prefs.gui_marked_fg);
3413 |
3414 | prefs_register_color_preference(gui_color_module, "marked_frame.bg", "Color preferences for a marked frame",
3415 | "Color preferences for a marked frame", &prefs.gui_marked_bg);
3416 |
3417 | prefs_register_color_preference(gui_color_module, "ignored_frame.fg", "Color preferences for a ignored frame",
3418 | "Color preferences for a ignored frame", &prefs.gui_ignored_fg);
3419 |
3420 | prefs_register_color_preference(gui_color_module, "ignored_frame.bg", "Color preferences for a ignored frame",
3421 | "Color preferences for a ignored frame", &prefs.gui_ignored_bg);
3422 |
3423 | prefs_register_color_preference(gui_color_module, "stream.client.fg", "TCP stream window color preference",
3424 | "TCP stream window color preference", &prefs.st_client_fg);
3425 |
3426 | prefs_register_color_preference(gui_color_module, "stream.client.bg", "TCP stream window color preference",
3427 | "TCP stream window color preference", &prefs.st_client_bg);
3428 |
3429 | prefs_register_color_preference(gui_color_module, "stream.server.fg", "TCP stream window color preference",
3430 | "TCP stream window color preference", &prefs.st_server_fg);
3431 |
3432 | prefs_register_color_preference(gui_color_module, "stream.server.bg", "TCP stream window color preference",
3433 | "TCP stream window color preference", &prefs.st_server_bg);
3434 |
3435 | custom_cbs.free_cb = free_string_like_preference;
3436 | custom_cbs.reset_cb = reset_string_like_preference;
3437 | custom_cbs.set_cb = colorized_frame_set_cb;
3438 | custom_cbs.type_name_cb = colorized_frame_type_name_cb;
3439 | custom_cbs.type_description_cb = colorized_frame_type_description_cb;
3440 | custom_cbs.is_default_cb = colorized_frame_is_default_cb;
3441 | custom_cbs.to_str_cb = colorized_frame_to_str_cb;
3442 | register_string_like_preference(gui_column_module, "colorized_frame.fg", "Colorized Foreground",
3443 | "Filter Colorized Foreground",
3444 | &prefs.gui_colorized_fg, PREF_CUSTOM, &custom_cbs, true1);
3445 |
3446 | custom_cbs.free_cb = free_string_like_preference;
3447 | custom_cbs.reset_cb = reset_string_like_preference;
3448 | custom_cbs.set_cb = colorized_frame_set_cb;
3449 | custom_cbs.type_name_cb = colorized_frame_type_name_cb;
3450 | custom_cbs.type_description_cb = colorized_frame_type_description_cb;
3451 | custom_cbs.is_default_cb = colorized_frame_is_default_cb;
3452 | custom_cbs.to_str_cb = colorized_frame_to_str_cb;
3453 | register_string_like_preference(gui_column_module, "colorized_frame.bg", "Colorized Background",
3454 | "Filter Colorized Background",
3455 | &prefs.gui_colorized_bg, PREF_CUSTOM, &custom_cbs, true1);
3456 |
3457 | prefs_register_color_preference(gui_color_module, "color_filter_fg.valid", "Valid color filter foreground",
3458 | "Valid color filter foreground", &prefs.gui_filter_valid_fg);
3459 | prefs_register_color_preference(gui_color_module, "color_filter_bg.valid", "Valid color filter background",
3460 | "Valid color filter background", &prefs.gui_filter_valid_bg);
3461 |
3462 | prefs_register_color_preference(gui_color_module, "color_filter_fg.invalid", "Invalid color filter foreground",
3463 | "Invalid color filter foreground", &prefs.gui_filter_invalid_fg);
3464 | prefs_register_color_preference(gui_color_module, "color_filter_bg.invalid", "Invalid color filter background",
3465 | "Invalid color filter background", &prefs.gui_filter_invalid_bg);
3466 |
3467 | prefs_register_color_preference(gui_color_module, "color_filter_fg.deprecated", "Deprecated color filter foreground",
3468 | "Deprecated color filter foreground", &prefs.gui_filter_deprecated_fg);
3469 | prefs_register_color_preference(gui_color_module, "color_filter_bg.deprecated", "Deprecated color filter background",
3470 | "Deprecated color filter background", &prefs.gui_filter_deprecated_bg);
3471 |
3472 | prefs_register_enum_preference(gui_module, "fileopen.style",
3473 | "Where to start the File Open dialog box",
3474 | "Where to start the File Open dialog box",
3475 | (int*)&prefs.gui_fileopen_style, gui_fileopen_style, false0);
3476 |
3477 | prefs_register_uint_preference(gui_module, "recent_files_count.max",
3478 | "The max. number of items in the open recent files list",
3479 | "The max. number of items in the open recent files list",
3480 | 10,
3481 | &prefs.gui_recent_files_count_max);
3482 |
3483 | prefs_register_uint_preference(gui_module, "recent_display_filter_entries.max",
3484 | "The max. number of entries in the display filter list",
3485 | "The max. number of entries in the display filter list",
3486 | 10,
3487 | &prefs.gui_recent_df_entries_max);
3488 |
3489 | register_string_like_preference(gui_module, "fileopen.dir", "Start Directory",
3490 | "Directory to start in when opening File Open dialog.",
3491 | &prefs.gui_fileopen_dir, PREF_DIRNAME, NULL((void*)0), true1);
3492 |
3493 | prefs_register_obsolete_preference(gui_module, "fileopen.remembered_dir");
3494 |
3495 | prefs_register_uint_preference(gui_module, "fileopen.preview",
3496 | "The preview timeout in the File Open dialog",
3497 | "The preview timeout in the File Open dialog",
3498 | 10,
3499 | &prefs.gui_fileopen_preview);
3500 |
3501 | register_string_like_preference(gui_module, "tlskeylog_command", "Program to launch with TLS Keylog",
3502 | "Program path or command line to launch with SSLKEYLOGFILE",
3503 | &prefs.gui_tlskeylog_command, PREF_STRING, NULL((void*)0), true1);
3504 |
3505 | prefs_register_bool_preference(gui_module, "ask_unsaved",
3506 | "Ask to save unsaved capture files",
3507 | "Ask to save unsaved capture files?",
3508 | &prefs.gui_ask_unsaved);
3509 |
3510 | prefs_register_bool_preference(gui_module, "autocomplete_filter",
3511 | "Display autocompletion for filter text",
3512 | "Display an autocomplete suggestion for display and capture filter controls",
3513 | &prefs.gui_autocomplete_filter);
3514 |
3515 | prefs_register_bool_preference(gui_module, "find_wrap",
3516 | "Wrap to beginning/end of file during search",
3517 | "Wrap to beginning/end of file during search?",
3518 | &prefs.gui_find_wrap);
3519 |
3520 | prefs_register_obsolete_preference(gui_module, "use_pref_save");
3521 |
3522 | prefs_register_bool_preference(gui_module, "geometry.save.position",
3523 | "Save window position at exit",
3524 | "Save window position at exit?",
3525 | &prefs.gui_geometry_save_position);
3526 |
3527 | prefs_register_bool_preference(gui_module, "geometry.save.size",
3528 | "Save window size at exit",
3529 | "Save window size at exit?",
3530 | &prefs.gui_geometry_save_size);
3531 |
3532 | prefs_register_bool_preference(gui_module, "geometry.save.maximized",
3533 | "Save window maximized state at exit",
3534 | "Save window maximized state at exit?",
3535 | &prefs.gui_geometry_save_maximized);
3536 |
3537 | prefs_register_obsolete_preference(gui_module, "macosx_style");
3538 |
3539 | prefs_register_obsolete_preference(gui_module, "geometry.main.x");
3540 | prefs_register_obsolete_preference(gui_module, "geometry.main.y");
3541 | prefs_register_obsolete_preference(gui_module, "geometry.main.width");
3542 | prefs_register_obsolete_preference(gui_module, "geometry.main.height");
3543 | prefs_register_obsolete_preference(gui_module, "toolbar_main_show");
3544 |
3545 | prefs_register_enum_preference(gui_module, "toolbar_main_style",
3546 | "Main Toolbar style",
3547 | "Main Toolbar style",
3548 | &prefs.gui_toolbar_main_style, gui_toolbar_style, false0);
3549 |
3550 | prefs_register_obsolete_preference(gui_module, "toolbar_filter_style");
3551 | prefs_register_obsolete_preference(gui_module, "webbrowser");
3552 |
3553 | prefs_register_bool_preference(gui_module, "update.enabled",
3554 | "Check for updates",
3555 | "Check for updates (Windows and macOS only)",
3556 | &prefs.gui_update_enabled);
3557 |
3558 | prefs_register_enum_preference(gui_module, "update.channel",
3559 | "Update channel",
3560 | "The type of update to fetch. You should probably leave this set to STABLE.",
3561 | (int*)(void*)(&prefs.gui_update_channel), gui_update_channel, false0);
3562 |
3563 | prefs_register_uint_preference(gui_module, "update.interval",
3564 | "How often to check for software updates",
3565 | "How often to check for software updates in seconds",
3566 | 10,
3567 | &prefs.gui_update_interval);
3568 |
3569 | prefs_register_uint_preference(gui_module, "debounce.timer",
3570 | "How long to wait before processing computationally intensive user input",
3571 | "How long to wait (in milliseconds) before processing "
3572 | "computationally intensive user input. "
3573 | "If you type quickly, consider lowering the value for a 'snappier' "
3574 | "experience. "
3575 | "If you type slowly, consider increasing the value to avoid performance issues. "
3576 | "This is currently used to delay searches in View -> Internals -> Supported Protocols "
3577 | "and Preferences -> Advanced menu.",
3578 | 10,
3579 | &prefs.gui_debounce_timer);
3580 |
3581 | register_string_like_preference(gui_module, "window_title", "Custom window title",
3582 | "Custom window title to be appended to the existing title\n"
3583 | "%C = capture comment from command line\n"
3584 | "%F = file path of the capture file\n"
3585 | "%P = profile name\n"
3586 | "%S = a conditional separator (\" - \") that only shows when surrounded by variables with values or static text\n"
3587 | "%V = version info",
3588 | &prefs.gui_window_title, PREF_STRING, NULL((void*)0), true1);
3589 |
3590 | register_string_like_preference(gui_module, "prepend_window_title", "Custom window title prefix",
3591 | "Custom window title to be prepended to the existing title\n"
3592 | "%C = capture comment from command line\n"
3593 | "%F = file path of the capture file\n"
3594 | "%P = profile name\n"
3595 | "%S = a conditional separator (\" - \") that only shows when surrounded by variables with values or static text\n"
3596 | "%V = version info",
3597 | &prefs.gui_prepend_window_title, PREF_STRING, NULL((void*)0), true1);
3598 |
3599 | register_string_like_preference(gui_module, "start_title", "Custom start page title",
3600 | "Custom start page title",
3601 | &prefs.gui_start_title, PREF_STRING, NULL((void*)0), true1);
3602 |
3603 | prefs_register_enum_preference(gui_module, "version_placement",
3604 | "Show version in the start page and/or main screen's title bar",
3605 | "Show version in the start page and/or main screen's title bar",
3606 | (int*)(void*)(&prefs.gui_version_placement), gui_version_placement_type, false0);
3607 |
3608 | prefs_register_obsolete_preference(gui_module, "auto_scroll_on_expand");
3609 | prefs_register_obsolete_preference(gui_module, "auto_scroll_percentage");
3610 |
3611 | prefs_register_uint_preference(gui_module, "max_export_objects",
3612 | "Maximum number of exported objects",
3613 | "The maximum number of objects that can be exported",
3614 | 10,
3615 | &prefs.gui_max_export_objects);
3616 | prefs_register_uint_preference(gui_module, "max_tree_items",
3617 | "Maximum number of tree items",
3618 | "The maximum number of items that can be added to the dissection tree (Increase with caution)",
3619 | 10,
3620 | &prefs.gui_max_tree_items);
3621 | /*
3622 | * Used independently by proto_tree_add_node, call_dissector*, dissector_try_heuristic,
3623 | * and increment_dissection_depth.
3624 | */
3625 | prefs_register_uint_preference(gui_module, "max_tree_depth",
3626 | "Maximum dissection depth",
3627 | "The maximum depth for dissection tree and protocol layer checks. (Increase with caution)",
3628 | 10,
3629 | &prefs.gui_max_tree_depth);
3630 |
3631 | prefs_register_bool_preference(gui_module, "welcome_page.show_recent",
3632 | "Show recent files on the welcome page",
3633 | "This will enable or disable the 'Open' list on the welcome page.",
3634 | &prefs.gui_welcome_page_show_recent);
3635 |
3636 | /* User Interface : Layout */
3637 | gui_layout_module = prefs_register_subtree(gui_module, prefs_modules, "Layout", "Layout", gui_layout_callback);
3638 | /* Adjust the preference effects of layout GUI for better handling of preferences at Wireshark (GUI) level */
3639 | layout_gui_flags = prefs_get_module_effect_flags(gui_layout_module);
3640 | layout_gui_flags |= PREF_EFFECT_GUI_LAYOUT(1u << 2);
3641 | layout_gui_flags &= (~PREF_EFFECT_DISSECTION(1u << 0));
3642 |
3643 | prefs_register_uint_preference(gui_layout_module, "layout_type",
3644 | "Layout type",
3645 | "Layout type (1-6)",
3646 | 10,
3647 | (unsigned*)(void*)(&prefs.gui_layout_type));
3648 | prefs_set_effect_flags_by_name(gui_layout_module, "layout_type", layout_gui_flags);
3649 |
3650 | prefs_register_enum_preference(gui_layout_module, "layout_content_1",
3651 | "Layout content of the pane 1",
3652 | "Layout content of the pane 1",
3653 | (int*)(void*)(&prefs.gui_layout_content_1), gui_layout_content, false0);
3654 | prefs_set_effect_flags_by_name(gui_layout_module, "layout_content_1", layout_gui_flags);
3655 |
3656 | prefs_register_enum_preference(gui_layout_module, "layout_content_2",
3657 | "Layout content of the pane 2",
3658 | "Layout content of the pane 2",
3659 | (int*)(void*)(&prefs.gui_layout_content_2), gui_layout_content, false0);
3660 | prefs_set_effect_flags_by_name(gui_layout_module, "layout_content_2", layout_gui_flags);
3661 |
3662 | prefs_register_enum_preference(gui_layout_module, "layout_content_3",
3663 | "Layout content of the pane 3",
3664 | "Layout content of the pane 3",
3665 | (int*)(void*)(&prefs.gui_layout_content_3), gui_layout_content, false0);
3666 | prefs_set_effect_flags_by_name(gui_layout_module, "layout_content_3", layout_gui_flags);
3667 |
3668 | prefs_register_bool_preference(gui_layout_module, "packet_list_separator.enabled",
3669 | "Enable Packet List Separator",
3670 | "Enable Packet List Separator",
3671 | &prefs.gui_packet_list_separator);
3672 |
3673 | prefs_register_bool_preference(gui_layout_module, "packet_header_column_definition.enabled",
3674 | "Show column definition in packet list header",
3675 | "Show column definition in packet list header",
3676 | &prefs.gui_packet_header_column_definition);
3677 |
3678 | /* packet_list_hover_style affects the colors, not the layout.
3679 | * It's in the layout module to group it with the other packet list
3680 | * preferences for the user's benefit with the dialog.
3681 | */
3682 | prefs_register_bool_preference(gui_layout_module, "packet_list_hover_style.enabled",
3683 | "Enable Packet List mouse-over colorization",
3684 | "Enable Packet List mouse-over colorization",
3685 | &prefs.gui_packet_list_hover_style);
3686 | prefs_set_effect_flags_by_name(gui_layout_module, "packet_list_hover_style.enabled", gui_color_effect_flags);
3687 |
3688 | prefs_register_bool_preference(gui_layout_module, "show_selected_packet.enabled",
3689 | "Show selected packet in the Status Bar",
3690 | "Show selected packet in the Status Bar",
3691 | &prefs.gui_show_selected_packet);
3692 |
3693 | prefs_register_bool_preference(gui_layout_module, "show_file_load_time.enabled",
3694 | "Show file load time in the Status Bar",
3695 | "Show file load time in the Status Bar",
3696 | &prefs.gui_show_file_load_time);
3697 |
3698 | prefs_register_enum_preference(gui_layout_module, "packet_dialog_layout",
3699 | "Packet Dialog layout",
3700 | "Packet Dialog layout",
3701 | (int*)(&prefs.gui_packet_dialog_layout), gui_packet_dialog_layout, false0);
3702 |
3703 | prefs_register_enum_preference(gui_module, "packet_list_elide_mode",
3704 | "Elide mode",
3705 | "The position of \"...\" (ellipsis) in packet list text.",
3706 | (int*)(void*)(&prefs.gui_packet_list_elide_mode), gui_packet_list_elide_mode, false0);
3707 | prefs_register_uint_preference(gui_module, "decimal_places1",
3708 | "Count of decimal places for values of type 1",
3709 | "Sets the count of decimal places for values of type 1."
3710 | "Type 1 values are defined by authors."
3711 | "Value can be in range 2 to 10.",
3712 | 10,&prefs.gui_decimal_places1);
3713 |
3714 | prefs_register_uint_preference(gui_module, "decimal_places2",
3715 | "Count of decimal places for values of type 2",
3716 | "Sets the count of decimal places for values of type 2."
3717 | "Type 2 values are defined by authors."
3718 | "Value can be in range 2 to 10.",
3719 | 10,&prefs.gui_decimal_places2);
3720 |
3721 | prefs_register_uint_preference(gui_module, "decimal_places3",
3722 | "Count of decimal places for values of type 3",
3723 | "Sets the count of decimal places for values of type 3."
3724 | "Type 3 values are defined by authors."
3725 | "Value can be in range 2 to 10.",
3726 | 10,&prefs.gui_decimal_places3);
3727 |
3728 | prefs_register_bool_preference(gui_module, "rtp_player_use_disk1",
3729 | "RTP Player saves temporary data to disk",
3730 | "If set to true, RTP Player saves temporary data to "
3731 | "temp files on disk. If not set, it uses memory."
3732 | "Every stream uses one file therefore you might touch "
3733 | "OS limit for count of opened files."
3734 | "When ui.rtp_player_use_disk2 is set to true too, it uses "
3735 | " two files per RTP stream together."
3736 | ,&prefs.gui_rtp_player_use_disk1);
3737 |
3738 | prefs_register_bool_preference(gui_module, "rtp_player_use_disk2",
3739 | "RTP Player saves temporary dictionary for data to disk",
3740 | "If set to true, RTP Player saves temporary dictionary to "
3741 | "temp files on disk. If not set, it uses memory."
3742 | "Every stream uses one file therefore you might touch "
3743 | "OS limit for count of opened files."
3744 | "When ui.rtp_player_use_disk1 is set to true too, it uses "
3745 | " two files per RTP stream."
3746 | ,&prefs.gui_rtp_player_use_disk2);
3747 |
3748 | prefs_register_enum_preference(gui_layout_module, "gui_packet_list_copy_format_options_for_keyboard_shortcut",
3749 | "Allows text to be copied with selected format",
3750 | "Allows text to be copied with selected format when copied via keyboard",
3751 | (int*)(void*)(&prefs.gui_packet_list_copy_format_options_for_keyboard_shortcut),
3752 | gui_packet_list_copy_format_options_for_keyboard_shortcut, false0);
3753 |
3754 | prefs_register_bool_preference(gui_layout_module, "gui_packet_list_copy_text_with_aligned_columns",
3755 | "Allows text to be copied with aligned columns",
3756 | "Allows text to be copied with aligned columns when copied via menu or keyboard",
3757 | &prefs.gui_packet_list_copy_text_with_aligned_columns);
3758 |
3759 | prefs_register_bool_preference(gui_layout_module, "packet_list_show_related",
3760 | "Show Related Packets",
3761 | "Show related packet indicators in the first column",
3762 | &prefs.gui_packet_list_show_related);
3763 |
3764 | prefs_register_bool_preference(gui_layout_module, "packet_list_show_minimap",
3765 | "Enable Intelligent Scroll Bar",
3766 | "Show the intelligent scroll bar (a minimap of packet list colors in the scrollbar)",
3767 | &prefs.gui_packet_list_show_minimap);
3768 |
3769 | prefs_register_enum_preference(gui_layout_module, "packet_list_multi_color_mode",
3770 | "Multi-Color Display Mode",
3771 | "How to display multiple colors: Equal Stripes (entire row) or Shift Right (configurable primary color percentage)",
3772 | (int*)(void*)(&prefs.gui_packet_list_multi_color_mode), gui_packet_list_multi_color_modes, false0);
3773 |
3774 | prefs_register_uint_preference(gui_layout_module, "packet_list_multi_color_shift_percent",
3775 | "Shift Right percentage",
3776 | "Primary color percentage in Shift Right mode (75, 80, 85, 90, or 95)",
3777 | 10,
3778 | &prefs.gui_packet_list_multi_color_shift_percent);
3779 |
3780 | prefs_register_bool_preference(gui_layout_module, "packet_list_multi_color_details",
3781 | "Display Multiple Colors in Packet Details",
3782 | "Show all matching color filter names in packet details pane and TShark output when multiple color filters match",
3783 | &prefs.gui_packet_list_multi_color_details);
3784 |
3785 | prefs_register_enum_preference(gui_layout_module, "packet_list_multi_color_separator",
3786 | "Color Stripe Separator Style",
3787 | "Shape of the boundary between color stripes: Vertical, Diagonal (candy-cane), or Bubble (half-moon)",
3788 | (int*)(void*)(&prefs.gui_packet_list_multi_color_separator), gui_packet_list_multi_color_separators, false0);
3789 |
3790 | prefs_register_bool_preference(gui_module, "packet_list_is_sortable",
3791 | "Allow packet list to be sortable",
3792 | "To prevent sorting by mistake (which can take some time to calculate), it can be disabled",
3793 | &prefs.gui_packet_list_sortable);
3794 |
3795 | prefs_register_uint_preference(gui_module, "packet_list_cached_rows_max",
3796 | "Maximum cached rows",
3797 | "Maximum number of rows that can be sorted by columns that require dissection. Increasing this increases memory consumption by caching column text",
3798 | 10,
3799 | &prefs.gui_packet_list_cached_rows_max);
3800 |
3801 | prefs_register_bool_preference(gui_module, "interfaces_show_hidden",
3802 | "Show hidden interfaces",
3803 | "Show all interfaces, including interfaces marked as hidden",
3804 | &prefs.gui_interfaces_show_hidden);
3805 |
3806 | prefs_register_bool_preference(gui_module, "interfaces_remote_display",
3807 | "Show Remote interfaces",
3808 | "Show remote interfaces in the interface selection",
3809 | &prefs.gui_interfaces_remote_display);
3810 |
3811 | register_string_like_preference(gui_module, "interfaces_hidden_types", "Hide interface types in list",
3812 | "Hide the given interface types in the startup list.\n"
3813 | "A comma-separated string of interface type values (e.g. 5,9).\n"
3814 | "0 = Wired,\n"
3815 | "1 = AirPCAP,\n"
3816 | "2 = Pipe,\n"
3817 | "3 = STDIN,\n"
3818 | "4 = Bluetooth,\n"
3819 | "5 = Wireless,\n"
3820 | "6 = Dial-Up,\n"
3821 | "7 = USB,\n"
3822 | "8 = External Capture,\n"
3823 | "9 = Virtual",
3824 | &prefs.gui_interfaces_hide_types, PREF_STRING, NULL((void*)0), true1);
3825 |
3826 | prefs_register_bool_preference(gui_module, "io_graph_automatic_update",
3827 | "Enables automatic updates for IO Graph",
3828 | "Enables automatic updates for IO Graph",
3829 | &prefs.gui_io_graph_automatic_update);
3830 |
3831 | prefs_register_bool_preference(gui_module, "io_graph_enable_legend",
3832 | "Enables the legend of IO Graph",
3833 | "Enables the legend of IO Graph",
3834 | &prefs.gui_io_graph_enable_legend);
3835 |
3836 | prefs_register_bool_preference(gui_module, "plot_automatic_update",
3837 | "Enables automatic updates for Plot",
3838 | "Enables automatic updates for Plot",
3839 | &prefs.gui_plot_automatic_update);
3840 |
3841 | prefs_register_bool_preference(gui_module, "plot_enable_legend",
3842 | "Enables the legend of Plot",
3843 | "Enables the legend of Plot",
3844 | &prefs.gui_plot_enable_legend);
3845 |
3846 | prefs_register_bool_preference(gui_module, "plot_enable_auto_scroll",
3847 | "Enables auto scroll of Plot",
3848 | "Enables auto scroll of Plot",
3849 | &prefs.gui_plot_enable_auto_scroll);
3850 |
3851 | prefs_register_bool_preference(gui_module, "show_byteview_in_dialog",
3852 | "Show the byte view in the packet details dialog",
3853 | "Show the byte view in the packet details dialog",
3854 | &prefs.gui_packet_details_show_byteview);
3855 |
3856 | /* Console
3857 | * These are preferences that can be read/written using the
3858 | * preference module API. These preferences still use their own
3859 | * configuration screens for access, but this cuts down on the
3860 | * preference "string compare list" in set_pref()
3861 | */
3862 | console_module = prefs_register_module(prefs_top_level_modules, prefs_modules, "console", "Console",
3863 | "Console logging and debugging output", NULL((void*)0), NULL((void*)0), false0);
3864 |
3865 | prefs_register_obsolete_preference(console_module, "log.level");
3866 |
3867 | prefs_register_bool_preference(console_module, "incomplete_dissectors_check_debug",
3868 | "Print debug line for incomplete dissectors",
3869 | "Look for dissectors that left some bytes undecoded (debug)",
3870 | &prefs.incomplete_dissectors_check_debug);
3871 |
3872 | /* Display filter Expressions
3873 | * This used to be an array of individual fields that has now been
3874 | * converted to a UAT. Just make it part of the GUI category even
3875 | * though the name of the preference will never be seen in preference
3876 | * file
3877 | */
3878 | filter_expression_register_uat(gui_module);
3879 |
3880 | /* Capture
3881 | * These are preferences that can be read/written using the
3882 | * preference module API. These preferences still use their own
3883 | * configuration screens for access, but this cuts down on the
3884 | * preference "string compare list" in set_pref()
3885 | */
3886 | capture_module = prefs_register_module(prefs_top_level_modules, prefs_modules, "capture", "Capture",
3887 | "Capture preferences", NULL((void*)0), apply_aggregation_prefs, false0);
3888 | /* Capture preferences don't affect dissection */
3889 | prefs_set_module_effect_flags(capture_module, PREF_EFFECT_CAPTURE(1u << 1));
3890 |
3891 | register_string_like_preference(capture_module, "device", "Default capture device",
3892 | "Default capture device",
3893 | &prefs.capture_device, PREF_STRING, NULL((void*)0), false0);
3894 |
3895 | register_string_like_preference(capture_module, "devices_linktypes", "Interface link-layer header type",
3896 | "Interface link-layer header types (Ex: en0(1),en1(143),...)",
3897 | &prefs.capture_devices_linktypes, PREF_STRING, NULL((void*)0), false0);
3898 |
3899 | register_string_like_preference(capture_module, "devices_descr", "Interface descriptions",
3900 | "Interface descriptions (Ex: eth0(eth0 descr),eth1(eth1 descr),...)",
3901 | &prefs.capture_devices_descr, PREF_STRING, NULL((void*)0), false0);
3902 |
3903 | register_string_like_preference(capture_module, "devices_hide", "Hide interface",
3904 | "Hide interface? (Ex: eth0,eth3,...)",
3905 | &prefs.capture_devices_hide, PREF_STRING, NULL((void*)0), false0);
3906 |
3907 | register_string_like_preference(capture_module, "devices_monitor_mode", "Capture in monitor mode",
3908 | "By default, capture in monitor mode on interface? (Ex: eth0,eth3,...)",
3909 | &prefs.capture_devices_monitor_mode, PREF_STRING, NULL((void*)0), false0);
3910 |
3911 | register_string_like_preference(capture_module, "devices_buffersize", "Interface buffer size",
3912 | "Interface buffer size (Ex: en0(1),en1(143),...)",
3913 | &prefs.capture_devices_buffersize, PREF_STRING, NULL((void*)0), false0);
3914 |
3915 | register_string_like_preference(capture_module, "devices_snaplen", "Interface snap length",
3916 | "Interface snap length (Ex: en0(65535),en1(1430),...)",
3917 | &prefs.capture_devices_snaplen, PREF_STRING, NULL((void*)0), false0);
3918 |
3919 | register_string_like_preference(capture_module, "devices_pmode", "Interface promiscuous mode",
3920 | "Interface promiscuous mode (Ex: en0(0),en1(1),...)",
3921 | &prefs.capture_devices_pmode, PREF_STRING, NULL((void*)0), false0);
3922 |
3923 | prefs_register_bool_preference(capture_module, "prom_mode", "Capture in promiscuous mode",
3924 | "Capture in promiscuous mode?", &prefs.capture_prom_mode);
3925 |
3926 | prefs_register_bool_preference(capture_module, "monitor_mode", "Capture in monitor mode on 802.11 devices",
3927 | "Capture in monitor mode on all 802.11 devices that support it?", &prefs.capture_monitor_mode);
3928 |
3929 | register_string_like_preference(capture_module, "devices_filter", "Interface capture filter",
3930 | "Interface capture filter (Ex: en0(tcp),en1(udp),...)",
3931 | &prefs.capture_devices_filter, PREF_STRING, NULL((void*)0), false0);
3932 |
3933 | prefs_register_bool_preference(capture_module, "pcap_ng", "Capture in pcapng format",
3934 | "Capture in pcapng format?", &prefs.capture_pcap_ng);
3935 |
3936 | prefs_register_bool_preference(capture_module, "real_time_update", "Update packet list in real time during capture",
3937 | "Update packet list in real time during capture?", &prefs.capture_real_time);
3938 |
3939 | prefs_register_uint_preference(capture_module, "update_interval",
3940 | "Capture update interval",
3941 | "Capture update interval in ms",
3942 | 10,
3943 | &prefs.capture_update_interval);
3944 |
3945 | prefs_register_bool_preference(capture_module, "enable_aggregation_view", "Enable aggregation view",
3946 | "Enable Aggregation View for real-time capturing", &prefs.enable_aggregation);
3947 |
3948 | prefs_register_bool_preference(capture_module, "no_interface_load", "Don't load interfaces on startup",
3949 | "Don't automatically load capture interfaces on startup", &prefs.capture_no_interface_load);
3950 |
3951 | prefs_register_bool_preference(capture_module, "no_extcap", "Disable external capture interfaces",
3952 | "Disable external capture modules (extcap)", &prefs.capture_no_extcap);
3953 |
3954 | prefs_register_obsolete_preference(capture_module, "auto_scroll");
3955 |
3956 | prefs_register_bool_preference(capture_module, "show_info", "Show capture information dialog while capturing",
3957 | "Show capture information dialog while capturing?", &prefs.capture_show_info);
3958 |
3959 | prefs_register_obsolete_preference(capture_module, "syntax_check_filter");
3960 |
3961 | custom_cbs.free_cb = capture_column_free_cb;
3962 | custom_cbs.reset_cb = capture_column_reset_cb;
3963 | custom_cbs.set_cb = capture_column_set_cb;
3964 | custom_cbs.type_name_cb = capture_column_type_name_cb;
3965 | custom_cbs.type_description_cb = capture_column_type_description_cb;
3966 | custom_cbs.is_default_cb = capture_column_is_default_cb;
3967 | custom_cbs.to_str_cb = capture_column_to_str_cb;
3968 | prefs_register_list_custom_preference(capture_module, "columns", "Capture options dialog column list",
3969 | "List of columns to be displayed", &custom_cbs, capture_column_init_cb, &prefs.capture_columns);
3970 | aggregation_field_register_uat(capture_module);
3971 |
3972 | /* Name Resolution */
3973 | nameres_module = prefs_register_module(prefs_top_level_modules, prefs_modules, "nameres", "Name Resolution",
3974 | "Name Resolution", "ChCustPreferencesSection.html#ChCustPrefsNameSection", addr_resolve_pref_apply, true1);
3975 | addr_resolve_pref_init(nameres_module);
3976 | oid_pref_init(nameres_module);
3977 | maxmind_db_pref_init(nameres_module);
3978 |
3979 | /* Printing
3980 | * None of these have any effect; we keep them as obsolete preferences
3981 | * in order to avoid errors when reading older preference files.
3982 | */
3983 | printing = prefs_register_module(prefs_top_level_modules, prefs_modules, "print", "Printing",
3984 | "Printing", NULL((void*)0), NULL((void*)0), false0);
3985 | prefs_register_obsolete_preference(printing, "format");
3986 | prefs_register_obsolete_preference(printing, "command");
3987 | prefs_register_obsolete_preference(printing, "file");
3988 |
3989 | /* Codecs */
3990 | codecs_module = prefs_register_module(prefs_top_level_modules, prefs_modules, "codecs", "Codecs",
3991 | "Codecs", NULL((void*)0), NULL((void*)0), true1);
3992 |
3993 | /* Statistics */
3994 | stats_module = prefs_register_module(prefs_top_level_modules, prefs_modules, "statistics", "Statistics",
3995 | "Statistics", "ChCustPreferencesSection.html#_statistics", &stats_callback, true1);
3996 |
3997 | prefs_register_uint_preference(stats_module, "update_interval",
3998 | "Tap update interval in ms",
3999 | "Determines time between tap updates",
4000 | 10,
4001 | &prefs.tap_update_interval);
4002 |
4003 | prefs_register_uint_preference(stats_module, "flow_graph_max_export_items",
4004 | "Maximum Flow Graph items to export as image",
4005 | "The maximum number of Flow Graph items (frames) "
4006 | "to include when exporting the graph as an image. "
4007 | "Note that some formats (e.g., JPEG) have inherent "
4008 | "pixel limits and image viewers might be unable to "
4009 | "handle very large images.",
4010 | 10,
4011 | &prefs.flow_graph_max_export_items);
4012 |
4013 | prefs_register_bool_preference(stats_module, "st_enable_burstinfo",
4014 | "Enable the calculation of burst information",
4015 | "If enabled burst rates will be calculated for statistics that use the stats_tree system. "
4016 | "Burst rates are calculated over a much shorter time interval than the rate column.",
4017 | &prefs.st_enable_burstinfo);
4018 |
4019 | prefs_register_bool_preference(stats_module, "st_burst_showcount",
4020 | "Show burst count for item rather than rate",
4021 | "If selected the stats_tree statistics nodes will show the count of events "
4022 | "within the burst window instead of a burst rate. Burst rate is calculated "
4023 | "as number of events within burst window divided by the burst windown length.",
4024 | &prefs.st_burst_showcount);
4025 |
4026 | prefs_register_uint_preference(stats_module, "st_burst_resolution",
4027 | "Burst rate resolution (ms)",
4028 | "Sets the duration of the time interval into which events are grouped when calculating "
4029 | "the burst rate. Higher resolution (smaller number) increases processing overhead.",
4030 | 10,&prefs.st_burst_resolution);
4031 |
4032 | prefs_register_uint_preference(stats_module, "st_burst_windowlen",
4033 | "Burst rate window size (ms)",
4034 | "Sets the duration of the sliding window during which the burst rate is "
4035 | "measured. Longer window relative to burst rate resolution increases "
4036 | "processing overhead. Will be truncated to a multiple of burst resolution.",
4037 | 10,&prefs.st_burst_windowlen);
4038 |
4039 | prefs_register_enum_preference(stats_module, "st_sort_defcolflag",
4040 | "Default sort column for stats_tree stats",
4041 | "Sets the default column by which stats based on the stats_tree "
4042 | "system is sorted.",
4043 | &prefs.st_sort_defcolflag, st_sort_col_vals, false0);
4044 |
4045 | prefs_register_bool_preference(stats_module, "st_sort_defdescending",
4046 | "Default stats_tree sort order is descending",
4047 | "When selected, statistics based on the stats_tree system will by default "
4048 | "be sorted in descending order.",
4049 | &prefs.st_sort_defdescending);
4050 |
4051 | prefs_register_bool_preference(stats_module, "st_sort_casesensitve",
4052 | "Case sensitive sort of stats_tree item names",
4053 | "When selected, the item/node names of statistics based on the stats_tree "
4054 | "system will be sorted taking case into account. Else the case of the name "
4055 | "will be ignored.",
4056 | &prefs.st_sort_casesensitve);
4057 |
4058 | prefs_register_bool_preference(stats_module, "st_sort_rng_nameonly",
4059 | "Always sort 'range' nodes by name",
4060 | "When selected, the stats_tree nodes representing a range of values "
4061 | "(0-49, 50-100, etc.) will always be sorted by name (the range of the "
4062 | "node). Else range nodes are sorted by the same column as the rest of "
4063 | " the tree.",
4064 | &prefs.st_sort_rng_nameonly);
4065 |
4066 | prefs_register_bool_preference(stats_module, "st_sort_rng_fixorder",
4067 | "Always sort 'range' nodes in ascending order",
4068 | "When selected, the stats_tree nodes representing a range of values "
4069 | "(0-49, 50-100, etc.) will always be sorted ascending; else it follows "
4070 | "the sort direction of the tree. Only effective if \"Always sort "
4071 | "'range' nodes by name\" is also selected.",
4072 | &prefs.st_sort_rng_fixorder);
4073 |
4074 | prefs_register_bool_preference(stats_module, "st_sort_showfullname",
4075 | "Display the full stats_tree plug-in name",
4076 | "When selected, the full name (including menu path) of the stats_tree "
4077 | "plug-in is show in windows. If cleared the plug-in name is shown "
4078 | "without menu path (only the part of the name after last '/' character.)",
4079 | &prefs.st_sort_showfullname);
4080 |
4081 | prefs_register_enum_preference(stats_module, "output_format",
4082 | "Default output format",
4083 | "Sets the default output format for statistical data. Only supported "
4084 | "by taps using the stats_tree system currently; other taps may honor "
4085 | "this preference in the future. ",
4086 | &prefs.st_format, st_format_vals, false0);
4087 |
4088 | module_t *conv_module;
4089 | // avoid using prefs_register_stat to prevent lint complaint about recursion
4090 | conv_module = prefs_register_submodule(stats_module, prefs_modules, "conv", "Conversations",
4091 | "Conversations & Endpoints", NULL((void*)0), NULL((void*)0), true1);
4092 | prefs_register_bool_preference(conv_module, "machine_readable",
4093 | "Display exact (machine-readable) byte counts",
4094 | "When enabled, exact machine-readable byte counts are displayed. "
4095 | "When disabled, human readable numbers with SI prefixes are displayed.",
4096 | &prefs.conv_machine_readable);
4097 |
4098 | /* Protocols */
4099 | protocols_module = prefs_register_module(prefs_top_level_modules, prefs_modules, "protocols", "Protocols",
4100 | "Protocols", "ChCustPreferencesSection.html#ChCustPrefsProtocolsSection", NULL((void*)0), true1);
4101 |
4102 | prefs_register_bool_preference(protocols_module, "display_hidden_proto_items",
4103 | "Display hidden protocol items",
4104 | "Display all hidden protocol items in the packet list.",
4105 | &prefs.display_hidden_proto_items);
4106 |
4107 | prefs_register_bool_preference(protocols_module, "display_byte_fields_with_spaces",
4108 | "Display byte fields with a space character between bytes",
4109 | "Display all byte fields with a space character between each byte in the packet list.",
4110 | &prefs.display_byte_fields_with_spaces);
4111 |
4112 | /*
4113 | * Note the -t / option only affects the display of the packet timestamp
4114 | * in the default time column; this is for all other absolute times.
4115 | */
4116 | prefs_register_enum_preference(protocols_module, "display_abs_time_ascii",
4117 | "Format absolute times like asctime",
4118 | "When to format absolute times similar to asctime instead of ISO 8601, for backwards compatibility with older Wireshark.",
4119 | (int*)&prefs.display_abs_time_ascii, abs_time_format_options, false0);
4120 |
4121 | prefs_register_bool_preference(protocols_module, "enable_incomplete_dissectors_check",
4122 | "Look for incomplete dissectors",
4123 | "Look for dissectors that left some bytes undecoded.",
4124 | &prefs.enable_incomplete_dissectors_check);
4125 |
4126 | prefs_register_bool_preference(protocols_module, "strict_conversation_tracking_heuristics",
4127 | "Enable stricter conversation tracking heuristics",
4128 | "Protocols may use things like VLAN ID or interface ID to narrow the potential for duplicate conversations. "
4129 | "Currently ICMP and ICMPv6 use this preference to add VLAN ID to conversation tracking, and IPv4 uses this preference to take VLAN ID into account during reassembly",
4130 | &prefs.strict_conversation_tracking_heuristics);
4131 |
4132 | prefs_register_bool_preference(protocols_module, "ignore_dup_frames",
4133 | "Ignore duplicate frames",
4134 | "Ignore frames that are exact duplicates of any previous frame.",
4135 | &prefs.ignore_dup_frames);
4136 |
4137 | prefs_register_enum_preference(protocols_module, "conversation_deinterlacing_key",
4138 | "Deinterlacing conversations key",
4139 | "Separate into different conversations frames that look like duplicates but have different Interface, MAC, or VLAN field values.",
4140 | (int *)&prefs.conversation_deinterlacing_key, conv_deint_options, false0);
4141 |
4142 | prefs_register_uint_preference(protocols_module, "ignore_dup_frames_cache_entries",
4143 | "The max number of hashes to keep in memory for determining duplicates frames",
4144 | "If \"Ignore duplicate frames\" is set, this setting sets the maximum number "
4145 | "of cache entries to maintain. A 0 means no limit.",
4146 | 10, &prefs.ignore_dup_frames_cache_entries);
4147 |
4148 |
4149 | /* Obsolete preferences
4150 | * These "modules" were reorganized/renamed to correspond to their GUI
4151 | * configuration screen within the preferences dialog
4152 | */
4153 |
4154 | /* taps is now part of the stats module */
4155 | prefs_register_module(prefs_top_level_modules, prefs_modules, "taps", "TAPS", "TAPS", NULL((void*)0), NULL((void*)0), false0);
4156 | /* packet_list is now part of the protocol (parent) module */
4157 | prefs_register_module(prefs_top_level_modules, prefs_modules, "packet_list", "PACKET_LIST", "PACKET_LIST", NULL((void*)0), NULL((void*)0), false0);
4158 | /* stream is now part of the gui module */
4159 | prefs_register_module(prefs_top_level_modules, prefs_modules, "stream", "STREAM", "STREAM", NULL((void*)0), NULL((void*)0), false0);
4160 |
4161 | }
4162 |
4163 | /* Parse through a list of comma-separated, possibly quoted strings.
4164 | Return a list of the string data. */
4165 | GList *
4166 | prefs_get_string_list(const char *str)
4167 | {
4168 | enum { PRE_STRING, IN_QUOT, NOT_IN_QUOT };
4169 |
4170 | int state = PRE_STRING, i = 0;
4171 | bool_Bool backslash = false0;
4172 | unsigned char cur_c;
4173 | const size_t default_size = 64;
4174 | GString *slstr = NULL((void*)0);
4175 | GList *sl = NULL((void*)0);
4176 |
4177 | /* Allocate a buffer for the first string. */
4178 | slstr = g_string_sized_new(default_size);
4179 |
4180 | for (;;) {
4181 | cur_c = str[i];
4182 | if (cur_c == '\0') {
4183 | /* It's the end of the input, so it's the end of the string we
4184 | were working on, and there's no more input. */
4185 | if (state == IN_QUOT || backslash) {
4186 | /* We were in the middle of a quoted string or backslash escape,
4187 | and ran out of characters; that's an error. */
4188 | g_string_free(slstr, TRUE)(__builtin_constant_p ((!(0))) ? (((!(0))) ? (g_string_free) ( (slstr), ((!(0)))) : g_string_free_and_steal (slstr)) : (g_string_free ) ((slstr), ((!(0)))));
4189 | prefs_clear_string_list(sl);
4190 | return NULL((void*)0);
4191 | }
4192 | if (slstr->len > 0)
4193 | sl = g_list_append(sl, g_string_free(slstr, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((slstr ), ((0))) : g_string_free_and_steal (slstr)) : (g_string_free ) ((slstr), ((0)))));
4194 | else
4195 | g_string_free(slstr, TRUE)(__builtin_constant_p ((!(0))) ? (((!(0))) ? (g_string_free) ( (slstr), ((!(0)))) : g_string_free_and_steal (slstr)) : (g_string_free ) ((slstr), ((!(0)))));
4196 | break;
4197 | }
4198 | if (cur_c == '"' && !backslash) {
4199 | switch (state) {
4200 | case PRE_STRING:
4201 | /* We hadn't yet started processing a string; this starts the
4202 | string, and we're now quoting. */
4203 | state = IN_QUOT;
4204 | break;
4205 | case IN_QUOT:
4206 | /* We're in the middle of a quoted string, and we saw a quotation
4207 | mark; we're no longer quoting. */
4208 | state = NOT_IN_QUOT;
4209 | break;
4210 | case NOT_IN_QUOT:
4211 | /* We're working on a string, but haven't seen a quote; we're
4212 | now quoting. */
4213 | state = IN_QUOT;
4214 | break;
4215 | default:
4216 | break;
4217 | }
4218 | } else if (cur_c == '\\' && !backslash) {
4219 | /* We saw a backslash, and the previous character wasn't a
4220 | backslash; escape the next character.
4221 |
4222 | This also means we've started a new string. */
4223 | backslash = true1;
4224 | if (state == PRE_STRING)
4225 | state = NOT_IN_QUOT;
4226 | } else if (cur_c == ',' && state != IN_QUOT && !backslash) {
4227 | /* We saw a comma, and we're not in the middle of a quoted string
4228 | and it wasn't preceded by a backslash; it's the end of
4229 | the string we were working on... */
4230 | if (slstr->len > 0) {
4231 | sl = g_list_append(sl, g_string_free(slstr, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((slstr ), ((0))) : g_string_free_and_steal (slstr)) : (g_string_free ) ((slstr), ((0)))));
4232 | slstr = g_string_sized_new(default_size);
4233 | }
4234 |
4235 | /* ...and the beginning of a new string. */
4236 | state = PRE_STRING;
4237 | } else if (!g_ascii_isspace(cur_c)((g_ascii_table[(guchar) (cur_c)] & G_ASCII_SPACE) != 0) || state != PRE_STRING) {
4238 | /* Either this isn't a white-space character, or we've started a
4239 | string (i.e., already seen a non-white-space character for that
4240 | string and put it into the string).
4241 |
4242 | The character is to be put into the string; do so. */
4243 | g_string_append_c(slstr, cur_c)g_string_append_c_inline (slstr, cur_c);
4244 |
4245 | /* If it was backslash-escaped, we're done with the backslash escape. */
4246 | backslash = false0;
4247 | }
4248 | i++;
4249 | }
4250 | return(sl);
4251 | }
4252 |
4253 | char *join_string_list(GList *sl)
4254 | {
4255 | GString *joined_str = g_string_new("");
4256 | GList *cur, *first;
4257 | char *str;
4258 | unsigned item_count = 0;
4259 |
4260 | cur = first = g_list_first(sl);
4261 | while (cur) {
4262 | item_count++;
4263 | str = (char *)cur->data;
4264 |
4265 | if (cur != first)
4266 | g_string_append_c(joined_str, ',')g_string_append_c_inline (joined_str, ',');
4267 |
4268 | if (item_count % 2) {
4269 | /* Wrap the line. */
4270 | g_string_append(joined_str, "\n\t")(__builtin_constant_p ("\n\t") ? __extension__ ({ const char * const __val = ("\n\t"); g_string_append_len_inline (joined_str , __val, (__val != ((void*)0)) ? (gssize) strlen (((__val) + ! (__val))) : (gssize) -1); }) : g_string_append_len_inline (joined_str , "\n\t", (gssize) -1));
4271 | } else
4272 | g_string_append_c(joined_str, ' ')g_string_append_c_inline (joined_str, ' ');
4273 |
4274 | g_string_append_c(joined_str, '"')g_string_append_c_inline (joined_str, '"');
4275 | while (*str) {
4276 | gunichar uc = g_utf8_get_char (str);
4277 |
4278 | if (uc == '"' || uc == '\\')
4279 | g_string_append_c(joined_str, '\\')g_string_append_c_inline (joined_str, '\\');
4280 |
4281 | if (g_unichar_isprint(uc))
4282 | g_string_append_unichar (joined_str, uc);
4283 |
4284 | str = g_utf8_next_char (str)(char *)((str) + g_utf8_skip[*(const guchar *)(str)]);
4285 | }
4286 |
4287 | g_string_append_c(joined_str, '"')g_string_append_c_inline (joined_str, '"');
4288 |
4289 | cur = cur->next;
4290 | }
4291 | return g_string_free(joined_str, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((joined_str ), ((0))) : g_string_free_and_steal (joined_str)) : (g_string_free ) ((joined_str), ((0))));
4292 | }
4293 |
4294 | void
4295 | prefs_clear_string_list(GList *sl)
4296 | {
4297 | g_list_free_full(sl, g_free);
4298 | }
4299 |
4300 | /*
4301 | * Takes a string, a pointer to an array of "enum_val_t"s, and a default int
4302 | * value.
4303 | * The array must be terminated by an entry with a null "name" string.
4304 | *
4305 | * If the string matches a "name" string in an entry, the value from that
4306 | * entry is returned.
4307 | *
4308 | * Otherwise, if a string matches a "description" string in an entry, the
4309 | * value from that entry is returned; we do that for backwards compatibility,
4310 | * as we used to have only a "name" string that was used both for command-line
4311 | * and configuration-file values and in the GUI (which meant either that
4312 | * the GUI had what might be somewhat cryptic values to select from or that
4313 | * the "-o" flag took long strings, often with spaces in them).
4314 | *
4315 | * Otherwise, the default value that was passed as the third argument is
4316 | * returned.
4317 | */
4318 | static int
4319 | find_val_for_string(const char *needle, const enum_val_t *haystack,
4320 | int default_value)
4321 | {
4322 | int i;
4323 |
4324 | for (i = 0; haystack[i].name != NULL((void*)0); i++) {
4325 | if (g_ascii_strcasecmp(needle, haystack[i].name) == 0) {
4326 | return haystack[i].value;
4327 | }
4328 | }
4329 | for (i = 0; haystack[i].name != NULL((void*)0); i++) {
4330 | if (g_ascii_strcasecmp(needle, haystack[i].description) == 0) {
4331 | return haystack[i].value;
4332 | }
4333 | }
4334 | return default_value;
4335 | }
4336 |
4337 | /* Preferences file format:
4338 | * - Configuration directives start at the beginning of the line, and
4339 | * are terminated with a colon.
4340 | * - Directives can be continued on the next line by preceding them with
4341 | * whitespace.
4342 | *
4343 | * Example:
4344 |
4345 | # This is a comment line
4346 | print.command: lpr
4347 | print.file: /a/very/long/path/
4348 | to/wireshark-out.ps
4349 | *
4350 | */
4351 |
4352 | /*
4353 | * Initialize non-dissector preferences used by the "register preference" API
4354 | * to default values so the default values can be used when registered.
4355 | *
4356 | * String, filename, and directory preferences will be g_freed so they must
4357 | * be g_mallocated.
4358 | */
4359 | static void
4360 | prefs_set_global_defaults(wmem_allocator_t* pref_scope, const char** col_fmt, int num_cols)
4361 | {
4362 | int i;
4363 | char *col_name;
4364 | fmt_data *cfmt;
4365 |
4366 | prefs.restore_filter_after_following_stream = false0;
4367 | prefs.gui_toolbar_main_style = TB_STYLE_ICONS0;
4368 | /* We try to find the best font in the Qt code */
4369 | wmem_free(pref_scope, prefs.gui_font_name);
4370 | prefs.gui_font_name = wmem_strdup(pref_scope, "");
4371 | prefs.gui_active_fg.red = 0;
4372 | prefs.gui_active_fg.green = 0;
4373 | prefs.gui_active_fg.blue = 0;
4374 | prefs.gui_active_bg.red = 52223;
4375 | prefs.gui_active_bg.green = 59647;
4376 | prefs.gui_active_bg.blue = 65535;
4377 | prefs.gui_active_style = COLOR_STYLE_DEFAULT0;
4378 | prefs.gui_inactive_fg.red = 0;
4379 | prefs.gui_inactive_fg.green = 0;
4380 | prefs.gui_inactive_fg.blue = 0;
4381 | prefs.gui_inactive_bg.red = 61439;
4382 | prefs.gui_inactive_bg.green = 61439;
4383 | prefs.gui_inactive_bg.blue = 61439;
4384 | prefs.gui_inactive_style = COLOR_STYLE_DEFAULT0;
4385 | prefs.gui_marked_fg.red = 65535;
4386 | prefs.gui_marked_fg.green = 65535;
4387 | prefs.gui_marked_fg.blue = 65535;
4388 | prefs.gui_marked_bg.red = 0;
4389 | prefs.gui_marked_bg.green = 8224;
4390 | prefs.gui_marked_bg.blue = 10794;
4391 | prefs.gui_ignored_fg.red = 32767;
4392 | prefs.gui_ignored_fg.green = 32767;
4393 | prefs.gui_ignored_fg.blue = 32767;
4394 | prefs.gui_ignored_bg.red = 65535;
4395 | prefs.gui_ignored_bg.green = 65535;
4396 | prefs.gui_ignored_bg.blue = 65535;
4397 | wmem_free(pref_scope, prefs.gui_colorized_fg);
4398 | prefs.gui_colorized_fg = wmem_strdup(pref_scope, "000000,000000,000000,000000,000000,000000,000000,000000,000000,000000");
4399 | wmem_free(pref_scope, prefs.gui_colorized_bg);
4400 | prefs.gui_colorized_bg = wmem_strdup(pref_scope, "ffc0c0,ffc0ff,e0c0e0,c0c0ff,c0e0e0,c0ffff,c0ffc0,ffffc0,e0e0c0,e0e0e0");
4401 | prefs.st_client_fg.red = 32767;
4402 | prefs.st_client_fg.green = 0;
4403 | prefs.st_client_fg.blue = 0;
4404 | prefs.st_client_bg.red = 64507;
4405 | prefs.st_client_bg.green = 60909;
4406 | prefs.st_client_bg.blue = 60909;
4407 | prefs.st_server_fg.red = 0;
4408 | prefs.st_server_fg.green = 0;
4409 | prefs.st_server_fg.blue = 32767;
4410 | prefs.st_server_bg.red = 60909;
4411 | prefs.st_server_bg.green = 60909;
4412 | prefs.st_server_bg.blue = 64507;
4413 |
4414 | if (gui_theme_is_dark) {
4415 | // Green, red and yellow with HSV V = 84
4416 | prefs.gui_filter_valid_bg.red = 0x0000; /* dark green */
4417 | prefs.gui_filter_valid_bg.green = 0x66ff;
4418 | prefs.gui_filter_valid_bg.blue = 0x0000;
4419 | prefs.gui_filter_valid_fg.red = 0xFFFF;
4420 | prefs.gui_filter_valid_fg.green = 0xFFFF;
4421 | prefs.gui_filter_valid_fg.blue = 0xFFFF;
4422 | prefs.gui_filter_invalid_bg.red = 0x66FF; /* dark red */
4423 | prefs.gui_filter_invalid_bg.green = 0x0000;
4424 | prefs.gui_filter_invalid_bg.blue = 0x0000;
4425 | prefs.gui_filter_invalid_fg.red = 0xFFFF;
4426 | prefs.gui_filter_invalid_fg.green = 0xFFFF;
4427 | prefs.gui_filter_invalid_fg.blue = 0xFFFF;
4428 | prefs.gui_filter_deprecated_bg.red = 0x66FF; /* dark yellow / olive */
4429 | prefs.gui_filter_deprecated_bg.green = 0x66FF;
4430 | prefs.gui_filter_deprecated_bg.blue = 0x0000;
4431 | prefs.gui_filter_deprecated_fg.red = 0xFFFF;
4432 | prefs.gui_filter_deprecated_fg.green = 0xFFFF;
4433 | prefs.gui_filter_deprecated_fg.blue = 0xFFFF;
4434 | } else {
4435 | // Green, red and yellow with HSV V = 20
4436 | prefs.gui_filter_valid_bg.red = 0xAFFF; /* light green */
4437 | prefs.gui_filter_valid_bg.green = 0xFFFF;
4438 | prefs.gui_filter_valid_bg.blue = 0xAFFF;
4439 | prefs.gui_filter_valid_fg.red = 0x0000;
4440 | prefs.gui_filter_valid_fg.green = 0x0000;
4441 | prefs.gui_filter_valid_fg.blue = 0x0000;
4442 | prefs.gui_filter_invalid_bg.red = 0xFFFF; /* light red */
4443 | prefs.gui_filter_invalid_bg.green = 0xAFFF;
4444 | prefs.gui_filter_invalid_bg.blue = 0xAFFF;
4445 | prefs.gui_filter_invalid_fg.red = 0x0000;
4446 | prefs.gui_filter_invalid_fg.green = 0x0000;
4447 | prefs.gui_filter_invalid_fg.blue = 0x0000;
4448 | prefs.gui_filter_deprecated_bg.red = 0xFFFF; /* light yellow */
4449 | prefs.gui_filter_deprecated_bg.green = 0xFFFF;
4450 | prefs.gui_filter_deprecated_bg.blue = 0xAFFF;
4451 | prefs.gui_filter_deprecated_fg.red = 0x0000;
4452 | prefs.gui_filter_deprecated_fg.green = 0x0000;
4453 | prefs.gui_filter_deprecated_fg.blue = 0x0000;
4454 | }
4455 |
4456 | prefs.gui_geometry_save_position = true1;
4457 | prefs.gui_geometry_save_size = true1;
4458 | prefs.gui_geometry_save_maximized= true1;
4459 | prefs.gui_fileopen_style = FO_STYLE_LAST_OPENED0;
4460 | prefs.gui_recent_df_entries_max = 10;
4461 | prefs.gui_recent_files_count_max = 10;
4462 | wmem_free(pref_scope, prefs.gui_fileopen_dir);
4463 | prefs.gui_fileopen_dir = wmem_strdup(pref_scope, get_persdatafile_dir());
4464 | prefs.gui_fileopen_preview = 3;
4465 | wmem_free(pref_scope, prefs.gui_tlskeylog_command);
4466 | prefs.gui_tlskeylog_command = wmem_strdup(pref_scope, "");
4467 | prefs.gui_ask_unsaved = true1;
4468 | prefs.gui_autocomplete_filter = true1;
4469 | prefs.gui_find_wrap = true1;
4470 | prefs.gui_update_enabled = true1;
4471 | prefs.gui_update_channel = UPDATE_CHANNEL_STABLE;
4472 | prefs.gui_update_interval = 60*60*24; /* Seconds */
4473 | prefs.gui_debounce_timer = 400; /* milliseconds */
4474 | wmem_free(pref_scope, prefs.gui_window_title);
4475 | prefs.gui_window_title = wmem_strdup(pref_scope, "");
4476 | wmem_free(pref_scope, prefs.gui_prepend_window_title);
4477 | prefs.gui_prepend_window_title = wmem_strdup(pref_scope, "");
4478 | wmem_free(pref_scope, prefs.gui_start_title);
4479 | prefs.gui_start_title = wmem_strdup(pref_scope, "The World's Most Popular Network Protocol Analyzer");
4480 | prefs.gui_version_placement = version_both;
4481 | prefs.gui_welcome_page_show_recent = true1;
4482 | prefs.gui_layout_type = layout_type_2;
4483 | prefs.gui_layout_content_1 = layout_pane_content_plist;
4484 | prefs.gui_layout_content_2 = layout_pane_content_pdetails;
4485 | prefs.gui_layout_content_3 = layout_pane_content_pbytes;
4486 | prefs.gui_packet_list_elide_mode = ELIDE_RIGHT;
4487 | prefs.gui_packet_list_copy_format_options_for_keyboard_shortcut = COPY_FORMAT_TEXT;
4488 | prefs.gui_packet_list_copy_text_with_aligned_columns = false0;
4489 | prefs.gui_packet_list_show_related = true1;
4490 | prefs.gui_packet_list_show_minimap = true1;
4491 | prefs.gui_packet_list_sortable = true1;
4492 | prefs.gui_packet_list_cached_rows_max = 10000;
4493 | prefs.gui_packet_list_multi_color_mode = PACKET_LIST_MULTI_COLOR_MODE_OFF;
4494 | prefs.gui_packet_list_multi_color_shift_percent = 85;
4495 | prefs.gui_packet_list_multi_color_details = false0;
4496 | prefs.gui_packet_list_multi_color_separator = PACKET_LIST_MULTI_COLOR_SEPARATOR_DIAGONAL;
4497 | wmem_free(pref_scope, prefs.gui_interfaces_hide_types);
4498 | prefs.gui_interfaces_hide_types = wmem_strdup(pref_scope, "");
4499 | prefs.gui_interfaces_show_hidden = false0;
4500 | prefs.gui_interfaces_remote_display = true1;
4501 | prefs.gui_packet_list_separator = false0;
4502 | prefs.gui_packet_header_column_definition = true1;
4503 | prefs.gui_packet_list_hover_style = true1;
4504 | prefs.gui_show_selected_packet = false0;
4505 | prefs.gui_show_file_load_time = false0;
4506 | prefs.gui_max_export_objects = 1000;
4507 | prefs.gui_max_tree_items = 1 * 1000 * 1000;
4508 | prefs.gui_max_tree_depth = 5 * 100;
4509 | prefs.gui_decimal_places1 = DEF_GUI_DECIMAL_PLACES12;
4510 | prefs.gui_decimal_places2 = DEF_GUI_DECIMAL_PLACES24;
4511 | prefs.gui_decimal_places3 = DEF_GUI_DECIMAL_PLACES36;
4512 |
4513 | if (prefs.col_list) {
4514 | free_col_info(prefs.col_list);
4515 | prefs.col_list = NULL((void*)0);
4516 | }
4517 | for (i = 0; i < num_cols; i++) {
4518 | cfmt = g_new0(fmt_data,1)((fmt_data *) g_malloc0_n ((1), sizeof (fmt_data)));
4519 | cfmt->title = g_strdup(col_fmt[i * 2])g_strdup_inline (col_fmt[i * 2]);
4520 | cfmt->visible = true1;
4521 | cfmt->display = COLUMN_DISPLAY_STRINGS'R';
4522 | parse_column_format(cfmt, col_fmt[(i * 2) + 1]);
4523 | prefs.col_list = g_list_append(prefs.col_list, cfmt);
4524 | }
4525 | prefs.num_cols = num_cols;
4526 |
4527 | /* set the default values for the capture dialog box */
4528 | prefs.capture_prom_mode = true1;
4529 | prefs.capture_monitor_mode = false0;
4530 | prefs.capture_pcap_ng = true1;
4531 | prefs.capture_real_time = true1;
4532 | prefs.capture_update_interval = DEFAULT_UPDATE_INTERVAL100;
4533 | prefs.capture_no_extcap = false0;
4534 | prefs.capture_show_info = false0;
4535 | prefs.enable_aggregation = false0;
4536 |
4537 | if (!prefs.capture_columns) {
4538 | /* First time through */
4539 | for (i = 0; i < num_capture_cols; i++) {
4540 | col_name = g_strdup(capture_cols[i])g_strdup_inline (capture_cols[i]);
4541 | prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
4542 | }
4543 | }
4544 |
4545 | /* set the default values for the tap/statistics dialog box */
4546 | prefs.tap_update_interval = TAP_UPDATE_DEFAULT_INTERVAL3000;
4547 | prefs.flow_graph_max_export_items = 1000;
4548 | prefs.st_enable_burstinfo = true1;
4549 | prefs.st_burst_showcount = false0;
4550 | prefs.st_burst_resolution = ST_DEF_BURSTRES5;
4551 | prefs.st_burst_windowlen = ST_DEF_BURSTLEN100;
4552 | prefs.st_sort_casesensitve = true1;
4553 | prefs.st_sort_rng_fixorder = true1;
4554 | prefs.st_sort_rng_nameonly = true1;
4555 | prefs.st_sort_defcolflag = ST_SORT_COL_COUNT2;
4556 | prefs.st_sort_defdescending = true1;
4557 | prefs.st_sort_showfullname = false0;
4558 | prefs.conv_machine_readable = false0;
4559 |
4560 | /* protocols */
4561 | prefs.display_hidden_proto_items = false0;
4562 | prefs.display_byte_fields_with_spaces = false0;
4563 | prefs.display_abs_time_ascii = ABS_TIME_ASCII_TREE;
4564 | prefs.ignore_dup_frames = false0;
4565 | prefs.ignore_dup_frames_cache_entries = 10000;
4566 |
4567 | /* set the default values for the io graph dialog */
4568 | prefs.gui_io_graph_automatic_update = true1;
4569 | prefs.gui_io_graph_enable_legend = true1;
4570 |
4571 | /* set the default values for the plot dialog */
4572 | prefs.gui_plot_automatic_update = true1;
4573 | prefs.gui_plot_enable_legend = true1;
4574 | prefs.gui_plot_enable_auto_scroll = false0;
4575 |
4576 | /* set the default values for the packet dialog */
4577 | prefs.gui_packet_dialog_layout = layout_vertical;
4578 | prefs.gui_packet_details_show_byteview = true1;
4579 | }
4580 |
4581 | /*
4582 | * Reset a single dissector preference.
4583 | */
4584 | void
4585 | reset_pref(pref_t *pref)
4586 | {
4587 | if (!pref) return;
4588 |
4589 | /*
4590 | * This preference is no longer supported; it's not a
4591 | * real preference, so we don't reset it (i.e., we
4592 | * treat it as if it weren't found in the list of
4593 | * preferences, and we weren't called in the first place).
4594 | */
4595 | if (pref->obsolete)
4596 | return;
4597 |
4598 | switch (pref->type) {
4599 |
4600 | case PREF_UINT:
4601 | *pref->varp.uint = pref->default_val.uint;
4602 | break;
4603 |
4604 | case PREF_INT:
4605 | *pref->varp.intp = pref->default_val.intval;
4606 | break;
4607 |
4608 | case PREF_FLOAT:
4609 | *pref->varp.floatp = pref->default_val.floatval;
4610 | break;
4611 |
4612 | case PREF_BOOL:
4613 | *pref->varp.boolp = pref->default_val.boolval;
4614 | break;
4615 |
4616 | case PREF_ENUM:
4617 | case PREF_PROTO_TCP_SNDAMB_ENUM:
4618 | *pref->varp.enump = pref->default_val.enumval;
4619 | break;
4620 |
4621 | case PREF_STRING:
4622 | case PREF_SAVE_FILENAME:
4623 | case PREF_OPEN_FILENAME:
4624 | case PREF_DIRNAME:
4625 | case PREF_PASSWORD:
4626 | case PREF_DISSECTOR:
4627 | reset_string_like_preference(pref);
4628 | break;
4629 |
4630 | case PREF_RANGE:
4631 | case PREF_DECODE_AS_RANGE:
4632 | wmem_free(pref->scope, *pref->varp.range);
4633 | *pref->varp.range = range_copy(pref->scope, pref->default_val.range);
4634 | break;
4635 |
4636 | case PREF_STATIC_TEXT:
4637 | case PREF_UAT:
4638 | /* Nothing to do */
4639 | break;
4640 |
4641 | case PREF_COLOR:
4642 | *pref->varp.colorp = pref->default_val.color;
4643 | break;
4644 |
4645 | case PREF_CUSTOM:
4646 | pref->custom_cbs.reset_cb(pref);
4647 | break;
4648 | }
4649 | }
4650 |
4651 | static void
4652 | reset_pref_cb(void *data, void *user_data)
4653 | {
4654 | pref_t *pref = (pref_t *) data;
4655 | module_t *module = (module_t *)user_data;
4656 |
4657 | if (pref && (pref->type == PREF_RANGE || pref->type == PREF_DECODE_AS_RANGE)) {
4658 | /*
4659 | * Some dissectors expect the range (returned via prefs_get_range_value)
4660 | * to remain valid if it has not changed. If it did change, then we
4661 | * should set "prefs_changed_flags" to ensure that the preference apply
4662 | * callback is invoked. That callback will notify dissectors that it
4663 | * should no longer assume the range to be valid.
4664 | */
4665 | if (ranges_are_equal(*pref->varp.range, pref->default_val.range)) {
4666 | /* Optimization: do not invoke apply callback if nothing changed. */
4667 | return;
4668 | }
4669 | module->prefs_changed_flags |= prefs_get_effect_flags(pref);
4670 | }
4671 | reset_pref(pref);
4672 | }
4673 |
4674 | /*
4675 | * Reset all preferences for a module.
4676 | */
4677 | static bool_Bool
4678 | reset_module_prefs(const void *key _U___attribute__((unused)), void *value, void *data _U___attribute__((unused)))
4679 | {
4680 | module_t *module = (module_t *)value;
4681 | g_list_foreach(module->prefs, reset_pref_cb, module);
4682 | return false0;
4683 | }
4684 |
4685 | /* Reset preferences */
4686 | void
4687 | prefs_reset(const char* app_env_var_prefix, const char** col_fmt, int num_cols)
4688 | {
4689 | g_free(prefs.saved_at_version);
4690 | prefs.saved_at_version = NULL((void*)0);
4691 |
4692 | /*
4693 | * Unload all UAT preferences.
4694 | */
4695 | uat_unload_all();
4696 |
4697 | /*
4698 | * Unload any loaded MIBs.
4699 | */
4700 | oids_cleanup();
4701 |
4702 | /*
4703 | * Reload all UAT preferences.
4704 | */
4705 | uat_load_all(app_env_var_prefix);
4706 |
4707 | /*
4708 | * Reset the non-dissector preferences.
4709 | */
4710 | prefs_set_global_defaults(wmem_epan_scope(), col_fmt, num_cols);
4711 |
4712 | /*
4713 | * Reset the non-UAT dissector preferences.
4714 | */
4715 | wmem_tree_foreach(prefs_modules, reset_module_prefs, NULL((void*)0));
4716 | }
4717 |
4718 | #ifdef _WIN32
4719 | static void
4720 | read_registry(void)
4721 | {
4722 | HKEY hTestKey;
4723 | DWORD data;
4724 | DWORD data_size = sizeof(DWORD);
4725 | DWORD ret;
4726 |
4727 | ret = RegOpenKeyExA(HKEY_CURRENT_USER, REG_HKCU_WIRESHARK_KEY"Software\\Wireshark", 0, KEY_READ, &hTestKey);
4728 | if (ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND) {
4729 | ws_noisy("Cannot open HKCU "REG_HKCU_WIRESHARK_KEY": 0x%lx", ret)do { if (1) { ws_log_full("Epan", LOG_LEVEL_NOISY, "epan/prefs.c" , 4729, __func__, "Cannot open HKCU ""Software\\Wireshark"": 0x%lx" , ret); } } while (0);
4730 | return;
4731 | }
4732 |
4733 | ret = RegQueryValueExA(hTestKey, LOG_HKCU_CONSOLE_OPEN"ConsoleOpen", NULL((void*)0), NULL((void*)0), (LPBYTE)&data, &data_size);
4734 | if (ret == ERROR_SUCCESS) {
4735 | ws_log_console_open = (ws_log_console_open_pref)data;
4736 | ws_noisy("Got "LOG_HKCU_CONSOLE_OPEN" from Windows registry: %d", ws_log_console_open)do { if (1) { ws_log_full("Epan", LOG_LEVEL_NOISY, "epan/prefs.c" , 4736, __func__, "Got ""ConsoleOpen"" from Windows registry: %d" , ws_log_console_open); } } while (0);
4737 | }
4738 | else if (ret != ERROR_FILE_NOT_FOUND) {
4739 | ws_noisy("Error reading registry key "LOG_HKCU_CONSOLE_OPEN": 0x%lx", ret)do { if (1) { ws_log_full("Epan", LOG_LEVEL_NOISY, "epan/prefs.c" , 4739, __func__, "Error reading registry key ""ConsoleOpen"": 0x%lx" , ret); } } while (0);
4740 | }
4741 |
4742 | RegCloseKey(hTestKey);
4743 | }
4744 | #endif
4745 |
4746 | void
4747 | prefs_read_module(const char *module, const char* app_env_var_prefix)
4748 | {
4749 | int err;
4750 | char *pf_path;
4751 | FILE *pf;
4752 |
4753 | module_t *target_module = prefs_find_module(module);
4754 | if (!target_module) {
4755 | return;
4756 | }
4757 |
4758 | /* Construct the pathname of the user's preferences file for the module. */
4759 | char *pf_name = wmem_strdup_printf(NULL((void*)0), "%s.cfg", module);
4760 | pf_path = get_persconffile_path(pf_name, true1, app_env_var_prefix);
4761 | wmem_free(NULL((void*)0), pf_name);
4762 |
4763 | /* Read the user's module preferences file, if it exists and is not a dir. */
4764 | if (!test_for_regular_file(pf_path) || ((pf = ws_fopenfopen(pf_path, "r")) == NULL((void*)0))) {
4765 | g_free(pf_path);
4766 | /* Fall back to the user's generic preferences file. */
4767 | pf_path = get_persconffile_path(PF_NAME"preferences", true1, app_env_var_prefix);
4768 | pf = ws_fopenfopen(pf_path, "r");
4769 | }
4770 |
4771 | if (pf != NULL((void*)0)) {
4772 | /* We succeeded in opening it; read it. */
4773 | err = read_prefs_file(pf_path, pf, set_pref, target_module);
4774 | if (err != 0) {
4775 | /* We had an error reading the file; report it. */
4776 | report_warning("Error reading your preferences file \"%s\": %s.",
4777 | pf_path, g_strerror(err));
4778 | } else
4779 | g_free(pf_path);
4780 | fclose(pf);
4781 | } else {
4782 | /* We failed to open it. If we failed for some reason other than
4783 | "it doesn't exist", return the errno and the pathname, so our
4784 | caller can report the error. */
4785 | if (errno(*__errno_location ()) != ENOENT2) {
4786 | report_warning("Can't open your preferences file \"%s\": %s.",
4787 | pf_path, g_strerror(errno(*__errno_location ())));
4788 | } else
4789 | g_free(pf_path);
4790 | }
4791 |
4792 | return;
4793 | }
4794 |
4795 | /* Read the preferences file, fill in "prefs", and return a pointer to it.
4796 |
4797 | If we got an error (other than "it doesn't exist") we report it through
4798 | the UI. */
4799 | e_prefs *
4800 | read_prefs(const char* app_env_var_prefix)
4801 | {
4802 | int err;
4803 | char *pf_path;
4804 | FILE *pf;
4805 |
4806 | /* clean up libsmi structures before reading prefs */
4807 | oids_cleanup();
4808 |
4809 | #ifdef _WIN32
4810 | read_registry();
4811 | #endif
4812 |
4813 | /*
4814 | * If we don't already have the pathname of the global preferences
4815 | * file, construct it. Then, in either case, try to open the file.
4816 | */
4817 | if (gpf_path == NULL((void*)0)) {
4818 | /*
4819 | * We don't have the path; try the new path first, and, if that
4820 | * file doesn't exist, try the old path.
4821 | */
4822 | gpf_path = get_datafile_path(PF_NAME"preferences", app_env_var_prefix);
4823 | if ((pf = ws_fopenfopen(gpf_path, "r")) == NULL((void*)0) && errno(*__errno_location ()) == ENOENT2) {
4824 | /*
4825 | * It doesn't exist by the new name; try the old name.
4826 | */
4827 | g_free(gpf_path);
4828 | gpf_path = get_datafile_path(OLD_GPF_NAME"wireshark.conf", app_env_var_prefix);
4829 | pf = ws_fopenfopen(gpf_path, "r");
4830 | }
4831 | } else {
4832 | /*
4833 | * We have the path; try it.
4834 | */
4835 | pf = ws_fopenfopen(gpf_path, "r");
4836 | }
4837 |
4838 | /*
4839 | * If we were able to open the file, read it.
4840 | * XXX - if it failed for a reason other than "it doesn't exist",
4841 | * report the error.
4842 | */
4843 | if (pf != NULL((void*)0)) {
4844 | /* We succeeded in opening it; read it. */
4845 | err = read_prefs_file(gpf_path, pf, set_pref, NULL((void*)0));
4846 | if (err != 0) {
4847 | /* We had an error reading the file; report it. */
4848 | report_warning("Error reading global preferences file \"%s\": %s.",
4849 | gpf_path, g_strerror(err));
4850 | }
4851 | fclose(pf);
4852 | } else {
4853 | /* We failed to open it. If we failed for some reason other than
4854 | "it doesn't exist", report the error. */
4855 | if (errno(*__errno_location ()) != ENOENT2) {
4856 | if (errno(*__errno_location ()) != 0) {
4857 | report_warning("Can't open global preferences file \"%s\": %s.",
4858 | gpf_path, g_strerror(errno(*__errno_location ())));
4859 | }
4860 | }
4861 | }
4862 |
4863 | /* Construct the pathname of the user's preferences file. */
4864 | pf_path = get_persconffile_path(PF_NAME"preferences", true1, app_env_var_prefix);
4865 |
4866 | /* Read the user's preferences file, if it exists. */
4867 | if ((pf = ws_fopenfopen(pf_path, "r")) != NULL((void*)0)) {
4868 |
4869 | /* We succeeded in opening it; read it. */
4870 | err = read_prefs_file(pf_path, pf, set_pref, NULL((void*)0));
4871 | if (err != 0) {
4872 | /* We had an error reading the file; report it. */
4873 | report_warning("Error reading your preferences file \"%s\": %s.",
4874 | pf_path, g_strerror(err));
4875 | } else
4876 | g_free(pf_path);
4877 | fclose(pf);
4878 | } else {
4879 | /* We failed to open it. If we failed for some reason other than
4880 | "it doesn't exist", return the errno and the pathname, so our
4881 | caller can report the error. */
4882 | if (errno(*__errno_location ()) != ENOENT2) {
4883 | report_warning("Can't open your preferences file \"%s\": %s.",
4884 | pf_path, g_strerror(errno(*__errno_location ())));
4885 | } else
4886 | g_free(pf_path);
4887 | }
4888 |
4889 | /* load SMI modules if needed */
4890 | oids_init(app_env_var_prefix);
4891 |
4892 | return &prefs;
4893 | }
4894 |
4895 | /* read the preferences file (or similar) and call the callback
4896 | * function to set each key/value pair found */
4897 | int
4898 | read_prefs_file(const char *pf_path, FILE *pf,
4899 | pref_set_pair_cb pref_set_pair_fct, void *private_data)
4900 | {
4901 | enum {
4902 | START, /* beginning of a line */
4903 | IN_VAR, /* processing key name */
4904 | PRE_VAL, /* finished processing key name, skipping white space before value */
4905 | IN_VAL, /* processing value */
4906 | IN_SKIP /* skipping to the end of the line */
4907 | } state = START;
4908 | int got_c;
4909 | GString *cur_val;
4910 | GString *cur_var;
4911 | bool_Bool got_val = false0;
4912 | int fline = 1, pline = 1;
4913 | char hint[] = "(save preferences to remove this warning)";
4914 | char ver[128];
4915 |
4916 | cur_val = g_string_new("");
4917 | cur_var = g_string_new("");
4918 |
4919 | /* Try to read in the profile name in the first line of the preferences file. */
4920 | if (fscanf(pf, "# Configuration file for %127[^\r\n]", ver) == 1) {
1 | Assuming the condition is false | →
2 | ← | Taking false branch | →
4921 | /* Assume trailing period and remove it */
4922 | g_free(prefs.saved_at_version);
4923 | prefs.saved_at_version = g_strndup(ver, strlen(ver) - 1);
4924 | }
4925 | rewind(pf);
3 | ← | After calling 'rewind' reading 'errno' is required to find out if the call has failed | →
4926 |
4927 | while ((got_c = ws_getc_unlockedgetc_unlocked(pf)) != EOF(-1)) {
4 | ← | Value of 'errno' was not checked and may be overwritten by function 'getc_unlocked'
4928 | if (got_c == '\r') {
4929 | /* Treat CR-LF at the end of a line like LF, so that if we're reading
4930 | * a Windows-format file on UN*X, we handle it the same way we'd handle
4931 | * a UN*X-format file. */
4932 | got_c = ws_getc_unlockedgetc_unlocked(pf);
4933 | if (got_c == EOF(-1))
4934 | break;
4935 | if (got_c != '\n') {
4936 | /* Put back the character after the CR, and process the CR normally. */
4937 | ungetc(got_c, pf);
4938 | got_c = '\r';
4939 | }
4940 | }
4941 | if (got_c == '\n') {
4942 | state = START;
4943 | fline++;
4944 | continue;
4945 | }
4946 |
4947 | switch (state) {
4948 | case START:
4949 | if (g_ascii_isalnum(got_c)((g_ascii_table[(guchar) (got_c)] & G_ASCII_ALNUM) != 0)) {
4950 | if (cur_var->len > 0) {
4951 | if (got_val) {
4952 | if (cur_val->len > 0) {
4953 | if (cur_val->str[cur_val->len-1] == ',') {
4954 | /*
4955 | * If the pref has a trailing comma, eliminate it.
4956 | */
4957 | cur_val->str[cur_val->len-1] = '\0';
4958 | ws_warning("%s line %d: trailing comma in \"%s\" %s", pf_path, pline, cur_var->str, hint)do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 4958, __func__, "%s line %d: trailing comma in \"%s\" %s", pf_path , pline, cur_var->str, hint); } } while (0);
4959 | }
4960 | }
4961 | /* Call the routine to set the preference; it will parse
4962 | the value as appropriate.
4963 |
4964 | Since we're reading a file, rather than processing
4965 | explicit user input, for range preferences, silently
4966 | lower values in excess of the range's maximum, rather
4967 | than reporting errors and failing. */
4968 | switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data, false0)) {
4969 |
4970 | case PREFS_SET_OK:
4971 | break;
4972 |
4973 | case PREFS_SET_SYNTAX_ERR:
4974 | report_warning("Syntax error in preference \"%s\" at line %d of\n%s %s",
4975 | cur_var->str, pline, pf_path, hint);
4976 | break;
4977 |
4978 | case PREFS_SET_NO_SUCH_PREF:
4979 | ws_warning("No such preference \"%s\" at line %d of\n%s %s",do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 4980, __func__, "No such preference \"%s\" at line %d of\n%s %s" , cur_var->str, pline, pf_path, hint); } } while (0)
4980 | cur_var->str, pline, pf_path, hint)do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 4980, __func__, "No such preference \"%s\" at line %d of\n%s %s" , cur_var->str, pline, pf_path, hint); } } while (0);
4981 | break;
4982 |
4983 | case PREFS_SET_OBSOLETE:
4984 | /*
4985 | * If an attempt is made to save the
4986 | * preferences, a popup warning will be
4987 | * displayed stating that obsolete prefs
4988 | * have been detected and the user will
4989 | * be given the opportunity to save these
4990 | * prefs under a different profile name.
4991 | * The prefs in question need to be listed
4992 | * in the console window so that the
4993 | * user can make an informed choice.
4994 | */
4995 | ws_warning("Obsolete preference \"%s\" at line %d of\n%s %s",do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 4996, __func__, "Obsolete preference \"%s\" at line %d of\n%s %s" , cur_var->str, pline, pf_path, hint); } } while (0)
4996 | cur_var->str, pline, pf_path, hint)do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 4996, __func__, "Obsolete preference \"%s\" at line %d of\n%s %s" , cur_var->str, pline, pf_path, hint); } } while (0);
4997 | break;
4998 | }
4999 | } else {
5000 | ws_warning("Incomplete preference at line %d: of\n%s %s", pline, pf_path, hint)do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 5000, __func__, "Incomplete preference at line %d: of\n%s %s" , pline, pf_path, hint); } } while (0);
5001 | }
5002 | }
5003 | state = IN_VAR;
5004 | got_val = false0;
5005 | g_string_truncate(cur_var, 0)g_string_truncate_inline (cur_var, 0);
5006 | g_string_append_c(cur_var, (char) got_c)g_string_append_c_inline (cur_var, (char) got_c);
5007 | pline = fline;
5008 | } else if (g_ascii_isspace(got_c)((g_ascii_table[(guchar) (got_c)] & G_ASCII_SPACE) != 0) && cur_var->len > 0 && got_val) {
5009 | state = PRE_VAL;
5010 | } else if (got_c == '#') {
5011 | state = IN_SKIP;
5012 | } else {
5013 | ws_warning("Malformed preference at line %d of\n%s %s", fline, pf_path, hint)do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 5013, __func__, "Malformed preference at line %d of\n%s %s" , fline, pf_path, hint); } } while (0);
5014 | }
5015 | break;
5016 | case IN_VAR:
5017 | if (got_c != ':') {
5018 | g_string_append_c(cur_var, (char) got_c)g_string_append_c_inline (cur_var, (char) got_c);
5019 | } else {
5020 | /* This is a colon (':') */
5021 | state = PRE_VAL;
5022 | g_string_truncate(cur_val, 0)g_string_truncate_inline (cur_val, 0);
5023 | /*
5024 | * Set got_val to true to accommodate prefs such as
5025 | * "gui.fileopen.dir" that do not require a value.
5026 | */
5027 | got_val = true1;
5028 | }
5029 | break;
5030 | case PRE_VAL:
5031 | if (!g_ascii_isspace(got_c)((g_ascii_table[(guchar) (got_c)] & G_ASCII_SPACE) != 0)) {
5032 | state = IN_VAL;
5033 | g_string_append_c(cur_val, (char) got_c)g_string_append_c_inline (cur_val, (char) got_c);
5034 | }
5035 | break;
5036 | case IN_VAL:
5037 | g_string_append_c(cur_val, (char) got_c)g_string_append_c_inline (cur_val, (char) got_c);
5038 | break;
5039 | case IN_SKIP:
5040 | break;
5041 | }
5042 | }
5043 | if (cur_var->len > 0) {
5044 | if (got_val) {
5045 | /* Call the routine to set the preference; it will parse
5046 | the value as appropriate.
5047 |
5048 | Since we're reading a file, rather than processing
5049 | explicit user input, for range preferences, silently
5050 | lower values in excess of the range's maximum, rather
5051 | than reporting errors and failing. */
5052 | switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data, false0)) {
5053 |
5054 | case PREFS_SET_OK:
5055 | break;
5056 |
5057 | case PREFS_SET_SYNTAX_ERR:
5058 | ws_warning("Syntax error in preference %s at line %d of\n%s %s",do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 5059, __func__, "Syntax error in preference %s at line %d of\n%s %s" , cur_var->str, pline, pf_path, hint); } } while (0)
5059 | cur_var->str, pline, pf_path, hint)do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 5059, __func__, "Syntax error in preference %s at line %d of\n%s %s" , cur_var->str, pline, pf_path, hint); } } while (0);
5060 | break;
5061 |
5062 | case PREFS_SET_NO_SUCH_PREF:
5063 | ws_warning("No such preference \"%s\" at line %d of\n%s %s",do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 5064, __func__, "No such preference \"%s\" at line %d of\n%s %s" , cur_var->str, pline, pf_path, hint); } } while (0)
5064 | cur_var->str, pline, pf_path, hint)do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 5064, __func__, "No such preference \"%s\" at line %d of\n%s %s" , cur_var->str, pline, pf_path, hint); } } while (0);
5065 | break;
5066 |
5067 | case PREFS_SET_OBSOLETE:
5068 | ws_warning("Obsolete preference \"%s\" at line %d of\n%s %s",do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 5069, __func__, "Obsolete preference \"%s\" at line %d of\n%s %s" , cur_var->str, pline, pf_path, hint); } } while (0)
5069 | cur_var->str, pline, pf_path, hint)do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 5069, __func__, "Obsolete preference \"%s\" at line %d of\n%s %s" , cur_var->str, pline, pf_path, hint); } } while (0);
5070 | break;
5071 | }
5072 | } else {
5073 | ws_warning("Incomplete preference at line %d of\n%s %s",do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 5074, __func__, "Incomplete preference at line %d of\n%s %s" , pline, pf_path, hint); } } while (0)
5074 | pline, pf_path, hint)do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 5074, __func__, "Incomplete preference at line %d of\n%s %s" , pline, pf_path, hint); } } while (0);
5075 | }
5076 | }
5077 |
5078 | g_string_free(cur_val, TRUE)(__builtin_constant_p ((!(0))) ? (((!(0))) ? (g_string_free) ( (cur_val), ((!(0)))) : g_string_free_and_steal (cur_val)) : ( g_string_free) ((cur_val), ((!(0)))));
5079 | g_string_free(cur_var, TRUE)(__builtin_constant_p ((!(0))) ? (((!(0))) ? (g_string_free) ( (cur_var), ((!(0)))) : g_string_free_and_steal (cur_var)) : ( g_string_free) ((cur_var), ((!(0)))));
5080 |
5081 | if (ferror(pf))
5082 | return errno(*__errno_location ());
5083 | else
5084 | return 0;
5085 | }
5086 |
5087 | /*
5088 | * If we were handed a preference starting with "uat:", try to turn it into
5089 | * a valid uat entry.
5090 | */
5091 | static bool_Bool
5092 | prefs_set_uat_pref(char *uat_entry, char **errmsg) {
5093 | char *p, *colonp;
5094 | uat_t *uat;
5095 | bool_Bool ret;
5096 |
5097 | colonp = strchr(uat_entry, ':');
5098 | if (colonp == NULL((void*)0))
5099 | return false0;
5100 |
5101 | p = colonp;
5102 | *p++ = '\0';
5103 |
5104 | /*
5105 | * Skip over any white space (there probably won't be any, but
5106 | * as we allow it in the preferences file, we might as well
5107 | * allow it here).
5108 | */
5109 | while (g_ascii_isspace(*p)((g_ascii_table[(guchar) (*p)] & G_ASCII_SPACE) != 0))
5110 | p++;
5111 | if (*p == '\0') {
5112 | /*
5113 | * Put the colon back, so if our caller uses, in an
5114 | * error message, the string they passed us, the message
5115 | * looks correct.
5116 | */
5117 | *colonp = ':';
5118 | return false0;
5119 | }
5120 |
5121 | uat = uat_find(uat_entry);
5122 | *colonp = ':';
5123 | if (uat == NULL((void*)0)) {
5124 | *errmsg = g_strdup("Unknown preference")g_strdup_inline ("Unknown preference");
5125 | return false0;
5126 | }
5127 |
5128 | ret = uat_load_str(uat, p, errmsg);
5129 | return ret;
5130 | }
5131 |
5132 | char *
5133 | prefs_sanitize_string(const char* str)
5134 | {
5135 | char *sanitized;
5136 | if (!prefs_regex) {
5137 | prefs_regex = g_regex_new("\\s*\\R\\s*", (GRegexCompileFlags)G_REGEX_OPTIMIZE,
5138 | (GRegexMatchFlags)G_REGEX_MATCH_BSR_ANYCRLF, NULL((void*)0));
5139 | } else {
5140 | g_regex_ref(prefs_regex);
5141 | }
5142 | sanitized = g_regex_replace(prefs_regex, str, -1, 0, " ", G_REGEX_MATCH_DEFAULT, NULL((void*)0));
5143 | g_regex_unref(prefs_regex);
5144 | return sanitized;
5145 | }
5146 |
5147 | /*
5148 | * Given a string of the form "<pref name>:<pref value>", as might appear
5149 | * as an argument to a "-o" option, parse it and set the preference in
5150 | * question. Return an indication of whether it succeeded or failed
5151 | * in some fashion.
5152 | */
5153 | prefs_set_pref_e
5154 | prefs_set_pref(char *prefarg, char **errmsg)
5155 | {
5156 | char *p, *colonp;
5157 | prefs_set_pref_e ret;
5158 |
5159 | *errmsg = NULL((void*)0);
5160 |
5161 | colonp = strchr(prefarg, ':');
5162 | if (colonp == NULL((void*)0)) {
5163 | *errmsg = g_strdup("missing ':' (syntax is prefname:value).")g_strdup_inline ("missing ':' (syntax is prefname:value).");
5164 | return PREFS_SET_SYNTAX_ERR;
5165 | }
5166 |
5167 | p = colonp;
5168 | *p++ = '\0';
5169 | /* XXX - Replace line terminators, or match and fail with errmsg, or ignore? */
5170 |
5171 | /*
5172 | * Skip over any white space (there probably won't be any, but
5173 | * as we allow it in the preferences file, we might as well
5174 | * allow it here).
5175 | */
5176 | while (g_ascii_isspace(*p)((g_ascii_table[(guchar) (*p)] & G_ASCII_SPACE) != 0))
5177 | p++;
5178 | /* The empty string is a legal value for range preferences (PREF_RANGE,
5179 | * PREF_DECODE_AS_RANGE), and string-like preferences (PREF_STRING,
5180 | * PREF_SAVE_FILENAME, PREF_OPEN_FILENAME, PREF_DIRNAME), indeed often
5181 | * not just useful but the default. A user might have a value saved
5182 | * to their preference file but want to override it to default behavior.
5183 | * Individual preference handlers of those types should be prepared to
5184 | * deal with an empty string. For other types, it is up to set_pref() to
5185 | * test for the empty string and set PREFS_SET_SYNTAX_ERROR there.
5186 | */
5187 | if (strcmp(prefarg, "uat")) {
5188 | ret = set_pref(prefarg, p, NULL((void*)0), true1);
5189 | } else {
5190 | ret = prefs_set_uat_pref(p, errmsg) ? PREFS_SET_OK : PREFS_SET_SYNTAX_ERR;
5191 | }
5192 | *colonp = ':'; /* put the colon back */
5193 | return ret;
5194 | }
5195 |
5196 | unsigned prefs_get_uint_value(pref_t *pref, pref_source_t source)
5197 | {
5198 | switch (source)
5199 | {
5200 | case pref_default:
5201 | return pref->default_val.uint;
5202 | case pref_stashed:
5203 | return pref->stashed_val.uint;
5204 | case pref_current:
5205 | return *pref->varp.uint;
5206 | default:
5207 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 5207 , __func__, "assertion \"not reached\" failed");
5208 | break;
5209 | }
5210 |
5211 | return 0;
5212 | }
5213 |
5214 | unsigned int prefs_set_int_value(pref_t* pref, int value, pref_source_t source)
5215 | {
5216 | int changed = 0;
5217 | switch (source)
5218 | {
5219 | case pref_default:
5220 | if (pref->default_val.intval != value) {
5221 | pref->default_val.intval = value;
5222 | changed = prefs_get_effect_flags(pref);
5223 | }
5224 | break;
5225 | case pref_stashed:
5226 | if (pref->stashed_val.intval != value) {
5227 | pref->stashed_val.intval = value;
5228 | changed = prefs_get_effect_flags(pref);
5229 | }
5230 | break;
5231 | case pref_current:
5232 | if (*pref->varp.intp != value) {
5233 | *pref->varp.intp = value;
5234 | changed = prefs_get_effect_flags(pref);
5235 | }
5236 | break;
5237 | default:
5238 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 5238 , __func__, "assertion \"not reached\" failed");
5239 | break;
5240 | }
5241 |
5242 | return changed;
5243 | }
5244 |
5245 | int prefs_get_int_value(pref_t* pref, pref_source_t source)
5246 | {
5247 | switch (source)
5248 | {
5249 | case pref_default:
5250 | return pref->default_val.intval;
5251 | case pref_stashed:
5252 | return pref->stashed_val.intval;
5253 | case pref_current:
5254 | return *pref->varp.intp;
5255 | default:
5256 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 5256 , __func__, "assertion \"not reached\" failed");
5257 | break;
5258 | }
5259 |
5260 | return 0;
5261 | }
5262 |
5263 | unsigned int prefs_set_float_value(pref_t* pref, double value, pref_source_t source)
5264 | {
5265 | int changed = 0;
5266 | switch (source)
5267 | {
5268 | case pref_default:
5269 | if (pref->default_val.floatval != value) {
5270 | pref->default_val.floatval = value;
5271 | changed = prefs_get_effect_flags(pref);
5272 | }
5273 | break;
5274 | case pref_stashed:
5275 | if (pref->stashed_val.floatval != value) {
5276 | pref->stashed_val.floatval = value;
5277 | changed = prefs_get_effect_flags(pref);
5278 | }
5279 | break;
5280 | case pref_current:
5281 | if (*pref->varp.floatp != value) {
5282 | *pref->varp.floatp = value;
5283 | changed = prefs_get_effect_flags(pref);
5284 | }
5285 | break;
5286 | default:
5287 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 5287 , __func__, "assertion \"not reached\" failed");
5288 | break;
5289 | }
5290 |
5291 | return changed;
5292 | }
5293 |
5294 | double prefs_get_float_value(pref_t* pref, pref_source_t source)
5295 | {
5296 | switch (source)
5297 | {
5298 | case pref_default:
5299 | return pref->default_val.floatval;
5300 | case pref_stashed:
5301 | return pref->stashed_val.floatval;
5302 | case pref_current:
5303 | return *pref->varp.floatp;
5304 | default:
5305 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 5305 , __func__, "assertion \"not reached\" failed");
5306 | break;
5307 | }
5308 |
5309 | return 0;
5310 | }
5311 |
5312 |
5313 | const char *prefs_get_password_value(pref_t *pref, pref_source_t source)
5314 | {
5315 | return prefs_get_string_value(pref, source);
5316 | }
5317 |
5318 |
5319 | unsigned int prefs_set_uint_value(pref_t *pref, unsigned value, pref_source_t source)
5320 | {
5321 | unsigned int changed = 0;
5322 | switch (source)
5323 | {
5324 | case pref_default:
5325 | if (pref->default_val.uint != value) {
5326 | pref->default_val.uint = value;
5327 | changed = prefs_get_effect_flags(pref);
5328 | }
5329 | break;
5330 | case pref_stashed:
5331 | if (pref->stashed_val.uint != value) {
5332 | pref->stashed_val.uint = value;
5333 | changed = prefs_get_effect_flags(pref);
5334 | }
5335 | break;
5336 | case pref_current:
5337 | if (*pref->varp.uint != value) {
5338 | *pref->varp.uint = value;
5339 | changed = prefs_get_effect_flags(pref);
5340 | }
5341 | break;
5342 | default:
5343 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 5343 , __func__, "assertion \"not reached\" failed");
5344 | break;
5345 | }
5346 |
5347 | return changed;
5348 | }
5349 |
5350 | /*
5351 | * For use by UI code that sets preferences.
5352 | */
5353 | unsigned int
5354 | prefs_set_password_value(pref_t *pref, const char* value, pref_source_t source)
5355 | {
5356 | return prefs_set_string_value(pref, value, source);
5357 | }
5358 |
5359 |
5360 | unsigned prefs_get_uint_base(pref_t *pref)
5361 | {
5362 | return pref->info.base;
5363 | }
5364 |
5365 | /*
5366 | * Returns true if the given device is hidden
5367 | */
5368 | bool_Bool
5369 | prefs_is_capture_device_hidden(const char *name)
5370 | {
5371 | char *tok, *devices;
5372 | size_t len;
5373 |
5374 | if (prefs.capture_devices_hide && name) {
5375 | devices = g_strdup (prefs.capture_devices_hide)g_strdup_inline (prefs.capture_devices_hide);
5376 | len = strlen (name);
5377 | for (tok = strtok (devices, ","); tok; tok = strtok(NULL((void*)0), ",")) {
5378 | if (strlen (tok) == len && strcmp (name, tok) == 0) {
5379 | g_free (devices);
5380 | return true1;
5381 | }
5382 | }
5383 | g_free (devices);
5384 | }
5385 |
5386 | return false0;
5387 | }
5388 |
5389 | /*
5390 | * Returns true if the given column is visible (not hidden)
5391 | */
5392 | static bool_Bool
5393 | prefs_is_column_visible(const char *cols_hidden, int col)
5394 | {
5395 | char *tok, *cols, *p;
5396 | int cidx;
5397 |
5398 | /*
5399 | * Do we have a list of hidden columns?
5400 | */
5401 | if (cols_hidden) {
5402 | /*
5403 | * Yes - check the column against each of the ones in the
5404 | * list.
5405 | */
5406 | cols = g_strdup(cols_hidden)g_strdup_inline (cols_hidden);
5407 | for (tok = strtok(cols, ","); tok; tok = strtok(NULL((void*)0), ",")) {
5408 | tok = g_strstrip(tok)g_strchomp (g_strchug (tok));
5409 |
5410 | cidx = (int)strtol(tok, &p, 10);
5411 | if (p == tok || *p != '\0') {
5412 | continue;
5413 | }
5414 | if (cidx != col) {
5415 | continue;
5416 | }
5417 | /*
5418 | * OK, they match, so it's one of the hidden fields,
5419 | * hence not visible.
5420 | */
5421 | g_free(cols);
5422 | return false0;
5423 | }
5424 | g_free(cols);
5425 | }
5426 |
5427 | /*
5428 | * No - either there are no hidden columns or this isn't one
5429 | * of them - so it is visible.
5430 | */
5431 | return true1;
5432 | }
5433 |
5434 | /*
5435 | * Returns true if the given column is visible (not hidden)
5436 | */
5437 | static bool_Bool
5438 | prefs_is_column_fmt_visible(const char *cols_hidden, fmt_data *cfmt)
5439 | {
5440 | char *tok, *cols;
5441 | fmt_data cfmt_hidden;
5442 |
5443 | /*
5444 | * Do we have a list of hidden columns?
5445 | */
5446 | if (cols_hidden) {
5447 | /*
5448 | * Yes - check the column against each of the ones in the
5449 | * list.
5450 | */
5451 | cols = g_strdup(cols_hidden)g_strdup_inline (cols_hidden);
5452 | for (tok = strtok(cols, ","); tok; tok = strtok(NULL((void*)0), ",")) {
5453 | tok = g_strstrip(tok)g_strchomp (g_strchug (tok));
5454 |
5455 | /*
5456 | * Parse this column format.
5457 | */
5458 | if (!parse_column_format(&cfmt_hidden, tok)) {
5459 | /*
5460 | * It's not valid; ignore it.
5461 | */
5462 | continue;
5463 | }
5464 |
5465 | /*
5466 | * Does it match the column?
5467 | */
5468 | if (cfmt->fmt != cfmt_hidden.fmt) {
5469 | /* No. */
5470 | g_free(cfmt_hidden.custom_fields);
5471 | cfmt_hidden.custom_fields = NULL((void*)0);
5472 | continue;
5473 | }
5474 | if (cfmt->fmt == COL_CUSTOM) {
5475 | /*
5476 | * A custom column has to have the same custom field
5477 | * and occurrence.
5478 | */
5479 | if (cfmt_hidden.custom_fields && cfmt->custom_fields) {
5480 | if (strcmp(cfmt->custom_fields,
5481 | cfmt_hidden.custom_fields) != 0) {
5482 | /* Different fields. */
5483 | g_free(cfmt_hidden.custom_fields);
5484 | cfmt_hidden.custom_fields = NULL((void*)0);
5485 | continue;
5486 | }
5487 | if (cfmt->custom_occurrence != cfmt_hidden.custom_occurrence) {
5488 | /* Different occurrences settings. */
5489 | g_free(cfmt_hidden.custom_fields);
5490 | cfmt_hidden.custom_fields = NULL((void*)0);
5491 | continue;
5492 | }
5493 | }
5494 | }
5495 |
5496 | /*
5497 | * OK, they match, so it's one of the hidden fields,
5498 | * hence not visible.
5499 | */
5500 | g_free(cfmt_hidden.custom_fields);
5501 | g_free(cols);
5502 | return false0;
5503 | }
5504 | g_free(cols);
5505 | }
5506 |
5507 | /*
5508 | * No - either there are no hidden columns or this isn't one
5509 | * of them - so it is visible.
5510 | */
5511 | return true1;
5512 | }
5513 |
5514 | /*
5515 | * Returns true if the given device should capture in monitor mode by default
5516 | */
5517 | bool_Bool
5518 | prefs_capture_device_monitor_mode(const char *name)
5519 | {
5520 | char *tok, *devices;
5521 | size_t len;
5522 |
5523 | if (prefs.capture_devices_monitor_mode && name) {
5524 | devices = g_strdup (prefs.capture_devices_monitor_mode)g_strdup_inline (prefs.capture_devices_monitor_mode);
5525 | len = strlen (name);
5526 | for (tok = strtok (devices, ","); tok; tok = strtok(NULL((void*)0), ",")) {
5527 | if (strlen (tok) == len && strcmp (name, tok) == 0) {
5528 | g_free (devices);
5529 | return true1;
5530 | }
5531 | }
5532 | g_free (devices);
5533 | }
5534 |
5535 | return false0;
5536 | }
5537 |
5538 | /*
5539 | * Returns true if the user has marked this column as visible
5540 | */
5541 | bool_Bool
5542 | prefs_capture_options_dialog_column_is_visible(const char *column)
5543 | {
5544 | GList *curr;
5545 | char *col;
5546 |
5547 | for (curr = g_list_first(prefs.capture_columns); curr; curr = g_list_next(curr)((curr) ? (((GList *)(curr))->next) : ((void*)0))) {
5548 | col = (char *)curr->data;
5549 | if (col && (g_ascii_strcasecmp(col, column) == 0)) {
5550 | return true1;
5551 | }
5552 | }
5553 | return false0;
5554 | }
5555 |
5556 | bool_Bool
5557 | prefs_has_layout_pane_content (layout_pane_content_e layout_pane_content)
5558 | {
5559 | return ((prefs.gui_layout_content_1 == layout_pane_content) ||
5560 | (prefs.gui_layout_content_2 == layout_pane_content) ||
5561 | (prefs.gui_layout_content_3 == layout_pane_content));
5562 | }
5563 |
5564 | char
5565 | string_to_name_resolve(const char *string, e_addr_resolve *name_resolve)
5566 | {
5567 | char c;
5568 |
5569 | memset(name_resolve, 0, sizeof(e_addr_resolve));
5570 | while ((c = *string++) != '\0') {
5571 | switch (c) {
5572 | case 'g':
5573 | name_resolve->maxmind_geoip = true1;
5574 | break;
5575 | case 'm':
5576 | name_resolve->mac_name = true1;
5577 | break;
5578 | case 'n':
5579 | name_resolve->network_name = true1;
5580 | break;
5581 | case 'N':
5582 | name_resolve->use_external_net_name_resolver = true1;
5583 | break;
5584 | case 't':
5585 | name_resolve->transport_name = true1;
5586 | break;
5587 | case 'd':
5588 | name_resolve->dns_pkt_addr_resolution = true1;
5589 | break;
5590 | case 's':
5591 | name_resolve->handshake_sni_addr_resolution = true1;
5592 | break;
5593 | case 'v':
5594 | name_resolve->vlan_name = true1;
5595 | break;
5596 | default:
5597 | /*
5598 | * Unrecognized letter.
5599 | */
5600 | return c;
5601 | }
5602 | }
5603 | return '\0';
5604 | }
5605 |
5606 | static bool_Bool
5607 | deprecated_heur_dissector_pref(char *pref_name, const char *value)
5608 | {
5609 | struct heur_pref_name
5610 | {
5611 | const char* pref_name;
5612 | const char* short_name;
5613 | bool_Bool more_dissectors; /* For multiple dissectors controlled by the same preference */
5614 | };
5615 |
5616 | static const struct heur_pref_name heur_prefs[] = {
5617 | {"acn.heuristic_acn", "acn_udp", 0},
5618 | {"bfcp.enable", "bfcp_tcp", 1},
5619 | {"bfcp.enable", "bfcp_udp", 0},
5620 | {"bt-dht.enable", "bittorrent_dht_udp", 0},
5621 | {"bt-utp.enable", "bt_utp_udp", 0},
5622 | {"cattp.enable", "cattp_udp", 0},
5623 | {"cfp.enable", "fp_eth", 0},
5624 | {"dicom.heuristic", "dicom_tcp", 0},
5625 | {"dnp3.heuristics", "dnp3_tcp", 1},
5626 | {"dnp3.heuristics", "dnp3_udp", 0},
5627 | {"dvb-s2_modeadapt.enable", "dvb_s2_udp", 0},
5628 | {"esl.enable", "esl_eth", 0},
5629 | {"fp.udp_heur", "fp_udp", 0},
5630 | {"gvsp.enable_heuristic", "gvsp_udp", 0},
5631 | {"hdcp2.enable", "hdcp2_tcp", 0},
5632 | {"hislip.enable_heuristic", "hislip_tcp", 0},
5633 | {"infiniband.dissect_eoib", "mellanox_eoib", 1},
5634 | {"infiniband.identify_payload", "eth_over_ib", 0},
5635 | {"jxta.udp.heuristic", "jxta_udp", 0},
5636 | {"jxta.tcp.heuristic", "jxta_tcp", 0},
5637 | {"jxta.sctp.heuristic", "jxta_sctp", 0},
5638 | {"mac-lte.heuristic_mac_lte_over_udp", "mac_lte_udp", 0},
5639 | {"mbim.bulk_heuristic", "mbim_usb_bulk", 0},
5640 | {"norm.heuristic_norm", "rmt_norm_udp", 0},
5641 | {"openflow.heuristic", "openflow_tcp", 0},
5642 | {"pdcp-lte.heuristic_pdcp_lte_over_udp", "pdcp_lte_udp", 0},
5643 | {"rlc.heuristic_rlc_over_udp", "rlc_udp", 0},
5644 | {"rlc-lte.heuristic_rlc_lte_over_udp", "rlc_lte_udp", 0},
5645 | {"rtcp.heuristic_rtcp", "rtcp_udp", 1},
5646 | {"rtcp.heuristic_rtcp", "rtcp_stun", 0},
5647 | {"rtp.heuristic_rtp", "rtp_udp", 1},
5648 | {"rtp.heuristic_rtp", "rtp_stun", 0},
5649 | {"teredo.heuristic_teredo", "teredo_udp", 0},
5650 | {"vssmonitoring.use_heuristics", "vssmonitoring_eth", 0},
5651 | {"xml.heuristic", "xml_http", 1},
5652 | {"xml.heuristic", "xml_sip", 1},
5653 | {"xml.heuristic", "xml_media", 0},
5654 | {"xml.heuristic_tcp", "xml_tcp", 0},
5655 | {"xml.heuristic_udp", "xml_udp", 0},
5656 | };
5657 |
5658 | unsigned int i;
5659 | heur_dtbl_entry_t* heuristic;
5660 |
5661 |
5662 | for (i = 0; i < array_length(heur_prefs)(sizeof (heur_prefs) / sizeof (heur_prefs)[0]); i++)
5663 | {
5664 | if (strcmp(pref_name, heur_prefs[i].pref_name) == 0)
5665 | {
5666 | heuristic = find_heur_dissector_by_unique_short_name(heur_prefs[i].short_name);
5667 | if (heuristic != NULL((void*)0)) {
5668 | heuristic->enabled = ((g_ascii_strcasecmp(value, "true") == 0) ? true1 : false0);
5669 | }
5670 |
5671 | if (!heur_prefs[i].more_dissectors)
5672 | return true1;
5673 | }
5674 | }
5675 |
5676 |
5677 | return false0;
5678 | }
5679 |
5680 | static bool_Bool
5681 | deprecated_enable_dissector_pref(char *pref_name, const char *value)
5682 | {
5683 | struct dissector_pref_name
5684 | {
5685 | const char* pref_name;
5686 | const char* short_name;
5687 | };
5688 |
5689 | struct dissector_pref_name dissector_prefs[] = {
5690 | {"transum.tsumenabled", "TRANSUM"},
5691 | {"snort.enable_snort_dissector", "Snort"},
5692 | {"prp.enable", "PRP"},
5693 | };
5694 |
5695 | unsigned int i;
5696 | int proto_id;
5697 |
5698 | for (i = 0; i < array_length(dissector_prefs)(sizeof (dissector_prefs) / sizeof (dissector_prefs)[0]); i++)
5699 | {
5700 | if (strcmp(pref_name, dissector_prefs[i].pref_name) == 0)
5701 | {
5702 | proto_id = proto_get_id_by_short_name(dissector_prefs[i].short_name);
5703 | if (proto_id >= 0)
5704 | proto_set_decoding(proto_id, ((g_ascii_strcasecmp(value, "true") == 0) ? true1 : false0));
5705 | return true1;
5706 | }
5707 | }
5708 |
5709 | return false0;
5710 | }
5711 |
5712 | static bool_Bool
5713 | deprecated_port_pref(char *pref_name, const char *value)
5714 | {
5715 | struct port_pref_name
5716 | {
5717 | const char* pref_name;
5718 | const char* module_name; /* the protocol filter name */
5719 | const char* table_name;
5720 | unsigned base;
5721 | };
5722 |
5723 | struct obsolete_pref_name
5724 | {
5725 | const char* pref_name;
5726 | };
5727 |
5728 | /* For now this is only supporting TCP/UDP port and RTP payload
5729 | * types dissector preferences, which are assumed to be decimal */
5730 | /* module_name is the filter name of the destination port preference,
5731 | * which is usually the same as the original module but not
5732 | * necessarily (e.g., if the preference is for what is now a PINO.)
5733 | * XXX: Most of these were changed pre-2.0. Can we end support
5734 | * for migrating legacy preferences at some point?
5735 | */
5736 | static const struct port_pref_name port_prefs[] = {
5737 | /* TCP */
5738 | {"cmp.tcp_alternate_port", "cmp", "tcp.port", 10},
5739 | {"h248.tcp_port", "h248", "tcp.port", 10},
5740 | {"cops.tcp.cops_port", "cops", "tcp.port", 10},
5741 | {"dhcpfo.tcp_port", "dhcpfo", "tcp.port", 10},
5742 | {"enttec.tcp_port", "enttec", "tcp.port", 10},
5743 | {"forces.tcp_alternate_port", "forces", "tcp.port", 10},
5744 | {"ged125.tcp_port", "ged125", "tcp.port", 10},
5745 | {"hpfeeds.dissector_port", "hpfeeds", "tcp.port", 10},
5746 | {"lsc.port", "lsc", "tcp.port", 10},
5747 | {"megaco.tcp.txt_port", "megaco", "tcp.port", 10},
5748 | {"netsync.tcp_port", "netsync", "tcp.port", 10},
5749 | {"osi.tpkt_port", "osi", "tcp.port", 10},
5750 | {"rsync.tcp_port", "rsync", "tcp.port", 10},
5751 | {"sametime.tcp_port", "sametime", "tcp.port", 10},
5752 | {"sigcomp.tcp.port2", "sigcomp", "tcp.port", 10},
5753 | {"synphasor.tcp_port", "synphasor", "tcp.port", 10},
5754 | {"tipc.alternate_port", "tipc", "tcp.port", 10},
5755 | {"vnc.alternate_port", "vnc", "tcp.port", 10},
5756 | {"scop.port", "scop", "tcp.port", 10},
5757 | {"scop.port_secure", "scop", "tcp.port", 10},
5758 | {"tpncp.tcp.trunkpack_port", "tpncp", "tcp.port", 10},
5759 | /* UDP */
5760 | {"h248.udp_port", "h248", "udp.port", 10},
5761 | {"actrace.udp_port", "actrace", "udp.port", 10},
5762 | {"brp.port", "brp", "udp.port", 10},
5763 | {"bvlc.additional_udp_port", "bvlc", "udp.port", 10},
5764 | {"capwap.udp.port.control", "capwap", "udp.port", 10},
5765 | {"capwap.udp.port.data", "capwap", "udp.port", 10},
5766 | {"coap.udp_port", "coap", "udp.port", 10},
5767 | {"enttec.udp_port", "enttec", "udp.port", 10},
5768 | {"forces.udp_alternate_port", "forces", "udp.port", 10},
5769 | {"ldss.udp_port", "ldss", "udp.port", 10},
5770 | {"lmp.udp_port", "lmp", "udp.port", 10},
5771 | {"ltp.port", "ltp", "udp.port", 10},
5772 | {"lwres.udp.lwres_port", "lwres", "udp.port", 10},
5773 | {"megaco.udp.txt_port", "megaco", "udp.port", 10},
5774 | {"pfcp.port_pfcp", "pfcp", "udp.port", 10},
5775 | {"pgm.udp.encap_ucast_port", "pgm", "udp.port", 10},
5776 | {"pgm.udp.encap_mcast_port", "pgm", "udp.port", 10},
5777 | {"quic.udp.quic.port", "quic", "udp.port", 10},
5778 | {"quic.udp.quics.port", "quic", "udp.port", 10},
5779 | {"radius.alternate_port", "radius", "udp.port", 10},
5780 | {"rdt.default_udp_port", "rdt", "udp.port", 10},
5781 | {"alc.default.udp_port", "alc", "udp.port", 10},
5782 | {"sigcomp.udp.port2", "sigcomp", "udp.port", 10},
5783 | {"synphasor.udp_port", "synphasor", "udp.port", 10},
5784 | {"tdmop.udpport", "tdmop", "udp.port", 10},
5785 | {"uaudp.port1", "uaudp", "udp.port", 10},
5786 | {"uaudp.port2", "uaudp", "udp.port", 10},
5787 | {"uaudp.port3", "uaudp", "udp.port", 10},
5788 | {"uaudp.port4", "uaudp", "udp.port", 10},
5789 | {"uhd.dissector_port", "uhd", "udp.port", 10},
5790 | {"vrt.dissector_port", "vrt", "udp.port", 10},
5791 | {"tpncp.udp.trunkpack_port", "tpncp", "udp.port", 10},
5792 | /* SCTP */
5793 | {"hnbap.port", "hnbap", "sctp.port", 10},
5794 | {"m2pa.port", "m2pa", "sctp.port", 10},
5795 | {"megaco.sctp.txt_port", "megaco", "sctp.port", 10},
5796 | {"rua.port", "rua", "sctp.port", 10},
5797 | /* SCTP PPI */
5798 | {"lapd.sctp_payload_protocol_identifier", "lapd", "sctp.ppi", 10},
5799 | /* SCCP SSN */
5800 | {"ranap.sccp_ssn", "ranap", "sccp.ssn", 10},
5801 | };
5802 |
5803 | static const struct port_pref_name port_range_prefs[] = {
5804 | /* TCP */
5805 | {"couchbase.tcp.ports", "couchbase", "tcp.port", 10},
5806 | {"gsm_ipa.tcp_ports", "gsm_ipa", "tcp.port", 10},
5807 | {"kafka.tcp.ports", "kafka", "tcp.port", 10},
5808 | {"kt.tcp.ports", "kt", "tcp.port", 10},
5809 | {"memcache.tcp.ports", "memcache", "tcp.port", 10},
5810 | {"mrcpv2.tcp.port_range", "mrcpv2", "tcp.port", 10},
5811 | {"pdu_transport.ports.tcp", "pdu_transport", "tcp.port", 10},
5812 | {"rtsp.tcp.port_range", "rtsp", "tcp.port", 10},
5813 | {"sip.tcp.ports", "sip", "tcp.port", 10},
5814 | {"someip.ports.tcp", "someip", "tcp.port", 10},
5815 | {"tds.tcp_ports", "tds", "tcp.port", 10},
5816 | {"tpkt.tcp.ports", "tpkt", "tcp.port", 10},
5817 | {"uma.tcp.ports", "uma", "tcp.port", 10},
5818 | /* UDP */
5819 | {"aruba_erm.udp.ports", "arubs_erm", "udp.port", 10},
5820 | {"diameter.udp.ports", "diameter", "udp.port", 10},
5821 | {"dmp.udp_ports", "dmp", "udp.port", 10},
5822 | {"dns.udp.ports", "dns", "udp.port", 10},
5823 | {"gsm_ipa.udp_ports", "gsm_ipa", "udp.port", 10},
5824 | {"hcrt.dissector_udp_port", "hcrt", "udp.port", 10},
5825 | {"memcache.udp.ports", "memcache", "udp.port", 10},
5826 | {"nb_rtpmux.udp_ports", "nb_rtpmux", "udp.port", 10},
5827 | {"gprs-ns.udp.ports", "gprs-ns", "udp.port", 10},
5828 | {"p_mul.udp_ports", "p_mul", "udp.port", 10},
5829 | {"pdu_transport.ports.udp", "pdu_transport", "udp.port", 10},
5830 | {"radius.ports", "radius", "udp.port", 10},
5831 | {"sflow.ports", "sflow", "udp.port", 10},
5832 | {"someip.ports.udp", "someip", "udp.port", 10},
5833 | {"sscop.udp.ports", "sscop", "udp.port", 10},
5834 | {"tftp.udp_ports", "tftp", "udp.port", 10},
5835 | {"tipc.udp.ports", "tipc", "udp.port", 10},
5836 | /* RTP */
5837 | {"amr.dynamic.payload.type", "amr", "rtp.pt", 10},
5838 | {"amr.wb.dynamic.payload.type", "amr_wb", "rtp.pt", 10},
5839 | {"dvb-s2_modeadapt.dynamic.payload.type", "dvb-s2_modeadapt", "rtp.pt", 10},
5840 | {"evs.dynamic.payload.type", "evs", "rtp.pt", 10},
5841 | {"h263p.dynamic.payload.type", "h263p", "rtp.pt", 10},
5842 | {"h264.dynamic.payload.type", "h264", "rtp.pt", 10},
5843 | {"h265.dynamic.payload.type", "h265", "rtp.pt", 10},
5844 | {"ismacryp.dynamic.payload.type", "ismacryp", "rtp.pt", 10},
5845 | {"iuup.dynamic.payload.type", "iuup", "rtp.pt", 10},
5846 | {"lapd.rtp_payload_type", "lapd", "rtp.pt", 10},
5847 | {"mp4ves.dynamic.payload.type", "mp4ves", "rtp.pt", 10},
5848 | {"mtp2.rtp_payload_type", "mtp2", "rtp.pt", 10},
5849 | {"opus.dynamic.payload.type", "opus", "rtp.pt", 10},
5850 | {"rtp.rfc2198_payload_type", "rtp_rfc2198", "rtp.pt", 10},
5851 | {"rtpevent.event_payload_type_value", "rtpevent", "rtp.pt", 10},
5852 | {"rtpevent.cisco_nse_payload_type_value", "rtpevent", "rtp.pt", 10},
5853 | {"rtpmidi.midi_payload_type_value", "rtpmidi", "rtp.pt", 10},
5854 | {"vp8.dynamic.payload.type", "vp8", "rtp.pt", 10},
5855 | /* SCTP */
5856 | {"diameter.sctp.ports", "diameter", "sctp.port", 10},
5857 | {"sgsap.sctp_ports", "sgsap", "sctp.port", 10},
5858 | /* SCCP SSN */
5859 | {"pcap.ssn", "pcap", "sccp.ssn", 10},
5860 | };
5861 |
5862 | /* These are subdissectors of TPKT/OSITP that used to have a
5863 | TCP port preference even though they were never
5864 | directly on TCP. Convert them to use Decode As
5865 | with the TPKT dissector handle */
5866 | static const struct port_pref_name tpkt_subdissector_port_prefs[] = {
5867 | {"dap.tcp.port", "dap", "tcp.port", 10},
5868 | {"disp.tcp.port", "disp", "tcp.port", 10},
5869 | {"dop.tcp.port", "dop", "tcp.port", 10},
5870 | {"dsp.tcp.port", "dsp", "tcp.port", 10},
5871 | {"p1.tcp.port", "p1", "tcp.port", 10},
5872 | {"p7.tcp.port", "p7", "tcp.port", 10},
5873 | {"rdp.tcp.port", "rdp", "tcp.port", 10},
5874 | };
5875 |
5876 | /* These are obsolete preferences from the dissectors' view,
5877 | (typically because of a switch from a single value to a
5878 | range value) but the name of the preference conflicts
5879 | with the generated preference name from the dissector table.
5880 | Don't allow the obsolete preference through to be handled */
5881 | static const struct obsolete_pref_name obsolete_prefs[] = {
5882 | {"diameter.tcp.port"},
5883 | {"kafka.tcp.port"},
5884 | {"mrcpv2.tcp.port"},
5885 | {"rtsp.tcp.port"},
5886 | {"sip.tcp.port"},
5887 | {"t38.tcp.port"},
5888 | };
5889 |
5890 | unsigned int i;
5891 | unsigned uval;
5892 | dissector_table_t sub_dissectors;
5893 | dissector_handle_t handle, tpkt_handle;
5894 | module_t *module;
5895 | pref_t *pref;
5896 |
5897 | static bool_Bool sanity_checked;
5898 | if (!sanity_checked) {
5899 | sanity_checked = true1;
5900 | for (i = 0; i < G_N_ELEMENTS(port_prefs)(sizeof (port_prefs) / sizeof ((port_prefs)[0])); i++) {
5901 | module = prefs_find_module(port_prefs[i].module_name);
5902 | if (!module) {
5903 | // We might not be Wireshark, and therefore might not have deprecated port prefs.
5904 | ws_noisy("Deprecated ports pref check - module '%s' not found", port_prefs[i].module_name)do { if (1) { ws_log_full("Epan", LOG_LEVEL_NOISY, "epan/prefs.c" , 5904, __func__, "Deprecated ports pref check - module '%s' not found" , port_prefs[i].module_name); } } while (0);
5905 | continue;
5906 | }
5907 | pref = prefs_find_preference(module, port_prefs[i].table_name);
5908 | if (!pref) {
5909 | ws_warning("Deprecated ports pref '%s.%s' not found", module->name, port_prefs[i].table_name)do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 5909, __func__, "Deprecated ports pref '%s.%s' not found", module ->name, port_prefs[i].table_name); } } while (0);
5910 | continue;
5911 | }
5912 | if (pref->type != PREF_DECODE_AS_RANGE) {
5913 | ws_warning("Deprecated ports pref '%s.%s' has wrong type: %#x (%s)", module->name, port_prefs[i].table_name, pref->type, prefs_pref_type_name(pref))do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 5913, __func__, "Deprecated ports pref '%s.%s' has wrong type: %#x (%s)" , module->name, port_prefs[i].table_name, pref->type, prefs_pref_type_name (pref)); } } while (0);
5914 | }
5915 | }
5916 | }
5917 |
5918 | for (i = 0; i < G_N_ELEMENTS(port_prefs)(sizeof (port_prefs) / sizeof ((port_prefs)[0])); i++) {
5919 | if (strcmp(pref_name, port_prefs[i].pref_name) == 0) {
5920 | if (!ws_basestrtou32(value, NULL((void*)0), &uval, port_prefs[i].base))
5921 | return false0; /* number was bad */
5922 |
5923 | module = prefs_find_module(port_prefs[i].module_name);
5924 | pref = prefs_find_preference(module, port_prefs[i].table_name);
5925 | if (pref != NULL((void*)0)) {
5926 | module->prefs_changed_flags |= prefs_get_effect_flags(pref);
5927 | if (pref->type == PREF_DECODE_AS_RANGE) {
5928 | // The legacy preference was a port number, but the new
5929 | // preference is a port range. Add to existing range.
5930 | if (uval) {
5931 | prefs_range_add_value(pref, uval);
5932 | }
5933 | }
5934 | }
5935 |
5936 | /* If the value is zero, it wouldn't add to the Decode As tables */
5937 | if (uval != 0)
5938 | {
5939 | sub_dissectors = find_dissector_table(port_prefs[i].table_name);
5940 | if (sub_dissectors != NULL((void*)0)) {
5941 | handle = dissector_table_get_dissector_handle(sub_dissectors, module->title);
5942 | if (handle != NULL((void*)0)) {
5943 | dissector_change_uint(port_prefs[i].table_name, uval, handle);
5944 | decode_build_reset_list(port_prefs[i].table_name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(uval)((gpointer) (gulong) (uval)), NULL((void*)0), NULL((void*)0));
5945 | }
5946 | }
5947 | }
5948 |
5949 | return true1;
5950 | }
5951 | }
5952 |
5953 | for (i = 0; i < array_length(port_range_prefs)(sizeof (port_range_prefs) / sizeof (port_range_prefs)[0]); i++)
5954 | {
5955 | if (strcmp(pref_name, port_range_prefs[i].pref_name) == 0)
5956 | {
5957 | uint32_t range_i, range_j;
5958 |
5959 | sub_dissectors = find_dissector_table(port_range_prefs[i].table_name);
5960 | if (sub_dissectors != NULL((void*)0)) {
5961 | switch (dissector_table_get_type(sub_dissectors)) {
5962 | case FT_UINT8:
5963 | case FT_UINT16:
5964 | case FT_UINT24:
5965 | case FT_UINT32:
5966 | break;
5967 |
5968 | default:
5969 | ws_error("The dissector table %s (%s) is not an integer type - are you using a buggy plugin?", port_range_prefs[i].table_name, get_dissector_table_ui_name(port_range_prefs[i].table_name))ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 5969 , __func__, "The dissector table %s (%s) is not an integer type - are you using a buggy plugin?" , port_range_prefs[i].table_name, get_dissector_table_ui_name (port_range_prefs[i].table_name));
5970 | ws_assert_not_reached()ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 5970 , __func__, "assertion \"not reached\" failed");
5971 | }
5972 |
5973 | module = prefs_find_module(port_range_prefs[i].module_name);
5974 | pref = prefs_find_preference(module, port_range_prefs[i].table_name);
5975 | if (pref != NULL((void*)0))
5976 | {
5977 | if (!prefs_set_range_value_work(pref, value, true1, &module->prefs_changed_flags))
5978 | {
5979 | return false0; /* number was bad */
5980 | }
5981 |
5982 | handle = dissector_table_get_dissector_handle(sub_dissectors, module->title);
5983 | if (handle != NULL((void*)0)) {
5984 |
5985 | for (range_i = 0; range_i < (*pref->varp.range)->nranges; range_i++) {
5986 | for (range_j = (*pref->varp.range)->ranges[range_i].low; range_j < (*pref->varp.range)->ranges[range_i].high; range_j++) {
5987 | dissector_change_uint(port_range_prefs[i].table_name, range_j, handle);
5988 | decode_build_reset_list(port_range_prefs[i].table_name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(range_j)((gpointer) (gulong) (range_j)), NULL((void*)0), NULL((void*)0));
5989 | }
5990 |
5991 | dissector_change_uint(port_range_prefs[i].table_name, (*pref->varp.range)->ranges[range_i].high, handle);
5992 | decode_build_reset_list(port_range_prefs[i].table_name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER((*pref->varp.range)->ranges[range_i].high)((gpointer) (gulong) ((*pref->varp.range)->ranges[range_i ].high)), NULL((void*)0), NULL((void*)0));
5993 | }
5994 | }
5995 | }
5996 | }
5997 |
5998 | return true1;
5999 | }
6000 | }
6001 |
6002 | for (i = 0; i < array_length(tpkt_subdissector_port_prefs)(sizeof (tpkt_subdissector_port_prefs) / sizeof (tpkt_subdissector_port_prefs )[0]); i++)
6003 | {
6004 | if (strcmp(pref_name, tpkt_subdissector_port_prefs[i].pref_name) == 0)
6005 | {
6006 | /* XXX - give an error if it doesn't fit in a unsigned? */
6007 | if (!ws_basestrtou32(value, NULL((void*)0), &uval, tpkt_subdissector_port_prefs[i].base))
6008 | return false0; /* number was bad */
6009 |
6010 | /* If the value is 0 or 102 (default TPKT port), don't add to the Decode As tables */
6011 | if ((uval != 0) && (uval != 102))
6012 | {
6013 | tpkt_handle = find_dissector("tpkt");
6014 | if (tpkt_handle != NULL((void*)0)) {
6015 | dissector_change_uint(tpkt_subdissector_port_prefs[i].table_name, uval, tpkt_handle);
6016 | }
6017 | }
6018 |
6019 | return true1;
6020 | }
6021 | }
6022 |
6023 | for (i = 0; i < array_length(obsolete_prefs)(sizeof (obsolete_prefs) / sizeof (obsolete_prefs)[0]); i++)
6024 | {
6025 | if (strcmp(pref_name, obsolete_prefs[i].pref_name) == 0)
6026 | {
6027 | /* Just ignore the preference */
6028 | return true1;
6029 | }
6030 | }
6031 | return false0;
6032 | }
6033 |
6034 | static prefs_set_pref_e
6035 | set_pref(char *pref_name, const char *value, void *private_data,
6036 | bool_Bool return_range_errors)
6037 | {
6038 | unsigned cval;
6039 | unsigned uval;
6040 | bool_Bool bval;
6041 | int enum_val, ival;
6042 | double fval;
6043 | char *dotp, *last_dotp;
6044 | module_t *module, *containing_module, *target_module;
6045 | pref_t *pref;
6046 | bool_Bool converted_pref = false0;
6047 |
6048 | target_module = (module_t*)private_data;
6049 |
6050 | if (deprecated_heur_dissector_pref(pref_name, value)) {
6051 | /* Handled within deprecated_heur_dissector_pref() if found */
6052 | } else if (deprecated_enable_dissector_pref(pref_name, value)) {
6053 | /* Handled within deprecated_enable_dissector_pref() if found */
6054 | } else if (deprecated_port_pref(pref_name, value)) {
6055 | /* Handled within deprecated_port_pref() if found */
6056 | } else if (strcmp(pref_name, "console.log.level") == 0) {
6057 | /* Handled on the command line within ws_log_parse_args() */
6058 | return PREFS_SET_OK;
6059 | } else {
6060 | /* To which module does this preference belong? */
6061 | module = NULL((void*)0);
6062 | last_dotp = pref_name;
6063 | while (!module) {
6064 | dotp = strchr(last_dotp, '.');
6065 | if (dotp == NULL((void*)0)) {
6066 | /* Either there's no such module, or no module was specified.
6067 | In either case, that means there's no such preference. */
6068 | return PREFS_SET_NO_SUCH_PREF;
6069 | }
6070 | *dotp = '\0'; /* separate module and preference name */
6071 | module = prefs_find_module(pref_name);
6072 |
6073 | /*
6074 | * XXX - "Diameter" rather than "diameter" was used in earlier
6075 | * versions of Wireshark; if we didn't find the module, and its name
6076 | * was "Diameter", look for "diameter" instead.
6077 | *
6078 | * In addition, the BEEP protocol used to be the BXXP protocol,
6079 | * so if we didn't find the module, and its name was "bxxp",
6080 | * look for "beep" instead.
6081 | *
6082 | * Also, the preferences for GTP v0 and v1 were combined under
6083 | * a single "gtp" heading, and the preferences for SMPP were
6084 | * moved to "smpp-gsm-sms" and then moved to "gsm-sms-ud".
6085 | * However, SMPP now has its own preferences, so we just map
6086 | * "smpp-gsm-sms" to "gsm-sms-ud", and then handle SMPP below.
6087 | *
6088 | * We also renamed "dcp" to "dccp", "x.25" to "x25", "x411" to "p1"
6089 | * and "nsip" to "gprs_ns".
6090 | *
6091 | * The SynOptics Network Management Protocol (SONMP) is now known by
6092 | * its modern name, the Nortel Discovery Protocol (NDP).
6093 | */
6094 | if (module == NULL((void*)0)) {
6095 | /*
6096 | * See if there's a backwards-compatibility name
6097 | * that maps to this module.
6098 | */
6099 | module = prefs_find_module_alias(pref_name);
6100 | if (module == NULL((void*)0)) {
6101 | /*
6102 | * There's no alias for the module; see if the
6103 | * module name matches any protocol aliases.
6104 | */
6105 | header_field_info *hfinfo = proto_registrar_get_byalias(pref_name);
6106 | if (hfinfo) {
6107 | module = (module_t *) wmem_tree_lookup_string(prefs_modules, hfinfo->abbrev, WMEM_TREE_STRING_NOCASE0x00000001);
6108 | }
6109 | }
6110 | if (module) {
6111 | converted_pref = true1;
6112 | }
6113 | }
6114 | *dotp = '.'; /* put the preference string back */
6115 | dotp++; /* skip past separator to preference name */
6116 | last_dotp = dotp;
6117 | }
6118 |
6119 | /* The pref is located in the module or a submodule.
6120 | * Assume module, then search for a submodule holding the pref. */
6121 | containing_module = module;
6122 | pref = prefs_find_preference_with_submodule(module, dotp, &containing_module);
6123 |
6124 | if (pref == NULL((void*)0)) {
6125 | /* "gui" prefix was added to column preferences for better organization
6126 | * within the preferences file
6127 | */
6128 | if (module == gui_column_module) {
6129 | /* While this has a subtree, there is no apply callback, so no
6130 | * need to use prefs_find_preference_with_submodule to update
6131 | * containing_module. It would not be useful. */
6132 | pref = prefs_find_preference(module, pref_name);
6133 | }
6134 | else if (strcmp(module->name, "tcp") == 0) {
6135 | /* Handle old names for TCP preferences. */
6136 | if (strcmp(dotp, "dissect_experimental_options_with_magic") == 0)
6137 | pref = prefs_find_preference(module, "dissect_experimental_options_rfc6994");
6138 | } else if (strcmp(module->name, "extcap") == 0) {
6139 | /* Handle the old "sshdump.remotesudo" preference; map it to the new
6140 | "sshdump.remotepriv" preference, and map the boolean values to the
6141 | appropriate strings of the new preference. */
6142 | if (strcmp(dotp, "sshdump.remotesudo") == 0) {
6143 | pref = prefs_find_preference(module, "sshdump.remotepriv");
6144 | if (g_ascii_strcasecmp(value, "true") == 0)
6145 | value = "sudo";
6146 | else
6147 | value = "none";
6148 | }
6149 | }
6150 | if (pref) {
6151 | converted_pref = true1;
6152 | }
6153 | }
6154 | if (pref == NULL((void*)0) ) {
6155 | if (strcmp(module->name, "extcap") == 0 && g_list_length(module->prefs) <= 1) {
6156 | /*
6157 | * Assume that we've skipped extcap preference registration
6158 | * and that only extcap.gui_save_on_start is loaded.
6159 | */
6160 | return PREFS_SET_OK;
6161 | }
6162 | return PREFS_SET_NO_SUCH_PREF; /* no such preference */
6163 | }
6164 |
6165 | if (target_module && target_module != containing_module) {
6166 | /* Ignore */
6167 | return PREFS_SET_OK;
6168 | }
6169 |
6170 | if (pref->obsolete)
6171 | return PREFS_SET_OBSOLETE; /* no such preference any more */
6172 |
6173 | if (converted_pref) {
6174 | ws_warning("Preference \"%s\" has been converted to \"%s.%s\"\n"do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 6176, __func__, "Preference \"%s\" has been converted to \"%s.%s\"\n" "Save your preferences to make this change permanent.", pref_name , module->name ? module->name : module->parent->name , prefs_get_name(pref)); } } while (0)
6175 | "Save your preferences to make this change permanent.",do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 6176, __func__, "Preference \"%s\" has been converted to \"%s.%s\"\n" "Save your preferences to make this change permanent.", pref_name , module->name ? module->name : module->parent->name , prefs_get_name(pref)); } } while (0)
6176 | pref_name, module->name ? module->name : module->parent->name, prefs_get_name(pref))do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 6176, __func__, "Preference \"%s\" has been converted to \"%s.%s\"\n" "Save your preferences to make this change permanent.", pref_name , module->name ? module->name : module->parent->name , prefs_get_name(pref)); } } while (0);
6177 | }
6178 |
6179 | switch (pref->type) {
6180 |
6181 | case PREF_UINT:
6182 | if (!ws_basestrtou32(value, NULL((void*)0), &uval, pref->info.base))
6183 | return PREFS_SET_SYNTAX_ERR; /* number was bad */
6184 | if (*pref->varp.uint != uval) {
6185 | containing_module->prefs_changed_flags |= prefs_get_effect_flags(pref);
6186 | *pref->varp.uint = uval;
6187 | }
6188 | break;
6189 |
6190 | case PREF_INT:
6191 | if (!ws_strtoi32(value, NULL((void*)0), &ival))
6192 | return PREFS_SET_SYNTAX_ERR; /* number was bad */
6193 | if (*pref->varp.intp != ival) {
6194 | containing_module->prefs_changed_flags |= prefs_get_effect_flags(pref);
6195 | *pref->varp.intp = ival;
6196 | }
6197 | break;
6198 |
6199 | case PREF_FLOAT:
6200 | fval = g_ascii_strtod(value, NULL((void*)0));
6201 | if (errno(*__errno_location ()) == ERANGE34)
6202 | return PREFS_SET_SYNTAX_ERR; /* number was bad */
6203 |
6204 | if (*pref->varp.floatp != fval) {
6205 | containing_module->prefs_changed_flags |= prefs_get_effect_flags(pref);
6206 | *pref->varp.floatp = fval;
6207 | }
6208 | break;
6209 |
6210 | case PREF_BOOL:
6211 | /* XXX - give an error if it's neither "true" nor "false"? */
6212 | if (g_ascii_strcasecmp(value, "true") == 0)
6213 | bval = true1;
6214 | else
6215 | bval = false0;
6216 | if (*pref->varp.boolp != bval) {
6217 | containing_module->prefs_changed_flags |= prefs_get_effect_flags(pref);
6218 | *pref->varp.boolp = bval;
6219 | }
6220 | break;
6221 |
6222 | case PREF_ENUM:
6223 | /* XXX - give an error if it doesn't match? */
6224 | enum_val = find_val_for_string(value, pref->info.enum_info.enumvals,
6225 | *pref->varp.enump);
6226 | if (*pref->varp.enump != enum_val) {
6227 | containing_module->prefs_changed_flags |= prefs_get_effect_flags(pref);
6228 | *pref->varp.enump = enum_val;
6229 | }
6230 | break;
6231 |
6232 | case PREF_STRING:
6233 | case PREF_SAVE_FILENAME:
6234 | case PREF_OPEN_FILENAME:
6235 | case PREF_DIRNAME:
6236 | case PREF_DISSECTOR:
6237 | containing_module->prefs_changed_flags |= prefs_set_string_value(pref, value, pref_current);
6238 | break;
6239 |
6240 | case PREF_PASSWORD:
6241 | /* Read value is every time empty */
6242 | containing_module->prefs_changed_flags |= prefs_set_string_value(pref, "", pref_current);
6243 | break;
6244 |
6245 | case PREF_RANGE:
6246 | {
6247 | if (!prefs_set_range_value_work(pref, value, return_range_errors,
6248 | &containing_module->prefs_changed_flags))
6249 | return PREFS_SET_SYNTAX_ERR; /* number was bad */
6250 | break;
6251 | }
6252 | case PREF_DECODE_AS_RANGE:
6253 | {
6254 | /* This is for backwards compatibility in case any of the preferences
6255 | that shared the "Decode As" preference name and used to be PREF_RANGE
6256 | are now applied directly to the Decode As functionality */
6257 | range_t *newrange;
6258 | dissector_table_t sub_dissectors;
6259 | dissector_handle_t handle;
6260 | uint32_t i, j;
6261 |
6262 | if (range_convert_str_work(pref->scope, &newrange, value, pref->info.max_value,
6263 | return_range_errors) != CVT_NO_ERROR) {
6264 | return PREFS_SET_SYNTAX_ERR; /* number was bad */
6265 | }
6266 |
6267 | if (!ranges_are_equal(*pref->varp.range, newrange)) {
6268 | wmem_free(pref->scope, *pref->varp.range);
6269 | *pref->varp.range = newrange;
6270 | containing_module->prefs_changed_flags |= prefs_get_effect_flags(pref);
6271 |
6272 | const char* table_name = prefs_get_dissector_table(pref);
6273 | sub_dissectors = find_dissector_table(table_name);
6274 | if (sub_dissectors != NULL((void*)0)) {
6275 | handle = dissector_table_get_dissector_handle(sub_dissectors, module->title);
6276 | if (handle != NULL((void*)0)) {
6277 | /* Delete all of the old values from the dissector table */
6278 | for (i = 0; i < (*pref->varp.range)->nranges; i++) {
6279 | for (j = (*pref->varp.range)->ranges[i].low; j < (*pref->varp.range)->ranges[i].high; j++) {
6280 | dissector_delete_uint(table_name, j, handle);
6281 | decode_build_reset_list(table_name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(j)((gpointer) (gulong) (j)), NULL((void*)0), NULL((void*)0));
6282 | }
6283 |
6284 | dissector_delete_uint(table_name, (*pref->varp.range)->ranges[i].high, handle);
6285 | decode_build_reset_list(table_name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER((*pref->varp.range)->ranges[i].high)((gpointer) (gulong) ((*pref->varp.range)->ranges[i].high )), NULL((void*)0), NULL((void*)0));
6286 | }
6287 |
6288 | /* Add new values to the dissector table */
6289 | for (i = 0; i < newrange->nranges; i++) {
6290 | for (j = newrange->ranges[i].low; j < newrange->ranges[i].high; j++) {
6291 | dissector_change_uint(table_name, j, handle);
6292 | decode_build_reset_list(table_name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(j)((gpointer) (gulong) (j)), NULL((void*)0), NULL((void*)0));
6293 | }
6294 |
6295 | dissector_change_uint(table_name, newrange->ranges[i].high, handle);
6296 | decode_build_reset_list(table_name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(newrange->ranges[i].high)((gpointer) (gulong) (newrange->ranges[i].high)), NULL((void*)0), NULL((void*)0));
6297 | }
6298 |
6299 | /* XXX - Do we save the decode_as_entries file here? */
6300 | }
6301 | }
6302 | } else {
6303 | wmem_free(pref->scope, newrange);
6304 | }
6305 | break;
6306 | }
6307 |
6308 | case PREF_COLOR:
6309 | {
6310 | if (!ws_hexstrtou32(value, NULL((void*)0), &cval))
6311 | return PREFS_SET_SYNTAX_ERR; /* number was bad */
6312 | if ((pref->varp.colorp->red != RED_COMPONENT(cval)(uint16_t) (((((cval) >> 16) & 0xff) * 65535 / 255) )) ||
6313 | (pref->varp.colorp->green != GREEN_COMPONENT(cval)(uint16_t) (((((cval) >> 8) & 0xff) * 65535 / 255))) ||
6314 | (pref->varp.colorp->blue != BLUE_COMPONENT(cval)(uint16_t) ( (((cval) & 0xff) * 65535 / 255)))) {
6315 | containing_module->prefs_changed_flags |= prefs_get_effect_flags(pref);
6316 | pref->varp.colorp->red = RED_COMPONENT(cval)(uint16_t) (((((cval) >> 16) & 0xff) * 65535 / 255) );
6317 | pref->varp.colorp->green = GREEN_COMPONENT(cval)(uint16_t) (((((cval) >> 8) & 0xff) * 65535 / 255));
6318 | pref->varp.colorp->blue = BLUE_COMPONENT(cval)(uint16_t) ( (((cval) & 0xff) * 65535 / 255));
6319 | }
6320 | break;
6321 | }
6322 |
6323 | case PREF_CUSTOM:
6324 | return pref->custom_cbs.set_cb(pref, value, &containing_module->prefs_changed_flags);
6325 |
6326 | case PREF_STATIC_TEXT:
6327 | case PREF_UAT:
6328 | break;
6329 |
6330 | case PREF_PROTO_TCP_SNDAMB_ENUM:
6331 | {
6332 | /* There's no point in setting the TCP sequence override
6333 | * value from the command line, because the pref is different
6334 | * for each frame and reset to the default (0) for each new
6335 | * file.
6336 | */
6337 | break;
6338 | }
6339 | }
6340 | }
6341 |
6342 | return PREFS_SET_OK;
6343 | }
6344 |
6345 | typedef struct {
6346 | FILE *pf;
6347 | bool_Bool is_gui_module;
6348 | } write_gui_pref_arg_t;
6349 |
6350 | const char *
6351 | prefs_pref_type_name(pref_t *pref)
6352 | {
6353 | const char *type_name = "[Unknown]";
6354 |
6355 | if (!pref) {
6356 | return type_name; /* ...or maybe assert? */
6357 | }
6358 |
6359 | if (pref->obsolete) {
6360 | type_name = "Obsolete";
6361 | } else {
6362 | switch (pref->type) {
6363 |
6364 | case PREF_UINT:
6365 | switch (pref->info.base) {
6366 |
6367 | case 10:
6368 | type_name = "Decimal";
6369 | break;
6370 |
6371 | case 8:
6372 | type_name = "Octal";
6373 | break;
6374 |
6375 | case 16:
6376 | type_name = "Hexadecimal";
6377 | break;
6378 | }
6379 | break;
6380 |
6381 | case PREF_INT:
6382 | type_name = "Integer";
6383 | break;
6384 |
6385 | case PREF_FLOAT:
6386 | type_name = "Float";
6387 | break;
6388 |
6389 | case PREF_BOOL:
6390 | type_name = "Boolean";
6391 | break;
6392 |
6393 | case PREF_ENUM:
6394 | case PREF_PROTO_TCP_SNDAMB_ENUM:
6395 | type_name = "Choice";
6396 | break;
6397 |
6398 | case PREF_STRING:
6399 | type_name = "String";
6400 | break;
6401 |
6402 | case PREF_SAVE_FILENAME:
6403 | case PREF_OPEN_FILENAME:
6404 | type_name = "Filename";
6405 | break;
6406 |
6407 | case PREF_DIRNAME:
6408 | type_name = "Directory";
6409 | break;
6410 |
6411 | case PREF_RANGE:
6412 | type_name = "Range";
6413 | break;
6414 |
6415 | case PREF_COLOR:
6416 | type_name = "Color";
6417 | break;
6418 |
6419 | case PREF_CUSTOM:
6420 | if (pref->custom_cbs.type_name_cb)
6421 | return pref->custom_cbs.type_name_cb();
6422 | type_name = "Custom";
6423 | break;
6424 |
6425 | case PREF_DECODE_AS_RANGE:
6426 | type_name = "Range (for Decode As)";
6427 | break;
6428 |
6429 | case PREF_STATIC_TEXT:
6430 | type_name = "Static text";
6431 | break;
6432 |
6433 | case PREF_UAT:
6434 | type_name = "UAT";
6435 | break;
6436 |
6437 | case PREF_PASSWORD:
6438 | type_name = "Password";
6439 | break;
6440 |
6441 | case PREF_DISSECTOR:
6442 | type_name = "Dissector";
6443 | break;
6444 | }
6445 | }
6446 |
6447 | return type_name;
6448 | }
6449 |
6450 | unsigned int
6451 | prefs_get_effect_flags(pref_t *pref)
6452 | {
6453 | if (pref == NULL((void*)0))
6454 | return 0;
6455 |
6456 | return pref->effect_flags;
6457 | }
6458 |
6459 | void
6460 | prefs_set_effect_flags(pref_t *pref, unsigned int flags)
6461 | {
6462 | if (pref != NULL((void*)0)) {
6463 | if (flags == 0) {
6464 | ws_error("Setting \"%s\" preference effect flags to 0", pref->name)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 6464 , __func__, "Setting \"%s\" preference effect flags to 0", pref ->name);
6465 | }
6466 | pref->effect_flags = flags;
6467 | }
6468 | }
6469 |
6470 | void
6471 | prefs_set_effect_flags_by_name(module_t * module, const char *pref, unsigned int flags)
6472 | {
6473 | prefs_set_effect_flags(prefs_find_preference(module, pref), flags);
6474 | }
6475 |
6476 | unsigned int
6477 | prefs_get_module_effect_flags(module_t * module)
6478 | {
6479 | if (module == NULL((void*)0))
6480 | return 0;
6481 |
6482 | return module->effect_flags;
6483 | }
6484 |
6485 | void
6486 | prefs_set_module_effect_flags(module_t * module, unsigned int flags)
6487 | {
6488 | if (module != NULL((void*)0)) {
6489 | if (flags == 0) {
6490 | ws_error("Setting module \"%s\" preference effect flags to 0", module->name)ws_log_fatal_full("Epan", LOG_LEVEL_ERROR, "epan/prefs.c", 6490 , __func__, "Setting module \"%s\" preference effect flags to 0" , module->name);
6491 | }
6492 | module->effect_flags = flags;
6493 | }
6494 | }
6495 |
6496 | char *
6497 | prefs_pref_type_description(pref_t *pref)
6498 | {
6499 | const char *type_desc = "An unknown preference type";
6500 |
6501 | if (!pref) {
6502 | return ws_strdup_printf("%s.", type_desc)wmem_strdup_printf(((void*)0), "%s.", type_desc); /* ...or maybe assert? */
6503 | }
6504 |
6505 | if (pref->obsolete) {
6506 | type_desc = "An obsolete preference";
6507 | } else {
6508 | switch (pref->type) {
6509 |
6510 | case PREF_UINT:
6511 | switch (pref->info.base) {
6512 |
6513 | case 10:
6514 | type_desc = "A decimal number";
6515 | break;
6516 |
6517 | case 8:
6518 | type_desc = "An octal number";
6519 | break;
6520 |
6521 | case 16:
6522 | type_desc = "A hexadecimal number";
6523 | break;
6524 | }
6525 | break;
6526 |
6527 | case PREF_INT:
6528 | type_desc = "A decimal number";
6529 | break;
6530 |
6531 | case PREF_FLOAT:
6532 | type_desc = "A floating point number";
6533 | break;
6534 |
6535 | case PREF_BOOL:
6536 | type_desc = "true or false (case-insensitive)";
6537 | break;
6538 |
6539 | case PREF_ENUM:
6540 | case PREF_PROTO_TCP_SNDAMB_ENUM:
6541 | {
6542 | const enum_val_t *enum_valp = pref->info.enum_info.enumvals;
6543 | GString *enum_str = g_string_new("One of: ");
6544 | GString *desc_str = g_string_new("\nEquivalently, one of: ");
6545 | bool_Bool distinct = false0;
6546 | while (enum_valp->name != NULL((void*)0)) {
6547 | g_string_append(enum_str, enum_valp->name)(__builtin_constant_p (enum_valp->name) ? __extension__ ({ const char * const __val = (enum_valp->name); g_string_append_len_inline (enum_str, __val, (__val != ((void*)0)) ? (gssize) strlen (( (__val) + !(__val))) : (gssize) -1); }) : g_string_append_len_inline (enum_str, enum_valp->name, (gssize) -1));
6548 | g_string_append(desc_str, enum_valp->description)(__builtin_constant_p (enum_valp->description) ? __extension__ ({ const char * const __val = (enum_valp->description); g_string_append_len_inline (desc_str, __val, (__val != ((void*)0)) ? (gssize) strlen (( (__val) + !(__val))) : (gssize) -1); }) : g_string_append_len_inline (desc_str, enum_valp->description, (gssize) -1));
6549 | if (g_strcmp0(enum_valp->name, enum_valp->description) != 0) {
6550 | distinct = true1;
6551 | }
6552 | enum_valp++;
6553 | if (enum_valp->name != NULL((void*)0)) {
6554 | g_string_append(enum_str, ", ")(__builtin_constant_p (", ") ? __extension__ ({ const char * const __val = (", "); g_string_append_len_inline (enum_str, __val, (__val != ((void*)0)) ? (gssize) strlen (((__val) + !(__val) )) : (gssize) -1); }) : g_string_append_len_inline (enum_str, ", ", (gssize) -1));
6555 | g_string_append(desc_str, ", ")(__builtin_constant_p (", ") ? __extension__ ({ const char * const __val = (", "); g_string_append_len_inline (desc_str, __val, (__val != ((void*)0)) ? (gssize) strlen (((__val) + !(__val) )) : (gssize) -1); }) : g_string_append_len_inline (desc_str, ", ", (gssize) -1));
6556 | }
6557 | }
6558 | if (distinct) {
6559 | g_string_append(enum_str, desc_str->str)(__builtin_constant_p (desc_str->str) ? __extension__ ({ const char * const __val = (desc_str->str); g_string_append_len_inline (enum_str, __val, (__val != ((void*)0)) ? (gssize) strlen (( (__val) + !(__val))) : (gssize) -1); }) : g_string_append_len_inline (enum_str, desc_str->str, (gssize) -1));
6560 | }
6561 | g_string_free(desc_str, TRUE)(__builtin_constant_p ((!(0))) ? (((!(0))) ? (g_string_free) ( (desc_str), ((!(0)))) : g_string_free_and_steal (desc_str)) : (g_string_free) ((desc_str), ((!(0)))));
6562 | g_string_append(enum_str, "\n(case-insensitive).")(__builtin_constant_p ("\n(case-insensitive).") ? __extension__ ({ const char * const __val = ("\n(case-insensitive)."); g_string_append_len_inline (enum_str, __val, (__val != ((void*)0)) ? (gssize) strlen (( (__val) + !(__val))) : (gssize) -1); }) : g_string_append_len_inline (enum_str, "\n(case-insensitive).", (gssize) -1));
6563 | return g_string_free(enum_str, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((enum_str ), ((0))) : g_string_free_and_steal (enum_str)) : (g_string_free ) ((enum_str), ((0))));
6564 | }
6565 |
6566 | case PREF_STRING:
6567 | type_desc = "A string";
6568 | break;
6569 |
6570 | case PREF_SAVE_FILENAME:
6571 | case PREF_OPEN_FILENAME:
6572 | type_desc = "A path to a file";
6573 | break;
6574 |
6575 | case PREF_DIRNAME:
6576 | type_desc = "A path to a directory";
6577 | break;
6578 |
6579 | case PREF_RANGE:
6580 | {
6581 | type_desc = "A string denoting an positive integer range (e.g., \"1-20,30-40\")";
6582 | break;
6583 | }
6584 |
6585 | case PREF_COLOR:
6586 | {
6587 | type_desc = "A six-digit hexadecimal RGB color triplet (e.g. fce94f)";
6588 | break;
6589 | }
6590 |
6591 | case PREF_CUSTOM:
6592 | if (pref->custom_cbs.type_description_cb)
6593 | return pref->custom_cbs.type_description_cb();
6594 | type_desc = "A custom value";
6595 | break;
6596 |
6597 | case PREF_DECODE_AS_RANGE:
6598 | type_desc = "A string denoting an positive integer range for Decode As";
6599 | break;
6600 |
6601 | case PREF_STATIC_TEXT:
6602 | type_desc = "[Static text]";
6603 | break;
6604 |
6605 | case PREF_UAT:
6606 | type_desc = "Configuration data stored in its own file";
6607 | break;
6608 |
6609 | case PREF_PASSWORD:
6610 | type_desc = "Password (never stored on disk)";
6611 | break;
6612 |
6613 | case PREF_DISSECTOR:
6614 | type_desc = "A dissector name";
6615 | break;
6616 |
6617 | default:
6618 | break;
6619 | }
6620 | }
6621 |
6622 | return g_strdup(type_desc)g_strdup_inline (type_desc);
6623 | }
6624 |
6625 | bool_Bool
6626 | prefs_pref_is_default(pref_t *pref)
6627 | {
6628 | if (!pref) return false0;
6629 |
6630 | if (pref->obsolete) {
6631 | return false0;
6632 | }
6633 |
6634 | switch (pref->type) {
6635 |
6636 | case PREF_UINT:
6637 | if (pref->default_val.uint == *pref->varp.uint)
6638 | return true1;
6639 | break;
6640 |
6641 | case PREF_INT:
6642 | if (pref->default_val.intval == *pref->varp.intp)
6643 | return true1;
6644 | break;
6645 |
6646 | case PREF_FLOAT:
6647 | if (pref->default_val.floatval == *pref->varp.floatp)
6648 | return true1;
6649 | break;
6650 |
6651 | case PREF_BOOL:
6652 | if (pref->default_val.boolval == *pref->varp.boolp)
6653 | return true1;
6654 | break;
6655 |
6656 | case PREF_ENUM:
6657 | case PREF_PROTO_TCP_SNDAMB_ENUM:
6658 | if (pref->default_val.enumval == *pref->varp.enump)
6659 | return true1;
6660 | break;
6661 |
6662 | case PREF_STRING:
6663 | case PREF_SAVE_FILENAME:
6664 | case PREF_OPEN_FILENAME:
6665 | case PREF_DIRNAME:
6666 | case PREF_PASSWORD:
6667 | case PREF_DISSECTOR:
6668 | if (!(g_strcmp0(pref->default_val.string, *pref->varp.string)))
6669 | return true1;
6670 | break;
6671 |
6672 | case PREF_DECODE_AS_RANGE:
6673 | case PREF_RANGE:
6674 | {
6675 | if ((ranges_are_equal(pref->default_val.range, *pref->varp.range)))
6676 | return true1;
6677 | break;
6678 | }
6679 |
6680 | case PREF_COLOR:
6681 | {
6682 | if ((pref->default_val.color.red == pref->varp.colorp->red) &&
6683 | (pref->default_val.color.green == pref->varp.colorp->green) &&
6684 | (pref->default_val.color.blue == pref->varp.colorp->blue))
6685 | return true1;
6686 | break;
6687 | }
6688 |
6689 | case PREF_CUSTOM:
6690 | return pref->custom_cbs.is_default_cb(pref);
6691 |
6692 | case PREF_STATIC_TEXT:
6693 | case PREF_UAT:
6694 | return false0;
6695 | /* ws_assert_not_reached(); */
6696 | break;
6697 | }
6698 |
6699 | return false0;
6700 | }
6701 |
6702 | char *
6703 | prefs_pref_to_str(pref_t *pref, pref_source_t source)
6704 | {
6705 | const char *pref_text = "[Unknown]";
6706 | void *valp; /* pointer to preference value */
6707 | color_t *pref_color;
6708 | char *tmp_value, *ret_value;
6709 |
6710 | if (!pref) {
6711 | return g_strdup(pref_text)g_strdup_inline (pref_text);
6712 | }
6713 |
6714 | switch (source) {
6715 | case pref_default:
6716 | valp = &pref->default_val;
6717 | /* valp = &boolval, &enumval, etc. are implied by union property */
6718 | pref_color = &pref->default_val.color;
6719 | break;
6720 | case pref_stashed:
6721 | valp = &pref->stashed_val;
6722 | /* valp = &boolval, &enumval, etc. are implied by union property */
6723 | pref_color = &pref->stashed_val.color;
6724 | break;
6725 | case pref_current:
6726 | valp = pref->varp.uint;
6727 | /* valp = boolval, enumval, etc. are implied by union property */
6728 | pref_color = pref->varp.colorp;
6729 | break;
6730 | default:
6731 | return g_strdup(pref_text)g_strdup_inline (pref_text);
6732 | }
6733 |
6734 | if (pref->obsolete) {
6735 | pref_text = "[Obsolete]";
6736 | } else {
6737 | switch (pref->type) {
6738 |
6739 | case PREF_UINT:
6740 | {
6741 | unsigned pref_uint = *(unsigned *) valp;
6742 | switch (pref->info.base) {
6743 |
6744 | case 10:
6745 | return ws_strdup_printf("%u", pref_uint)wmem_strdup_printf(((void*)0), "%u", pref_uint);
6746 |
6747 | case 8:
6748 | return ws_strdup_printf("%#o", pref_uint)wmem_strdup_printf(((void*)0), "%#o", pref_uint);
6749 |
6750 | case 16:
6751 | return ws_strdup_printf("%#x", pref_uint)wmem_strdup_printf(((void*)0), "%#x", pref_uint);
6752 | }
6753 | break;
6754 | }
6755 | case PREF_INT:
6756 | return ws_strdup_printf("%d", *(int*)valp)wmem_strdup_printf(((void*)0), "%d", *(int*)valp);
6757 |
6758 | case PREF_FLOAT:
6759 | return ws_strdup_printf("%.*f", pref->info.base, *(double*)valp)wmem_strdup_printf(((void*)0), "%.*f", pref->info.base, *( double*)valp);
6760 |
6761 | case PREF_BOOL:
6762 | return g_strdup((*(bool *) valp) ? "TRUE" : "FALSE")g_strdup_inline ((*(_Bool *) valp) ? "TRUE" : "FALSE");
6763 |
6764 | case PREF_ENUM:
6765 | case PREF_PROTO_TCP_SNDAMB_ENUM:
6766 | {
6767 | int pref_enumval = *(int *) valp;
6768 | const enum_val_t *enum_valp = pref->info.enum_info.enumvals;
6769 | /*
6770 | * TODO - We write the "description" value, because the "name" values
6771 | * weren't validated to be command line friendly until 5.0, and a few
6772 | * of them had to be changed. This allows older versions of Wireshark
6773 | * to read preferences that they supported, as we supported either
6774 | * the short name or the description when reading the preference files
6775 | * or an "-o" option. Once 5.0 is the oldest supported version, switch
6776 | * to writing the name below.
6777 | */
6778 | while (enum_valp->name != NULL((void*)0)) {
6779 | if (enum_valp->value == pref_enumval)
6780 | return g_strdup(enum_valp->description)g_strdup_inline (enum_valp->description);
6781 | enum_valp++;
6782 | }
6783 | break;
6784 | }
6785 |
6786 | case PREF_STRING:
6787 | case PREF_SAVE_FILENAME:
6788 | case PREF_OPEN_FILENAME:
6789 | case PREF_DIRNAME:
6790 | case PREF_PASSWORD:
6791 | case PREF_DISSECTOR:
6792 | return prefs_sanitize_string(*(const char **) valp);
6793 |
6794 | case PREF_DECODE_AS_RANGE:
6795 | case PREF_RANGE:
6796 | /* Convert wmem to g_alloc memory */
6797 | tmp_value = range_convert_range(NULL((void*)0), *(range_t **) valp);
6798 | ret_value = g_strdup(tmp_value)g_strdup_inline (tmp_value);
6799 | wmem_free(NULL((void*)0), tmp_value);
6800 | return ret_value;
6801 |
6802 | case PREF_COLOR:
6803 | return ws_strdup_printf("%02x%02x%02x",wmem_strdup_printf(((void*)0), "%02x%02x%02x", (pref_color-> red * 255 / 65535), (pref_color->green * 255 / 65535), (pref_color ->blue * 255 / 65535))
6804 | (pref_color->red * 255 / 65535),wmem_strdup_printf(((void*)0), "%02x%02x%02x", (pref_color-> red * 255 / 65535), (pref_color->green * 255 / 65535), (pref_color ->blue * 255 / 65535))
6805 | (pref_color->green * 255 / 65535),wmem_strdup_printf(((void*)0), "%02x%02x%02x", (pref_color-> red * 255 / 65535), (pref_color->green * 255 / 65535), (pref_color ->blue * 255 / 65535))
6806 | (pref_color->blue * 255 / 65535))wmem_strdup_printf(((void*)0), "%02x%02x%02x", (pref_color-> red * 255 / 65535), (pref_color->green * 255 / 65535), (pref_color ->blue * 255 / 65535));
6807 |
6808 | case PREF_CUSTOM:
6809 | if (pref->custom_cbs.to_str_cb)
6810 | return pref->custom_cbs.to_str_cb(pref, source == pref_default ? true1 : false0);
6811 | pref_text = "[Custom]";
6812 | break;
6813 |
6814 | case PREF_STATIC_TEXT:
6815 | pref_text = "[Static text]";
6816 | break;
6817 |
6818 | case PREF_UAT:
6819 | {
6820 | uat_t *uat = pref->varp.uat;
6821 | if (uat && uat->filename)
6822 | return ws_strdup_printf("[Managed in the file \"%s\"]", uat->filename)wmem_strdup_printf(((void*)0), "[Managed in the file \"%s\"]" , uat->filename);
6823 | else
6824 | pref_text = "[Managed in an unknown file]";
6825 | break;
6826 | }
6827 |
6828 | default:
6829 | break;
6830 | }
6831 | }
6832 |
6833 | return g_strdup(pref_text)g_strdup_inline (pref_text);
6834 | }
6835 |
6836 | /*
6837 | * Write out a single dissector preference.
6838 | */
6839 | void
6840 | pref_write_individual(void *data, void *user_data)
6841 | {
6842 | pref_t *pref = (pref_t *)data;
6843 | write_pref_arg_t *arg = (write_pref_arg_t *)user_data;
6844 | char **desc_lines;
6845 | int i;
6846 |
6847 | if (!pref || pref->obsolete) {
6848 | /*
6849 | * This preference is no longer supported; it's not a
6850 | * real preference, so we don't write it out (i.e., we
6851 | * treat it as if it weren't found in the list of
6852 | * preferences, and we weren't called in the first place).
6853 | */
6854 | return;
6855 | }
6856 |
6857 | switch (pref->type) {
6858 |
6859 | case PREF_STATIC_TEXT:
6860 | case PREF_UAT:
6861 | /* Nothing to do; don't bother printing the description */
6862 | return;
6863 | case PREF_DECODE_AS_RANGE:
6864 | /* Data is saved through Decode As mechanism and not part of preferences file */
6865 | return;
6866 | case PREF_PROTO_TCP_SNDAMB_ENUM:
6867 | /* Not written to the preference file because the override is only
6868 | * for the lifetime of the capture file and there is no single
6869 | * value to write.
6870 | */
6871 | return;
6872 | default:
6873 | break;
6874 | }
6875 |
6876 | if (pref->type != PREF_CUSTOM || pref->custom_cbs.type_name_cb() != NULL((void*)0)) {
6877 | /*
6878 | * The prefix will either be the module name or the parent
6879 | * name if it's a subtree
6880 | */
6881 | const char *name_prefix = (arg->module->name != NULL((void*)0)) ? arg->module->name : arg->module->parent->name;
6882 | char *type_desc, *pref_text;
6883 | const char * def_prefix = prefs_pref_is_default(pref) ? "#" : "";
6884 |
6885 | if (pref->type == PREF_CUSTOM)
6886 | fprintf(arg->pf, "\n# %s", pref->custom_cbs.type_name_cb());
6887 | fprintf(arg->pf, "\n");
6888 | if (pref->description &&
6889 | (g_ascii_strncasecmp(pref->description,"", 2) != 0)) {
6890 | if (pref->type != PREF_CUSTOM) {
6891 | /* We get duplicate lines otherwise. */
6892 |
6893 | desc_lines = g_strsplit(pref->description, "\n", 0);
6894 | for (i = 0; desc_lines[i] != NULL((void*)0); ++i) {
6895 | fprintf(arg->pf, "# %s\n", desc_lines[i]);
6896 | }
6897 | g_strfreev(desc_lines);
6898 | }
6899 | } else {
6900 | fprintf(arg->pf, "# No description\n");
6901 | }
6902 |
6903 | type_desc = prefs_pref_type_description(pref);
6904 | desc_lines = g_strsplit(type_desc, "\n", 0);
6905 | for (i = 0; desc_lines[i] != NULL((void*)0); ++i) {
6906 | fprintf(arg->pf, "# %s\n", desc_lines[i]);
6907 | }
6908 | g_strfreev(desc_lines);
6909 | g_free(type_desc);
6910 |
6911 | pref_text = prefs_pref_to_str(pref, pref_current);
6912 | fprintf(arg->pf, "%s%s.%s: ", def_prefix, name_prefix, pref->name);
6913 | if (pref->type != PREF_PASSWORD)
6914 | {
6915 | desc_lines = g_strsplit(pref_text, "\n", 0);
6916 | for (i = 0; desc_lines[i] != NULL((void*)0); ++i) {
6917 | fprintf(arg->pf, "%s%s\n", i == 0 ? "" : def_prefix, desc_lines[i]);
6918 | }
6919 | if (i == 0)
6920 | fprintf(arg->pf, "\n");
6921 | g_strfreev(desc_lines);
6922 | } else {
6923 | /* We never store password value */
6924 | fprintf(arg->pf, "\n");
6925 | }
6926 | g_free(pref_text);
6927 | }
6928 |
6929 | }
6930 |
6931 | static void
6932 | count_non_uat_pref(void *data, void *user_data)
6933 | {
6934 | pref_t *pref = (pref_t *)data;
6935 | int *arg = (int *)user_data;
6936 |
6937 | switch (pref->type)
6938 | {
6939 | case PREF_UAT:
6940 | case PREF_DECODE_AS_RANGE:
6941 | case PREF_PROTO_TCP_SNDAMB_ENUM:
6942 | //These types are not written in preference file
6943 | break;
6944 | default:
6945 | (*arg)++;
6946 | break;
6947 | }
6948 | }
6949 |
6950 | int
6951 | prefs_num_non_uat(module_t *module)
6952 | {
6953 | int num = 0;
6954 |
6955 | g_list_foreach(module->prefs, count_non_uat_pref, &num);
6956 |
6957 | return num;
6958 | }
6959 |
6960 | /*
6961 | * Write out all preferences for a module.
6962 | */
6963 | static unsigned
6964 | write_module_prefs(module_t *module, void *user_data)
6965 | {
6966 | write_gui_pref_arg_t *gui_pref_arg = (write_gui_pref_arg_t*)user_data;
6967 | write_pref_arg_t arg;
6968 |
6969 | /* The GUI module needs to be explicitly called out so it
6970 | can be written out of order */
6971 | if ((module == gui_module) && (gui_pref_arg->is_gui_module != true1))
6972 | return 0;
6973 |
6974 | /* Write a header for the main modules and GUI sub-modules */
6975 | if (((module->parent == NULL((void*)0)) || (module->parent == gui_module)) &&
6976 | ((prefs_module_has_submodules(module)) ||
6977 | (prefs_num_non_uat(module) > 0) ||
6978 | (module->name == NULL((void*)0)))) {
6979 | if ((module->name == NULL((void*)0)) && (module->parent != NULL((void*)0))) {
6980 | fprintf(gui_pref_arg->pf, "\n####### %s: %s ########\n", module->parent->title, module->title);
6981 | } else {
6982 | fprintf(gui_pref_arg->pf, "\n####### %s ########\n", module->title);
6983 | }
6984 | }
6985 |
6986 | arg.module = module;
6987 | arg.pf = gui_pref_arg->pf;
6988 | g_list_foreach(arg.module->prefs, pref_write_individual, &arg);
6989 |
6990 | if (prefs_module_has_submodules(module))
6991 | return prefs_modules_foreach_submodules(module->submodules, write_module_prefs, user_data);
6992 |
6993 | return 0;
6994 | }
6995 |
6996 | #ifdef _WIN32
6997 | static void
6998 | write_registry(void)
6999 | {
7000 | HKEY hTestKey;
7001 | DWORD data;
7002 | DWORD data_size;
7003 | DWORD ret;
7004 |
7005 | ret = RegCreateKeyExA(HKEY_CURRENT_USER, REG_HKCU_WIRESHARK_KEY"Software\\Wireshark", 0, NULL((void*)0),
7006 | REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL((void*)0),
7007 | &hTestKey, NULL((void*)0));
7008 | if (ret != ERROR_SUCCESS) {
7009 | ws_noisy("Cannot open HKCU "REG_HKCU_WIRESHARK_KEY": 0x%lx", ret)do { if (1) { ws_log_full("Epan", LOG_LEVEL_NOISY, "epan/prefs.c" , 7009, __func__, "Cannot open HKCU ""Software\\Wireshark"": 0x%lx" , ret); } } while (0);
7010 | return;
7011 | }
7012 |
7013 | data = ws_log_console_open;
7014 | data_size = sizeof(DWORD);
7015 | ret = RegSetValueExA(hTestKey, LOG_HKCU_CONSOLE_OPEN"ConsoleOpen", 0, REG_DWORD, (const BYTE *)&data, data_size);
7016 | if (ret == ERROR_SUCCESS) {
7017 | ws_noisy("Wrote "LOG_HKCU_CONSOLE_OPEN" to Windows registry: 0x%lu", data)do { if (1) { ws_log_full("Epan", LOG_LEVEL_NOISY, "epan/prefs.c" , 7017, __func__, "Wrote ""ConsoleOpen"" to Windows registry: 0x%lu" , data); } } while (0);
7018 | }
7019 | else {
7020 | ws_noisy("Error writing registry key "LOG_HKCU_CONSOLE_OPEN": 0x%lx", ret)do { if (1) { ws_log_full("Epan", LOG_LEVEL_NOISY, "epan/prefs.c" , 7020, __func__, "Error writing registry key ""ConsoleOpen"": 0x%lx" , ret); } } while (0);
7021 | }
7022 |
7023 | RegCloseKey(hTestKey);
7024 | }
7025 | #endif
7026 |
7027 | /* Write out "prefs" to the user's preferences file, and return 0.
7028 |
7029 | If the preferences file path is NULL, write to stdout.
7030 |
7031 | If we got an error, stuff a pointer to the path of the preferences file
7032 | into "*pf_path_return", and return the errno. */
7033 | int
7034 | write_prefs(const char* app_env_var_prefix, char **pf_path_return)
7035 | {
7036 | char *pf_path;
7037 | FILE *pf;
7038 | write_gui_pref_arg_t write_gui_pref_info;
7039 |
7040 | #ifdef _WIN32
7041 | write_registry();
7042 | #endif
7043 |
7044 | /* To do:
7045 | * - Split output lines longer than MAX_VAL_LEN
7046 | * - Create a function for the preference directory check/creation
7047 | * so that duplication can be avoided with filter.c
7048 | */
7049 |
7050 | if (pf_path_return != NULL((void*)0)) {
7051 | pf_path = get_persconffile_path(PF_NAME"preferences", true1, app_env_var_prefix);
7052 | if ((pf = ws_fopenfopen(pf_path, "w")) == NULL((void*)0)) {
7053 | *pf_path_return = pf_path;
7054 | return errno(*__errno_location ());
7055 | }
7056 | g_free(pf_path);
7057 | } else {
7058 | pf = stdoutstdout;
7059 | }
7060 |
7061 | /*
7062 | * If the preferences file is being written, be sure to write UAT files
7063 | * first that were migrated from the preferences file.
7064 | */
7065 | if (pf_path_return != NULL((void*)0)) {
7066 | if (prefs.filter_expressions_old) {
7067 | char *err = NULL((void*)0);
7068 | prefs.filter_expressions_old = false0;
7069 | if (!uat_save(uat_get_table_by_name("Display expressions"), app_env_var_prefix, &err)) {
7070 | ws_warning("Unable to save Display expressions: %s", err)do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 7070, __func__, "Unable to save Display expressions: %s", err ); } } while (0);
7071 | g_free(err);
7072 | }
7073 | }
7074 |
7075 | module_t *extcap_module = prefs_find_module("extcap");
7076 | if (extcap_module && !prefs.capture_no_extcap) {
7077 | char *ext_path = get_persconffile_path("extcap.cfg", true1, app_env_var_prefix);
7078 | FILE *extf;
7079 | if ((extf = ws_fopenfopen(ext_path, "w")) == NULL((void*)0)) {
7080 | if (errno(*__errno_location ()) != EISDIR21) {
7081 | ws_warning("Unable to save extcap preferences \"%s\": %s",do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 7082, __func__, "Unable to save extcap preferences \"%s\": %s" , ext_path, g_strerror((*__errno_location ()))); } } while (0 )
7082 | ext_path, g_strerror(errno))do { if (1) { ws_log_full("Epan", LOG_LEVEL_WARNING, "epan/prefs.c" , 7082, __func__, "Unable to save extcap preferences \"%s\": %s" , ext_path, g_strerror((*__errno_location ()))); } } while (0 );
7083 | }
7084 | g_free(ext_path);
7085 | } else {
7086 | g_free(ext_path);
7087 |
7088 | fputs("# Extcap configuration file for Wireshark " VERSION"4.7.0" ".\n"
7089 | "#\n"
7090 | "# This file is regenerated each time preferences are saved within\n"
7091 | "# Wireshark. Making manual changes should be safe, however.\n"
7092 | "# Preferences that have been commented out have not been\n"
7093 | "# changed from their default value.\n", extf);
7094 |
7095 | write_gui_pref_info.pf = extf;
7096 | write_gui_pref_info.is_gui_module = false0;
7097 |
7098 | write_module_prefs(extcap_module, &write_gui_pref_info);
7099 |
7100 | fclose(extf);
7101 | }
7102 | }
7103 | }
7104 |
7105 | fputs("# Configuration file for Wireshark " VERSION"4.7.0" ".\n"
7106 | "#\n"
7107 | "# This file is regenerated each time preferences are saved within\n"
7108 | "# Wireshark. Making manual changes should be safe, however.\n"
7109 | "# Preferences that have been commented out have not been\n"
7110 | "# changed from their default value.\n", pf);
7111 |
7112 | /*
7113 | * For "backwards compatibility" the GUI module is written first as it's
7114 | * at the top of the file. This is followed by all modules that can't
7115 | * fit into the preferences read/write API. Finally the remaining modules
7116 | * are written in alphabetical order (including of course the protocol preferences)
7117 | */
7118 | write_gui_pref_info.pf = pf;
7119 | write_gui_pref_info.is_gui_module = true1;
7120 |
7121 | write_module_prefs(gui_module, &write_gui_pref_info);
7122 |
7123 | write_gui_pref_info.is_gui_module = false0;
7124 | prefs_module_list_foreach(prefs_top_level_modules, write_module_prefs, &write_gui_pref_info, true1);
7125 |
7126 | fclose(pf);
7127 |
7128 | /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
7129 | an error indication, or maybe write to a new preferences file and
7130 | rename that file on top of the old one only if there are not I/O
7131 | errors. */
7132 | return 0;
7133 | }
7134 |
7135 | /** The col_list is only partly managed by the custom preference API
7136 | * because its data is shared between multiple preferences, so
7137 | * it's freed here
7138 | */
7139 | static void
7140 | free_col_info(GList *list)
7141 | {
7142 | fmt_data *cfmt;
7143 | GList *list_head = list;
7144 |
7145 | while (list != NULL((void*)0)) {
7146 | cfmt = (fmt_data *)list->data;
7147 |
7148 | g_free(cfmt->title);
7149 | g_free(cfmt->custom_fields);
7150 | g_free(cfmt);
7151 | list = g_list_next(list)((list) ? (((GList *)(list))->next) : ((void*)0));
7152 | }
7153 | g_list_free(list_head);
7154 | }
7155 |
7156 | /*
7157 | * Editor modelines
7158 | *
7159 | * Local Variables:
7160 | * c-basic-offset: 4
7161 | * tab-width: 8
7162 | * indent-tabs-mode: nil
7163 | * End:
7164 | *
7165 | * ex: set shiftwidth=4 tabstop=8 expandtab:
7166 | * :indentSize=4:tabSize=8:noTabs=true:
7167 | */