Module: kamailio
Branch: 6.0
Commit: b38925b0b3628539840de2b6240da75b9f9f3cc6
URL: 
https://github.com/kamailio/kamailio/commit/b38925b0b3628539840de2b6240da75b9f9f3cc6

Author: Bastian Triller <bastian.tril...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2025-01-28T10:13:31+01:00

htable: Fix expiry on assignment

Update cell expiry on assignment for htables w/o updateexpiry (analogue to 
#4079).

(cherry picked from commit 75994f40c99ffa2c7c33e5fce5e3d3cd8db7d780)

---

Modified: src/modules/htable/ht_api.c
Modified: src/modules/htable/ht_api.h

---

Diff:  
https://github.com/kamailio/kamailio/commit/b38925b0b3628539840de2b6240da75b9f9f3cc6.diff
Patch: 
https://github.com/kamailio/kamailio/commit/b38925b0b3628539840de2b6240da75b9f9f3cc6.patch

---

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

_______________________________________________
Kamailio - Development Mailing List -- sr-dev@lists.kamailio.org
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to