소스 검색

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 년 전
부모
커밋
6759d6bbdd
5개의 변경된 파일117개의 추가작업 그리고 69개의 파일을 삭제
  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
 TMX Module
 
 
 Daniel-Constantin Mierla
 Daniel-Constantin Mierla
@@ -11,8 +12,8 @@ Daniel-Constantin Mierla
 
 
    <[email protected]>
    <[email protected]>
 
 
-   Copyright © 2009 Daniel-Constantin Mierla
-     __________________________________________________________________
+   Copyright © 2009 Daniel-Constantin Mierla
+     _________________________________________________________________
 
 
    Table of Contents
    Table of Contents
 
 
@@ -26,24 +27,24 @@ Daniel-Constantin Mierla
 
 
         3. Functions
         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
         4. Exported pseudo-variables
         5. MI Commands
         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
         6. Statistics
 
 
@@ -83,24 +84,24 @@ Chapter 1. Admin Guide
 
 
    3. Functions
    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
    4. Exported pseudo-variables
    5. MI Commands
    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
    6. Statistics
 
 
@@ -135,25 +136,25 @@ Chapter 1. Admin Guide
 
 
 2.2. External Libraries or Applications
 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:
    running Kamailio with this module loaded:
      * None.
      * None.
 
 
 3. Functions
 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)
 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.
    called for a SIP reply that will identify the current branch.
 
 
    Parameter can be:.
    Parameter can be:.
@@ -210,9 +211,9 @@ if (t_reply_callid("123qaz", "5", "458", "Replied remotely")) {
 
 
 3.4.  t_flush_flags()
 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 .
    This function can be used from ANY_ROUTE .
 
 
@@ -274,8 +275,8 @@ route[abc] {
 
 
 3.8.  t_suspend()
 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
    case of success and internal transaction index and label are available
    via $T(id_index) and $T(id_label).
    via $T(id_index) and $T(id_label).
 
 
@@ -292,15 +293,15 @@ if(t_suspend())
 
 
 3.9.  t_continue(tindex, tlabel, rtname)
 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].
    tlabel with the actions defined in route[rtname].
 
 
    Parameters:.
    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.
        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.
        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.
        string value or a dynamic string with pseudo-variables.
 
 
    This function can be used in ANY_ROUTE.
    This function can be used in ANY_ROUTE.
@@ -318,17 +319,18 @@ tcontinue('123', '456', 'MYROUTE');
      * $T_reply_last
      * $T_reply_last
      * $T_req(pv)
      * $T_req(pv)
      * $T_rpl(pv)
      * $T_rpl(pv)
+     * $T_reply_ruid
 
 
    Exported pseudo-variables are documented at
    Exported pseudo-variables are documented at
    http://www.kamailio.org/dokuwiki/.
    http://www.kamailio.org/dokuwiki/.
 
 
 5. MI Commands
 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
 5.1.  t_uac_dlg
 
 
@@ -337,13 +339,13 @@ tcontinue('123', '456', 'MYROUTE');
    Parameters:
    Parameters:
      * method - request method
      * method - request method
      * RURI - request SIP URI
      * 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.
        if no value.
      * headers - set of additional headers to be added to the request; at
      * 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
 5.2.  t_uac_cancel
 
 
@@ -367,12 +369,13 @@ tcontinue('123', '456', 'MYROUTE');
    Parameters:
    Parameters:
      * code - reply code
      * code - reply code
      * reason - reason phrase.
      * 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
      * to_tag - To tag to be added to TO header
      * new_headers - extra headers to be appended to the reply; use a dot
      * 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
 5.5.  t_reply_callid
 
 
@@ -385,9 +388,9 @@ tcontinue('123', '456', 'MYROUTE');
      * cseq - SIP CSeq header
      * cseq - SIP CSeq header
      * to_tag - To tag to be added to TO header
      * to_tag - To tag to be added to TO header
      * new_headers - extra headers to be appended to the reply; use a dot
      * 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
 6. Statistics
 
 
@@ -403,8 +406,8 @@ tcontinue('123', '456', 'MYROUTE');
    6.10. 6xx_transactions
    6.10. 6xx_transactions
    6.11. inuse_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
 6.1. received_replies
 
 

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

@@ -355,6 +355,9 @@ tcontinue('123', '456', 'MYROUTE');
 			<listitem><para>
 			<listitem><para>
 				<emphasis>$T_rpl(pv)</emphasis>
 				<emphasis>$T_rpl(pv)</emphasis>
 			</para></listitem>
 			</para></listitem>
+			<listitem><para>
+				<emphasis>$T_reply_ruid</emphasis>
+			</para></listitem>
 		</itemizedlist>
 		</itemizedlist>
 		<para>
 		<para>
 		Exported pseudo-variables are documented at &kamwikilink;.
 		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;
 	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,
 int pv_get_tm_reply_code(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res)
 		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;
 				code = msg->first_line.u.reply.statuscode;
 				break;
 				break;
 			case FAILURE_ROUTE:
 			case FAILURE_ROUTE:
+			case BRANCH_FAILURE_ROUTE:
 				/* use the status of the winning reply */
 				/* use the status of the winning reply */
 				if ( (branch=_tmx_tmb.t_get_picked_branch())<0 ) {
 				if ( (branch=_tmx_tmb.t_get_picked_branch())<0 ) {
 					LM_CRIT("no picked branch (%d) for a final response"
 					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,
 int pv_get_tm_branch_idx(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res);
 		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,
 int pv_get_tm_reply_code(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res);
 		pv_value_t *res);
 int pv_get_tm_reply_reason(struct sip_msg *msg, pv_param_t *param,
 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,
 	{ {"T_branch_idx", sizeof("T_branch_idx")-1}, PVT_OTHER,
 		pv_get_tm_branch_idx, 0,
 		pv_get_tm_branch_idx, 0,
 		 0, 0, 0, 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,
 	{ {"T_reply_code", sizeof("T_reply_code")-1}, PVT_OTHER,
 		pv_get_tm_reply_code, 0,
 		pv_get_tm_reply_code, 0,
 		 0, 0, 0, 0 },
 		 0, 0, 0, 0 },