| 1 | package Mail::Decency::Core::POEForking::Postfix; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use version 0.74; our $VERSION = qv( "v0.1.5" ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use base qw/ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | Mail::Decency::Core::POEForking | ||||||||||||||||||||||||||||
| 10 | 11 | /; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 11 | ▶ | use POE qw/ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | Wheel::ReadWrite | ||||||||||||||||||||||||||||
| 14 | 11 | /; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 11 | ▶ | use Scalar::Util qw/ weaken /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 11 | ▶ | use Socket qw/ inet_ntoa /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head1 NAME | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | Mail::Decency::Core::POEForking::Postfix | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | Postfix instance to be used with POEForking | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | =head1 METHODS | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head2 create_handler | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | Called by the forking/treading parent server | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =cut | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | sub create_handler { | ||||||||||||||||||||||||||
|
Subroutine
create_handler: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 37 | 0 | my ( $heap, $session, $socket, $peer_addr, $peer_port ) | |||||||||||||||||||||||||||
| 38 | = @_[ HEAP, SESSION, ARG0, ARG1, ARG2 ]; | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | POE::Session->create( | ||||||||||||||||||||||||||||
| 41 | inline_states => { | ||||||||||||||||||||||||||||
| 42 | _start => \&postfix_start, | ||||||||||||||||||||||||||||
| 43 | _stop => \&postfix_stop, | ||||||||||||||||||||||||||||
| 44 | postfix_input => \&postfix_input, | ||||||||||||||||||||||||||||
| 45 | postfix_flush => \&postfix_flush, | ||||||||||||||||||||||||||||
| 46 | postfix_error => \&postfix_error, | ||||||||||||||||||||||||||||
| 47 | good_night => \&postfix_stop, | ||||||||||||||||||||||||||||
| 48 | #_parent => sub { 0 }, | ||||||||||||||||||||||||||||
| 49 | # _default => sub { | ||||||||||||||||||||||||||||
| 50 | # my ( $heap, $event, $args ) = @_[ HEAP, ARG0, ARG1 ]; | ||||||||||||||||||||||||||||
| 51 | # $heap->{ decency }->logger->error( "** UNKNOWN EVENT $event, $args" ); | ||||||||||||||||||||||||||||
| 52 | # } | ||||||||||||||||||||||||||||
| 53 | }, | ||||||||||||||||||||||||||||
| 54 | heap => { | ||||||||||||||||||||||||||||
| 55 | decency => $heap->{ decency }, | ||||||||||||||||||||||||||||
| 56 | logger => $heap->{ decency }->logger, | ||||||||||||||||||||||||||||
| 57 | conf => $heap->{ conf }, | ||||||||||||||||||||||||||||
| 58 | handler => $heap->{ decency }->get_handlers(), | ||||||||||||||||||||||||||||
| 59 | server => $heap->{ server }, | ||||||||||||||||||||||||||||
| 60 | 0 | parent => $session, | |||||||||||||||||||||||||||
| 61 | socket => $socket, | ||||||||||||||||||||||||||||
| 62 | peer_addr => inet_ntoa( $peer_addr ), | ||||||||||||||||||||||||||||
| 63 | peer_port => $peer_port, | ||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | =head2 postfix_start | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | Start connection from postfix | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub postfix_start { | ||||||||||||||||||||||||||
|
Subroutine
postfix_start: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 0 | my ( $kernel, $session, $heap ) = @_[ KERNEL, SESSION, HEAP ]; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | # tell the parent session we are here | ||||||||||||||||||||||||||||
| 79 | 0 | $kernel->post( $heap->{ parent }, "new_client_session", $session ); | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # start new r/w on the socket | ||||||||||||||||||||||||||||
| 82 | $heap->{ client } = POE::Wheel::ReadWrite->new( | ||||||||||||||||||||||||||||
| 83 | Handle => $heap->{ socket }, | ||||||||||||||||||||||||||||
| 84 | 0 | Filter => POE::Filter::Postfix::Plain->new(), | |||||||||||||||||||||||||||
| 85 | InputEvent => "postfix_input", | ||||||||||||||||||||||||||||
| 86 | ErrorEvent => "postfix_error", | ||||||||||||||||||||||||||||
| 87 | FlushedEvent => "postfix_flush", | ||||||||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =head2 postfix_input | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | Incoming data from postfix | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | =cut | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub postfix_input { | ||||||||||||||||||||||||||
|
Subroutine
postfix_input: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 0 | my ( $heap, $attr ) = @_[ HEAP, ARG0 ]; | |||||||||||||||||||||||||||
| 100 | $heap->{ client }->put( | ||||||||||||||||||||||||||||
| 101 | 0 | $heap->{ handler }->( $heap->{ server }, $attr ) | |||||||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =head2 postfix_stop | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | Stop connection.. called when WE finish the connection (eg SIG TERM) | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =cut | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub postfix_stop { | ||||||||||||||||||||||||||
|
Subroutine
postfix_stop: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | 0 | my ( $heap, $session ) = @_[ HEAP, SESSION ]; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | $heap->{ logger }->debug2( "Disconnecting from postfix" ); | |||||||||||||||||||||||||||
| 116 | 0 | eval { | |||||||||||||||||||||||||||
| 117 | 0 | delete $heap->{ $_ } for qw/ client socket /; | |||||||||||||||||||||||||||
| 118 | }; | ||||||||||||||||||||||||||||
| 119 | 0 | ▶ | $heap->{ logger }->error( "Could not remove client from list after postfix stop: $@" ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | if $@; | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | return; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =head2 postfix_flush | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | Flush connection .. ignore this | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =cut | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | ▶ | sub postfix_flush { | ||||||||||||||||||||||||||
|
Subroutine
postfix_flush: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 133 | 0 | my ( $heap, $session ) = @_[ HEAP, SESSION ]; | |||||||||||||||||||||||||||
| 134 | 0 | $heap->{ logger }->debug3( "Flush from $heap->{ peer_addr } (". $session->ID. ")" ); | |||||||||||||||||||||||||||
| 135 | 0 | eval { | |||||||||||||||||||||||||||
| 136 | 0 | delete $heap->{ $_ } for qw/ client /; | |||||||||||||||||||||||||||
| 137 | }; | ||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =head2 postfix_error | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | Handles connection erros from postfix .. as well as disconnects (not flush) | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | =cut | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | ▶ | sub postfix_error { | ||||||||||||||||||||||||||
|
Subroutine
postfix_error: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 148 | 0 | my ( $heap, $session, $operation, $errnum, $errstr, $id ) = @_[ HEAP, SESSION, ARG0..ARG3 ]; | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | # disconnect .. | ||||||||||||||||||||||||||||
| 151 | 0 | ▶ | if ( $operation eq 'read' && $errnum == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$operation eq "read" and $errnum == 0
MC/DC0%0/2
$operation eq "read" and $errnum == 0
$operation eq "read"
$errnum == 0
Truth table0%0/3
A and B
A= $operation eq "read"B= $errnum == 0
| |||||||||||||||||||||||||||||
| 152 | 0 | $heap->{ logger }->debug2( "Postfix closed connection" ); | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | # real error .. | ||||||||||||||||||||||||||||
| 156 | else { | ||||||||||||||||||||||||||||
| 157 | 0 | $heap->{ logger }->error( "Weird disconnection from postfix ". $session->ID. " (OP: $operation, ENUM: $errnum, ESTR: $errstr, WID: $id)" ); | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | # close all sockets .. | ||||||||||||||||||||||||||||
| 161 | 0 | eval { | |||||||||||||||||||||||||||
| 162 | #delete $heap->{ $_ } for qw/ client socket /; # | ||||||||||||||||||||||||||||
| 163 | 0 | $heap->{ socket }->flush; | |||||||||||||||||||||||||||
| 164 | }; | ||||||||||||||||||||||||||||
| 165 | 0 | ▶ | $heap->{ logger }->error( "Could not remove client from list after weird disconnect: $@" ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | if $@; | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 0 | return; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | Ulrich Kautz <uk@fortrabbit.de> | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | Copyright (c) 2010 the L</AUTHOR> as listed above | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | =head1 LICENCSE | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | This library is free software and may be distributed under the same terms as perl itself. | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =cut | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 11 | 1; | |||||||||||||||||||||||||||