浏览代码

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

Juha Heinanen 11 年之前
父节点
当前提交
af69a3075a
共有 3 个文件被更改,包括 28 次插入17 次删除
  1. 14 12
      modules/mtree/README
  2. 5 2
      modules/mtree/doc/mtree_admin.xml
  3. 9 3
      modules/mtree/mtree.c

+ 14 - 12
modules/mtree/README

@@ -20,9 +20,9 @@ Juha Heinanen
 
 
    <[email protected]>
    <[email protected]>
 
 
-   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
    Table of Contents
@@ -275,8 +275,8 @@ modparam("mtree", "pv_value", "$var(mtval)")
 
 
 3.10. pv_values (string)
 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)".
    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)
+4.1.  mt_match(mtree, pv, mode)
 
 
    Match 'pv' value against 'mtree'. If 'mtree' type is 0 or 2 and value
    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
    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
    matching prefix is in avp index 0. Parameter 'mode' can be an integer
    constant or a pseudo variable with integer value.
    constant or a pseudo variable with integer value.
 
 
+   Returns 1 if match succeeded and -1 otherwise.
+
    Example 1.14. mt_match usage
    Example 1.14. mt_match usage
 ...
 ...
 mt_match("mytree", "$rU", "0");
 mt_match("mytree", "$rU", "0");
@@ -345,7 +347,7 @@ mt_match("mytree", "$rU", "0");
    5.3. mt_summary
    5.3. mt_summary
    5.4. mt_match
    5.4. mt_match
 
 
-5.1. mt_list
+5.1.  mt_list
 
 
    List content of a tree.
    List content of a tree.
 
 
@@ -359,7 +361,7 @@ mt_match("mytree", "$rU", "0");
                 _mtname_
                 _mtname_
                 _empty_line_
                 _empty_line_
 
 
-5.2. mt_reload
+5.2.  mt_reload
 
 
    Reload mtree from database.
    Reload mtree from database.
 
 
@@ -374,7 +376,7 @@ mt_match("mytree", "$rU", "0");
                 _mtname_
                 _mtname_
                 _empty_line_
                 _empty_line_
 
 
-5.3. mt_summary
+5.3.  mt_summary
 
 
    List usage summary for all trees.
    List usage summary for all trees.
 
 
@@ -386,7 +388,7 @@ mt_match("mytree", "$rU", "0");
                 :mt_summary:_reply_fifo_file_
                 :mt_summary:_reply_fifo_file_
                 _empty_line_
                 _empty_line_
 
 
-5.4. mt_match
+5.4.  mt_match
 
 
    Match prefix value against mtree.
    Match prefix value against mtree.
 
 
@@ -410,7 +412,7 @@ mt_match("mytree", "$rU", "0");
    6.2. mtree.reload
    6.2. mtree.reload
    6.3. mtree.match
    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
    List usage summary for all trees or for the tree whose name is given as
    parameter.
    parameter.
@@ -418,7 +420,7 @@ mt_match("mytree", "$rU", "0");
    Parameters:
    Parameters:
      * _mtree_ - (optional) the name of the tree.
      * _mtree_ - (optional) the name of the tree.
 
 
-6.2. mtree.reload
+6.2.  mtree.reload
 
 
    Reload mtree from database to memory.
    Reload mtree from database to memory.
 
 
@@ -426,7 +428,7 @@ mt_match("mytree", "$rU", "0");
      * _mtree_
      * _mtree_
        - name of mtree or empty string meaning all mtrees
        - name of mtree or empty string meaning all mtrees
 
 
-6.3. mtree.match
+6.3.  mtree.match
 
 
    Match prefix value against mtree
    Match prefix value against mtree
 
 

+ 5 - 2
modules/mtree/doc/mtree_admin.xml

@@ -248,8 +248,8 @@ modparam("mtree", "pv_value", "$var(mtval)")
 	<section>
 	<section>
 	    <title><varname>pv_values</varname> (string)</title>
 	    <title><varname>pv_values</varname> (string)</title>
 	    <para>
 	    <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>
 	    <para>
 	    <para>
 		<emphasis>
 		<emphasis>
@@ -343,6 +343,9 @@ modparam("mtree", "mt_allow_duplicates", 1)
 		to avp specified by pv_values parameter so that a value of longest
 		to avp specified by pv_values parameter so that a value of longest
 		matching prefix is in avp index 0.  Parameter 'mode' can be an integer
 		matching prefix is in avp index 0.  Parameter 'mode' can be an integer
 		constant or a pseudo variable with integer value.
 		constant or a pseudo variable with integer value.
+	    </para>
+	    <para>
+	      Returns 1 if match succeeded and -1 otherwise.
 	    </para>
 	    </para>
 		<example>
 		<example>
 		<title><function>mt_match</function> usage</title>
 		<title><function>mt_match</function> usage</title>

+ 9 - 3
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 mt_add_tvalues(struct sip_msg *msg, m_tree_t *pt, str *tomatch)
 {
 {
-	int l;
+        int l, n;
 	mt_node_t *itn;
 	mt_node_t *itn;
 	int_str val, values_avp_name;
 	int_str val, values_avp_name;
 	unsigned short values_name_type;
 	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;
 		return -1;
 	}
 	}
 
 
-	l = 0;
+	destroy_avps(values_name_type, values_avp_name, 1);
+
+	l = n = 0;
 	itn = pt->head;
 	itn = pt->head;
 
 
 	while (itn != NULL && l < tomatch->len && l < MT_MAX_DEPTH) {
 	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);
 						val.s.s);
 				add_avp(values_name_type|AVP_VAL_STR, values_avp_name, val);
 				add_avp(values_name_type|AVP_VAL_STR, values_avp_name, val);
 			}
 			}
+			n++;
 			tvalues = tvalues->next;
 			tvalues = tvalues->next;
 		}
 		}
 
 
@@ -384,7 +387,10 @@ int mt_add_tvalues(struct sip_msg *msg, m_tree_t *pt, str *tomatch)
 		l++;	
 		l++;	
 	}
 	}
 
 
-	return 0;
+	if (n > 0)
+	        return 0;
+	else
+	        return -1;
 }
 }
 
 
 int mt_match_prefix(struct sip_msg *msg, m_tree_t *it,
 int mt_match_prefix(struct sip_msg *msg, m_tree_t *it,