Bug 9531: Make SIP2 message terminator configurable via SIPconfig.xml
authorKyle M Hall <kyle@bywatersolutions.com>
Fri, 1 Feb 2013 15:40:50 +0000 (10:40 -0500)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 20 Dec 2013 13:49:03 +0000 (08:49 -0500)
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>
(cherry picked from commit 90e2aafeb538f2d5e52fd1d32fce528f72076df8)
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
(cherry picked from commit b0474ebcf0a83cbbe8484b95986b350162959188)
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
(cherry picked from commit b0474ebcf0a83cbbe8484b95986b350162959188)
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
(cherry picked from commit 20e11030e5060bc7eab1734b45e3bd5e4ca0f5e9)

C4/SIP/Sip.pm
C4/SIP/Sip/MsgType.pm
etc/SIPconfig.xml

index 5f5c130..6d16678 100644 (file)
@@ -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
@@ -228,7 +218,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);
@@ -244,10 +238,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'");
     }
 
index 62f9280..cd4fd00 100644 (file)
@@ -484,7 +484,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);
 }
 
@@ -602,7 +602,7 @@ sub handle_checkout {
        }
     }
 
-    $self->write_msg($resp);
+    $self->write_msg($resp,undef,$server->{account}->{terminator});
     return(CHECKOUT);
 }
 
@@ -690,7 +690,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);
 }
@@ -734,7 +734,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);
 }
 
@@ -776,7 +776,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
@@ -788,7 +788,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;
@@ -864,7 +864,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 : '';
 }
 
@@ -1010,7 +1010,7 @@ sub handle_patron_info {
         }
     }
 
-    $self->write_msg($resp);
+    $self->write_msg($resp,undef,$server->{account}->{terminator});
     return(PATRON_INFO);
 }
 
@@ -1037,7 +1037,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);
 }
@@ -1071,7 +1071,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);
 }
@@ -1138,7 +1138,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);
 }
@@ -1187,7 +1187,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);
 }
@@ -1238,7 +1238,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);
 }
@@ -1304,7 +1304,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);
 }
@@ -1393,7 +1393,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);
 }
@@ -1443,7 +1443,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);
 }
@@ -1553,7 +1553,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;
 }
 
index f229b9a..37ce187 100644 (file)
@@ -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" />