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 189-195 sub telnet_transport { Link Here
189
    my $account = undef;
189
    my $account = undef;
190
    my $input;
190
    my $input;
191
    my $config  = $self->{config};
191
    my $config  = $self->{config};
192
    my $timeout = $self->{service}->{timeout} || $config->{timeout} || 30;
192
    my $timeout = get_timeout( $self, { transport => 1 } );
193
    syslog("LOG_DEBUG", "telnet_transport: timeout is %s", $timeout);
193
    syslog("LOG_DEBUG", "telnet_transport: timeout is %s", $timeout);
194
194
195
    eval {
195
    eval {
Lines 251-257 sub sip_protocol_loop { Link Here
251
    my $self = shift;
251
    my $self = shift;
252
    my $service = $self->{service};
252
    my $service = $self->{service};
253
    my $config  = $self->{config};
253
    my $config  = $self->{config};
254
    my $timeout = $self->{service}->{client_timeout} || $config->{client_timeout};
254
255
    my $timeout = get_timeout( $self, { client => 1 } );
255
    my $input;
256
    my $input;
256
257
257
    # The spec says the first message will be:
258
    # The spec says the first message will be:
Lines 268-279 sub sip_protocol_loop { Link Here
268
    #
269
    #
269
    # In short, we'll take any valid message here.
270
    # In short, we'll take any valid message here.
270
    #my $expect = SC_STATUS;
271
    #my $expect = SC_STATUS;
271
    local $SIG{ALRM} = sub { die "SIP Timed Out!\n"; } if $timeout;
272
    local $SIG{ALRM} = sub { die "SIP Timed Out!\n"; };
272
    my $expect = '';
273
    my $expect = '';
273
    while (1) {
274
    while (1) {
274
        if ($timeout) {
275
        alarm $timeout;
275
            alarm $timeout;
276
        }
277
        $input = read_SIP_packet(*STDIN);
276
        $input = read_SIP_packet(*STDIN);
278
        unless ($input) {
277
        unless ($input) {
279
            return;        # EOF
278
            return;        # EOF
Lines 299-307 sub sip_protocol_loop { Link Here
299
        }
298
        }
300
        # We successfully received and processed what we were expecting
299
        # We successfully received and processed what we were expecting
301
        $expect = '';
300
        $expect = '';
302
        if ($timeout ) {
301
        alarm 0;
303
            alarm 0;
304
        }
305
    }
302
    }
306
}
303
}
307
304
(-)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