Changeset 97

Show
Ignore:
Timestamp:
04/13/05 13:16:49
Author:
tobias
Message:

threads support in proxy_check

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plugins/spamlookup/spamlookup.pl

    r95 r97  
    626626    my $TARGET_CONTENT_TYPE    = q{image/gif}; 
    627627 
     628    # see if we can use threads to run parallel requests 
     629    my @threads; 
     630    my $threaded=eval { require threads; 1 }; 
     631 
    628632    # create new user agent 
    629633    my $ua = LWP::UserAgent->new( 
     
    643647        } 
    644648        $ua->proxy('http', qq{http://$ip:$port/}); 
    645         my $r = $ua->head($TARGET); 
    646         next if($r->is_error); 
    647         # no error - let's see if we got the right stuff - content-length match? 
    648         if ($r->header('Content-Length') != $TARGET_CONTENT_LENGTH) { 
    649             # or content-type match? 
    650             next unless ($r->header('Content-Type') =~ 
    651                 m/^\Q$TARGET_CONTENT_TYPE\E$/i); 
    652         } 
    653         # yep - this is a good proxy 
    654         $data->{__reason} = "Found proxy at $ip:$port"; 
    655         $data->{is_proxy} = 1; 
    656         return $data->{proxycheck_moderate} ? MODERATE : BLOCK; 
     649        if($threaded) { 
     650            push(@threads, 
     651                 { 
     652                  proxy => qq{$ip:$port}, 
     653                  thread => 
     654                  threads->create(sub { 
     655                                      my $r = $ua->head($TARGET); 
     656                                      if(!$r->is_error) { 
     657                                          if ($r->header('Content-Length') != $TARGET_CONTENT_LENGTH) { 
     658                                              # or content-type match? 
     659                                              return 0 unless ($r->header('Content-Type') =~ 
     660                                                               m/^\Q$TARGET_CONTENT_TYPE\E$/i); 
     661                                          } 
     662                                          return 1; 
     663                                      } 
     664                                      return 0; 
     665                                  }) 
     666                 } 
     667                ); 
     668        } else { 
     669            my $r = $ua->head($TARGET); 
     670            next if($r->is_error); 
     671            # no error - let's see if we got the right stuff - content-length match? 
     672            if ($r->header('Content-Length') != $TARGET_CONTENT_LENGTH) { 
     673                # or content-type match? 
     674                next unless ($r->header('Content-Type') =~ 
     675                             m/^\Q$TARGET_CONTENT_TYPE\E$/i); 
     676            } 
     677            # yep - this is a good proxy 
     678            $data->{__reason} = "Found proxy at $ip:$port"; 
     679            $data->{is_proxy} = 1; 
     680            return $data->{proxycheck_moderate} ? MODERATE : BLOCK; 
     681        } 
     682    } 
     683    if($threaded) { 
     684        foreach (@threads) { 
     685            if($_->{thread}->join()) { 
     686                unless($data->{is_proxy}) { 
     687                    $data->{is_proxy}=1; 
     688                    $data->{__reason} = "Found proxy at ".$_->{proxy}; 
     689                } 
     690            } 
     691        } 
     692        return $data->{proxycheck_moderate} ? MODERATE : BLOCK if($data->{is_proxy}); 
    657693    } 
    658694    # no port matched - no proxy