From 61e610f2523589f91d1e0d5e889634a0c05f0d1b Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Tue, 16 Jun 2015 14:33:52 -0400 Subject: [PATCH] LP 1463943: Encode output messages. This commit adds support for an encoding attribute that can be added to accounts in the configuration file. When set, SIPServer will encode response messages in the specified encoding. Valid encodings are those listed in the Encode::Supported man page. This feature is useful if you have a vendor who cannot support the default UTF-8 output by SIPServer. An example is provided in SIPConfig.xml. The lpl-sc account has been set to use the ascii encoding. This particular code was mostly taken from a patch to Koha's SIPServer by Adrien Saurat , Christophe Croullebois , and others. http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=9865 Signed-off-by: Jason Stephenson Signed-off-by: Martha Driscoll --- SIPconfig.xml | 2 +- Sip.pm | 8 ++++++-- Sip/MsgType.pm | 37 +++++++++++++++++++++++-------------- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/SIPconfig.xml b/SIPconfig.xml index 180f4d4..c2038a7 100644 --- a/SIPconfig.xml +++ b/SIPconfig.xml @@ -63,7 +63,7 @@ - + diff --git a/Sip.pm b/Sip.pm index d9f14c4..d800f57 100644 --- a/Sip.pm +++ b/Sip.pm @@ -219,7 +219,7 @@ sub read_SIP_packet { } # -# write_msg($msg, $file) +# write_msg($msg, $file, $encoding) # # Send $msg to the SC. If error detection is active, then # add the sequence number (if $seqno is non-zero) and checksum @@ -228,9 +228,13 @@ sub read_SIP_packet { # If $file is set, then it's a file handle: write to it, otherwise # just write to the default destination. # +# If encoding is set, the message will be encoded to that encoding. +# sub write_msg { - my ($self, $msg, $file) = @_; + my ($self, $msg, $file, $encoding) = @_; + + $msg = encode($encoding, $msg) if ($encoding); if ($error_detection) { if (defined($self->{seqno})) { diff --git a/Sip/MsgType.pm b/Sip/MsgType.pm index 4079467..684fa76 100644 --- a/Sip/MsgType.pm +++ b/Sip/MsgType.pm @@ -520,7 +520,7 @@ sub handle_patron_status { $resp = build_patron_status($patron, $lang, $fields, $server); - $self->write_msg($resp); + $self->write_msg($resp, undef, $account->{encoding}); return (PATRON_STATUS_REQ); } @@ -643,7 +643,7 @@ sub handle_checkout { } } - $self->write_msg($resp); + $self->write_msg($resp, undef, $account->{encoding}); return(CHECKOUT); } @@ -716,7 +716,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, $account->{encoding}); return(CHECKIN); } @@ -763,7 +763,7 @@ sub handle_block_patron { $resp = build_patron_status($patron, $language, $fields, $server); - $self->write_msg($resp); + $self->write_msg($resp, undef, $account->{encoding}); return(BLOCK_PATRON); } @@ -974,6 +974,7 @@ sub summary_info { sub handle_patron_info { my ($self, $server) = @_; my $ils = $server->{ils}; + my $account = $server->{account}; my ($lang, $trans_date, $summary) = @{$self->{fixed_fields}}; my $fields = $self->{fields}; my ($inst_id, $patron_id, $terminal_pwd, $patron_pwd, $start, $end); @@ -1082,7 +1083,7 @@ sub handle_patron_info { } } - $self->write_msg($resp); + $self->write_msg($resp, undef, $account->{encoding}); return(PATRON_INFO); } @@ -1090,6 +1091,7 @@ sub handle_patron_info { sub handle_end_patron_session { my ($self, $server) = @_; my $ils = $server->{ils}; + my $account = $server->{account}; my $trans_date; my $fields = $self->{fields}; my $resp = END_SESSION_RESP; @@ -1110,7 +1112,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, $account->{encoding}); return(END_PATRON_SESSION); } @@ -1118,6 +1120,7 @@ sub handle_end_patron_session { sub handle_fee_paid { my ($self, $server) = @_; my $ils = $server->{ils}; + my $account = $server->{account}; my ($trans_date, $fee_type, $pay_type, $currency) = @{$self->{fixed_fields}}; my $fields = $self->{fields}; my ($fee_amt, $inst_id, $patron_id, $terminal_pwd, $patron_pwd); @@ -1144,7 +1147,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, $account->{encoding}); return(FEE_PAID); } @@ -1152,6 +1155,7 @@ sub handle_fee_paid { sub handle_item_information { my ($self, $server) = @_; my $ils = $server->{ils}; + my $account = $server->{account}; my $trans_date; my $fields = $self->{fields}; my $resp = ITEM_INFO_RESP; @@ -1212,7 +1216,7 @@ sub handle_item_information { } } - $self->write_msg($resp); + $self->write_msg($resp, undef, $account->{encoding}); return(ITEM_INFORMATION); } @@ -1220,6 +1224,7 @@ sub handle_item_information { sub handle_item_status_update { my ($self, $server) = @_; my $ils = $server->{ils}; + my $account = $server->{account}; my ($trans_date, $item_id, $terminal_pwd, $item_props); my $fields = $self->{fields}; my $status; @@ -1259,7 +1264,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, $account->{encoding}); return(ITEM_STATUS_UPDATE); } @@ -1267,6 +1272,7 @@ sub handle_item_status_update { sub handle_patron_enable { my ($self, $server) = @_; my $ils = $server->{ils}; + my $account = $server->{account}; my $fields = $self->{fields}; my ($trans_date, $patron_id, $terminal_pwd, $patron_pwd); my ($status, $patron); @@ -1310,7 +1316,7 @@ sub handle_patron_enable { $resp .= add_field(FID_INST_ID, $ils->institution); - $self->write_msg($resp); + $self->write_msg($resp, undef, $account->{encoding}); return(PATRON_ENABLE); } @@ -1318,6 +1324,7 @@ sub handle_patron_enable { sub handle_hold { my ($self, $server) = @_; my $ils = $server->{ils}; + my $account = $server->{account}; my ($hold_mode, $trans_date); my ($expiry_date, $pickup_locn, $hold_type, $patron_id, $patron_pwd); my ($item_id, $title_id, $fee_ack); @@ -1382,7 +1389,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, $account->{encoding}); return(HOLD); } @@ -1390,6 +1397,7 @@ sub handle_hold { sub handle_renew { my ($self, $server) = @_; my $ils = $server->{ils}; + my $account = $server->{account}; my ($third_party, $no_block, $trans_date, $nb_due_date); my ($patron_id, $patron_pwd, $item_id, $title_id, $item_props, $fee_ack); my $fields = $self->{fields}; @@ -1466,7 +1474,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, $account->{encoding}); return(RENEW); } @@ -1474,6 +1482,7 @@ sub handle_renew { sub handle_renew_all { my ($self, $server) = @_; my $ils = $server->{ils}; + my $account = $server->{account}; my ($trans_date, $patron_id, $patron_pwd, $terminal_pwd, $fee_ack); my $fields = $self->{fields}; my $resp = RENEW_ALL_RESP; @@ -1514,7 +1523,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, $account->{encoding}); return(RENEW_ALL); } @@ -1618,7 +1627,7 @@ sub send_acs_status { # Do we want to tell the terminal its location? - $self->write_msg($msg); + $self->write_msg($msg, undef, $account->{encoding}); return 1; } -- 2.11.0