On Dec 10, 2008 at 19:17, Daniel-Constantin Mierla <[email protected]> wrote:
> Hello,
> 
> I have uploaded xlog and (stripped) pv Kamailio/Openser modules to 
> sip-router.org site at:
> http://sip-router.org/pub/tmp/miconda/
> 
> If you are willing to test them, then just get the branch "master"  from 
> git and merge with "daniel/pv". Details about GIT repository:
> http://sip-router.org/2008/11/18/git-repository-online/
> 
> The pv module does not include yet the pseudo-variables and 
> transformations dependent of K/O extensions (e.g., branch, script flags, 
> ...). Probably one important to decide upon is the AVP (to start a new 
> discussion about it separately). The ones missing now will be gradually 
> activated as dependent code is sorted out. Testing and feedback is welcome.


The attached patch adds AVP support to it (for sip-router).
Tested andrei/script_vars merged with daniel/pv  with the attached pvar.cfg
(includes ser style avp, kamailio scriptvar pvars and kamailio avp pvars)
 and ser's xlog.

I'll do another merge into master soon, so that it could be tested
directly.


Andrei
diff -ru daniel_pv/pv/pv.c pv/pv.c
--- daniel_pv/pv/pv.c	2008-12-10 16:45:37.000000000 +0100
+++ pv/pv.c	2008-12-16 09:49:34.000000000 +0100
@@ -64,10 +64,8 @@
 		PVT_OTHER, pv_get_stat, 0,
 		pv_parse_stat_name, 0, 0, 0 },
 
-#ifdef KAMAILIO_MODULE
 	{{"avp", (sizeof("avp")-1)}, PVT_AVP, pv_get_avp, pv_set_avp,
 		pv_parse_avp_name, pv_parse_index, 0, 0},
-#endif
 	{{"hdr", (sizeof("hdr")-1)}, PVT_HDR, pv_get_hdr, 0, pv_parse_hdr_name,
 		pv_parse_index, 0, 0},
 	{{"var", (sizeof("var")-1)}, PVT_SCRIPTVAR, pv_get_scriptvar,
diff -ru daniel_pv/pv/pv_core.c pv/pv_core.c
--- daniel_pv/pv/pv_core.c	2008-12-10 16:44:35.000000000 +0100
+++ pv/pv_core.c	2008-12-16 10:52:47.000000000 +0100
@@ -1189,19 +1189,17 @@
 }
 #endif
 
-#ifdef KAMAILIO_MODULE
 int pv_get_avp(struct sip_msg *msg,  pv_param_t *param, pv_value_t *res)
 {
 	unsigned short name_type;
 	int_str avp_name;
 	int_str avp_value;
 	struct usr_avp *avp;
-	int_str avp_value0;
-	struct usr_avp *avp0;
+	struct search_state st; /* avp search state */
+
 	int idx;
 	int idxf;
 	char *p;
-	int n=0;
 
 	if(msg==NULL || res==NULL || param==NULL)
 		return -1;
@@ -1219,11 +1217,11 @@
 		return -1;
 	}
 	
-	if ((avp=search_first_avp(name_type, avp_name, &avp_value, 0))==0)
-		return pv_get_null(msg, param, res);
 	res->flags = PV_VAL_STR;
 	if(idxf==0 && idx==0)
 	{
+		if ((avp=search_first_avp(name_type, avp_name, &avp_value, 0))==0)
+			return pv_get_null(msg, param, res);
 		if(avp->flags & AVP_VAL_STR)
 		{
 			res->rs = avp_value.s;
@@ -1236,6 +1234,8 @@
 	}
 	if(idxf==PV_IDX_ALL)
 	{
+		if ((avp=search_first_avp(name_type, avp_name, &avp_value, &st))==0)
+			return pv_get_null(msg, param, res);
 		p = pv_local_buf;
 		do {
 			if(p!=pv_local_buf)
@@ -1262,8 +1262,7 @@
 			}
 			memcpy(p, res->rs.s, res->rs.len);
 			p += res->rs.len;
-		} while ((avp=search_first_avp(name_type, avp_name,
-						&avp_value, avp))!=0);
+		} while ((avp=search_next_avp(&st, &avp_value))!=0);
 		*p = 0;
 		res->rs.s = pv_local_buf;
 		res->rs.len = p - pv_local_buf;
