|
Lines 5-23
use strict;
Link Here
|
| 5 |
use warnings; |
5 |
use warnings; |
| 6 |
use FindBin qw($Bin); |
6 |
use FindBin qw($Bin); |
| 7 |
use lib "$Bin"; |
7 |
use lib "$Bin"; |
| 8 |
use Sys::Syslog qw(syslog); |
|
|
| 9 |
use Net::Server::PreFork; |
8 |
use Net::Server::PreFork; |
| 10 |
use IO::Socket::INET; |
9 |
use IO::Socket::INET; |
| 11 |
use Socket qw(:DEFAULT :crlf); |
10 |
use Socket qw(:DEFAULT :crlf); |
|
|
11 |
use Scalar::Util qw(blessed); |
| 12 |
require UNIVERSAL::require; |
12 |
require UNIVERSAL::require; |
| 13 |
|
13 |
|
| 14 |
use C4::Context; |
14 |
use C4::Context; |
|
|
15 |
use C4::SIP::Sip qw(syslog); |
| 15 |
use C4::SIP::Sip::Constants qw(:all); |
16 |
use C4::SIP::Sip::Constants qw(:all); |
| 16 |
use C4::SIP::Sip::Configuration; |
17 |
use C4::SIP::Sip::Configuration; |
| 17 |
use C4::SIP::Sip::Checksum qw(checksum verify_cksum); |
18 |
use C4::SIP::Sip::Checksum qw(checksum verify_cksum); |
| 18 |
use C4::SIP::Sip::MsgType qw( handle login_core ); |
19 |
use C4::SIP::Sip::MsgType qw( handle login_core ); |
| 19 |
use Koha::Caches; |
20 |
use Koha::Caches; |
| 20 |
|
21 |
|
|
|
22 |
use Koha::Logger; |
| 23 |
use C4::SIP::Trapper; |
| 24 |
tie *STDERR, "C4::SIP::Trapper"; |
| 25 |
|
| 21 |
use base qw(Net::Server::PreFork); |
26 |
use base qw(Net::Server::PreFork); |
| 22 |
|
27 |
|
| 23 |
use constant LOG_SIP => "local6"; # Local alias for the logging facility |
28 |
use constant LOG_SIP => "local6"; # Local alias for the logging facility |
|
Lines 81-86
__PACKAGE__ ->run(@parms);
Link Here
|
| 81 |
# Child |
86 |
# Child |
| 82 |
# |
87 |
# |
| 83 |
|
88 |
|
|
|
89 |
my $activeSIPServer; |
| 90 |
my $activeLogger; |
| 91 |
|
| 84 |
# process_request is the callback used by Net::Server to handle |
92 |
# process_request is the callback used by Net::Server to handle |
| 85 |
# an incoming connection request. |
93 |
# an incoming connection request. |
| 86 |
|
94 |
|
|
Lines 95-100
sub process_request {
Link Here
|
| 95 |
# Flushing L1 to make sure the request will be processed using the correct data |
103 |
# Flushing L1 to make sure the request will be processed using the correct data |
| 96 |
Koha::Caches->flush_L1_caches(); |
104 |
Koha::Caches->flush_L1_caches(); |
| 97 |
|
105 |
|
|
|
106 |
$self->{account} = undef; # Clear out the account from the last request, it may be different |
| 107 |
$self->{logger} = _set_logger( Koha::Logger->get( { interface => 'sip' } ) ); |
| 108 |
|
| 109 |
# Flush previous MDCs to prevent accidentally leaking incorrect MDC-entries |
| 110 |
Log::Log4perl::MDC->put( "accountid", undef ); |
| 111 |
Log::Log4perl::MDC->put( "peeraddr", undef ); |
| 112 |
|
| 98 |
my $sockname = getsockname(STDIN); |
113 |
my $sockname = getsockname(STDIN); |
| 99 |
|
114 |
|
| 100 |
# Check if socket connection is IPv6 before resolving address |
115 |
# Check if socket connection is IPv6 before resolving address |
|
Lines 160-165
sub raw_transport {
Link Here
|
| 160 |
} |
175 |
} |
| 161 |
alarm 0; |
176 |
alarm 0; |
| 162 |
|
177 |
|
|
|
178 |
$self->{logger} = _set_logger( |
| 179 |
Koha::Logger->get( |
| 180 |
{ |
| 181 |
interface => 'sip', |
| 182 |
category => $self->{account}->{id}, # Add id to namespace |
| 183 |
} |
| 184 |
) |
| 185 |
); |
| 186 |
|
| 187 |
# Set MDCs after properly authenticating |
| 188 |
Log::Log4perl::MDC->put( "accountid", $self->{account}->{id} ); |
| 189 |
Log::Log4perl::MDC->put( "peeraddr", $self->{server}->{peeraddr} ); |
| 190 |
|
| 163 |
syslog("LOG_DEBUG", "raw_transport: uname/inst: '%s/%s'", |
191 |
syslog("LOG_DEBUG", "raw_transport: uname/inst: '%s/%s'", |
| 164 |
$self->{account}->{id}, |
192 |
$self->{account}->{id}, |
| 165 |
$self->{account}->{institution}); |
193 |
$self->{account}->{institution}); |
|
Lines 397-402
sub get_timeout {
Link Here
|
| 397 |
} |
425 |
} |
| 398 |
} |
426 |
} |
| 399 |
|
427 |
|
|
|
428 |
=head2 get_SIPServer |
| 429 |
|
| 430 |
my $sipServer = C4::SIP::SIPServer::get_SIPServer() |
| 431 |
|
| 432 |
@RETURNS C4::SIP::SIPServer, the current server's child-process used to handle this SIP-transaction |
| 433 |
|
| 434 |
=cut |
| 435 |
|
| 436 |
sub get_SIPServer { |
| 437 |
unless($activeSIPServer) { |
| 438 |
my @cc = caller(1); |
| 439 |
die "$cc[3]() asks for \$activeSIPServer, but he is not defined yet"; |
| 440 |
} |
| 441 |
return $activeSIPServer; |
| 442 |
} |
| 443 |
|
| 444 |
sub _set_SIPServer { |
| 445 |
my ($sipServer) = @_; |
| 446 |
unless (blessed($sipServer) && $sipServer->isa('C4::SIP::SIPServer')) { |
| 447 |
my @cc = caller(0); |
| 448 |
die "$cc[3]():> \$sipServer '$sipServer' is not a C4::SIP::SIPServer-object"; |
| 449 |
} |
| 450 |
$activeSIPServer = $sipServer; |
| 451 |
return $activeSIPServer; |
| 452 |
} |
| 453 |
|
| 454 |
=head2 get_logger |
| 455 |
|
| 456 |
my $logger = C4::SIP::SIPServer::get_logger() |
| 457 |
|
| 458 |
@RETURNS Koha::Logger, the logger used to log this SIP-transaction |
| 459 |
|
| 460 |
=cut |
| 461 |
|
| 462 |
sub get_logger { |
| 463 |
unless($activeLogger) { |
| 464 |
my @cc = caller(1); |
| 465 |
die "$cc[3]() asks for \$activeLogger, but he is not defined yet"; |
| 466 |
} |
| 467 |
return $activeLogger; |
| 468 |
} |
| 469 |
|
| 470 |
sub _set_logger { |
| 471 |
my ($logger) = @_; |
| 472 |
unless (blessed($logger) && $logger->isa('Koha::Logger')) { |
| 473 |
my @cc = caller(0); |
| 474 |
die "$cc[3]():> \$logger '$logger' is not a Koha::Logger-object"; |
| 475 |
} |
| 476 |
$activeLogger = $logger; |
| 477 |
return $activeLogger; |
| 478 |
} |
| 479 |
|
| 400 |
1; |
480 |
1; |
| 401 |
|
481 |
|
| 402 |
__END__ |
482 |
__END__ |