Commit f067d267 authored by gregor herrmann's avatar gregor herrmann

Update upstream source from tag 'upstream/0.820'

Update to upstream version '0.820'
with Debian dir 3975fa4d16717e71cd4c7cc26c45710a47241f61
parents e6e18ed7 50ccd47f
Revision history for Net::SIP
0.820 2019-02-14
- loose check from 0.819 - allow multiple contacts
0.819 2019-02-14
- Net::SIP::Packet - add more checks when parsing a packet from string,
notably about conflicting fields like multiple cseq or conflic between
method in cseq vs method in request.
0.818 2018-11-10
- fixed wrong skip size in t/22_stateless_proxy_ack_on_error.t in case specific
features like IPv6 or TLS where not available
......
......@@ -85,6 +85,7 @@ t/19_call_with_dtmf.t
t/20_channel_on_hold.t
t/21_channel_on_hold_stateless_proxy.t
t/22_stateless_proxy_ack_on_error.t
t/23_valid_message.t
t/certs/caller.sip.test.pem
t/certs/listen.sip.test.pem
t/certs/proxy.sip.test.pem
......
......@@ -49,6 +49,6 @@
"url" : "https://github.com/noxxi/p5-net-sip"
}
},
"version" : "0.818",
"version" : "0.820",
"x_serialization_backend" : "JSON::PP version 2.27400_02"
}
......@@ -24,5 +24,5 @@ resources:
homepage: https://github.com/noxxi/p5-net-sip
license: http://dev.perl.org/licenses/
repository: https://github.com/noxxi/p5-net-sip
version: '0.818'
version: '0.820'
x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
......@@ -3,7 +3,7 @@ use warnings;
use 5.010;
package Net::SIP;
our $VERSION = '0.818';
our $VERSION = '0.820';
# this includes nearly everything else
use Net::SIP::Simple ();
......
......@@ -564,19 +564,36 @@ sub as_parts {
'warning' => \&_hdrkey_parse_comma_seperated,
'call-id' => sub {
$_[0] =~ $callid_rx or die "invalid callid, should be 'word [@ word]'";
$_[0] =~ $callid_rx or
die "invalid callid, should be 'word [@ word]'\n";
return $_[0];
},
'cseq' => sub {
$_[0] =~ m{^\d+\s+\w+\s*$} or die "invalid cseq, should be 'number method'";
$_[0] =~ m{^\d+\s+\w+\s*$} or
die "invalid cseq, should be 'number method'\n";
return $_[0];
},
);
my %once = map { ($_ => 1) }
qw(cseq content-type from to call-id content-length);
my %key2check = (
rsp => undef,
req => {
cseq => sub {
my ($v,$result) = @_;
$v =~ m{^\d+\s+(\w+)\s*$} or
die "invalid cseq, should be 'number method'\n";
$result->{method} eq $1 or
die "method in cseq does not match method of request\n";
},
}
);
sub _hdrkey_parse_keep { return $_[0] };
sub _hdrkey_parse_num {
my ($v,$k) = @_;
$v =~m{^(\d+)\s*$} || die "invalid $k, should be number";
$v =~m{^(\d+)\s*$} || die "invalid $k, should be number\n";
return $1;
};
......@@ -597,7 +614,7 @@ sub as_parts {
}
} else {
# missing end-quote
die "missing '$quote' in '$v'";
die "missing '$quote' in '$v'\n";
}
} elsif ( $v =~m{\G(.*?)([\\"<,])}gc ) {
if ( $2 eq "\\" ) {
......@@ -629,16 +646,19 @@ sub as_parts {
my ($header,$body) = split( m{\r?\n\r?\n}, $string,2 );
my @header = split( m{\r?\n}, $header );
my $key2check;
if ( $header[0] =~m{^SIP/2.0\s+(\d+)\s+(\S.*?)\s*$} ) {
# Response, e.g. SIP/2.0 407 Authorization required
$result{code} = $1;
$result{text} = $2;
$key2check = $key2check{rsp};
} elsif ( $header[0] =~m{^(\w+)\s+(\S.*?)\s+SIP/2\.0\s*$} ) {
# Request, e.g. INVITE <sip:bla@fasel> SIP/2.0
$result{method} = $1;
$result{text} = $2;
$key2check = $key2check{req};
} else {
die "bad request: starts with '$header[0]'";
die "bad request: starts with '$header[0]'\n";
}
shift(@header);
......@@ -646,9 +666,11 @@ sub as_parts {
my @hdr;
my @lines;
my @check;
my %check_once;
while (@header) {
my ($k,$v) = $header[0] =~m{^([^\s:]+)\s*:\s*(.*)}
or die "bad header line $header[0]";
or die "bad header line $header[0]\n";
my $line = shift(@header);
while ( @header && $header[0] =~m{^\s+(.*)} ) {
# continuation line
......@@ -666,10 +688,22 @@ sub as_parts {
} else {
push @hdr, Net::SIP::HeaderPair->new( $k,$v[0],scalar(@lines) );
}
if (my $k2c = $key2check->{$nk}) {
push @check, [ $k2c, $_ ] for @v;
}
if ($once{$nk}) {
($check_once{$nk} //= $_) eq $_ or
die "conflicting definition of $nk\n"
for @v;
}
push @lines, [ $line, int(@v) ];
}
$result{header} = \@hdr;
$result{lines} = \@lines;
for(@check) {
my ($sub,$v) = @$_;
$sub->($v,\%result);
}
return \%result;
}
}
......
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
use Net::SIP::Packet;
use Net::SIP::Request;
use Net::SIP::Response;
check(undef, <<'REQ');
INVITE sip:foo@bar.com SIP/2.0
From: <sip:me@example.com>
To: <sip:you@example.com>
Call-Id: foobar@example.com
Cseq: 10 INVITE
Content-length: 0
REQ
check(qr/method in cseq does not match method of request/, <<'REQ');
INVITE sip:foo@bar.com SIP/2.0
From: <sip:me@example.com>
To: <sip:you@example.com>
Call-Id: foobar@example.com
Cseq: 10 BYE
Content-length: 0
REQ
check(qr/conflicting definition of cseq/, <<'REQ');
INVITE sip:foo@bar.com SIP/2.0
From: <sip:me@example.com>
To: <sip:you@example.com>
Call-Id: foobar@example.com
Cseq: 10 INVITE
Cseq: 20 INVITE
Content-length: 0
REQ
check(qr/conflicting definition of call-id/, <<'REQ');
INVITE sip:foo@bar.com SIP/2.0
From: <sip:me@example.com>
To: <sip:you@example.com>
Call-Id: foobar@example.com
Cseq: 20 INVITE
Call-Id: barfoot@example.com
Content-length: 0
REQ
check(qr/conflicting definition of content-length/, <<'REQ');
INVITE sip:foo@bar.com SIP/2.0
From: <sip:me@example.com>
To: <sip:you@example.com>
Call-Id: foobar@example.com
Cseq: 20 INVITE
Content-length: 0
Content-length: 10
REQ
check(qr/conflicting definition of from/, <<'REQ');
INVITE sip:foo@bar.com SIP/2.0
From: <sip:me@example.com>
To: <sip:you@example.com>
Call-Id: foobar@example.com
Cseq: 20 INVITE
Content-length: 0
From: <sip:foo@example.com>
REQ
check(qr/conflicting definition of to/, <<'REQ');
INVITE sip:foo@bar.com SIP/2.0
From: <sip:me@example.com>
To: <sip:you@example.com>
Call-Id: foobar@example.com
Cseq: 20 INVITE
Content-length: 0
To: <sip:foo@example.com>
REQ
check(undef, <<'REQ');
INVITE sip:foo@bar.com SIP/2.0
From: <sip:me@example.com>
To: <sip:you@example.com>
Call-Id: foobar@example.com
Cseq: 20 INVITE
Content-length: 0
Contact: <sip:foo@example.com>
Contact: <sip:bar@example.com>
REQ
done_testing();
sub check {
my ($expect_err,$string) = @_;
my $pkt = eval { Net::SIP::Packet->new($string) };
# diag($@ ? "error: $@": "no error");
if (! $expect_err) {
ok($pkt,'valid message');
} else {
like($@, $expect_err, "expected error: $expect_err");
}
# diag($pkt->as_string) if $pkt;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment