Michael Wray wrote:

> Hello,
> 
> I am writing a redirector script for SQUID, and when I use URI to parse 
> the URL, URI is not functioning the same in "redirector" mode as it is 
> under command line mode...
> 
> i.e. The only difference is where the URL is coming from..and URI 
> doesn't appear to fully function, here is the code:

> At any rate all those strings are empty in the first method passed the 
> exact same string..
> 
> Any CLues?


It could be your shell is having trouble with the wildcard chars, try
quoting the URL:

myscript.pl "http://www.playboy.com/somepath/somedoc.html?var=some&var2=else";

Rewrote the code to:

use URI;

# MAIN URI Doesn't WORK Right
# Errors out with:Cannot find Method{host} in _generic.
# Nothing is parsed correctly...

$| = 1;
my $debug = 1;

if (0) {                        # set to 1 to test this method

while (<STDIN>) {       # is your intent to pass filenames as args here ?
                        # or to read from STDIN ?
# 
my @X = split;
# 
my $url = $X[0];

        chomp;
        my $url = $_;
        print "url='$url'\n";

        my @url_array = parse_url ($url);
        my %url_hash;
        @url_hash{'scheme', 'opaque', 'authority', 'path', 'fragment', 'host',
          'query'} = @url_array;
        print "The contents of @url_array" if $debug;

        my $mask = do_lookup ($url_hash{host});
        if ($mask > 0) {
                print "http://auth1.s4f.com/blocked.asp\n";;
        } else {
                print "$url\n";
        }
        exit;
}

}       # end reading from STDIN method

# MAIN URI Works
# same program but instead of taking input from STDIN, takes input from
# command line..same input..a URL. even prints the same

my $url = $ARGV[0];
my @url_array = parse_url ($url);
my %url_hash;
@url_hash{'scheme', 'opaque', 'authority', 'path', 'fragment', 'host',
   'query'} = @url_array;
print "The contents of @url_array" if $debug;

my $mask = do_lookup ($url_hash{host});
if ($mask > 0) {
        print "http://auth1.s4f.com/blocked.asp\n";;
} else {
        print "$url\n";
}

# Parse URL

sub parse_url {
        my $URL = shift;

print STDERR "URL=$URL\n" if $debug;

my $u = URI->new($URL);
print &Data::Dumper::Dumper(\$u);
my $scheme = $u->scheme;
my $opaque = $u->opaque;
my $authority = $u->authority;
my $path = $u->path;
my $fragment = $u->fragment;
my $host = $u->host;
my $query = $u->query;
my @response = ($scheme, $opaque, $authority, $path, $fragment, $host, $query);

print STDERR "scheme=$scheme\n" if $debug;
print STDERR "opaque=$opaque\n" if $debug;
print STDERR "authority=$authority\n" if $debug;
print STDERR "path=$path\n" if $debug;
print STDERR "fragment=$fragment\n" if $debug;
print STDERR "host=$host\n" if $debug;
print STDERR "query=$query\n" if $debug;

return @response;

}

sub do_lookup {
        my $mask = 0;
# Do SOME STUFF TO Find a mask for the URL.
return $mask;

}

__END__




-- 
   ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
  (_/   /  )    // //       DBE Collectibles   Mailto:[EMAIL PROTECTED]
   / ) /--<  o // //      http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/

_______________________________________________
Perl-Unix-Users mailing list. To unsubscribe go to 
http://listserv.ActiveState.com/mailman/subscribe/perl-unix-users

Reply via email to