[OpenSIPS-Users] replace_body()

Mark Farmer farmorg at gmail.com
Wed Mar 25 12:33:46 EST 2020


Now that I've corrected my silly xlog() lines I've got it partially
working, transcoding is working (correct codecs passed in either direction).

However the connection & origin IP addresses are incorrect. I tried
reversing the in-face & out-face flags but that made no difference.

Nearly there, any idea why I have the IP issue?


On Wed, 25 Mar 2020 at 11:06, Mark Farmer <farmorg at gmail.com> wrote:

> Hi Bogdan, thanks for the reply.
>
> That was what I ended up trying to do, hence the other question about
> deleting a line from a pvar but that's another thread.
>
> However, I do have a related question.
> Does the body modification also apply to a reply? The issue I have now is
> that when I try to apply modifications to the reply, they are not applied.
>
> I set $avp(CallFlow) before sending the INVITE and check it in the reply
> route in order to apply the rtpengine() flags but the outgoing reply has
> the wrong media IP & codec,
>
> onreply_route[DROUTING_RTPENGINE] {
>
>         ...
>
>         if ($rs=~"(2[0-9][0-9])|(183)" && has_body("application/sdp")) {
>             xlog("CUSTOM_LOG: Processing reply $fU Gateway Attribues:
> $var(gw_attrs)");
>             fix_nated_contact();
>             if (is_from_gw("2") && $avp(CallFlow)=="TPTY_PSTN") {
>                     xlog("CUSTOM_LOG: Reply from PSTN to TPTY");
>                     setflag(R_PSTN_TPTY);
>                 } else if (is_from_gw("2") && $avp(CallFlow)=="PBX_PSTN") {
>                     xlog("CUSTOM_LOG: Reply from PSTN to PBX");
>                     setflag(R_PSTN_PBX);
>                 } else if (is_from_gw("3") && $avp(CallFlow)=="PBX_TPTY") {
>                     xlog("CUSTOM_LOG: Reply from TPTY to PBX");
>                     setflag(R_TPTY_PBX);
>                 } else if (is_from_gw("3") && $avp(CallFlow)=="PSTN_TPTY")
> {
>                     xlog("CUSTOM_LOG: Reply from MSDR to PSTN");
>                     setflag(R_TPTY_PSTN);
>                 } else if (is_from_gw("1") && $avp(CallFlow)=="PSTN_PBX") {
>                     xlog("CUSTOM_LOG: Reply from PBX to PSTN");
>                     setflag(R_PBX_PSTN);
>                 } else if (is_from_gw("1") && $avp(CallFlow)=="TPTY_PBX") {
>                     xlog("CUSTOM_LOG: Reply from PBX to MSDR");
>                     setflag(R_PBX_TPTY);
>                 } else xlog("CUSTOM_LOG: No match in on_reply route!");
>         }
>
>         $var(R_PSTN_TPTY) = "RTP AVP ICE=remove in-face=external
> out-face=internal codec-mask-PCMA transcode-G722 replace-session-connection
> replace-origin";
>         $var(R_PSTN_PBX) = "RTP AVP ICE=remove in-face=external
> out-face=internal replace-session-connection replace-origin";
>         $var(R_TPTY_PBX) = "RTP AVP ICE=remove in-face=internal
> out-face=internal replace-session-connection replace-origin";
>         $var(R_TPTY_PSTN) = "RTP AVP ICE=remove in-face=internal
> out-face=external codec-mask-G722 transcode-PCMA replace-session-connection
> replace-origin";
>         $var(R_PBX_PSTN) = "RTP AVP ICE=remove in-face=internal
> out-face=external replace-session-connection replace-origin";
>         $var(R_PBX_TPTY) = "RTP AVP ICE=remove in-face=internal
> out-face=internal codec-mask-PCMA transcode-G722 replace-session-connection
> replace-origin";
>
>         if (isflagset(R_PSTN_TPTY)) {
>                 xlog("CUSTOM_LOG: Setting up media on reply using variable
> $$R_PSTN_TPTY $R_PSTN_TPTY");
>                 rtpengine_answer("$var(R_PSTN_TPTY)");
>             } else if (isflagset(R_PSTN_PBX)) {
>                 xlog("CUSTOM_LOG: Setting up media on reply using variable
> $$R__PSTN_PBX $R_PSTN_PBX");
>                 rtpengine_answer("$var(R_PSTN_PBX)");
>             } else if (isflagset(R_TPTY_PBX)) {
>                 xlog("CUSTOM_LOG: Setting up media on reply using variable
> $$R_TPTY_PBX $R_TPTY_PBX");
>                 rtpengine_answer("$var(R_TPTY_PBX)");
>             } else if (isflagset(R_TPTY_PSTN)) {
>                 xlog("CUSTOM_LOG: Setting up media on reply using variable
> $$R_TPTY_PSTN $R_TPTY_PSTN");
>                 rtpengine_answer("$var(R_TPTY_PSTN)");
>             } else if (isflagset(R_PBX_PSTN)){
>                 xlog("CUSTOM_LOG: Setting up media on reply using variable
> $$R_PBX_PSTN $R_PBX_PSTN");
>                 rtpengine_answer("$var(R_PBX_PSTN)");
>             } else if (isflagset(R_PBX_TPTY)) {
>                 xlog("CUSTOM_LOG: Setting up media on reply using variable
> $$R_PBX_TPTY $R_PBX_TPTY");
>                 rtpengine_answer("$var(R_PBX_TPTY)");
>             }
> }
>
>
> On Fri, 20 Mar 2020 at 11:04, Bogdan-Andrei Iancu <bogdan at opensips.org>
> wrote:
>
>> Hi Mark,
>>
>> You mentioned calling rtpengine before? if so, note that you cannot have
>> more than one change over the same part of the body. And rtpengine is
>> replacing the whole body, so you cannot change a prev change.
>> What you have to do is to tell  rtpengine_offer() to provide the new
>> body into a variable (rather then changing the msg), so you can change the
>> value of the variable and push it into the msg afterwards.
>>
>> PS: why do you do record_route_set() + record_route() in the same time ???
>>
>> Regards,
>>
>> Bogdan-Andrei Iancu
>>
>> OpenSIPS Founder and Developer
>>   https://www.opensips-solutions.com
>> OpenSIPS Summit, Amsterdam, May 2020
>>   https://www.opensips.org/events/Summit-2020Amsterdam/
>>
>> On 3/19/20 1:21 PM, Mark Farmer wrote:
>>
>> Hi everyone
>>
>> I am trying to remove a line from the SDP resulting from
>> rtpengine_offer() but it's not working for me. Can anyone tell me what I am
>> doing wrong please?
>>
>> if (is_from_gw("2")) {
>>                 remove_hf("Contact","g");
>>                 insert_hf("Contact:
>> <sip:$fU@$var(fqdn):5061;did=$DLG_did>\r\n");
>>                 xlog("CUSTOM_LOG: Call to Microsoft - Adjusting SIP
>> Headers & SDP");
>>                 set_advertised_address("$var(fqdn)");
>>                 record_route_preset("my.fqdn:5061;transport=tls",
>> "XXX.XXX.XXX.XXX:5060");
>>                 add_rr_param(";r2=on");
>>                 record_route();
>>                 if (replace_body("a=setup:actpass","")) {
>>                         xlog("CUSTOM_LOG: Removed a=setup:actpass line
>> from SDP");
>>                 }
>> }
>>
>> I have also tried:
>>
>> if (replace_body("a=setup:actpass\r",""))
>> and
>> if (replace_body("a=setup:actpass\r\n",""))
>>
>> Many thanks
>> Mark.
>>
>>
>> _______________________________________________
>> Users mailing listUsers at lists.opensips.orghttp://lists.opensips.org/cgi-bin/mailman/listinfo/users
>>
>>
>>
>
> --
> Mark Farmer
> farmorg at gmail.com
>


-- 
Mark Farmer
farmorg at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20200325/86017c23/attachment-0001.html>


More information about the Users mailing list