| 1 |
package Qpsmtpd::TcpServer::Prefork; |
| 2 |
use Qpsmtpd::TcpServer; |
| 3 |
use Qpsmtpd::SMTP::Prefork; |
| 4 |
use Qpsmtpd::Constants; |
| 5 |
|
| 6 |
@ISA = qw(Qpsmtpd::SMTP::Prefork Qpsmtpd::TcpServer); |
| 7 |
|
| 8 |
my $first_0; |
| 9 |
|
| 10 |
sub start_connection { |
| 11 |
my $self = shift; |
| 12 |
|
| 13 |
#reset info |
| 14 |
$self->{_connection} = Qpsmtpd::Connection->new(); #reset connection |
| 15 |
$self->reset_transaction; |
| 16 |
$self->SUPER::start_connection(@_); |
| 17 |
} |
| 18 |
|
| 19 |
sub read_input { |
| 20 |
my $self = shift; |
| 21 |
|
| 22 |
my $timeout = $self->config('timeoutsmtpd') # qmail smtpd control file |
| 23 |
|| $self->config('timeout') # qpsmtpd control file |
| 24 |
|| 1200; # default value |
| 25 |
|
| 26 |
alarm $timeout; |
| 27 |
eval { |
| 28 |
while (<STDIN>) { |
| 29 |
alarm 0; |
| 30 |
$_ =~ s/\r?\n$//s; # advanced chomp |
| 31 |
$self->log(LOGINFO, "dispatching $_"); |
| 32 |
$self->connection->notes('original_string', $_); |
| 33 |
defined $self->dispatch(split / +/, $_, 2) |
| 34 |
or $self->respond(502, "command unrecognized: '$_'"); |
| 35 |
alarm $timeout; |
| 36 |
} |
| 37 |
unless ($self->connection->notes('disconnected')) { |
| 38 |
$self->reset_transaction; |
| 39 |
$self->run_hooks('disconnect'); |
| 40 |
$self->connection->notes(disconnected => 1); |
| 41 |
} |
| 42 |
}; |
| 43 |
if ($@ =~ /^disconnect_tcpserver/) { |
| 44 |
die "disconnect_tcpserver"; |
| 45 |
} |
| 46 |
else { |
| 47 |
$self->run_hooks("post-connection"); |
| 48 |
$self->connection->reset; |
| 49 |
die "died while reading from STDIN (probably broken sender) - $@"; |
| 50 |
} |
| 51 |
alarm(0); |
| 52 |
} |
| 53 |
|
| 54 |
sub respond { |
| 55 |
my ($self, $code, @messages) = @_; |
| 56 |
|
| 57 |
if (!$self->check_socket()) { |
| 58 |
$self->log(LOGERROR, |
| 59 |
"Lost connection to client, cannot send response."); |
| 60 |
return (0); |
| 61 |
} |
| 62 |
|
| 63 |
while (my $msg = shift @messages) { |
| 64 |
my $line = $code . (@messages ? "-" : " ") . $msg; |
| 65 |
$self->log(LOGINFO, $line); |
| 66 |
print "$line\r\n" |
| 67 |
or ($self->log(LOGERROR, "Could not print [$line]: $!"), return 0); |
| 68 |
} |
| 69 |
return 1; |
| 70 |
} |
| 71 |
|
| 72 |
sub disconnect { |
| 73 |
my $self = shift; |
| 74 |
$self->log(LOGINFO, "click, disconnecting"); |
| 75 |
$self->SUPER::disconnect(@_); |
| 76 |
$self->run_hooks("post-connection"); |
| 77 |
$self->connection->reset; |
| 78 |
die "disconnect_tcpserver"; |
| 79 |
} |
| 80 |
|
| 81 |
1; |