@@ -1274,19 +1273,13 @@
 	/* we have a numeric index */
 	if(idx<0)
 	{
-		n = 1;
-		avp0 = avp;
-		while ((avp0=search_first_avp(name_type, avp_name,
-						&avp_value0, avp0))!=0) n++;
-		idx = -idx;
-		if(idx>n)
+		avp= search_avp_by_index(name_type|AVP_INDEX_BACKWARD, avp_name,
+			  					&avp_value, -idx);
+		if(avp==0)
 		{
 			LM_DBG("index out of range\n");
 			return pv_get_null(msg, param, res);
-		}
-		idx = n - idx;
-		if(idx==0)
-		{
+		}else{
 			if(avp->flags & AVP_VAL_STR)
 			{
 				res->rs = avp_value.s;
@@ -1295,14 +1288,11 @@
 				res->ri = avp_value.n;
 				res->flags |= PV_VAL_INT|PV_TYPE_INT;
 			}
-			return 0;
 		}
+		return 0;
 	}
-	n=0;
-	while(n<idx 
-			&& (avp=search_first_avp(name_type, avp_name, &avp_value, avp))!=0)
-		n++;
-
+	avp= search_avp_by_index(name_type|AVP_INDEX_FORWARD, avp_name,
+			  					&avp_value, idx);
 	if(avp!=0)
 	{
 		if(avp->flags & AVP_VAL_STR)
@@ -1315,11 +1305,9 @@
 		}
 		return 0;
 	}
-
 	LM_DBG("index out of range\n");
 	return pv_get_null(msg, param, res);
 }
-#endif
 
 int pv_get_hdr(struct sip_msg *msg,  pv_param_t *param, pv_value_t *res)
 {
@@ -1526,7 +1514,6 @@
 /********* end PV get functions *********/
 
 /********* start PV set functions *********/
-#ifdef KAMAILIO_MODULE
 int pv_set_avp(struct sip_msg* msg, pv_param_t *param,
 		int op, pv_value_t *val)
 {
@@ -1534,6 +1521,7 @@
 	int_str avp_val;
 	int flags;
 	unsigned short name_type;
+	struct usr_avp* avp;
 	
 	if(param==NULL)
 	{
@@ -1548,14 +1536,16 @@
 	}
 	if(val == NULL)
 	{
-		if(op == COLONEQ_T)
-			destroy_avps(name_type, avp_name, 1);
-		else
-			destroy_avps(name_type, avp_name, 0);
+		if((name_type & AVP_INDEX_ALL) != AVP_INDEX_ALL)
+			delete_avp(name_type, avp_name);
+		else{
+			avp=search_first_avp(name_type, avp_name, 0, 0);
+			if (avp) destroy_avp(avp);
+		}
 		return 0;
 	}
-	if(op == COLONEQ_T)
-		destroy_avps(name_type, avp_name, 1);
+	if((name_type & AVP_INDEX_ALL) != AVP_INDEX_ALL)
+		delete_avp(name_type, avp_name);
 	flags = name_type;
 	if(val->flags&PV_TYPE_INT)
 	{
@@ -1573,7 +1563,6 @@
 error:
 	return -1;
 }
-#endif
 
 int pv_set_scriptvar(struct sip_msg* msg, pv_param_t *param,
 		int op, pv_value_t *val)
@@ -2066,7 +2055,6 @@
 }
 
 
-#ifdef KAMAILIO_MODULE
 int pv_parse_avp_name(pv_spec_p sp, str *in)
 {
 	char *p;
@@ -2099,7 +2087,7 @@
 	}
 	/*LM_DBG("static name [%.*s]\n", in->len, in->s);*/
 	if(parse_avp_spec(in, &sp->pvp.pvn.u.isname.type,
-				&sp->pvp.pvn.u.isname.name)!=0)
+				&sp->pvp.pvn.u.isname.name, 0)!=0)
 	{
 		LM_ERR("bad avp name [%.*s]\n", in->len, in->s);
 		return -1;
@@ -2107,5 +2095,4 @@
 	sp->pvp.pvn.type = PV_NAME_INTSTR;
 	return 0;
 }
-#endif
 
diff -ru daniel_pv/pv/pv_core.h pv/pv_core.h
--- daniel_pv/pv/pv_core.h	2008-12-10 16:44:01.000000000 +0100
+++ pv/pv_core.h	2008-12-16 09:53:51.000000000 +0100
@@ -186,9 +186,9 @@
 
 int pv_get_branches(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res);
+#endif
 
 int pv_get_avp(struct sip_msg *msg,  pv_param_t *param, pv_value_t *res);
-#endif
 
 int pv_get_hdr(struct sip_msg *msg,  pv_param_t *param, pv_value_t *res);
 
@@ -197,10 +197,8 @@
 /********* end PV get functions *********/
 
 /********* start PV set functions *********/
-#ifdef KAMAILIO_MODULE
 int pv_set_avp(struct sip_msg* msg, pv_param_t *param,
 		int op, pv_value_t *val);
-#endif
 int pv_set_scriptvar(struct sip_msg* msg, pv_param_t *param,
 		int op, pv_value_t *val);
 
@@ -244,9 +242,7 @@
 
 int pv_parse_hdr_name(pv_spec_p sp, str *in);
 
