use strict;
use warnings;
use Exporter;
-use Readonly;
use Sys::Syslog qw(syslog);
use POSIX qw(strftime);
our $error_detection = 0;
our $protocol_version = 1;
our $field_delimiter = '|'; # Protocol Default
-# The message terminator for a SIP message is '\r' in the standard doc
-# However most sip devices in the wild send a CR LF pair
-# This is required by Telnet if that is your carrier mechanism
-# On raw connections it may also be required because the buffer is
-# only flushed on linefeed and its absence causes enough delay for
-# client machines to go into an error state
-# The below works for almost all machines if however you have one
-# which does not like the additional linefeed change value to $CR
-Readonly my $msg_terminator => $CRLF;
# We need to keep a copy of the last message we sent to the SC,
# in case there's a transmission error and the SC sends us a
#
sub write_msg {
- my ($self, $msg, $file) = @_;
+ my ($self, $msg, $file, $terminator) = @_;
+
+ $terminator ||= q{};
+ $terminator = ( $terminator eq 'CR' ) ? $CR : $CRLF;
+
my $cksum;
# $msg = encode_utf8($msg);
if ($file) {
$file->autoflush(1);
- print $file $msg, $msg_terminator;
+ print $file $msg, $terminator;
} else {
STDOUT->autoflush(1);
- print $msg, $msg_terminator;
+ print $msg, $terminator;
syslog("LOG_INFO", "OUTPUT MSG: '$msg'");
}
$ils->check_inst_id($fields->{(FID_INST_ID)}, "handle_patron_status");
$patron = $ils->find_patron($fields->{(FID_PATRON_ID)});
$resp = build_patron_status($patron, $lang, $fields);
- $self->write_msg($resp);
+ $self->write_msg($resp,undef,$server->{account}->{terminator});
return (PATRON_STATUS_REQ);
}
}
}
- $self->write_msg($resp);
+ $self->write_msg($resp,undef,$server->{account}->{terminator});
return(CHECKOUT);
}
$resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
$resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
- $self->write_msg($resp);
+ $self->write_msg($resp,undef,$server->{account}->{terminator});
return(CHECKIN);
}
}
$resp = build_patron_status($patron, $patron->language, $fields);
- $self->write_msg($resp);
+ $self->write_msg($resp,undef,$server->{account}->{terminator});
return(BLOCK_PATRON);
}
if (!$last_response) {
# We haven't sent anything yet, so respond with a
# REQUEST_SC_RESEND msg (p. 16)
- $self->write_msg(REQUEST_SC_RESEND);
+ $self->write_msg(REQUEST_SC_RESEND,undef,$server->{account}->{terminator});
} elsif ((length($last_response) < 9)
|| substr($last_response, -9, 2) ne 'AY') {
# When resending a message, we aren't supposed to include
# Cut out the sequence number and checksum, since the old
# checksum is wrong for the resent message.
my $rebuilt = substr($last_response, 0, -9);
- $self->write_msg($rebuilt);
+ $self->write_msg($rebuilt,undef,$server->{account}->{terminator});
}
return REQUEST_ACS_RESEND;
}
else { $status = login_core($server,$uid,$pwd); }
- $self->write_msg(LOGIN_RESP . $status);
+ $self->write_msg(LOGIN_RESP . $status,undef,$server->{account}->{terminator});
return $status ? LOGIN : '';
}
}
}
- $self->write_msg($resp);
+ $self->write_msg($resp,undef,$server->{account}->{terminator});
return(PATRON_INFO);
}
$resp .= maybe_add(FID_SCREEN_MSG, $screen_msg);
$resp .= maybe_add(FID_PRINT_LINE, $print_line);
- $self->write_msg($resp);
+ $self->write_msg($resp,undef,$server->{account}->{terminator});
return(END_PATRON_SESSION);
}
$resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
$resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
- $self->write_msg($resp);
+ $self->write_msg($resp,undef,$server->{account}->{terminator});
return(FEE_PAID);
}
$resp .= maybe_add(FID_PRINT_LINE, $item->print_line);
}
- $self->write_msg($resp);
+ $self->write_msg($resp,undef,$server->{account}->{terminator});
return(ITEM_INFORMATION);
}
$resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
$resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
- $self->write_msg($resp);
+ $self->write_msg($resp,undef,$server->{account}->{terminator});
return(ITEM_STATUS_UPDATE);
}
$resp .= add_field(FID_INST_ID, $ils->institution);
- $self->write_msg($resp);
+ $self->write_msg($resp,undef,$server->{account}->{terminator});
return(PATRON_ENABLE);
}
$resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
$resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
- $self->write_msg($resp);
+ $self->write_msg($resp,undef,$server->{account}->{terminator});
return(HOLD);
}
$resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
$resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
- $self->write_msg($resp);
+ $self->write_msg($resp,undef,$server->{account}->{terminator});
return(RENEW);
}
$resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
$resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
- $self->write_msg($resp);
+ $self->write_msg($resp,undef,$server->{account}->{terminator});
return(RENEW_ALL);
}
# Do we want to tell the terminal its location?
- $self->write_msg($msg);
+ $self->write_msg($msg,undef,$server->{account}->{terminator});
return 1;
}