View | Details | Raw Unified | Return to bug 9531
Collapse All | Expand All

(-)a/C4/SIP/Sip.pm (-13 / +7 lines)
Lines 7-13 package Sip; Link Here
7
use strict;
7
use strict;
8
use warnings;
8
use warnings;
9
use Exporter;
9
use Exporter;
10
use Readonly;
11
10
12
use Sys::Syslog qw(syslog);
11
use Sys::Syslog qw(syslog);
13
use POSIX qw(strftime);
12
use POSIX qw(strftime);
Lines 39-53 BEGIN { Link Here
39
our $error_detection = 0;
38
our $error_detection = 0;
40
our $protocol_version = 1;
39
our $protocol_version = 1;
41
our $field_delimiter = '|'; # Protocol Default
40
our $field_delimiter = '|'; # Protocol Default
42
# The message terminator for a SIP message is '\r' in the standard doc
43
# However most sip devices in the wild send a CR LF pair
44
# This is required by Telnet if that is your carrier mechanism
45
# On raw connections it may also be required because the buffer is
46
# only flushed on linefeed and its absence causes enough delay for
47
# client machines to go into an error state
48
# The below works for almost all machines if however you have one
49
# which does not like the additional linefeed change value to $CR
50
Readonly my $msg_terminator => $CRLF;
51
41
52
# We need to keep a copy of the last message we sent to the SC,
42
# We need to keep a copy of the last message we sent to the SC,
53
# in case there's a transmission error and the SC sends us a
43
# in case there's a transmission error and the SC sends us a
Lines 219-225 sub read_SIP_packet { Link Here
219
#
209
#
220
210
221
sub write_msg {
211
sub write_msg {
222
    my ($self, $msg, $file) = @_;
212
    my ($self, $msg, $file, $terminator) = @_;
213
    
214
    $terminator ||= q{};    
215
    $terminator = ( $terminator eq 'CR' ) ? $CR : $CRLF;
216
223
    my $cksum;
217
    my $cksum;
224
218
225
    # $msg = encode_utf8($msg);
219
    # $msg = encode_utf8($msg);
Lines 235-244 sub write_msg { Link Here
235
229
236
    if ($file) {
230
    if ($file) {
237
        $file->autoflush(1);
231
        $file->autoflush(1);
238
        print $file $msg, $msg_terminator;
232
        print $file $msg, $terminator;
239
    } else {
233
    } else {
240
        STDOUT->autoflush(1);
234
        STDOUT->autoflush(1);
241
        print $msg, $msg_terminator;
235
        print $msg, $terminator;
242
        syslog("LOG_INFO", "OUTPUT MSG: '$msg'");
236
        syslog("LOG_INFO", "OUTPUT MSG: '$msg'");
243
    }
237
    }
244
238
(-)a/C4/SIP/Sip/MsgType.pm (-17 / +17 lines)
Lines 486-492 sub handle_patron_status { Link Here
486
    $ils->check_inst_id($fields->{(FID_INST_ID)}, "handle_patron_status");
486
    $ils->check_inst_id($fields->{(FID_INST_ID)}, "handle_patron_status");
487
    $patron = $ils->find_patron($fields->{(FID_PATRON_ID)});
487
    $patron = $ils->find_patron($fields->{(FID_PATRON_ID)});
488
    $resp = build_patron_status($patron, $lang, $fields);
488
    $resp = build_patron_status($patron, $lang, $fields);
489
    $self->write_msg($resp);
489
    $self->write_msg($resp,undef,$server->{account}->{terminator});
490
    return (PATRON_STATUS_REQ);
490
    return (PATRON_STATUS_REQ);
491
}
491
}
492
492
Lines 604-610 sub handle_checkout { Link Here
604
	}
604
	}
605
    }
605
    }
606
606
607
    $self->write_msg($resp);
607
    $self->write_msg($resp,undef,$server->{account}->{terminator});
608
    return(CHECKOUT);
608
    return(CHECKOUT);
609
}
609
}
610
610
Lines 692-698 sub handle_checkin { Link Here
692
    $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
692
    $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
693
    $resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
693
    $resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
694
694
695
    $self->write_msg($resp);
695
    $self->write_msg($resp,undef,$server->{account}->{terminator});
696
696
697
    return(CHECKIN);
697
    return(CHECKIN);
698
}
698
}
Lines 736-742 sub handle_block_patron { Link Here
736
	}
