[sr-dev] git:master: modules/mtree: fixed return value of mt_match when mode=2

Juha Heinanen jh at tutpro.com
Fri Sep 5 16:14:20 CEST 2014


Module: sip-router
Branch: master
Commit: af69a3075ac4a7a46d72b0d60e6bc1740a56b7a7
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=af69a3075ac4a7a46d72b0d60e6bc1740a56b7a7

Author: Juha Heinanen <jh at tutpro.com>
Committer: Juha Heinanen <jh at tutpro.com>
Date:   Fri Sep  5 17:11:47 2014 +0300

modules/mtree: fixed return value of mt_match when mode=2
- initialize pv_values avp by mt_match when mode=2
- documented mt_match return value

---

 modules/mtree/README              |   26 ++++++++++++++------------
 modules/mtree/doc/mtree_admin.xml |    7 +++++--
 modules/mtree/mtree.c             |   12 +++++++++---
 3 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/modules/mtree/README b/modules/mtree/README
index b0a6543..28dd6d8 100644
--- a/modules/mtree/README
+++ b/modules/mtree/README
@@ -20,9 +20,9 @@ Juha Heinanen
 
    <jh at tutpro.com>
 
-   Copyright © 2010 Daniel-Constantin Mierla (asipto.com)
+   Copyright (c) 2010 Daniel-Constantin Mierla (asipto.com)
 
-   Copyright © 2011 Juha Heinanen
+   Copyright (c) 2011 Juha Heinanen
      __________________________________________________________________
 
    Table of Contents
@@ -275,8 +275,8 @@ modparam("mtree", "pv_value", "$var(mtval)")
 
 3.10. pv_values (string)
 
-   The PV spec where to store the matched values when mtree is of type 0
-   or 2 and mode of mt_match() call has value 2. It can be any AVP.
+   The AVP where to store the matched values when mtree is of type 0 or 2
+   and mode of mt_match() call has value 2.
 
    Default value is "$avp(s:tvalues)".
 
@@ -323,7 +323,7 @@ modparam("mtree", "mt_allow_duplicates", 1)
 
    4.1. mt_match(mtree, pv, mode)
 
-4.1. mt_match(mtree, pv, mode)
+4.1.  mt_match(mtree, pv, mode)
 
    Match 'pv' value against 'mtree'. If 'mtree' type is 0 or 2 and value
    of 'mode' is NOT 2, sets a value of the longest matching prefix to
@@ -333,6 +333,8 @@ modparam("mtree", "mt_allow_duplicates", 1)
    matching prefix is in avp index 0. Parameter 'mode' can be an integer
    constant or a pseudo variable with integer value.
 
+   Returns 1 if match succeeded and -1 otherwise.
+
    Example 1.14. mt_match usage
 ...
 mt_match("mytree", "$rU", "0");
@@ -345,7 +347,7 @@ mt_match("mytree", "$rU", "0");
    5.3. mt_summary
    5.4. mt_match
 
-5.1. mt_list
+5.1.  mt_list
 
    List content of a tree.
 
@@ -359,7 +361,7 @@ mt_match("mytree", "$rU", "0");
                 _mtname_
                 _empty_line_
 
-5.2. mt_reload
+5.2.  mt_reload
 
    Reload mtree from database.
 
@@ -374,7 +376,7 @@ mt_match("mytree", "$rU", "0");
                 _mtname_
                 _empty_line_
 
-5.3. mt_summary
+5.3.  mt_summary
 
    List usage summary for all trees.
 
@@ -386,7 +388,7 @@ mt_match("mytree", "$rU", "0");
                 :mt_summary:_reply_fifo_file_
                 _empty_line_
 
-5.4. mt_match
+5.4.  mt_match
 
    Match prefix value against mtree.
 
@@ -410,7 +412,7 @@ mt_match("mytree", "$rU", "0");
    6.2. mtree.reload
    6.3. mtree.match
 
-6.1. mtree.summary
+6.1.  mtree.summary
 
    List usage summary for all trees or for the tree whose name is given as
    parameter.
@@ -418,7 +420,7 @@ mt_match("mytree", "$rU", "0");
    Parameters:
      * _mtree_ - (optional) the name of the tree.
 
-6.2. mtree.reload
+6.2.  mtree.reload
 
    Reload mtree from database to memory.
 
@@ -426,7 +428,7 @@ mt_match("mytree", "$rU", "0");
      * _mtree_
        - name of mtree or empty string meaning all mtrees
 
-6.3. mtree.match
+6.3.  mtree.match
 
    Match prefix value against mtree
 
diff --git a/modules/mtree/doc/mtree_admin.xml b/modules/mtree/doc/mtree_admin.xml
index cf91bbc..17c2c8f 100644
--- a/modules/mtree/doc/mtree_admin.xml
+++ b/modules/mtree/doc/mtree_admin.xml
@@ -248,8 +248,8 @@ modparam("mtree", "pv_value", "$var(mtval)")
 	<section>
 	    <title><varname>pv_values</varname> (string)</title>
 	    <para>
-		The PV spec where to store the matched values when mtree is of type
-		0 or 2 and mode of mt_match() call has value 2. It can be any AVP.
+		The AVP where to store the matched values when mtree is of type
+		0 or 2 and mode of mt_match() call has value 2.
 		</para>
 	    <para>
 		<emphasis>
@@ -344,6 +344,9 @@ modparam("mtree", "mt_allow_duplicates", 1)
 		matching prefix is in avp index 0.  Parameter 'mode' can be an integer
 		constant or a pseudo variable with integer value.
 	    </para>
+	    <para>
+	      Returns 1 if match succeeded and -1 otherwise.
+	    </para>
 		<example>
 		<title><function>mt_match</function> usage</title>
 		<programlisting format="linespecific">
diff --git a/modules/mtree/mtree.c b/modules/mtree/mtree.c
index 63521f5..6b6283d 100644
--- a/modules/mtree/mtree.c
+++ b/modules/mtree/mtree.c
@@ -336,7 +336,7 @@ is_t* mt_get_tvalue(m_tree_t *pt, str *tomatch, int *len)
 
 int mt_add_tvalues(struct sip_msg *msg, m_tree_t *pt, str *tomatch)
 {
-	int l;
+        int l, n;
 	mt_node_t *itn;
 	int_str val, values_avp_name;
 	unsigned short values_name_type;
@@ -353,7 +353,9 @@ int mt_add_tvalues(struct sip_msg *msg, m_tree_t *pt, str *tomatch)
 		return -1;
 	}
 
-	l = 0;
+	destroy_avps(values_name_type, values_avp_name, 1);
+
+	l = n = 0;
 	itn = pt->head;
 
 	while (itn != NULL && l < tomatch->len && l < MT_MAX_DEPTH) {
@@ -377,6 +379,7 @@ int mt_add_tvalues(struct sip_msg *msg, m_tree_t *pt, str *tomatch)
 						val.s.s);
 				add_avp(values_name_type|AVP_VAL_STR, values_avp_name, val);
 			}
+			n++;
 			tvalues = tvalues->next;
 		}
 
@@ -384,7 +387,10 @@ int mt_add_tvalues(struct sip_msg *msg, m_tree_t *pt, str *tomatch)
 		l++;	
 	}
 
-	return 0;
+	if (n > 0)
+	        return 0;
+	else
+	        return -1;
 }
 
 int mt_match_prefix(struct sip_msg *msg, m_tree_t *it,




More information about the sr-dev mailing list