Module: kamailio
Branch: master
Commit: 9d3a126cecbb051393dd79f7ae4d6c7ac6b9880b
URL:
https://github.com/kamailio/kamailio/commit/9d3a126cecbb051393dd79f7ae4d6c7…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-09-16T11:36:07+02:00
htable: exported KSR.htable.sht_setiex(htname, itname, ival, exval)
---
Modified: src/modules/htable/htable.c
---
Diff:
https://github.com/kamailio/kamailio/commit/9d3a126cecbb051393dd79f7ae4d6c7…
Patch:
https://github.com/kamailio/kamailio/commit/9d3a126cecbb051393dd79f7ae4d6c7…
---
diff --git a/src/modules/htable/htable.c b/src/modules/htable/htable.c
index 64a8bb6511..270db053d8 100644
--- a/src/modules/htable/htable.c
+++ b/src/modules/htable/htable.c
@@ -991,11 +991,10 @@ static int ki_ht_setex(sip_msg_t *msg, str *htname, str *itname, int
itval)
return -1;
}
- isval.n = itval;
-
- LM_DBG("set expire value for sht: %.*s key: %.*s exp: %d\n", htname->len,
+ LM_DBG("set expire value for sht: %.*s key: %.*s exp: %d\n", htname->len,
htname->s, itname->len, itname->s, itval);
+ isval.n = itval;
if (ht->dmqreplicate>0
&& ht_dmq_replicate_action(HT_DMQ_SET_CELL_EXPIRE, htname,
itname, 0, &isval, 0)!=0) {
@@ -1010,6 +1009,49 @@ static int ki_ht_setex(sip_msg_t *msg, str *htname, str *itname,
int itval)
return 0;
}
+/**
+ *
+ */
+static int ki_ht_setiex(sip_msg_t *msg, str *htname, str *itname, int itval,
+ int exval)
+{
+ int_str isval;
+ ht_t *ht;
+
+ /* Find the htable */
+ ht = ht_get_table(htname);
+ if (!ht) {
+ LM_ERR("No such htable: %.*s\n", htname->len, htname->s);
+ return -1;
+ }
+
+ LM_DBG("set value and expire for sht: %.*s key: %.*s val: %d exp: %d\n",
+ htname->len, htname->s, itname->len, itname->s, itval, exval);
+
+ if (ht->dmqreplicate>0) {
+ isval.n = itval;
+ if(ht_dmq_replicate_action(HT_DMQ_SET_CELL,
+ &ht->name, itname, 0, &isval, 1)!=0) {
+ LM_ERR("dmq set value relication failed\n");
+ } else {
+ isval.n = exval;
+ if(ht_dmq_replicate_action(HT_DMQ_SET_CELL_EXPIRE, htname,
+ itname, 0, &isval, 0)!=0) {
+ LM_ERR("dmq set expire relication failed\n");
+ }
+ }
+ }
+ isval.n = itval;
+
+ if(ht_set_cell_ex(ht, itname, 0, &isval, 1, exval)!=0) {
+ LM_ERR("cannot set value and expire for sht: %.*s key: %.*s\n",
+ htname->len, htname->s, itname->len, itname->s);
+ return -1;
+ }
+
+ return 0;
+}
+
#define RPC_DATE_BUF_LEN 21
static const char* htable_dump_doc[2] = {
@@ -1597,6 +1639,11 @@ static sr_kemi_t sr_kemi_htable_exports[] = {
{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_INT,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
+ { str_init("htable"), str_init("sht_setiex"),
+ SR_KEMIP_INT, ki_ht_setiex,
+ { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_INT,
+ SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
};