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) {
$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,
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
</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;
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)
$res->content($cont);
$c->send_response($res);
}
+
+sub update {
+ untie %map;
+ tie(%map, 'DB_File', $uris_dbm.".db", O_RDONLY, 0664);
+}