Skip to content
Snippets Groups Projects
Commit 45657b64 authored by Tomáš Plesník's avatar Tomáš Plesník
Browse files

pridana funkce trim(); otrimovani chybovych hlasek

parent 508e03b3
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,18 @@ use Carp; ...@@ -19,6 +19,18 @@ use Carp;
our $VERSION = "2.2"; our $VERSION = "2.2";
#-------------------------------------------------------------------------------
# trim - remove whitespace from the start and end of the string
#-------------------------------------------------------------------------------
sub trim
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
} # End of trim
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# errMsg - prints error msg and returns undef or prints warning and returns 1 # errMsg - prints error msg and returns undef or prints warning and returns 1
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
...@@ -68,11 +80,11 @@ sub c2s ...@@ -68,11 +80,11 @@ sub c2s
# create SOAP::Transport::HTTP:Client object # create SOAP::Transport::HTTP:Client object
eval { eval {
$client = SOAP::Transport::HTTP::Client->new(); $client = SOAP::Transport::HTTP::Client->new();
} or return errMsg("Error in function 'c2s()' when creating SOAP::Transport::HTTP::Client object: " . $@); } or return errMsg("Error in function 'c2s()' when creating SOAP::Transport::HTTP::Client object: " . trim($@));
# setting of connection timeout # setting of connection timeout
eval {$client->timeout($WardenClientCommon::CONNECTION_TIMEOUT);} eval {$client->timeout($WardenClientCommon::CONNECTION_TIMEOUT);}
or return errMsg("Error in function 'c2s()' when setting connection timeout: " . $@); or return errMsg("Error in function 'c2s()' when setting connection timeout: " . trim($@));
# setting of SSL options # setting of SSL options
eval { eval {
...@@ -83,24 +95,24 @@ sub c2s ...@@ -83,24 +95,24 @@ sub c2s
SSL_cert_file => $WardenClientCommon::SSL_CERT, SSL_cert_file => $WardenClientCommon::SSL_CERT,
SSL_ca_file => $WardenClientCommon::SSL_CA_CERT); SSL_ca_file => $WardenClientCommon::SSL_CA_CERT);
return 1; # fix of eval triggering 'or' statement return 1; # fix of eval triggering 'or' statement
} or return errMsg("Ërror in function 'c2s()' when setting SSL options: " . $@); } or return errMsg("Ërror in function 'c2s()' when setting SSL options: " . trim($@));
# setting of service URI # setting of service URI
my $soap; my $soap;
eval { eval {
$soap = SOAP::Lite->uri($service)->proxy($WardenClientCommon::URI); $soap = SOAP::Lite->uri($service)->proxy($WardenClientCommon::URI);
} or return errMsg("Error in function 'c2s()' when setting service URI: " . $@); } or return errMsg("Error in function 'c2s()' when setting service URI: " . trim($@));
# serialize SOAP envelope or SOAP envelope and data object # serialize SOAP envelope or SOAP envelope and data object
my $envelope; my $envelope;
if (!defined $data) { if (!defined $data) {
eval { eval {
$envelope = $soap->serializer->envelope(method => $method); $envelope = $soap->serializer->envelope(method => $method);
} or return errMsg("Error in function 'c2s()' when serializing envelope: " . $@); } or return errMsg("Error in function 'c2s()' when serializing envelope: " . trim($@));
} else { } else {
eval { eval {
$envelope = $soap->serializer->envelope(method => $method, $data); $envelope = $soap->serializer->envelope(method => $method, $data);
} or return errMsg("Error in function 'c2s()' when serializing envelope and data: " . $@); } or return errMsg("Error in function 'c2s()' when serializing envelope and data: " . trim($@));
} }
# setting of complete HTTPs URI and send serialized SOAP envelope and data # setting of complete HTTPs URI and send serialized SOAP envelope and data
...@@ -108,7 +120,7 @@ sub c2s ...@@ -108,7 +120,7 @@ sub c2s
my $result; my $result;
eval { eval {
$result = $client->send_receive(envelope => $envelope, endpoint => $server_uri); $result = $client->send_receive(envelope => $envelope, endpoint => $server_uri);
} or return errMsg("Error in function 'c2s()' when sending SOAP envelope and data: " . $@); } or return errMsg("Error in function 'c2s()' when sending SOAP envelope and data: " . trim($@));
# check server response # check server response
if (!defined $result) { if (!defined $result) {
...@@ -118,9 +130,9 @@ sub c2s ...@@ -118,9 +130,9 @@ sub c2s
my $response; my $response;
eval { eval {
$response = $soap->deserializer->deserialize($result); $response = $soap->deserializer->deserialize($result);
} or return errMsg("Error in deserialization of server response:" . $@ . "\nReceived response: " . $result); } or return errMsg("Error in deserialization of server response: " . trim($@) . "\nReceived response: " . trim($result));
# check SOAP fault status # check SOAP fault status
$response->fault ? return errMsg("Server sent error message: " . $response->faultstring) : return $response; $response->fault ? return errMsg("Server sent error message: " . trim($response->faultstring)) : return $response;
} }
} }
...@@ -144,8 +156,8 @@ sub loadConf ...@@ -144,8 +156,8 @@ sub loadConf
our $SYSLOG_FACILITY = undef; our $SYSLOG_FACILITY = undef;
unless (do $conf_file) { unless (do $conf_file) {
die("Errors in config file '$conf_file': $@") if $@; die("Errors in config file '$conf_file': " . trim($@)) if $@;
die("Can't read config file '$conf_file': $!") unless defined $_; die("Can't read config file '$conf_file': " . trim($!)) unless defined $_;
# if $_ defined, it's retvalue of last statement of conf, for which we don't care # if $_ defined, it's retvalue of last statement of conf, for which we don't care
} }
} # End of loadConf } # End of loadConf
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment