]> matita.cs.unibo.it Git - helm.git/commitdiff
Various changes:
authorStefano Zacchiroli <zack@upsilon.cc>
Fri, 16 Mar 2001 16:34:24 +0000 (16:34 +0000)
committerStefano Zacchiroli <zack@upsilon.cc>
Fri, 16 Mar 2001 16:34:24 +0000 (16:34 +0000)
- added "patch_dtd" parameter to /getciconly method
- removed "remove_header" feature to the download subroutine
- patched response in gz file answering (now use x-gzip encoding header)
- remove /conf method
- removed hard coded "localhost" url

helm/http_getter/http_getter.pl.in

index 44001955c7570652434640874f17bc1fd6ddefec..b1840c8f11df3fddf3dd37f08a6744a192c01e0f 100755 (executable)
@@ -110,13 +110,18 @@ while (my $c = $d->accept) {
             # 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/;
@@ -141,10 +146,10 @@ while (my $c = $d->accept) {
                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;
@@ -161,7 +166,7 @@ while (my $c = $d->accept) {
                $cont .= $_;
               }
                close(FD);
-               answer($c,$cont);
+               answer($c,$cont,"normal");
             } else {
                die "Could not find DTD!";
             }
@@ -176,7 +181,7 @@ while (my $c = $d->accept) {
                $cont .= $_;
               }
                close(FD);
-               answer($c,$cont);
+               answer($c,$cont,"normal");
             } else {
                die "Could not find Style Configuration File!";
             }
@@ -196,27 +201,17 @@ while (my $c = $d->accept) {
                 $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/&/&amp;/g;
-            $quoted_html_link =~ s/</&lt;/g;
-            $quoted_html_link =~ s/>/&gt;/g;
-            $quoted_html_link =~ s/'/&apos;/g;
-            $quoted_html_link =~ s/"/&quot;/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);
@@ -236,22 +231,22 @@ 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,"<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";
@@ -327,7 +322,7 @@ sub finduris { # find uris for cic and theory trees generation
  } 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";
@@ -444,9 +439,8 @@ sub gzip {  # gzip the content argument and save it to filename argument
        $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
@@ -529,10 +523,7 @@ sub download
    }
    # $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") {
@@ -551,11 +542,14 @@ sub download
  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);
 }