# finds the uri, url and filename
my $cicuri = $inputuri;
my $answerformat = $cgi->param('format');
+ my $patch_dtd = $cgi->param('patch_dtd');
$answerformat = "" if (not defined($answerformat));
-
+ $patch_dtd = "" if (not defined($patch_dtd));
if (($answerformat ne "gz") and ($answerformat ne "normal")
and ($answerformat ne "")) {
die "Wrong output format: $answerformat, must be 'normal' ".
"or 'gz'\n";
}
+ if (($patch_dtd ne "yes") and ($patch_dtd ne "no")
+ and ($patch_dtd ne "")) {
+ die "Wrong param, patch_dtd must be 'yes' or 'no'\n";
+ }
my $cicfilename = $cicuri;
$cicfilename =~ s/cic:(.*)/$1/;
print_request("cic",$cicuri,$cicurl,$cicfilename);
# Retrieves the file
- my $ciccontent = download(0,"cic",$cicurl,$cicfilename,$answerformat);
+ my $ciccontent = download($patch_dtd,"cic",$cicurl,$cicfilename,$answerformat);
# Answering the client
- answer($c,$ciccontent);
+ answer($c,$ciccontent,$answerformat);
}
} elsif ($http_method eq 'GET' and $http_path eq "/getdtd") {
my $filename = $inputuri;
$cont .= $_;
}
close(FD);
- answer($c,$cont);
+ answer($c,$cont,"normal");
} else {
die "Could not find DTD!";
}
$cont .= $_;
}
close(FD);
- answer($c,$cont);
+ answer($c,$cont,"normal");
} else {
die "Could not find Style Configuration File!";
}
$cont .= $_;
}
close(FD);
- answer($c,$cont);
+ answer($c,$cont,"normal");
} else {
die "Could not find XSLT!";
}
- } elsif ($http_method eq 'GET' and $http_path eq "/conf") {
- my $quoted_html_link = $html_link;
- $quoted_html_link =~ s/&/&/g;
- $quoted_html_link =~ s/</</g;
- $quoted_html_link =~ s/>/>/g;
- $quoted_html_link =~ s/'/'/g;
- $quoted_html_link =~ s/"/"/g;
- print "\nConfiguration requested, returned #$quoted_html_link#\n";
- $cont = "<?xml version=\"1.0\"?><html_link>$quoted_html_link</html_link>";
- answer($c,$cont);
} elsif ($http_method eq 'GET' and $http_path eq "/update") {
# rebuild urls_of_uris.db
print "Update requested...\n";
mk_urls_of_uris();
kill(USR1,getppid()); # signal changes to parent
print " done\n";
- answer($c,"<html><body><h1>Update done</h1></body></html>");
+ answer($c,"<html><body><h1>Update done</h1></body></html>","normal");
} 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>");
+ "\"txt\" or \"xml\"</h1></body></html>","normal");
} else { # valid output
print "BASEURI $baseuri, FORMAT $outype\n";
$cont = finduris($uritype,$uripattern,$outype);
- answer($c,$cont);
+ answer($c,$cont,"normal");
}
} 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>");
+ "\"cic:\", \"theory:\" or \"*:\"</h1></body></html>","normal");
}
} 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>");
+ $VERSION."</h1></body></html>","normal");
} 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 .= '"http://localhost:8081/getdtd?uri=ls.dtd">' . "\n\n";
+ $content .= "$myownurl/getdtd?uri=ls.dtd>" . "\n\n";
$content .= "<ls>\n";
foreach $key (sort(keys %dirs)) {
$content .= "\t<section>$key</section>\n";
$gz->gzclose();
}
-sub download
-{
- my ($remove_headers,$str,$url,$filename,$format) = @_;
+sub download {
+ my ($patch_dtd,$str,$url,$filename,$format) = @_;
my ($gz, $buffer);
#my $debug=1; # for DEBUG only
}
# $cont now contained uncompressed data
}
- if ($remove_headers) {
- $cont =~ s/<\?xml [^?]*\?>//sg;
- $cont =~ s/<!DOCTYPE [^>]*>//sg;
- } else {
+ if ($patch_dtd eq "yes") {
$cont =~ s/DOCTYPE (.*) SYSTEM\s+"http:\/\/www.cs.unibo.it\/helm\/dtd\//DOCTYPE $1 SYSTEM "$myownurl\/getdtd?uri=/g;
}
if ($format eq "gz") {
return $cont;
}
-sub answer
-{
- my ($c,$cont) = @_;
+sub answer {
+ my ($c,$cont,$contype) = @_; # $contype must be "normal" or "gz"
my $res = new HTTP::Response;
$res->content($cont);
+ $res->push_header("Content-Type" => "text/plain");
+ if ($contype eq "gz") {
+ $res->push_header("Content-Encoding" => "x-gzip");
+ }
$c->send_response($res);
}