[sr-dev] git:master:5d0494f9: sl: new pv $ltt(key) - return local generated to tag
Alex Balashov
abalashov at evaristesys.com
Wed Oct 10 17:05:18 CEST 2018
Thank you very much for this!!
--
Sent from mobile. Apologies for brevity and errors.
-----Original Message-----
From: Daniel-Constantin Mierla <miconda at gmail.com>
To: sr-dev at lists.kamailio.org
Sent: Tue, 09 Oct 2018 10:19 PM
Subject: [sr-dev] git:master:5d0494f9: sl: new pv $ltt(key) - return local generated to tag
Module: kamailio
Branch: master
Commit: 5d0494f9444b73a639a90c4ff2da933fb2d11d5d
URL: https://github.com/kamailio/kamailio/commit/5d0494f9444b73a639a90c4ff2da933fb2d11d5d
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2018-10-09T22:17:13+02:00
sl: new pv $ltt(key) - return local generated to tag
- the to-tag used when kamailio sends a reply
- $ltt(s) - the to-tag used in stateless replies
- $ltt(t) - the to-tag used in transaction stateful replies (transaction
has to be created at that time, eg., by t_newtran() or in a
branch/failure route, otherwise it returns $null)
- $ltt(x) - $ltt(t) if the transaction was created already, otherwise
$ltt(s)
---
Modified: src/modules/sl/sl.c
---
Diff: https://github.com/kamailio/kamailio/commit/5d0494f9444b73a639a90c4ff2da933fb2d11d5d.diff
Patch: https://github.com/kamailio/kamailio/commit/5d0494f9444b73a639a90c4ff2da933fb2d11d5d.patch
---
diff --git a/src/modules/sl/sl.c b/src/modules/sl/sl.c
index 96c3fdfdf5..36c8a8eec7 100644
--- a/src/modules/sl/sl.c
+++ b/src/modules/sl/sl.c
@@ -78,6 +78,17 @@ static int child_init(int rank);
static void mod_destroy();
static int fixup_sl_reply(void** param, int param_no);
+static int pv_get_ltt(sip_msg_t *msg, pv_param_t *param, pv_value_t *res);
+static int pv_parse_ltt_name(pv_spec_p sp, str *in);
+
+
+static pv_export_t mod_pvs[] = {
+ { {"ltt", (sizeof("ltt")-1)}, PVT_OTHER, pv_get_ltt, 0,
+ pv_parse_ltt_name, 0, 0, 0 },
+
+ { {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
+};
+
static cmd_export_t cmds[]={
{"sl_send_reply", w_sl_send_reply, 2, fixup_sl_reply, 0,
REQUEST_ROUTE},
@@ -120,7 +131,7 @@ struct module_exports exports= {
cmds, /* cmd (cfg function) exports */
params, /* param exports */
sl_rpc, /* RPC method exports */
- 0, /* pv exports */
+ mod_pvs, /* pv exports */
0, /* response handling function */
mod_init, /* module init function */
child_init, /* per-child init function */
@@ -485,6 +496,83 @@ static int w_sl_forward_reply2(sip_msg_t* msg, char* str1, char* str2)
return w_sl_forward_reply(msg, &code, &reason);
}
+/**
+ *
+ */
+static int pv_get_ltt(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
+{
+ str ttag = STR_NULL;
+ tm_cell_t *t = NULL;
+
+ if(msg==NULL)
+ return pv_get_null(msg, param, res);
+
+ if(param==NULL)
+ return pv_get_null(msg, param, res);
+
+ switch(param->pvn.u.isname.name.n) {
+ case 0: /* mixed */
+ if(get_reply_totag(msg, &ttag)<0) {
+ return pv_get_null(msg, param, res);
+ }
+ return pv_get_strval(msg, param, res, &ttag);
+ case 1: /* stateless */
+ if(sl_get_reply_totag(msg, &ttag)<0) {
+ return pv_get_null(msg, param, res);
+ }
+ return pv_get_strval(msg, param, res, &ttag);
+ case 2: /* transaction stateful */
+ if(sl_bind_tm==0 || tmb.t_gett==0) {
+ return pv_get_null(msg, param, res);
+ }
+
+ t = tmb.t_gett();
+ if(t== NULL || t==T_UNDEFINED) {
+ return pv_get_null(msg, param, res);
+ }
+ if(tmb.t_get_reply_totag(msg, &ttag)<0) {
+ return pv_get_null(msg, param, res);
+ }
+ return pv_get_strval(msg, param, res, &ttag);
+ default:
+ return pv_get_null(msg, param, res);
+ }
+}
+
+/**
+ *
+ */
+static int pv_parse_ltt_name(pv_spec_p sp, str *in)
+{
+ if(sp==NULL || in==NULL || in->len<=0)
+ return -1;
+
+ switch(in->len) {
+ case 1:
+ if(strncmp(in->s, "x", 1)==0) {
+ sp->pvp.pvn.u.isname.name.n = 0;
+ } else if(strncmp(in->s, "s", 1)==0) {
+ sp->pvp.pvn.u.isname.name.n = 1;
+ } else if(strncmp(in->s, "t", 1)==0) {
+ sp->pvp.pvn.u.isname.name.n = 2;
+ } else {
+ goto error;
+ }
+ break;
+ default:
+ goto error;
+ }
+ sp->pvp.pvn.type = PV_NAME_INTSTR;
+ sp->pvp.pvn.u.isname.type = 0;
+
+ return 0;
+
+error:
+ LM_ERR("unknown PV ltt key: %.*s\n", in->len, in->s);
+ return -1;
+}
+
+
/**
* @brief bind functions to SL API structure
*/
_______________________________________________
Kamailio (SER) - Development Mailing List
sr-dev at lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev
More information about the sr-dev
mailing list