Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
prefs-int.h
Go to the documentation of this file.
1/* prefs-int.h
2 * Definitions for implementation of preference handling routines;
3 * used by "friends" of the preferences type.
4 *
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
8 *
9 * SPDX-License-Identifier: GPL-2.0-or-later
10 */
11#pragma once
12#include <stdio.h>
13#include "ws_symbol_export.h"
14#include <epan/wmem_scopes.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
28 const char *name;
29 const char *title;
30 const char *description;
31 const char *help;
32 void (*apply_cb)(void);
34 GList *prefs;
38 unsigned int prefs_changed_flags;
39 bool obsolete;
42 bool use_gui;
49 unsigned int effect_flags;
52};
53
57typedef struct {
58 module_t* module;
59 FILE* pf;
61
62
67typedef void (*pref_custom_free_cb)(pref_t* pref);
68
73typedef void (*pref_custom_reset_cb)(pref_t* pref);
74
82typedef prefs_set_pref_e (*pref_custom_set_cb)(pref_t* pref, const char* value, unsigned int* changed_flags);
83
84/* typedef void (*pref_custom_write_cb) (pref_t* pref, write_pref_arg_t* arg); Deprecated. */
85
90typedef const char* (*pref_custom_type_name_cb)(void);
91
96typedef char* (*pref_custom_type_description_cb)(void);
97
103typedef bool (*pref_custom_is_default_cb)(pref_t* pref);
104
111typedef char* (*pref_custom_to_str_cb)(pref_t* pref, bool default_val);
112
126
127
158
159/*
160 * (1) These are only supported for "internal" (non-protocol) use
161 * and not as a generic protocol preference.
162 * (2) Internal use only, not a generic protocol preference.
163 * (3) Like string, but never saved to prefs file.
164 * (4) Dedicated to TCP PROTOCOL for handling manual SEQ interpretation,
165 * and allow users manage the sender traffic ambiguities
166 * (5) Like string, but with dissector name syntax check.
167 */
168
169/* read_prefs_file: read in a generic config file and do a callback to */
170/* pref_set_pair_fct() for every key/value pair found */
184typedef prefs_set_pref_e (*pref_set_pair_cb) (char *key, const char *value, void *private_data, bool return_range_errors);
185
192WS_DLL_PUBLIC
193const char* prefs_get_description(pref_t *pref);
194
201WS_DLL_PUBLIC
202const char* prefs_get_title(pref_t *pref);
203
209WS_DLL_PUBLIC
210const char* prefs_get_name(pref_t *pref);
211
218WS_DLL_PUBLIC
219int prefs_get_type(pref_t *pref);
220
227WS_DLL_PUBLIC uint32_t prefs_get_max_value(pref_t *pref);
228
237WS_DLL_PUBLIC
238unsigned int prefs_get_effect_flags(pref_t *pref);
239
252WS_DLL_PUBLIC
253void prefs_set_effect_flags(pref_t *pref, unsigned int flags);
254
262WS_DLL_PUBLIC
263void prefs_set_effect_flags_by_name(module_t * module, const char *pref, unsigned int flags);
264
276WS_DLL_PUBLIC
277unsigned int prefs_get_module_effect_flags(module_t * module);
278
290WS_DLL_PUBLIC
291unsigned prefs_module_list_foreach(const wmem_tree_t* module_list, module_cb callback,
292 void* user_data, bool skip_obsolete);
293
308WS_DLL_PUBLIC
309void prefs_set_module_effect_flags(module_t * module, unsigned int flags);
310
311
321WS_DLL_PUBLIC
322bool prefs_set_range_value_work(pref_t *pref, const char *value,
323 bool return_range_errors, unsigned int *changed_flags);
324
332WS_DLL_PUBLIC
333unsigned int
334prefs_set_stashed_range_value(pref_t *pref, const char *value);
335
341WS_DLL_PUBLIC
342void
343prefs_range_add_value(pref_t *pref, uint32_t val);
344
350WS_DLL_PUBLIC
351void
352prefs_range_remove_value(pref_t *pref, uint32_t val);
353
363WS_DLL_PUBLIC unsigned int prefs_set_bool_value(pref_t *pref, bool value, pref_source_t source);
364
372WS_DLL_PUBLIC bool prefs_get_bool_value(pref_t *pref, pref_source_t source);
373
380WS_DLL_PUBLIC void prefs_invert_bool_value(pref_t *pref, pref_source_t source);
381
390WS_DLL_PUBLIC unsigned int prefs_set_uint_value(pref_t *pref, unsigned value, pref_source_t source);
391
398WS_DLL_PUBLIC unsigned prefs_get_uint_base(pref_t *pref);
399
407WS_DLL_PUBLIC unsigned prefs_get_uint_value(pref_t *pref, pref_source_t source);
408
417WS_DLL_PUBLIC unsigned int prefs_set_int_value(pref_t* pref, int value, pref_source_t source);
418
426WS_DLL_PUBLIC int prefs_get_int_value(pref_t* pref, pref_source_t source);
427
436WS_DLL_PUBLIC unsigned int prefs_set_float_value(pref_t* pref, double value, pref_source_t source);
437
445WS_DLL_PUBLIC double prefs_get_float_value(pref_t* pref, pref_source_t source);
446
456WS_DLL_PUBLIC unsigned int prefs_set_enum_value(pref_t *pref, int value, pref_source_t source);
457
466WS_DLL_PUBLIC unsigned int prefs_set_enum_string_value(pref_t *pref, const char *value, pref_source_t source);
467
475WS_DLL_PUBLIC int prefs_get_enum_value(pref_t *pref, pref_source_t source);
476
483WS_DLL_PUBLIC const enum_val_t* prefs_get_enumvals(pref_t *pref);
484
491WS_DLL_PUBLIC bool prefs_get_enum_radiobuttons(pref_t *pref);
492
501WS_DLL_PUBLIC bool prefs_set_color_value(pref_t *pref, color_t value, pref_source_t source);
502
510WS_DLL_PUBLIC color_t* prefs_get_color_value(pref_t *pref, pref_source_t source);
511
520WS_DLL_PUBLIC unsigned int prefs_set_custom_value(pref_t *pref, const char *value, pref_source_t source);
521
530WS_DLL_PUBLIC unsigned int prefs_set_string_value(pref_t *pref, const char* value, pref_source_t source);
531
539WS_DLL_PUBLIC const char *prefs_get_string_value(pref_t *pref, pref_source_t source);
540
547WS_DLL_PUBLIC struct epan_uat* prefs_get_uat_value(pref_t *pref);
548
557WS_DLL_PUBLIC bool prefs_set_range_value(pref_t *pref, range_t *value, pref_source_t source);
558
566WS_DLL_PUBLIC range_t* prefs_get_range_value_real(pref_t *pref, pref_source_t source);
567
576WS_DLL_PUBLIC bool prefs_add_decode_as_value(pref_t *pref, unsigned value, bool replace);
577
586WS_DLL_PUBLIC bool prefs_remove_decode_as_value(pref_t *pref, unsigned value, bool set_default);
587
596WS_DLL_PUBLIC unsigned int prefs_set_password_value(pref_t *pref, const char* value, pref_source_t source);
597
605WS_DLL_PUBLIC const char *prefs_get_password_value(pref_t *pref, pref_source_t source);
606
615WS_DLL_PUBLIC bool prefs_add_list_value(pref_t *pref, void *value, pref_source_t source);
616
624WS_DLL_PUBLIC GList* prefs_get_list_value(pref_t *pref, pref_source_t source);
625
631WS_DLL_PUBLIC void reset_pref(pref_t *pref);
632
637WS_DLL_PUBLIC const wmem_tree_t* prefs_get_module_tree(void);
638
649WS_DLL_PUBLIC
650int
651read_prefs_file(const char *pf_path, FILE *pf, pref_set_pair_cb pref_set_pair_fct, void *private_data);
652
663WS_DLL_PUBLIC
664void
665prefs_read_module(const char *name, const char* app_env_var_prefix);
666
673WS_DLL_PUBLIC
674bool
676
684WS_DLL_PUBLIC
685unsigned pref_stash(pref_t *pref, void *unused);
686
697
707WS_DLL_PUBLIC
708unsigned pref_unstash(pref_t *pref, void *unstash_data_p);
709
719WS_DLL_PUBLIC
720unsigned pref_clean_stash(pref_t *pref, void *unused);
721
727WS_DLL_PUBLIC
728void reset_stashed_pref(pref_t *pref);
729
740WS_DLL_PUBLIC
741char *
742join_string_list(GList *sl);
743
752WS_DLL_PUBLIC
753char *
754prefs_sanitize_string(const char* str);
755
756#ifdef __cplusplus
757}
758#endif /* __cplusplus */
WS_DLL_PUBLIC const char * prefs_get_name(pref_t *pref)
Fetch the name of a preference.
Definition prefs.c:282
WS_DLL_PUBLIC unsigned prefs_module_list_foreach(const wmem_tree_t *module_list, module_cb callback, void *user_data, bool skip_obsolete)
Iterate through all modules with preferences.
Definition prefs.c:862
WS_DLL_PUBLIC unsigned int prefs_set_int_value(pref_t *pref, int value, pref_source_t source)
Set an integer preference value.
Definition prefs.c:5074
WS_DLL_PUBLIC unsigned prefs_get_uint_base(pref_t *pref)
Get the base value of an unsigned integer preference.
Definition prefs.c:5220
WS_DLL_PUBLIC void prefs_set_effect_flags(pref_t *pref, unsigned int flags)
Set flags for the effect of the preference.
Definition prefs.c:6320
WS_DLL_PUBLIC bool prefs_set_range_value(pref_t *pref, range_t *value, pref_source_t source)
Set a range value for a preference.
Definition prefs.c:1750
WS_DLL_PUBLIC void prefs_set_effect_flags_by_name(module_t *module, const char *pref, unsigned int flags)
Same as prefs_set_effect_flags, just different way to get preference.
Definition prefs.c:6331
WS_DLL_PUBLIC unsigned int prefs_set_enum_value(pref_t *pref, int value, pref_source_t source)
Set an enum preference value.
Definition prefs.c:1379
WS_DLL_PUBLIC const char * prefs_get_string_value(pref_t *pref, pref_source_t source)
Get the string value of a preference.
Definition prefs.c:1557
WS_DLL_PUBLIC unsigned pref_unstash(pref_t *pref, void *unstash_data_p)
"Unstash" a preference. Set a preference to its stashed value. Can be called from prefs_pref_foreach(...
Definition prefs.c:2165
WS_DLL_PUBLIC char * join_string_list(GList *sl)
Convert a string list preference to a preference string.
Definition prefs.c:4192
WS_DLL_PUBLIC bool prefs_pref_is_default(pref_t *pref)
Check if a preference is at its default value.
Definition prefs.c:6486
WS_DLL_PUBLIC bool prefs_set_color_value(pref_t *pref, color_t value, pref_source_t source)
Set a color value for a preference.
Definition prefs.c:1870
struct pref_unstash_data pref_unstash_data_t
Carries context data used when unstashing preferences back to their live values.
prefs_set_pref_e(* pref_set_pair_cb)(char *key, const char *value, void *private_data, bool return_range_errors)
Set a preference based on a key-value pair.
Definition prefs-int.h:184
char *(* pref_custom_type_description_cb)(void)
Callback that returns a newly allocated human-readable description of a custom preference type.
Definition prefs-int.h:96
WS_DLL_PUBLIC struct epan_uat * prefs_get_uat_value(pref_t *pref)
Get the UAT value for a preference.
Definition prefs.c:1851
WS_DLL_PUBLIC GList * prefs_get_list_value(pref_t *pref, pref_source_t source)
Get the list value for a preference based on the source.
Definition prefs.c:1732
WS_DLL_PUBLIC void prefs_set_module_effect_flags(module_t *module, unsigned int flags)
Set flags for module's preferences effect.
Definition prefs.c:6346
WS_DLL_PUBLIC const char * prefs_get_password_value(pref_t *pref, pref_source_t source)
Get the password value for a preference.
Definition prefs.c:5173
WS_DLL_PUBLIC void reset_pref(pref_t *pref)
Reset a preference to its default value.
Definition prefs.c:4443
WS_DLL_PUBLIC bool prefs_get_bool_value(pref_t *pref, pref_source_t source)
Get the boolean value of a preference.
Definition prefs.c:1326
WS_DLL_PUBLIC unsigned int prefs_get_module_effect_flags(module_t *module)
Fetch flags that show module's preferences effect.
Definition prefs.c:6337
WS_DLL_PUBLIC const enum_val_t * prefs_get_enumvals(pref_t *pref)
Get the enumeration values for a preference.
Definition prefs.c:1436
WS_DLL_PUBLIC uint32_t prefs_get_max_value(pref_t *pref)
Fetches the maximum value for a preference.
Definition prefs.c:287
WS_DLL_PUBLIC int prefs_get_type(pref_t *pref)
Retrieves the type of a preference.
Definition prefs.c:277
WS_DLL_PUBLIC double prefs_get_float_value(pref_t *pref, pref_source_t source)
Get the float value of a preference.
Definition prefs.c:5154
WS_DLL_PUBLIC const wmem_tree_t * prefs_get_module_tree(void)
Get the list of all modules with preferences (used for iterating through all preferences)
Definition prefs.c:340
WS_DLL_PUBLIC bool prefs_get_enum_radiobuttons(pref_t *pref)
Get the radio button values for an enumeration preference.
Definition prefs.c:1441
WS_DLL_PUBLIC const char * prefs_get_title(pref_t *pref)
Get the title of a preference.
Definition prefs.c:272
WS_DLL_PUBLIC void prefs_range_remove_value(pref_t *pref, uint32_t val)
Remove a range value of a range preference.
Definition prefs.c:1819
WS_DLL_PUBLIC unsigned prefs_get_uint_value(pref_t *pref, pref_source_t source)
Get the unsigned integer value of a preference.
Definition prefs.c:5056
WS_DLL_PUBLIC char * prefs_sanitize_string(const char *str)
Sanitize a string so that it can be written to a preference file.
Definition prefs.c:4993
WS_DLL_PUBLIC color_t * prefs_get_color_value(pref_t *pref, pref_source_t source)
Get the color value for a preference based on the specified source.
Definition prefs.c:1908
WS_DLL_PUBLIC void prefs_invert_bool_value(pref_t *pref, pref_source_t source)
Inverts the boolean value of a preference based on the specified source.
Definition prefs.c:1307
WS_DLL_PUBLIC bool prefs_add_list_value(pref_t *pref, void *value, pref_source_t source)
Add a list value to a preference.
Definition prefs.c:1711
bool(* pref_custom_is_default_cb)(pref_t *pref)
Callback that reports whether a custom preference currently holds its default value.
Definition prefs-int.h:103
pref_type_e
Discriminator tag identifying the type and UI representation of a preference entry.
Definition prefs-int.h:138
@ PREF_CUSTOM
Definition prefs-int.h:148
@ PREF_COLOR
Definition prefs-int.h:147
@ PREF_BOOL
Definition prefs-int.h:140
@ PREF_OPEN_FILENAME
Definition prefs-int.h:151
@ PREF_STATIC_TEXT
Definition prefs-int.h:144
@ PREF_UAT
Definition prefs-int.h:145
@ PREF_PROTO_TCP_SNDAMB_ENUM
Definition prefs-int.h:153
@ PREF_DECODE_AS_RANGE
Definition prefs-int.h:150
@ PREF_RANGE
Definition prefs-int.h:143
@ PREF_ENUM
Definition prefs-int.h:141
@ PREF_FLOAT
Definition prefs-int.h:156
@ PREF_PASSWORD
Definition prefs-int.h:152
@ PREF_DISSECTOR
Definition prefs-int.h:154
@ PREF_STRING
Definition prefs-int.h:142
@ PREF_SAVE_FILENAME
Definition prefs-int.h:146
@ PREF_UINT
Definition prefs-int.h:139
@ PREF_INT
Definition prefs-int.h:155
@ PREF_DIRNAME
Definition prefs-int.h:149
WS_DLL_PUBLIC unsigned pref_stash(pref_t *pref, void *unused)
"Stash" a preference. Copy a preference to its stashed value. Can be called from prefs_pref_foreach()...
void(* pref_custom_reset_cb)(pref_t *pref)
Callback invoked to reset a custom preference to its default value.
Definition prefs-int.h:73
WS_DLL_PUBLIC int read_prefs_file(const char *pf_path, FILE *pf, pref_set_pair_cb pref_set_pair_fct, void *private_data)
Read the preferences file (or similar) and call the callback function to set each key/value pair foun...
Definition prefs.c:4758
WS_DLL_PUBLIC void reset_stashed_pref(pref_t *pref)
Set a stashed preference to its default value.
Definition prefs.c:2332
WS_DLL_PUBLIC int prefs_get_int_value(pref_t *pref, pref_source_t source)
Get the integer value of a preference based on the specified source.
Definition prefs.c:5105
WS_DLL_PUBLIC unsigned int prefs_set_string_value(pref_t *pref, const char *value, pref_source_t source)
Set a string value for a preference.
Definition prefs.c:1511
WS_DLL_PUBLIC unsigned int prefs_set_custom_value(pref_t *pref, const char *value, pref_source_t source)
Set a custom value for a preference.
Definition prefs.c:1450
WS_DLL_PUBLIC range_t * prefs_get_range_value_real(pref_t *pref, pref_source_t source)
Get the range value for a preference based on the specified source.
Definition prefs.c:1785
WS_DLL_PUBLIC unsigned int prefs_set_enum_string_value(pref_t *pref, const char *value, pref_source_t source)
Set an enum value for a preference.
Definition prefs.c:1411
WS_DLL_PUBLIC void prefs_range_add_value(pref_t *pref, uint32_t val)
Add a range value of a range preference.
Definition prefs.c:1813
WS_DLL_PUBLIC bool prefs_set_range_value_work(pref_t *pref, const char *value, bool return_range_errors, unsigned int *changed_flags)
Set a range value for a range preference.
Definition prefs.c:1668
WS_DLL_PUBLIC unsigned int prefs_get_effect_flags(pref_t *pref)
Fetch flags that show the effect of the preference.
Definition prefs.c:6311
WS_DLL_PUBLIC unsigned pref_clean_stash(pref_t *pref, void *unused)
Clean up a stashed preference. Can be called from prefs_pref_foreach().
char *(* pref_custom_to_str_cb)(pref_t *pref, bool default_val)
Callback that serializes a custom preference to a newly allocated string.
Definition prefs-int.h:111
WS_DLL_PUBLIC bool prefs_add_decode_as_value(pref_t *pref, unsigned value, bool replace)
Adds or replaces a decode-as value for a preference.
Definition prefs.c:2034
prefs_set_pref_e(* pref_custom_set_cb)(pref_t *pref, const char *value, unsigned int *changed_flags)
Callback invoked to set a custom preference from a string value, reporting which flags changed.
Definition prefs-int.h:82
WS_DLL_PUBLIC unsigned int prefs_set_stashed_range_value(pref_t *pref, const char *value)
Set a stashed range value for a preference.
Definition prefs.c:1692
const char *(* pref_custom_type_name_cb)(void)
Callback that returns the type name string for a custom preference; returns NULL for internal or hidd...
Definition prefs-int.h:90
void(* pref_custom_free_cb)(pref_t *pref)
Callback invoked to free any resources allocated by a custom preference.
Definition prefs-int.h:67
WS_DLL_PUBLIC void prefs_read_module(const char *name, const char *app_env_var_prefix)
Read the preferences for a specific module.
Definition prefs.c:4606
WS_DLL_PUBLIC unsigned int prefs_set_password_value(pref_t *pref, const char *value, pref_source_t source)
Set a password value for a preference.
Definition prefs.c:5214
WS_DLL_PUBLIC bool prefs_remove_decode_as_value(pref_t *pref, unsigned value, bool set_default)
Removes a decode-as value from a preference.
Definition prefs.c:2059
WS_DLL_PUBLIC int prefs_get_enum_value(pref_t *pref, pref_source_t source)
Get the current value of an enumeration preference.
Definition prefs.c:1418
WS_DLL_PUBLIC unsigned int prefs_set_float_value(pref_t *pref, double value, pref_source_t source)
Set a float value for a preference.
Definition prefs.c:5123
WS_DLL_PUBLIC const char * prefs_get_description(pref_t *pref)
Get the description of a preference.
Definition prefs.c:267
WS_DLL_PUBLIC unsigned int prefs_set_uint_value(pref_t *pref, unsigned value, pref_source_t source)
Set an unsigned integer preference value.
Definition prefs.c:5179
WS_DLL_PUBLIC unsigned int prefs_set_bool_value(pref_t *pref, bool value, pref_source_t source)
Set a boolean preference value.
Definition prefs.c:1275
pref_source_t
Selects which copy of a preference value is used as the active source.
Definition prefs.h:140
unsigned(* module_cb)(module_t *module, void *user_data)
Definition prefs.h:536
prefs_set_pref_e
Result of setting a preference.
Definition prefs.h:1271
Internal memory allocator interface used by the wmem subsystem.
Definition wmem_allocator.h:34
Internal representation of a wmem balanced tree.
Definition wmem_tree-int.h:81
RGB color representation with 16-bit precision per channel.
Definition color.h:27
Defines a single named value within an enumerated preference or option type.
Definition params.h:16
Definition range.h:42
Represents a User Accessible Table (UAT), managing a set of user-editable records exposed to a dissec...
Definition uat-int.h:44
char * name
Definition uat-int.h:45
Callback table for a PREF_CUSTOM preference, providing lifecycle and serialization hooks.
Definition prefs-int.h:116
pref_custom_reset_cb reset_cb
Definition prefs-int.h:118
pref_custom_is_default_cb is_default_cb
Definition prefs-int.h:123
pref_custom_type_description_cb type_description_cb
Definition prefs-int.h:122
pref_custom_type_name_cb type_name_cb
Definition prefs-int.h:121
pref_custom_set_cb set_cb
Definition prefs-int.h:119
pref_custom_free_cb free_cb
Definition prefs-int.h:117
pref_custom_to_str_cb to_str_cb
Definition prefs-int.h:124
Represents a preference module grouping related preferences under a named, hierarchical entry in the ...
Definition prefs-int.h:27
unsigned int effect_flags
Definition prefs-int.h:49
wmem_allocator_t * scope
Definition prefs-int.h:33
GList * prefs
Definition prefs-int.h:34
bool use_gui
Definition prefs-int.h:42
wmem_tree_t * submodules
Definition prefs-int.h:36
const char * description
Definition prefs-int.h:30
const char * name
Definition prefs-int.h:28
bool obsolete
Definition prefs-int.h:39
struct pref_module * parent
Definition prefs-int.h:35
unsigned int prefs_changed_flags
Definition prefs-int.h:38
void(* apply_cb)(void)
Definition prefs-int.h:32
int numprefs
Definition prefs-int.h:37
const char * title
Definition prefs-int.h:29
const char * help
Definition prefs-int.h:31
Carries context data used when unstashing preferences back to their live values.
Definition prefs-int.h:691
module_t *bool handle_decode_as
Definition prefs-int.h:694
Definition prefs.c:207
Bundles a preference module with a file handle for use during preference serialization.
Definition prefs-int.h:57
module_t *FILE * pf
Definition prefs-int.h:59