From 42036b659c474f2336b026c37c2742faa322cc95 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 17 Sep 2024 18:28:11 +0000 Subject: [PATCH] Bug 37582: Add ability to for SIP to convert control and separator characters to spaces This came up with a SIP vendor recently - when reading responses they were only getting part of a patron's information. It seemed to have been caused by patrons with multiple restrictions and a new line in the response Test Plan: 1) Add multiple debarments to a patron 2) Run a sip patron information response, note the presence of newlines 3) Apply this patch 4) Add the new option convert_control_characters to your SIP account, set the value to " -- " 5) Restart all the things! 7) Run a sip patron information response, note the newlines have been replaced! --- C4/SIP/Sip.pm | 19 +++++++++---------- C4/SIP/Sip/MsgType.pm | 34 +++++++++++++++++----------------- etc/SIPconfig.xml | 2 ++ 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/C4/SIP/Sip.pm b/C4/SIP/Sip.pm index c29bff282ff..2cf14ad9479 100644 --- a/C4/SIP/Sip.pm +++ b/C4/SIP/Sip.pm @@ -187,11 +187,16 @@ sub boolspace { # sub write_msg { - my ($self, $msg, $file, $terminator, $encoding) = @_; + my ($self, $msg, $server) = @_; + my $terminator = $server->{account}->{terminator}; + my $encoding = $server->{account}->{encoding}; $terminator ||= q{}; $terminator = ( $terminator eq 'CR' ) ? $CR : $CRLF; + my $separator = $server->{account}->{convert_control_characters}; + $msg =~ s/[^[:print:]]/$separator/g; if defined $separator; + $msg = encode($encoding, $msg) if ( $encoding ); my $cksum; @@ -206,15 +211,9 @@ sub write_msg { $msg .= sprintf('%04.4X', $cksum); } - - if ($file) { - $file->autoflush(1); - print $file $msg, $terminator; - } else { - STDOUT->autoflush(1); - print $msg, $terminator; - siplog("LOG_INFO", "OUTPUT MSG: '$msg'"); - } + STDOUT->autoflush(1); + print $msg, $terminator; + siplog("LOG_INFO", "OUTPUT MSG: '$msg'"); $last_response = $msg; } diff --git a/C4/SIP/Sip/MsgType.pm b/C4/SIP/Sip/MsgType.pm index 3c52df30f47..2169ae1b8c2 100644 --- a/C4/SIP/Sip/MsgType.pm +++ b/C4/SIP/Sip/MsgType.pm @@ -505,7 +505,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, $server ); - $self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} ); + $self->write_msg( $resp, $server ); return (PATRON_STATUS_REQ); } @@ -645,7 +645,7 @@ sub handle_checkout { } } - $self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} ); + $self->write_msg( $resp, $server ); return (CHECKOUT); } @@ -744,7 +744,7 @@ sub handle_checkin { $resp .= maybe_add( FID_SCREEN_MSG, $status->screen_msg, $server ); $resp .= maybe_add( FID_PRINT_LINE, $status->print_line, $server ); - $self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} ); + $self->write_msg( $resp, $server ); return (CHECKIN); } @@ -791,7 +791,7 @@ sub handle_block_patron { } $resp = build_patron_status( $patron, $patron->language, $fields, $server ); - $self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} ); + $self->write_msg( $resp, $server ); return (BLOCK_PATRON); } @@ -832,7 +832,7 @@ sub handle_request_acs_resend { # We haven't sent anything yet, so respond with a # REQUEST_SC_RESEND msg (p. 16) - $self->write_msg( REQUEST_SC_RESEND, undef, $server->{account}->{terminator}, $server->{account}->{encoding} ); + $self->write_msg( REQUEST_SC_RESEND, $server ); } elsif ( ( length($last_response) < 9 ) || substr( $last_response, -9, 2 ) ne 'AY' ) { @@ -846,7 +846,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, undef, $server->{account}->{terminator}, $server->{account}->{encoding} ); + $self->write_msg( $rebuilt, $server ); } return REQUEST_ACS_RESEND; @@ -928,7 +928,7 @@ sub handle_login { $status = login_core( $server, $uid, $pwd ); } - $self->write_msg( LOGIN_RESP . $status, undef, $server->{account}->{terminator}, $server->{account}->{encoding} ); + $self->write_msg( LOGIN_RESP . $status, $server ); return $status ? LOGIN : ''; } @@ -1097,7 +1097,7 @@ sub handle_patron_info { $resp .= maybe_add( FID_SCREEN_MSG, INVALID_CARD, $server ); } - $self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} ); + $self->write_msg( $resp, $server ); return (PATRON_INFO); } @@ -1124,7 +1124,7 @@ sub handle_end_patron_session { $resp .= maybe_add( FID_SCREEN_MSG, $screen_msg, $server ); $resp .= maybe_add( FID_PRINT_LINE, $print_line, $server ); - $self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} ); + $self->write_msg( $resp, $server ); return (END_PATRON_SESSION); } @@ -1206,7 +1206,7 @@ sub handle_fee_paid { $resp .= maybe_add( FID_SCREEN_MSG, $status->screen_msg, $server ); $resp .= maybe_add( FID_PRINT_LINE, $status->print_line, $server ); - $self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} ); + $self->write_msg( $resp, $server ); return (FEE_PAID); } @@ -1299,7 +1299,7 @@ sub handle_item_information { $resp .= $item->build_custom_field_string( $server ); } - $self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} ); + $self->write_msg( $resp, $server ); return (ITEM_INFORMATION); } @@ -1349,7 +1349,7 @@ sub handle_item_status_update { $resp .= maybe_add( FID_SCREEN_MSG, $status->screen_msg, $server ); $resp .= maybe_add( FID_PRINT_LINE, $status->print_line, $server ); - $self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} ); + $self->write_msg( $resp, $server ); return (ITEM_STATUS_UPDATE); } @@ -1403,7 +1403,7 @@ sub handle_patron_enable { $resp .= add_field( FID_INST_ID, $ils->institution, $server ); - $self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} ); + $self->write_msg( $resp, $server ); return (PATRON_ENABLE); } @@ -1468,7 +1468,7 @@ sub handle_hold { $resp .= maybe_add( FID_SCREEN_MSG, $status->screen_msg, $server ); $resp .= maybe_add( FID_PRINT_LINE, $status->print_line, $server ); - $self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} ); + $self->write_msg( $resp, $server ); return (HOLD); } @@ -1555,7 +1555,7 @@ sub handle_renew { $resp .= maybe_add( FID_SCREEN_MSG, $status->screen_msg, $server ); $resp .= maybe_add( FID_PRINT_LINE, $status->print_line, $server ); - $self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} ); + $self->write_msg( $resp, $server ); return (RENEW); } @@ -1608,7 +1608,7 @@ sub handle_renew_all { $resp .= maybe_add( FID_SCREEN_MSG, $status->screen_msg, $server ); $resp .= maybe_add( FID_PRINT_LINE, $status->print_line, $server ); - $self->write_msg( $resp, undef, $server->{account}->{terminator}, $server->{account}->{encoding} ); + $self->write_msg( $resp, $server ); return (RENEW_ALL); } @@ -1714,7 +1714,7 @@ sub send_acs_status { # Do we want to tell the terminal its location? - $self->write_msg( $msg, undef, $server->{account}->{terminator}, $server->{account}->{encoding} ); + $self->write_msg( $msg, $server ); return 1; } diff --git a/etc/SIPconfig.xml b/etc/SIPconfig.xml index 356175af123..72467c95f22 100644 --- a/etc/SIPconfig.xml +++ b/etc/SIPconfig.xml @@ -59,6 +59,7 @@ + -- 2.39.3 (Apple Git-146)