mirror of
https://github.com/mirror/wget.git
synced 2025-03-25 01:00:13 +08:00
Correct HSTS debug message
* src/main.c (save_hsts): save the in-memory HSTS database to a file only if something changed. * src/hsts.c (struct hsts_store): new field 'changed'. (hsts_match): update field 'changed' accordingly. (hsts_store_entry): update field 'changed' accordingly. (hsts_store_has_changed): new function. * src/hsts.h (hsts_store_has_changed): new function.
This commit is contained in:
parent
2aaf12990c
commit
5224d752a5
23
src/hsts.c
23
src/hsts.c
@ -53,6 +53,7 @@ as that of the covered work. */
|
||||
struct hsts_store {
|
||||
struct hash_table *table;
|
||||
time_t last_mtime;
|
||||
bool changed;
|
||||
};
|
||||
|
||||
struct hsts_kh {
|
||||
@ -386,10 +387,14 @@ hsts_match (hsts_store_t store, struct url *u)
|
||||
if (u->port == 80)
|
||||
u->port = 443;
|
||||
url_changed = true;
|
||||
store->changed = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
hsts_remove_entry (store, kh);
|
||||
{
|
||||
hsts_remove_entry (store, kh);
|
||||
store->changed = true;
|
||||
}
|
||||
}
|
||||
xfree (kh->host);
|
||||
}
|
||||
@ -439,7 +444,10 @@ hsts_store_entry (hsts_store_t store,
|
||||
if (entry && match == CONGRUENT_MATCH)
|
||||
{
|
||||
if (max_age == 0)
|
||||
hsts_remove_entry (store, kh);
|
||||
{
|
||||
hsts_remove_entry (store, kh);
|
||||
store->changed = true;
|
||||
}
|
||||
else if (max_age > 0)
|
||||
{
|
||||
if (entry->max_age != max_age ||
|
||||
@ -452,6 +460,8 @@ hsts_store_entry (hsts_store_t store,
|
||||
entry->created = t;
|
||||
entry->max_age = max_age;
|
||||
entry->include_subdomains = include_subdomains;
|
||||
|
||||
store->changed = true;
|
||||
}
|
||||
}
|
||||
/* we ignore negative max_ages */
|
||||
@ -466,6 +476,8 @@ hsts_store_entry (hsts_store_t store,
|
||||
happen we got a non-existent entry with max_age == 0.
|
||||
*/
|
||||
result = hsts_add_entry (store, host, port, max_age, include_subdomains);
|
||||
if (result)
|
||||
store->changed = true;
|
||||
}
|
||||
/* we ignore new entries with max_age == 0 */
|
||||
xfree (kh->host);
|
||||
@ -484,6 +496,7 @@ hsts_store_open (const char *filename)
|
||||
store = xnew0 (struct hsts_store);
|
||||
store->table = hash_table_new (0, hsts_hash_func, hsts_cmp_func);
|
||||
store->last_mtime = 0;
|
||||
store->changed = false;
|
||||
|
||||
if (file_exists_p (filename))
|
||||
{
|
||||
@ -561,6 +574,12 @@ hsts_store_save (hsts_store_t store, const char *filename)
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
hsts_store_has_changed (hsts_store_t store)
|
||||
{
|
||||
return (store ? store->changed : false);
|
||||
}
|
||||
|
||||
void
|
||||
hsts_store_close (hsts_store_t store)
|
||||
{
|
||||
|
@ -43,6 +43,7 @@ hsts_store_t hsts_store_open (const char *);
|
||||
|
||||
void hsts_store_save (hsts_store_t, const char *);
|
||||
void hsts_store_close (hsts_store_t);
|
||||
bool hsts_store_has_changed (hsts_store_t);
|
||||
|
||||
bool hsts_store_entry (hsts_store_t,
|
||||
enum url_scheme, const char *, int,
|
||||
|
@ -204,10 +204,12 @@ save_hsts (void)
|
||||
{
|
||||
char *filename = get_hsts_database ();
|
||||
|
||||
if (filename)
|
||||
DEBUGP (("Saving HSTS entries to %s\n", filename));
|
||||
if (filename && hsts_store_has_changed (hsts_store))
|
||||
{
|
||||
DEBUGP (("Saving HSTS entries to %s\n", filename));
|
||||
hsts_store_save (hsts_store, filename);
|
||||
}
|
||||
|
||||
hsts_store_save (hsts_store, filename);
|
||||
hsts_store_close (hsts_store);
|
||||
|
||||
xfree (filename);
|
||||
|
Loading…
Reference in New Issue
Block a user