-#ifdef KAMAILIO_MODULE
 int pv_parse_avp_name(pv_spec_p sp, str *in);
-#endif
 
 #endif
 
# do not return the Server: header field in a response
server_signature=0
# do not return the Warning: header field in a response
sip_warning=0

#listen= sctp:(10.36.2.56,10.36.2.58):5080 127.0.0.1
#listen=(eth0)
#listen=___MY_IP___
#listen=___XMLRPC_IP___
alias="example.com"
children=2

#loadmodule "modules/ctl/ctl.so"
# ser xlog
loadmodule "modules/xlog/xlog.so"
loadmodule "modules/pv/pv.so"
# k xlog
#loadmodule "modules/x_xlog/xlog.so"
#modparam("ctl", "binrpc", "tcp:3012")               # tcp any , port 3012
#modparam("ctl", "binrpc", "udp:*:3012")             # udp any , port 3012
disable_tls=0
memlog=1
memdbg=100 # disable verbose mallocs
use_dns_cache=on
dns_try_naptr=on
use_dst_blacklist=on

tcp_defer_accept=10
tcp_syncnt=1

route {
        xlog("L_ALERT", "plain string" " test\n");
        $avp(fu.stest)="avp_test1";
        xlog("L_ALERT", "1. avp  %$fu.stest \n");
        $fu.stest="test2_" + "avp_test2";
        $avp(tmp)="tmp_"+$fu.stest;
        xlog("L_ALERT", "2. avp  fu.stest=%$fu.stest , tmp=%$tmp\n");
        if ($tmp!="tmp_"+$fu.stest || "test2_avp_test2"!=$fu.stest ||
                $tmp!="tmp_test2_avp_test2")
                xlog("L_CRIT", "BUG: sanity check 1 failed: fu.stest=%$fu.stest 
,"
                                " tmp=%$tmp\n");
        $iavp=1+2+3+4+5;
        $fu.stest=($fu.stest+$iavp)+"-"+1;
        if ($iavp!=15 || $fu.stest!="test2_avp_test215-1")
                xlog("L_CRIT", "BUG: sanity check 2 failed: $iavp=%$iavp ,"
                                " $fu.stest=%$fu.stest\n");
        $(var(foo))=$iavp+100;
        xlog("L_ALERT", "%%$iavp=  %$iavp  \n");
        xlog("L_ALERT", "%%$f.iavp=  %$f.iavp  \n");
        xlog("L_ALERT", "%%$fr.iavp=  %$fr.iavp  \n");
        xlog("L_ALERT", "%%$fu.iavp=  %$fu.iavp  \n");
        xlog("L_ALERT", "3. avp  %$fu.stest \n");
        if (2+1>0+1)
                xlog("L_ALERT", "IF1\n");
        if ($iavp>($iavp-1))
                xlog("L_ALERT", "IF2\n");
        if (($iavp=-1+$iavp)<2)
                xlog("L_ALERT", "IF3, %%$iavp = %$iavp\n");
        if ($tmp=="tmp_test2_avp_test2")
                xlog("L_ALERT", "IF4, %%$tmp = %$tmp\n");
        else
                xlog("L_ALERT", "ELSEIF4 if failed: %%$tmp = %$tmp\n");
        $tmp="host="[email protected];
        xlog("L_ALERT", "uri: %$tmp\n");
        if ($tmp+"xxx" == "host="[email protected]+"xxx")
                xlog("L_ALERT", "IF5 (select):tmp=\"%$tmp\"\n");
        if (method=="INVITE")
                xlog("L_ALERT", "IF6 (method==INVITE)\n");
        $tmp="INV";
        if (method==$tmp+"ITE")
                xlog("L_ALERT", "IF7 (method==%$tmp)\n");
        if (method=="INVITE" !=0 )
                xlog("L_ALERT", "IF8 (method==INVITE !=0)\n");
        $tmp=$tmp+"I"+"T"+"E";
        if (method==$tmp)
                xlog("L_ALERT", "IF9 (method==%$tmp)\n");
        if (method=="I"+"NV"+"ITE")
                xlog("L_ALERT", "IF10\n");
        # more optimizations tests
        $var(x)=$iavp;
        $iavp2=1+$var(x)+2+3;
        $iavp=1+2+3+$iavp;
        $iavp3=(2+1)*$iavp*(1+1)-20;
        $iavp4=$iavp-5-10;
        $iavp6=(1+4)+($iavp+5);
        $iavp5=(3+3)+(4+$(avp(iavp))  );
        xlog("L_ALERT", "$iavp=%$iavp $iavp2=%$iavp2 $iavp3=%$iavp3"
                                        " $iavp4=%$iavp4 $iavp5=%$iavp5 
$iavp6=%$iavp6\n");
        drop;
}


_______________________________________________
Serdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/serdev

Reply via email to