From e2ca196b7e2c695557b013285b3c7e5e5b885f5a Mon Sep 17 00:00:00 2001 From: Tomas Plesnik <plesnik@ics.muni.cz> Date: Mon, 6 Aug 2012 10:44:10 +0200 Subject: [PATCH] pridan limit pro nastaveni maximalniho poctu odeslanych udalosti klientovi, ochrana pred zahlcenim klienta --- src/warden-server/doc/CHANGELOG | 3 ++- src/warden-server/doc/README | 4 ++++ src/warden-server/lib/Warden.pm | 17 +++++++++-------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/warden-server/doc/CHANGELOG b/src/warden-server/doc/CHANGELOG index 7d07ced..18133f5 100644 --- a/src/warden-server/doc/CHANGELOG +++ b/src/warden-server/doc/CHANGELOG @@ -1,6 +1,7 @@ 2012-00-00 v2.1 stable version ------------------------------ -- receiving of all types of messages now supported +- add limit of events that can be downloaded from server to client +- add receiving of all types of messages 2012-07-27 v2.0 stable version diff --git a/src/warden-server/doc/README b/src/warden-server/doc/README index c6bad8a..ec0ebdf 100644 --- a/src/warden-server/doc/README +++ b/src/warden-server/doc/README @@ -157,6 +157,10 @@ C. Installation DB_HOST - MySQL database host e.g. localhost + MAX_EVENT_LIMIT - maximum number of events that can be downloaded from Warden server + in a single getNewEvents client function call + e.g. 2000000 + c) warden-apache.conf The Apache2 configuration file for Warden server diff --git a/src/warden-server/lib/Warden.pm b/src/warden-server/lib/Warden.pm index f56150f..842ca30 100755 --- a/src/warden-server/lib/Warden.pm +++ b/src/warden-server/lib/Warden.pm @@ -33,16 +33,17 @@ our $DB_NAME = undef; our $DB_USER = undef; our $DB_PASS = undef; our $DB_HOST = undef; +our $MAX_EVENT_LIMIT = undef; # read config file if (!open( TMP, $conf_file)) { - die errMsg("Can't read config file '$conf_file': $!\n"); + errMsg("Can't read config file '$conf_file': $!\n"); } close TMP; # load set variables by user if (!do $conf_file) { - die errMsg("Errors in config file '$conf_file': $@"); + errMsg("Errors in config file '$conf_file': $@"); } @@ -241,30 +242,30 @@ sub getNewEvents my $client_type = "r"; # incoming client MUST be sender # parse SOAP data object - my $requested_type = $data->{'REQUESTED_TYPE'}; - my $last_id = $data->{'LAST_ID'}; + my $requested_type = $data->{'REQUESTED_TYPE'}; + my $last_id = $data->{'LAST_ID'}; my %client = authorizeClient($alt_names, $ip, $requested_type, $client_type, '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;"); + $sth = $DBH->prepare("SELECT * FROM events WHERE type != 'test' AND id > ? AND valid = 't' ORDER BY id ASC limit $MAX_EVENT_LIMIT;"); if (!defined $sth) {die("Cannot prepare ROE-ANY statement in getNewEvents: $DBI::errstr\n")} $sth->execute($last_id); } else { - $sth = $DBH->prepare("SELECT * FROM events WHERE type != 'test' AND id > ? AND type = ? AND valid = 't' ORDER BY id ASC;"); + $sth = $DBH->prepare("SELECT * FROM events WHERE type != 'test' AND id > ? AND type = ? AND valid = 't' ORDER BY id ASC limit $MAX_EVENT_LIMIT;"); if (!defined $sth) {die("Cannot prepare ROE statement in getNewEvents: $DBI::errstr\n")} $sth->execute($last_id, $requested_type); } } 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;"); + $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;"); if (!defined $sth) {die("Cannot prepare ANY statement in getNewEvents: $DBI::errstr\n")} my ($domain) = $cn =~ /([^\.]+\.[^\.]+)$/; $domain = '\%' . $domain; $sth->execute($last_id, $domain); } 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;"); + $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;"); if (!defined $sth) {die("Cannot prepare statement in getNewEvents: $DBI::errstr\n")} my ($domain) = $cn =~ /([^\.]+\.[^\.]+)$/; $domain = '\%' . $domain; -- GitLab