From 975ab2f71a5e39379d44a494d73b8e05a8a0ad5d Mon Sep 17 00:00:00 2001 From: Claudio Sacerdoti Coen Date: Fri, 24 Nov 2000 14:41:40 +0000 Subject: [PATCH] http_getter reimplemented from scratch --- .../local/etc/helm/configuration.xml | 2 +- helm/header/setheader.xsl | 2 +- helm/http_getter/http_getter.pl | 363 ++++++------------ helm/interface/getter.ml | 4 +- helm/interface/pxpUriResolver.ml | 6 +- helm/style/basic.xsl | 2 +- helm/style/content.xsl | 8 +- helm/style/content_to_html.xsl | 2 +- helm/style/html_init.xsl | 2 +- helm/style/html_reals.xsl | 2 +- helm/style/html_set.xsl | 2 +- helm/style/mmlextension.xsl | 16 +- helm/style/proofs.xsl | 2 +- helm/style/reals.xsl | 2 +- helm/style/ricerca.xsl | 2 +- helm/style/set.xsl | 2 +- helm/style/theory_content.xsl | 2 +- 17 files changed, 155 insertions(+), 266 deletions(-) diff --git a/helm/configuration/local/etc/helm/configuration.xml b/helm/configuration/local/etc/helm/configuration.xml index c0ce319b7..29672d5e1 100644 --- a/helm/configuration/local/etc/helm/configuration.xml +++ b/helm/configuration/local/etc/helm/configuration.xml @@ -18,5 +18,5 @@ http://localhost/cgi-bin/helm/webeqp.pl http://localhost/cgi-bin/helm/use_webeqp.pl ?baseurl=&stylesheet1=rootcontent.xsl&stylesheet2=content_to_html.xsl&xmluri= - http://localhost:8081/getwithtypes?url= + http://localhost:8081/get?uri= diff --git a/helm/header/setheader.xsl b/helm/header/setheader.xsl index a1ba13199..a5f6a7f89 100644 --- a/helm/header/setheader.xsl +++ b/helm/header/setheader.xsl @@ -8,7 +8,7 @@ -http://localhost:8081/get?url= +http://localhost:8081/get?uri= diff --git a/helm/http_getter/http_getter.pl b/helm/http_getter/http_getter.pl index 884bbc307..ccc8a82b8 100755 --- a/helm/http_getter/http_getter.pl +++ b/helm/http_getter/http_getter.pl @@ -16,7 +16,10 @@ use HTTP::Request; use LWP::UserAgent; use DB_File; -my $cont = ""; +#CSC: mancano i controlli sulle condizioni di errore di molte funzioni +#CSC: ==> non e' robusto +#CSC: altra roba da sistemare segnata con CSC + my $d = new HTTP::Daemon LocalPort => 8081; tie(%map, 'DB_File', $uris_dbm.".db", O_RDONLY, 0664); print "Please contact me at: url, ">\n"; @@ -29,256 +32,103 @@ while (my $c = $d->accept) { while (my $r = $c->get_request) { #CSC: mancano i controlli di sicurezza - $cont = ""; - my $cicuri = $r->url; - $cicuri =~ s/^[^?]*\?url=(.*)/$1/; - print "*".$r->url."\n"; + my $inputuri = $r->url; + $inputuri =~ s/^[^?]*\?uri=(.*)/$1/; + print "\nRequest: ".$r->url."\n\n"; my $http_method = $r->method; my $http_path = $r->url->path; - if ($http_method eq 'GET' and $http_path eq "/get") { - my $filename = $cicuri; - $filename =~ s/cic:(.*)/$1/; - $filename =~ s/theory:(.*)/$1/; - $filename = $helm_dir.$filename.".xml"; - my $resolved = $map{$cicuri}; - print "$cicuri ==> $resolved ($filename)\n"; - if (stat($filename)) { - print "Using local copy\n"; - open(FD, $filename); - while() { $cont .= $_; } - close(FD); - my $res = new HTTP::Response; - $res->content($cont); - $c->send_response($res); - } else { - print "Downloading\n"; - $ua = LWP::UserAgent->new; - $request = HTTP::Request->new(GET => "$resolved"); - $response = $ua->request($request, \&callback); - - print "Storing file\n"; - mkdirs($filename); - open(FD, ">".$filename); - print FD $cont; - close(FD); - my $res = new HTTP::Response; - $res->content($cont); - $c->send_response($res); - } - } elsif ($http_method eq 'GET' and $http_path eq "/annotate") { - my $do_annotate = ($cicuri =~ /\.ann$/); - my $target_to_annotate = $cicuri; - $target_to_annotate =~ s/(.*)\.ann$/$1/ if $do_annotate; - my $filename = $cicuri; - $filename =~ s/cic:(.*)/$1/; - $filename =~ s/theory:(.*)/$1/; - my $filename_target = $helm_dir.$filename if $do_annotate; - $filename = $helm_dir.$filename.".xml"; - $filename_target =~ s/(.*)\.ann$/$1.xml/ if $do_annotate; - my $resolved = $map{$cicuri}; - my $resolved_target = $map{$target_to_annotate} if $do_annotate; - if ($do_annotate) { - print "($cicuri, $target_to_annotate) ==> ($resolved + $resolved_target) ($filename)\n"; - } else { - print "$cicuri ==> $resolved ($filename)\n"; - } - - # Retrieves the annotation - - if (stat($filename)) { - print "Using local copy for the annotation\n"; - open(FD, $filename); - while() { $cont .= $_; } - close(FD); - } else { - print "Downloading the annotation\n"; - $ua = LWP::UserAgent->new; - $request = HTTP::Request->new(GET => "$resolved"); - $response = $ua->request($request, \&callback); - - print "Storing file for the annotation\n"; - mkdirs($filename); - open(FD, ">".$filename); - print FD $cont; - close(FD); - } - my $annotation = $cont; + if ($http_method eq 'GET' and $http_path eq "/getciconly") { + # finds the uri, url and filename + my $cicuri = $inputuri; - # Retrieves the target to annotate + my $cicfilename = $cicuri; + $cicfilename =~ s/cic:(.*)/$1/; + $cicfilename =~ s/theory:(.*)/$1/; + $cicfilename = $helm_dir.$cicfilename.".xml"; - $cont = ""; - if ($do_annotate) { - if (stat($filename_target)) { - print "Using local copy for the file to annotate\n"; - open(FD, $filename_target); - while() { $cont .= $_; } - close(FD); - } else { - print "Downloading the file to annotate\n"; - $ua = LWP::UserAgent->new; - $request = HTTP::Request->new(GET => "$resolved_target"); - $response = $ua->request($request, \&callback); - - print "Storing file for the file to annotate\n"; - mkdirs($filename_target); - open(FD, ">".$filename_target); - print FD $cont; - close(FD); - } - } - my $target = $cont; + my $cicurl = $map{$cicuri}; - # Merging the annotation and the target + print_request("cic",$cicuri,$cicurl,$cicfilename); - $target =~ s/<\?xml [^?]*\?>//sg; - $target =~ s/]*>//sg; - $annotation =~ s/<\?xml [^?]*\?>//sg; - $annotation =~ s/]*>//sg; - my $merged = < - -$target -$annotation - -EOT + # Retrieves the file + my $ciccontent = download(0,"cic",$cicurl,$cicfilename); # Answering the client - - my $res = new HTTP::Response; - $res->content($merged); - $c->send_response($res); - } elsif ($http_method eq 'GET' and $http_path eq "/getwithtypes") { - my $mode; - my $do_annotate; - if ($cicuri =~ /\.types$/) { - $do_annotate = 1; - $mode = "types"; - } elsif ($cicuri =~ /\.ann$/) { - $do_annotate = 1; - $mode = "ann"; + answer($c,$ciccontent); + } elsif ($http_method eq 'GET' and $http_path eq "/get") { + # finds the uris, urls and filenames + my $cicuri = $inputuri, + $typesuri = $inputuri, + $annuri = $inputuri; + my $annsuffix; + if ($inputuri =~ /\.types$/) { + $cicuri =~ s/(.*)\.types$/$1/; + undef($annuri); + } elsif ($inputuri =~ /\.types\.ann$/) { + $cicuri =~ s/(.*)\.types\.ann$/$1/; + $typesuri =~ s/(.*)\.ann$/$1/; + $annsuffix = ".types.ann"; + } elsif ($inputuri =~ /\.ann$/) { + $cicuri =~ s/(.*)\.ann$/$1/; + undef($typesuri); + $annsuffix = ".ann"; } else { - $do_annotate = 0; - } - my $target_to_annotate = $cicuri; - if ($mode eq "types") { - $target_to_annotate =~ s/(.*)\.types$/$1/; - } elsif ($mode eq "ann") { - $target_to_annotate =~ s/(.*)\.ann$/$1/; - } - my $filename = $cicuri; - $filename =~ s/cic:(.*)/$1/; - $filename =~ s/theory:(.*)/$1/; - my $filename_target = $helm_dir.$filename if $do_annotate; - $filename = $helm_dir.$filename.".xml"; - if ($mode eq "types") { - $filename_target =~ s/(.*)\.types$/$1.xml/; - } elsif ($mode eq "ann") { - $filename_target =~ s/(.*)\.ann$/$1.xml/; - } - my $resolved = $map{$cicuri}; - my $resolved_target = $map{$target_to_annotate} if $do_annotate; - if ($do_annotate) { - print "GETWITHTYPES!!\n" if ($mode eq "types"); - print "GETWITHANN!!\n" if ($mode eq "ann"); - print "($cicuri, $target_to_annotate) ==> ($resolved + $resolved_target) ($filename)\n"; - } else { - print "$cicuri ==> $resolved ($filename)\n"; + undef($typesuri); + undef($annuri); } - # Retrieves the annotation + my $cicfilename = $cicuri; + $cicfilename =~ s/cic:(.*)/$1/; + $cicfilename =~ s/theory:(.*)/$1/; + $cicfilename = $helm_dir.$cicfilename; - if (stat($filename)) { - print "Using local copy for the types\n" if ($mode eq "types"); - print "Using local copy for the ann\n" if ($mode eq "ann"); - open(FD, $filename); - while() { $cont .= $_; } - close(FD); - } else { - print "Downloading the types\n" if ($mode eq "types"); - print "Downloading the ann\n" if ($mode eq "ann"); - $ua = LWP::UserAgent->new; - $request = HTTP::Request->new(GET => "$resolved"); - $response = $ua->request($request, \&callback); - - print "Storing file for the types\n" if ($mode eq "types"); - print "Storing file for the ann\n" if ($mode eq "ann"); - mkdirs($filename); - open(FD, ">".$filename); - print FD $cont; - close(FD); - } - my $annotation = $cont; + my $typesfilename = $cicfilename.".types.xml" if $typesuri; + my $annfilename = $cicfilename.$annsuffix.".xml" if $annuri; + $cicfilename .= ".xml"; - # Retrieves the target to annotate + my $cicurl = $map{$cicuri}; + my $typesurl = $map{$typesuri} if $typesuri; + my $annurl = $map{$annuri} if $annuri; - $cont = ""; - my $target; - if ($do_annotate) { - if (stat($filename_target)) { - print "Using local copy for the file to type\n"; - open(FD, $filename_target); - while() { $cont .= $_; } - close(FD); - } else { - print "Downloading the file to type\n"; - $ua = LWP::UserAgent->new; - $request = HTTP::Request->new(GET => "$resolved_target"); - $response = $ua->request($request, \&callback); - - print "Storing file for the file to type\n"; - mkdirs($filename_target); - open(FD, ">".$filename_target); - print FD $cont; - close(FD); - } - $target = $cont; - } else { - $target = $annotation; - $annotation = ""; - } + print_request("cic",$cicuri,$cicurl,$cicfilename); + print_request("types",$typesuri,$typesurl,$typesfilename) + if ($typesuri); + print_request("ann",$annuri,$annurl,$annfilename) + if ($annuri); - # Merging the annotation and the target + # 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 - $target =~ s/<\?xml [^?]*\?>//sg; - $target =~ s/]*>//sg; - $annotation =~ s/<\?xml [^?]*\?>//sg; - $annotation =~ s/]*>//sg; - my $element, $endelement; - if ($mode eq "types") { - $element = ""; - $endelement = ""; - } elsif ($mode eq "ann") { - $element = ""; - $endelement = ""; - } my $merged = < - -$target -$element -$annotation -$endelement + +$ciccontent +$typescontent +$anncontent EOT # Answering the client - - my $res = new HTTP::Response; - $res->content($merged); - $c->send_response($res); + answer($c,$merged); } elsif ($http_method eq 'GET' and $http_path eq "/getdtd") { - my $filename = $cicuri; + my $filename = $inputuri; $filename = $dtd_dir."/".$filename; - print "DTD: $cicuri ==> ($filename)\n"; + print "DTD: $inputuri ==> ($filename)\n"; if (stat($filename)) { print "Using local copy\n"; open(FD, $filename); + $cont = ""; while() { $cont .= $_; } close(FD); - my $res = new HTTP::Response; - $res->content($cont); - $c->send_response($res); + answer($c,$cont); } else { die "Could not find DTD!"; } @@ -289,15 +139,14 @@ EOT $quoted_html_link =~ s/>/>/g; $quoted_html_link =~ s/'/'/g; $quoted_html_link =~ s/"/"/g; - print "Configuration requested, returned #$quoted_html_link#\n"; + print "\nConfiguration requested, returned #$quoted_html_link#\n"; $cont = "$quoted_html_link"; - my $res = new HTTP::Response; - $res->content($cont); - $c->send_response($res); + answer($c,$cont); } else { - print "INVALID REQUEST!!!!!\n"; + print "\nINVALID REQUEST!!!!!\n"; $c->send_error(RC_FORBIDDEN) } + print "\nRequest solved: ".$r->url."\n\n"; } $c->close; undef($c); @@ -308,23 +157,67 @@ EOT #================================ -sub callback -{ - my ($data) = @_; - $cont .= $data; -} -# Does not raise errors if could not create dirs/files - -# Too much powerful: creates even /home, /home/users/, ... +#CSC: Too much powerful: creates even /home, /home/users/, ... +#CSC: Does not raise errors if could not create dirs/files sub mkdirs { my ($pathname) = @_; my @dirs = split /\//,$pathname; my $tmp; foreach $dir (@dirs) { - $tmp = ((defined($tmp)) ? $tmp = $tmp."\/".$dir : ""); + $tmp = ((defined($tmp)) ? $tmp."\/".$dir : ""); mkdir($tmp,0777); } rmdir($tmp); } + +sub print_request +{ + my ($str,$uri,$url,$filename) = @_; + print $str."uri: $uri\n"; + print $str."url: $url\n"; + print $str."filename: $filename\n\n"; +} + +sub callback +{ + my ($data) = @_; + $cont .= $data; +} + +sub download +{ + my ($remove_headers,$str,$url,$filename) = @_; + $cont = ""; # modified by side-effect by the callback function + if (stat($filename)) { + print "Using local copy for the $str file\n"; + open(FD, $filename); + while() { $cont .= $_; } + close(FD); + } else { + print "Downloading the $str file\n"; + $ua = LWP::UserAgent->new; + $request = HTTP::Request->new(GET => "$url"); + $response = $ua->request($request, \&callback); + + print "Storing the $str file\n"; + mkdirs($filename); + open(FD, ">".$filename); + print FD $cont; + close(FD); + } + if ($remove_headers) { + $cont =~ s/<\?xml [^?]*\?>//sg; + $cont =~ s/]*>//sg; + } + return $cont; +} + +sub answer +{ + my ($c,$cont) = @_; + my $res = new HTTP::Response; + $res->content($cont); + $c->send_response($res); +} diff --git a/helm/interface/getter.ml b/helm/interface/getter.ml index 21c1901a1..39af104cc 100644 --- a/helm/interface/getter.ml +++ b/helm/interface/getter.ml @@ -115,8 +115,8 @@ let get uri = let module U = UriManager in get_file (U.uri_of_string - (Str.replace_first (Str.regexp "\.ann$") "" - (Str.replace_first (Str.regexp "\.types$") "" (U.string_of_uri uri)))) + (Str.replace_first (Str.regexp "\.types$") "" + (Str.replace_first (Str.regexp "\.ann$") "" (U.string_of_uri uri)))) ;; (* get_ann : uri -> filename *) diff --git a/helm/interface/pxpUriResolver.ml b/helm/interface/pxpUriResolver.ml index 6ebbf71bd..ad8713cf3 100644 --- a/helm/interface/pxpUriResolver.ml +++ b/helm/interface/pxpUriResolver.ml @@ -10,11 +10,11 @@ let resolve = function - "http://localhost:8081/getdtd?url=cic.dtd" -> + "http://localhost:8081/getdtd?uri=cic.dtd" -> Configuration.dtd_dir ^ "/cic.dtd" - | "http://localhost:8081/getdtd?url=maththeory.dtd" -> + | "http://localhost:8081/getdtd?uri=maththeory.dtd" -> Configuration.dtd_dir ^ "/maththeory.dtd" - | "http://localhost:8081/getdtd?url=annotations.dtd" -> + | "http://localhost:8081/getdtd?uri=annotations.dtd" -> Configuration.dtd_dir ^ "/annotations.dtd" | s -> s ;; diff --git a/helm/style/basic.xsl b/helm/style/basic.xsl index 93eb28052..a05a281b9 100644 --- a/helm/style/basic.xsl +++ b/helm/style/basic.xsl @@ -14,7 +14,7 @@ -http://localhost:8081/get?url= +http://localhost:8081/getciconly?uri= diff --git a/helm/style/content.xsl b/helm/style/content.xsl index 7d211d2f7..68a418dcd 100644 --- a/helm/style/content.xsl +++ b/helm/style/content.xsl @@ -37,7 +37,7 @@ Amaya o da chi di dovere in /really_very_local/helm/PARSER/example/.../] -http://localhost:8081/get?url= +http://localhost:8081/getciconly?uri= @@ -45,11 +45,7 @@ Amaya o da chi di dovere in /really_very_local/helm/PARSER/example/.../] - - - + diff --git a/helm/style/content_to_html.xsl b/helm/style/content_to_html.xsl index dd1c07794..f2d618274 100644 --- a/helm/style/content_to_html.xsl +++ b/helm/style/content_to_html.xsl @@ -14,7 +14,7 @@ - + diff --git a/helm/style/html_init.xsl b/helm/style/html_init.xsl index 9e81b169c..44d75fd0a 100644 --- a/helm/style/html_init.xsl +++ b/helm/style/html_init.xsl @@ -8,7 +8,7 @@ -http://localhost:8081/get?url= +http://localhost:8081/getciconly?uri= diff --git a/helm/style/html_reals.xsl b/helm/style/html_reals.xsl index 04ff478c5..1f1750b2d 100644 --- a/helm/style/html_reals.xsl +++ b/helm/style/html_reals.xsl @@ -8,7 +8,7 @@ -http://localhost:8081/get?url= +http://localhost:8081/getciconly?uri= diff --git a/helm/style/html_set.xsl b/helm/style/html_set.xsl index 6c7f66b1b..ca38298d1 100644 --- a/helm/style/html_set.xsl +++ b/helm/style/html_set.xsl @@ -8,7 +8,7 @@ -http://localhost:8081/get?url= +http://localhost:8081/getciconly?uri= diff --git a/helm/style/mmlextension.xsl b/helm/style/mmlextension.xsl index d467b77af..cd6609aa1 100644 --- a/helm/style/mmlextension.xsl +++ b/helm/style/mmlextension.xsl @@ -18,7 +18,7 @@ - + @@ -474,7 +474,7 @@ - :> + :> @@ -491,7 +491,7 @@ ( - :> + :> ) @@ -802,7 +802,7 @@ - we proved + we proved _ @@ -1015,7 +1015,7 @@ - we get + we get _ @@ -1033,7 +1033,7 @@ - we get + we get _ @@ -1221,9 +1221,9 @@ - + - + diff --git a/helm/style/proofs.xsl b/helm/style/proofs.xsl index a3f2a1507..da751e437 100644 --- a/helm/style/proofs.xsl +++ b/helm/style/proofs.xsl @@ -14,7 +14,7 @@ -http://localhost:8081/get?url= +http://localhost:8081/getciconly?uri= diff --git a/helm/style/reals.xsl b/helm/style/reals.xsl index 6c47f9562..208d8416e 100644 --- a/helm/style/reals.xsl +++ b/helm/style/reals.xsl @@ -15,7 +15,7 @@ -http://localhost:8081/get?url= +http://localhost:8081/getciconly?uri= diff --git a/helm/style/ricerca.xsl b/helm/style/ricerca.xsl index e0fa13a93..28e210dca 100644 --- a/helm/style/ricerca.xsl +++ b/helm/style/ricerca.xsl @@ -10,7 +10,7 @@ -http://localhost:8081/get?url= +http://localhost:8081/getciconly?uri= diff --git a/helm/style/set.xsl b/helm/style/set.xsl index b61b44e88..cdb96ec3e 100644 --- a/helm/style/set.xsl +++ b/helm/style/set.xsl @@ -14,7 +14,7 @@ -http://localhost:8081/get?url= +http://localhost:8081/getciconly?uri= diff --git a/helm/style/theory_content.xsl b/helm/style/theory_content.xsl index 9b65cc5b2..5ff5a41f7 100644 --- a/helm/style/theory_content.xsl +++ b/helm/style/theory_content.xsl @@ -13,7 +13,7 @@ -http://localhost:8081/get?url= +http://localhost:8081/getciconly?uri= -- 2.39.2