noxxi / p5-net-sip

Net::SIP Perl Module
Other
15 stars 22 forks source link

Handle 302 redirect and other 'unhandled' responses? #66

Closed kobaz closed 8 months ago

kobaz commented 8 months ago

Hi!

I need to be able to read a 302 redirect response from an INVITE So far it doesn't seem like there's a callback to hook into for this... so I added one for Net::SIP::Leg

sub receive {
    my Net::SIP::Leg $self = shift;
    #my $self = shift;
    my ($packet,$from) = @_;

    $DEBUG && DEBUG( 2,"received packet on %s from %s:\n%s",
        sip_sockinfo2uri($self->{proto},@{$self->{src}}{qw(addr port family)}),
        sip_sockinfo2uri(@{$from}{qw(proto addr port family)}),
        $packet->dump( Net::SIP::Debug->level -2 )
    );

    invoke_callback($self->{cb_recieve}, 'OK',$self, $packet); # <--- invoke a new cb_recieve callback on a Leg so the user can process

    return ($packet,$from);
}

Is this the right spot? It definitely does do the job...

noxxi commented 8 months ago

If you want to catch arbitrary packets coming into a leg you can simply subclass Net::SIP:Leg and add the functionality to your derived class (after calling the original method), instead of adding the functionality to the existing implementation.