From e815e071797aa5aa97261a10eb1a373c2e4c308c Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sat, 9 Dec 2006 18:27:40 +0200 Subject: [PATCH] Bug 887: save_cookies reports errors if requested by the user. --- src/cookies/cookies.c | 59 +++++++++++++++++++++++++++++++++++-------- src/cookies/cookies.h | 3 ++- src/cookies/dialogs.c | 2 +- 3 files changed, 51 insertions(+), 13 deletions(-) diff --git a/src/cookies/cookies.c b/src/cookies/cookies.c index 4c7c32a1c..ab5810b23 100644 --- a/src/cookies/cookies.c +++ b/src/cookies/cookies.c @@ -802,7 +802,7 @@ static void resave_cookies_bottom_half(void *always_null) { if (get_cookies_save() && get_cookies_resave()) - save_cookies(0); /* checks cookies_dirty */ + save_cookies(NULL); /* checks cookies_dirty */ } /* Note that the cookies have been modified, and register a bottom @@ -822,27 +822,58 @@ set_cookies_dirty(void) register_bottom_half(resave_cookies_bottom_half, NULL); } -/* @interactive is 1 if the user told ELinks to save cookies, or 0 if - * ELinks decided that on its own. In the latter case, this function - * does not save the cookies if it thinks the file is already up to - * date. */ +/* @term is non-NULL if the user told ELinks to save cookies, or NULL + * if ELinks decided that on its own. In the former case, this + * function reports errors to @term, unless CONFIG_SMALL is defined. + * In the latter case, this function does not save the cookies if it + * thinks the file is already up to date. */ void -save_cookies(int interactive) { +save_cookies(struct terminal *term) { struct cookie *c; unsigned char *cookfile; struct secure_save_info *ssi; time_t now; - if (cookies_nosave || !elinks_home || !(cookies_dirty || interactive) - || get_cmd_opt_bool("anonymous")) +#ifdef CONFIG_SMALL +# define CANNOT_SAVE_COOKIES(message) +#else +# define CANNOT_SAVE_COOKIES(flags, message) \ + do { \ + if (term) \ + info_box(term, flags, N_("Cannot save cookies"),\ + ALIGN_LEFT, message); \ + } while (0) +#endif + + if (cookies_nosave) { + assert(term == NULL); + if_assert_failed {} return; + } + if (!elinks_home) { + CANNOT_SAVE_COOKIES(0, N_("ELinks was started without a home directory.")); + return; + } + if (!cookies_dirty && !term) + return; + if (get_cmd_opt_bool("anonymous")) { + CANNOT_SAVE_COOKIES(0, N_("ELinks was started with the -anonymous option.")); + return; + } cookfile = straconcat(elinks_home, COOKIES_FILENAME, NULL); - if (!cookfile) return; + if (!cookfile) { + CANNOT_SAVE_COOKIES(0, N_("Out of memory")); + return; + } ssi = secure_open(cookfile); mem_free(cookfile); - if (!ssi) return; + if (!ssi) { + CANNOT_SAVE_COOKIES(MSGBOX_NO_TEXT_INTL, + secsave_strerror(secsave_errno, term)); + return; + } now = time(NULL); foreach (c, cookies) { @@ -856,7 +887,13 @@ save_cookies(int interactive) { break; } + secsave_errno = SS_ERR_OTHER; /* @secure_close doesn't always set it */ if (!secure_close(ssi)) cookies_dirty = 0; + else { + CANNOT_SAVE_COOKIES(MSGBOX_NO_TEXT_INTL, + secsave_strerror(secsave_errno, term)); + } +#undef CANNOT_SAVE_COOKIES } static void @@ -884,7 +921,7 @@ done_cookies(struct module *module) free_list(c_domains); if (!cookies_nosave && get_cookies_save()) - save_cookies(0); + save_cookies(NULL); free_cookies_list(&cookies); free_cookies_list(&cookie_queries); diff --git a/src/cookies/cookies.h b/src/cookies/cookies.h index bf67ae7de..4a7dfa483 100644 --- a/src/cookies/cookies.h +++ b/src/cookies/cookies.h @@ -8,6 +8,7 @@ #include "util/time.h" struct listbox_item; +struct terminal; enum cookies_accept { COOKIES_ACCEPT_NONE, @@ -44,7 +45,7 @@ void done_cookie(struct cookie *); void delete_cookie(struct cookie *); void set_cookie(struct uri *, unsigned char *); void load_cookies(void); -void save_cookies(int interactive); +void save_cookies(struct terminal *); void set_cookies_dirty(void); /* Note that the returned value points to a static structure and thus the diff --git a/src/cookies/dialogs.c b/src/cookies/dialogs.c index 9d6bdf219..3af9c3dc2 100644 --- a/src/cookies/dialogs.c +++ b/src/cookies/dialogs.c @@ -465,7 +465,7 @@ push_add_server_button(struct dialog_data *dlg_data, struct widget_data *button) static widget_handler_status_T push_save_button(struct dialog_data *dlg_data, struct widget_data *button) { - save_cookies(1); + save_cookies(dlg_data->win->term); return EVENT_PROCESSED; }