Selaa lähdekoodia

modules/tmx: Add $T_reply_ruid pv to return ruid for a branch reply

- Can be run from a failure_route or branch_failure_route
Hugh Waite 12 vuotta sitten
vanhempi
commit
6759d6bbdd
5 muutettua tiedostoa jossa 117 lisäystä ja 69 poistoa
  1. 72 69
      modules/tmx/README
  2. 3 0
      modules/tmx/doc/tmx_admin.xml
  3. 37 0
      modules/tmx/t_var.c
  4. 2 0
      modules/tmx/t_var.h
  5. 3 0
      modules/tmx/tmx_mod.c

+ 72 - 69
modules/tmx/README

@@ -1,3 +1,4 @@
+
 TMX Module
 
 Daniel-Constantin Mierla
@@ -11,8 +12,8 @@ Daniel-Constantin Mierla
 
    <[email protected]>
 
-   Copyright © 2009 Daniel-Constantin Mierla
-     __________________________________________________________________
+   Copyright © 2009 Daniel-Constantin Mierla
+     _________________________________________________________________
 
    Table of Contents
 
@@ -26,24 +27,24 @@ Daniel-Constantin Mierla
 
         3. Functions
 
-              3.1. t_cancel_branches(which)
-              3.2. t_cancel_callid(callid, cseq, flag)
-              3.3. t_reply_callid(callid, cseq, code, reason)
-              3.4. t_flush_flags()
-              3.5. t_is_failure_route()
-              3.6. t_is_branch_route()
-              3.7. t_is_reply_route()
-              3.8. t_suspend()
-              3.9. t_continue(tindex, tlabel, rtname)
+              3.1. t_cancel_branches(which) 
+              3.2. t_cancel_callid(callid, cseq, flag) 
+              3.3. t_reply_callid(callid, cseq, code, reason) 
+              3.4. t_flush_flags() 
+              3.5. t_is_failure_route() 
+              3.6. t_is_branch_route() 
+              3.7. t_is_reply_route() 
+              3.8. t_suspend() 
+              3.9. t_continue(tindex, tlabel, rtname) 
 
         4. Exported pseudo-variables
         5. MI Commands
 
-              5.1. t_uac_dlg
-              5.2. t_uac_cancel
-              5.3. t_hash
-              5.4. t_reply
-              5.5. t_reply_callid
+              5.1. t_uac_dlg 
+              5.2. t_uac_cancel 
+              5.3. t_hash 
+              5.4. t_reply 
+              5.5. t_reply_callid 
 
         6. Statistics
 
@@ -83,24 +84,24 @@ Chapter 1. Admin Guide
 
    3. Functions
 
-        3.1. t_cancel_branches(which)
-        3.2. t_cancel_callid(callid, cseq, flag)
-        3.3. t_reply_callid(callid, cseq, code, reason)
-        3.4. t_flush_flags()
-        3.5. t_is_failure_route()
-        3.6. t_is_branch_route()
-        3.7. t_is_reply_route()
-        3.8. t_suspend()
-        3.9. t_continue(tindex, tlabel, rtname)
+        3.1. t_cancel_branches(which) 
+        3.2. t_cancel_callid(callid, cseq, flag) 
+        3.3. t_reply_callid(callid, cseq, code, reason) 
+        3.4. t_flush_flags() 
+        3.5. t_is_failure_route() 
+        3.6. t_is_branch_route() 
+        3.7. t_is_reply_route() 
+        3.8. t_suspend() 
+        3.9. t_continue(tindex, tlabel, rtname) 
 
    4. Exported pseudo-variables
    5. MI Commands
 
-        5.1. t_uac_dlg
-        5.2. t_uac_cancel
-        5.3. t_hash
-        5.4. t_reply
-        5.5. t_reply_callid
+        5.1. t_uac_dlg 
+        5.2. t_uac_cancel 
+        5.3. t_hash 
+        5.4. t_reply 
+        5.5. t_reply_callid 
 
    6. Statistics
 
@@ -135,25 +136,25 @@ Chapter 1. Admin Guide
 
 2.2. External Libraries or Applications
 
-   The following libraries or applications must be installed before
+   The  following  libraries  or  applications  must  be installed before
    running Kamailio with this module loaded:
      * None.
 
 3. Functions
 
-   3.1. t_cancel_branches(which)
-   3.2. t_cancel_callid(callid, cseq, flag)
-   3.3. t_reply_callid(callid, cseq, code, reason)
-   3.4. t_flush_flags()
-   3.5. t_is_failure_route()
-   3.6. t_is_branch_route()
-   3.7. t_is_reply_route()
-   3.8. t_suspend()
-   3.9. t_continue(tindex, tlabel, rtname)
+   3.1. t_cancel_branches(which) 
+   3.2. t_cancel_callid(callid, cseq, flag) 
+   3.3. t_reply_callid(callid, cseq, code, reason) 
+   3.4. t_flush_flags() 
+   3.5. t_is_failure_route() 
+   3.6. t_is_branch_route() 
+   3.7. t_is_reply_route() 
+   3.8. t_suspend() 
+   3.9. t_continue(tindex, tlabel, rtname) 
 
 3.1.  t_cancel_branches(which)
 
