From a7914ac0dc31555734c90dfb5eacaa3c7b98ee3b Mon Sep 17 00:00:00 2001 From: Matt Sergeant Date: Tue, 28 Aug 2007 18:42:01 +0000 Subject: [PATCH] Support for $transaction->id to get a unique id for this transaction git-svn-id: https://svn.perl.org/qpsmtpd/trunk@775 958fd67b-6ff1-0310-b445-bb7760255be9 --- lib/Qpsmtpd/SMTP.pm | 2 +- lib/Qpsmtpd/TcpServer/Prefork.pm | 2 +- lib/Qpsmtpd/Transaction.pm | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/Qpsmtpd/SMTP.pm b/lib/Qpsmtpd/SMTP.pm index c420215..0ebc4de 100644 --- a/lib/Qpsmtpd/SMTP.pm +++ b/lib/Qpsmtpd/SMTP.pm @@ -135,7 +135,7 @@ sub transaction { sub reset_transaction { my $self = shift; $self->run_hooks("reset_transaction") if $self->{_transaction}; - return $self->{_transaction} = Qpsmtpd::Transaction->new(); + return $self->{_transaction} = Qpsmtpd::Transaction->new(connection => $self->connection); } diff --git a/lib/Qpsmtpd/TcpServer/Prefork.pm b/lib/Qpsmtpd/TcpServer/Prefork.pm index 71aa221..cd2dac5 100644 --- a/lib/Qpsmtpd/TcpServer/Prefork.pm +++ b/lib/Qpsmtpd/TcpServer/Prefork.pm @@ -12,7 +12,7 @@ sub start_connection { #reset info $self->{_connection} = Qpsmtpd::Connection->new(); #reset connection - $self->{_transaction} = Qpsmtpd::Transaction->new(); #reset transaction + $self->reset_transaction; $self->SUPER::start_connection(@_); } diff --git a/lib/Qpsmtpd/Transaction.pm b/lib/Qpsmtpd/Transaction.pm index 6cfaed4..2abc735 100644 --- a/lib/Qpsmtpd/Transaction.pm +++ b/lib/Qpsmtpd/Transaction.pm @@ -4,6 +4,8 @@ use Qpsmtpd; use strict; use Qpsmtpd::Utils; use Qpsmtpd::Constants; +use Socket qw(inet_aton); +use Time::HiRes qw(time); use IO::File qw(O_RDWR O_CREAT); @@ -13,11 +15,23 @@ sub start { my $proto = shift; my $class = ref($proto) || $proto; my %args = @_; - my $self = { _rcpt => [], started => time }; + + # generate id + my $conn = $args{connection}; + my $ip = $conn->local_port || "0"; + my $start = time; + my $id = "$start.$$.$ip"; + + my $self = { _rcpt => [], started => $start, _id => $id }; bless ($self, $class); return $self; } +sub id { + my $self = shift; + $self->{_id}; +} + sub add_recipient { my $self = shift; @_ and push @{$self->{_recipients}}, shift;