[sr-dev] mt_match return value

Daniel-Constantin Mierla miconda at gmail.com
Fri Sep 5 14:55:50 CEST 2014


On 05/09/14 13:34, Juha Heinanen wrote:
> mtree README does not mention about return value of mt_match
> function. however, code has this:
>
> 	if(mt_match_prefix(msg, tr, &tomatch, mval)<0)
> 	{
> 		LM_DBG("no prefix found in [%.*s] for [%.*s]\n",
> 				tname.len, tname.s,
> 				tomatch.len, tomatch.s);
> 		goto error;
> 	}
>
> 	lock_get( mt_lock );
> 	mt_tree_refcnt--;
> 	lock_release( mt_lock );
> 	return 1;
>
> error:
> 	lock_get( mt_lock );
> 	mt_tree_refcnt--;
> 	lock_release( mt_lock );
> 	return -1;
>
> so it looks like mt_match would return 1 if match succeeded and -1 if
> it did not.
>
> however, this does not work if mode param has value 2, because in that
> case result of mt_add_tvalues is returned:
>
> 	if ((it->type==MT_TREE_SVAL) || (it->type==MT_TREE_IVAL)) {
> 		if (mode == 2)
> 			return mt_add_tvalues(msg, it, tomatch);
>
> mt_add_values, in turn, always returns 0 in case there is no error.
>
> would it be ok if i make mt_add_tvalues to return -1 if no match is
> found?  i could then also document the return value.
Yes, you can change, it looks like right expectation.

Cheers,
Daniel

-- 
Daniel-Constantin Mierla
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Next Kamailio Advanced Trainings 2014 - http://www.asipto.com
Sep 22-25, Berlin, Germany




More information about the sr-dev mailing list