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

(-)a/C4/SIP/SIPServer.pm (-37 / +20 lines)
Lines 21-27 use constant LOG_SIP => "local6"; # Local alias for the logging facility Link Here
21
use vars qw(@ISA $VERSION);
21
use vars qw(@ISA $VERSION);
22
22
23
BEGIN {
23
BEGIN {
24
	$VERSION = 1.02;
24
	$VERSION = 1.03;
25
	@ISA = qw(Net::Server::PreFork);
25
	@ISA = qw(Net::Server::PreFork);
26
}
26
}
27
27
Lines 35-41 BEGIN { Link Here
35
my %transports = (
35
my %transports = (
36
    RAW    => \&raw_transport,
36
    RAW    => \&raw_transport,
37
    telnet => \&telnet_transport,
37
    telnet => \&telnet_transport,
38
    # http   => \&http_transport,	# for http just use the OPAC
39
);
38
);
40
39
41
#
40
#
Lines 126-156 sub raw_transport { Link Here
126
    my $self = shift;
125
    my $self = shift;
127
    my ($input);
126
    my ($input);
128
    my $service = $self->{service};
127
    my $service = $self->{service};
129
    my $strikes = 3;
130
128
131
    eval {
129
    while (!$self->{account}) {
132
		local $SIG{ALRM} = sub { die "raw_transport Timed Out!\n"; };
130
	local $SIG{ALRM} = sub { die "raw_transport Timed Out!\n"; };
133
		syslog("LOG_DEBUG", "raw_transport: timeout is %d", $service->{timeout});
131
	syslog("LOG_DEBUG", "raw_transport: timeout is %d", $service->{timeout});
134
		while ($strikes--) {
132
	$input = Sip::read_SIP_packet(*STDIN);
135
		    alarm $service->{timeout};
133
	if (!$input) {
136
		    $input = Sip::read_SIP_packet(*STDIN);
134
		# EOF on the socket
137
		    alarm 0;
135
		syslog("LOG_INFO", "raw_transport: shutting down: EOF during login");
138
			if (!$input) {
136
		return;
139
				# EOF on the socket
137
	}
140
				syslog("LOG_INFO", "raw_transport: shutting down: EOF during login");
138
	$input =~ s/[\r\n]+$//sm;	# Strip off trailing line terminator(s)
141
				return;
139
	last if Sip::MsgType::handle($input, $self, LOGIN);
142
		    }
143
		    $input =~ s/[\r\n]+$//sm;	# Strip off trailing line terminator(s)
144
		    last if Sip::MsgType::handle($input, $self, LOGIN);
145
		}
146
	};
147
148
    if (length $@) {
149
		syslog("LOG_ERR", "raw_transport: LOGIN ERROR: '$@'");
150
		die "raw_transport: login error (timeout? $@), exiting";
151
    } elsif (!$self->{account}) {
152
		syslog("LOG_ERR", "raw_transport: LOGIN FAILED");
153
		die "raw_transport: Login failed (no account), exiting";
154
    }
140
    }
155
141
156
    syslog("LOG_DEBUG", "raw_transport: uname/inst: '%s/%s'",
142
    syslog("LOG_DEBUG", "raw_transport: uname/inst: '%s/%s'",
Lines 269-300 sub sip_protocol_loop { Link Here
269
	# In short, we'll take any valid message here.
255
	# In short, we'll take any valid message here.
270
	#my $expect = SC_STATUS;
256
	#my $expect = SC_STATUS;
271
    my $expect = '';
257
    my $expect = '';
272
    my $strikes = 3;
258
    while (1) {
273
    while ($input = Sip::read_SIP_packet(*STDIN)) {
259
    		$input = Sip::read_SIP_packet(*STDIN);
260
    		unless ($input) {
261
    			return;		# EOF
262
    		}
274
		# begin input hacks ...  a cheap stand in for better Telnet layer
263
		# begin input hacks ...  a cheap stand in for better Telnet layer
275
		$input =~ s/^[^A-z0-9]+//s;	# Kill leading bad characters... like Telnet handshakers
264
		$input =~ s/^[^A-z0-9]+//s;	# Kill leading bad characters... like Telnet handshakers
276
		$input =~ s/[^A-z0-9]+$//s;	# Same on the end, should get DOSsy ^M line-endings too.
265
		$input =~ s/[^A-z0-9]+$//s;	# Same on the end, should get DOSsy ^M line-endings too.
277
		while (chomp($input)) {warn "Extra line ending on input";}
266
		while (chomp($input)) {warn "Extra line ending on input";}
278
		unless ($input) {
267
		unless ($input) {
279
			if ($strikes--) {
268
			syslog("LOG_ERR", "sip_protocol_loop: empty input skipped");
280
				syslog("LOG_ERR", "sip_protocol_loop: empty input skipped");
269
			print("96$CR");
281
				next;
270
			next;
282
			} else {
283
				syslog("LOG_ERR", "sip_protocol_loop: quitting after too many errors");
284
				die "sip_protocol_loop: quitting after too many errors";
285
			}
286
		}
271
		}
287
		# end cheap input hacks
272
		# end cheap input hacks
288
		my $status = Sip::MsgType::handle($input, $self, $expect);
273
		my $status = Sip::MsgType::handle($input, $self, $expect);
289
		if (!$status) {
274
		if (!$status) {
290
			syslog("LOG_ERR", "sip_protocol_loop: failed to handle %s",substr($input,0,2));
275
			syslog("LOG_ERR", "sip_protocol_loop: failed to handle %s",substr($input,0,2));
291
			die "sip_protocol_loop: failed Sip::MsgType::handle('$input', $self, '$expect')";
292
		}
276
		}
293
		next if $status eq REQUEST_ACS_RESEND;
277
		next if $status eq REQUEST_ACS_RESEND;
294
		if ($expect && ($status ne $expect)) {
278
		if ($expect && ($status ne $expect)) {
295
			# We received a non-"RESEND" that wasn't what we were expecting.
279
			# We received a non-"RESEND" that wasn't what we were expecting.
296
		    syslog("LOG_ERR", "sip_protocol_loop: expected %s, received %s, exiting", $expect, $input);
280
		    syslog("LOG_ERR", "sip_protocol_loop: expected %s, received %s, exiting", $expect, $input);
297
			die "sip_protocol_loop: exiting: expected '$expect', received '$status'";
298
		}
281
		}
299
		# We successfully received and processed what we were expecting
282
		# We successfully received and processed what we were expecting
300
		$expect = '';
283
		$expect = '';
(-)a/C4/SIP/Sip.pm (-8 lines)
Lines 156-162 sub read_SIP_packet { Link Here
156
    # local $/ = "\r";      # don't need any of these here.  use whatever the prevailing $/ is.
156
    # local $/ = "\r";      # don't need any of these here.  use whatever the prevailing $/ is.
157
    local $/ = "\015";    # proper SPEC: (octal) \015 = (hex) x0D = (dec) 13 = (ascii) carriage return
157
    local $/ = "\015";    # proper SPEC: (octal) \015 = (hex) x0D = (dec) 13 = (ascii) carriage return
158
    {    # adapted from http://perldoc.perl.org/5.8.8/functions/readline.html
158
    {    # adapted from http://perldoc.perl.org/5.8.8/functions/readline.html
159
        for ( my $tries = 1 ; $tries <= 3 ; $tries++ ) {
160
            undef $!;
159
            undef $!;
161
            $record = readline($fh);
160
            $record = readline($fh);
162
            if ( defined($record) ) {
161
            if ( defined($record) ) {
Lines 171-184 sub read_SIP_packet { Link Here
171
                while ( chomp($record) ) { 1; }
170
                while ( chomp($record) ) { 1; }
172
171
173
                $record and last;    # success
172
                $record and last;    # success
174
            } else {
175
                if ($!) {
176
                    syslog( "LOG_DEBUG", "read_SIP_packet (try #$tries) ERROR: $! $@" );
177
                    # die "read_SIP_packet ERROR: $!";
178
                    warn "read_SIP_packet ERROR: $! $@";
179
                }
180
            }
173
            }
181
        }
182
    }
174
    }
183
    if ($record) {
175
    if ($record) {
184
        my $len2 = length($record);
176
        my $len2 = length($record);
(-)a/C4/SIP/Sip/MsgType.pm (-2 / +3 lines)
Lines 405-411 sub handle { Link Here
405
	}
405
	}
406
	unless ($self->{handler}) {
406
	unless ($self->{handler}) {
407
		syslog("LOG_WARNING", "No handler defined for '%s'", $msg);
407
		syslog("LOG_WARNING", "No handler defined for '%s'", $msg);
408
		return undef;
408
		$last_response = REQUEST_SC_RESEND;
409
		print("$last_response\r");
410
		return REQUEST_ACS_RESEND;
409
	}
411
	}
410
    return($self->{handler}->($self, $server));  # FIXME
412
    return($self->{handler}->($self, $server));  # FIXME
411
	# FIXME: Use of uninitialized value in subroutine entry
413
	# FIXME: Use of uninitialized value in subroutine entry
412
- 

Return to bug 7787