mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
Merge with git+ssh://pasky.or.cz/srv/git/elinks.git
This commit is contained in:
commit
c07168e579
@ -60,37 +60,7 @@ write_config_dialog(struct terminal *term, unsigned char *config_file,
|
||||
return;
|
||||
}
|
||||
|
||||
switch (secsave_error) {
|
||||
case SS_ERR_OPEN_READ:
|
||||
strerr = _("Cannot read the file", term);
|
||||
break;
|
||||
case SS_ERR_STAT:
|
||||
strerr = _("Cannot get file status", term);
|
||||
break;
|
||||
case SS_ERR_ACCESS:
|
||||
strerr = _("Cannot access the file", term);
|
||||
break;
|
||||
case SS_ERR_MKSTEMP:
|
||||
strerr = _("Cannot create temp file", term);
|
||||
break;
|
||||
case SS_ERR_RENAME:
|
||||
strerr = _("Cannot rename the file", term);
|
||||
break;
|
||||
case SS_ERR_DISABLED:
|
||||
strerr = _("File saving disabled by option", term);
|
||||
break;
|
||||
case SS_ERR_OUT_OF_MEM:
|
||||
strerr = _("Out of memory", term);
|
||||
break;
|
||||
case SS_ERR_OPEN_WRITE:
|
||||
strerr = _("Cannot write the file", term);
|
||||
break;
|
||||
case SS_ERR_NONE: /* Impossible. */
|
||||
case SS_ERR_OTHER:
|
||||
default:
|
||||
strerr = _("Secure file saving error", term);
|
||||
break;
|
||||
}
|
||||
strerr = secsave_strerror(secsave_error, term);
|
||||
|
||||
if (stdio_error > 0)
|
||||
errmsg = straconcat(strerr, " (", strerror(stdio_error), ")", NULL);
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "intl/gettext/libintl.h"
|
||||
#include "main/module.h"
|
||||
#include "main/object.h"
|
||||
#include "main/select.h"
|
||||
#include "protocol/date.h"
|
||||
#include "protocol/header.h"
|
||||
#include "protocol/protocol.h"
|
||||
@ -69,6 +70,7 @@ static INIT_LIST_HEAD(c_domains);
|
||||
* struct cookie_server. */
|
||||
static INIT_LIST_HEAD(cookie_servers);
|
||||
|
||||
/* Only @set_cookies_dirty may make this nonzero. */
|
||||
static int cookies_dirty = 0;
|
||||
|
||||
enum cookies_option {
|
||||
@ -207,6 +209,10 @@ done_cookie(struct cookie *c)
|
||||
mem_free(c);
|
||||
}
|
||||
|
||||
/* The cookie @c can be either in @cookies or in @cookie_queries.
|
||||
* Because changes in @cookie_queries should not affect the cookie
|
||||
* file, this function does not set @cookies_dirty. Instead, the
|
||||
* caller must do that if appropriate. */
|
||||
void
|
||||
delete_cookie(struct cookie *c)
|
||||
{
|
||||
@ -498,11 +504,12 @@ accept_cookie(struct cookie *cookie)
|
||||
continue;
|
||||
|
||||
delete_cookie(c);
|
||||
/* @set_cookies_dirty will be called below. */
|
||||
}
|
||||
}
|
||||
|
||||
add_to_list(cookies, cookie);
|
||||
cookies_dirty = 1;
|
||||
set_cookies_dirty();
|
||||
|
||||
/* XXX: This crunches CPU too. --pasky */
|
||||
foreach (cd, c_domains)
|
||||
@ -516,9 +523,6 @@ accept_cookie(struct cookie *cookie)
|
||||
|
||||
memcpy(cd->domain, cookie->domain, domain_len + 1);
|
||||
add_to_list(c_domains, cd);
|
||||
|
||||
if (get_cookies_save() && get_cookies_resave())
|
||||
save_cookies();
|
||||
}
|
||||
|
||||
#if 0
|
||||
@ -545,9 +549,6 @@ delete_cookie(struct cookie *c)
|
||||
end:
|
||||
del_from_list(c);
|
||||
done_cookie(c);
|
||||
|
||||
if (get_cookies_save() && get_cookies_resave())
|
||||
save_cookies();
|
||||
}
|
||||
|
||||
|
||||
@ -573,6 +574,7 @@ reject_cookie(void *idp)
|
||||
if (!c) return;
|
||||
|
||||
delete_cookie(c);
|
||||
set_cookies_dirty(); /* @find_cookie_id doesn't use @cookie_queries */
|
||||
}
|
||||
|
||||
|
||||
@ -675,7 +677,7 @@ send_cookies(struct uri *uri)
|
||||
#endif
|
||||
delete_cookie(c);
|
||||
|
||||
cookies_dirty = 1;
|
||||
set_cookies_dirty();
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -696,9 +698,6 @@ send_cookies(struct uri *uri)
|
||||
|
||||
mem_free(path);
|
||||
|
||||
if (cookies_dirty && get_cookies_save() && get_cookies_resave())
|
||||
save_cookies();
|
||||
|
||||
if (!header.length) {
|
||||
done_string(&header);
|
||||
return NULL;
|
||||
@ -768,7 +767,7 @@ load_cookies(void) {
|
||||
/* Skip expired cookies if any. */
|
||||
expires = str_to_time_t(members[EXPIRES].pos);
|
||||
if (!expires || expires <= now) {
|
||||
cookies_dirty = 1;
|
||||
set_cookies_dirty();
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -799,23 +798,82 @@ load_cookies(void) {
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
static void
|
||||
resave_cookies_bottom_half(void *always_null)
|
||||
{
|
||||
if (get_cookies_save() && get_cookies_resave())
|
||||
save_cookies(NULL); /* checks cookies_dirty */
|
||||
}
|
||||
|
||||
/* Note that the cookies have been modified, and register a bottom
|
||||
* half for saving them if appropriate. We use a bottom half so that
|
||||
* if something makes multiple changes and calls this for each change,
|
||||
* the cookies get saved only once at the end. */
|
||||
void
|
||||
save_cookies(void) {
|
||||
set_cookies_dirty(void)
|
||||
{
|
||||
/* Do not check @cookies_dirty here. If the previous attempt
|
||||
* to save cookies failed, @cookies_dirty can still be nonzero
|
||||
* even though @resave_cookies_bottom_half is no longer in the
|
||||
* queue. */
|
||||
cookies_dirty = 1;
|
||||
/* If @resave_cookies_bottom_half is already in the queue,
|
||||
* @register_bottom_half does nothing. */
|
||||
register_bottom_half(resave_cookies_bottom_half, NULL);
|
||||
}
|
||||
|
||||
/* @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(struct terminal *term) {
|
||||
struct cookie *c;
|
||||
unsigned char *cookfile;
|
||||
struct secure_save_info *ssi;
|
||||
time_t now;
|
||||
|
||||
if (cookies_nosave || !elinks_home || !cookies_dirty
|
||||
|| 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) {
|
||||
@ -829,7 +887,13 @@ save_cookies(void) {
|
||||
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
|
||||
@ -839,6 +903,8 @@ init_cookies(struct module *module)
|
||||
load_cookies();
|
||||
}
|
||||
|
||||
/* Like @delete_cookie, this function does not set @cookies_dirty.
|
||||
* The caller must do that if appropriate. */
|
||||
static void
|
||||
free_cookies_list(struct list_head *list)
|
||||
{
|
||||
@ -855,10 +921,15 @@ done_cookies(struct module *module)
|
||||
free_list(c_domains);
|
||||
|
||||
if (!cookies_nosave && get_cookies_save())
|
||||
save_cookies();
|
||||
save_cookies(NULL);
|
||||
|
||||
free_cookies_list(&cookies);
|
||||
free_cookies_list(&cookie_queries);
|
||||
/* If @save_cookies failed above, @cookies_dirty can still be
|
||||
* nonzero. Now if @resave_cookies_bottom_half were in the
|
||||
* queue, it could save the empty @cookies list to the file.
|
||||
* Prevent that. */
|
||||
cookies_dirty = 0;
|
||||
}
|
||||
|
||||
struct module cookies_module = struct_module(
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "util/time.h"
|
||||
|
||||
struct listbox_item;
|
||||
struct terminal;
|
||||
|
||||
enum cookies_accept {
|
||||
COOKIES_ACCEPT_NONE,
|
||||
@ -44,7 +45,8 @@ void done_cookie(struct cookie *);
|
||||
void delete_cookie(struct cookie *);
|
||||
void set_cookie(struct uri *, unsigned char *);
|
||||
void load_cookies(void);
|
||||
void save_cookies(void);
|
||||
void save_cookies(struct terminal *);
|
||||
void set_cookies_dirty(void);
|
||||
|
||||
/* Note that the returned value points to a static structure and thus the
|
||||
* string will be overwritten at the next call time. The string source
|
||||
|
@ -188,12 +188,8 @@ delete_cookie_item(struct listbox_item *item, int last)
|
||||
assert(!is_object_used(cookie));
|
||||
|
||||
delete_cookie(cookie);
|
||||
set_cookies_dirty();
|
||||
}
|
||||
|
||||
if (last
|
||||
&& get_opt_bool("cookies.save")
|
||||
&& get_opt_bool("cookies.resave"))
|
||||
save_cookies();
|
||||
}
|
||||
|
||||
static struct listbox_ops_messages cookies_messages = {
|
||||
@ -246,6 +242,7 @@ set_cookie_name(struct dialog_data *dlg_data, struct widget_data *widget_data)
|
||||
|
||||
if (!value || !cookie) return EVENT_NOT_PROCESSED;
|
||||
mem_free_set(&cookie->name, stracpy(value));
|
||||
set_cookies_dirty();
|
||||
return EVENT_PROCESSED;
|
||||
}
|
||||
|
||||
@ -257,6 +254,7 @@ set_cookie_value(struct dialog_data *dlg_data, struct widget_data *widget_data)
|
||||
|
||||
if (!value || !cookie) return EVENT_NOT_PROCESSED;
|
||||
mem_free_set(&cookie->value, stracpy(value));
|
||||
set_cookies_dirty();
|
||||
return EVENT_PROCESSED;
|
||||
}
|
||||
|
||||
@ -268,6 +266,7 @@ set_cookie_domain(struct dialog_data *dlg_data, struct widget_data *widget_data)
|
||||
|
||||
if (!value || !cookie) return EVENT_NOT_PROCESSED;
|
||||
mem_free_set(&cookie->domain, stracpy(value));
|
||||
set_cookies_dirty();
|
||||
return EVENT_PROCESSED;
|
||||
}
|
||||
|
||||
@ -286,6 +285,7 @@ set_cookie_expires(struct dialog_data *dlg_data, struct widget_data *widget_data
|
||||
if (errno || *end || number < 0) return EVENT_NOT_PROCESSED;
|
||||
|
||||
cookie->expires = (time_t) number;
|
||||
set_cookies_dirty();
|
||||
return EVENT_PROCESSED;
|
||||
}
|
||||
|
||||
@ -304,6 +304,7 @@ set_cookie_secure(struct dialog_data *dlg_data, struct widget_data *widget_data)
|
||||
if (errno || *end) return EVENT_NOT_PROCESSED;
|
||||
|
||||
cookie->secure = (number != 0);
|
||||
set_cookies_dirty();
|
||||
return EVENT_PROCESSED;
|
||||
}
|
||||
|
||||
@ -464,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();
|
||||
save_cookies(dlg_data->win->term);
|
||||
return EVENT_PROCESSED;
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "elinks.h"
|
||||
|
||||
#include "config/options.h"
|
||||
#include "intl/gettext/libintl.h"
|
||||
#include "osdep/osdep.h" /* Needed for mkstemp() on win32 */
|
||||
#include "util/memory.h"
|
||||
#include "util/secsave.h"
|
||||
@ -350,3 +351,30 @@ secure_fprintf(struct secure_save_info *ssi, const char *format, ...)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
unsigned char *
|
||||
secsave_strerror(enum secsave_errno secsave_error, struct terminal *term)
|
||||
{
|
||||
switch (secsave_error) {
|
||||
case SS_ERR_OPEN_READ:
|
||||
return _("Cannot read the file", term);
|
||||
case SS_ERR_STAT:
|
||||
return _("Cannot get file status", term);
|
||||
case SS_ERR_ACCESS:
|
||||
return _("Cannot access the file", term);
|
||||
case SS_ERR_MKSTEMP:
|
||||
return _("Cannot create temp file", term);
|
||||
case SS_ERR_RENAME:
|
||||
return _("Cannot rename the file", term);
|
||||
case SS_ERR_DISABLED:
|
||||
return _("File saving disabled by option", term);
|
||||
case SS_ERR_OUT_OF_MEM:
|
||||
return _("Out of memory", term);
|
||||
case SS_ERR_OPEN_WRITE:
|
||||
return _("Cannot write the file", term);
|
||||
case SS_ERR_NONE: /* Impossible. */
|
||||
case SS_ERR_OTHER:
|
||||
default:
|
||||
return _("Secure file saving error", term);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h> /* mode_t */
|
||||
|
||||
struct terminal;
|
||||
|
||||
enum secsave_errno {
|
||||
SS_ERR_NONE = 0,
|
||||
SS_ERR_DISABLED, /* secsave is disabled. */
|
||||
@ -40,4 +42,6 @@ int secure_fputc(struct secure_save_info *, int);
|
||||
|
||||
int secure_fprintf(struct secure_save_info *, const char *, ...);
|
||||
|
||||
unsigned char *secsave_strerror(enum secsave_errno, struct terminal *);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user