| 1 | #!/usr/bin/perl -w | ||
| 2 | |||
| 3 | # $Id: resolve,v 1.9 2008-04-11 12:03:31 mike Exp $ | ||
| 4 | # | ||
| 5 | # This is the front end for Keystone Resolver when invoked either as | ||
| 6 | # an OpenURL 0.1 resolver, or as a Z39.88 (OpenURL 1.0) resolver using | ||
| 7 | # any of the transports | ||
| 8 | # info:ofi/tsp:http:openurl-by-val | ||
| 9 | # info:ofi/tsp:http:openurl-by-ref | ||
| 10 | # info:ofi/tsp:http:openurl-inline | ||
| 11 | # or their secure HTTPS equivalents, as defined in Part 1, section | ||
| 12 | # 15.1 of the standard, and as described in Part 2, section 9. It | ||
| 13 | # works using both HTTP GET and HTTP POST. | ||
| 14 | # | ||
| 15 | # The classes that do the actual work are designed to work with other | ||
| 16 | # Z39.88 transports too, but none have been defined yet. | ||
| 17 | |||
| 18 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 20 | 1 | ▶ | use CGI; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | 0 | ▶ | use Keystone::Resolver; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 22 | |||
| 23 | Keystone::Resolver::Utils::apache_non_moronic_logging(); | ||
| 24 | |||
| 25 | { | ||
| 26 | my $cgi = new CGI(); | ||
| 27 | if (0) { | ||
| 28 | ### Temporary measure. We will want better logging down the line. | ||
| 29 | my $file = "/usr/local/src/cvs/resolver/samples/openurls/samples"; | ||
| 30 | open F, ">>$file" | ||
| 31 | or die "can't write to OpenURL log file '$file': $!"; | ||
| 32 | |||
| 33 | print F $cgi->query_string(), "\n"; | ||
| 34 | close F; | ||
| 35 | } | ||
| 36 | |||
| 37 | binmode STDERR, ":utf8"; # For any temporary debugging output | ||
| 38 | my $referer = $ENV{HTTP_REFERER} || "http://made.up.referrer/foo"; | ||
| 39 | my $resolver = new Keystone::Resolver(); | ||
| 40 | my $openURL = Keystone::Resolver::OpenURL->newFromCGI($resolver, $cgi, $referer); | ||
| 41 | |||
| 42 | my($type, $content); | ||
| 43 | eval { | ||
| 44 | ($type, $content) = $openURL->resolve(); | ||
| 45 | }; if ($@ && !ref $@ && $@ =~ /DBI connect.*failed/) { | ||
| 46 | print <<__EOT__; | ||
| 47 | It was not possible to connect to the Keystone Resolver database. | ||
| 48 | Please see /usr/share/libkeystone-resolver-perl/db/README | ||
| 49 | |||
| 50 | Detailed error message follows, but you can probably ignore it: | ||
| 51 | -- | ||
| 52 | $@ | ||
| 53 | __EOT__ | ||
| 54 | } elsif ($@ && (!ref $@ || $@->isa("HTML::Mason::Exception")) && $@ =~ /Unknown column/) { | ||
| 55 | print <<__EOT__; | ||
| 56 | A column was missing from a table in the Keystone Resolver database. | ||
| 57 | This probably means that the structure of your database is out of date | ||
| 58 | Please see /usr/share/libkeystone-resolver-perl/db/README.update | ||
| 59 | |||
| 60 | Detailed error message follows, but you can probably ignore it: | ||
| 61 | -- | ||
| 62 | $@ | ||
| 63 | __EOT__ | ||
| 64 | return; | ||
| 65 | } elsif ($@) { | ||
| 66 | print "Uh-oh!\n$@"; | ||
| 67 | exit; | ||
| 68 | } | ||
| 69 | |||
| 70 | my $r = Keystone::Resolver::Utils::apache_request($cgi); | ||
| 71 | $r->content_type($type); | ||
| 72 | print $content; | ||
| 73 | } | ||