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