View | Details | Raw Unified | Return to bug 15006
Collapse All | Expand All

(-)a/C4/SIP/SIPServer.pm (-11 / +8 lines)
Lines 15-21 use C4::SIP::Sip::Constants qw(:all); Link Here
15
use C4::SIP::Sip::Configuration;
15
use C4::SIP::Sip::Configuration;
16
use C4::SIP::Sip::Checksum qw(checksum verify_cksum);
16
use C4::SIP::Sip::Checksum qw(checksum verify_cksum);
17
use C4::SIP::Sip::MsgType qw( handle login_core );
17
use C4::SIP::Sip::MsgType qw( handle login_core );
18
use C4::SIP::Sip qw( read_SIP_packet );
18
use C4::SIP::Sip qw( read_SIP_packet get_timeout );
19
19
20
use base qw(Net::Server::PreFork);
20
use base qw(Net::Server::PreFork);
21
21
Lines 128-134 sub raw_transport { Link Here
128
    my $strikes = 3;
128
    my $strikes = 3;
129
129
130
    local $SIG{ALRM} = sub { die "raw_transport Timed Out!\n"; };
130
    local $SIG{ALRM} = sub { die "raw_transport Timed Out!\n"; };
131
    my $timeout = $service->{timeout} || 30;
131
    my $timeout = get_timeout( $self, { transport => 1 } );
132
    syslog("LOG_DEBUG", "raw_transport: timeout is %d", $timeout);
132
    syslog("LOG_DEBUG", "raw_transport: timeout is %d", $timeout);
133
133
134
    while( $strikes && ( !$self->{account} || !$self->{account}->{id} )) {
134
    while( $strikes && ( !$self->{account} || !$self->{account}->{id} )) {
Lines 193-199 sub telnet_transport { Link Here
193
    my $account = undef;
193
    my $account = undef;
194
    my $input;
194
    my $input;
195
    my $config  = $self->{config};
195
    my $config  = $self->{config};
196
    my $timeout = $self->{service}->{timeout} || $config->{timeout} || 30;
196
    my $timeout = get_timeout( $self, { transport => 1 } );
197
    syslog("LOG_DEBUG", "telnet_transport: timeout is %s", $timeout);
197
    syslog("LOG_DEBUG", "telnet_transport: timeout is %s", $timeout);
198
198
199
    eval {
199
    eval {
Lines 255-261 sub sip_protocol_loop { Link Here
255
    my $self = shift;
255
    my $self = shift;
256
    my $service = $self->{service};
256
    my $service = $self->{service};
257
    my $config  = $self->{config};
257
    my $config  = $self->{config};
258
    my $timeout = $self->{service}->{client_timeout} || $config->{client_timeout};
258
259
    my $timeout = get_timeout( $self, { client => 1 } );
259
    my $input;
260
    my $input;
260
261
261
    # The spec says the first message will be:
262
    # The spec says the first message will be:
Lines 272-283 sub sip_protocol_loop { Link Here
272
    #
273
    #
273
    # In short, we'll take any valid message here.
274
    # In short, we'll take any valid message here.
274
    #my $expect = SC_STATUS;
275
    #my $expect = SC_STATUS;
275
    local $SIG{ALRM} = sub { die "SIP Timed Out!\n"; } if $timeout;
276
    local $SIG{ALRM} = sub { die "SIP Timed Out!\n"; };
276
    my $expect = '';
277
    my $expect = '';
277
    while (1) {
278
    while (1) {
278
        if ($timeout) {
279
        alarm $timeout;
279
            alarm $timeout;
280
        }
281
        $input = read_SIP_packet(*STDIN);
280
        $input = read_SIP_packet(*STDIN);
282
        unless ($input) {
281
        unless ($input) {
283
            return;        # EOF
282
            return;        # EOF
Lines 303-311 sub sip_protocol_loop { Link Here
303
        }
302
        }
304
        # We successfully received and processed what we were expecting
303
        # We successfully received and processed what we were expecting
305
        $expect = '';
304
        $expect = '';
306
        if ($timeout ) {
305
        alarm 0;
307
            alarm 0;
308
        }
309
    }
306
    }
310
}
307
}
311
308
(-)a/C4/SIP/Sip.pm (-2 / +26 lines)
Lines 23-35 BEGIN { Link Here
23
23
24
	@EXPORT_OK = qw(y_or_n timestamp add_field maybe_add add_count
24
	@EXPORT_OK = qw(y_or_n timestamp add_field maybe_add add_count
25
		    denied sipbool boolspace write_msg read_SIP_packet
25
		    denied sipbool boolspace write_msg read_SIP_packet
26
            get_timeout
26
		    $error_detection $protocol_version $field_delimiter
27
		    $error_detection $protocol_version $field_delimiter
27
		    $last_response);
28
		    $last_response);
28
29
29
	%EXPORT_TAGS = (
30
	%EXPORT_TAGS = (
30
		    all => [qw(y_or_n timestamp add_field maybe_add
31
		    all => [qw(y_or_n timestamp add_field maybe_add
31
			       add_count denied sipbool boolspace write_msg
32
			       add_count denied sipbool boolspace write_msg
32
			       read_SIP_packet
33
                   read_SIP_packet get_timeout
33
			       $error_detection $protocol_version
34
			       $error_detection $protocol_version
34
			       $field_delimiter $last_response)]);
35
			       $field_delimiter $last_response)]);
35
}
36
}
Lines 251-254 sub write_msg { Link Here
251
    $last_response = $msg;
252
    $last_response = $msg;
252
}
253
}
253
254
255
# get_timeout( $server, { transport|client => 1, fallback => some_val } );
256
#
257
# Centralizes all timeout logic from SIPServer into one routine
258
259
sub get_timeout {
260
    my ( $server, $params ) = @_;
261
262
    my $fallback = $params->{fallback} || 30;
263
    if( $params->{transport} ) {
264
        # We do not allow zero values here
265
        return $server->{service}->{timeout} || $fallback;
266
    } elsif( $params->{client} ) {
267
        if( exists $server->{policy}->{timeout} ) {
268
        # We do allow zero values here to indicate no timeout
269
            my $val = $server->{policy}->{timeout};
270
            $val = 0 if ! $val > 0; # just precautious
271
            return $val;
272
        }
273
        return $server->{service}->{timeout} || $fallback;
274
    } else {
275
        return $fallback;
276
    }
277
}
278
254
1;
279
1;
255
- 

Return to bug 15006