print "\nUnescaped query: ".$http_query."\n";
- if ($http_method eq 'GET' and $http_path eq "/getciconly") {
+ if ($http_method eq 'GET' and $http_path eq "/getxml") {
# finds the uri, url and filename
my $cicuri = $inputuri;
my $answerformat = $cgi->param('format');
$cicfilename =~ s/theory:(.*)/$1/;
my $cicurl = $map{$cicuri};
+ if (not defined($cicurl)) {
+ die "uri \"$cicuri\" can't be resolved\n";
+ }
my $extension;
if ($cicurl =~ /\.xml$/) { # non gzipped file
$extension = ".xml";
my $ciccontent = download($patch_dtd,"cic",$cicurl,$cicfilename,$answerformat);
# Answering the client
- answer($c,$ciccontent,$answerformat);
+ answer($c,$ciccontent,"text/xml","x-gzip");
}
+ } elsif ($http_method eq 'GET' and $http_path eq "/resolve") {
+ my $outputurl = $map{$inputuri};
+ $outputurl = "" if (not defined($outputurl));
+ $cont = "<?xml version=\"1.0\" ?>\n\n";
+ if ($outputurl eq "") {
+ $cont .= "<unresolved />\n";
+ } else {
+ $cont .= "<url value=\"$outputurl\" />\n";
+ }
+ answer($c,$cont,"text/xml","");
} elsif ($http_method eq 'GET' and $http_path eq "/getdtd") {
my $filename = $inputuri;
$filename = $dtd_dir."/".$filename;
$cont .= $_;
}
close(FD);
- answer($c,$cont,"normal");
+ answer($c,$cont,"text/xml","");
} else {
die "Could not find DTD!";
}
$cont .= $_;
}
close(FD);
- answer($c,$cont,"normal");
+ answer($c,$cont,"text/plain","");
} else {
die "Could not find Style Configuration File!";
}
$cont .= $_;
}
close(FD);
- answer($c,$cont,"normal");
+ answer($c,$cont,"text/xml","");
} else {
die "Could not find XSLT!";
}
mk_urls_of_uris();
kill(USR1,getppid()); # signal changes to parent
print " done\n";
- answer($c,"<html><body><h1>Update done</h1></body></html>","normal");
+ answer($c,"<html><body><h1>Update done</h1></body></html>","text/html","");
} elsif ($http_method eq 'GET' and $http_path eq "/ls") {
# send back keys that begin with a given uri
my ($uritype,$uripattern,$uriprefix);
if (($outype ne 'txt') and ($outype ne 'xml')) { # invalid out type
print "Invalid output type specified: $outype\n";
answer($c,"<html><body><h1>Invalid output type, may be ".
- "\"txt\" or \"xml\"</h1></body></html>","normal");
+ "\"txt\" or \"xml\"</h1></body></html>","text/html","");
} else { # valid output
print "BASEURI $baseuri, FORMAT $outype\n";
$cont = finduris($uritype,$uripattern,$outype);
- answer($c,$cont,"normal");
+ if ($outype eq 'txt') {
+ answer($c,$cont,"text/plain","");
+ } elsif ($outype eq 'xml') {
+ answer($c,$cont,"text/xml","");
+ } else {
+ die "Internal error, exiting!";
+ }
}
} else { # invalid uri
print "Invalid uri: $baseuri, may begin with 'cic:', ".
"'theory:' or '*:'\n";
answer($c,"<html><body><h1>Invalid uri , may begin with ".
- "\"cic:\", \"theory:\" or \"*:\"</h1></body></html>","normal");
+ "\"cic:\", \"theory:\" or \"*:\"</h1></body></html>","text/html","");
}
} elsif ($http_method eq 'GET' and $http_path eq "/help") {
print "Help requested!";
answer($c,"<html><body><h1>HTTP Getter Version ".
- $VERSION."</h1></body></html>","normal");
+ $VERSION."</h1></body></html>","text/html","");
} else {
print "\n";
print "INVALID REQUEST!!!!!\n";
}
} elsif ($format eq "xml") { # XML output
$content .= '<?xml version="1.0" encoding="ISO-8859-1"?>' . "\n";
- $content .= '<!DOCTYPE ls SYSTEM ';
- $content .= "$myownurl/getdtd?uri=ls.dtd>" . "\n\n";
+ $content .= "<!DOCTYPE ls SYSTEM ";
+ $content .= "\"$myownurl/getdtd?uri=ls.dtd\">" . "\n\n";
$content .= "<ls>\n";
foreach $key (sort(keys %dirs)) {
$content .= "\t<section>$key</section>\n";
}
sub answer {
- my ($c,$cont,$contype) = @_; # $contype must be "normal" or "gz"
+ my ($c,$cont,$contype,$contenc) = @_;
my $res = new HTTP::Response;
$res->content($cont);
- $res->push_header("Content-Type" => "text/xml");
- if ($contype eq "gz") {
- $res->push_header("Content-Encoding" => "x-gzip");
- }
+ $res->push_header("Content-Type" => $contype);
+ $res->push_header("Content-Encoding" => $contenc)
+ unless ($contenc eq "");
$c->send_response($res);
}