Skip Menu |

This queue is for tickets about the Net-SIP CPAN distribution.

Report information
The Basics
Id: 120593
Status: resolved
Priority: 0/
Queue: Net-SIP

People
Owner: Nobody in particular
Requestors: richard.carver [...] cloudmont.co.uk
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: StatelessProxy contact rewriting for URIs with no '@'
Date: Sun, 12 Mar 2017 12:05:47 +0000
To: "bug-Net-SIP [...] rt.cpan.org" <bug-Net-SIP [...] rt.cpan.org>
From: Richard Carver <richard.carver [...] cloudmont.co.uk>
I am using StatelessProxy.pm to make several SIP systems talk to each other where they have slightly different non-standard behaviour. One of them uses a Contact URI that does not contain '@'. I would like to have Statelessproxy.pm support this for contact rewriting. The default contact rewriting function uses the presence of an '@' in the address that it is passed to determine whether it is rewriting forwards or backwards, so in my scenario when it is passed a URI without the '@' it does a backwards rewrite when I need it to do a forwards rewrite. I propose to add support for Contact URIs that do not contain an '@' without changing the requirements of the default or any other contact rewriting function. I achieve this by adding an '@' to the start of the address before calling the rewrite function for forward rewriting if there is not one present, and by removing a leading '@' from the returned address of backwards rewriting if one is present. See the below proposed patch. In theory this could break people's existing custom rewrite functions, but I view this as very unlikely as there are only two scenarios where I can see that this would happen: 1) They are already using Contact URIs with no '@', they ignore the perl warning and have an external proxy that corrects the broken contact header that it creates. 2) They map contact URIs that do contain '@' and for some reason are adding an additional '@' to the start of the mapped URI that they return. I suspect that this would break the rewrite-back logic, so as well as being an odd thing to do it probably wouldn't work anyway. *** /usr/local/share/perl5/Net/SIP/StatelessProxy.pm.orig Mon Jan 30 08:24:25 2017 --- /usr/local/share/perl5/Net/SIP/StatelessProxy.pm Sun Mar 12 07:42:27 2017 *************** sub receive { *** 220,225 **** --- 220,226 ---- my $outgoing_leg; if ( my $back = invoke_callback( $rewrite_contact,$name,$incoming_leg,\$outgoing_leg )) { + $back =~ s{^\@}{}; $to = $pre.$back; DEBUG( 10,"rewrote URI from '%s' back to '%s'", $packet->uri, $to ); $packet->set_uri( $to ); *************** sub __forward_packet_final { *** 509,520 **** --- 510,523 ---- # if contact was rewritten rewrite back if ( $addr =~m{^(\w+)(\@.*)} and my $newaddr = invoke_callback( $rewrite_contact,$1,$incoming_leg,$outgoing_leg)) { + $newaddr =~ s{^\@}{}; my $cnew = sip_parts2hdrval( 'contact', $pre.$newaddr.$post, $p ); DEBUG( 50,"rewrote back '$c' to '$cnew'" ); $c = $cnew; # otherwise rewrite it } else { + $addr = '@' . $addr unless $addr =~ m{\@}; $addr = invoke_callback($rewrite_contact,$addr,$incoming_leg, $outgoing_leg); $addr .= '@'.$outgoing_leg->laddr(2);

Message body is not shown because it is too large.

Am So 12. Mär 2017, 10:38:14, richard.carver@cloudmont.co.uk schrieb: Show quoted text
> .. > The default contact rewriting function uses the presence of an '@' in > the address that it is passed to determine whether it is rewriting > forwards or backwards ...
Thanks for the patch. I've changed the use of the rewriting function to add an additional argument force_rewrite. This is set inside StatelessProxy.pm in case a forward rewrite should be done. This way this decision no longer depends on the existence of the '@' sign in the address. I think that this is a cleaner way to deal with your use case. See commit 6ce0421.