From: djfiander Date: Fri, 21 Apr 2006 02:15:43 +0000 (+0000) Subject: Clean up handling of SIP boolean flags, and fix interface to X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=a032e8921859b6949071f470dcd921ae08257517;p=working%2FSIPServer.git Clean up handling of SIP boolean flags, and fix interface to write_msg(). Since it never used the $server parameter, get rid of it, and add an optional $file parameter, so that write_msg() can be use by the test harness. --- diff --git a/ILS/Patron.pm b/ILS/Patron.pm index deae7c4..f4bd188 100644 --- a/ILS/Patron.pm +++ b/ILS/Patron.pm @@ -28,11 +28,11 @@ our %patron_db = ( address => '2 Meadowvale Dr. St Thomas, ON', home_phone => '(519) 555 1234', email_addr => 'djfiander@hotmail.com', - charge_ok => 'Y', - renew_ok => 'Y', - recall_ok => 'N', - hold_ok => 'Y', - card_lost => 'N', + charge_ok => 1, + renew_ok => 1, + recall_ok => 0, + hold_ok => 1, + card_lost => 0, items_charged => 5, claims_returned => 0, fines => 100, @@ -57,10 +57,15 @@ sub new { my $self; if (!exists($patron_db{$patron_id})) { + syslog("DEBUG", "new ILS::Patron(%s): no such patron", $patron_id); return undef; } + $self = $patron_db{$patron_id}; + syslog("DEBUG", "new ILS::Patron(%s): found patron '%s'", $patron_id, + $self->{id}); + bless $self, $type; return $self; } @@ -381,7 +386,7 @@ sub block { my ($self, $card_retained, $blocked_card_msg) = @_; foreach my $field ('charge_ok', 'renew_ok', 'recall_ok', 'hold_ok') { - $self->{$field} = 'N'; + $self->{$field} = 0; } $self->{screen_msg} = $blocked_card_msg || "Card Blocked. Please contact library staff"; @@ -393,7 +398,7 @@ sub enable { my $self = shift; foreach my $field ('charge_ok', 'renew_ok', 'recall_ok', 'hold_ok') { - $self->{$field} = 'Y'; + $self->{$field} = 1; } syslog("DEBUG", "Patron(%s)->enable: charge: %s, renew:%s, recall:%s", diff --git a/Sip.pm b/Sip.pm index a143460..a42b270 100644 --- a/Sip.pm +++ b/Sip.pm @@ -105,21 +105,13 @@ sub add_count { sub denied { my $bool = shift; - if (!$bool || ($bool eq 'N') || $bool eq 'False') { - return 'Y'; - } else { - return ' '; - } + return boolspace(!$bool); } sub sipbool { my $bool = shift; - if (!$bool || ($bool =~/^false|n|no$/i)) { - return('N'); - } else { - return('Y'); - } + return $bool ? 'Y' : 'N'; } # @@ -128,24 +120,23 @@ sub sipbool { sub boolspace { my $bool = shift; - if (!$bool || ($bool eq 'N' || $bool eq 'False')) { - return ' '; - } else { - return 'Y'; - } + return $bool ? 'Y' : ' '; } # -# write_msg($msg, $server) +# write_msg($msg, $file) # # Send $msg to the SC. If error detection is active, then # add the sequence number (if $seqno is non-zero) and checksum # to the message, and save the whole thing as $last_response +# +# If $file is set, then it's a file handle: write to it, otherwise +# just write to the default destination. # sub write_msg { - my ($self, $msg, $server) = @_; + my ($self, $msg, $file) = @_; my $cksum; if ($error_detection) { @@ -159,7 +150,12 @@ sub write_msg { syslog("LOG_DEBUG", "OUTPUT MSG: '$msg'"); - print "$msg\r"; + if ($file) { + print $file "$msg\r"; + } else { + print "$msg\r"; + } + $last_response = $msg; } diff --git a/Sip/MsgType.pm b/Sip/MsgType.pm index 9560bff..c42ec2e 100644 --- a/Sip/MsgType.pm +++ b/Sip/MsgType.pm @@ -491,7 +491,7 @@ sub handle_patron_status { $resp = build_patron_status($patron, $lang, $fields); - $self->write_msg($resp, $server); + $self->write_msg($resp); return (PATRON_STATUS_REQ); } @@ -606,7 +606,7 @@ sub handle_checkout { } } - $self->write_msg($resp, $server); + $self->write_msg($resp); return(CHECKOUT); } @@ -670,7 +670,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, $server); + $self->write_msg($resp); return(CHECKIN); } @@ -720,7 +720,7 @@ sub handle_block_patron { $fields->{(FID_PATRON_PWD)} = $patron->password; $resp = build_patron_status($patron, '000', $fields); - $self->write_msg($resp, $server); + $self->write_msg($resp); return(BLOCK_PATRON); } @@ -754,7 +754,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, $server); + $self->write_msg(REQUEST_SC_RESEND); } elsif ((length($last_response) < 9) || substr($last_response, -9, 2) ne 'AY') { # When resending a message, we aren't supposed to include @@ -768,7 +768,7 @@ sub handle_request_acs_resend { # Cut out the sequence number and checksum, since the old # checksum is wrong for the resent message. $rebuilt = substr($last_response, 0, -9); - $self->write_msg($rebuilt, $server); + $self->write_msg($rebuilt); } return REQUEST_ACS_RESEND; @@ -808,7 +808,7 @@ sub handle_login { $server->{account}->{id}, $server->{account}->{institution}); } - $self->write_msg(LOGIN_RESP . $status, $server); + $self->write_msg(LOGIN_RESP . $status); return $status ? LOGIN : ''; } @@ -932,7 +932,7 @@ sub handle_patron_info { $resp .= add_field(FID_INST_ID, $server->{ils}->institution); - $self->write_msg($resp, $server); + $self->write_msg($resp); return(PATRON_INFO); } @@ -960,7 +960,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, $server); + $self->write_msg($resp); return(END_PATRON_SESSION); } @@ -998,7 +998,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, $server); + $self->write_msg($resp); return(FEE_PAID); } @@ -1065,7 +1065,7 @@ sub handle_item_information { $resp .= maybe_add(FID_PRINT_LINE, $item->print_line); } - $self->write_msg($resp, $server); + $self->write_msg($resp); return(ITEM_INFORMATION); } @@ -1114,7 +1114,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, $server); + $self->write_msg($resp); return(ITEM_STATUS_UPDATE); } @@ -1159,7 +1159,7 @@ sub handle_patron_enable { $resp .= add_field(FID_INST_ID, $ils->institution); - $self->write_msg($resp, $server); + $self->write_msg($resp); return(PATRON_ENABLE); } @@ -1231,7 +1231,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, $server); + $self->write_msg($resp); return(HOLD); } @@ -1313,7 +1313,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, $server); + $self->write_msg($resp); return(RENEW); } @@ -1354,7 +1354,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, $server); + $self->write_msg($resp); return(RENEW_ALL); } @@ -1421,7 +1421,7 @@ sub send_acs_status { # Do we want to tell the terminal its location? - $self->write_msg($msg, $server); + $self->write_msg($msg); return 1; } @@ -1433,6 +1433,8 @@ sub patron_status_string { my $patron = shift; my $patron_status; + syslog("DEBUG", "patron_status_string: %s charge_ok: %s", $patron->id, + $patron->charge_ok); $patron_status = sprintf('%s%s%s%s%s%s%s%s%s%s%s%s%s%s', denied($patron->charge_ok), denied($patron->renew_ok),