Hsts struct has dtor.

Now I can put them into a container.
This commit is contained in:
2025-04-24 08:54:30 -04:00
parent aec0331924
commit b8bc9d5c44

View File

@ -36,11 +36,11 @@
#include <string>
typedef struct {
char *host;
struct HstsData_t {
std::string host;
time_t expires_at;
bool_t subdomains;
} HstsData_t;
};
/* When there is difficulty in representing future dates, use the (by far)
* most likely latest representable time of January 19, 2038.
@ -48,12 +48,6 @@ typedef struct {
static time_t hsts_latest_representable_time;
static Dlist *domains;
static void Hsts_free_policy(HstsData_t *p)
{
dFree(p->host);
dFree(p);
}
void a_Hsts_freeall(void)
{
if (prefs.http_strict_transport_security) {
@ -62,7 +56,7 @@ void a_Hsts_freeall(void)
for (i = 0; i < n; i++) {
policy = reinterpret_cast< HstsData_t * >( dList_nth_data(domains, i) );
Hsts_free_policy(policy);
delete policy;
}
dList_free(domains);
}
@ -76,7 +70,7 @@ static int Domain_node_domain_str_cmp(const void *v1, const void *v2)
const HstsData_t *node = reinterpret_cast< const HstsData_t * >( v1 );
const char *host = reinterpret_cast< const char * >( v2 );
return dStrAsciiCasecmp(node->host, host);
return dStrAsciiCasecmp(node->host.c_str(), host);
}
static HstsData_t *Hsts_get_policy(const char *host)
@ -88,7 +82,7 @@ static void Hsts_remove_policy(HstsData_t *policy)
{
if (policy) {
_MSG("HSTS: removed policy for %s\n", policy->host);
Hsts_free_policy(policy);
delete policy;
dList_remove(domains, policy);
}
}
@ -120,7 +114,7 @@ static int Domain_node_cmp(const void *v1, const void *v2)
{
const HstsData_t *node1 = reinterpret_cast< const HstsData_t * >( v1 ), *node2 = reinterpret_cast< const HstsData_t * >( v2 );
return dStrAsciiCasecmp(node1->host, node2->host);
return dStrAsciiCasecmp(node1->host.c_str(), node2->host.c_str());
}
static void Hsts_set_policy(const char *host, long max_age, bool_t subdomains)
@ -132,8 +126,8 @@ static void Hsts_set_policy(const char *host, long max_age, bool_t subdomains)
(subdomains ? " and subdomains" : ""), ctime(&exp));
if (policy == NULL) {
policy = dNew0(HstsData_t, 1);
policy->host = dStrdup(host);
policy = new HstsData_t;
policy->host = host;
dList_insert_sorted(domains, policy, Domain_node_cmp);
}
policy->subdomains = subdomains;