mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Bug 887: save_cookies reports errors if requested by the user.
This commit is contained in:
parent
7551be3194
commit
e815e07179
@ -802,7 +802,7 @@ static void
|
|||||||
resave_cookies_bottom_half(void *always_null)
|
resave_cookies_bottom_half(void *always_null)
|
||||||
{
|
{
|
||||||
if (get_cookies_save() && get_cookies_resave())
|
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
|
/* 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);
|
register_bottom_half(resave_cookies_bottom_half, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @interactive is 1 if the user told ELinks to save cookies, or 0 if
|
/* @term is non-NULL if the user told ELinks to save cookies, or NULL
|
||||||
* ELinks decided that on its own. In the latter case, this function
|
* if ELinks decided that on its own. In the former case, this
|
||||||
* does not save the cookies if it thinks the file is already up to
|
* function reports errors to @term, unless CONFIG_SMALL is defined.
|
||||||
* date. */
|
* In the latter case, this function does not save the cookies if it
|
||||||
|
* thinks the file is already up to date. */
|
||||||
void
|
void
|
||||||
save_cookies(int interactive) {
|
save_cookies(struct terminal *term) {
|
||||||
struct cookie *c;
|
struct cookie *c;
|
||||||
unsigned char *cookfile;
|
unsigned char *cookfile;
|
||||||
struct secure_save_info *ssi;
|
struct secure_save_info *ssi;
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
||||||
if (cookies_nosave || !elinks_home || !(cookies_dirty || interactive)
|
#ifdef CONFIG_SMALL
|
||||||
|| get_cmd_opt_bool("anonymous"))
|
# 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;
|
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);
|
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);
|
ssi = secure_open(cookfile);
|
||||||
mem_free(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);
|
now = time(NULL);
|
||||||
foreach (c, cookies) {
|
foreach (c, cookies) {
|
||||||
@ -856,7 +887,13 @@ save_cookies(int interactive) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
secsave_errno = SS_ERR_OTHER; /* @secure_close doesn't always set it */
|
||||||
if (!secure_close(ssi)) cookies_dirty = 0;
|
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
|
static void
|
||||||
@ -884,7 +921,7 @@ done_cookies(struct module *module)
|
|||||||
free_list(c_domains);
|
free_list(c_domains);
|
||||||
|
|
||||||
if (!cookies_nosave && get_cookies_save())
|
if (!cookies_nosave && get_cookies_save())
|
||||||
save_cookies(0);
|
save_cookies(NULL);
|
||||||
|
|
||||||
free_cookies_list(&cookies);
|
free_cookies_list(&cookies);
|
||||||
free_cookies_list(&cookie_queries);
|
free_cookies_list(&cookie_queries);
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "util/time.h"
|
#include "util/time.h"
|
||||||
|
|
||||||
struct listbox_item;
|
struct listbox_item;
|
||||||
|
struct terminal;
|
||||||
|
|
||||||
enum cookies_accept {
|
enum cookies_accept {
|
||||||
COOKIES_ACCEPT_NONE,
|
COOKIES_ACCEPT_NONE,
|
||||||
@ -44,7 +45,7 @@ void done_cookie(struct cookie *);
|
|||||||
void delete_cookie(struct cookie *);
|
void delete_cookie(struct cookie *);
|
||||||
void set_cookie(struct uri *, unsigned char *);
|
void set_cookie(struct uri *, unsigned char *);
|
||||||
void load_cookies(void);
|
void load_cookies(void);
|
||||||
void save_cookies(int interactive);
|
void save_cookies(struct terminal *);
|
||||||
void set_cookies_dirty(void);
|
void set_cookies_dirty(void);
|
||||||
|
|
||||||
/* Note that the returned value points to a static structure and thus the
|
/* Note that the returned value points to a static structure and thus the
|
||||||
|
@ -465,7 +465,7 @@ push_add_server_button(struct dialog_data *dlg_data, struct widget_data *button)
|
|||||||
static widget_handler_status_T
|
static widget_handler_status_T
|
||||||
push_save_button(struct dialog_data *dlg_data, struct widget_data *button)
|
push_save_button(struct dialog_data *dlg_data, struct widget_data *button)
|
||||||
{
|
{
|
||||||
save_cookies(1);
|
save_cookies(dlg_data->win->term);
|
||||||
return EVENT_PROCESSED;
|
return EVENT_PROCESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user