X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;ds=sidebyside;f=lib%2FZOOM.pm;h=0e3e5836f05346d3e9e32ff2e1f667b5e97112bb;hb=a093850375464520c98525423b6222f89e7f7b1a;hp=b7c54e619c3b45108e1fd1f8fda45c5535a96267;hpb=32187e3628d827500ba3e433d78282b366f7566f;p=ZOOM-Perl-moved-to-github.git diff --git a/lib/ZOOM.pm b/lib/ZOOM.pm index b7c54e6..0e3e583 100644 --- a/lib/ZOOM.pm +++ b/lib/ZOOM.pm @@ -1,7 +1,8 @@ -# $Id: ZOOM.pm,v 1.30 2006-04-07 12:17:54 mike Exp $ +# $Id: ZOOM.pm,v 1.36 2006-10-04 17:15:03 mike Exp $ use strict; use warnings; +use IO::File; use Net::Z3950::ZOOM; @@ -41,6 +42,8 @@ sub UNSUPPORTED_QUERY { Net::Z3950::ZOOM::ERROR_UNSUPPORTED_QUERY } sub INVALID_QUERY { Net::Z3950::ZOOM::ERROR_INVALID_QUERY } sub CQL_PARSE { Net::Z3950::ZOOM::ERROR_CQL_PARSE } sub CQL_TRANSFORM { Net::Z3950::ZOOM::ERROR_CQL_TRANSFORM } +sub CCL_CONFIG { Net::Z3950::ZOOM::ERROR_CCL_CONFIG } +sub CCL_PARSE { Net::Z3950::ZOOM::ERROR_CCL_PARSE } # The following are added specifically for this OO interface sub CREATE_QUERY { 20001 } sub QUERY_CQL { 20002 } @@ -51,6 +54,22 @@ sub PACKAGE { 20006 } sub SCANTERM { 20007 } sub LOGLEVEL { 20008 } +# Separate space for CCL errors. Great. +package ZOOM::CCL::Error; +sub OK { Net::Z3950::ZOOM::CCL_ERR_OK } +sub TERM_EXPECTED { Net::Z3950::ZOOM::CCL_ERR_TERM_EXPECTED } +sub RP_EXPECTED { Net::Z3950::ZOOM::CCL_ERR_RP_EXPECTED } +sub SETNAME_EXPECTED { Net::Z3950::ZOOM::CCL_ERR_SETNAME_EXPECTED } +sub OP_EXPECTED { Net::Z3950::ZOOM::CCL_ERR_OP_EXPECTED } +sub BAD_RP { Net::Z3950::ZOOM::CCL_ERR_BAD_RP } +sub UNKNOWN_QUAL { Net::Z3950::ZOOM::CCL_ERR_UNKNOWN_QUAL } +sub DOUBLE_QUAL { Net::Z3950::ZOOM::CCL_ERR_DOUBLE_QUAL } +sub EQ_EXPECTED { Net::Z3950::ZOOM::CCL_ERR_EQ_EXPECTED } +sub BAD_RELATION { Net::Z3950::ZOOM::CCL_ERR_BAD_RELATION } +sub TRUNC_NOT_LEFT { Net::Z3950::ZOOM::CCL_ERR_TRUNC_NOT_LEFT } +sub TRUNC_NOT_BOTH { Net::Z3950::ZOOM::CCL_ERR_TRUNC_NOT_BOTH } +sub TRUNC_NOT_RIGHT { Net::Z3950::ZOOM::CCL_ERR_TRUNC_NOT_RIGHT } + # The "Event" package contains constants returned by last_event() package ZOOM::Event; sub NONE { Net::Z3950::ZOOM::EVENT_NONE } @@ -63,7 +82,7 @@ sub SEND_APDU { Net::Z3950::ZOOM::EVENT_SEND_APDU } sub RECV_APDU { Net::Z3950::ZOOM::EVENT_RECV_APDU } sub RECV_RECORD { Net::Z3950::ZOOM::EVENT_RECV_RECORD } sub RECV_SEARCH { Net::Z3950::ZOOM::EVENT_RECV_SEARCH } -sub END { Net::Z3950::ZOOM::EVENT_END } +sub ZEND { Net::Z3950::ZOOM::EVENT_END } # ---------------------------------------------------------------------------- @@ -94,12 +113,10 @@ sub diag_str { return Net::Z3950::ZOOM::diag_str($code); } -### Undocumented sub event_str { return Net::Z3950::ZOOM::event_str(@_); } -### Undocumented sub event { my($connsref) = @_; @@ -110,7 +127,7 @@ sub event { sub _oops { my($code, $addinfo, $diagset) = @_; - die new ZOOM::Exception($code, diag_str($code), $addinfo, $diagset); + die new ZOOM::Exception($code, undef, $addinfo, $diagset); } # ---------------------------------------------------------------------------- @@ -121,11 +138,18 @@ sub new { my $class = shift(); my($code, $message, $addinfo, $diagset) = @_; + $diagset ||= "ZOOM"; + if ($diagset eq "ZOOM") { + $message ||= ZOOM::diag_str($code); + } else { + # Should fill in messages for other diagsets, too. + } + return bless { code => $code, message => $message, addinfo => $addinfo, - diagset => $diagset || "ZOOM", + diagset => $diagset, }, $class; } @@ -290,22 +314,24 @@ sub new { my $class = shift(); my($host, $port, @options) = @_; - my $_conn = Net::Z3950::ZOOM::connection_new($host, $port || 0); - my $conn = bless { - host => $host, - port => $port, - _conn => $_conn, - }; - + my $_opts = Net::Z3950::ZOOM::options_create(); while (@options >= 2) { my $key = shift(@options); my $val = shift(@options); - $conn->option($key, $val); + Net::Z3950::ZOOM::options_set($_opts, $key, $val); } die "Odd number of options specified" if @options; + my $_conn = Net::Z3950::ZOOM::connection_create($_opts); + Net::Z3950::ZOOM::connection_connect($_conn, $host, $port || 0); + my $conn = bless { + host => $host, + port => $port, + _conn => $_conn, + }; + $conn->_check(); return $conn; } @@ -457,13 +483,18 @@ sub package { return _new ZOOM::Package($this, $options, $_p); } -### Undocumented sub last_event { my $this = shift(); return Net::Z3950::ZOOM::connection_last_event($this->_conn()); } +sub is_idle { + my $this = shift(); + + return Net::Z3950::ZOOM::connection_is_idle($this->_conn()); +} + sub destroy { my $this = shift(); @@ -545,6 +576,43 @@ sub new { } +# We have to work around the retarded ZOOM_query_ccl2rpn() API +package ZOOM::Query::CCL2RPN; +our @ISA = qw(ZOOM::Query); + +sub new { + my $class = shift(); + my($string, $conn) = @_; + + my $q = Net::Z3950::ZOOM::query_create() + or ZOOM::_oops(ZOOM::Error::CREATE_QUERY); + + my $config = $conn->option("cclqual"); + if (!defined $config) { + my $cclfile = $conn->option("cclfile") + or ZOOM::_oops(ZOOM::Error::CCL_CONFIG, + "no 'cclqual' or 'cclfile' specified"); + my $fh = new IO::File("<$cclfile") + or ZOOM::_oops(ZOOM::Error::CCL_CONFIG, + "can't open cclfile '$cclfile': $!"); + $config = join("", <$fh>); + $fh->close(); + } + + my($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0, "", 0); + if (Net::Z3950::ZOOM::query_ccl2rpn($q, $string, $config, + $ccl_errcode, $ccl_errstr, + $ccl_errpos) < 0) { + # We have no use for $ccl_errcode or $ccl_errpos + ZOOM::_oops(ZOOM::Error::CCL_PARSE, $ccl_errstr); + } + + return bless { + _query => $q, + }, $class; +} + + package ZOOM::Query::PQF; our @ISA = qw(ZOOM::Query);