Browse Source

Bug 9531: Make SIP2 message terminator configurable via SIPconfig.xml

Add a terminator option to SIPConfig.xml, choices for 'terminator' are
'CR' or 'CRLF'.  The default continues to be 'CRLF' if 'terminator' is
undefined.

Test Plan:
1) Apply patch
2) Start SIP server
3) Run C4/SIP/t/04patron_status.t
4) Stop SIP server
5) Add terminator="CR" for account login 'term1'
6) Run 04patron_status.t again, you should see no change

Signed-off-by: Frédéric Demians <f.demians@tamil.fr>
Signed-off-by: Adrien Saurat <adrien.saurat@biblibre.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
new/bootstrap-opac
Kyle Hall 10 years ago
committed by Galen Charlton
parent
commit
90e2aafeb5
  1. 20
      C4/SIP/Sip.pm
  2. 34
      C4/SIP/Sip/MsgType.pm
  3. 2
      etc/SIPconfig.xml

20
C4/SIP/Sip.pm

@ -7,7 +7,6 @@ package Sip;
use strict;
use warnings;
use Exporter;
use Readonly;
use Sys::Syslog qw(syslog);
use POSIX qw(strftime);
@ -39,15 +38,6 @@ BEGIN {
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
@ -219,7 +209,11 @@ sub read_SIP_packet {
#
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);
@ -235,10 +229,10 @@ sub write_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'");
}

34
C4/SIP/Sip/MsgType.pm

@ -486,7 +486,7 @@ sub handle_patron_status {
$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);
}
@ -604,7 +604,7 @@ sub handle_checkout {
}
}
$self->write_msg($resp);
$self->write_msg($resp,undef,$server->{account}->{terminator});
return(CHECKOUT);
}
@ -692,7 +692,7 @@ sub handle_checkin {
$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);
}
@ -736,7 +736,7 @@ sub handle_block_patron {
}
$resp = build_patron_status($patron, $patron->language, $fields);
$self->write_msg($resp);
$self->write_msg($resp,undef,$server->{account}->{terminator});
return(BLOCK_PATRON);
}
@ -778,7 +778,7 @@ sub handle_request_acs_resend {
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
@ -790,7 +790,7 @@ sub handle_request_acs_resend {
# 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;
@ -866,7 +866,7 @@ sub handle_login {
}
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 : '';
}
@ -1012,7 +1012,7 @@ sub handle_patron_info {
}
}
$self->write_msg($resp);
$self->write_msg($resp,undef,$server->{account}->{terminator});
return(PATRON_INFO);
}
@ -1039,7 +1039,7 @@ sub handle_end_patron_session {
$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);
}
@ -1073,7 +1073,7 @@ sub handle_fee_paid {
$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);
}
@ -1140,7 +1140,7 @@ sub handle_item_information {
$resp .= maybe_add(FID_PRINT_LINE, $item->print_line);
}
$self->write_msg($resp);
$self->write_msg($resp,undef,$server->{account}->{terminator});
return(ITEM_INFORMATION);
}
@ -1189,7 +1189,7 @@ sub handle_item_status_update {
$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);
}
@ -1240,7 +1240,7 @@ sub handle_patron_enable {
$resp .= add_field(FID_INST_ID, $ils->institution);
$self->write_msg($resp);
$self->write_msg($resp,undef,$server->{account}->{terminator});
return(PATRON_ENABLE);
}
@ -1306,7 +1306,7 @@ sub handle_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(HOLD);
}
@ -1395,7 +1395,7 @@ sub handle_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);
}
@ -1445,7 +1445,7 @@ sub handle_renew_all {
$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);
}
@ -1555,7 +1555,7 @@ sub send_acs_status {
# Do we want to tell the terminal its location?
$self->write_msg($msg);
$self->write_msg($msg,undef,$server->{account}->{terminator});
return 1;
}

2
etc/SIPconfig.xml

@ -38,7 +38,7 @@
<accounts>
<login id="term1" password="term1" delimiter="|" error-detect="enabled" institution="CPL" />
<login id="koha" password="koha" delimiter="|" error-detect="enabled" institution="kohalibrary" />
<login id="koha2" password="koha" institution="kohalibrary2" />
<login id="koha2" password="koha" institution="kohalibrary2" terminator="CR" />
<login id="lpl-sc" password="1234" institution="LPL" />
<login id="lpl-sc-beacock" password="xyzzy"
delimiter="|" error-detect="enabled" institution="LPL" />

Loading…
Cancel
Save