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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (secsave_error) {
|
strerr = secsave_strerror(secsave_error, term);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stdio_error > 0)
|
if (stdio_error > 0)
|
||||||
errmsg = straconcat(strerr, " (", strerror(stdio_error), ")", NULL);
|
errmsg = straconcat(strerr, " (", strerror(stdio_error), ")", NULL);
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include "intl/gettext/libintl.h"
|
#include "intl/gettext/libintl.h"
|
||||||
#include "main/module.h"
|
#include "main/module.h"
|
||||||
#include "main/object.h"
|
#include "main/object.h"
|
||||||
|
#include "main/select.h"
|
||||||
#include "protocol/date.h"
|
#include "protocol/date.h"
|
||||||
#include "protocol/header.h"
|
#include "protocol/header.h"
|
||||||
#include "protocol/protocol.h"
|
#include "protocol/protocol.h"
|
||||||
@ -69,6 +70,7 @@ static INIT_LIST_HEAD(c_domains);
|
|||||||
* struct cookie_server. */
|
* struct cookie_server. */
|
||||||
static INIT_LIST_HEAD(cookie_servers);
|
static INIT_LIST_HEAD(cookie_servers);
|
||||||
|
|
||||||
|
/* Only @set_cookies_dirty may make this nonzero. */
|
||||||
static int cookies_dirty = 0;
|
static int cookies_dirty = 0;
|
||||||
|
|
||||||
enum cookies_option {
|
enum cookies_option {
|
||||||
@ -207,6 +209,10 @@ done_cookie(struct cookie *c)
|
|||||||
mem_free(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
|
void
|
||||||
delete_cookie(struct cookie *c)
|
delete_cookie(struct cookie *c)
|
||||||
{
|
{
|
||||||
@ -498,11 +504,12 @@ accept_cookie(struct cookie *cookie)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
delete_cookie(c);
|
delete_cookie(c);
|
||||||
|
/* @set_cookies_dirty will be called below. */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
add_to_list(cookies, cookie);
|
add_to_list(cookies, cookie);
|
||||||
cookies_dirty = 1;
|
set_cookies_dirty();
|
||||||
|
|
||||||
/* XXX: This crunches CPU too. --pasky */
|
/* XXX: This crunches CPU too. --pasky */
|
||||||
foreach (cd, c_domains)
|
foreach (cd, c_domains)
|
||||||
@ -516,9 +523,6 @@ accept_cookie(struct cookie *cookie)
|
|||||||
|
|
||||||
memcpy(cd->domain, cookie->domain, domain_len + 1);
|
memcpy(cd->domain, cookie->domain, domain_len + 1);
|
||||||
add_to_list(c_domains, cd);
|
add_to_list(c_domains, cd);
|
||||||
|
|
||||||
if (get_cookies_save() && get_cookies_resave())
|
|
||||||
save_cookies();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -545,9 +549,6 @@ delete_cookie(struct cookie *c)
|
|||||||
end:
|
end:
|
||||||
del_from_list(c);
|
del_from_list(c);
|
||||||
done_cookie(c);
|
done_cookie(c);
|
||||||
|
|
||||||
if (get_cookies_save() && get_cookies_resave())
|
|
||||||
save_cookies();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -573,6 +574,7 @@ reject_cookie(void *idp)
|
|||||||
if (!c) return;
|
if (!c) return;
|
||||||
|
|
||||||
delete_cookie(c);
|
delete_cookie(c);
|
||||||
|
set_cookies_dirty(); /* @find_cookie_id doesn't use @cookie_queries */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -675,7 +677,7 @@ send_cookies(struct uri *uri)
|
|||||||
#endif
|
#endif
|
||||||
delete_cookie(c);
|
delete_cookie(c);
|
||||||
|
|
||||||
cookies_dirty = 1;
|
set_cookies_dirty();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -696,9 +698,6 @@ send_cookies(struct uri *uri)
|
|||||||
|
|
||||||
mem_free(path);
|
mem_free(path);
|
||||||
|
|
||||||
if (cookies_dirty && get_cookies_save() && get_cookies_resave())
|
|
||||||
save_cookies();
|
|
||||||
|
|
||||||
if (!header.length) {
|
if (!header.length) {
|
||||||
done_string(&header);
|
done_string(&header);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -768,7 +767,7 @@ load_cookies(void) {
|
|||||||
/* Skip expired cookies if any. */
|
/* Skip expired cookies if any. */
|
||||||
expires = str_to_time_t(members[EXPIRES].pos);
|
expires = str_to_time_t(members[EXPIRES].pos);
|
||||||
if (!expires || expires <= now) {
|
if (!expires || expires <= now) {
|
||||||
cookies_dirty = 1;
|
set_cookies_dirty();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -799,23 +798,82 @@ load_cookies(void) {
|
|||||||
fclose(fp);
|
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
|
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;
|
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
|
#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) {
|
||||||
@ -829,7 +887,13 @@ save_cookies(void) {
|
|||||||
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
|
||||||
@ -839,6 +903,8 @@ init_cookies(struct module *module)
|
|||||||
load_cookies();
|
load_cookies();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Like @delete_cookie, this function does not set @cookies_dirty.
|
||||||
|
* The caller must do that if appropriate. */
|
||||||
static void
|
static void
|
||||||
free_cookies_list(struct list_head *list)
|
free_cookies_list(struct list_head *list)
|
||||||
{
|
{
|
||||||
@ -855,10 +921,15 @@ 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();
|
save_cookies(NULL);
|
||||||
|
|
||||||
free_cookies_list(&cookies);
|
free_cookies_list(&cookies);
|
||||||
free_cookies_list(&cookie_queries);
|
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(
|
struct module cookies_module = struct_module(
|
||||||
|
@ -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,8 @@ 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(void);
|
void save_cookies(struct terminal *);
|
||||||
|
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
|
||||||
* string will be overwritten at the next call time. The string source
|
* 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));
|
assert(!is_object_used(cookie));
|
||||||
|
|
||||||
delete_cookie(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 = {
|
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;
|
if (!value || !cookie) return EVENT_NOT_PROCESSED;
|
||||||
mem_free_set(&cookie->name, stracpy(value));
|
mem_free_set(&cookie->name, stracpy(value));
|
||||||
|
set_cookies_dirty();
|
||||||
return EVENT_PROCESSED;
|
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;
|
if (!value || !cookie) return EVENT_NOT_PROCESSED;
|
||||||
mem_free_set(&cookie->value, stracpy(value));
|
mem_free_set(&cookie->value, stracpy(value));
|
||||||
|
set_cookies_dirty();
|
||||||
return EVENT_PROCESSED;
|
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;
|
if (!value || !cookie) return EVENT_NOT_PROCESSED;
|
||||||
mem_free_set(&cookie->domain, stracpy(value));
|
mem_free_set(&cookie->domain, stracpy(value));
|
||||||
|
set_cookies_dirty();
|
||||||
return EVENT_PROCESSED;
|
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;
|
if (errno || *end || number < 0) return EVENT_NOT_PROCESSED;
|
||||||
|
|
||||||
cookie->expires = (time_t) number;
|
cookie->expires = (time_t) number;
|
||||||
|
set_cookies_dirty();
|
||||||
return EVENT_PROCESSED;
|
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;
|
if (errno || *end) return EVENT_NOT_PROCESSED;
|
||||||
|
|
||||||
cookie->secure = (number != 0);
|
cookie->secure = (number != 0);
|
||||||
|
set_cookies_dirty();
|
||||||
return EVENT_PROCESSED;
|
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
|
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();
|
save_cookies(dlg_data->win->term);
|
||||||
return EVENT_PROCESSED;
|
return EVENT_PROCESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "elinks.h"
|
#include "elinks.h"
|
||||||
|
|
||||||
#include "config/options.h"
|
#include "config/options.h"
|
||||||
|
#include "intl/gettext/libintl.h"
|
||||||
#include "osdep/osdep.h" /* Needed for mkstemp() on win32 */
|
#include "osdep/osdep.h" /* Needed for mkstemp() on win32 */
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
#include "util/secsave.h"
|
#include "util/secsave.h"
|
||||||
@ -350,3 +351,30 @@ secure_fprintf(struct secure_save_info *ssi, const char *format, ...)
|
|||||||
|
|
||||||
return ret;
|
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 <stdio.h>
|
||||||
#include <sys/types.h> /* mode_t */
|
#include <sys/types.h> /* mode_t */
|
||||||
|
|
||||||
|
struct terminal;
|
||||||
|
|
||||||
enum secsave_errno {
|
enum secsave_errno {
|
||||||
SS_ERR_NONE = 0,
|
SS_ERR_NONE = 0,
|
||||||
SS_ERR_DISABLED, /* secsave is disabled. */
|
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 *, ...);
|
int secure_fprintf(struct secure_save_info *, const char *, ...);
|
||||||
|
|
||||||
|
unsigned char *secsave_strerror(enum secsave_errno, struct terminal *);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user