From: djfiander Date: Fri, 8 Jan 2010 23:46:07 +0000 (+0000) Subject: Various utf8 fixes X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=d19d5be09cd0a1a5723064bc895a145095cbaf98;p=working%2FSIPServer.git Various utf8 fixes --- diff --git a/ILS.pm b/ILS.pm index 4a16c3b..81e3615 100644 --- a/ILS.pm +++ b/ILS.pm @@ -24,6 +24,7 @@ package ILS; use warnings; use strict; use Sys::Syslog qw(syslog); +use Encode; use ILS::Item; use ILS::Patron; @@ -177,7 +178,7 @@ sub checkout { $circ->desensitize(!$item->magnetic); syslog("LOG_DEBUG", "ILS::Checkout: patron %s has checked out %s", - $patron_id, join(', ', @{$patron->{items}})); + $patron_id, join(', ', encode_utf8(@{$patron->{items}}))); } # END TRANSACTION diff --git a/ILS/Item.pm b/ILS/Item.pm index 1f109f6..333a1e0 100644 --- a/ILS/Item.pm +++ b/ILS/Item.pm @@ -28,6 +28,8 @@ package ILS::Item; use strict; use warnings; +use Encode; + use Sys::Syslog qw(syslog); use ILS::Transaction; @@ -48,7 +50,7 @@ our %item_db = ( hold_queue => [], }, '660' => { - title => "Harry Potter y el cáliz de fuego ", + title => decode_utf8('Harry Potter y el cáliz de fuego'), id => '660', sip_media_type => '001', magnetic_media => 0, @@ -71,7 +73,7 @@ sub new { bless $self, $type; syslog("LOG_DEBUG", "new ILS::Item('%s'): found with title '%s'", - $item_id, $self->{title}); + $item_id, encode_utf8($self->{title})); return $self; } @@ -188,7 +190,11 @@ sub hold_queue_position { sub due_date { my $self = shift; - return $self->{due_date} || 0; + if ($self->{due_date}) { + return Sip::timestamp($self->{due_date}); + } else { + return 0; + } } sub recall_date { diff --git a/ILS/Transaction/Checkout.pm b/ILS/Transaction/Checkout.pm index ae949b4..b042bbb 100644 --- a/ILS/Transaction/Checkout.pm +++ b/ILS/Transaction/Checkout.pm @@ -26,6 +26,8 @@ use warnings; use strict; use POSIX qw(strftime); +use Sip::Constants qw(SIP_DATETIME); + use ILS; use ILS::Transaction; @@ -49,7 +51,8 @@ sub new { } @{$self}{keys %fields} = values %fields; - $self->{'due'} = time() + (60*60*24*14); # two weeks hence + $self->{'due'} = strftime(SIP_DATETIME, + localtime(time() + (60*60*24*14))); # two weeks hence return bless $self, $class; } diff --git a/Sip.pm b/Sip.pm index 68379c1..9bac051 100644 --- a/Sip.pm +++ b/Sip.pm @@ -26,6 +26,7 @@ use strict; use warnings; use English; use Exporter; +use Encode; use Sys::Syslog qw(syslog); use POSIX qw(strftime); @@ -177,7 +178,7 @@ sub read_SIP_packet { # on the input. # $record =~ s/^\012// if $record; - syslog("LOG_INFO", "INPUT MSG: '$record'") if $record; + syslog("LOG_INFO", encode_utf8("INPUT MSG: '$record'")) if $record; return $record; } @@ -210,7 +211,7 @@ sub write_msg { print $file "$msg\r"; } else { print "$msg\r"; - syslog("LOG_INFO", "OUTPUT MSG: '$msg'"); + syslog("LOG_INFO", encode_utf8("OUTPUT MSG: '$msg'")); } $last_response = $msg; diff --git a/Sip/Checksum.pm b/Sip/Checksum.pm index 5840d38..8d18ddd 100644 --- a/Sip/Checksum.pm +++ b/Sip/Checksum.pm @@ -1,74 +1,74 @@ -# -# Copyright (C) 2006-2008 Georgia Public Library Service -# -# Author: David J. Fiander -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of version 2 of the GNU General Public -# License as published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public -# License along with this program; if not, write to the Free -# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, -# MA 02111-1307 USA - -package Sip::Checksum; - -use Exporter; -use strict; -use warnings; - -our @ISA = qw(Exporter); -our @EXPORT_OK = qw(checksum verify_cksum); - -sub checksum { - my $pkt = shift; - - return (-unpack('%16C*', $pkt) & 0xFFFF); -} - -sub verify_cksum { - my $pkt = shift; - my $cksum; - my $shortsum; - - return 0 if (substr($pkt, -6, 2) ne "AZ"); # No checksum at end - - # Convert the checksum back to hex and calculate the sum of the - # pack without the checksum. - $cksum = hex(substr($pkt, -4)); - $shortsum = unpack("%16U*", substr($pkt, 0, -4)); - - # The checksum is valid if the hex sum, plus the checksum of the - # base packet short when truncated to 16 bits. - return (($cksum + $shortsum) & 0xFFFF) == 0; -} - -{ - no warnings qw(once); - eval join('',) || die $@ unless caller(); -} -__END__ - -# -# Some simple test data -# -sub test { - my $testpkt = shift; - my $cksum = checksum($testpkt); - my $fullpkt = sprintf("%s%4X", $testpkt, $cksum); - - print $fullpkt, "\n"; -} - -while (<>) { - chomp; - test($_); -} - -1; +# +# Copyright (C) 2006-2008 Georgia Public Library Service +# +# Author: David J. Fiander +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of version 2 of the GNU General Public +# License as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the Free +# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA + +package Sip::Checksum; + +use Exporter; +use strict; +use warnings; + +our @ISA = qw(Exporter); +our @EXPORT_OK = qw(checksum verify_cksum); + +sub checksum { + my $pkt = shift; + + return (-unpack('%16C*', $pkt) & 0xFFFF); +} + +sub verify_cksum { + my $pkt = shift; + my $cksum; + my $shortsum; + + return 0 if (substr($pkt, -6, 2) ne "AZ"); # No checksum at end + + # Convert the checksum back to hex and calculate the sum of the + # pack without the checksum. + $cksum = hex(substr($pkt, -4)); + $shortsum = unpack("%16C*", substr($pkt, 0, -4)); + + # The checksum is valid if the hex sum, plus the checksum of the + # base packet short when truncated to 16 bits. + return (($cksum + $shortsum) & 0xFFFF) == 0; +} + +{ + no warnings qw(once); + eval join('',) || die $@ unless caller(); +} +__END__ + +# +# Some simple test data +# +sub test { + my $testpkt = shift; + my $cksum = checksum($testpkt); + my $fullpkt = sprintf("%s%4X", $testpkt, $cksum); + + print $fullpkt, "\n"; +} + +while (<>) { + chomp; + test($_); +} + +1; diff --git a/t/SIPtest.pm b/t/SIPtest.pm index 41e3132..4eed28b 100644 --- a/t/SIPtest.pm +++ b/t/SIPtest.pm @@ -47,6 +47,8 @@ our @EXPORT_OK = qw(run_sip_tests no_tagged_fields use Test::More; use IO::Socket::INET; +use Encode; + use Sip qw(:all); use Sip::Checksum qw(verify_cksum); use Sip::Constants qw(:all); @@ -89,7 +91,7 @@ our $item2_owner = 'UWOLS'; # An item with a diacritical in the title our $item_diacritic_barcode = '660'; -our $item_diacritic_title = 'Harry Potter y el cáliz de fuego'; +our $item_diacritic_title = decode_utf8('Harry Potter y el cáliz de fuego'); our $item_diacritic_owner = 'UWOLS'; # End configuration @@ -204,7 +206,7 @@ sub one_msg { return; } - if (exists($fields{$field}) && ($fields{$field} !~ $ftest->{pat})) { + if (exists($fields{$field}) && (decode_utf8($fields{$field}) !~ $ftest->{pat})) { fail("$test->{id} field test $field"); diag("Field pattern '$ftest->{pat}' for '$field' doesn't match in '$resp'");