Module: kamailio
Branch: master
Commit: 16006cd97c4eccb4b45c459a8585649450bf5772
URL:
https://github.com/kamailio/kamailio/commit/16006cd97c4eccb4b45c459a8585649…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2017-07-26T12:18:15+02:00
dialplan: exported dp_match() and dp_replace() to kemi framework
---
Modified: src/modules/dialplan/dialplan.c
---
Diff:
https://github.com/kamailio/kamailio/commit/16006cd97c4eccb4b45c459a8585649…
Patch:
https://github.com/kamailio/kamailio/commit/16006cd97c4eccb4b45c459a8585649…
---
diff --git a/src/modules/dialplan/dialplan.c b/src/modules/dialplan/dialplan.c
index 5a94e8c21c..85dc0d652b 100644
--- a/src/modules/dialplan/dialplan.c
+++ b/src/modules/dialplan/dialplan.c
@@ -55,6 +55,7 @@
#include "../../core/rpc.h"
#include "../../core/rpc_lookup.h"
#include "../../core/lvalue.h"
+#include "../../core/kemi.h"
#include "dialplan.h"
#include "dp_db.h"
@@ -256,17 +257,21 @@ static int dp_update(struct sip_msg * msg, pv_spec_t * dest,
memset(&val, 0, sizeof(pv_value_t));
val.flags = PV_VAL_STR;
- no_change = (dest==NULL) || (dest->type == PVT_NONE) || (!repl->s) ||
(!repl->len);
+ no_change = (dest==NULL) || (dest->type == PVT_NONE)
+ || (!repl->s) || (!repl->len);
if (no_change)
goto set_attr_pvar;
val.rs = *repl;
- if(dest->setf(msg, &dest->pvp, (int)EQ_T, &val)<0)
- {
- LM_ERR("setting dst pseudo-variable failed\n");
- return -1;
+ if(dest->setf) {
+ if(dest->setf(msg, &dest->pvp, (int)EQ_T, &val)<0) {
+ LM_ERR("setting dst pseudo-variable failed\n");
+ return -1;
+ }
+ } else {
+ LM_WARN("target variable is read only - skipping setting its value\n");
}
if(dp_append_branch!=0) {
@@ -506,6 +511,19 @@ static int w_dp_replace(sip_msg_t* msg, char* pid, char* psrc, char*
pdst)
return dp_replace_helper(msg, dpid, &src, pvd);
}
+static int ki_dp_replace(sip_msg_t* msg, int dpid, str* src, str* dst)
+{
+ pv_spec_t *pvd = NULL;
+
+ pvd = pv_cache_get(dst);
+ if(pvd==NULL) {
+ LM_ERR("cannot get pv spec for [%.*s]\n", dst->len, dst->s);
+ return -1;
+ }
+
+ return dp_replace_helper(msg, dpid, src, pvd);
+}
+
static int w_dp_match(sip_msg_t* msg, char* pid, char* psrc)
{
int dpid = 1;
@@ -523,6 +541,11 @@ static int w_dp_match(sip_msg_t* msg, char* pid, char* psrc)
return dp_replace_helper(msg, dpid, &src, NULL);
}
+static int ki_dp_match(sip_msg_t* msg, int dpid, str* src)
+{
+ return dp_replace_helper(msg, dpid, src, NULL);
+}
+
int dp_replace_fixup(void** param, int param_no)
{
if (param_no == 1)
@@ -776,3 +799,32 @@ static int dialplan_init_rpc(void)
}
return 0;
}
+
+/**
+ *
+ */
+/* clang-format off */
+static sr_kemi_t sr_kemi_dialplan_exports[] = {
+ { str_init("dialplan"), str_init("dp_match"),
+ SR_KEMIP_INT, ki_dp_match,
+ { SR_KEMIP_INT, SR_KEMIP_STR, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+ { str_init("dialplan"), str_init("dp_replace"),
+ SR_KEMIP_INT, ki_dp_replace,
+ { SR_KEMIP_INT, SR_KEMIP_STR, SR_KEMIP_STR,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+
+ { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
+};
+/* clang-format on */
+
+/**
+ *
+ */
+int mod_register(char *path, int *dlflags, void *p1, void *p2)
+{
+ sr_kemi_modules_add(sr_kemi_dialplan_exports);
+ return 0;
+}
\ No newline at end of file