From 7d408702f26937d2d1188df806d2aaf42dbfe2c9 Mon Sep 17 00:00:00 2001
From: Tomas Plesnik <plesnik@ics.muni.cz>
Date: Mon, 13 Aug 2012 15:54:30 +0200
Subject: [PATCH] odstranena nadbytecnost v dereferenci pole,  presunut do
 placeholderu, odstranena zavislost na modulu List::Util

---
 src/warden-server/lib/Warden.pm | 21 +++++++++------------
 src/warden-server/sh/install.sh |  2 +-
 2 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/src/warden-server/lib/Warden.pm b/src/warden-server/lib/Warden.pm
index a3e0fe5..31abf07 100755
--- a/src/warden-server/lib/Warden.pm
+++ b/src/warden-server/lib/Warden.pm
@@ -19,7 +19,6 @@ use Net::CIDR::Lite;
 use DateTime;
 use MIME::Base64;
 use Crypt::X509;
-use List::Util 'first';
 
 our $VERSION = "2.1";
 
@@ -222,9 +221,7 @@ sub saveNewEvent
   if(defined %client) {
 
     # check validity of event attributes - TYPE
-    my $valid_types_ref = $VALID_STRINGS{'type'};
-    my @valid_types = @$valid_types_ref;
-    my $match = first { /$type/ } @valid_types;
+    my $match = grep /$type/, @{$VALID_STRINGS{'type'}};
     if ($match) {
       $sth=$DBH->prepare("INSERT INTO events VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);");
       if (!defined $sth) { die("Cannot do insert statement in $function_name: $DBI::errstr\n") }
@@ -263,27 +260,27 @@ sub getNewEvents
   if(defined %client) {
     if ($client{'receive_own'} eq 't') {	# check if client want your own events or not
       if ($requested_type eq '_any_') {		  # check if client want each or only one type of messages
-        $sth = $DBH->prepare("SELECT * FROM events WHERE type != 'test' AND id > ? AND valid = 't' ORDER BY id ASC limit $MAX_EVENT_LIMIT;");
+        $sth = $DBH->prepare("SELECT * FROM events WHERE type != 'test' AND id > ? AND valid = 't' ORDER BY id ASC LIMIT ?;");
         if (!defined $sth) {die("Cannot prepare ROE-ANY statement in $function_name: $DBI::errstr\n")}
-        $sth->execute($last_id);
+        $sth->execute($last_id, $MAX_EVENT_LIMIT);
       } else {
-        $sth = $DBH->prepare("SELECT * FROM events WHERE type != 'test' AND id > ? AND type = ? AND valid = 't' ORDER BY id ASC limit $MAX_EVENT_LIMIT;");
+        $sth = $DBH->prepare("SELECT * FROM events WHERE type != 'test' AND id > ? AND type = ? AND valid = 't' ORDER BY id ASC LIMIT ?;");
         if (!defined $sth) {die("Cannot prepare ROE statement in $function_name: $DBI::errstr\n")}
-        $sth->execute($last_id, $requested_type);
+        $sth->execute($last_id, $requested_type, $MAX_EVENT_LIMIT);
       }
     } else {
       if ($requested_type eq '_any_') {
-        $sth = $DBH->prepare("SELECT * FROM events WHERE type != 'test' AND id > ? AND valid = 't' AND hostname NOT LIKE ? ORDER BY id ASC limit $MAX_EVENT_LIMIT;");
+        $sth = $DBH->prepare("SELECT * FROM events WHERE type != 'test' AND id > ? AND valid = 't' AND hostname NOT LIKE ? ORDER BY id ASC LIMIT ?;");
         if (!defined $sth) {die("Cannot prepare ANY statement in $function_name: $DBI::errstr\n")}
         my ($domain) = $cn =~ /([^\.]+\.[^\.]+)$/;
         $domain = '\%' . $domain;
-        $sth->execute($last_id, $domain);
+        $sth->execute($last_id, $domain, $MAX_EVENT_LIMIT);
       } else {
-        $sth = $DBH->prepare("SELECT * FROM events WHERE type != 'test' AND id > ? AND type = ? AND valid = 't' AND hostname NOT LIKE ? ORDER BY id ASC limit $MAX_EVENT_LIMIT;");
+        $sth = $DBH->prepare("SELECT * FROM events WHERE type != 'test' AND id > ? AND type = ? AND valid = 't' AND hostname NOT LIKE ? ORDER BY id ASC LIMIT ?;");
         if (!defined $sth) {die("Cannot prepare statement in $function_name: $DBI::errstr\n")}
         my ($domain) = $cn =~ /([^\.]+\.[^\.]+)$/;
         $domain = '\%' . $domain;
-        $sth->execute($last_id, $requested_type, $domain);
+        $sth->execute($last_id, $requested_type, $domain, $MAX_EVENT_LIMIT);
       }
     }
 
diff --git a/src/warden-server/sh/install.sh b/src/warden-server/sh/install.sh
index 72fb228..82e15dd 100755
--- a/src/warden-server/sh/install.sh
+++ b/src/warden-server/sh/install.sh
@@ -288,7 +288,7 @@ create_symlinks()
 #-------------------------------------------------------------------------------
 
 # list of used Perl modules
-modules=(SOAP::Lite SOAP::Transport::HTTP DBI DBD::mysql Format::Human::Bytes Sys::Syslog File::Basename Net::CIDR::Lite DateTime Getopt::Std Switch IO::Socket::SSL MIME::Base64 Crypt::X509 List::Util)
+modules=(SOAP::Lite SOAP::Transport::HTTP DBI DBD::mysql Format::Human::Bytes Sys::Syslog File::Basename Net::CIDR::Lite DateTime Getopt::Std Switch IO::Socket::SSL MIME::Base64 Crypt::X509)
 
 # read input
 while getopts "d:k:c:a:Vh" options; do
-- 
GitLab