diff options
author | Guy Harris <guy@alum.mit.edu> | 2004-10-12 03:13:17 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2004-10-12 03:13:17 +0000 |
commit | eb088099b072573c67bc1a1be5e0bebea63606f0 (patch) | |
tree | dfcd8547c0c8a6a202b15be471f2b0a59d8de34d /gtk/prefs_dlg.c | |
parent | 38ed258bc5871f85fc52a83d60f2dc9d92fd7a83 (diff) |
Check the values of the protocol preferences before fetching them; if
any are not valid, pop up an alert box and don't dismiss the preferences
dialog.
svn path=/trunk/; revision=12269
Diffstat (limited to 'gtk/prefs_dlg.c')
-rw-r--r-- | gtk/prefs_dlg.c | 106 |
1 files changed, 93 insertions, 13 deletions
diff --git a/gtk/prefs_dlg.c b/gtk/prefs_dlg.c index d52e3a8ff2..cf329a0524 100644 --- a/gtk/prefs_dlg.c +++ b/gtk/prefs_dlg.c @@ -213,7 +213,7 @@ pref_show(pref_t *pref, gpointer user_data) #define MAX_TREE_NODE_NAME_LEN 64 /* show prefs page for each registered module (protocol) */ -static void +static guint module_prefs_show(module_t *module, gpointer user_data) { struct ct_struct *cts = user_data; @@ -243,7 +243,7 @@ module_prefs_show(module_t *module, gpointer user_data) * nothing under it that will be displayed, don't put it into * the window. */ - return; + return 0; } } @@ -334,6 +334,8 @@ module_prefs_show(module_t *module, gpointer user_data) /* Show 'em what we got */ gtk_widget_show_all(main_vb); } + + return 0; } @@ -853,6 +855,53 @@ create_preference_entry(GtkWidget *main_tb, int table_position, } static guint +pref_check(pref_t *pref, gpointer user_data) +{ + const char *str_val; + char *p; + guint uval; + pref_t **badpref = user_data; + + /* Fetch the value of the preference, and check whether it's valid. */ + switch (pref->type) { + + case PREF_UINT: + str_val = gtk_entry_get_text(GTK_ENTRY(pref->control)); + uval = strtoul(str_val, &p, pref->info.base); + if (p == str_val || *p != '\0') { + *badpref = pref; + return PREFS_SET_SYNTAX_ERR; /* number was bad */ + } + break; + + case PREF_BOOL: + /* Value can't be bad. */ + break; + + case PREF_ENUM: + /* Value can't be bad. */ + break; + + case PREF_STRING: + /* Value can't be bad. */ + break; + + case PREF_OBSOLETE: + g_assert_not_reached(); + break; + } + return 0; +} + +static guint +module_prefs_check(module_t *module, gpointer user_data) +{ + /* For all preferences in this module, fetch its value from this + module's notebook page and check whether it's valid. */ + return prefs_pref_foreach(module, pref_check, user_data); +} + +static guint pref_fetch(pref_t *pref, gpointer user_data) { const char *str_val; @@ -918,7 +967,7 @@ pref_fetch(pref_t *pref, gpointer user_data) return 0; } -static void +static guint module_prefs_fetch(module_t *module, gpointer user_data) { gboolean *must_redissect_p = user_data; @@ -933,6 +982,8 @@ module_prefs_fetch(module_t *module, gpointer user_data) could cause packets to be dissected differently. */ if (module->prefs_changed) *must_redissect_p = TRUE; + + return 0; /* keep fetching module preferences */ } static guint @@ -963,19 +1014,40 @@ pref_clean(pref_t *pref, gpointer user_data _U_) return 0; } -static void +static guint module_prefs_clean(module_t *module, gpointer user_data _U_) { /* For all preferences in this module, clean up any cruft allocated for use by the GUI code. */ prefs_pref_foreach(module, pref_clean, NULL); + return 0; /* keep cleaning modules */ } - /* fetch all pref values from all pages */ -static void +static gboolean prefs_main_fetch_all(GtkWidget *dlg, gboolean *must_redissect) { + pref_t *badpref; + + /* First, check that the values are all valid. */ + /* XXX - check the non-registered preferences too */ + switch (prefs_modules_foreach(module_prefs_check, (gpointer)&badpref)) { + + case PREFS_SET_SYNTAX_ERR: + switch (badpref->type) { + + case PREF_UINT: + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, + "The value for \"%s\" is not a valid number.", + badpref->title); + return FALSE; + + default: + g_assert_not_reached(); + break; + } + } + /* Fetch the preferences (i.e., make sure all the values set in all of the preferences panes have been copied to "prefs" and the registered preferences). */ @@ -998,8 +1070,9 @@ prefs_main_fetch_all(GtkWidget *dlg, gboolean *must_redissect) nameres_prefs_fetch(OBJECT_GET_DATA(dlg, E_NAMERES_PAGE_KEY)); prefs_modules_foreach(module_prefs_fetch, must_redissect); -} + return TRUE; +} /* apply all pref values to the real world */ static void @@ -1066,7 +1139,8 @@ prefs_main_ok_cb(GtkWidget *ok_bt _U_, gpointer parent_w) { gboolean must_redissect = FALSE; - prefs_main_fetch_all(parent_w, &must_redissect); + if (!prefs_main_fetch_all(parent_w, &must_redissect)) + return; /* Errors in some preference setting */ prefs_main_apply_all(parent_w); @@ -1084,7 +1158,8 @@ prefs_main_apply_cb(GtkWidget *apply_bt _U_, gpointer parent_w) { gboolean must_redissect = FALSE; - prefs_main_fetch_all(parent_w, &must_redissect); + if (!prefs_main_fetch_all(parent_w, &must_redissect)) + return; /* Errors in some preference setting */ prefs_main_apply_all(parent_w); @@ -1102,7 +1177,8 @@ prefs_main_save_cb(GtkWidget *save_bt _U_, gpointer parent_w) char *pf_dir_path; char *pf_path; - prefs_main_fetch_all(parent_w, &must_redissect); + if (!prefs_main_fetch_all(parent_w, &must_redissect)) + return; /* Errors in some preference setting */ /* Create the directory that holds personal configuration files, if necessary. */ @@ -1188,7 +1264,7 @@ pref_revert(pref_t *pref, gpointer user_data) return 0; } -static void +static guint module_prefs_revert(module_t *module, gpointer user_data) { gboolean *must_redissect_p = user_data; @@ -1204,6 +1280,7 @@ module_prefs_revert(module_t *module, gpointer user_data) could cause packets to be dissected differently. */ if (module->prefs_changed) *must_redissect_p = TRUE; + return 0; /* keep processing modules */ } /* cancel button pressed, revert prefs to saved and exit dialog */ @@ -1256,14 +1333,17 @@ struct properties_data { module_t *module; }; -static void +static guint module_search_properties(module_t *module, gpointer user_data) { struct properties_data *p = (struct properties_data *)user_data; /* If this module has the specified title, remember it. */ - if (strcmp(module->title, p->title) == 0) + if (strcmp(module->title, p->title) == 0) { p->module = module; + return 1; /* stops the search */ + } + return 0; } void |