[SR-Users] Capture a Match from Regex comparison

Daniel-Constantin Mierla miconda at gmail.com
Fri Jun 19 12:02:55 CEST 2015


Hello,

On 19/06/15 11:52, Sebastian Damm wrote:
> Hi,
>
> we have some cases, where we get multiple PCMA lines with different
> numbers from a peer. One of our backend systems doesn't handle that
> correctly. So what I want to do is detect whether there is a PCMA line
> with a non-standard number in the SDP.
>
> This is how an SDP looks like:
> v=0
> o=hiQ9200 2990220150519102450 1229717573 IN IP4 1.2.3.4
> s=Phone Call
> c=IN IP4 1.2.3.4
> t=0 0
> m=audio 40174 RTP/AVP 8 0 18 96 97 13 100 98 99
> a=rtpmap:8 PCMA/8000
> a=fmtp:8 vad=no
> a=rtpmap:0 PCMU/8000
> a=fmtp:0 vad=no
> a=rtpmap:18 G729/8000
> a=fmtp:18 annexb=yes
> a=rtpmap:96 G726-32/8000
> a=rtpmap:97 AAL2-G726-32/8000
> a=rtpmap:100 telephone-event/8000
> a=fmtp:100 0-15
> a=rtpmap:98 PCMA/8000
> a=gpmd:98 vbd=yes
> a=rtpmap:99 PCMU/8000
> a=gpmd:99 vbd=yes
> a=sqn: 0
> a=cdsc: 1 image udptl t38
> a=sendrecv
> a=pmft: T38
> a=ptime:20
>
> I tried something like that (expecting that the number doesn't change):
>
> if (sdp_get_line_startswith("$avp(badcodec)", "a=rtpmap:98 PCMA")) {
>
> But this makes Kamailio drop the INVITE when arriving at the line in
> the config. I guess, "startswith" stops parsing the line at the colon.

there was a bug returning 0 in case of a no match. I just pushed a fix
in master, going to backport it.

>
> So I thought I'll make it more generically:
>
> sdp_get("$avp(sdp)");
> if ($avp(sdp) =~ "a=rtpmap:([1-9][0-9][0-9]?) PCMA") {
>     sdp_remove_codecs_by_id("$missingvariable");
> }
>
> What I need is to capture the number in the a=rtpmap line so I can
> delete the codec by ID. But I couldn't find a way to capture the
> matches from my regex comparison. Am I missing something?
Maybe you can use the subst transformation here.

Cheers,
Daniel

-- 
Daniel-Constantin Mierla
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Book: SIP Routing With Kamailio - http://www.asipto.com




More information about the sr-users mailing list