Module: kamailio Branch: master Commit: 9eaea57fd7e43c538a13d87c73a48786e287d113 URL: https://github.com/kamailio/kamailio/commit/9eaea57fd7e43c538a13d87c73a48786...
Author: Luis Azedo luis.azedo@factorlusitano.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2018-12-03T20:53:28+01:00
tmx: new function t_drop([rcode])
- based on GH #1726
---
Modified: src/modules/tmx/doc/tmx_admin.xml Modified: src/modules/tmx/tmx_mod.c
---
Diff: https://github.com/kamailio/kamailio/commit/9eaea57fd7e43c538a13d87c73a48786... Patch: https://github.com/kamailio/kamailio/commit/9eaea57fd7e43c538a13d87c73a48786...
---
diff --git a/src/modules/tmx/doc/tmx_admin.xml b/src/modules/tmx/doc/tmx_admin.xml index 19c808c931..e6646ecdb7 100644 --- a/src/modules/tmx/doc/tmx_admin.xml +++ b/src/modules/tmx/doc/tmx_admin.xml @@ -432,6 +432,60 @@ route[MYROUTE] { </programlisting> </example> </section> + <section id="tmx.f.t_drop"> + <title> + <function moreinfo="none">t_drop([rcode]) + </function> + </title> + <para> + Drops the transaction with response code (500 default). + </para> + <para> + Parameters:. + </para> + <itemizedlist> + <listitem><para> + <emphasis>rcode</emphasis> - response code to set in uas status. + </para></listitem> + </itemizedlist> + <para> + This function can be used in ANY_ROUTE. + </para> + <example> + <title><function>t_drop</function> usage</title> + <programlisting format="linespecific"> +... +route[MYREQ] +{ +... + if (!t_newtran()) { + xlog("L_ERROR", "$ci|log|failed to create transaction\n"); + drop; + } + + t_on_failure("TR_ERROR"); + t_on_reply("TR_OK"); + t_relay(); +} + +failure_route[TR_ERROR] +{ + xlog("L_INFO", "$ci|log|failed $T_reply_code $T_reply_reason\n"); + t_drop(); +} + +onreply_route[TR_OK] +{ + xlog("L_INFO", "$ci|log|checking transaction result\n"); + if(status=~"60[0-9]") { + t_drop(); + } +... +} +... +</programlisting> + </example> + </section>
<section id="tmx.f.t_reuse_branch"> <title> diff --git a/src/modules/tmx/tmx_mod.c b/src/modules/tmx/tmx_mod.c index a40a00da6e..c31eae6713 100644 --- a/src/modules/tmx/tmx_mod.c +++ b/src/modules/tmx/tmx_mod.c @@ -74,6 +74,8 @@ static int w_t_is_branch_route(sip_msg_t* msg, char*, char* ); static int w_t_is_reply_route(sip_msg_t* msg, char*, char*); static int w_t_is_request_route(sip_msg_t* msg, char*, char*);
+static int w_t_drop0(sip_msg_t* msg, char*, char*); +static int w_t_drop1(sip_msg_t* msg, char*, char*); static int w_t_suspend(sip_msg_t* msg, char*, char*); static int w_t_continue(sip_msg_t* msg, char *idx, char *lbl, char *rtn); static int w_t_reuse_branch(sip_msg_t* msg, char*, char*); @@ -198,6 +200,8 @@ static cmd_export_t cmds[]={ REQUEST_ROUTE }, {"bind_tmx", (cmd_function)bind_tmx, 1, 0, 0, ANY_ROUTE }, + {"t_drop", (cmd_function)w_t_drop0, 0, 0, 0, ANY_ROUTE}, + {"t_drop", (cmd_function)w_t_drop1, 1, fixup_igp_null, 0, ANY_ROUTE}, {0,0,0,0,0,0} };
@@ -697,6 +701,43 @@ static int t_is_request_route(sip_msg_t* msg) return -1; }
+/** + * + */ +static int w_t_drop1(sip_msg_t* msg, char *p1, char *p2) +{ + tm_cell_t *t = 0; + unsigned int uas_status = 500; + + if(p1) { + if(fixup_get_ivalue(msg, (gparam_p)p1, (int*)&uas_status)<0) + { + uas_status = 500; + } + } + + t=_tmx_tmb.t_gett(); + if (t==NULL || t==T_UNDEFINED) { + LM_ERR("no transaction\n"); + return -1; + } + + t->uas.status = uas_status; + if(t_is_request_route(msg) == 1) { + _tmx_tmb.t_release(msg); + } + return 0; +} + +/** + * + */ +static int w_t_drop0(sip_msg_t* msg, char *p1, char *p2) +{ + return w_t_drop1(msg, NULL, NULL); +} + + /** * */