#!/usr/bin/perl -w


## begin POD documentation

=head1 NAME

    validator - a program for validating urls

    
=head1 SYNOPSIS

    validator [-t,--timeout timeout]
    
=head1 DESCRIPTION
    
    this program simply checks out a url and makes sure
    that it is not a dead link.

=head1 OPTIONS

=over4
=item -t --timeout timeout
    set the maximum amount of time to wait for a response
    from the server in seconds. default is 10 seconds.
    
=head1 RETURN VALUE

    returns 'good' if the url is fetched without error. returns
    'bad' if errors are encountered. these are not to be taken as
    moral judgements of the page fetched, merely whether it is
    reachable.
    
=head1 EXAMPLES

    % validate -t 5
    http://www.nonexistantdomain.com
    bad
    http://www.perl.com
    good
    
=head1 ENVIRONMENT

    requires a proper network network connection. duh.
    LWP::UserAgent module must be available
    
=head1 AUTHOR

    MAD, llc
    
    anders pearson <F<anp8@columbia.edu>>
    david masao dodobara <F<dmd69@columbia.edu>>
    guillermo m ramos <F<gmr9@columbia.edu>>
    karl mcclare questelles <F<kmq2@columbia.edu>>
    miriam shana adlerstein <F<msa22@columbia.edu>>

=head1 SEE ALSO

    artemis         the main manpage for the artemis
                    mp3 search engine
    artemis-spider  the background spidering program
    db-wrapper      a nice wrapper for the database
    
=head1 BUGS

    none that we know of yet.

=head1 RESTRICTIONS

    does not handle proxies yet. probably never will.
    only deals with the basic protocals that LWP::UserAgent
    handles automatically.

=head1 HISTORY

    2000-02-28 -- anders
        genesis.

=cut

    ## end POD documentation
    
use strict;
require LWP::UserAgent;

# handle arguments
# default to 10 seconds if no arguments present
my $timeout = (
              (($ARGV[0] eq '-t' ) ||
               ($ARGV[0] eq '--timeout')) &&
              ($ARGV[1])) ? $ARGV[1] : 10;

# create our user agent and set its attributes
my $ua = new LWP::UserAgent;
$ua->agent('Artemis Validator/0.1');
$ua->from('anp8@columbia.edu');
$ua->timeout($timeout);
$ua->max_size(1024);


while(<STDIN>){

    # do this for every line sent in
    my $request = new HTTP::Request('GET',$_);
    my $response = $ua->request($request);
    
    if($response->is_success){
	print "good\n";  # we got the file
    } else {
	print "bad\n";   # we got a 404, 403, 500, etc
    }
}

# -------------- END validator ------------ #