-   Cancel branches of an active SIP transaction. The function can be
+   Cancel  branches  of  an  active  SIP transaction. The function can be
    called for a SIP reply that will identify the current branch.
 
    Parameter can be:.
@@ -210,9 +211,9 @@ if (t_reply_callid("123qaz", "5", "458", "Replied remotely")) {
 
 3.4.  t_flush_flags()
 
-   Flush the flags from current SIP message into the already created
-   transaction. It make sense only in routing block if the transaction was
-   created via t_newtran() and the flags have been altered since.
+   Flush  the  flags  from  current  SIP message into the already created
+   transaction.  It  make  sense only in routing block if the transaction
+   was created via t_newtran() and the flags have been altered since.
 
    This function can be used from ANY_ROUTE .
 
@@ -274,8 +275,8 @@ route[abc] {
 
 3.8.  t_suspend()
 
-   Suspend the execution of SIP request in a transaction. If transaction
-   was not created yet, it is created by this function. Returns true in
+   Suspend  the execution of SIP request in a transaction. If transaction
+   was  not  created yet, it is created by this function. Returns true in
    case of success and internal transaction index and label are available
    via $T(id_index) and $T(id_label).
 
@@ -292,15 +293,15 @@ if(t_suspend())
 
 3.9.  t_continue(tindex, tlabel, rtname)
 
-   Continue the execution of the transaction identified by tindex and
+   Continue  the  execution  of  the transaction identified by tindex and
    tlabel with the actions defined in route[rtname].
 
    Parameters:.
-     * tindex - internal index of transaction. Can be an integer or a
+     * tindex  -  internal  index  of transaction. Can be an integer or a
        pseudo-variable.
-     * tlabel - internal label of transaction. Can be an integer or a
+     * tlabel  -  internal  label  of transaction. Can be an integer or a
        pseudo-variable.
-     * rtname - the name of the route block to execute. Can be a static
+     * rtname  -  the name of the route block to execute. Can be a static
        string value or a dynamic string with pseudo-variables.
 
    This function can be used in ANY_ROUTE.
@@ -318,17 +319,18 @@ tcontinue('123', '456', 'MYROUTE');
      * $T_reply_last
      * $T_req(pv)
      * $T_rpl(pv)
+     * $T_reply_ruid
 
    Exported pseudo-variables are documented at
    http://www.kamailio.org/dokuwiki/.
 
 5. MI Commands
 
-   5.1. t_uac_dlg
-   5.2. t_uac_cancel
-   5.3. t_hash
-   5.4. t_reply
-   5.5. t_reply_callid
+   5.1. t_uac_dlg 
+   5.2. t_uac_cancel 
+   5.3. t_hash 
+   5.4. t_reply 
+   5.5. t_reply_callid 
 
 5.1.  t_uac_dlg
 
@@ -337,13 +339,13 @@ tcontinue('123', '456', 'MYROUTE');
    Parameters:
      * method - request method
      * RURI - request SIP URI
-     * NEXT HOP - next hop SIP URI (OBP); use “.� if no value.
-     * socket - local socket to be used for sending the request; use “.�
+     * NEXT HOP - next hop SIP URI (OBP); use "." if no value.
+     * socket  - local socket to be used for sending the request; use "."
        if no value.
      * headers - set of additional headers to be added to the request; at
-       least “From� and “To� headers must be specify)
-     * body - (optional, may not be present) request body (if present,
-       requires the “Content-Type� and “Content-length� headers)
+       least "From" and "To" headers must be specify)
+     * body  -  (optional,  may not be present) request body (if present,
+       requires the "Content-Type" and "Content-length" headers)
 
 5.2.  t_uac_cancel
 
@@ -367,12 +369,13 @@ tcontinue('123', '456', 'MYROUTE');
    Parameters:
      * code - reply code
      * reason - reason phrase.
-     * trans_id - transaction identifier (has the hash_entry:label format)
+     * trans_id   -  transaction  identifier  (has  the  hash_entry:label
+       format)
      * to_tag - To tag to be added to TO header
      * new_headers - extra headers to be appended to the reply; use a dot
-       (“.�) char only if there are no headers;
-     * body - (optional, may not be present) reply body (if present,
-       requires the “Content-Type� and “Content-length� headers)
+       (".") char only if there are no headers;
+     * body  -  (optional,  may  not  be present) reply body (if present,
+       requires the "Content-Type" and "Content-length" headers)
 
 5.5.  t_reply_callid
 
