mirror of
https://github.com/rkd77/elinks.git
synced 2025-01-03 14:57:44 -05:00
Prevent successive calls to time(), since it doesn't have much impact.
This commit is contained in:
parent
458fc5ee79
commit
ac5441db9e
@ -602,9 +602,6 @@ is_path_prefix(unsigned char *d, unsigned char *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define is_expired(t) ((t) && (t) <= time(NULL))
|
|
||||||
#define is_dead(t) (!(t) || (t) <= time(NULL))
|
|
||||||
|
|
||||||
struct string *
|
struct string *
|
||||||
send_cookies(struct uri *uri)
|
send_cookies(struct uri *uri)
|
||||||
{
|
{
|
||||||
@ -612,6 +609,7 @@ send_cookies(struct uri *uri)
|
|||||||
struct cookie *c, *next;
|
struct cookie *c, *next;
|
||||||
unsigned char *path = NULL;
|
unsigned char *path = NULL;
|
||||||
static struct string header;
|
static struct string header;
|
||||||
|
time_t now;
|
||||||
|
|
||||||
if (!uri->host || !uri->data)
|
if (!uri->host || !uri->data)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -626,12 +624,13 @@ send_cookies(struct uri *uri)
|
|||||||
|
|
||||||
init_string(&header);
|
init_string(&header);
|
||||||
|
|
||||||
|
now = time(NULL);
|
||||||
foreachsafe (c, next, cookies) {
|
foreachsafe (c, next, cookies) {
|
||||||
if (!is_in_domain(c->domain, uri->host, uri->hostlen)
|
if (!is_in_domain(c->domain, uri->host, uri->hostlen)
|
||||||
|| !is_path_prefix(c->path, path))
|
|| !is_path_prefix(c->path, path))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (is_expired(c->expires)) {
|
if (c->expires && c->expires <= now) {
|
||||||
#ifdef DEBUG_COOKIES
|
#ifdef DEBUG_COOKIES
|
||||||
DBG("Cookie %s=%s (exp %d) expired.",
|
DBG("Cookie %s=%s (exp %d) expired.",
|
||||||
c->name, c->value, c->expires);
|
c->name, c->value, c->expires);
|
||||||
@ -681,6 +680,7 @@ load_cookies(void) {
|
|||||||
unsigned char in_buffer[6 * MAX_STR_LEN];
|
unsigned char in_buffer[6 * MAX_STR_LEN];
|
||||||
unsigned char *cookfile = COOKIES_FILENAME;
|
unsigned char *cookfile = COOKIES_FILENAME;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
time_t now;
|
||||||
|
|
||||||
if (elinks_home) {
|
if (elinks_home) {
|
||||||
cookfile = straconcat(elinks_home, cookfile, NULL);
|
cookfile = straconcat(elinks_home, cookfile, NULL);
|
||||||
@ -701,6 +701,7 @@ load_cookies(void) {
|
|||||||
* periodically to our death. */
|
* periodically to our death. */
|
||||||
cookies_nosave = 1;
|
cookies_nosave = 1;
|
||||||
|
|
||||||
|
now = time(NULL);
|
||||||
while (fgets(in_buffer, 6 * MAX_STR_LEN, fp)) {
|
while (fgets(in_buffer, 6 * MAX_STR_LEN, fp)) {
|
||||||
struct cookie *cookie;
|
struct cookie *cookie;
|
||||||
unsigned char *p, *q = in_buffer;
|
unsigned char *p, *q = in_buffer;
|
||||||
@ -728,7 +729,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 (is_dead(expires)) {
|
if (!expires || expires <= now) {
|
||||||
cookies_dirty = 1;
|
cookies_dirty = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -765,6 +766,7 @@ save_cookies(void) {
|
|||||||
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;
|
||||||
|
|
||||||
if (cookies_nosave || !elinks_home || !cookies_dirty
|
if (cookies_nosave || !elinks_home || !cookies_dirty
|
||||||
|| get_cmd_opt_bool("anonymous"))
|
|| get_cmd_opt_bool("anonymous"))
|
||||||
@ -777,8 +779,9 @@ save_cookies(void) {
|
|||||||
mem_free(cookfile);
|
mem_free(cookfile);
|
||||||
if (!ssi) return;
|
if (!ssi) return;
|
||||||
|
|
||||||
|
now = time(NULL);
|
||||||
foreach (c, cookies) {
|
foreach (c, cookies) {
|
||||||
if (is_dead(c->expires)) continue;
|
if (!c->expires || c->expires <= now) continue;
|
||||||
if (secure_fprintf(ssi, "%s\t%s\t%s\t%s\t%s\t%ld\t%d\n",
|
if (secure_fprintf(ssi, "%s\t%s\t%s\t%s\t%s\t%ld\t%d\n",
|
||||||
c->name, c->value,
|
c->name, c->value,
|
||||||
c->server->host,
|
c->server->host,
|
||||||
|
Loading…
Reference in New Issue
Block a user