/*
- * Copyright 2024 Vsevolod Stakhov
+ * Copyright 2025 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
ts.tv_sec = 0;
ts.tv_nsec = MUTEX_SLEEP_TIME;
/* Spin */
- while (nanosleep(&ts, &ts) == -1 && errno == EINTR)
- ;
+ while (nanosleep(&ts, &ts) == -1 && errno == EINTR);
#else
#error No methods to spin are defined
#endif
}
#endif
-#define RSPAMD_MEMPOOL_VARS_HASH_SEED 0xb32ad7c55eb2e647ULL
void rspamd_mempool_set_variable(rspamd_mempool_t *pool,
const char *name,
gpointer value,
}
}
- int hv = rspamd_cryptobox_fast_hash(name, strlen(name),
- RSPAMD_MEMPOOL_VARS_HASH_SEED);
khiter_t it;
int r;
- it = kh_put(rspamd_mempool_vars_hash, pool->priv->variables, hv, &r);
+ it = kh_put(rspamd_mempool_vars_hash, pool->priv->variables, name, &r);
if (it == kh_end(pool->priv->variables)) {
g_assert_not_reached();
pvar->dtor(pvar->data);
}
}
+ else {
+ /* Store copy of the key to provide persistent storage */
+ kh_key(pool->priv->variables, it) = rspamd_mempool_strdup(pool, name);
+ }
pvar = &kh_val(pool->priv->variables, it);
pvar->data = value;
}
khiter_t it;
- int hv = rspamd_cryptobox_fast_hash(name, strlen(name),
- RSPAMD_MEMPOOL_VARS_HASH_SEED);
- it = kh_get(rspamd_mempool_vars_hash, pool->priv->variables, hv);
+ it = kh_get(rspamd_mempool_vars_hash, pool->priv->variables, name);
if (it != kh_end(pool->priv->variables)) {
struct rspamd_mempool_variable *pvar;
}
khiter_t it;
- int hv = rspamd_cryptobox_fast_hash(name, strlen(name),
- RSPAMD_MEMPOOL_VARS_HASH_SEED);
-
- it = kh_get(rspamd_mempool_vars_hash, pool->priv->variables, hv);
+ it = kh_get(rspamd_mempool_vars_hash, pool->priv->variables, name);
if (it != kh_end(pool->priv->variables)) {
struct rspamd_mempool_variable *pvar;
{
if (pool->priv->variables != NULL) {
khiter_t it;
- int hv = rspamd_cryptobox_fast_hash(name, strlen(name),
- RSPAMD_MEMPOOL_VARS_HASH_SEED);
- it = kh_get(rspamd_mempool_vars_hash, pool->priv->variables, hv);
+ it = kh_get(rspamd_mempool_vars_hash, pool->priv->variables, name);
if (it != kh_end(pool->priv->variables)) {
struct rspamd_mempool_variable *pvar;
/*
- * Copyright 2024 Vsevolod Stakhov
+ * Copyright 2025 Vsevolod Stakhov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
};
KHASH_INIT(rspamd_mempool_vars_hash,
- uint32_t, struct rspamd_mempool_variable, 1,
- kh_int_hash_func, kh_int_hash_equal);
+ const char *, struct rspamd_mempool_variable, 1,
+ kh_str_hash_func, kh_str_hash_equal);
struct rspamd_mempool_specific {
struct _pool_chain *pools[RSPAMD_MEMPOOL_MAX];