From 86a6a5f35f2e0b6f410062a5b1859176ec0e53c2 Mon Sep 17 00:00:00 2001 From: Adrien Saurat Date: Fri, 8 Nov 2013 11:49:56 +0100 Subject: [PATCH] Bug 9865: make 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 encode to utf8. For this, simply add the parameter: encoding="utf8" Signed-off-by: Chris Cormack Works as advertised, does nothing if encoding is not set. Blows up all the machines that can't handled utf8 if it is set :) But that's not Koha's fault. :) Patch rebased by Christophe Croullebois Signed-off-by: Petter Goksoyr Asen But now I did it the right way! And I can confirm that this patch solves all issues with mangled characters in SIP messages. Confirmed that it looks good with Norwegian characters in patron name and in book titles. Signed-off-by: Kyle M Hall Signed-off-by: Galen Charlton (cherry picked from commit 4a72f6b2375895c690dcaaaff26b07de53cfd518) Signed-off-by: Fridolin Somers --- C4/SIP/Sip.pm | 6 ++++-- C4/SIP/Sip/MsgType.pm | 34 +++++++++++++++++----------------- etc/SIPconfig.xml | 4 ++-- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/C4/SIP/Sip.pm b/C4/SIP/Sip.pm index f407634a73..b6f1916ac9 100644 --- a/C4/SIP/Sip.pm +++ b/C4/SIP/Sip.pm @@ -7,7 +7,7 @@ package Sip; use strict; use warnings; use Exporter; - +use Encode; use Sys::Syslog qw(syslog); use POSIX qw(strftime); use Socket qw(:crlf); @@ -209,11 +209,13 @@ 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; + $msg = encode($encoding, $msg) if ( $encoding ); + my $cksum; # $msg = encode_utf8($msg); diff --git a/C4/SIP/Sip/MsgType.pm b/C4/SIP/Sip/MsgType.pm index 17185e0012..fceb16b302 100644 --- a/C4/SIP/Sip/MsgType.pm +++ b/C4/SIP/Sip/MsgType.pm @@ -490,7 +490,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}); + $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); return (PATRON_STATUS_REQ); } @@ -608,7 +608,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); } @@ -696,7 +696,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); } @@ -740,7 +740,7 @@ sub handle_block_patron { } $resp = build_patron_status( $patron, $patron->language, $fields, $server ); - $self->write_msg($resp,undef,$server->{account}->{terminator}); + $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); return(BLOCK_PATRON); } @@ -782,7 +782,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 @@ -794,7 +794,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; @@ -870,7 +870,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 : ''; } @@ -1019,7 +1019,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); } @@ -1046,7 +1046,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); } @@ -1080,7 +1080,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); } @@ -1147,7 +1147,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); } @@ -1196,7 +1196,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); } @@ -1247,7 +1247,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); } @@ -1313,7 +1313,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); } @@ -1402,7 +1402,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); } @@ -1452,7 +1452,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); } @@ -1562,7 +1562,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 bd464e2dac..6da9c0136d 100644 --- a/etc/SIPconfig.xml +++ b/etc/SIPconfig.xml @@ -36,8 +36,8 @@ - - + +