From 20e11030e5060bc7eab1734b45e3bd5e4ca0f5e9 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 1 Feb 2013 10:40:50 -0500 Subject: [PATCH] Bug 9531: Make SIP2 message terminator configurable via SIPconfig.xml MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Adrien Saurat Signed-off-by: Chris Cormack Signed-off-by: Galen Charlton (cherry picked from commit 90e2aafeb538f2d5e52fd1d32fce528f72076df8) Signed-off-by: Tomas Cohen Arazi (cherry picked from commit b0474ebcf0a83cbbe8484b95986b350162959188) Signed-off-by: Bernardo Gonzalez Kriegel (cherry picked from commit b0474ebcf0a83cbbe8484b95986b350162959188) --- C4/SIP/Sip.pm | 20 +++++++------------- C4/SIP/Sip/MsgType.pm | 34 +++++++++++++++++----------------- etc/SIPconfig.xml | 2 +- 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/C4/SIP/Sip.pm b/C4/SIP/Sip.pm index 8807df6d6d..8d1fa88fdd 100644 --- a/C4/SIP/Sip.pm +++ b/C4/SIP/Sip.pm @@ -8,7 +8,6 @@ use strict; use warnings; use English; use Exporter; -use Readonly; use Sys::Syslog qw(syslog); use POSIX qw(strftime); @@ -40,15 +39,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 @@ -220,7 +210,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); @@ -236,10 +230,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'"); } diff --git a/C4/SIP/Sip/MsgType.pm b/C4/SIP/Sip/MsgType.pm index 43f48dcf78..6d7ff6f354 100644 --- a/C4/SIP/Sip/MsgType.pm +++ b/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; } diff --git a/etc/SIPconfig.xml b/etc/SIPconfig.xml index f229b9a51b..37ce187c3b 100644 --- a/etc/SIPconfig.xml +++ b/etc/SIPconfig.xml @@ -38,7 +38,7 @@ - + -- 2.39.5