736
	}
737
737
738
    $resp = build_patron_status($patron, $patron->language, $fields);
738
    $resp = build_patron_status($patron, $patron->language, $fields);
739
    $self->write_msg($resp);
739
    $self->write_msg($resp,undef,$server->{account}->{terminator});
740
    return(BLOCK_PATRON);
740
    return(BLOCK_PATRON);
741
}
741
}
742
742
Lines 778-784 sub handle_request_acs_resend { Link Here
778
    if (!$last_response) {
778
    if (!$last_response) {
779
	# We haven't sent anything yet, so respond with a
779
	# We haven't sent anything yet, so respond with a
780
	# REQUEST_SC_RESEND msg (p. 16)
780
	# REQUEST_SC_RESEND msg (p. 16)
781
	$self->write_msg(REQUEST_SC_RESEND);
781
	$self->write_msg(REQUEST_SC_RESEND,undef,$server->{account}->{terminator});
782
    } elsif ((length($last_response) < 9)
782
    } elsif ((length($last_response) < 9)
783
	     || substr($last_response, -9, 2) ne 'AY') {
783
	     || substr($last_response, -9, 2) ne 'AY') {
784
	# When resending a message, we aren't supposed to include
784
	# When resending a message, we aren't supposed to include
Lines 790-796 sub handle_request_acs_resend { Link Here
790
	# Cut out the sequence number and checksum, since the old
790
	# Cut out the sequence number and checksum, since the old
791
	# checksum is wrong for the resent message.
791
	# checksum is wrong for the resent message.
792
	my $rebuilt = substr($last_response, 0, -9);
792
	my $rebuilt = substr($last_response, 0, -9);
793
	$self->write_msg($rebuilt);
793
	$self->write_msg($rebuilt,undef,$server->{account}->{terminator});
794
    }
794
    }
795
795
796
    return REQUEST_ACS_RESEND;
796
    return REQUEST_ACS_RESEND;
Lines 866-872 sub handle_login { Link Here
866
    }
866
    }
867
	else { $status = login_core($server,$uid,$pwd); }
867
	else { $status = login_core($server,$uid,$pwd); }
868
868
869
	$self->write_msg(LOGIN_RESP . $status);
869
	$self->write_msg(LOGIN_RESP . $status,undef,$server->{account}->{terminator});
870
    return $status ? LOGIN : '';
870
    return $status ? LOGIN : '';
871
}
871
}
872
872
Lines 1012-1018 sub handle_patron_info { Link Here
1012
        }
1012
        }
1013
    }
1013
    }
1014
1014
1015
    $self->write_msg($resp);
1015
    $self->write_msg($resp,undef,$server->{account}->{terminator});
1016
    return(PATRON_INFO);
1016
    return(PATRON_INFO);
1017
}
1017
}
1018
1018
Lines 1039-1045 sub handle_end_patron_session { Link Here
1039
    $resp .= maybe_add(FID_SCREEN_MSG, $screen_msg);
1039
    $resp .= maybe_add(FID_SCREEN_MSG, $screen_msg);
1040
    $resp .= maybe_add(FID_PRINT_LINE, $print_line);
1040
    $resp .= maybe_add(FID_PRINT_LINE, $print_line);
1041
1041
1042
    $self->write_msg($resp);
1042
    $self->write_msg($resp,undef,$server->{account}->{terminator});
1043
1043
1044
    return(END_PATRON_SESSION);
1044
    return(END_PATRON_SESSION);
1045
}
1045
}
Lines 1073-1079 sub handle_fee_paid { Link Here
1073
    $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
1073
    $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
1074
    $resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
1074
    $resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
1075
1075
1076
    $self->write_msg($resp);
1076
    $self->write_msg($resp,undef,$server->{account}->{terminator});
1077
1077
1078
    return(FEE_PAID);
1078
    return(FEE_PAID);
1079
}
1079
}
Lines 1140-1146 sub handle_item_information { Link Here
1140
	$resp .= maybe_add(FID_PRINT_LINE, $item->print_line);
1140
	$resp .= maybe_add(FID_PRINT_LINE, $item->print_line);
1141
    }
