[sr-dev] git:master:83adc896: htable: export sht_sets() and sht_seti() to kemi framework

Daniel-Constantin Mierla miconda at gmail.com
Tue Sep 11 12:35:32 CEST 2018


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2018-09-11T12:34:36+02:00

htable: export sht_sets() and sht_seti() to kemi framework

---

Modified: src/modules/htable/htable.c

---

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

---

diff --git a/src/modules/htable/htable.c b/src/modules/htable/htable.c
index 04c4bb7c9a..61b9e8896a 100644
--- a/src/modules/htable/htable.c
+++ b/src/modules/htable/htable.c
@@ -912,6 +912,70 @@ int ht_param(modparam_t type, void *val)
 
 }
 
+/**
+ *
+ */
+static int ki_ht_sets(sip_msg_t *msg, str *htname, str *itname, str *itval)
+{
+	int_str isvalue;
+	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;
+	}
+
+	isvalue.s = *itval;
+
+	if (ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_SET_CELL,
+				&ht->name, itname, AVP_VAL_STR, &isvalue, 1)!=0) {
+		LM_ERR("dmq relication failed\n");
+	}
+
+	if(ht_set_cell(ht, itname, AVP_VAL_STR, &isvalue, 1)!=0) {
+		LM_ERR("cannot set hash table: %.*s key: %.*s\n", htname->len, htname->s,
+				itname->len, itname->s);
+		return -1;
+	}
+
+	return 1;
+}
+
+/**
+ *
+ */
+static int ki_ht_seti(sip_msg_t *msg, str *htname, str *itname, int itval)
+{
+	int_str isvalue;
+	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;
+	}
+
+	isvalue.n = itval;
+
+	if (ht->dmqreplicate>0 && ht_dmq_replicate_action(HT_DMQ_SET_CELL,
+				&ht->name, itname, 0, &isvalue, 1)!=0) {
+		LM_ERR("dmq relication failed\n");
+	}
+
+	if(ht_set_cell(ht, itname, 0, &isvalue, 1)!=0) {
+		LM_ERR("cannot set sht: %.*s key: %.*s\n", htname->len, htname->s,
+				itname->len, itname->s);
+		LM_ERR("cannot set hash table: %.*s key: %.*s\n", htname->len, htname->s,
+				itname->len, itname->s);
+		return -1;
+	}
+
+	return 1;
+}
+
 #define RPC_DATE_BUF_LEN 21
 
 static const char* htable_dump_doc[2] = {
@@ -1484,6 +1548,16 @@ static sr_kemi_t sr_kemi_htable_exports[] = {
 		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
 	},
+	{ str_init("htable"), str_init("sht_sets"),
+		SR_KEMIP_INT, ki_ht_sets,
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+	{ str_init("htable"), str_init("sht_seti"),
+		SR_KEMIP_INT, ki_ht_seti,
+		{ 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