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 = ''; |