Module: kamailio
Branch: master
Commit: 75994f40c99ffa2c7c33e5fce5e3d3cd8db7d780
URL:
https://github.com/kamailio/kamailio/commit/75994f40c99ffa2c7c33e5fce5e3d3c…
Author: Bastian Triller <bastian.triller(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2025-01-27T10:15:59+01:00
htable: Fix expiry on assignment
Update cell expiry on assignment for htables w/o updateexpiry (analogue to #4079).
---
Modified: src/modules/htable/ht_api.c
Modified: src/modules/htable/ht_api.h
---
Diff:
https://github.com/kamailio/kamailio/commit/75994f40c99ffa2c7c33e5fce5e3d3c…
Patch:
https://github.com/kamailio/kamailio/commit/75994f40c99ffa2c7c33e5fce5e3d3c…
---
diff --git a/src/modules/htable/ht_api.c b/src/modules/htable/ht_api.c
index 9190dd310ff..47b4b975194 100644
--- a/src/modules/htable/ht_api.c
+++ b/src/modules/htable/ht_api.c
@@ -496,9 +496,7 @@ int ht_set_cell_ex(
it->value.s.s[it->value.s.len] = '\0';
if(exv <= 0) {
- if(ht->updateexpire) {
- it->expire = now + ht->htexpire;
- }
+ HT_UPDATE_EXPIRE(ht, it, now);
} else {
it->expire = now + exv;
}
@@ -514,11 +512,7 @@ int ht_set_cell_ex(
cell->next = it->next;
cell->prev = it->prev;
if(exv <= 0) {
- if(ht->updateexpire) {
- cell->expire = now + ht->htexpire;
- } else {
- cell->expire = it->expire;
- }
+ HT_COPY_EXPIRE(ht, cell, now, it);
} else {
it->expire = now + exv;
}
@@ -535,9 +529,7 @@ int ht_set_cell_ex(
it->value.n = val->n;
if(exv <= 0) {
- if(ht->updateexpire) {
- it->expire = now + ht->htexpire;
- }
+ HT_UPDATE_EXPIRE(ht, it, now);
} else {
it->expire = now + exv;
}
@@ -556,11 +548,7 @@ int ht_set_cell_ex(
return -1;
}
if(exv <= 0) {
- if(ht->updateexpire) {
- cell->expire = now + ht->htexpire;
- } else {
- cell->expire = it->expire;
- }
+ HT_COPY_EXPIRE(ht, cell, now, it);
} else {
it->expire = now + exv;
}
@@ -578,9 +566,7 @@ int ht_set_cell_ex(
it->value.n = val->n;
if(exv <= 0) {
- if(ht->updateexpire) {
- it->expire = now + ht->htexpire;
- }
+ HT_UPDATE_EXPIRE(ht, it, now);
} else {
it->expire = now + exv;
}
diff --git a/src/modules/htable/ht_api.h b/src/modules/htable/ht_api.h
index 5ac11b9bb00..4e0757f237b 100644
--- a/src/modules/htable/ht_api.h
+++ b/src/modules/htable/ht_api.h
@@ -143,4 +143,11 @@ ht_cell_t *ht_iterator_get_current(str *iname);
void ht_slot_lock(ht_t *ht, int idx);
void ht_slot_unlock(ht_t *ht, int idx);
+
+#define HT_UPDATE_EXPIRE(ht, it, now) \
+ if(ht->updateexpire || (now && it->expire && it->expire <
now)) \
+ it->expire = now + ht->htexpire
+#define HT_COPY_EXPIRE(ht, it, now, src) \
+ HT_UPDATE_EXPIRE(ht, it, now); \
+ else it->expire = src->expire
#endif