--- wwwis Thu Apr 2 17:15:25 1998 +++ my_wwwis Fri Apr 3 13:54:37 1998 @@ -17,7 +17,7 @@ use strict; use File::Copy; -use Socket; +use LWP::UserAgent; if( ! $\ ){ # this stops the error Use of uninitialized value at .../File/Copy.pm line 84 @@ -690,81 +690,66 @@ sub URLsize { - my($five) = @_; - my($dummy, $dummy, $server, $url); + my($url) = @_; - my( $x,$y) = (0,0); + my($x,$y) = (0,0); + my($ua, $request, $response); - print "URLsize: $five\n" if $debug; + print "URLsize: $url\n" if $debug; # first check the hash table (if we're using one) if(&istrue($UseHash) && - $hashx{$five} && - $hashy{$five} ){ + $hashx{$url} && + $hashy{$url} ){ print "Hash " if $debug; - $x=$hashx{$five}; - $y=$hashy{$five}; + $x=$hashx{$url}; + $y=$hashy{$url}; return($x,$y); } + + $ua = new LWP::UserAgent; + $ua->agent("WWWis/2.20 " . $ua->agent); if( $Proxy =~ /\S+/ ){ - ($dummy, $dummy, $server, $url) = split(/\//, $Proxy, 4); - $url=$five; - } else { - ($dummy, $dummy, $server, $url) = split(/\//, $five, 4); - $url= '/' . $url; - } - - my($them,$port) = split(/:/, $server); - my( $iaddr, $paddr, $proto ); - - $port = 80 unless $port; - $them = 'localhost' unless $them; + $ua->proxy(http => $Proxy); + } - print "\nThey are $them on port $port\n" if $debug;# && $Proxy; print "url is $url\n" if $debug; $_=$url; - if( /gif/i || /jpeg/i || /jpg/i || /xbm/i ){ - $iaddr= inet_aton( $them ); - $paddr= sockaddr_in( $port, $iaddr ); - $proto=getprotobyname('tcp'); - - # Make the socket filehandle. - - if(socket(STRM, PF_INET, SOCK_STREAM, $proto) && - connect(STRM,$paddr) ){ - # Set socket to be command buffered. - select(STRM); $| = 1; select(STDOUT); - - print "Getting $url\n" if $debug; - - print STRM "GET $url\n\n"; - - if ($url =~ /\.jpg$/i || $url =~ /\.jpeg$/i) { - ($x,$y) = &jpegsize(\*STRM); - } elsif($url =~ /\.gif$/i) { - ($x,$y) = &gifsize(\*STRM); - } elsif($url =~ /\.xbm$/i) { - ($x,$y) = &xbmsize(\*STRM); - } elsif($url =~ /\.png$/i) { - ($x,$y) = &pngsize(\*STRM); - } else { - print "$url is not gif, jpeg, xbm or png (or has stupid name)"; - } - close ( STRM ); + print "Getting $url\n" if $debug; + + $request = new HTTP::Request 'GET' => "$url"; + + $response = $ua->request($request, "/tmp/wwwis.$$"); + if ($response->is_success && open(STRM, "/tmp/wwwis.$$")){ + binmode( STRM ); # for crappy MS OSes - Win/Dos/NT use is NOT SUPPORTED + + print "Content type: ", $response->content_type, "\n" if $debug; + + if ($response->content_type eq 'image/jpeg') { + ($x,$y) = &jpegsize(\*STRM); + } elsif($response->content_type eq 'image/gif') { + ($x,$y) = &gifsize(\*STRM); + } elsif($response->content_type eq 'image/xbm') { + ($x,$y) = &xbmsize(\*STRM); + } elsif($response->content_type eq 'image/png') { + ($x,$y) = &pngsize(\*STRM); } else { - # there was a problem - print "ERROR: $!"; - } + print "$url is not gif, jpeg, xbm or png (or has stupid content type)"; + } + close ( STRM ); + unlink ( "/tmp/wwwis.$$" ); } else { - print "$url is not gif, xbm or jpeg (or has stupid name)"; + # there was a problem + print "ERROR: $!"; } + if(&istrue($UseHash) && $x && $y){ - $hashx{$five}=$x; - $hashy{$five}=$y; + $hashx{$url}=$x; + $hashy{$url}=$y; } return ($x,$y); }