Skip to content

Loading…

count_unrecognized_commands: efficiency & readability #27

Closed
wants to merge 3 commits into from

1 participant

@msimerson
qpsmtpd member

removed hook_connect, redundant

rearranged hook_unrecognized_command for better logging and readability

msimerson added some commits
@msimerson msimerson count_unrecognized_commands: efficiency & readability
removed hook_connect, redundant

rearranged hook_unrecognized_command for better logging and readability
42f5f84
@msimerson msimerson count: replace ++operator with + 1
requires no need to understand the difference between ++$var and $var++
c03a915
@msimerson msimerson count: trying again ec986b8
@msimerson msimerson closed this
@msimerson msimerson deleted the msimerson:count branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 4, 2012
  1. @msimerson

    count_unrecognized_commands: efficiency & readability

    msimerson committed
    removed hook_connect, redundant
    
    rearranged hook_unrecognized_command for better logging and readability
Commits on Jun 5, 2012
  1. @msimerson

    count: replace ++operator with + 1

    msimerson committed
    requires no need to understand the difference between ++$var and $var++
  2. @msimerson

    count: trying again

    msimerson committed
Showing with 10 additions and 20 deletions.
  1. +10 −20 plugins/count_unrecognized_commands
View
30 plugins/count_unrecognized_commands
@@ -2,7 +2,7 @@
=head1 NAME
-count_unrecognized_commands - Count unrecognized commands and disconnect when we have too many
+count_unrecognized_commands - and disconnect after too many
=head1 DESCRIPTION
@@ -31,29 +31,19 @@ sub register {
}
}
-sub hook_connect {
- my $self = shift;
-
- $self->connection->notes('unrec_cmd_count', 0);
- return DECLINED;
-}
-
sub hook_unrecognized_command {
my ($self, $cmd) = @_[0,2];
- $self->log(LOGINFO, "Unrecognized command '$cmd'");
-
- my $badcmdcount =
- $self->connection->notes( 'unrec_cmd_count',
- ($self->connection->notes('unrec_cmd_count') || 0) + 1
- );
+ my $count = $self->connection->notes('unrec_cmd_count') || 0;
+ $count = $count + 1;
+ $self->connection->notes('unrec_cmd_count', $count);
- if ($badcmdcount >= $self->{_unrec_cmd_max}) {
- my $msg = "Closing connection, $badcmdcount unrecognized commands.";
- $self->log(LOGINFO, "fail: $msg");
- return (DENY_DISCONNECT, "$msg Perhaps you should read RFC 2821?");
- }
+ if ( $count < $self->{_unrec_cmd_max} ) {
+ $self->log(LOGINFO, "'$cmd', ($count)");
+ return DECLINED;
+ };
- return DECLINED;
+ $self->log(LOGINFO, "fail, '$cmd' ($count)");
+ return (DENY_DISCONNECT, "Closing connection, $count unrecognized commands. Perhaps you should read RFC 2821?" );
}
Something went wrong with that request. Please try again.