Lines 5-22
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 |
|
20 |
|
|
|
21 |
use Koha::Logger; |
22 |
use C4::SIP::Trapper; |
23 |
tie *STDERR, "C4::SIP::Trapper"; |
24 |
|
20 |
use base qw(Net::Server::PreFork); |
25 |
use base qw(Net::Server::PreFork); |
21 |
|
26 |
|
22 |
use constant LOG_SIP => "local6"; # Local alias for the logging facility |
27 |
use constant LOG_SIP => "local6"; # Local alias for the logging facility |
Lines 80-85
__PACKAGE__ ->run(@parms);
Link Here
|
80 |
# Child |
85 |
# Child |
81 |
# |
86 |
# |
82 |
|
87 |
|
|
|
88 |
my $activeSIPServer; |
89 |
my $activeLogger; |
90 |
|
83 |
# process_request is the callback used by Net::Server to handle |
91 |
# process_request is the callback used by Net::Server to handle |
84 |
# an incoming connection request. |
92 |
# an incoming connection request. |
85 |
|
93 |
|
Lines 91-96
sub process_request {
Link Here
|
91 |
|
99 |
|
92 |
$self->{config} = $config; |
100 |
$self->{config} = $config; |
93 |
|
101 |
|
|
|
102 |
$self->{account} = undef; # Clear out the account from the last request, it may be different |
103 |
$self->{logger} = _set_logger( Koha::Logger->get( { interface => 'sip' } ) ); |
104 |
|
105 |
# Flush previous MDCs to prevent accidentally leaking incorrect MDC-entries |
106 |
Log::Log4perl::MDC->put( "accountid", undef ); |
107 |
Log::Log4perl::MDC->put( "peeraddr", undef ); |
108 |
|
94 |
my $sockname = getsockname(STDIN); |
109 |
my $sockname = getsockname(STDIN); |
95 |
|
110 |
|
96 |
# Check if socket connection is IPv6 before resolving address |
111 |
# Check if socket connection is IPv6 before resolving address |
Lines 156-161
sub raw_transport {
Link Here
|
156 |
} |
171 |
} |
157 |
alarm 0; |
172 |
alarm 0; |
158 |
|
173 |
|
|
|
174 |
$self->{logger} = _set_logger( |
175 |
Koha::Logger->get( |
176 |
{ |
177 |
interface => 'sip', |
178 |
category => $self->{account}->{id}, # Add id to namespace |
179 |
} |
180 |
) |
181 |
); |
182 |
|
183 |
# Set MDCs after properly authenticating |
184 |
Log::Log4perl::MDC->put( "accountid", $self->{account}->{id} ); |
185 |
Log::Log4perl::MDC->put( "peeraddr", $self->{server}->{peeraddr} ); |
186 |
|
159 |
syslog("LOG_DEBUG", "raw_transport: uname/inst: '%s/%s'", |
187 |
syslog("LOG_DEBUG", "raw_transport: uname/inst: '%s/%s'", |
160 |
$self->{account}->{id}, |
188 |
$self->{account}->{id}, |
161 |
$self->{account}->{institution}); |
189 |
$self->{account}->{institution}); |
Lines 393-398
sub get_timeout {
Link Here
|
393 |
} |
421 |
} |
394 |
} |
422 |
} |
395 |
|
423 |
|
|
|
424 |
=head2 get_SIPServer |
425 |
|
426 |
my $sipServer = C4::SIP::SIPServer::get_SIPServer() |
427 |
|
428 |
@RETURNS C4::SIP::SIPServer, the current server's child-process used to handle this SIP-transaction |
429 |
|
430 |
=cut |
431 |
|
432 |
sub get_SIPServer { |
433 |
unless($activeSIPServer) { |
434 |
my @cc = caller(1); |
435 |
die "$cc[3]() asks for \$activeSIPServer, but he is not defined yet"; |
436 |
} |
437 |
return $activeSIPServer; |
438 |
} |
439 |
|
440 |
sub _set_SIPServer { |
441 |
my ($sipServer) = @_; |
442 |
unless (blessed($sipServer) && $sipServer->isa('C4::SIP::SIPServer')) { |
443 |
my @cc = caller(0); |
444 |
die "$cc[3]():> \$sipServer '$sipServer' is not a C4::SIP::SIPServer-object"; |
445 |
} |
446 |
$activeSIPServer = $sipServer; |
447 |
return $activeSIPServer; |
448 |
} |
449 |
|
450 |
=head2 get_logger |
451 |
|
452 |
my $logger = C4::SIP::SIPServer::get_logger() |
453 |
|
454 |
@RETURNS Koha::Logger, the logger used to log this SIP-transaction |
455 |
|
456 |
=cut |
457 |
|
458 |
sub get_logger { |
459 |
unless($activeLogger) { |
460 |
my @cc = caller(1); |
461 |
die "$cc[3]() asks for \$activeLogger, but he is not defined yet"; |
462 |
} |
463 |
return $activeLogger; |
464 |
} |
465 |
|
466 |
sub _set_logger { |
467 |
my ($logger) = @_; |
468 |
unless (blessed($logger) && $logger->isa('Koha::Logger')) { |
469 |
my @cc = caller(0); |
470 |
die "$cc[3]():> \$logger '$logger' is not a Koha::Logger-object"; |
471 |
} |
472 |
$activeLogger = $logger; |
473 |
return $activeLogger; |
474 |
} |
475 |
|
396 |
1; |
476 |
1; |
397 |
|
477 |
|
398 |
__END__ |
478 |
__END__ |