File: 17_call_with_reinvite_and_auth.t

package info (click to toggle)
libnet-sip-perl 0.66-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 944 kB
  • sloc: perl: 8,988; makefile: 7
file content (98 lines) | stat: -rw-r--r-- 2,169 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/perl

use strict;
use warnings;
use Test::More tests => 11;
do './testlib.pl' || do './t/testlib.pl' || die "no testlib";

use Net::SIP ':all';

my ($csock,$caddr) = create_socket();
my ($ssock,$saddr) = create_socket();

# start UAS
my $uas = fork_sub( 'uas',$ssock,$caddr,$saddr );
fd_grep_ok( 'Listening',$uas );

# start UAC once UAS is ready
my $uac = fork_sub( 'uac',$csock,$caddr,$saddr );
fd_grep_ok( 'Started',$uac );
fd_grep_ok( 'Call accepted',$uas );

# then re-invite
fd_grep_ok( 'Starting ReInvite', $uac );
fd_grep_ok( 'ReInvite accepted',$uas );
fd_grep_ok( 'ReInvite done', $uac );

# BYE from UAC
fd_grep_ok( 'Send BYE',$uac );
fd_grep_ok( 'Received BYE',$uas );
fd_grep_ok( 'BYE done',$uac );


killall();


#############################################################################
#            UAC
#############################################################################

sub uac {
	my ($lsock,$laddr,$peer) = @_;
	my $ua = Simple->new(
		leg => $lsock,
		from => "sip:me\@$laddr",
		auth => [ 'me','secret' ],
	);

	print "Started\n";
	my $call = $ua->invite( "sip:me\@$peer") or die;

	sleep(1);
	print "Starting ReInvite\n";
	my $reinvite_ok;
	$call->reinvite( cb_final => \$reinvite_ok ) or die;
	$ua->loop( 10,\$reinvite_ok );
	print "ReInvite done\n" if $reinvite_ok;

	sleep(1);
	# and bye
	print "Send BYE\n";
	$call->bye( cb_final => \( my $bye_ok ));
	$ua->loop( 10,\$bye_ok );
	print "BYE done\n" if $bye_ok;


}


#############################################################################
#            UAS
#############################################################################

sub uas {
	my ($lsock,$laddr,$peer) = @_;
	my $ua = Simple->new(
		leg => $lsock,
		from => "sip:me\@$laddr",
	);

	# accept call
	my $invite = my $reinvite = my $bye = 0;
	$ua->listen( 
		auth_user2pass => { 'me' => 'secret' },
		cb_established => sub { $reinvite++ if $invite++ },
		cb_cleanup     => \$bye,
	);
	print "Listening\n";
	$ua->loop( \$invite );
	print "Call accepted\n";
	$ua->loop( \$reinvite );
	print "ReInvite accepted\n";


	# wait until I got BYE
	$ua->loop( 10, \$bye );
	print "Received BYE\n" if $bye;
}