#include <string.h>
#include <errno.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
#include <glib.h>
#include <stdio.h>
#include <epan/proto.h>
#include <epan/strutil.h>
#include <epan/column.h>
+#include <epan/decode_as.h>
#include "print.h"
#include <wsutil/file_util.h>
+#include <wsutil/ws_printf.h> /* ws_g_warning */
#include <epan/prefs-int.h>
#include <epan/uat-int.h>
static module_t *prefs_register_module_or_subtree(module_t *parent,
const char *name, const char *title, const char *description, gboolean is_subtree,
void (*apply_cb)(void), gboolean use_gui);
+static void prefs_register_modules(void);
static prefs_set_pref_e set_pref(gchar*, const gchar*, void *, gboolean);
static void free_col_info(GList *);
static void pre_init_prefs(void);
static gboolean parse_column_format(fmt_data *cfmt, const char *fmt);
static void try_convert_to_custom_column(gpointer *el_data);
+#define IS_PREF_OBSOLETE(p) ((p) & PREF_OBSOLETE)
+#define SET_PREF_OBSOLETE(p) ((p) |= PREF_OBSOLETE)
+#define RESET_PREF_OBSOLETE(p) ((p) &= ~PREF_OBSOLETE)
#define PF_NAME "preferences"
#define OLD_GPF_NAME "wireshark.conf" /* old name for global preferences file */
static gboolean prefs_initialized = FALSE;
-static gboolean prefs_pre_initialized = FALSE;
static gchar *gpf_path = NULL;
static gchar *cols_hidden_list = NULL;
};
#define CAPTURE_COL_TYPE_DESCRIPTION \
"Possible values: INTERFACE, LINK, PMODE, SNAPLEN, MONITOR, BUFFER, FILTER\n"
-#elif defined(_WIN32) && !defined (HAVE_PCAP_CREATE)
+#elif defined(CAN_SET_CAPTURE_BUFFER_SIZE)
/* Can set buffer size but not monitor mode. */
static gint num_capture_cols = 6;
static const gchar *capture_cols[6] = {
"Possible values: INTERFACE, LINK, PMODE, SNAPLEN, FILTER\n"
#endif
+static const enum_val_t gui_packet_list_elide_mode[] = {
+ {"LEFT", "LEFT", ELIDE_LEFT},
+ {"RIGHT", "RIGHT", ELIDE_RIGHT},
+ {"MIDDLE", "MIDDLE", ELIDE_MIDDLE},
+ {"NONE", "NONE", ELIDE_NONE},
+ {NULL, NULL, -1}
+};
+
+/** Struct to hold preference data */
+struct preference {
+ const char *name; /**< name of preference */
+ const char *title; /**< title to use in GUI */
+ const char *description; /**< human-readable description of preference */
+ int ordinal; /**< ordinal number of this preference */
+ int type; /**< type of that preference */
+ gui_type_t gui; /**< type of the GUI (QT, GTK or both) the preference is registered for */
+ union { /* The Qt preference code assumes that these will all be pointers (and unique) */
+ guint *uint;
+ gboolean *boolp;
+ gint *enump;
+ char **string;
+ range_t **range;
+ struct epan_uat* uat;
+ color_t *colorp;
+ GList** list;
+ } varp; /**< pointer to variable storing the value */
+ union {
+ guint uint;
+ gboolean boolval;
+ gint enumval;
+ char *string;
+ range_t *range;
+ color_t color;
+ GList* list;
+ } stashed_val; /**< original value, when editing from the GUI */
+ union {
+ guint uint;
+ gboolean boolval;
+ gint enumval;
+ char *string;
+ range_t *range;
+ color_t color;
+ GList* list;
+ } default_val; /**< the default value of the preference */
+ union {
+ guint base; /**< input/output base, for PREF_UINT */
+ guint32 max_value; /**< maximum value of a range */
+ struct {
+ const enum_val_t *enumvals; /**< list of name & values */
+ gboolean radio_buttons; /**< TRUE if it should be shown as
+ radio buttons rather than as an
+ option menu or combo box in
+ the preferences tab */
+ } enum_info; /**< for PREF_ENUM */
+ } info; /**< display/text file information */
+ struct pref_custom_cbs custom_cbs; /**< for PREF_CUSTOM */
+ void *control; /**< handle for GUI control for this preference. GTK+ only? */
+};
+
+const char* prefs_get_description(pref_t *pref)
+{
+ return pref->description;
+}
+
+const char* prefs_get_title(pref_t *pref)
+{
+ return pref->title;
+}
+
+int prefs_get_type(pref_t *pref)
+{
+ return pref->type;
+}
+
+gui_type_t prefs_get_gui_type(pref_t *pref)
+{
+ return pref->gui;
+}
+
+const char* prefs_get_name(pref_t *pref)
+{
+ return pref->name;
+}
+
+guint32 prefs_get_max_value(pref_t *pref)
+{
+ return pref->info.max_value;
+}
+
+void* prefs_get_control(pref_t *pref)
+{
+ return pref->control;
+}
+
+void prefs_set_control(pref_t *pref, void* control)
+{
+ pref->control = control;
+}
+
+int prefs_get_ordinal(pref_t *pref)
+{
+ return pref->ordinal;
+}
+
/*
* List of all modules with preference settings.
*/
void
prefs_init(void)
{
+ memset(&prefs, 0, sizeof(prefs));
prefs_modules = wmem_tree_new(wmem_epan_scope());
prefs_top_level_modules = wmem_tree_new(wmem_epan_scope());
}
+/*
+ * Free the strings for a string-like preference.
+ */
+static void
+free_string_like_preference(pref_t *pref)
+{
+ g_free(*pref->varp.string);
+ *pref->varp.string = NULL;
+ g_free(pref->default_val.string);
+ pref->default_val.string = NULL;
+}
+
static void
free_pref(gpointer data, gpointer user_data _U_)
{
pref_t *pref = (pref_t *)data;
+ int type = pref->type;
- switch (pref->type) {
- case PREF_OBSOLETE:
+ /* we reset the PREF_OBSOLETE bit in order to allow the original preference to be freed */
+ RESET_PREF_OBSOLETE(type);
+
+ switch (type) {
case PREF_BOOL:
case PREF_ENUM:
case PREF_UINT:
+ case PREF_DECODE_AS_UINT:
case PREF_STATIC_TEXT:
case PREF_UAT:
case PREF_COLOR:
case PREF_STRING:
case PREF_FILENAME:
case PREF_DIRNAME:
- g_free((char *)*pref->varp.string);
+ g_free(*pref->varp.string);
*pref->varp.string = NULL;
g_free(pref->default_val.string);
pref->default_val.string = NULL;
break;
case PREF_RANGE:
- g_free(*pref->varp.range);
+ case PREF_DECODE_AS_RANGE:
+ wmem_free(wmem_epan_scope(), *pref->varp.range);
*pref->varp.range = NULL;
- g_free(pref->default_val.range);
+ wmem_free(wmem_epan_scope(), pref->default_val.range);
pref->default_val.range = NULL;
break;
case PREF_CUSTOM:
* do what clean up we can.
*/
prefs_modules_foreach(free_module_prefs, NULL);
+
+ /* Clean the uats */
+ uat_cleanup();
}
/*
FALSE, apply_cb, use_gui);
}
+static void
+prefs_deregister_module(module_t *parent, const char *name, const char *title)
+{
+ /* Remove this module from the list of all modules */
+ module_t *module = (module_t *)wmem_tree_remove_string(prefs_modules, name, WMEM_TREE_STRING_NOCASE);
+
+ if (!module)
+ return;
+
+ if (parent == NULL) {
+ /* Remove from top */
+ wmem_tree_remove_string(prefs_top_level_modules, title, WMEM_TREE_STRING_NOCASE);
+ } else if (parent->submodules) {
+ /* Remove from parent */
+ wmem_tree_remove_string(parent->submodules, title, WMEM_TREE_STRING_NOCASE);
+ }
+
+ free_module_prefs(module, NULL);
+ wmem_free(wmem_epan_scope(), module);
+}
+
/*
* Register a subtree that will have modules under it.
* Specify the module under which to register it or NULL to register it
* No. Register Protocols subtree as well as any preferences
* for non-dissector modules.
*/
+ pre_init_prefs();
prefs_register_modules();
}
protocol = find_protocol_by_id(id);
proto_get_protocol_name(id), apply_cb, TRUE);
}
+void
+prefs_deregister_protocol (int id)
+{
+ protocol_t *protocol = find_protocol_by_id(id);
+ prefs_deregister_module (protocols_module,
+ proto_get_protocol_filter_name(id),
+ proto_get_protocol_short_name(protocol));
+}
+
module_t *
prefs_register_protocol_subtree(const char *subtree, int id, void (*apply_cb)(void))
{
* No. Register Protocols subtree as well as any preferences
* for non-dissector modules.
*/
+ pre_init_prefs();
prefs_register_modules();
}
* No. Register Protocols subtree as well as any preferences
* for non-dissector modules.
*/
+ pre_init_prefs();
prefs_register_modules();
}
protocol = find_protocol_by_id(id);
* No. Register Statistics subtree as well as any preferences
* for non-dissector modules.
*/
- prefs_register_modules();
+ pre_init_prefs();
+ prefs_register_modules();
}
return prefs_register_module(stats_module, name, title, description,
} call_foreach_t;
static gboolean
-call_foreach_cb(void *value, void *data)
+call_foreach_cb(const void *key _U_, void *value, void *data)
{
module_t *module = (module_t*)value;
call_foreach_t *call_data = (call_foreach_t*)data;
}
static gboolean
-call_apply_cb(void *value, void *data _U_)
+call_apply_cb(const void *key _U_, void *value, void *data _U_)
{
module_t *module = (module_t *)value;
(*module->apply_cb)();
module->prefs_changed = FALSE;
}
+ if (module->submodules)
+ wmem_tree_foreach(module->submodules, call_apply_cb, NULL);
return FALSE;
}
prefs_apply(module_t *module)
{
if (module && module->prefs_changed)
- call_apply_cb(module, NULL);
+ call_apply_cb(NULL, module, NULL);
}
/*
*/
static pref_t *
register_preference(module_t *module, const char *name, const char *title,
- const char *description, pref_type_t type)
+ const char *description, int type)
{
pref_t *preference;
const gchar *p;
+ const char *name_prefix = (module->name != NULL) ? module->name : module->parent->name;
preference = g_new(pref_t,1);
preference->name = name;
if (prefs_find_preference(module, name) != NULL)
g_error("Preference %s has already been registered", name);
- if ((type != PREF_OBSOLETE) &&
+ if ((!IS_PREF_OBSOLETE(type)) &&
/* Don't compare if it's a subtree */
(module->name != NULL)) {
/*
g_error("Preference %s begins with the module name", name);
}
+ /* The title shows up in the preferences dialog. Make sure it's UI-friendly. */
+ if (preference->title) {
+ const char *cur_char;
+ if (preference->type != PREF_STATIC_TEXT && g_utf8_strlen(preference->title, -1) > 80) { // Arbitrary.
+ g_error("Title for preference %s.%s is too long: %s", name_prefix, preference->name, preference->title);
+ }
+
+ if (!g_utf8_validate(preference->title, -1, NULL)) {
+ g_error("Title for preference %s.%s isn't valid UTF-8.", name_prefix, preference->name);
+ }
+
+ for (cur_char = preference->title; *cur_char; cur_char = g_utf8_next_char(cur_char)) {
+ if (!g_unichar_isprint(g_utf8_get_char(cur_char))) {
+ g_error("Title for preference %s.%s isn't printable UTF-8.", name_prefix, preference->name);
+ }
+ }
+ }
+
+ if (preference->description) {
+ if (!g_utf8_validate(preference->description, -1, NULL)) {
+ g_error("Description for preference %s.%s isn't valid UTF-8.", name_prefix, preference->name);
+ }
+ }
+
/*
- * There isn't already one with that name, so add the
- * preference.
+ * We passed all of our checks. Add the preference.
*/
module->prefs = g_list_append(module->prefs, preference);
if (title != NULL)
typedef struct {
GList *list_entry;
const char *name;
+ module_t *submodule;
} find_pref_arg_t;
static gint
}
static gboolean
-module_find_pref_cb(void *value, void *data)
+module_find_pref_cb(const void *key _U_, void *value, void *data)
{
find_pref_arg_t* arg = (find_pref_arg_t*)data;
GList *list_entry;
return FALSE;
arg->list_entry = list_entry;
+ arg->submodule = module;
return TRUE;
}
-struct preference *
-prefs_find_preference(module_t *module, const char *name)
+/* Tries to find a preference, setting containing_module to the (sub)module
+ * holding this preference. */
+static struct preference *
+prefs_find_preference_with_submodule(module_t *module, const char *name,
+ module_t **containing_module)
{
find_pref_arg_t arg;
GList *list_entry;
list_entry = g_list_find_custom(module->prefs, name,
preference_match);
+ arg.submodule = NULL;
if (list_entry == NULL)
{
if (list_entry == NULL)
return NULL; /* no such preference */
+ if (containing_module)
+ *containing_module = arg.submodule ? arg.submodule : module;
+
return (struct preference *) list_entry->data;
}
+struct preference *
+prefs_find_preference(module_t *module, const char *name)
+{
+ return prefs_find_preference_with_submodule(module, name, NULL);
+}
+
/*
* Returns TRUE if the given protocol has registered preferences
*/
preference->default_val.boolval = *var;
}
+gboolean prefs_set_bool_value(pref_t *pref, gboolean value, pref_source_t source)
+{
+ gboolean changed = FALSE;
+
+ switch (source)
+ {
+ case pref_default:
+ if (pref->default_val.boolval != value) {
+ pref->default_val.boolval = value;
+ changed = TRUE;
+ }
+ break;
+ case pref_stashed:
+ if (pref->stashed_val.boolval != value) {
+ pref->stashed_val.boolval = value;
+ changed = TRUE;
+ }
+ break;
+ case pref_current:
+ if (*pref->varp.boolp != value) {
+ *pref->varp.boolp = value;
+ changed = TRUE;
+ }
+ break;
+ default:
+ g_assert_not_reached();
+ break;
+ }
+
+ return changed;
+}
+
+void prefs_invert_bool_value(pref_t *pref, pref_source_t source)
+{
+ switch (source)
+ {
+ case pref_default:
+ pref->default_val.boolval = !pref->default_val.boolval;
+ break;
+ case pref_stashed:
+ pref->stashed_val.boolval = !pref->stashed_val.boolval;
+ break;
+ case pref_current:
+ *pref->varp.boolp = !(*pref->varp.boolp);
+ break;
+ default:
+ g_assert_not_reached();
+ break;
+ }
+}
+
+gboolean prefs_get_bool_value(pref_t *pref, pref_source_t source)
+{
+ switch (source)
+ {
+ case pref_default:
+ return pref->default_val.boolval;
+ break;
+ case pref_stashed:
+ return pref->stashed_val.boolval;
+ break;
+ case pref_current:
+ return *pref->varp.boolp;
+ break;
+ default:
+ g_assert_not_reached();
+ break;
+ }
+
+ return FALSE;
+}
+
/*
* Register a preference with an enumerated value.
*/
+/*
+ * XXX Should we get rid of the radio_buttons parameter and make that
+ * behavior automatic depending on the number of items?
+ */
void
prefs_register_enum_preference(module_t *module, const char *name,
const char *title, const char *description,
preference->info.enum_info.radio_buttons = radio_buttons;
}
-static pref_t*
+gboolean prefs_set_enum_value(pref_t *pref, gint value, pref_source_t source)
+{
+ gboolean changed = FALSE;
+
+ switch (source)
+ {
+ case pref_default:
+ if (pref->default_val.enumval != value) {
+ pref->default_val.enumval = value;
+ changed = TRUE;
+ }
+ break;
+ case pref_stashed:
+ if (pref->stashed_val.enumval != value) {
+ pref->stashed_val.enumval = value;
+ changed = TRUE;
+ }
+ break;
+ case pref_current:
+ if (*pref->varp.enump != value) {
+ *pref->varp.enump = value;
+ changed = TRUE;
+ }
+ break;
+ default:
+ g_assert_not_reached();
+ break;
+ }
+
+ return changed;
+}
+
+gint prefs_get_enum_value(pref_t *pref, pref_source_t source)
+{
+ switch (source)
+ {
+ case pref_default:
+ return pref->default_val.enumval;
+ break;
+ case pref_stashed:
+ return pref->stashed_val.enumval;
+ break;
+ case pref_current:
+ return *pref->varp.enump;
+ break;
+ default:
+ g_assert_not_reached();
+ break;
+ }
+
+ return 0;
+}
+
+const enum_val_t* prefs_get_enumvals(pref_t *pref)
+{
+ return pref->info.enum_info.enumvals;
+}
+
+gboolean prefs_get_enum_radiobuttons(pref_t *pref)
+{
+ return pref->info.enum_info.radio_buttons;
+}
+
+static void
register_string_like_preference(module_t *module, const char *name,
const char *title, const char *description,
- const char **var, pref_type_t type)
+ char **var, int type,
+ struct pref_custom_cbs* custom_cbs,
+ gboolean free_tmp)
{
- pref_t *preference;
- char *varcopy;
+ pref_t *pref;
+ gchar *tmp;
- preference = register_preference(module, name, title, description,
- type);
+ pref = register_preference(module, name, title, description, type);
/*
* String preference values should be non-null (as you can't
* If the value is a null pointer, make it a copy of a null
* string, otherwise make it a copy of the value.
*/
+ tmp = *var;
if (*var == NULL) {
*var = g_strdup("");
- varcopy = g_strdup("");
} else {
*var = g_strdup(*var);
- varcopy = g_strdup(*var);
}
- preference->varp.string = var;
- preference->default_val.string = varcopy;
- preference->stashed_val.string = NULL;
-
- return preference;
+ if (free_tmp) {
+ g_free(tmp);
+ }
+ pref->varp.string = var;
+ pref->default_val.string = g_strdup(*var);
+ pref->stashed_val.string = NULL;
+ if (type == PREF_CUSTOM) {
+ g_assert(custom_cbs);
+ pref->custom_cbs = *custom_cbs;
+ }
}
/*
- * Register a preference with a character-string value.
+ * For use by UI code that sets preferences.
*/
-void
-prefs_register_string_preference(module_t *module, const char *name,
- const char *title, const char *description,
- const char **var)
+gboolean
+prefs_set_string_value(pref_t *pref, const char* value, pref_source_t source)
+{
+ gboolean changed = FALSE;
+
+ switch (source)
+ {
+ case pref_default:
+ if (*pref->default_val.string) {
+ if (strcmp(pref->default_val.string, value) != 0) {
+ changed = TRUE;
+ g_free(pref->default_val.string);
+ pref->default_val.string = g_strdup(value);
+ }
+ } else if (value) {
+ pref->default_val.string = g_strdup(value);
+ }
+ break;
+ case pref_stashed:
+ if (pref->stashed_val.string) {
+ if (strcmp(pref->stashed_val.string, value) != 0) {
+ changed = TRUE;
+ g_free(pref->stashed_val.string);
+ pref->stashed_val.string = g_strdup(value);
+ }
+ } else if (value) {
+ pref->stashed_val.string = g_strdup(value);
+ }
+ break;
+ case pref_current:
+ if (*pref->varp.string) {
+ if (strcmp(*pref->varp.string, value) != 0) {
+ changed = TRUE;
+ g_free(*pref->varp.string);
+ *pref->varp.string = g_strdup(value);
+ }
+ } else if (value) {
+ *pref->varp.string = g_strdup(value);
+ }
+ break;
+ default:
+ g_assert_not_reached();
+ break;
+ }
+
+ return changed;
+}
+
+char* prefs_get_string_value(pref_t *pref, pref_source_t source)
{
- register_string_like_preference(module, name, title, description, var,
- PREF_STRING);
+ switch (source)
+ {
+ case pref_default:
+ return pref->default_val.string;
+ case pref_stashed:
+ return pref->stashed_val.string;
+ case pref_current:
+ return *pref->varp.string;
+ default:
+ g_assert_not_reached();
+ break;
+ }
+
+ return NULL;
}
/*
- * Register a "custom" preference with a character-string value.
- * XXX - This should be temporary until we can find a better way
- * to do "custom" preferences
+ * Reset the value of a string-like preference.
*/
static void
-prefs_register_string_custom_preference(module_t *module, const char *name,
- const char *title, const char *description,
- struct pref_custom_cbs* custom_cbs, const char **var)
+reset_string_like_preference(pref_t *pref)
{
- pref_t *preference;
-
- preference = register_string_like_preference(module, name, title, description, var,
- PREF_CUSTOM);
-
- preference->custom_cbs = *custom_cbs;
+ g_free(*pref->varp.string);
+ *pref->varp.string = g_strdup(pref->default_val.string);
}
+/*
+ * Register a preference with a character-string value.
+ */
+void
+prefs_register_string_preference(module_t *module, const char *name,
+ const char *title, const char *description,
+ const char **var)
+{
+DIAG_OFF(cast-qual)
+ register_string_like_preference(module, name, title, description,
+ (char **)var, PREF_STRING, NULL, FALSE);
+DIAG_ON(cast-qual)
+}
/*
* Register a preference with a file name (string) value.
const char *title, const char *description,
const char **var)
{
- register_string_like_preference(module, name, title, description, var,
- PREF_FILENAME);
+DIAG_OFF(cast-qual)
+ register_string_like_preference(module, name, title, description,
+ (char **)var, PREF_FILENAME, NULL, FALSE);
+DIAG_ON(cast-qual)
}
/*
const char *title, const char *description,
const char **var)
{
- register_string_like_preference(module, name, title, description, var,
- PREF_DIRNAME);
+DIAG_OFF(cast-qual)
+ register_string_like_preference(module, name, title, description,
+ (char **)var, PREF_DIRNAME, NULL, FALSE);
+DIAG_ON(cast-qual)
}
-/*
- * Register a preference with a ranged value.
- */
-void
-prefs_register_range_preference(module_t *module, const char *name,
+/* Refactoring to handle both PREF_RANGE and PREF_DECODE_AS_RANGE */
+static void
+prefs_register_range_preference_common(module_t *module, const char *name,
const char *title, const char *description,
- range_t **var, guint32 max_value)
+ range_t **var, guint32 max_value, int type)
{
pref_t *preference;
- preference = register_preference(module, name, title, description,
- PREF_RANGE);
+ preference = register_preference(module, name, title, description, type);
preference->info.max_value = max_value;
-
/*
* Range preference values should be non-null (as you can't
* keep them null after using the preferences GUI, you can at best
* If the value is a null pointer, make it an empty range.
*/
if (*var == NULL)
- *var = range_empty();
+ *var = range_empty(wmem_epan_scope());
preference->varp.range = var;
- preference->default_val.range = range_copy(*var);
+ preference->default_val.range = range_copy(wmem_epan_scope(), *var);
preference->stashed_val.range = NULL;
}
/*
- * Register a static text 'preference'. It can be used to add explanatory
- * text inline with other preferences in the GUI.
- * Note: Static preferences are not saved to the preferences file.
+ * Register a preference with a ranged value.
*/
void
-prefs_register_static_text_preference(module_t *module, const char *name,
- const char *title,
- const char *description)
+prefs_register_range_preference(module_t *module, const char *name,
+ const char *title, const char *description,
+ range_t **var, guint32 max_value)
{
- register_preference(module, name, title, description, PREF_STATIC_TEXT);
+ prefs_register_range_preference_common(module, name, title,
+ description, var, max_value, PREF_RANGE);
+}
+
+gboolean
+prefs_set_range_value_work(pref_t *pref, const gchar *value,
+ gboolean return_range_errors, gboolean *changed)
+{
+ range_t *newrange;
+
+ if (range_convert_str_work(wmem_epan_scope(), &newrange, value, pref->info.max_value,
+ return_range_errors) != CVT_NO_ERROR) {
+ return FALSE; /* number was bad */
+ }
+
+ if (!ranges_are_equal(*pref->varp.range, newrange)) {
+ *changed = TRUE;
+ wmem_free(wmem_epan_scope(), *pref->varp.range);
+ *pref->varp.range = newrange;
+ } else {
+ wmem_free(wmem_epan_scope(), newrange);
+ }
+ return TRUE;
}
/*
- * Register a uat 'preference'. It adds a button that opens the uat's window in the
- * preferences tab of the module.
+ * For use by UI code that sets preferences.
*/
-extern void
-prefs_register_uat_preference(module_t *module, const char *name,
- const char *title, const char *description,
- uat_t* uat)
+gboolean
+prefs_set_stashed_range_value(pref_t *pref, const gchar *value)
{
+ range_t *newrange;
- pref_t* preference = register_preference(module, name, title, description, PREF_UAT);
+ if (range_convert_str_work(wmem_epan_scope(), &newrange, value, pref->info.max_value,
+ TRUE) != CVT_NO_ERROR) {
+ return FALSE; /* number was bad */
+ }
- preference->varp.uat = uat;
+ if (!ranges_are_equal(pref->stashed_val.range, newrange)) {
+ wmem_free(wmem_epan_scope(), pref->stashed_val.range);
+ pref->stashed_val.range = newrange;
+ } else {
+ wmem_free(wmem_epan_scope(), newrange);
+ }
+ return TRUE;
+
+}
+
+gboolean prefs_set_range_value(pref_t *pref, range_t *value, pref_source_t source)
+{
+ gboolean changed = FALSE;
+
+ switch (source)
+ {
+ case pref_default:
+ if (!ranges_are_equal(pref->default_val.range, value)) {
+ wmem_free(wmem_epan_scope(), pref->default_val.range);
+ pref->default_val.range = range_copy(wmem_epan_scope(), value);
+ changed = TRUE;
+ }
+ break;
+ case pref_stashed:
+ if (!ranges_are_equal(pref->stashed_val.range, value)) {
+ wmem_free(wmem_epan_scope(), pref->stashed_val.range);
+ pref->stashed_val.range = range_copy(wmem_epan_scope(), value);
+ changed = TRUE;
+ }
+ break;
+ case pref_current:
+ if (!ranges_are_equal(*pref->varp.range, value)) {
+ wmem_free(wmem_epan_scope(), *pref->varp.range);
+ *pref->varp.range = range_copy(wmem_epan_scope(), value);
+ changed = TRUE;
+ }
+ break;
+ default:
+ g_assert_not_reached();
+ break;
+ }
+
+ return changed;
+}
+
+range_t* prefs_get_range_value_real(pref_t *pref, pref_source_t source)
+{
+ switch (source)
+ {
+ case pref_default:
+ return pref->default_val.range;
+ case pref_stashed:
+ return pref->stashed_val.range;
+ break;
+ case pref_current:
+ return *pref->varp.range;
+ break;
+ default:
+ g_assert_not_reached();
+ break;
+ }
+
+ return NULL;
+}
+
+range_t* prefs_get_range_value(const char *module_name, const char* pref_name)
+{
+ return prefs_get_range_value_real(prefs_find_preference(prefs_find_module(module_name), pref_name), pref_current);
+}
+
+void
+prefs_range_add_value(pref_t *pref, guint32 val)
+{
+ range_add_value(wmem_epan_scope(), pref->varp.range, val);
+}
+
+void
+prefs_range_remove_value(pref_t *pref, guint32 val)
+{
+ range_remove_value(wmem_epan_scope(), pref->varp.range, val);
+}
+
+/*
+ * Register a static text 'preference'. It can be used to add explanatory
+ * text inline with other preferences in the GUI.
+ * Note: Static preferences are not saved to the preferences file.
+ */
+void
+prefs_register_static_text_preference(module_t *module, const char *name,
+ const char *title,
+ const char *description)
+{
+ register_preference(module, name, title, description, PREF_STATIC_TEXT);
+}
+
+/*
+ * Register a uat 'preference'. It adds a button that opens the uat's window in the
+ * preferences tab of the module.
+ */
+extern void
+prefs_register_uat_preference(module_t *module, const char *name,
+ const char *title, const char *description,
+ uat_t* uat)
+{
+
+ pref_t* preference = register_preference(module, name, title, description, PREF_UAT);
+
+ preference->varp.uat = uat;
+}
+
+/*
+ * Register a uat 'preference' for QT only. It adds a button that opens the uat's window in the
+ * preferences tab of the module.
+ */
+extern void
+prefs_register_uat_preference_qt(module_t *module, const char *name,
+ const char *title, const char *description,
+ uat_t* uat)
+{
+
+ pref_t* preference = register_preference(module, name, title, description, PREF_UAT);
+
+ preference->varp.uat = uat;
+
+ preference->gui = GUI_QT;
+}
+
+struct epan_uat* prefs_get_uat_value(pref_t *pref)
+{
+ return pref->varp.uat;
+}
+
+/*
+ * Register a color preference.
+ */
+void
+prefs_register_color_preference(module_t *module, const char *name,
+ const char *title, const char *description,
+ color_t *color)
+{
+ pref_t* preference = register_preference(module, name, title, description, PREF_COLOR);
+
+ preference->varp.colorp = color;
+ preference->default_val.color = *color;
+}
+
+gboolean prefs_set_color_value(pref_t *pref, color_t value, pref_source_t source)
+{
+ gboolean changed = FALSE;
+
+ switch (source)
+ {
+ case pref_default:
+ if ((pref->default_val.color.red != value.red) &&
+ (pref->default_val.color.green != value.green) &&
+ (pref->default_val.color.blue != value.blue)) {
+ changed = TRUE;
+ pref->default_val.color = value;
+ }
+ break;
+ case pref_stashed:
+ if ((pref->stashed_val.color.red != value.red) &&
+ (pref->stashed_val.color.green != value.green) &&
+ (pref->stashed_val.color.blue != value.blue)) {
+ changed = TRUE;
+ pref->stashed_val.color = value;
+ }
+ break;
+ case pref_current:
+ if ((pref->varp.colorp->red != value.red) &&
+ (pref->varp.colorp->green != value.green) &&
+ (pref->varp.colorp->blue != value.blue)) {
+ changed = TRUE;
+ *pref->varp.colorp = value;
+ }
+ break;
+ default:
+ g_assert_not_reached();
+ break;
+ }
+
+ return changed;
+}
+
+color_t* prefs_get_color_value(pref_t *pref, pref_source_t source)
+{
+ switch (source)
+ {
+ case pref_default:
+ return &pref->default_val.color;
+ case pref_stashed:
+ return &pref->stashed_val.color;
+ break;
+ case pref_current:
+ return pref->varp.colorp;
+ break;
+ default:
+ g_assert_not_reached();
+ break;
+ }
+
+ return NULL;
+}
+
+/*
+ * Register a "custom" preference with a list.
+ * XXX - This should be temporary until we can find a better way
+ * to do "custom" preferences
+ */
+typedef void (*pref_custom_list_init_cb) (pref_t* pref, GList** value);
+
+static void
+prefs_register_list_custom_preference(module_t *module, const char *name,
+ const char *title, const char *description,
+ struct pref_custom_cbs* custom_cbs,
+ pref_custom_list_init_cb init_cb,
+ GList** list)
+{
+ pref_t* preference = register_preference(module, name, title, description, PREF_CUSTOM);
+
+ preference->custom_cbs = *custom_cbs;
+ init_cb(preference, list);
+}
+
+/*
+ * Register a custom preference.
+ */
+void
+prefs_register_custom_preference(module_t *module, const char *name,
+ const char *title, const char *description,
+ struct pref_custom_cbs* custom_cbs,
+ void **custom_data _U_)
+{
+ pref_t* preference = register_preference(module, name, title, description, PREF_CUSTOM);
+
+ preference->custom_cbs = *custom_cbs;
+ /* XXX - wait until we can handle void** pointers
+ preference->custom_cbs.init_cb(preference, custom_data);
+ */
+}
+
+/*
+ * Register a (internal) "Decode As" preference with a ranged value.
+ */
+void prefs_register_decode_as_range_preference(module_t *module, const char *name,
+ const char *title, const char *description, range_t **var,
+ guint32 max_value)
+{
+ prefs_register_range_preference_common(module, name, title,
+ description, var, max_value, PREF_DECODE_AS_RANGE);
+}
+
+/*
+ * Register a (internal) "Decode As" preference with an unsigned integral value
+ * for a dissector table.
+ */
+void prefs_register_decode_as_preference(module_t *module, const char *name,
+ const char *title, const char *description, guint *var)
+{
+ pref_t *preference;
+
+ preference = register_preference(module, name, title, description,
+ PREF_DECODE_AS_UINT);
+ preference->varp.uint = var;
+ preference->default_val.uint = *var;
+ /* XXX - Presume base 10 for now */
+ preference->info.base = 10;
+}
+
+gboolean prefs_add_decode_as_value(pref_t *pref, guint value, gboolean replace)
+{
+ switch(pref->type)
+ {
+ case PREF_DECODE_AS_UINT:
+ /* This doesn't support multiple values for a dissector in Decode As because the
+ preference only supports a single value. This leads to a "last port for
+ dissector in Decode As wins" */
+ *pref->varp.uint = value;
+ break;
+ case PREF_DECODE_AS_RANGE:
+ if (replace)
+ {
+ /* If range has single value, replace it */
+ if (((*pref->varp.range)->nranges == 1) &&
+ ((*pref->varp.range)->ranges[0].low == (*pref->varp.range)->ranges[0].high)) {
+ wmem_free(wmem_epan_scope(), *pref->varp.range);
+ *pref->varp.range = range_empty(wmem_epan_scope());
+ }
+ }
+
+ prefs_range_add_value(pref, value);
+ break;
+ default:
+ /* XXX - Worth asserting over? */
+ break;
+ }
+
+ return TRUE;
+}
+
+gboolean prefs_remove_decode_as_value(pref_t *pref, guint value, gboolean set_default)
+{
+ switch(pref->type)
+ {
+ case PREF_DECODE_AS_UINT:
+ if (set_default) {
+ *pref->varp.uint = pref->default_val.uint;
+ } else {
+ *pref->varp.uint = 0;
+ }
+ break;
+ case PREF_DECODE_AS_RANGE:
+ prefs_range_remove_value(pref, value);
+ break;
+ default:
+ break;
+ }
+
+ return TRUE;
+}
+
+/*
+ * Register a preference that used to be supported but no longer is.
+ */
+void
+prefs_register_obsolete_preference(module_t *module, const char *name)
+{
+ register_preference(module, name, NULL, NULL, PREF_OBSOLETE);
+}
+
+/*
+ * Check to see if a preference is obsolete.
+ */
+extern gboolean
+prefs_get_preference_obsolete(pref_t *pref)
+{
+ if (pref)
+ return (IS_PREF_OBSOLETE(pref->type) ? TRUE : FALSE);
+
+ return TRUE;
+}
+
+/*
+ * Make a preference obsolete.
+ */
+extern prefs_set_pref_e
+prefs_set_preference_obsolete(pref_t *pref)
+{
+ if (pref) {
+ SET_PREF_OBSOLETE(pref->type);
+ return PREFS_SET_OK;
+ }
+ return PREFS_SET_NO_SUCH_PREF;
+}
+
+guint
+pref_stash(pref_t *pref, gpointer unused _U_)
+{
+ switch (pref->type) {
+
+ case PREF_DECODE_AS_UINT:
+ pref->stashed_val.uint = *pref->varp.uint;
+ break;
+
+ case PREF_UINT:
+ pref->stashed_val.uint = *pref->varp.uint;
+ break;
+
+ case PREF_BOOL:
+ pref->stashed_val.boolval = *pref->varp.boolp;
+ break;
+
+ case PREF_ENUM:
+ pref->stashed_val.enumval = *pref->varp.enump;
+ break;
+
+ case PREF_STRING:
+ case PREF_FILENAME:
+ case PREF_DIRNAME:
+ g_free(pref->stashed_val.string);
+ pref->stashed_val.string = g_strdup(*pref->varp.string);
+ break;
+
+ case PREF_DECODE_AS_RANGE:
+ case PREF_RANGE:
+ wmem_free(wmem_epan_scope(), pref->stashed_val.range);
+ pref->stashed_val.range = range_copy(wmem_epan_scope(), *pref->varp.range);
+ break;
+
+ case PREF_COLOR:
+ pref->stashed_val.color = *pref->varp.colorp;
+ break;
+
+ case PREF_STATIC_TEXT:
+ case PREF_UAT:
+ case PREF_CUSTOM:
+ break;
+
+ case PREF_OBSOLETE:
+ g_assert_not_reached();
+ break;
+ }
+ return 0;
+}
+
+guint
+pref_unstash(pref_t *pref, gpointer unstash_data_p)
+{
+ pref_unstash_data_t *unstash_data = (pref_unstash_data_t *)unstash_data_p;
+ dissector_table_t sub_dissectors = NULL;
+ dissector_handle_t handle = NULL;
+
+ /* Revert the preference to its saved value. */
+ switch (pref->type) {
+
+ case PREF_DECODE_AS_UINT:
+ if (*pref->varp.uint != pref->stashed_val.uint) {
+ unstash_data->module->prefs_changed = TRUE;
+
+ if (unstash_data->handle_decode_as) {
+ if (*pref->varp.uint != pref->default_val.uint) {
+ dissector_reset_uint(pref->name, *pref->varp.uint);
+ }
+ }
+
+ *pref->varp.uint = pref->stashed_val.uint;
+
+ if (unstash_data->handle_decode_as) {
+ sub_dissectors = find_dissector_table(pref->name);
+ if (sub_dissectors != NULL) {
+ handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)unstash_data->module->title);
+ if (handle != NULL) {
+ dissector_change_uint(pref->name, *pref->varp.uint, handle);
+ }
+ }
+ }
+ }
+ break;
+
+ case PREF_UINT:
+ if (*pref->varp.uint != pref->stashed_val.uint) {
+ unstash_data->module->prefs_changed = TRUE;
+ *pref->varp.uint = pref->stashed_val.uint;
+ }
+ break;
+
+ case PREF_BOOL:
+ if (*pref->varp.boolp != pref->stashed_val.boolval) {
+ unstash_data->module->prefs_changed = TRUE;
+ *pref->varp.boolp = pref->stashed_val.boolval;
+ }
+ break;
+
+ case PREF_ENUM:
+ if (*pref->varp.enump != pref->stashed_val.enumval) {
+ unstash_data->module->prefs_changed = TRUE;
+ *pref->varp.enump = pref->stashed_val.enumval;
+ }
+ break;
+
+ case PREF_STRING:
+ case PREF_FILENAME:
+ case PREF_DIRNAME:
+ if (strcmp(*pref->varp.string, pref->stashed_val.string) != 0) {
+ unstash_data->module->prefs_changed = TRUE;
+ g_free(*pref->varp.string);
+ *pref->varp.string = g_strdup(pref->stashed_val.string);
+ }
+ break;
+
+ case PREF_DECODE_AS_RANGE:
+ if (!ranges_are_equal(*pref->varp.range, pref->stashed_val.range)) {
+ guint32 i, j;
+ unstash_data->module->prefs_changed = TRUE;
+
+ if (unstash_data->handle_decode_as) {
+ sub_dissectors = find_dissector_table(pref->name);
+ if (sub_dissectors != NULL) {
+ handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)unstash_data->module->title);
+ if (handle != NULL) {
+ /* Delete all of the old values from the dissector table */
+ for (i = 0; i < (*pref->varp.range)->nranges; i++) {
+ for (j = (*pref->varp.range)->ranges[i].low; j < (*pref->varp.range)->ranges[i].high; j++) {
+ dissector_delete_uint(pref->name, j, handle);
+ decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(j), NULL, NULL);
+ }
+
+ dissector_delete_uint(pref->name, (*pref->varp.range)->ranges[i].high, handle);
+ decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER((*pref->varp.range)->ranges[i].high), NULL, NULL);
+ }
+ }
+ }
+ }
+
+ wmem_free(wmem_epan_scope(), *pref->varp.range);
+ *pref->varp.range = range_copy(wmem_epan_scope(), pref->stashed_val.range);
+
+ if (unstash_data->handle_decode_as) {
+ if ((sub_dissectors != NULL) && (handle != NULL)) {
+
+ /* Add new values to the dissector table */
+ for (i = 0; i < (*pref->varp.range)->nranges; i++) {
+
+ for (j = (*pref->varp.range)->ranges[i].low; j < (*pref->varp.range)->ranges[i].high; j++) {
+ dissector_change_uint(pref->name, j, handle);
+ decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(j), NULL, NULL);
+ }
+
+ dissector_change_uint(pref->name, (*pref->varp.range)->ranges[i].high, handle);
+ decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER((*pref->varp.range)->ranges[i].high), NULL, NULL);
+ }
+ }
+ }
+ }
+ break;
+
+ case PREF_RANGE:
+ if (!ranges_are_equal(*pref->varp.range, pref->stashed_val.range)) {
+ unstash_data->module->prefs_changed = TRUE;
+ wmem_free(wmem_epan_scope(), *pref->varp.range);
+ *pref->varp.range = range_copy(wmem_epan_scope(), pref->stashed_val.range);
+ }
+ break;
+
+ case PREF_COLOR:
+ *pref->varp.colorp = pref->stashed_val.color;
+ break;
+
+ case PREF_STATIC_TEXT:
+ case PREF_UAT:
+ case PREF_CUSTOM:
+ break;
+
+ case PREF_OBSOLETE:
+ g_assert_not_reached();
+ break;
+ }
+ return 0;
}
-/*
- * Register a uat 'preference' for QT only. It adds a button that opens the uat's window in the
- * preferences tab of the module.
- */
-extern void
-prefs_register_uat_preference_qt(module_t *module, const char *name,
- const char *title, const char *description,
- uat_t* uat)
-{
+void
+reset_stashed_pref(pref_t *pref) {
+ switch (pref->type) {
- pref_t* preference = register_preference(module, name, title, description, PREF_UAT);
+ case PREF_DECODE_AS_UINT:
+ pref->stashed_val.uint = pref->default_val.uint;
+ break;
- preference->varp.uat = uat;
+ case PREF_UINT:
+ pref->stashed_val.uint = pref->default_val.uint;
+ break;
- preference->gui = GUI_QT;
-}
+ case PREF_BOOL:
+ pref->stashed_val.boolval = pref->default_val.boolval;
+ break;
-/*
- * Register a color preference.
- */
-void
-prefs_register_color_preference(module_t *module, const char *name,
- const char *title, const char *description,
- color_t *color)
-{
- pref_t* preference = register_preference(module, name, title, description, PREF_COLOR);
+ case PREF_ENUM:
+ pref->stashed_val.enumval = pref->default_val.enumval;
+ break;
- preference->varp.colorp = color;
- preference->default_val.color = *color;
-}
+ case PREF_STRING:
+ case PREF_FILENAME:
+ case PREF_DIRNAME:
+ g_free(pref->stashed_val.string);
+ pref->stashed_val.string = g_strdup(pref->default_val.string);
+ break;
-/*
- * Register a "custom" preference with a list.
- * XXX - This should be temporary until we can find a better way
- * to do "custom" preferences
- */
-typedef void (*pref_custom_list_init_cb) (pref_t* pref, GList** value);
+ case PREF_DECODE_AS_RANGE:
+ case PREF_RANGE:
+ wmem_free(wmem_epan_scope(), pref->stashed_val.range);
+ pref->stashed_val.range = range_copy(wmem_epan_scope(), pref->default_val.range);
+ break;
-static void
-prefs_register_list_custom_preference(module_t *module, const char *name,
- const char *title, const char *description,
- struct pref_custom_cbs* custom_cbs,
- pref_custom_list_init_cb init_cb,
- GList** list)
-{
- pref_t* preference = register_preference(module, name, title, description, PREF_CUSTOM);
+ case PREF_COLOR:
+ memcpy(&pref->stashed_val.color, &pref->default_val.color, sizeof(color_t));
+ break;
- preference->custom_cbs = *custom_cbs;
- init_cb(preference, list);
+ case PREF_STATIC_TEXT:
+ case PREF_UAT:
+ case PREF_CUSTOM:
+ break;
+
+ case PREF_OBSOLETE:
+ g_assert_not_reached();
+ break;
+ }
}
-/*
- * Register a custom preference.
- */
-void
-prefs_register_custom_preference(module_t *module, const char *name,
- const char *title, const char *description,
- struct pref_custom_cbs* custom_cbs,
- void **custom_data _U_)
+guint
+pref_clean_stash(pref_t *pref, gpointer unused _U_)
{
- pref_t* preference = register_preference(module, name, title, description, PREF_CUSTOM);
+ switch (pref->type) {
- preference->custom_cbs = *custom_cbs;
- /* XXX - wait until we can handle void** pointers
- preference->custom_cbs.init_cb(preference, custom_data);
- */
-}
+ case PREF_UINT:
+ case PREF_DECODE_AS_UINT:
+ break;
-/*
- * Register a preference that used to be supported but no longer is.
- */
-void
-prefs_register_obsolete_preference(module_t *module, const char *name)
-{
- register_preference(module, name, NULL, NULL, PREF_OBSOLETE);
-}
+ case PREF_BOOL:
+ break;
-/*
- * Check to see if a preference is obsolete.
- */
-extern gboolean
-prefs_get_preference_obsolete(pref_t *pref)
-{
- if (pref)
- return pref->type == PREF_OBSOLETE ? TRUE : FALSE;
+ case PREF_ENUM:
+ break;
- return TRUE;
-}
+ case PREF_STRING:
+ case PREF_FILENAME:
+ case PREF_DIRNAME:
+ if (pref->stashed_val.string != NULL) {
+ g_free(pref->stashed_val.string);
+ pref->stashed_val.string = NULL;
+ }
+ break;
-/*
- * Make a preference obsolete.
- */
-extern prefs_set_pref_e
-prefs_set_preference_obsolete(pref_t *pref)
-{
- if (pref) {
- pref->type = PREF_OBSOLETE;
- return PREFS_SET_OK;
+ case PREF_DECODE_AS_RANGE:
+ case PREF_RANGE:
+ if (pref->stashed_val.range != NULL) {
+ wmem_free(wmem_epan_scope(), pref->stashed_val.range);
+ pref->stashed_val.range = NULL;
+ }
+ break;
+
+ case PREF_STATIC_TEXT:
+ case PREF_UAT:
+ case PREF_COLOR:
+ case PREF_CUSTOM:
+ break;
+
+ case PREF_OBSOLETE:
+ g_assert_not_reached();
+ break;
}
- return PREFS_SET_NO_SUCH_PREF;
+ return 0;
}
#if 0
for (elem = g_list_first(module->prefs); elem != NULL; elem = g_list_next(elem)) {
pref = (pref_t *)elem->data;
- if (pref->type == PREF_OBSOLETE) {
+ if (IS_PREF_OBSOLETE(pref->type)) {
/*
* This preference is no longer supported; it's
* not a real preference, so we don't call the
#define PRS_COL_NUM "column.number"
static module_t *gui_column_module = NULL;
-static void
-column_hidden_free_cb(pref_t* pref)
-{
- g_free((char *)*pref->varp.string);
- *pref->varp.string = NULL;
- g_free(pref->default_val.string);
- pref->default_val.string = NULL;
-}
-
-static void
-column_hidden_reset_cb(pref_t* pref)
-{
- g_free((void *)*pref->varp.string);
- *pref->varp.string = g_strdup(pref->default_val.string);
-}
-
static prefs_set_pref_e
column_hidden_set_cb(pref_t* pref, const gchar* value, gboolean* changed)
{
fmt_data *cfmt;
pref_t *format_pref;
- if (*pref->varp.string) {
- if (strcmp(*pref->varp.string, value) != 0) {
- *changed = TRUE;
- g_free((void *)*pref->varp.string);
- *pref->varp.string = g_strdup(value);
- }
- } else if (value) {
- *pref->varp.string = g_strdup(value);
- }
+ (*changed) |= prefs_set_string_value(pref, value, pref_current);
/*
* Set the "visible" flag for the existing columns; we need to
while (clp) {
gchar *prefs_fmt;
cfmt = (fmt_data *) clp->data;
- if ((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_field)) {
+ if ((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_fields)) {
prefs_fmt = g_strdup_printf("%s:%s:%d:%c",
col_format_to_string(cfmt->fmt),
- cfmt->custom_field,
+ cfmt->custom_fields,
cfmt->custom_occurrence,
cfmt->resolved ? 'R' : 'U');
} else {
g_string_append (cols_hidden, ",");
g_string_append (cols_hidden, prefs_fmt);
}
+ g_free(prefs_fmt);
clp = clp->next;
}
dest_cfmt = g_new(fmt_data,1);
dest_cfmt->title = g_strdup(src_cfmt->title);
dest_cfmt->fmt = src_cfmt->fmt;
- if (src_cfmt->custom_field) {
- dest_cfmt->custom_field = g_strdup(src_cfmt->custom_field);
+ if (src_cfmt->custom_fields) {
+ dest_cfmt->custom_fields = g_strdup(src_cfmt->custom_fields);
dest_cfmt->custom_occurrence = src_cfmt->custom_occurrence;
} else {
- dest_cfmt->custom_field = NULL;
+ dest_cfmt->custom_fields = NULL;
dest_cfmt->custom_occurrence = 0;
}
dest_cfmt->visible = src_cfmt->visible;
dest_cfmt = g_new(fmt_data,1);
dest_cfmt->title = g_strdup(src_cfmt->title);
dest_cfmt->fmt = src_cfmt->fmt;
- if (src_cfmt->custom_field) {
- dest_cfmt->custom_field = g_strdup(src_cfmt->custom_field);
+ if (src_cfmt->custom_fields) {
+ dest_cfmt->custom_fields = g_strdup(src_cfmt->custom_fields);
dest_cfmt->custom_occurrence = src_cfmt->custom_occurrence;
} else {
- dest_cfmt->custom_field = NULL;
+ dest_cfmt->custom_fields = NULL;
dest_cfmt->custom_occurrence = 0;
}
dest_cfmt->visible = src_cfmt->visible;
try_convert_to_custom_column(&col_l_elt->data);
} else {
/* We don't need the custom column field on this pass. */
- g_free(cfmt_check.custom_field);
+ g_free(cfmt_check.custom_fields);
}
/* Go past the format. */
}
prefs_clear_string_list(col_l);
- column_hidden_free_cb(hidden_pref);
+ free_string_like_preference(hidden_pref);
return PREFS_SET_OK;
}
def_cfmt = (fmt_data *) def_col->data;
if ((g_strcmp0(cfmt->title, def_cfmt->title) != 0) ||
(cfmt->fmt != def_cfmt->fmt) ||
- (((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_field)) &&
- ((g_strcmp0(cfmt->custom_field, def_cfmt->custom_field) != 0) ||
+ (((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_fields)) &&
+ ((g_strcmp0(cfmt->custom_fields, def_cfmt->custom_fields) != 0) ||
(cfmt->resolved != def_cfmt->resolved)))) {
is_default = FALSE;
break;
while (clp) {
cfmt = (fmt_data *) clp->data;
col_l = g_list_append(col_l, g_strdup(cfmt->title));
- if ((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_field)) {
+ if ((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_fields)) {
prefs_fmt = g_strdup_printf("%s:%s:%d:%c",
col_format_to_string(cfmt->fmt),
- cfmt->custom_field,
+ cfmt->custom_fields,
cfmt->custom_occurrence,
cfmt->resolved ? 'R' : 'U');
} else {
static void
capture_column_free_cb(pref_t* pref)
{
- GList *clist = prefs.capture_columns;
- gchar *col_name;
-
- while (clist) {
- col_name = (gchar *)clist->data;
- g_free(col_name);
- clist = g_list_remove_link(clist, clist);
- }
- g_list_free(clist);
+ prefs_clear_string_list(prefs.capture_columns);
prefs.capture_columns = NULL;
if (pref->stashed_val.boolval == TRUE) {
- GList *dlist;
- gchar *col;
-
- dlist = pref->default_val.list;
- while (dlist != NULL) {
- col = (gchar *)dlist->data;
- g_free(col);
- dlist = g_list_remove_link(dlist, dlist);
- }
- g_list_free(dlist);
- dlist = NULL;
+ prefs_clear_string_list(pref->default_val.list);
+ pref->default_val.list = NULL;
}
}
static void
capture_column_reset_cb(pref_t* pref)
{
- GList *vlist, *dlist;
- gchar *vcol;
+ GList *vlist = NULL, *dlist;
/* Free the column name strings and remove the links from *pref->varp.list */
- vlist = *pref->varp.list;
- while (vlist != NULL) {
- vcol = (gchar *)vlist->data;
- g_free(vcol);
- vlist = g_list_remove_link(vlist, vlist);
- }
- g_list_free(vlist);
- vlist = NULL;
+ prefs_clear_string_list(*pref->varp.list);
for (dlist = pref->default_val.list; dlist != NULL; dlist = g_list_next(dlist)) {
vlist = g_list_append(vlist, g_strdup((gchar *)dlist->data));
static prefs_set_pref_e
capture_column_set_cb(pref_t* pref, const gchar* value, gboolean* changed _U_)
{
- GList *col_l = prefs_get_string_list(value);
- GList *col_l_elt;
- gchar *col_name;
+ GList *col_l = prefs_get_string_list(value);
+ GList *col_l_elt;
+ gchar *col_name;
int i;
if (col_l == NULL)
prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
}
pref->varp.list = &prefs.capture_columns;
+ prefs_clear_string_list(col_l);
return PREFS_SET_SYNTAX_ERR;
}
col_l_elt = col_l_elt->next;
col_l_elt = col_l_elt->next;
}
pref->varp.list = &prefs.capture_columns;
+ g_list_free(col_l);
return PREFS_SET_OK;
}
return capture_column_str;
}
-
-static void
-colorized_frame_free_cb(pref_t* pref)
-{
- g_free((char *)*pref->varp.string);
- *pref->varp.string = NULL;
- g_free(pref->default_val.string);
- pref->default_val.string = NULL;
-
-}
-
-static void
-colorized_frame_reset_cb(pref_t* pref)
-{
- g_free((void *)*pref->varp.string);
- *pref->varp.string = g_strdup(pref->default_val.string);
-}
-
static prefs_set_pref_e
colorized_frame_set_cb(pref_t* pref, const gchar* value, gboolean* changed)
{
- if (strcmp(*pref->varp.string, value) != 0) {
- *changed = TRUE;
- g_free((void *)*pref->varp.string);
- *pref->varp.string = g_strdup(value);
- }
-
+ (*changed) |= prefs_set_string_value(pref, value, pref_current);
return PREFS_SET_OK;
}
static module_t *gui_color_module = NULL;
static module_t *nameres_module = NULL;
-void
+static void
prefs_register_modules(void)
{
module_t *printing, *capture_module, *console_module,
*gui_layout_module, *gui_font_module;
+#ifdef HAVE_EXTCAP
+ module_t *extcap_module;
+#endif
+
struct pref_custom_cbs custom_cbs;
if (protocols_module != NULL) {
return;
}
- /* Ensure the "global" preferences have been initialized so the
- * preference API has the proper default values to work from
+#ifdef HAVE_EXTCAP
+ /* GUI
+ * These are "simple" GUI preferences that can be read/written using the
+ * preference module API. These preferences still use their own
+ * configuration screens for access, but this cuts down on the
+ * preference "string compare list" in set_pref()
*/
- pre_init_prefs();
+ extcap_module = prefs_register_module(NULL, "extcap", "Extcap Utilities",
+ "Extcap Utilities", NULL, FALSE);
+
+ /* Setting default value to true */
+ prefs.extcap_save_on_start = TRUE;
+ prefs_register_bool_preference(extcap_module, "gui_save_on_start",
+ "Save arguments on start of capture",
+ "Save arguments on start of capture",
+ &prefs.extcap_save_on_start);
+#endif
/* GUI
* These are "simple" GUI preferences that can be read/written using the
*/
prefs_register_enum_preference(gui_module, "console_open",
"Open a console window",
- "Open a console window (WIN32 only)",
+ "Open a console window (Windows only)",
(gint*)(void*)(&prefs.gui_console_open), gui_console_open_type, FALSE);
prefs_register_obsolete_preference(gui_module, "scrollbar_on_right");
gui_column_module = prefs_register_subtree(gui_module, "Columns", "Columns", NULL);
- custom_cbs.free_cb = column_hidden_free_cb;
- custom_cbs.reset_cb = column_hidden_reset_cb;
+ custom_cbs.free_cb = free_string_like_preference;
+ custom_cbs.reset_cb = reset_string_like_preference;
custom_cbs.set_cb = column_hidden_set_cb;
custom_cbs.type_name_cb = column_hidden_type_name_cb;
custom_cbs.type_description_cb = column_hidden_type_description_cb;
custom_cbs.is_default_cb = column_hidden_is_default_cb;
custom_cbs.to_str_cb = column_hidden_to_str_cb;
- prefs_register_string_custom_preference(gui_column_module, PRS_COL_HIDDEN, "Packet list hidden columns",
- "List all columns to hide in the packet list", &custom_cbs, (const char **)&cols_hidden_list);
+ register_string_like_preference(gui_column_module, PRS_COL_HIDDEN, "Packet list hidden columns",
+ "List all columns to hide in the packet list",
+ &cols_hidden_list, PREF_CUSTOM, &custom_cbs, FALSE);
custom_cbs.free_cb = column_format_free_cb;
custom_cbs.reset_cb = column_format_reset_cb;
prefs_register_obsolete_preference(gui_font_module, "font_name");
- prefs_register_string_preference(gui_font_module, "gtk2.font_name", "Font name",
- "Font name for packet list, protocol tree, and hex dump panes. (GTK+)", (const char **)&prefs.gui_gtk2_font_name);
+ register_string_like_preference(gui_font_module, "gtk2.font_name", "Font name",
+ "Font name for packet list, protocol tree, and hex dump panes. (GTK+)",
+ &prefs.gui_gtk2_font_name, PREF_STRING, NULL, TRUE);
- prefs_register_string_preference(gui_font_module, "qt.font_name", "Font name",
- "Font name for packet list, protocol tree, and hex dump panes. (Qt)", (const char **)&prefs.gui_qt_font_name);
+ register_string_like_preference(gui_font_module, "qt.font_name", "Font name",
+ "Font name for packet list, protocol tree, and hex dump panes. (Qt)",
+ &prefs.gui_qt_font_name, PREF_STRING, NULL, TRUE);
/* User Interface : Colors */
gui_color_module = prefs_register_subtree(gui_module, "Colors", "Colors", NULL);
prefs_register_color_preference(gui_color_module, "stream.server.bg", "TCP stream window color preference",
"TCP stream window color preference", &prefs.st_server_bg);
- custom_cbs.free_cb = colorized_frame_free_cb;
- custom_cbs.reset_cb = colorized_frame_reset_cb;
+ custom_cbs.free_cb = free_string_like_preference;
+ custom_cbs.reset_cb = reset_string_like_preference;
custom_cbs.set_cb = colorized_frame_set_cb;
custom_cbs.type_name_cb = colorized_frame_type_name_cb;
custom_cbs.type_description_cb = colorized_frame_type_description_cb;
custom_cbs.is_default_cb = colorized_frame_is_default_cb;
custom_cbs.to_str_cb = colorized_frame_to_str_cb;
- prefs_register_string_custom_preference(gui_column_module, "colorized_frame.fg", "Colorized Foreground",
- "Filter Colorized Foreground", &custom_cbs, (const char **)&prefs.gui_colorized_fg);
+ register_string_like_preference(gui_column_module, "colorized_frame.fg", "Colorized Foreground",
+ "Filter Colorized Foreground",
+ &prefs.gui_colorized_fg, PREF_CUSTOM, &custom_cbs, TRUE);
- custom_cbs.free_cb = colorized_frame_free_cb;
- custom_cbs.reset_cb = colorized_frame_reset_cb;
+ custom_cbs.free_cb = free_string_like_preference;
+ custom_cbs.reset_cb = reset_string_like_preference;
custom_cbs.set_cb = colorized_frame_set_cb;
custom_cbs.type_name_cb = colorized_frame_type_name_cb;
custom_cbs.type_description_cb = colorized_frame_type_description_cb;
custom_cbs.is_default_cb = colorized_frame_is_default_cb;
custom_cbs.to_str_cb = colorized_frame_to_str_cb;
- prefs_register_string_custom_preference(gui_column_module, "colorized_frame.bg", "Colorized Background",
- "Filter Colorized Background", &custom_cbs, (const char **)&prefs.gui_colorized_bg);
+ register_string_like_preference(gui_column_module, "colorized_frame.bg", "Colorized Background",
+ "Filter Colorized Background",
+ &prefs.gui_colorized_bg, PREF_CUSTOM, &custom_cbs, TRUE);
prefs_register_color_preference(gui_color_module, "color_filter_bg.valid", "Valid color filter background",
"Valid color filter background", &prefs.gui_text_valid);
10,
&prefs.gui_recent_df_entries_max);
- prefs_register_directory_preference(gui_module, "fileopen.dir", "Start Directory",
- "Directory to start in when opening File Open dialog.", (const char **)&prefs.gui_fileopen_dir);
+ register_string_like_preference(gui_module, "fileopen.dir", "Start Directory",
+ "Directory to start in when opening File Open dialog.",
+ &prefs.gui_fileopen_dir, PREF_DIRNAME, NULL, TRUE);
prefs_register_obsolete_preference(gui_module, "fileopen.remembered_dir");
"Save window maximized state at exit?",
&prefs.gui_geometry_save_maximized);
+ /* GTK+ only */
prefs_register_bool_preference(gui_module, "macosx_style",
- "Use Mac OS X style",
- "Use Mac OS X style (Mac OS X with native GTK only)?",
+ "Use OS X style",
+ "Use OS X style (OS X with native GTK only)?",
&prefs.gui_macosx_style);
prefs_register_obsolete_preference(gui_module, "geometry.main.x");
"Filter Toolbar style",
&prefs.gui_toolbar_filter_style, gui_toolbar_style, FALSE);
- prefs_register_string_preference(gui_module, "webbrowser", "The path to the webbrowser",
- "The path to the webbrowser (Ex: mozilla)", (const char **)&prefs.gui_webbrowser);
+ register_string_like_preference(gui_module, "webbrowser", "The path to the webbrowser",
+ "The path to the webbrowser (Ex: mozilla)",
+ &prefs.gui_webbrowser, PREF_STRING, NULL, TRUE);
prefs_register_bool_preference(gui_module, "update.enabled",
"Check for updates",
10,
&prefs.gui_update_interval);
- prefs_register_string_preference(gui_module, "window_title", "Custom window title",
- "Custom window title. (Appended to existing titles.)", (const char **)&prefs.gui_window_title);
+ register_string_like_preference(gui_module, "window_title", "Custom window title",
+ "Custom window title to be appended to the existing title\n%P = profile name\n%V = version info",
+ &prefs.gui_window_title, PREF_STRING, NULL, TRUE);
+
+ register_string_like_preference(gui_module, "prepend_window_title", "Custom window title prefix",
+ "Custom window title to be prepended to the existing title\n%P = profile name\n%V = version info",
+ &prefs.gui_prepend_window_title, PREF_STRING, NULL, TRUE);
- prefs_register_string_preference(gui_module, "start_title", "Custom start page title",
- "Custom start page title", (const char**)(&prefs.gui_start_title));
+ register_string_like_preference(gui_module, "start_title", "Custom start page title",
+ "Custom start page title",
+ &prefs.gui_start_title, PREF_STRING, NULL, TRUE);
prefs_register_enum_preference(gui_module, "version_placement",
"Show version in the start page and/or main screen's title bar",
(gint*)(void*)(&prefs.gui_version_placement), gui_version_placement_type, FALSE);
prefs_register_bool_preference(gui_module, "auto_scroll_on_expand",
- "Automatically scroll the recently expanded item",
- "Automatically scroll the recently expanded item",
+ "Automatically scroll packet details",
+ "When selecting a new packet, automatically scroll"
+ "to the packet detail item that matches the most"
+ "recently selected item",
&prefs.gui_auto_scroll_on_expand);
prefs_register_uint_preference(gui_module, "auto_scroll_percentage",
- "The percentage down the view the recently expanded item should be scrolled",
- "The percentage down the view the recently expanded item should be scrolled",
+ "Packet detail scroll percentage",
+ "The percentage down the view the recently expanded detail item should be scrolled",
10,
&prefs.gui_auto_scroll_percentage);
"Layout content of the pane 3",
(gint*)(void*)(&prefs.gui_layout_content_3), gui_layout_content, FALSE);
+ prefs_register_bool_preference(gui_layout_module, "packet_list_separator.enabled",
+ "Enable Packet List Separator",
+ "Enable Packet List Separator",
+ &prefs.gui_qt_packet_list_separator);
+
prefs_register_bool_preference(gui_module, "packet_editor.enabled",
"Enable Packet Editor",
"Enable Packet Editor (Experimental)",
&prefs.gui_packet_editor);
+
+ prefs_register_enum_preference(gui_module, "packet_list_elide_mode",
+ "Elide mode",
+ "The position of \"...\" in packet list text.",
+ (gint*)(void*)(&prefs.gui_packet_list_elide_mode), gui_packet_list_elide_mode, FALSE);
+
+ prefs_register_bool_preference(gui_layout_module, "packet_list_show_related",
+ "Show Related Packets",
+ "Show related packet indicators in the first column",
+ &prefs.gui_packet_list_show_related);
+
+ prefs_register_bool_preference(gui_layout_module, "packet_list_show_minimap",
+ "Enable Intelligent Scroll Bar",
+ "Show the intelligent scroll bar (a minimap of packet list colors in the scrollbar)",
+ &prefs.gui_packet_list_show_minimap);
+
+
+ prefs_register_bool_preference(gui_module, "interfaces_show_hidden",
+ "Show hidden interfaces",
+ "Show all interfaces, including interfaces marked as hidden",
+ &prefs.gui_interfaces_show_hidden);
+
+#ifdef HAVE_PCAP_REMOTE
+ prefs_register_bool_preference(gui_module, "interfaces_remote_display",
+ "Show Remote interfaces",
+ "Show remote interfaces in the interface selection",
+ &prefs.gui_interfaces_remote_display);
+#endif
+
+ register_string_like_preference(gui_module, "interfaces_hidden_types", "Hide interface types in list",
+ "Hide the given interface types in the startup list",
+ &prefs.gui_interfaces_hide_types, PREF_STRING, NULL, TRUE);
+
/* Console
* These are preferences that can be read/written using the
* preference module API. These preferences still use their own
* preference "string compare list" in set_pref()
*/
console_module = prefs_register_module(NULL, "console", "Console",
- "CONSOLE", NULL, FALSE);
+ "Console logging and debugging output", NULL, FALSE);
custom_cbs.free_cb = custom_pref_no_cb;
custom_cbs.reset_cb = console_log_level_reset_cb;
custom_cbs.is_default_cb = console_log_level_is_default_cb;
custom_cbs.to_str_cb = console_log_level_to_str_cb;
prefs_register_uint_custom_preference(console_module, "log.level", "logging level",
- "A bitmask of glib log levels", &custom_cbs, &prefs.console_log_level);
+ "A bitmask of GLib log levels", &custom_cbs, &prefs.console_log_level);
+
+ prefs_register_bool_preference(console_module, "incomplete_dissectors_check_debug",
+ "Print debug line for incomplete dissectors",
+ "Look for dissectors that left some bytes undecoded (debug)",
+ &prefs.incomplete_dissectors_check_debug);
/* Capture
* These are preferences that can be read/written using the
* preference "string compare list" in set_pref()
*/
capture_module = prefs_register_module(NULL, "capture", "Capture",
- "CAPTURE", NULL, FALSE);
+ "Capture preferences", NULL, FALSE);
- prefs_register_string_preference(capture_module, "device", "Default capture device",
- "Default capture device", (const char **)&prefs.capture_device);
+ register_string_like_preference(capture_module, "device", "Default capture device",
+ "Default capture device",
+ &prefs.capture_device, PREF_STRING, NULL, FALSE);
- prefs_register_string_preference(capture_module, "devices_linktypes", "Interface link-layer header type",
+ register_string_like_preference(capture_module, "devices_linktypes", "Interface link-layer header type",
"Interface link-layer header types (Ex: en0(1),en1(143),...)",
- (const char **)&prefs.capture_devices_linktypes);
+ &prefs.capture_devices_linktypes, PREF_STRING, NULL, FALSE);
- prefs_register_string_preference(capture_module, "devices_descr", "Interface descriptions",
+ register_string_like_preference(capture_module, "devices_descr", "Interface descriptions",
"Interface descriptions (Ex: eth0(eth0 descr),eth1(eth1 descr),...)",
- (const char **)&prefs.capture_devices_descr);
+ &prefs.capture_devices_descr, PREF_STRING, NULL, FALSE);
- prefs_register_string_preference(capture_module, "devices_hide", "Hide interface",
- "Hide interface? (Ex: eth0,eth3,...)", (const char **)&prefs.capture_devices_hide);
+ register_string_like_preference(capture_module, "devices_hide", "Hide interface",
+ "Hide interface? (Ex: eth0,eth3,...)",
+ &prefs.capture_devices_hide, PREF_STRING, NULL, FALSE);
- prefs_register_string_preference(capture_module, "devices_monitor_mode", "Capture in monitor mode",
+ register_string_like_preference(capture_module, "devices_monitor_mode", "Capture in monitor mode",
"By default, capture in monitor mode on interface? (Ex: eth0,eth3,...)",
- (const char **)&prefs.capture_devices_monitor_mode);
+ &prefs.capture_devices_monitor_mode, PREF_STRING, NULL, FALSE);
-#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
- prefs_register_string_preference(capture_module, "devices_buffersize", "Interface buffer size",
+#ifdef CAN_SET_CAPTURE_BUFFER_SIZE
+ register_string_like_preference(capture_module, "devices_buffersize", "Interface buffer size",
"Interface buffer size (Ex: en0(1),en1(143),...)",
- ((const char **)&prefs.capture_devices_buffersize));
+ &prefs.capture_devices_buffersize, PREF_STRING, NULL, FALSE);
#endif
- prefs_register_string_preference(capture_module, "devices_snaplen", "Interface snap length",
+ register_string_like_preference(capture_module, "devices_snaplen", "Interface snap length",
"Interface snap length (Ex: en0(65535),en1(1430),...)",
- (const char **)&prefs.capture_devices_snaplen);
+ &prefs.capture_devices_snaplen, PREF_STRING, NULL, FALSE);
- prefs_register_string_preference(capture_module, "devices_pmode", "Interface promiscuous mode",
+ register_string_like_preference(capture_module, "devices_pmode", "Interface promiscuous mode",
"Interface promiscuous mode (Ex: en0(0),en1(1),...)",
- (const char **)&prefs.capture_devices_pmode);
+ &prefs.capture_devices_pmode, PREF_STRING, NULL, FALSE);
prefs_register_bool_preference(capture_module, "prom_mode", "Capture in promiscuous mode",
"Capture in promiscuous mode?", &prefs.capture_prom_mode);
- prefs_register_string_preference(capture_module, "devices_filter", "Interface capture filter",
+ register_string_like_preference(capture_module, "devices_filter", "Interface capture filter",
"Interface capture filter (Ex: en0(tcp),en1(udp),...)",
- (const char **)&prefs.capture_devices_filter);
+ &prefs.capture_devices_filter, PREF_STRING, NULL, FALSE);
prefs_register_bool_preference(capture_module, "pcap_ng", "Capture in Pcap-NG format",
"Capture in Pcap-NG format?", &prefs.capture_pcap_ng);
prefs_register_bool_preference(capture_module, "real_time_update", "Update packet list in real time during capture",
"Update packet list in real time during capture?", &prefs.capture_real_time);
+ /* We might want to make this a "recent" setting. */
prefs_register_bool_preference(capture_module, "auto_scroll", "Scroll packet list during capture",
"Scroll packet list during capture?", &prefs.capture_auto_scroll);
+ /* GTK+ only */
prefs_register_bool_preference(capture_module, "show_info", "Show capture info dialog while capturing",
"Show capture info dialog while capturing?", &prefs.capture_show_info);
&prefs.pr_dest, print_dest_vals, TRUE);
#ifndef _WIN32
- prefs_register_string_preference(printing, "command", "Command",
- "Output gets piped to this command when the destination is set to \"command\"", (const char**)(&prefs.pr_cmd));
+ register_string_like_preference(printing, "command", "Command",
+ "Output gets piped to this command when the destination is set to \"command\"",
+ &prefs.pr_cmd, PREF_STRING, NULL, TRUE);
#endif
- prefs_register_filename_preference(printing, "file", "File",
- "This is the file that gets written to when the destination is set to \"file\"", (const char**)(&prefs.pr_file));
-
+ register_string_like_preference(printing, "file", "File",
+ "This is the file that gets written to when the destination is set to \"file\"",
+ &prefs.pr_file, PREF_FILENAME, NULL, TRUE);
/* Statistics */
stats_module = prefs_register_module(NULL, "statistics", "Statistics",
"Display all hidden protocol items in the packet list.",
&prefs.display_hidden_proto_items);
+ prefs_register_bool_preference(protocols_module, "display_byte_fields_with_spaces",
+ "Display byte fields with a space character between bytes",
+ "Display all byte fields with a space character between each byte in the packet list.",
+ &prefs.display_byte_fields_with_spaces);
+
+ prefs_register_bool_preference(protocols_module, "enable_incomplete_dissectors_check",
+ "Look for incomplete dissectors",
+ "Look for dissectors that left some bytes undecoded.",
+ &prefs.enable_incomplete_dissectors_check);
+
/* Obsolete preferences
* These "modules" were reorganized/renamed to correspond to their GUI
* configuration screen within the preferences dialog
GString *joined_str = g_string_new("");
GList *cur, *first;
gchar *str;
- gchar *quoted_str;
guint item_count = 0;
cur = first = g_list_first(sl);
} else
g_string_append_c(joined_str, ' ');
- quoted_str = g_strescape(str, "");
- g_string_append_printf(joined_str, "\"%s\"", quoted_str);
- g_free(quoted_str);
+ g_string_append_c(joined_str, '"');
+ while (*str) {
+ gunichar uc = g_utf8_get_char (str);
+
+ if (uc == '"' || uc == '\\')
+ g_string_append_c(joined_str, '\\');
+
+ if (g_unichar_isprint(uc))
+ g_string_append_unichar (joined_str, uc);
+
+ str = g_utf8_next_char (str);
+ }
+
+ g_string_append_c(joined_str, '"');
cur = cur->next;
}
void
prefs_clear_string_list(GList *sl)
{
- GList *l = sl;
-
- while (l) {
- g_free(l->data);
- l = g_list_remove_link(l, l);
- }
+ /* g_list_free_full() only exists since 2.28. */
+ g_list_foreach(sl, (GFunc)g_free, NULL);
+ g_list_free(sl);
}
/*
* If the string matches a "name" string in an entry, the value from that
* entry is returned.
*
- * Otherwise, if a string matches a "desctiption" string in an entry, the
+ * Otherwise, if a string matches a "description" string in an entry, the
* value from that entry is returned; we do that for backwards compatibility,
* as we used to have only a "name" string that was used both for command-line
* and configuration-file values and in the GUI (which meant either that
return default_value;
}
+
+/* Array of columns that have been migrated to custom columns */
+struct deprecated_columns {
+ const gchar *col_fmt;
+ const gchar *col_expr;
+};
+static struct deprecated_columns migrated_columns[] = {
+ { /* COL_COS_VALUE */ "%U", "vlan.priority" },
+ { /* COL_CIRCUIT_ID */ "%c", "iax2.call" },
+ { /* COL_BSSGP_TLLI */ "%l", "bssgp.tlli" },
+ { /* COL_HPUX_SUBSYS */ "%H", "nettl.subsys" },
+ { /* COL_HPUX_DEVID */ "%P", "nettl.devid" },
+ { /* COL_FR_DLCI */ "%C", "fr.dlci" },
+ { /* COL_REL_CONV_TIME */ "%rct", "tcp.time_relative" },
+ { /* COL_DELTA_CONV_TIME */ "%dct", "tcp.time_delta" },
+ { /* COL_OXID */ "%XO", "fc.ox_id" },
+ { /* COL_RXID */ "%XR", "fc.rx_id" },
+ { /* COL_SRCIDX */ "%Xd", "mdshdr.srcidx" },
+ { /* COL_DSTIDX */ "%Xs", "mdshdr.dstidx" },
+ { /* COL_DCE_CTX */ "%z", "dcerpc.cn_ctx_id" }
+};
+
+static gboolean
+is_deprecated_column_format(const gchar* fmt)
+{
+ guint haystack_idx;
+
+ for (haystack_idx = 0;
+ haystack_idx < G_N_ELEMENTS(migrated_columns);
+ ++haystack_idx) {
+
+ if (strcmp(migrated_columns[haystack_idx].col_fmt, fmt) == 0) {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
/* Preferences file format:
* - Configuration directives start at the beginning of the line, and
* are terminated with a colon.
gchar **cust_format_info;
char *p;
int col_fmt;
- gchar *col_custom_field = NULL;
+ gchar *col_custom_fields = NULL;
long col_custom_occurrence = 0;
gboolean col_resolved = TRUE;
/* Yes. */
col_fmt = COL_CUSTOM;
cust_format_info = g_strsplit(&fmt[cust_format_len+1],":",3); /* add 1 for ':' */
- col_custom_field = g_strdup(cust_format_info[0]);
- if (col_custom_field && cust_format_info[1]) {
+ col_custom_fields = g_strdup(cust_format_info[0]);
+ if (col_custom_fields && cust_format_info[1]) {
col_custom_occurrence = strtol(cust_format_info[1], &p, 10);
if (p == cust_format_info[1] || *p != '\0') {
/* Not a valid number. */
- g_free(col_custom_field);
+ g_free(col_custom_fields);
g_strfreev(cust_format_info);
return FALSE;
}
}
- if (col_custom_field && cust_format_info[1] && cust_format_info[2]) {
+ if (col_custom_fields && cust_format_info[1] && cust_format_info[2]) {
col_resolved = (cust_format_info[2][0] == 'U') ? FALSE : TRUE;
}
g_strfreev(cust_format_info);
} else {
col_fmt = get_column_format_from_str(fmt);
- if (col_fmt == -1)
+ if ((col_fmt == -1) && (!is_deprecated_column_format(fmt)))
return FALSE;
}
cfmt->fmt = col_fmt;
- cfmt->custom_field = col_custom_field;
+ cfmt->custom_fields = col_custom_fields;
cfmt->custom_occurrence = (int)col_custom_occurrence;
cfmt->resolved = col_resolved;
return TRUE;
}
-/* Initialize non-dissector preferences to wired-in default values.
- * (The dissector preferences are assumed to be set to those values
- * by the dissectors.)
- * They may be overridden by the global preferences file or the
- * user's preferences file.
+/* Initialize non-dissector preferences to wired-in default values Called
+ * at program startup and any time the profile changes. (The dissector
+ * preferences are assumed to be set to those values by the dissectors.)
+ * They may be overridden by the global preferences file or the user's
+ * preferences file.
*/
static void
init_prefs(void)
uat_load_all();
+ /*
+ * Ensure the "global" preferences have been initialized so the
+ * preference API has the proper default values to work from
+ */
+ pre_init_prefs();
+
prefs_register_modules();
- filter_expression_init(TRUE);
+ filter_expression_init();
prefs_initialized = TRUE;
}
-/* Initialize non-dissector preferences used by the "register preference" API
- * to default values so the default values can be used when registered
+/*
+ * Initialize non-dissector preferences used by the "register preference" API
+ * to default values so the default values can be used when registered.
+ *
+ * String, filename, and directory preferences will be g_freed so they must
+ * be g_mallocated.
*/
static void
pre_init_prefs(void)
"Protocol", "%p", "Length", "%L",
"Info", "%i"};
- if (prefs_pre_initialized)
- return;
-
prefs.pr_format = PR_FMT_TEXT;
prefs.pr_dest = PR_DEST_CMD;
- prefs.pr_file = "wireshark.out";
- prefs.pr_cmd = "lpr";
+ if (prefs.pr_file) g_free(prefs.pr_file);
+ prefs.pr_file = g_strdup("wireshark.out");
+ if (prefs.pr_cmd) g_free(prefs.pr_cmd);
+ prefs.pr_cmd = g_strdup("lpr");
prefs.gui_altern_colors = FALSE;
prefs.gui_expert_composite_eyecandy = FALSE;
prefs.filter_toolbar_show_in_statusbar = FALSE;
prefs.gui_toolbar_main_style = TB_STYLE_ICONS;
prefs.gui_toolbar_filter_style = TB_STYLE_TEXT;
- /* These string prefs will be strduped shortly, so we can safely cast away
- * their constness in these assignments */
+ /* These will be g_freed, so they must be g_mallocated. */
+ if (prefs.gui_gtk2_font_name) g_free(prefs.gui_gtk2_font_name);
#ifdef _WIN32
- prefs.gui_gtk2_font_name = (char *) "Lucida Console 10";
+ prefs.gui_gtk2_font_name = g_strdup("Lucida Console 10");
#else
- prefs.gui_gtk2_font_name = (char *) "Monospace 10";
+ prefs.gui_gtk2_font_name = g_strdup("Monospace 10");
#endif
/* We try to find the best font in the Qt code */
- prefs.gui_qt_font_name = (char *) "";
- prefs.gui_marked_fg.pixel = 65535;
+ if (prefs.gui_qt_font_name) g_free(prefs.gui_qt_font_name);
+ prefs.gui_qt_font_name = g_strdup("");
prefs.gui_marked_fg.red = 65535;
prefs.gui_marked_fg.green = 65535;
prefs.gui_marked_fg.blue = 65535;
- prefs.gui_marked_bg.pixel = 0;
prefs.gui_marked_bg.red = 0;
prefs.gui_marked_bg.green = 8224;
prefs.gui_marked_bg.blue = 10794;
- prefs.gui_ignored_fg.pixel = 32767;
prefs.gui_ignored_fg.red = 32767;
prefs.gui_ignored_fg.green = 32767;
prefs.gui_ignored_fg.blue = 32767;
- prefs.gui_ignored_bg.pixel = 65535;
prefs.gui_ignored_bg.red = 65535;
prefs.gui_ignored_bg.green = 65535;
prefs.gui_ignored_bg.blue = 65535;
- prefs.gui_colorized_fg = "000000,000000,000000,000000,000000,000000,000000,000000,000000,000000";
- prefs.gui_colorized_bg = "ffc0c0,ffc0ff,e0c0e0,c0c0ff,c0e0e0,c0ffff,c0ffc0,ffffc0,e0e0c0,e0e0e0";
- prefs.st_client_fg.pixel = 0;
+ if (prefs.gui_colorized_fg) g_free(prefs.gui_colorized_fg);
+ prefs.gui_colorized_fg = g_strdup("000000,000000,000000,000000,000000,000000,000000,000000,000000,000000");
+ if (prefs.gui_colorized_bg) g_free(prefs.gui_colorized_bg);
+ prefs.gui_colorized_bg = g_strdup("ffc0c0,ffc0ff,e0c0e0,c0c0ff,c0e0e0,c0ffff,c0ffc0,ffffc0,e0e0c0,e0e0e0");
prefs.st_client_fg.red = 32767;
prefs.st_client_fg.green = 0;
prefs.st_client_fg.blue = 0;
- prefs.st_client_bg.pixel = 0;
prefs.st_client_bg.red = 64507;
prefs.st_client_bg.green = 60909;
prefs.st_client_bg.blue = 60909;
- prefs.st_server_fg.pixel = 0;
prefs.st_server_fg.red = 0;
prefs.st_server_fg.green = 0;
prefs.st_server_fg.blue = 32767;
- prefs.st_server_bg.pixel = 0;
prefs.st_server_bg.red = 60909;
prefs.st_server_bg.green = 60909;
prefs.st_server_bg.blue = 64507;
- prefs.gui_text_valid.pixel = 0; /* light green */
- prefs.gui_text_valid.red = 0xAFFF;
- prefs.gui_text_valid.green = 0xFFFF;
- prefs.gui_text_valid.blue = 0xAFFF;
- prefs.gui_text_invalid.pixel = 0; /* light red */
- prefs.gui_text_invalid.red = 0xFFFF;
+ prefs.gui_text_valid.red = 0xAFFF; /* light green */
+ prefs.gui_text_valid.green = 0xFFFF;
+ prefs.gui_text_valid.blue = 0xAFFF;
+ prefs.gui_text_invalid.red = 0xFFFF; /* light red */
prefs.gui_text_invalid.green = 0xAFFF;
prefs.gui_text_invalid.blue = 0xAFFF;
- prefs.gui_text_deprecated.pixel = 0; /* light yellow */
- prefs.gui_text_deprecated.red = 0xFFFF;
+ prefs.gui_text_deprecated.red = 0xFFFF; /* light yellow */
prefs.gui_text_deprecated.green = 0xFFFF;
prefs.gui_text_deprecated.blue = 0xAFFF;
prefs.gui_geometry_save_position = TRUE;
prefs.gui_fileopen_style = FO_STYLE_LAST_OPENED;
prefs.gui_recent_df_entries_max = 10;
prefs.gui_recent_files_count_max = 10;
- prefs.gui_fileopen_dir = (char *) get_persdatafile_dir();
+ if (prefs.gui_fileopen_dir) g_free(prefs.gui_fileopen_dir);
+ prefs.gui_fileopen_dir = g_strdup(get_persdatafile_dir());
prefs.gui_fileopen_preview = 3;
prefs.gui_ask_unsaved = TRUE;
prefs.gui_find_wrap = TRUE;
prefs.gui_update_enabled = TRUE;
prefs.gui_update_channel = UPDATE_CHANNEL_STABLE;
prefs.gui_update_interval = 60*60*24; /* Seconds */
-#ifdef HTML_VIEWER
- prefs.gui_webbrowser = (char *) HTML_VIEWER " %s";
-#else
- prefs.gui_webbrowser = (char *) "";
-#endif
- prefs.gui_window_title = (char *) "";
- prefs.gui_start_title = "The World's Most Popular Network Protocol Analyzer";
+ if (prefs.gui_webbrowser) g_free(prefs.gui_webbrowser);
+ prefs.gui_webbrowser = g_strdup("");
+ if (prefs.gui_window_title) g_free(prefs.gui_window_title);
+ prefs.gui_window_title = g_strdup("");
+ if (prefs.gui_prepend_window_title) g_free(prefs.gui_prepend_window_title);
+ prefs.gui_prepend_window_title = g_strdup("");
+ if (prefs.gui_start_title) g_free(prefs.gui_start_title);
+ prefs.gui_start_title = g_strdup("The World's Most Popular Network Protocol Analyzer");
prefs.gui_version_placement = version_both;
prefs.gui_auto_scroll_on_expand = FALSE;
prefs.gui_auto_scroll_percentage = 0;
prefs.gui_layout_content_2 = layout_pane_content_pdetails;
prefs.gui_layout_content_3 = layout_pane_content_pbytes;
prefs.gui_packet_editor = FALSE;
+ prefs.gui_packet_list_elide_mode = ELIDE_RIGHT;
+ prefs.gui_packet_list_show_related = TRUE;
+ prefs.gui_packet_list_show_minimap = TRUE;
+ if (prefs.gui_interfaces_hide_types) g_free (prefs.gui_interfaces_hide_types);
+ prefs.gui_interfaces_hide_types = g_strdup("");
+ prefs.gui_interfaces_show_hidden = FALSE;
+#ifdef HAVE_PCAP_REMOTE
+ prefs.gui_interfaces_remote_display = TRUE;
+#endif
- prefs.col_list = NULL;
+ prefs.gui_qt_packet_list_separator = FALSE;
+
+ if (prefs.col_list) {
+ free_col_info(prefs.col_list);
+ prefs.col_list = NULL;
+ }
for (i = 0; i < DEF_NUM_COLS; i++) {
cfmt = g_new(fmt_data,1);
cfmt->title = g_strdup(col_fmt[i * 2]);
parse_column_format(cfmt, col_fmt[(i * 2) + 1]);
cfmt->visible = TRUE;
cfmt->resolved = TRUE;
- cfmt->custom_field = NULL;
+ cfmt->custom_fields = NULL;
cfmt->custom_occurrence = 0;
prefs.col_list = g_list_append(prefs.col_list, cfmt);
}
prefs.capture_auto_scroll = TRUE;
prefs.capture_show_info = FALSE;
- prefs.capture_columns = NULL;
- for (i = 0; i < num_capture_cols; i++) {
- col_name = g_strdup(capture_cols[i]);
- prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
+ if (!prefs.capture_columns) {
+ /* First time through */
+ for (i = 0; i < num_capture_cols; i++) {
+ col_name = g_strdup(capture_cols[i]);
+ prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
+ }
}
prefs.console_log_level =
prefs.st_sort_defdescending = TRUE;
prefs.st_sort_showfullname = FALSE;
prefs.display_hidden_proto_items = FALSE;
-
- prefs_pre_initialized = TRUE;
+ prefs.display_byte_fields_with_spaces = FALSE;
}
/*
* Reset a single dissector preference.
*/
-static void
+void
reset_pref(pref_t *pref)
{
+ int type;
if (!pref) return;
- switch (pref->type) {
+ type = pref->type;
+
+ /*
+ * This preference is no longer supported; it's not a
+ * real preference, so we don't reset it (i.e., we
+ * treat it as if it weren't found in the list of
+ * preferences, and we weren't called in the first place).
+ */
+ if (IS_PREF_OBSOLETE(type))
+ return;
+ else
+ RESET_PREF_OBSOLETE(type);
+
+ switch (type) {
case PREF_UINT:
+ case PREF_DECODE_AS_UINT:
*pref->varp.uint = pref->default_val.uint;
break;
case PREF_STRING:
case PREF_FILENAME:
case PREF_DIRNAME:
- g_free((void *)*pref->varp.string);
- *pref->varp.string = g_strdup(pref->default_val.string);
+ reset_string_like_preference(pref);
break;
case PREF_RANGE:
- g_free(*pref->varp.range);
- *pref->varp.range = range_copy(pref->default_val.range);
+ case PREF_DECODE_AS_RANGE:
+ wmem_free(wmem_epan_scope(), *pref->varp.range);
+ *pref->varp.range = range_copy(wmem_epan_scope(), pref->default_val.range);
break;
case PREF_STATIC_TEXT:
case PREF_CUSTOM:
pref->custom_cbs.reset_cb(pref);
break;
-
- case PREF_OBSOLETE:
- /*
- * This preference is no longer supported; it's not a
- * real preference, so we don't reset it (i.e., we
- * treat it as if it weren't found in the list of
- * preferences, and we weren't called in the first place).
- */
- break;
}
}
* Reset all preferences for a module.
*/
static gboolean
-reset_module_prefs(void *value, void *data _U_)
+reset_module_prefs(const void *key _U_, void *value, void *data _U_)
{
reset_pref_arg_t arg;
*/
oids_cleanup();
+ /*
+ * Free the filter expression list.
+ */
+ filter_expression_free(*pfilter_expression_head);
+ *pfilter_expression_head = NULL;
+
/*
* Reset the non-dissector preferences.
*/
and a pointer to the path of the file into "*pf_path_return", and
return NULL. */
e_prefs *
-
read_prefs(int *gpf_errno_return, int *gpf_read_errno_return,
char **gpf_path_return, int *pf_errno_return,
int *pf_read_errno_return, char **pf_path_return)
return &prefs;
}
-/* read the preferences file (or similiar) and call the callback
+/* read the preferences file (or similar) and call the callback
* function to set each key/value pair found */
int
read_prefs_file(const char *pf_path, FILE *pf,
/* Try to read in the profile name in the first line of the preferences file. */
if (fscanf(pf, "# Configuration file for %127[^\r\n]", ver) == 1) {
/* Assume trailing period and remove it */
+ g_free(prefs.saved_at_version);
prefs.saved_at_version = g_strndup(ver, strlen(ver) - 1);
}
rewind(pf);
- while ((got_c = getc(pf)) != EOF) {
+ while ((got_c = ws_getc_unlocked(pf)) != EOF) {
if (got_c == '\r') {
/* Treat CR-LF at the end of a line like LF, so that if we're reading
* a Windows-format file on UN*X, we handle it the same way we'd handle
* a UN*X-format file. */
- got_c = getc(pf);
+ got_c = ws_getc_unlocked(pf);
if (got_c == EOF)
break;
if (got_c != '\n') {
* If the pref has a trailing comma, eliminate it.
*/
cur_val->str[cur_val->len-1] = '\0';
- g_warning ("%s line %d: trailing comma in \"%s\" %s", pf_path, pline, cur_var->str, hint);
+ ws_g_warning ("%s line %d: trailing comma in \"%s\" %s", pf_path, pline, cur_var->str, hint);
}
}
/* Call the routine to set the preference; it will parse
break;
case PREFS_SET_SYNTAX_ERR:
- g_warning ("Syntax error in preference \"%s\" at line %d of\n%s %s",
+ ws_g_warning ("Syntax error in preference \"%s\" at line %d of\n%s %s",
cur_var->str, pline, pf_path, hint);
break;
* on non-Win32 platforms.
*/
if (strcmp(cur_var->str, "print.command") != 0)
- g_warning ("No such preference \"%s\" at line %d of\n%s %s",
+ ws_g_warning ("No such preference \"%s\" at line %d of\n%s %s",
cur_var->str, pline, pf_path, hint);
prefs.unknown_prefs = TRUE;
break;
The prefs in question need to be listed in the console window so that the
user can make an informed choice.
*/
- g_warning ("Obsolete preference \"%s\" at line %d of\n%s %s",
+ ws_g_warning ("Obsolete preference \"%s\" at line %d of\n%s %s",
cur_var->str, pline, pf_path, hint);
prefs.unknown_prefs = TRUE;
break;
}
} else {
- g_warning ("Incomplete preference at line %d: of\n%s %s", pline, pf_path, hint);
+ ws_g_warning ("Incomplete preference at line %d: of\n%s %s", pline, pf_path, hint);
}
}
state = IN_VAR;
} else if (got_c == '#') {
state = IN_SKIP;
} else {
- g_warning ("Malformed preference at line %d of\n%s %s", fline, pf_path, hint);
+ ws_g_warning ("Malformed preference at line %d of\n%s %s", fline, pf_path, hint);
}
break;
case IN_VAR:
break;
case PREFS_SET_SYNTAX_ERR:
- g_warning ("Syntax error in preference %s at line %d of\n%s %s",
+ ws_g_warning ("Syntax error in preference %s at line %d of\n%s %s",
cur_var->str, pline, pf_path, hint);
break;
case PREFS_SET_NO_SUCH_PREF:
- g_warning ("No such preference \"%s\" at line %d of\n%s %s",
+ ws_g_warning ("No such preference \"%s\" at line %d of\n%s %s",
cur_var->str, pline, pf_path, hint);
prefs.unknown_prefs = TRUE;
break;
break;
}
} else {
- g_warning ("Incomplete preference at line %d of\n%s %s",
+ ws_g_warning("Incomplete preference at line %d of\n%s %s",
pline, pf_path, hint);
}
}
prefs_set_uat_pref(char *uat_entry) {
gchar *p, *colonp;
uat_t *uat;
- gchar *err;
+ gchar *err = NULL;
+ gboolean ret;
colonp = strchr(uat_entry, ':');
if (colonp == NULL)
return FALSE;
}
- if (uat_load_str(uat, p, &err)) {
- return TRUE;
- }
- return FALSE;
+ ret = uat_load_str(uat, p, &err);
+ g_free(err);
+ return ret;
}
/*
return ret;
}
+guint prefs_get_uint_value_real(pref_t *pref, pref_source_t source)
+{
+ switch (source)
+ {
+ case pref_default:
+ return pref->default_val.uint;
+ break;
+ case pref_stashed:
+ return pref->stashed_val.uint;
+ break;
+ case pref_current:
+ return *pref->varp.uint;
+ break;
+ default:
+ g_assert_not_reached();
+ break;
+ }
+
+ return 0;
+}
+
+guint prefs_get_uint_value(const char *module_name, const char* pref_name)
+{
+ return prefs_get_uint_value_real(prefs_find_preference(prefs_find_module(module_name), pref_name), pref_current);
+}
+
+gboolean prefs_set_uint_value(pref_t *pref, guint value, pref_source_t source)
+{
+ gboolean changed = FALSE;
+ switch (source)
+ {
+ case pref_default:
+ if (pref->default_val.uint != value) {
+ pref->default_val.uint = value;
+ changed = TRUE;
+ }
+ break;
+ case pref_stashed:
+ if (pref->stashed_val.uint != value) {
+ pref->stashed_val.uint = value;
+ changed = TRUE;
+ }
+ break;
+ case pref_current:
+ if (*pref->varp.uint != value) {
+ *pref->varp.uint = value;
+ changed = TRUE;
+ }
+ break;
+ default:
+ g_assert_not_reached();
+ break;
+ }
+
+ return changed;
+}
+
+guint prefs_get_uint_base(pref_t *pref)
+{
+ return pref->info.base;
+}
+
/*
* Returns TRUE if the given device is hidden
*/
*/
if (cfmt->fmt != cfmt_hidden.fmt) {
/* No. */
- g_free(cfmt_hidden.custom_field);
- cfmt_hidden.custom_field = NULL;
+ g_free(cfmt_hidden.custom_fields);
+ cfmt_hidden.custom_fields = NULL;
continue;
}
if (cfmt->fmt == COL_CUSTOM) {
* A custom column has to have the
* same custom field and occurrence.
*/
- if (cfmt_hidden.custom_field && cfmt->custom_field) {
- if (strcmp(cfmt->custom_field,
- cfmt_hidden.custom_field) != 0) {
+ if (cfmt_hidden.custom_fields && cfmt->custom_fields) {
+ if (strcmp(cfmt->custom_fields,
+ cfmt_hidden.custom_fields) != 0) {
/* Different fields. */
- g_free(cfmt_hidden.custom_field);
- cfmt_hidden.custom_field = NULL;
+ g_free(cfmt_hidden.custom_fields);
+ cfmt_hidden.custom_fields = NULL;
continue;
}
if (cfmt->custom_occurrence != cfmt_hidden.custom_occurrence) {
/* Different occurrences. */
- g_free(cfmt_hidden.custom_field);
- cfmt_hidden.custom_field = NULL;
+ g_free(cfmt_hidden.custom_fields);
+ cfmt_hidden.custom_fields = NULL;
continue;
}
}
* OK, they match, so it's one of the hidden fields,
* hence not visible.
*/
- g_free(cfmt_hidden.custom_field);
+ g_free(cfmt_hidden.custom_fields);
g_free(cols);
return FALSE;
}
#define PRS_GUI_FILTER_EXPR "gui.filter_expressions.expr"
#define PRS_GUI_FILTER_ENABLED "gui.filter_expressions.enabled"
+/*
+ * Extract the red, green, and blue components of a 24-bit RGB value
+ * and convert them from [0,255] to [0,65535].
+ */
#define RED_COMPONENT(x) (guint16) (((((x) >> 16) & 0xff) * 65535 / 255))
#define GREEN_COMPONENT(x) (guint16) (((((x) >> 8) & 0xff) * 65535 / 255))
#define BLUE_COMPONENT(x) (guint16) ( (((x) & 0xff) * 65535 / 255))
name_resolve->transport_name = TRUE;
break;
case 'C':
- name_resolve->concurrent_dns = TRUE;
+ /* DEPRECATED */
+ /* name_resolve->concurrent_dns */
+ break;
+ case 'd':
+ name_resolve->dns_pkt_addr_resolution = TRUE;
+ break;
+ case 'v':
+ name_resolve->vlan_name = TRUE;
break;
default:
/*
return '\0';
}
-
static void
try_convert_to_custom_column(gpointer *el_data)
{
- /* Array of columns that have been migrated to custom columns */
- struct {
- gint el;
- const gchar *col_expr;
- } migrated_columns[] = {
- { COL_COS_VALUE, "vlan.priority" },
- { COL_CIRCUIT_ID, "iax2.call" },
- { COL_BSSGP_TLLI, "bssgp.tlli" },
- { COL_HPUX_SUBSYS, "nettl.subsys" },
- { COL_HPUX_DEVID, "nettl.devid" },
- { COL_FR_DLCI, "fr.dlci" },
- { COL_REL_CONV_TIME, "tcp.time_relative" },
- { COL_DELTA_CONV_TIME, "tcp.time_delta" },
- { COL_OXID, "fc.ox_id" },
- { COL_RXID, "fc.rx_id" },
- { COL_SRCIDX, "mdshdr.srcidx" },
- { COL_DSTIDX, "mdshdr.dstidx" },
- { COL_DCE_CTX, "dcerpc.cn_ctx_id" }
- };
-
guint haystack_idx;
- const gchar *haystack_fmt;
gchar **fmt = (gchar **) el_data;
haystack_idx < G_N_ELEMENTS(migrated_columns);
++haystack_idx) {
- haystack_fmt = col_format_to_string(migrated_columns[haystack_idx].el);
- if (strcmp(haystack_fmt, *fmt) == 0) {
+ if (strcmp(migrated_columns[haystack_idx].col_fmt, *fmt) == 0) {
gchar *cust_col = g_strdup_printf("%%Cus:%s:0",
migrated_columns[haystack_idx].col_expr);
}
}
+static gboolean
+deprecated_heur_dissector_pref(gchar *pref_name, const gchar *value)
+{
+ struct heur_pref_name
+ {
+ const char* pref_name;
+ const char* short_name;
+ gboolean more_dissectors; /* For multiple dissectors controlled by the same preference */
+ };
+
+ struct heur_pref_name heur_prefs[] = {
+ {"acn.heuristic_acn", "acn_udp", 0},
+ {"bfcp.enable", "bfcp_tcp", 1},
+ {"bfcp.enable", "bfcp_udp", 0},
+ {"bt-dht.enable", "bittorrent_dht_udp", 0},
+ {"bt-utp.enable", "bt_utp_udp", 0},
+ {"cattp.enable", "cattp_udp", 0},
+ {"cfp.enable", "fp_eth", 0},
+ {"dicom.heuristic", "dicom_tcp", 0},
+ {"dnp3.heuristics", "dnp3_tcp", 1},
+ {"dnp3.heuristics", "dnp3_udp", 0},
+ {"dvb-s2_modeadapt.enable", "dvb_s2_udp", 0},
+ {"esl.enable", "esl_eth", 0},
+ {"fp.udp_heur", "fp_udp", 0},
+ {"gvsp.enable_heuristic", "gvsp_udp", 0},
+ {"hdcp2.enable", "hdcp2_tcp", 0},
+ {"hislip.enable_heuristic", "hislip_tcp", 0},
+ {"infiniband.dissect_eoib", "mellanox_eoib", 1},
+ {"infiniband.identify_payload", "eth_over_ib", 0},
+ {"jxta.udp.heuristic", "jxta_udp", 0},
+ {"jxta.tcp.heuristic", "jxta_tcp", 0},
+ {"jxta.sctp.heuristic", "jxta_sctp", 0},
+ {"mac-lte.heuristic_mac_lte_over_udp", "mac_lte_udp", 0},
+ {"mbim.bulk_heuristic", "mbim_usb_bulk", 0},
+ {"norm.heuristic_norm", "rmt_norm_udp", 0},
+ {"openflow.heuristic", "openflow_tcp", 0},
+ {"pdcp-lte.heuristic_pdcp_lte_over_udp", "pdcp_lte_udp", 0},
+ {"rlc.heuristic_rlc_over_udp", "rlc_udp", 0},
+ {"rlc-lte.heuristic_rlc_lte_over_udp", "rlc_lte_udp", 0},
+ {"rtcp.heuristic_rtcp", "rtcp_udp", 1},
+ {"rtcp.heuristic_rtcp", "rtcp_stun", 0},
+ {"rtp.heuristic_rtp", "rtp_udp", 1},
+ {"rtp.heuristic_rtp", "rtp_stun", 0},
+ {"teredo.heuristic_teredo", "teredo_udp", 0},
+ {"vssmonitoring.use_heuristics", "vssmonitoring_eth", 0},
+ {"xml.heuristic", "xml_http", 1},
+ {"xml.heuristic", "xml_sip", 1},
+ {"xml.heuristic", "xml_media", 0},
+ {"xml.heuristic_tcp", "xml_tcp", 0},
+ {"xml.heuristic_udp", "xml_udp", 0},
+ };
+
+ unsigned int i;
+ heur_dtbl_entry_t* heuristic;
+
+
+ for (i = 0; i < sizeof(heur_prefs)/sizeof(struct heur_pref_name); i++)
+ {
+ if (strcmp(pref_name, heur_prefs[i].pref_name) == 0)
+ {
+ heuristic = find_heur_dissector_by_unique_short_name(heur_prefs[i].short_name);
+ if (heuristic != NULL) {
+ heuristic->enabled = ((g_ascii_strcasecmp(value, "true") == 0) ? TRUE : FALSE);
+ }
+
+ if (!heur_prefs[i].more_dissectors)
+ return TRUE;
+ }
+ }
+
+
+ return FALSE;
+}
+
+static gboolean
+deprecated_enable_dissector_pref(gchar *pref_name, const gchar *value)
+{
+ struct dissector_pref_name
+ {
+ const char* pref_name;
+ const char* short_name;
+ };
+
+ struct dissector_pref_name dissector_prefs[] = {
+ {"transum.tsumenabled", "TRANSUM"},
+ {"snort.enable_snort_dissector", "Snort"},
+ {"prp.enable", "PRP"},
+ };
+
+ unsigned int i;
+ int proto_id;
+
+ for (i = 0; i < sizeof(dissector_prefs)/sizeof(struct dissector_pref_name); i++)
+ {
+ if (strcmp(pref_name, dissector_prefs[i].pref_name) == 0)
+ {
+ proto_id = proto_get_id_by_short_name(dissector_prefs[i].short_name);
+ if (proto_id >= 0)
+ proto_set_decoding(proto_id, ((g_ascii_strcasecmp(value, "true") == 0) ? TRUE : FALSE));
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+static gboolean
+deprecated_port_pref(gchar *pref_name, const gchar *value)
+{
+ struct port_pref_name
+ {
+ const char* pref_name;
+ const char* module_name;
+ const char* table_name;
+ guint base;
+ };
+
+ struct obsolete_pref_name
+ {
+ const char* pref_name;
+ };
+
+ /* For now this is only supporting TCP/UDP port dissector preferences
+ which are assumed to be decimal */
+ struct port_pref_name port_prefs[] = {
+ /* TCP */
+ {"cmp.tcp_alternate_port", "CMP", "tcp.port", 10},
+ {"h248.tcp_port", "H248", "tcp.port", 10},
+ {"cops.tcp.cops_port", "COPS", "tcp.port", 10},
+ {"dhcpfo.tcp_port", "DHCPFO", "tcp.port", 10},
+ {"enttec.tcp_port", "ENTTEC", "tcp.port", 10},
+ {"forces.tcp_alternate_port", "ForCES", "tcp.port", 10},
+ {"ged125.tcp_port", "GED125", "tcp.port", 10},
+ {"hpfeeds.dissector_port", "HPFEEDS", "tcp.port", 10},
+ {"lsc.port", "LSC", "tcp.port", 10},
+ {"megaco.tcp.txt_port", "MEGACO", "tcp.port", 10},
+ {"netsync.tcp_port", "Netsync", "tcp.port", 10},
+ {"osi.tpkt_port", "OSI", "tcp.port", 10},
+ {"rsync.tcp_port", "RSYNC", "tcp.port", 10},
+ {"sametime.tcp_port", "SAMETIME", "tcp.port", 10},
+ {"sigcomp.tcp.port2", "SIGCOMP", "tcp.port", 10},
+ {"synphasor.tcp_port", "SYNCHROPHASOR", "tcp.port", 10},
+ {"tipc.alternate_port", "TIPC", "tcp.port", 10},
+ {"vnc.alternate_port", "VNC", "tcp.port", 10},
+ {"scop.port", "SCoP", "tcp.port", 10},
+ {"scop.port_secure", "SCoP", "tcp.port", 10},
+ /* UDP */
+ {"h248.udp_port", "H248", "udp.port", 10},
+ {"actrace.udp_port", "ACtrace", "udp.port", 10},
+ {"brp.port", "BRP", "udp.port", 10},
+ {"bvlc.additional_udp_port", "BVLC", "udp.port", 10},
+ {"capwap.udp.port.control", "CAPWAP-CONTROL", "udp.port", 10},
+ {"capwap.udp.port.data", "CAPWAP-CONTROL", "udp.port", 10},
+ {"coap.udp_port", "CoAP", "udp.port", 10},
+ {"enttec.udp_port", "ENTTEC", "udp.port", 10},
+ {"forces.udp_alternate_port", "ForCES", "udp.port", 10},
+ {"ldss.udp_port", "LDSS", "udp.port", 10},
+ {"lmp.udp_port", "LMP", "udp.port", 10},
+ {"ltp.port", "LTP", "udp.port", 10},
+ {"lwres.udp.lwres_port", "LWRES", "udp.port", 10},
+ {"megaco.udp.txt_port", "MEGACO", "udp.port", 10},
+ {"pgm.udp.encap_ucast_port", "PGM", "udp.port", 10},
+ {"pgm.udp.encap_mcast_port", "PGM", "udp.port", 10},
+ {"quic.udp.quic.port", "QUIC", "udp.port", 10},
+ {"quic.udp.quics.port", "QUIC", "udp.port", 10},
+ {"radius.alternate_port", "RADIUS", "udp.port", 10},
+ {"rdt.default_udp_port", "RDT", "udp.port", 10},
+ {"alc.default.udp_port", "ALC", "udp.port", 10},
+ {"sigcomp.udp.port2", "SIGCOMP", "udp.port", 10},
+ {"synphasor.udp_port", "SYNCHROPHASOR", "udp.port", 10},
+ {"tdmop.udpport", "TDMoP", "udp.port", 10},
+ {"uaudp.port1", "UAUDP", "udp.port", 10},
+ {"uaudp.port2", "UAUDP", "udp.port", 10},
+ {"uaudp.port3", "UAUDP", "udp.port", 10},
+ {"uaudp.port4", "UAUDP", "udp.port", 10},
+ {"uhd.dissector_port", "UHD", "udp.port", 10},
+ {"vrt.dissector_port", "VITA 49", "udp.port", 10},
+ {"vuze-dht.udp_port", "Vuze-DHT", "udp.port", 10},
+ {"wimaxasncp.udp.wimax_port", "WiMAX ASN CP", "udp.port", 10},
+ };
+
+ struct port_pref_name port_range_prefs[] = {
+ /* TCP */
+ {"couchbase.tcp.ports", "Couchbase", "tcp.port", 10},
+ {"gsm_ipa.tcp_ports", "GSM over IP", "tcp.port", 10},
+ {"kafka.tcp.ports", "Kafka", "tcp.port", 10},
+ {"kt.tcp.ports", "Kyoto Tycoon", "tcp.port", 10},
+ {"memcache.tcp.ports", "MEMCACHE", "tcp.port", 10},
+ {"mrcpv2.tcp.port_range", "MRCPv2", "tcp.port", 10},
+ {"rtsp.tcp.port_range", "RTSP", "tcp.port", 10},
+ {"sip.tcp.ports", "SIP", "tcp.port", 10},
+ {"tds.tcp_ports", "TDS", "tcp.port", 10},
+ {"uma.tcp.ports", "UMA", "tcp.port", 10},
+ /* UDP */
+ {"aruba_erm.udp.ports", "ARUBA_ERM", "udp.port", 10},
+ {"diameter.udp.ports", "DIAMETER", "udp.port", 10},
+ {"dmp.udp_ports", "DMP", "udp.port", 10},
+ {"dns.udp.ports", "DNS", "udp.port", 10},
+ {"gsm_ipa.udp_ports", "GSM over IP", "udp.port", 10},
+ {"hcrt.dissector_udp_port", "HCrt", "udp.port", 10},
+ {"memcache.udp.ports", "MEMCACHE", "udp.port", 10},
+ {"nb_rtpmux.udp_ports", "NB_RTPMUX", "udp.port", 10},
+ {"gprs-ns.udp.ports", "GPRS-NS", "udp.port", 10},
+ {"p_mul.udp_ports", "P_MUL", "udp.port", 10},
+ {"radius.ports", "RADIUS", "udp.port", 10},
+ {"sflow.ports", "sFlow", "udp.port", 10},
+ {"sscop.udp.ports", "SSCOP", "udp.port", 10},
+ {"tftp.udp_ports", "TFTP", "udp.port", 10},
+ {"tipc.udp.ports", "TIPC", "udp.port", 10},
+ };
+
+ /* These are subdissectors of TPKT/OSITP that used to have a
+ TCP port preference even though they were never
+ directly on TCP. Convert them to use Decode As
+ with the TPKT dissector handle */
+ struct port_pref_name tpkt_subdissector_port_prefs[] = {
+ {"dap.tcp.port", "DAP", "tcp.port", 10},
+ {"disp.tcp.port", "DISP", "tcp.port", 10},
+ {"dop.tcp.port", "DOP", "tcp.port", 10},
+ {"dsp.tcp.port", "DSP", "tcp.port", 10},
+ {"p1.tcp.port", "P1", "tcp.port", 10},
+ {"p7.tcp.port", "P7", "tcp.port", 10},
+ {"rdp.tcp.port", "RDP", "tcp.port", 10},
+ };
+
+ /* These are obsolete preferences from the dissectors' view,
+ (typically because of a switch from a single value to a
+ range value) but the name of the preference conflicts
+ with the generated preference name from the dissector table.
+ Don't allow the obsolete preference through to be handled */
+ struct obsolete_pref_name obsolete_prefs[] = {
+ {"diameter.tcp.port"},
+ {"kafka.tcp.port"},
+ {"mrcpv2.tcp.port"},
+ {"rtsp.tcp.port"},
+ {"sip.tcp.port"},
+ {"t38.tcp.port"},
+ };
+
+ unsigned int i;
+ char *p;
+ guint uval;
+ dissector_table_t sub_dissectors;
+ dissector_handle_t handle, tpkt_handle;
+ module_t *module;
+ pref_t *pref;
+
+ for (i = 0; i < sizeof(port_prefs)/sizeof(struct port_pref_name); i++)
+ {
+ if (strcmp(pref_name, port_prefs[i].pref_name) == 0)
+ {
+ /* XXX - give an error if it doesn't fit in a guint? */
+ uval = (guint)strtoul(value, &p, port_prefs[i].base);
+ if (p == value || *p != '\0')
+ return FALSE; /* number was bad */
+
+ module = prefs_find_module((gchar*)port_prefs[i].module_name);
+ pref = prefs_find_preference(module, port_prefs[i].table_name);
+ if (pref != NULL)
+ {
+ module->prefs_changed = TRUE;
+ *pref->varp.uint = uval;
+ }
+
+ /* If the value is zero, it wouldn't add to the Decode As tables */
+ if (uval != 0)
+ {
+ sub_dissectors = find_dissector_table(port_prefs[i].table_name);
+ if (sub_dissectors != NULL) {
+ handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)port_prefs[i].module_name);
+ if (handle != NULL) {
+ dissector_change_uint(port_prefs[i].table_name, uval, handle);
+ decode_build_reset_list(port_prefs[i].table_name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(uval), NULL, NULL);
+ }
+ }
+ }
+
+ return TRUE;
+ }
+ }
+
+ for (i = 0; i < sizeof(port_range_prefs)/sizeof(struct port_pref_name); i++)
+ {
+ if (strcmp(pref_name, port_range_prefs[i].pref_name) == 0)
+ {
+ guint32 range_i, range_j;
+
+ sub_dissectors = find_dissector_table(port_range_prefs[i].table_name);
+ if (sub_dissectors != NULL) {
+ switch (dissector_table_get_type(sub_dissectors)) {
+ case FT_UINT8:
+ case FT_UINT16:
+ case FT_UINT24:
+ case FT_UINT32:
+ break;
+
+ default:
+ g_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));
+ g_assert_not_reached();
+ }
+
+ module = prefs_find_module((gchar*)port_range_prefs[i].module_name);
+ pref = prefs_find_preference(module, port_range_prefs[i].table_name);
+ if (pref != NULL)
+ {
+ if (!prefs_set_range_value_work(pref, value, TRUE, &module->prefs_changed))
+ {
+ return FALSE; /* number was bad */
+ }
+
+ handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)port_range_prefs[i].module_name);
+ if (handle != NULL) {
+
+ for (range_i = 0; range_i < (*pref->varp.range)->nranges; range_i++) {
+ for (range_j = (*pref->varp.range)->ranges[range_i].low; range_j < (*pref->varp.range)->ranges[range_i].high; range_j++) {
+ dissector_change_uint(port_range_prefs[i].table_name, range_j, handle);
+ decode_build_reset_list(port_range_prefs[i].table_name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(range_j), NULL, NULL);
+ }
+
+ dissector_change_uint(port_range_prefs[i].table_name, (*pref->varp.range)->ranges[range_i].high, handle);
+ 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), NULL, NULL);
+ }
+ }
+ }
+ }
+
+ return TRUE;
+ }
+ }
+
+ for (i = 0; i < sizeof(tpkt_subdissector_port_prefs)/sizeof(struct port_pref_name); i++)
+ {
+ if (strcmp(pref_name, tpkt_subdissector_port_prefs[i].pref_name) == 0)
+ {
+ /* XXX - give an error if it doesn't fit in a guint? */
+ uval = (guint)strtoul(value, &p, tpkt_subdissector_port_prefs[i].base);
+ if (p == value || *p != '\0')
+ return FALSE; /* number was bad */
+
+ /* If the value is 0 or 102 (default TPKT port), don't add to the Decode As tables */
+ if ((uval != 0) && (uval != 102))
+ {
+ tpkt_handle = find_dissector("tpkt");
+ if (tpkt_handle != NULL) {
+ dissector_change_uint(tpkt_subdissector_port_prefs[i].table_name, uval, tpkt_handle);
+ }
+ }
+
+ return TRUE;
+ }
+ }
+
+ for (i = 0; i < sizeof(obsolete_prefs)/sizeof(struct obsolete_pref_name); i++)
+ {
+ if (strcmp(pref_name, obsolete_prefs[i].pref_name) == 0)
+ {
+ /* Just ignore the preference */
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
static prefs_set_pref_e
set_pref(gchar *pref_name, const gchar *value, void *private_data _U_,
gboolean return_range_errors)
static gchar *filter_label = NULL;
static gboolean filter_enabled = FALSE;
gchar *filter_expr = NULL;
- module_t *module;
+ module_t *module, *containing_module;
pref_t *pref;
+ int type;
if (strcmp(pref_name, PRS_GUI_FILTER_LABEL) == 0) {
filter_label = g_strdup(value);
gbl_resolv_flags.mac_name = TRUE;
gbl_resolv_flags.network_name = TRUE;
gbl_resolv_flags.transport_name = TRUE;
- gbl_resolv_flags.concurrent_dns = TRUE;
}
else if (g_ascii_strcasecmp(value, "false") == 0) {
- gbl_resolv_flags.mac_name = FALSE;
- gbl_resolv_flags.network_name = FALSE;
- gbl_resolv_flags.transport_name = FALSE;
- gbl_resolv_flags.concurrent_dns = FALSE;
+ disable_name_resolution();
}
else {
/* start out with none set */
- gbl_resolv_flags.mac_name = FALSE;
- gbl_resolv_flags.network_name = FALSE;
- gbl_resolv_flags.transport_name = FALSE;
- gbl_resolv_flags.concurrent_dns = FALSE;
+ disable_name_resolution();
if (string_to_name_resolve(value, &gbl_resolv_flags) != '\0')
return PREFS_SET_SYNTAX_ERR;
}
+ } else if (deprecated_heur_dissector_pref(pref_name, value)) {
+ /* Handled within deprecated_heur_dissector_pref() if found */
+ } else if (deprecated_enable_dissector_pref(pref_name, value)) {
+ /* Handled within deprecated_enable_dissector_pref() if found */
+ } else if (deprecated_port_pref(pref_name, value)) {
+ /* Handled within deprecated_port_pref() if found */
} else {
/* Handle deprecated "global" options that don't have a module
* associated with them
return PREFS_SET_OBSOLETE;
}
if (module) {
- g_warning ("Preference \"%s.%s\" has been converted to \"%s.%s.%s\"\n"
+ ws_g_warning ("Preference \"%s.%s\" has been converted to \"%s.%s.%s\"\n"
"Save your preferences to make this change permanent.",
pref_name, dotp+1, module->parent->name, pref_name, dotp+1);
prefs.unknown_prefs = TRUE;
}
}
- pref = prefs_find_preference(module, dotp);
+ /* The pref is located in the module or a submodule.
+ * Assume module, then search for a submodule holding the pref. */
+ containing_module = module;
+ pref = prefs_find_preference_with_submodule(module, dotp, &containing_module);
if (pref == NULL) {
prefs.unknown_prefs = TRUE;
/* "gui" prefix was added to column preferences for better organization
* within the preferences file
*/
- if ((strcmp(pref_name, PRS_COL_HIDDEN) == 0) ||
- (strcmp(pref_name, PRS_COL_FMT) == 0)) {
+ if (module == gui_column_module) {
+ /* While this has a subtree, there is no apply callback, so no
+ * need to use prefs_find_preference_with_submodule to update
+ * containing_module. It would not be useful. */
pref = prefs_find_preference(module, pref_name);
}
else if (strcmp(module->name, "mgcp") == 0) {
} else if (strcmp(module->name, "smpp") == 0) {
/* Handle preferences that moved from SMPP. */
module_t *new_module = prefs_find_module("gsm-sms-ud");
- if (new_module){
- if (strcmp(dotp, "port_number_udh_means_wsp") == 0)
+ if (new_module) {
+ if (strcmp(dotp, "port_number_udh_means_wsp") == 0) {
pref = prefs_find_preference(new_module, "port_number_udh_means_wsp");
- else if (strcmp(dotp, "try_dissect_1st_fragment") == 0)
+ containing_module = new_module;
+ } else if (strcmp(dotp, "try_dissect_1st_fragment") == 0) {
pref = prefs_find_preference(new_module, "try_dissect_1st_fragment");
+ containing_module = new_module;
+ }
}
} else if (strcmp(module->name, "asn1") == 0) {
/* Handle old generic ASN.1 preferences (it's not really a
module_t *new_module = prefs_find_module("vlan");
if (new_module) {
pref = prefs_find_preference(new_module, "qinq_ethertype");
- module = new_module;
+ containing_module = new_module;
}
}
} else if (strcmp(module->name, "taps") == 0) {
if (pref == NULL)
return PREFS_SET_NO_SUCH_PREF; /* no such preference */
- switch (pref->type) {
+ type = pref->type;
+ if (IS_PREF_OBSOLETE(type)) {
+ return PREFS_SET_OBSOLETE; /* no such preference any more */
+ } else {
+ RESET_PREF_OBSOLETE(type);
+ }
+
+ switch (type) {
case PREF_UINT:
/* XXX - give an error if it doesn't fit in a guint? */
if (p == value || *p != '\0')
return PREFS_SET_SYNTAX_ERR; /* number was bad */
if (*pref->varp.uint != uval) {
- module->prefs_changed = TRUE;
+ containing_module->prefs_changed = TRUE;
*pref->varp.uint = uval;
}
break;
+ case PREF_DECODE_AS_UINT:
+ {
+ /* This is for backwards compatibility in case any of the preferences
+ that shared the "Decode As" preference name and used to be PREF_UINT
+ are now applied directly to the Decode As funtionality */
+
+ dissector_table_t sub_dissectors;
+ dissector_handle_t handle;
+
+ /* XXX - give an error if it doesn't fit in a guint? */
+ uval = (guint)strtoul(value, &p, pref->info.base);
+ if (p == value || *p != '\0')
+ return PREFS_SET_SYNTAX_ERR; /* number was bad */
+
+ if (*pref->varp.uint != uval) {
+ containing_module->prefs_changed = TRUE;
+ *pref->varp.uint = uval;
+
+ /* Name of preference is the dissector table */
+ sub_dissectors = find_dissector_table(pref->name);
+ if (sub_dissectors != NULL) {
+ handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)module->title);
+ if (handle != NULL) {
+ if (uval != 0) {
+ dissector_change_uint(pref->name, uval, handle);
+ decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(uval), NULL, NULL);
+ } else {
+ dissector_delete_uint(pref->name, *pref->varp.uint, handle);
+ decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), pref->varp.uint, NULL, NULL);
+ }
+ /* XXX - Do we save the decode_as_entries file here? */
+ }
+ }
+ }
+ break;
+ }
case PREF_BOOL:
/* XXX - give an error if it's neither "true" nor "false"? */
if (g_ascii_strcasecmp(value, "true") == 0)
else
bval = FALSE;
if (*pref->varp.boolp != bval) {
- module->prefs_changed = TRUE;
+ containing_module->prefs_changed = TRUE;
*pref->varp.boolp = bval;
}
break;
enum_val = find_val_for_string(value, pref->info.enum_info.enumvals,
*pref->varp.enump);
if (*pref->varp.enump != enum_val) {
- module->prefs_changed = TRUE;
+ containing_module->prefs_changed = TRUE;
*pref->varp.enump = enum_val;
}
break;
case PREF_STRING:
case PREF_FILENAME:
case PREF_DIRNAME:
- if (strcmp(*pref->varp.string, value) != 0) {
- module->prefs_changed = TRUE;
- g_free((void *)*pref->varp.string);
- *pref->varp.string = g_strdup(value);
- }
+ containing_module->prefs_changed |= prefs_set_string_value(pref, value, pref_current);
break;
case PREF_RANGE:
{
+ if (!prefs_set_range_value_work(pref, value, return_range_errors,
+ &containing_module->prefs_changed))
+ return PREFS_SET_SYNTAX_ERR; /* number was bad */
+ break;
+ }
+ case PREF_DECODE_AS_RANGE:
+ {
+ /* This is for backwards compatibility in case any of the preferences
+ that shared the "Decode As" preference name and used to be PREF_RANGE
+ are now applied directly to the Decode As funtionality */
range_t *newrange;
+ dissector_table_t sub_dissectors;
+ dissector_handle_t handle;
+ guint32 i, j;
- if (range_convert_str_work(&newrange, value, pref->info.max_value,
+ if (range_convert_str_work(wmem_epan_scope(), &newrange, value, pref->info.max_value,
return_range_errors) != CVT_NO_ERROR) {
return PREFS_SET_SYNTAX_ERR; /* number was bad */
}
if (!ranges_are_equal(*pref->varp.range, newrange)) {
- module->prefs_changed = TRUE;
- g_free(*pref->varp.range);
+ wmem_free(wmem_epan_scope(), *pref->varp.range);
*pref->varp.range = newrange;
+ containing_module->prefs_changed = TRUE;
+
+ /* Name of preference is the dissector table */
+ sub_dissectors = find_dissector_table(pref->name);
+ if (sub_dissectors != NULL) {
+ handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)module->title);
+ if (handle != NULL) {
+ /* Delete all of the old values from the dissector table */
+ for (i = 0; i < (*pref->varp.range)->nranges; i++) {
+ for (j = (*pref->varp.range)->ranges[i].low; j < (*pref->varp.range)->ranges[i].high; j++) {
+ dissector_delete_uint(pref->name, j, handle);
+ decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(j), NULL, NULL);
+ }
+
+ dissector_delete_uint(pref->name, (*pref->varp.range)->ranges[i].high, handle);
+ decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER((*pref->varp.range)->ranges[i].high), NULL, NULL);
+ }
+
+ /* Add new values to the dissector table */
+ for (i = 0; i < newrange->nranges; i++) {
+ for (j = newrange->ranges[i].low; j < newrange->ranges[i].high; j++) {
+ dissector_change_uint(pref->name, j, handle);
+ decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(j), NULL, NULL);
+ }
+
+ dissector_change_uint(pref->name, newrange->ranges[i].high, handle);
+ decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(newrange->ranges[i].high), NULL, NULL);
+ }
+
+ /* XXX - Do we save the decode_as_entries file here? */
+ }
+ }
} else {
- g_free (newrange);
+ wmem_free(wmem_epan_scope(), newrange);
}
break;
}
case PREF_COLOR:
{
cval = strtoul(value, NULL, 16);
- pref->varp.colorp->pixel = 0;
if ((pref->varp.colorp->red != RED_COMPONENT(cval)) ||
(pref->varp.colorp->green != GREEN_COMPONENT(cval)) ||
(pref->varp.colorp->blue != BLUE_COMPONENT(cval))) {
- module->prefs_changed = TRUE;
+ containing_module->prefs_changed = TRUE;
pref->varp.colorp->red = RED_COMPONENT(cval);
pref->varp.colorp->green = GREEN_COMPONENT(cval);
pref->varp.colorp->blue = BLUE_COMPONENT(cval);
}
case PREF_CUSTOM:
- return pref->custom_cbs.set_cb(pref, value, &module->prefs_changed);
+ return pref->custom_cbs.set_cb(pref, value, &containing_module->prefs_changed);
case PREF_STATIC_TEXT:
case PREF_UAT:
{
break;
}
-
- case PREF_OBSOLETE:
- return PREFS_SET_OBSOLETE; /* no such preference any more */
}
}
prefs_pref_type_name(pref_t *pref)
{
const char *type_name = "[Unknown]";
+ int type;
if (!pref) {
return type_name; /* ...or maybe assert? */
}
- switch (pref->type) {
+ type = pref->type;
+
+ if (IS_PREF_OBSOLETE(type)) {
+ type_name = "Obsolete";
+ } else {
+ RESET_PREF_OBSOLETE(type);
+ }
+
+ switch (type) {
case PREF_UINT:
switch (pref->info.base) {
type_name = "Custom";
break;
- case PREF_OBSOLETE:
- type_name = "Obsolete";
+ case PREF_DECODE_AS_UINT:
+ type_name = "Decode As value";
+ break;
+
+ case PREF_DECODE_AS_RANGE:
+ type_name = "Range (for Decode As)";
break;
case PREF_STATIC_TEXT:
char *
prefs_pref_type_description(pref_t *pref)
{
- const char *type_desc = "An unkown preference type";
+ const char *type_desc = "An unknown preference type";
+ int type;
if (!pref) {
return g_strdup_printf("%s.", type_desc); /* ...or maybe assert? */
}
- switch (pref->type) {
+ type = pref->type;
+
+ if (IS_PREF_OBSOLETE(type)) {
+ type_desc = "An obsolete preference";
+ } else {
+ RESET_PREF_OBSOLETE(type);
+ }
+
+ switch (type) {
case PREF_UINT:
switch (pref->info.base) {
type_desc = "A custom value";
break;
- case PREF_OBSOLETE:
- type_desc = "An obsolete preference";
+ case PREF_DECODE_AS_UINT:
+ type_desc = "An integer value used in Decode As";
+ break;
+
+ case PREF_DECODE_AS_RANGE:
+ type_desc = "A string denoting an positive integer range for Decode As";
break;
case PREF_STATIC_TEXT:
return g_strdup(type_desc);
}
-static gboolean
-prefs_pref_is_default(pref_t *pref) {
+gboolean
+prefs_pref_is_default(pref_t *pref)
+{
+ int type;
if (!pref) return FALSE;
- switch (pref->type) {
+ type = pref->type;
+ if (IS_PREF_OBSOLETE(type)) {
+ return FALSE;
+ } else {
+ RESET_PREF_OBSOLETE(type);
+ }
+
+ switch (type) {
+
+ case PREF_DECODE_AS_UINT:
+ if (pref->default_val.uint == *pref->varp.uint)
+ return TRUE;
+ break;
case PREF_UINT:
if (pref->default_val.uint == *pref->varp.uint)
return TRUE;
break;
+ case PREF_DECODE_AS_RANGE:
case PREF_RANGE:
{
if ((ranges_are_equal(pref->default_val.range, *pref->varp.range)))
case PREF_CUSTOM:
return pref->custom_cbs.is_default_cb(pref);
- case PREF_OBSOLETE:
case PREF_STATIC_TEXT:
case PREF_UAT:
return FALSE;
const char *pref_text = "[Unknown]";
void *valp; /* pointer to preference value */
color_t *pref_color;
+ gchar *tmp_value, *ret_value;
+ int type;
if (!pref) {
return g_strdup(pref_text);
return g_strdup(pref_text);
}
- switch (pref->type) {
+ type = pref->type;
+ if (IS_PREF_OBSOLETE(type)) {
+ pref_text = "[Obsolete]";
+ } else {
+ RESET_PREF_OBSOLETE(type);
+ }
+
+ switch (type) {
+ case PREF_DECODE_AS_UINT:
case PREF_UINT:
{
guint pref_uint = *(guint *) valp;
}
case PREF_BOOL:
- return g_strdup_printf("%s", (*(gboolean *) valp) ? "TRUE" : "FALSE");
+ return g_strdup((*(gboolean *) valp) ? "TRUE" : "FALSE");
case PREF_ENUM:
{
case PREF_DIRNAME:
return g_strdup(*(const char **) valp);
+ case PREF_DECODE_AS_RANGE:
case PREF_RANGE:
- pref_text = range_convert_range(*(range_t **) valp);
- break;
+ /* Convert wmem to g_alloc memory */
+ tmp_value = range_convert_range(NULL, *(range_t **) valp);
+ ret_value = g_strdup(tmp_value);
+ wmem_free(NULL, tmp_value);
+ return ret_value;
case PREF_COLOR:
return g_strdup_printf("%02x%02x%02x",
pref_text = "[Custom]";
break;
- case PREF_OBSOLETE:
- pref_text = "[Obsolete]";
- break;
-
case PREF_STATIC_TEXT:
pref_text = "[Static text]";
break;
write_pref_arg_t *arg = (write_pref_arg_t *)user_data;
gchar **desc_lines;
int i;
+ int type;
- switch (pref->type) {
- case PREF_OBSOLETE:
+ type = pref->type;
+
+ if (IS_PREF_OBSOLETE(type)) {
/*
* This preference is no longer supported; it's not a
* real preference, so we don't write it out (i.e., we
* preferences, and we weren't called in the first place).
*/
return;
+ } else {
+ RESET_PREF_OBSOLETE(type);
+ }
+
+ switch (type) {
case PREF_STATIC_TEXT:
case PREF_UAT:
/* Nothing to do; don't bother printing the description */
return;
+ case PREF_DECODE_AS_UINT:
+ case PREF_DECODE_AS_RANGE:
+ /* Data is saved through Decode As mechanism and not part of preferences file */
+ return;
default:
break;
}
*pf_path_return = pf_path;
return errno;
}
+ g_free(pf_path);
} else {
pf = stdout;
}
struct filter_expression *fe = *(struct filter_expression **)prefs.filter_expressions;
if (fe != NULL)
- fprintf(pf, "\n####### Filter Expressions ########\n");
+ fprintf(pf, "\n####### Filter Expressions ########\n\n");
while (fe != NULL) {
if (fe->deleted == FALSE) {
* it's freed here
*/
static void
-free_col_info(GList * list)
+free_col_info(GList *list)
{
fmt_data *cfmt;
+ GList *list_head = list;
while (list != NULL) {
cfmt = (fmt_data *)list->data;
g_free(cfmt->title);
- g_free(cfmt->custom_field);
+ g_free(cfmt->custom_fields);
g_free(cfmt);
- list = g_list_remove_link(list, list);
+ list = g_list_next(list);
}
- g_list_free(list);
- list = NULL;
+ g_list_free(list_head);
}
/*