[OpenSIPS-Users] Regex to test variable

Donat Zenichev donat.zenichev at gmail.com
Wed Nov 25 17:31:14 EST 2020


Hi! Are you sure that the condition indeed doesn't work?
It shouldn't have been so, if $avp(audio_stream) is indeed equal to "101".

Other than that, I would advise to have more informative xlog() output,
something like:
xlog("CUSTOM_LOG: Audio stream is <$avp(audio_stream)> \n");

So with braces.
Thus you can see if you got some irrelevant spaces or might return a
carriage sign.


On Wed, Nov 25, 2020 at 7:14 PM Mark Farmer <farmorg at gmail.com> wrote:

> OK some progress
>
> I'm using the s.select transformation which returns the last field
> correctly:
>
> $avp(audio_stream) = $(rb{sdp.line,m}{s.select,-1, });
>                 xlog("CUSTOM_LOG: Audio stream is $avp(audio_stream)\n");
>                 if ($avp(audio_stream) == "101") {
>
> CUSTOM_LOG: Audio stream is 101
>
> But if ($avp(audio_stream) == "101") still doesn't match :(
>
> What am I doing wrong here?
>
> Thanks
> Mark.
>
>
> On Wed, 25 Nov 2020 at 16:09, Mark Farmer <farmorg at gmail.com> wrote:
>
>> Thanks for the reply!
>>
>> I've changed my regex to
>>
>> if ($avp(audio_stream) =~ "^m=audio.*101\r\n")
>>
>> Tried with and without escaping the equals sign but still not matching.
>> Also changed to using an avp.
>>
>> Mark.
>>
>>
>> On Wed, 25 Nov 2020 at 15:54, M S <medeanwz at gmail.com> wrote:
>>
>>> something with your regex. each header has a \r\n in the end too, also
>>> I'm not sure you need \ before =
>>>
>>> On Wed, Nov 25, 2020 at 4:26 PM Mark Farmer <farmorg at gmail.com> wrote:
>>>
>>>> Hi everyone
>>>>
>>>> I am trying to detect a string using sdp.line,m and a regex pattern but
>>>> it is failing to match.
>>>> I am trying to match the 101 at the end of the m=audio line:
>>>>
>>>> m=audio 25224 RTP/AVP 8 18 101
>>>>
>>>> This is my code:
>>>>
>>>> if (is_method("INVITE") && has_body_part("application/sdp")) {
>>>>                 $var(audio_stream) = $(rb{sdp.line,m});
>>>>                 xlog("CUSTOM_LOG: Audio stream is
>>>> $var(audio_stream)\n");
>>>>                 if ($var(audio_stream) =~ "^m\=audio.*101$") {
>>>>                         $var(dtmf_compat)=1;
>>>>                 } else $var(dtmf_compat)=0;
>>>>                 if ($var(dtmf_compat)=0) {
>>>>                         xlog("CUSTOM_LOG: Would do something else now");
>>>>                 }
>>>>                 xlog("CUSTOM_LOG: DTMF validity = $var(dtmf_compat)");
>>>>         }
>>>>
>>>> I can see that var(audio_stream) is being set correctly:
>>>> CUSTOM_LOG: Audio stream is m=audio 25914 RTP/AVP 8 18 101
>>>>
>>>> But it seems not to match:
>>>> CUSTOM_LOG: DTMF validity = 0
>>>>
>>>> Is anyone able to help me solve this please?
>>>>
>>>> Many thanks!
>>>> Mark.
>>>>
>>>>
>>>> _______________________________________________
>>>> Users mailing list
>>>> Users at lists.opensips.org
>>>> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>>>>
>>> _______________________________________________
>>> Users mailing list
>>> Users at lists.opensips.org
>>> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>>>
>>
>>
>> --
>> Mark Farmer
>> farmorg at gmail.com
>>
>
>
> --
> Mark Farmer
> farmorg at gmail.com
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>


-- 

Best regards,
Donat Zenichev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20201125/becc87ce/attachment.html>


More information about the Users mailing list