From c56011e693a3fa25c615b8433eab444329b7b9e0 Mon Sep 17 00:00:00 2001 From: Adrien Saurat Date: Wed, 20 Mar 2013 12:06:00 +0100 Subject: [PATCH] Bug 9865: SIP msg encoding configurable via SIPconfig.xml The accounts->login tag in SIPconfig.xml can now accept a new parameter, "encoding". It will be mostly used to encore to utf8. For this, simply add the parameter: encoding="utf8" --- C4/SIP/Sip.pm | 10 ++++++++-- C4/SIP/Sip/MsgType.pm | 34 +++++++++++++++++----------------- etc/SIPconfig.xml | 4 ++-- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/C4/SIP/Sip.pm b/C4/SIP/Sip.pm index 9d9bd57..52bf876 100644 --- a/C4/SIP/Sip.pm +++ b/C4/SIP/Sip.pm @@ -7,6 +7,7 @@ package Sip; use strict; use warnings; use Exporter; +use Encode; use Sys::Syslog qw(syslog); use POSIX qw(strftime); @@ -209,14 +210,19 @@ sub read_SIP_packet { # sub write_msg { - my ($self, $msg, $file, $terminator) = @_; + my ($self, $msg, $file, $terminator, $encoding) = @_; $terminator ||= q{}; $terminator = ( $terminator eq 'CR' ) ? $CR : $CRLF; + $encoding ||= q{}; + my $cksum; - # $msg = encode_utf8($msg); + if ($encoding ne '') { + $msg = encode($encoding, $msg); + } + if ($error_detection) { if (defined($self->{seqno})) { $msg .= 'AY' . $self->{seqno}; diff --git a/C4/SIP/Sip/MsgType.pm b/C4/SIP/Sip/MsgType.pm index a6af767..040b9df 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,undef,$server->{account}->{terminator}); + $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); return (PATRON_STATUS_REQ); } @@ -604,7 +604,7 @@ sub handle_checkout { } } - $self->write_msg($resp,undef,$server->{account}->{terminator}); + $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); 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,undef,$server->{account}->{terminator}); + $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); return(CHECKIN); } @@ -736,7 +736,7 @@ sub handle_block_patron { } $resp = build_patron_status($patron, $patron->language, $fields); - $self->write_msg($resp,undef,$server->{account}->{terminator}); + $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); 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,undef,$server->{account}->{terminator}); + $self->write_msg(REQUEST_SC_RESEND,undef,$server->{account}->{terminator},$server->{account}->{encoding}); } 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,undef,$server->{account}->{terminator}); + $self->write_msg($rebuilt,undef,$server->{account}->{terminator},$server->{account}->{encoding}); } return REQUEST_ACS_RESEND; @@ -866,7 +866,7 @@ sub handle_login { } else { $status = login_core($server,$uid,$pwd); } - $self->write_msg(LOGIN_RESP . $status,undef,$server->{account}->{terminator}); + $self->write_msg(LOGIN_RESP . $status,undef,$server->{account}->{terminator},$server->{account}->{encoding}); return $status ? LOGIN : ''; } @@ -1012,7 +1012,7 @@ sub handle_patron_info { } } - $self->write_msg($resp,undef,$server->{account}->{terminator}); + $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); 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,undef,$server->{account}->{terminator}); + $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); 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,undef,$server->{account}->{terminator}); + $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); return(FEE_PAID); } @@ -1140,7 +1140,7 @@ sub handle_item_information { $resp .= maybe_add(FID_PRINT_LINE, $item->print_line); } - $self->write_msg($resp,undef,$server->{account}->{terminator}); + $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); 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,undef,$server->{account}->{terminator}); + $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); return(ITEM_STATUS_UPDATE); } @@ -1240,7 +1240,7 @@ sub handle_patron_enable { $resp .= add_field(FID_INST_ID, $ils->institution); - $self->write_msg($resp,undef,$server->{account}->{terminator}); + $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); 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,undef,$server->{account}->{terminator}); + $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); 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,undef,$server->{account}->{terminator}); + $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); 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,undef,$server->{account}->{terminator}); + $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); return(RENEW_ALL); } @@ -1555,7 +1555,7 @@ sub send_acs_status { # Do we want to tell the terminal its location? - $self->write_msg($msg,undef,$server->{account}->{terminator}); + $self->write_msg($msg,undef,$server->{account}->{terminator},$server->{account}->{encoding}); return 1; } diff --git a/etc/SIPconfig.xml b/etc/SIPconfig.xml index 37ce187..6e1ddad 100644 --- a/etc/SIPconfig.xml +++ b/etc/SIPconfig.xml @@ -36,8 +36,8 @@ - - + +