# in progress.
# based on geo.pl
# should be closer to finger.pl? hostname/list?

require 'chat2.pl';


sub listen {
        local($secs) = @_;
        local($return,$tmp) = "";
        while (length($tmp = &chat'expect($secs, '(.|\n)+', '$&'))) {
                print $tmp if $trace;
                $return .= $tmp;
        }
	$return;
}
# Call-Sign: N1DPU                    Class: TECHNICIAN
# Previously: KA1MRJ                  Class: NOVICE
# Real Name: MARK W EICHIN            Birthday: FEB 7, 1967
# Mailing Address: 15 POLARIS DR, NEW MILFORD, CT  06776
# Station Address: SAME AS MAILING ADDRESS
# Valid From: JUL 12, 1985            To: JUL 12, 1995
# Records Last Processed: JUL 12, 1985

sub do_callsign {
    local($args)=@_;
    $args =~ m,\?(.+),;
    $args = $1;
($args =~ s/\+/ /g);

    $request = $args;

    if(!$request){
	 alarm($time_out);
	 print "<isindex><h1>Enter the amateur radio callsign you wish to look up</h1>";
	 print "e.g. \"N1DPU\" <p>";
	 print "This server contains mostly information on locations within the US\n";
	 print "and is provided by the University of Buffalo.<p>";
	 print "Gateway written by <A HREF=\"/people/eichin.html\">Mark Eichin</A>\n";
	 alarm(0);
	 return;
    }
print "<isindex>";

&chat'open_port('callsign.cs.buffalo.edu', 2000) || die "open: $!";
$_=&listen(2);
# particularly bogus possible behaviour. 
## < 0x0   fffb01fffb03
## RCVD will ECHO
## SENT do ECHO
## RCVD will SUPPRESS GO AHEAD
## SENT do SUPPRESS GO AHEAD
## > 0x0   fffd01fffd03

if($_ eq "\377\373\001\377\373\003") {
    &chat'print("\377\375\001\377\375\003");
}

while(!/Callbook/){
$_=&listen(5);
}
   alarm($time_out);
print("<h1>Amateur License Callbook Query:  \"$request\"</h1><pre>\n");

if($request =~ /^info$/i) {
    &chat'print("more 0\n\r");
    &chat'print("info\n\r");
} else {
    &chat'print("call $request\n\r");
}
$_=&listen(3);
split(/\n/);
shift; # skip the echo'ed query
foreach $dataline (@_){
	chop($dataline);
	print("$dataline\n") if ($dataline ne ">>");
}
&chat'print("quit\n\r");
print "</pre>";
		alarm(0);
}
