Extract data from AVP

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Extract data from AVP

Mickael HUBERT
Hi all,
I want to extract the channel ID from a line in SDP (a=channel:d87c363c1b5b4f13@speechrecog)
I can extract this line, but I don't know how can I have only the ID (d87c363c1b5b4f13)

Do you have a way for me please ?

thanks in advance

SDP example:
***********
m=application 1544 TCP/MRCPv2 1
a=setup:passive
a=connection:new
a=channel:d87c363c1b5b4f13@speechrecog
a=cmid:1
m=audio 5002 RTP/AVP 8 101

*************

My conf:

My result: "line in the SDP body is a=channel:d87c363c1b5b4f13@speechrecog"
I want only: d87c363c1b5b4f13 in specific avp
onreply_route[reply_mrcp]
{
xlog("L_INFO","$avp(startlog) In REPLY ROUTE MRCP - fu : $fu , si : $si , rs: $rs\n");
if(has_body_part("application/sdp"))
{
if (search_body("m=application.*TCP\/MRCPv2")) {
if(search_body("a=channel:.*")) {
$var(i) = 0;
$var(whileflag) = 0;
while ($var(i) < 10 && $var(whileflag) != 1)
{
$avp(aline) = $(rb{sdp.line,a,$var(i)});
if($avp(aline)=~"a=channel")
{
xlog("line in the SDP body is $avp(aline)\n");
$var(whileflag) = 1;
}
$var(i) = $var(i) + 1;
}
xlog("var i = $var(i)\n");
}
}
}
}

_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Extract data from AVP

Ben Newlin

Have you tried using the substitution transformation?

 

https://www.opensips.org/Documentation/Script-Tran-2-4#toc82

 

Ben Newlin

 

From: Users <[hidden email]> on behalf of Mickael Hubert <[hidden email]>
Reply-To: OpenSIPS users mailling list <[hidden email]>
Date: Wednesday, November 27, 2019 at 11:11 AM
To: OpenSIPS users mailling list <[hidden email]>
Subject: [OpenSIPS-Users] Extract data from AVP

 

Hi all,

I want to extract the channel ID from a line in SDP (a=channel:d87c363c1b5b4f13@speechrecog)

I can extract this line, but I don't know how can I have only the ID (d87c363c1b5b4f13)

 

Do you have a way for me please ?

 

thanks in advance

 

SDP example:

***********
m=application 1544 TCP/MRCPv2 1
a=setup:passive
a=connection:new
a=channel:d87c363c1b5b4f13@speechrecog
a=cmid:1
m=audio 5002 RTP/AVP 8 101

*************

 

My conf:

 

My result: "line in the SDP body is a=channel:d87c363c1b5b4f13@speechrecog"

I want only: d87c363c1b5b4f13 in specific avp

 

onreply_route[reply_mrcp]

 

{

 

xlog("L_INFO","$avp(startlog) In REPLY ROUTE MRCP - fu : $fu , si : $si , rs: $rs\n");

 

if(has_body_part("application/sdp"))

 

{

 

if (search_body("m=application.*TCP\/MRCPv2"))

{

 

if(search_body("a=channel:.*")) {

 

$var(i)

=

0;

 

$var(whileflag)

=

0;

 

while ($var(i)

< 

10

&&

$var(whileflag)

!=

1)

 

{

 

$avp(aline)

= $(rb{sdp.line,a,$var(i)});

 

if($avp(aline)=~"a=channel")

 

{

 

xlog("line in the SDP body is $avp(aline)\n");

 

$var(whileflag)

=

1;

 

}

 

$var(i)

=

$var(i)

+

1;

 

}

 

xlog("var i = $var(i)\n");

 

}

 

}

 

}

 

}

 


_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Extract data from AVP

Mickael HUBERT
Thanks Ben,
yes I tried this:
$var(toto) = $(avp(aline){re.subst,/.*:(.*)/\1/g}); # delete a=channel:

xlog("line in the SDP body is $(var(toto){re.subst,/(.*)@.*/\1/g})\n");
xlog("line in the SDP body is $(var(toto){re.subst,/.*@(.*)/\1/g})\n");

It works like a charm, maybe there is a better way ...

Le mer. 27 nov. 2019 à 17:51, Ben Newlin <[hidden email]> a écrit :

Have you tried using the substitution transformation?

 

https://www.opensips.org/Documentation/Script-Tran-2-4#toc82

 

Ben Newlin

 

From: Users <[hidden email]> on behalf of Mickael Hubert <[hidden email]>
Reply-To: OpenSIPS users mailling list <[hidden email]>
Date: Wednesday, November 27, 2019 at 11:11 AM
To: OpenSIPS users mailling list <[hidden email]>
Subject: [OpenSIPS-Users] Extract data from AVP

 

Hi all,

I want to extract the channel ID from a line in SDP (a=channel:d87c363c1b5b4f13@speechrecog)

I can extract this line, but I don't know how can I have only the ID (d87c363c1b5b4f13)

 

Do you have a way for me please ?

 

thanks in advance

 