1141
    }
1142
1142
1143
    $self->write_msg($resp);
1143
    $self->write_msg($resp,undef,$server->{account}->{terminator});
1144
1144
1145
    return(ITEM_INFORMATION);
1145
    return(ITEM_INFORMATION);
1146
}
1146
}
Lines 1189-1195 sub handle_item_status_update { Link Here
1189
    $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
1189
    $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
1190
    $resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
1190
    $resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
1191
1191
1192
    $self->write_msg($resp);
1192
    $self->write_msg($resp,undef,$server->{account}->{terminator});
1193
1193
1194
    return(ITEM_STATUS_UPDATE);
1194
    return(ITEM_STATUS_UPDATE);
1195
}
1195
}
Lines 1240-1246 sub handle_patron_enable { Link Here
1240
1240
1241
    $resp .= add_field(FID_INST_ID, $ils->institution);
1241
    $resp .= add_field(FID_INST_ID, $ils->institution);
1242
1242
1243
    $self->write_msg($resp);
1243
    $self->write_msg($resp,undef,$server->{account}->{terminator});
1244
1244
1245
    return(PATRON_ENABLE);
1245
    return(PATRON_ENABLE);
1246
}
1246
}
Lines 1306-1312 sub handle_hold { Link Here
1306
    $resp .= maybe_add(FID_SCREEN_MSG,  $status->screen_msg);
1306
    $resp .= maybe_add(FID_SCREEN_MSG,  $status->screen_msg);
1307
    $resp .= maybe_add(FID_PRINT_LINE,  $status->print_line);
1307
    $resp .= maybe_add(FID_PRINT_LINE,  $status->print_line);
1308
1308
1309
    $self->write_msg($resp);
1309
    $self->write_msg($resp,undef,$server->{account}->{terminator});
1310
1310
1311
    return(HOLD);
1311
    return(HOLD);
1312
}
1312
}
Lines 1395-1401 sub handle_renew { Link Here
1395
    $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
1395
    $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
1396
    $resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
1396
    $resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
1397
1397
1398
    $self->write_msg($resp);
1398
    $self->write_msg($resp,undef,$server->{account}->{terminator});
1399
1399
1400
    return(RENEW);
1400
    return(RENEW);
1401
}
1401
}
Lines 1445-1451 sub handle_renew_all { Link Here
1445
    $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
1445
    $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
1446
    $resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
1446
    $resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
1447
1447
1448
    $self->write_msg($resp);
1448
    $self->write_msg($resp,undef,$server->{account}->{terminator});
1449
1449
1450
    return(RENEW_ALL);
1450
    return(RENEW_ALL);
1451
}
1451
}
Lines 1555-1561 sub send_acs_status { Link Here
1555
1555
1556
    # Do we want to tell the terminal its location?
1556
    # Do we want to tell the terminal its location?
1557
1557
1558
    $self->write_msg($msg);
1558
    $self->write_msg($msg,undef,$server->{account}->{terminator});
1559
    return 1;
1559
    return 1;
1560
}
1560
}
1561
1561
(-)a/etc/SIPconfig.xml (-2 / +1 lines)
Lines 38-44 Link Here
38
  <accounts>
38
  <accounts>
39
      <login id="term1"  password="term1" delimiter="|" error-detect="enabled" institution="CPL" />
39
      <login id="term1"  password="term1" delimiter="|" error-detect="enabled" institution="CPL" />
40
      <login id="koha"   password="koha"  delimiter="|" error-detect="enabled" institution="kohalibrary" />
40
      <login id="koha"   password="koha"  delimiter="|" error-detect="enabled" institution="kohalibrary" />
41
      <login id="koha2"  password="koha" institution="kohalibrary2" />
41
      <login id="koha2"  password="koha" institution="kohalibrary2" terminator="CR" />
42
      <login id="lpl-sc" password="1234" institution="LPL" />
42
      <login id="lpl-sc" password="1234" institution="LPL" />
43
      <login id="lpl-sc-beacock" password="xyzzy"
43
      <login id="lpl-sc-beacock" password="xyzzy"
44
             delimiter="|" error-detect="enabled" institution="LPL" />
44
             delimiter="|" error-detect="enabled" institution="LPL" />
45
- 

Return to bug 9531