From 3ca1c8d46b0cb920dffaaa8538a10f7a0929b093 Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Fri, 16 Mar 2001 18:17:18 +0000 Subject: [PATCH] - renamed /getciconly in /getxml - added control on not existent url - added /resolve method --- helm/http_getter/Makefile.in | 2 +- helm/http_getter/http_getter.pl.in | 52 ++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/helm/http_getter/Makefile.in b/helm/http_getter/Makefile.in index 26771201b..5aebd5a9e 100644 --- a/helm/http_getter/Makefile.in +++ b/helm/http_getter/Makefile.in @@ -5,7 +5,7 @@ all: install: cp http_getter.pl $(INSTALL_DIR) - cp *.cgi $(INSTALL_DIR) + cp *.cgi $(INSTALL_DIR) clean: diff --git a/helm/http_getter/http_getter.pl.in b/helm/http_getter/http_getter.pl.in index 483b71b1d..484041c8e 100755 --- a/helm/http_getter/http_getter.pl.in +++ b/helm/http_getter/http_getter.pl.in @@ -106,7 +106,7 @@ while (my $c = $d->accept) { 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'); @@ -128,6 +128,9 @@ while (my $c = $d->accept) { $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"; @@ -149,8 +152,18 @@ while (my $c = $d->accept) { 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 = "\n\n"; + if ($outputurl eq "") { + $cont .= "\n"; + } else { + $cont .= "\n"; + } + answer($c,$cont,"text/xml",""); } elsif ($http_method eq 'GET' and $http_path eq "/getdtd") { my $filename = $inputuri; $filename = $dtd_dir."/".$filename; @@ -166,7 +179,7 @@ while (my $c = $d->accept) { $cont .= $_; } close(FD); - answer($c,$cont,"normal"); + answer($c,$cont,"text/xml",""); } else { die "Could not find DTD!"; } @@ -181,7 +194,7 @@ while (my $c = $d->accept) { $cont .= $_; } close(FD); - answer($c,$cont,"normal"); + answer($c,$cont,"text/plain",""); } else { die "Could not find Style Configuration File!"; } @@ -201,7 +214,7 @@ while (my $c = $d->accept) { $cont .= $_; } close(FD); - answer($c,$cont,"normal"); + answer($c,$cont,"text/xml",""); } else { die "Could not find XSLT!"; } @@ -211,7 +224,7 @@ while (my $c = $d->accept) { mk_urls_of_uris(); kill(USR1,getppid()); # signal changes to parent print " done\n"; - answer($c,"

Update done

","normal"); + answer($c,"

Update done

","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); @@ -231,22 +244,28 @@ while (my $c = $d->accept) { if (($outype ne 'txt') and ($outype ne 'xml')) { # invalid out type print "Invalid output type specified: $outype\n"; answer($c,"

Invalid output type, may be ". - "\"txt\" or \"xml\"

","normal"); + "\"txt\" or \"xml\"","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,"

Invalid uri , may begin with ". - "\"cic:\", \"theory:\" or \"*:\"

","normal"); + "\"cic:\", \"theory:\" or \"*:\"","text/html",""); } } elsif ($http_method eq 'GET' and $http_path eq "/help") { print "Help requested!"; answer($c,"

HTTP Getter Version ". - $VERSION."

","normal"); + $VERSION."","text/html",""); } else { print "\n"; print "INVALID REQUEST!!!!!\n"; @@ -321,8 +340,8 @@ sub finduris { # find uris for cic and theory trees generation } } elsif ($format eq "xml") { # XML output $content .= '' . "\n"; - $content .= '" . "\n\n"; + $content .= "" . "\n\n"; $content .= "\n"; foreach $key (sort(keys %dirs)) { $content .= "\t
$key
\n"; @@ -543,13 +562,12 @@ sub download { } 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); } -- 2.39.2