SDP example:

***********
m=application 1544 TCP/MRCPv2 1
a=setup:passive
a=connection:new
a=channel:d87c363c1b5b4f13@speechrecog
a=cmid:1
m=audio 5002 RTP/AVP 8 101

*************

 

My conf:

 

My result: "line in the SDP body is a=channel:d87c363c1b5b4f13@speechrecog"

I want only: d87c363c1b5b4f13 in specific avp

 

onreply_route[reply_mrcp]

 

{

 

xlog("L_INFO","$avp(startlog) In REPLY ROUTE MRCP - fu : $fu , si : $si , rs: $rs\n");

 

if(has_body_part("application/sdp"))

 

{

 

if (search_body("m=application.*TCP\/MRCPv2"))

{

 

if(search_body("a=channel:.*")) {

 

$var(i)

=

0;

 

$var(whileflag)

=

0;

 

while ($var(i)

< 

10

&&

$var(whileflag)

!=

1)

 

{

 

$avp(aline)

= $(rb{sdp.line,a,$var(i)});

 

if($avp(aline)=~"a=channel")

 

{

 

xlog("line in the SDP body is $avp(aline)\n");

 

$var(whileflag)

=

1;

 

}

 

$var(i)

=

$var(i)

+

1;

 

}

 

xlog("var i = $var(i)\n");

 

}

 

}

 

}

 

}

 

_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users

_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Extract data from AVP

Ben Newlin

Well, you could improve it by combining the two substitutions into one:

 

$var(toto) = $(avp(aline){re.subst,/.*:(.*)@.*/\1/g});

 

Beyond that if this is something you do often you can use the dialplan module [1] to store the regex as a rule and apply it anywhere you want. It may have been designed for dialplan management but it is basically a database-backed regex module that can be used for anything.

 

[1] https://opensips.org/html/docs/modules/2.4.x/dialplan.html

 

Ben Newlin

 

From: Users <[hidden email]> on behalf of Mickael Hubert <[hidden email]>
Reply-To: OpenSIPS users mailling list <[hidden email]>
Date: Wednesday, November 27, 2019 at 1:29 PM
To: OpenSIPS users mailling list <[hidden email]>
Subject: Re: [OpenSIPS-Users] Extract data from AVP

 

Thanks Ben,

yes I tried this:

$var(toto) = $(avp(aline){re.subst,/.*:(.*)/\1/g}); # delete a=channel:

 

 

xlog("line in the SDP body is $(var(toto){re.subst,/(.*)@.*/\1/g})\n");

xlog("line in the SDP body is $(var(toto){re.subst,/.*@(.*)/\1/g})\n");

 

It works like a charm, maybe there is a better way ...

 

Le mer. 27 nov. 2019 à 17:51, Ben Newlin <[hidden email]> a écrit :

Have you tried using the substitution transformation?

 

https://www.opensips.org/Documentation/Script-Tran-2-4#toc82

 

Ben Newlin

 

From: Users <[hidden email]> on behalf of Mickael Hubert <[hidden email]>
Reply-To: OpenSIPS users mailling list <[hidden email]>
Date: Wednesday, November 27, 2019 at 11:11 AM
To: OpenSIPS users mailling list <[hidden email]>
Subject: [OpenSIPS-Users] Extract data from AVP

 

Hi all,

I want to extract the channel ID from a line in SDP (a=channel:d87c363c1b5b4f13@speechrecog)

I can extract this line, but I don't know how can I have only the ID (d87c363c1b5b4f13)

 

Do you have a way for me please ?

 

thanks in advance

 

SDP example:

***********
m=application 1544 TCP/MRCPv2 1
a=setup:passive
a=connection:new
a=channel:d87c363c1b5b4f13@speechrecog
a=cmid:1
m=audio 5002 RTP/AVP 8 101

*************

 

My conf:

 

My result: "line in the SDP body is a=channel:d87c363c1b5b4f13@speechrecog"

I want only: d87c363c1b5b4f13 in specific avp

 

onreply_route[reply_mrcp]

 

{

 

xlog("L_INFO","$avp(startlog) In REPLY ROUTE MRCP - fu : $fu , si : $si , rs: $rs\n");

 

if(has_body_part("application/sdp"))

 

{

 

if (search_body("m=application.*TCP\/MRCPv2"))

{

 

if(search_body("a=channel:.*")) {

 

$var(i)

=

0;

 

$var(whileflag)

=

0;

 

while ($var(i)

10

&&

$var(whileflag)

!=

1)

 

{

 

$avp(aline)

= $(rb{sdp.line,a,$var(i)});

 

if($avp(aline)=~"a=channel")

 

{

 

xlog("line in the SDP body is $avp(aline)\n");

 

$var(whileflag)

=

1;

 

}

 

$var(i)

=

$var(i)

+

1;

 

}

 

xlog("var i = $var(i)\n");

 

}

 

}

 

}

 

}

 

_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


_______________________________________________
Users mailing list
[hidden email]
http://lists.opensips.org/cgi-bin/mailman/listinfo/users