]> matita.cs.unibo.it Git - helm.git/commitdiff
update method added; now returns NOT_FOUND if the document is not found
authorClaudio Sacerdoti Coen <claudio.sacerdoticoen@unibo.it>
Fri, 1 Dec 2000 19:59:41 +0000 (19:59 +0000)
committerClaudio Sacerdoti Coen <claudio.sacerdoticoen@unibo.it>
Fri, 1 Dec 2000 19:59:41 +0000 (19:59 +0000)
helm/http_getter/http_getter.pl

index ccc8a82b81f6deece6e8161c0cd85e313b715bc5..769a47cc3ef14bb169a49d11bd0267f06585875f 100755 (executable)
@@ -27,6 +27,7 @@ print "helm_dir: $helm_dir\n";
 print "dtd_dir: $dtd_dir\n";
 print "urls_of_uris.db: $uris_dbm.db\n";
 $SIG{CHLD} = "IGNORE"; # do not accumulate defunct processes
+$SIG{USR1} = \&update; # sent by the child to make the parent update
 while (my $c = $d->accept) {
  if (fork() == 0) {
     while (my $r = $c->get_request) {
@@ -48,14 +49,18 @@ while (my $c = $d->accept) {
             $cicfilename = $helm_dir.$cicfilename.".xml";
 
             my $cicurl   = $map{$cicuri};
+            if (!defined($cicurl)) {
+             print "\nNOT FOUND!!!!!\n";
+             $c->send_error(RC_NOT_FOUND)
+            } else {
+               print_request("cic",$cicuri,$cicurl,$cicfilename);
 
-            print_request("cic",$cicuri,$cicurl,$cicfilename);
-
-            # Retrieves the file
-            my $ciccontent = download(0,"cic",$cicurl,$cicfilename);
+               # Retrieves the file
+               my $ciccontent = download(0,"cic",$cicurl,$cicfilename);
 
-            # Answering the client
-            answer($c,$ciccontent);
+               # Answering the client
+               answer($c,$ciccontent);
+            }
         } elsif ($http_method eq 'GET' and $http_path eq "/get") {
             # finds the uris, urls and filenames
             my $cicuri = $inputuri,
@@ -91,23 +96,30 @@ while (my $c = $d->accept) {
             my $typesurl = $map{$typesuri} if $typesuri;
             my $annurl   = $map{$annuri}  if $annuri;
 
-            print_request("cic",$cicuri,$cicurl,$cicfilename);
-            print_request("types",$typesuri,$typesurl,$typesfilename)
-             if ($typesuri);
-            print_request("ann",$annuri,$annurl,$annfilename)
-             if ($annuri);
-
-            # Retrieves the files
-
-            my $ciccontent = download(1,"cic",$cicurl,$cicfilename);
-            my $typescontent =
-             download(1,"types",$typesurl,$typesfilename) if ($typesuri);
-            my $anncontent =
-             download(1,"ann",$annurl,$annfilename) if ($annuri);
-
-            # Merging the files together
-
-            my $merged = <<EOT;
+            if (!defined($cicurl) ||
+               (!defined($typesurl) && $typesuri) ||
+               (!defined($annuri) && $annuri))
+            {
+             print "\nNOT FOUND!!!!!\n";
+             $c->send_error(RC_NOT_FOUND)
+            } else {
+               print_request("cic",$cicuri,$cicurl,$cicfilename);
+               print_request("types",$typesuri,$typesurl,$typesfilename)
+                if ($typesuri);
+               print_request("ann",$annuri,$annurl,$annfilename)
+                if ($annuri);
+               # Retrieves the files
+
+               my $ciccontent = download(1,"cic",$cicurl,$cicfilename);
+               my $typescontent =
+                download(1,"types",$typesurl,$typesfilename) if ($typesuri);
+               my $anncontent =
+                download(1,"ann",$annurl,$annfilename) if ($annuri);
+               # Merging the files together
+               my $merged = <<EOT;
 <?xml version="1.0" encoding="UTF-8"?>
 <cicxml uri="$cicuri">
 $ciccontent
@@ -116,8 +128,9 @@ $anncontent
 </cicxml>
 EOT
 
-            # Answering the client
-            answer($c,$merged);
+               # Answering the client
+               answer($c,$merged);
+            }
          } elsif ($http_method eq 'GET' and $http_path eq "/getdtd") {
             my $filename = $inputuri;
             $filename = $dtd_dir."/".$filename;
@@ -142,6 +155,12 @@ EOT
             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") {
+           print "Update requested...";
+           update();
+           kill(USR1,getppid());
+           print " done\n";
+           answer($c,"<html><body><h1>Update done</h1></body></html>");
         } else {
             print "\nINVALID REQUEST!!!!!\n";
             $c->send_error(RC_FORBIDDEN)
@@ -221,3 +240,8 @@ sub answer
  $res->content($cont);
  $c->send_response($res);
 }
+
+sub update {
+ untie %map;
+ tie(%map, 'DB_File', $uris_dbm.".db", O_RDONLY, 0664);
+}