@@ -385,9 +388,9 @@ tcontinue('123', '456', 'MYROUTE');
      * cseq - SIP CSeq header
      * to_tag - To tag to be added to TO header
      * new_headers - extra headers to be appended to the reply; use a dot
-       (“.�) char only if there are no headers;
-     * body - (optional, may not be present) reply body (if present,
-       requires the “Content-Type� and “Content-length� headers)
+       (".") char only if there are no headers;
+     * body  -  (optional,  may  not  be present) reply body (if present,
+       requires the "Content-Type" and "Content-length" headers)
 
 6. Statistics
 
@@ -403,8 +406,8 @@ tcontinue('123', '456', 'MYROUTE');
    6.10. 6xx_transactions
    6.11. inuse_transactions
 
-   Exported statistics are listed in the next sections. All statistics
-   except “inuse_transactions� can be reset.
+   Exported  statistics  are  listed in the next sections. All statistics
+   except "inuse_transactions" can be reset.
 
 6.1. received_replies
 

+ 3 - 0
modules/tmx/doc/tmx_admin.xml

@@ -355,6 +355,9 @@ tcontinue('123', '456', 'MYROUTE');
 			<listitem><para>
 				<emphasis>$T_rpl(pv)</emphasis>
 			</para></listitem>
+			<listitem><para>
+				<emphasis>$T_reply_ruid</emphasis>
+			</para></listitem>
 		</itemizedlist>
 		<para>
 		Exported pseudo-variables are documented at &kamwikilink;.

+ 37 - 0
modules/tmx/t_var.c

@@ -417,6 +417,42 @@ int pv_get_tm_branch_idx(struct sip_msg *msg, pv_param_t *param,
 	return 0;
 }
 
+int pv_get_tm_reply_ruid(struct sip_msg *msg, pv_param_t *param,
+		pv_value_t *res)
+{
+	struct cell *t;
+	int branch;
+
+	if(msg==NULL || res==NULL)
+		return -1;
+
+	/* first get the transaction */
+	if (_tmx_tmb.t_check( msg , 0 )==-1) return -1;
+	if ( (t=_tmx_tmb.t_gett())==0) {
+		/* no T */
+		res->rs = _empty_str;
+	} else {
+		switch (get_route_type()) {
+			case FAILURE_ROUTE:
+			case BRANCH_FAILURE_ROUTE:
+				/* use the reason of the winning reply */
+				if ( (branch=_tmx_tmb.t_get_picked_branch())<0 ) {
+					LM_CRIT("no picked branch (%d) for a final response"
+							" in MODE_ONFAILURE\n", branch);
+					return -1;
+				}
+				res->rs = t->uac[branch].ruid;
+				break;
+			default:
+				LM_ERR("unsupported route_type %d\n", get_route_type());
+				return -1;
+		}
+	}
+	LM_DBG("reply ruid is [%.*s]\n", res->rs.len, res->rs.s);
+	res->flags = PV_VAL_STR;
+	return 0;
+}
+
 int pv_get_tm_reply_code(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res)
 {
@@ -449,6 +485,7 @@ int pv_get_tm_reply_code(struct sip_msg *msg, pv_param_t *param,
 				code = msg->first_line.u.reply.statuscode;
 				break;
 			case FAILURE_ROUTE:
+			case BRANCH_FAILURE_ROUTE:
 				/* use the status of the winning reply */
 				if ( (branch=_tmx_tmb.t_get_picked_branch())<0 ) {
 					LM_CRIT("no picked branch (%d) for a final response"

+ 2 - 0
modules/tmx/t_var.h

@@ -38,6 +38,8 @@ int pv_parse_t_var_name(pv_spec_p sp, str *in);
 
 int pv_get_tm_branch_idx(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res);
+int pv_get_tm_reply_ruid(struct sip_msg *msg, pv_param_t *param,
+		pv_value_t *res);
 int pv_get_tm_reply_code(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res);
 int pv_get_tm_reply_reason(struct sip_msg *msg, pv_param_t *param,

+ 3 - 0
modules/tmx/tmx_mod.c

@@ -123,6 +123,9 @@ static pv_export_t mod_pvs[] = {
 	{ {"T_branch_idx", sizeof("T_branch_idx")-1}, PVT_OTHER,
 		pv_get_tm_branch_idx, 0,
 		 0, 0, 0, 0 },
+	{ {"T_reply_ruid", sizeof("T_reply_ruid")-1}, PVT_OTHER,
+		pv_get_tm_reply_ruid, 0,
+		 0, 0, 0, 0 },
 	{ {"T_reply_code", sizeof("T_reply_code")-1}, PVT_OTHER,
 		pv_get_tm_reply_code, 0,
 		 0, 0, 0, 0 },