[sr-dev] git:master:fba9ea88: htable: exported sht_setex(...) to kemi framework

Daniel-Constantin Mierla miconda at gmail.com
Fri Sep 14 10:56:12 CEST 2018


Module: kamailio
Branch: master
Commit: fba9ea8823bf9beb009c5d857d674fa7bc665a37
URL: https://github.com/kamailio/kamailio/commit/fba9ea8823bf9beb009c5d857d674fa7bc665a37

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2018-09-14T10:54:56+02:00

htable: exported sht_setex(...) to kemi framework

- API function to set expires value for an item:

---

Modified: src/modules/htable/htable.c

---

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

---

diff --git a/src/modules/htable/htable.c b/src/modules/htable/htable.c
index 61b9e8896a..64a8bb6511 100644
--- a/src/modules/htable/htable.c
+++ b/src/modules/htable/htable.c
@@ -976,6 +976,40 @@ static int ki_ht_seti(sip_msg_t *msg, str *htname, str *itname, int itval)
 	return 1;
 }
 
+/**
+ *
+ */
+static int ki_ht_setex(sip_msg_t *msg, str *htname, str *itname, int itval)
+{
+	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;
+	}
+
+	isval.n = itval;
+
+	LM_DBG("set expire value for  sht: %.*s key: %.*s exp: %d\n", htname->len,
+			htname->s, itname->len, itname->s, itval);
+
+	if (ht->dmqreplicate>0
+				&& ht_dmq_replicate_action(HT_DMQ_SET_CELL_EXPIRE, htname,
+				itname, 0, &isval, 0)!=0) {
+		LM_ERR("dmq relication failed\n");
+	}
+	if(ht_set_cell_expire(ht, itname, 0, &isval)!=0) {
+		LM_ERR("cannot set 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] = {
@@ -1558,6 +1592,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_setex"),
+		SR_KEMIP_INT, ki_ht_setex,
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_INT,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
 
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
 };




More information about the sr-dev mailing list