Module: kamailio
Branch: master
Commit: 9121118444e638223c789641618ed4145a67b0f3
URL:
https://github.com/kamailio/kamailio/commit/9121118444e638223c789641618ed41…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2018-09-03T14:50:16+02:00
htable: exported sht_rm_value_re() and sht_rm_name_re() to kemi
- GH #1614
---
Modified: src/modules/htable/htable.c
---
Diff:
https://github.com/kamailio/kamailio/commit/9121118444e638223c789641618ed41…
Patch:
https://github.com/kamailio/kamailio/commit/9121118444e638223c789641618ed41…
---
diff --git a/src/modules/htable/htable.c b/src/modules/htable/htable.c
index fbe016e0aa..43c58d1942 100644
--- a/src/modules/htable/htable.c
+++ b/src/modules/htable/htable.c
@@ -354,13 +354,49 @@ static int fixup_ht_key(void** param, int param_no)
return 0;
}
-static int ht_rm_name_re(struct sip_msg* msg, char* key, char* foo)
+/**
+ *
+ */
+static int ht_rm_re_helper(sip_msg_t *msg, ht_t *ht, str *rexp, int rmode)
+{
+ int_str isval;
+
+ if (ht->dmqreplicate>0) {
+ isval.s = *rexp;
+ if (ht_dmq_replicate_action(HT_DMQ_RM_CELL_RE, &ht->name, NULL,
+ AVP_VAL_STR, &isval, rmode)!=0) {
+ LM_ERR("dmq relication failed for [%.*s]\n", ht->name.len,
ht->name.s);
+ }
+ }
+ if(ht_rm_cell_re(rexp, ht, rmode)<0)
+ return -1;
+ return 1;
+}
+
+/**
+ *
+ */
+static int ki_ht_rm_name_re(sip_msg_t *msg, str *htname, str *rexp)
+{
+ ht_t *ht;
+
+ ht = ht_get_table(htname);
+ if(ht==NULL) {
+ return 1;
+ }
+
+ return ht_rm_re_helper(msg, ht, rexp, 0);
+}
+
+/**
+ *
+ */
+static int ht_rm_name_re(sip_msg_t* msg, char* key, char* foo)
{
ht_pv_t *hpv;
str sre;
pv_spec_t *sp;
sp = (pv_spec_t*)key;
- int_str isval;
hpv = (ht_pv_t*)sp->pvp.pvn.u.dname;
@@ -375,24 +411,33 @@ static int ht_rm_name_re(struct sip_msg* msg, char* key, char* foo)
LM_ERR("cannot get $sht expression\n");
return -1;
}
- if (hpv->ht->dmqreplicate>0) {
- isval.s = sre;
- if (ht_dmq_replicate_action(HT_DMQ_RM_CELL_RE, &hpv->htname, NULL, AVP_VAL_STR,
&isval, 0)!=0) {
- LM_ERR("dmq relication failed\n");
- }
+ return ht_rm_re_helper(msg, hpv->ht, &sre, 0);
+}
+
+/**
+ *
+ */
+static int ki_ht_rm_value_re(sip_msg_t *msg, str *htname, str *rexp)
+{
+ ht_t *ht;
+
+ ht = ht_get_table(htname);
+ if(ht==NULL) {
+ return 1;
}
- if(ht_rm_cell_re(&sre, hpv->ht, 0)<0)
- return -1;
- return 1;
+
+ return ht_rm_re_helper(msg, ht, rexp, 1);
}
-static int ht_rm_value_re(struct sip_msg* msg, char* key, char* foo)
+/**
+ *
+ */
+static int ht_rm_value_re(sip_msg_t* msg, char* key, char* foo)
{
ht_pv_t *hpv;
str sre;
pv_spec_t *sp;
sp = (pv_spec_t*)key;
- int_str isval;
hpv = (ht_pv_t*)sp->pvp.pvn.u.dname;
@@ -407,16 +452,7 @@ static int ht_rm_value_re(struct sip_msg* msg, char* key, char* foo)
LM_ERR("cannot get $sht expression\n");
return -1;
}
-
- if (hpv->ht->dmqreplicate>0) {
- isval.s = sre;
- if (ht_dmq_replicate_action(HT_DMQ_RM_CELL_RE, &hpv->htname, NULL, AVP_VAL_STR,
&isval, 1)!=0) {
- LM_ERR("dmq relication failed\n");
- }
- }
- if(ht_rm_cell_re(&sre, hpv->ht, 1)<0)
- return -1;
- return 1;
+ return ht_rm_re_helper(msg, hpv->ht, &sre, 1);
}
static int ht_rm_items(sip_msg_t* msg, str* hname, str* op, str *val,
@@ -1275,6 +1311,16 @@ static sr_kemi_t sr_kemi_htable_exports[] = {
{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
},
+ { str_init("htable"), str_init("sht_rm_name_re"),
+ SR_KEMIP_INT, ki_ht_rm_name_re,
+ { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+ { str_init("htable"), str_init("sht_rm_value_re"),
+ SR_KEMIP_INT, ki_ht_rm_value_re,
+ { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
};