Re: [interchange] Update routine to recognize "RobotUAFinal"

Peter <[email protected]>
Newsgroups gmane.comp.web.interchange.users
Message-ID <[email protected]>
On 18/01/17 17:38, Peter wrote:
> There are cases where $ret is set to 1 and then further (wasted)
> processing is done to determine if $ret should be set to 1.  The logic
> is also insanely deep and confusing here.  I propose this simplification
> which also fixes the other issues I mentioned (I'll push if you're
> agreeable):

Oops, I pasted a partial patch, here's the full one:

diff --git a/lib/Vend/Server.pm b/lib/Vend/Server.pm
index a7eb80b..d5b62b5 100644
--- a/lib/Vend/Server.pm
+++ b/lib/Vend/Server.pm
@@ -279,45 +279,44 @@ EOF
 #::logDebug("request_method=$CGI::request_method");
 #::logDebug("content_type=$CGI::content_type");

-	$Vend::Robot = check_is_robot();
+	$Vend::Robot ||= check_is_robot();

 	$CGI::values{mv_tmp_session} ||= 1 if $Vend::Robot;
 }


 sub check_is_robot {
-	my $ret = 1;
-
 #::logDebug("Check robot UA=$Global::RobotUA IP=$Global::RobotIP");
-	if ($Global::RobotIP and $CGI::remote_addr =~ $Global::RobotIP) {
+    if ($Global::RobotIP and $CGI::remote_addr =~ $Global::RobotIP) {
 #::logDebug("It is a robot by IP!");
-		$ret = 1;
+	return 1;
+    }
+
+    if ($Global::HostnameLookups && $Global::RobotHost) {
+	if (!$CGI::remote_host && $CGI::remote_addr) {
+	    $CGI::remote_host =
gethostbyaddr(Socket::inet_aton($CGI::remote_addr),Socket::AF_INET);
+	    $CGI::host = $CGI::remote_host || $CGI::remote_addr;
 	}
-	elsif ($Global::HostnameLookups && $Global::RobotHost) {
-		if (!$CGI::remote_host && $CGI::remote_addr) {
-			$CGI::remote_host =
gethostbyaddr(Socket::inet_aton($CGI::remote_addr),Socket::AF_INET);
-			$CGI::host = $CGI::remote_host || $CGI::remote_addr;
-		}
-		if ($CGI::remote_host && $CGI::remote_host =~ $Global::RobotHost) {
+	if ($CGI::remote_host && $CGI::remote_host =~ $Global::RobotHost) {
 #::logDebug("It is a robot by host!");
-			$ret = 1;
-		}
-	}
-	if ($Global::RobotUAFinal and $CGI::useragent =~ $Global::RobotUAFinal) {
-		$ret = 1;
-	}
-	else {
-		unless ($Vend::Robot) {
-			if ($Global::NotRobotUA and $CGI::useragent =~ $Global::NotRobotUA) {
-				# do nothing
-			}
-			elsif ($Global::RobotUA and $CGI::useragent =~ $Global::RobotUA) {
-	#::logDebug("It is a robot by UA!");
-				$ret = 1;
-			}
-		}
+	    return 1;
 	}
-	return $ret;
+    }
+
+    if ($Global::RobotUAFinal and $CGI::useragent =~
$Global::RobotUAFinal) {
+	return 1;
+    }
+
+    if ($Global::NotRobotUA and $CGI::useragent =~ $Global::NotRobotUA) {
+	return 0;
+    }
+
+    if ($Global::RobotUA and $CGI::useragent =~ $Global::RobotUA) {
+#::logDebug("It is a robot by UA!");
+	return 1;
+    }
+
+    return 0;
 }

 # This is called by parse_multipart



Peter
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.