d167a4edaf7de1fd763f25c908f23c53cb64b272
[ZOOM-Perl-moved-to-github.git] / lib / Net / Z3950.pm
1 # $Id: Z3950.pm,v 1.2 2007-02-26 15:58:33 mike Exp $
2
3 use strict;
4 use warnings;
5 use Net::Z3950::ZOOM;
6
7 our $VERSION = '0.99';  # Supersedes "proper" Net::Z3950 v0.51
8
9
10 # Member naming convention is the same as in ../ZOOM.pm
11
12 # ----------------------------------------------------------------------------
13 # Enumerations are copied from the old Net::Z3950 module.
14 # It's not entirely clear yet which of these we actually need, for for
15 # now I am commenting them all out, and faulting in the ones we need.
16 # ----------------------------------------------------------------------------
17
18 # Define the operation-code enumeration.  The values here are chosen
19 # to be in a distinctive range (i.e. 3950 plus a small integer) so
20 # that if they are misused in another context, they're easy to spot.
21 package Net::Z3950::Op;
22 sub Error    { 3951 }
23 sub Init     { 3952 }
24 sub Search   { 3953 }
25 sub Get      { 3954 }
26 sub DeleteRS { 3955 }
27 sub Scan     { 3956 }
28 package Net::Z3950;
29
30
31 ## Define the record-syntax enumeration.  These values must be kept
32 ## synchronised with the values implied by the oid_value enumeration in
33 ## the header file "yaz/oid.h"
34 #package Net::Z3950::RecordSyntax;
35 #sub UNIMARC    { 16 }
36 #sub INTERMARC  { 17 }
37 #sub CCF        { 18 }
38 #sub USMARC     { 19 }
39 #sub UKMARC     { 20 }
40 #sub NORMARC    { 21 }
41 #sub LIBRISMARC { 22 }
42 #sub DANMARC    { 23 }
43 #sub FINMARC    { 24 }
44 #sub MAB        { 25 }
45 #sub CANMARC    { 26 }
46 #sub SBN        { 27 }
47 #sub PICAMARC   { 28 }
48 #sub AUSMARC    { 29 }
49 #sub IBERMARC   { 30 }
50 #sub CATMARC    { 31 }
51 #sub MALMARC    { 32 }
52 #sub EXPLAIN    { 33 }
53 #sub SUTRS      { 34 }
54 #sub OPAC       { 35 }
55 #sub SUMMARY    { 36 }
56 #sub GRS0       { 37 }
57 #sub GRS1       { 38 }
58 #sub EXTENDED   { 39 }
59 #sub TEXT_HTML  { 70 }
60 #sub XML        { 80 }
61 #sub TEXT_XML   { 80 }
62 #sub APPLICATION_XML { 81 }
63 #
64 #use vars '%map';
65 ## Maps record-syntax name strings to enumeration members
66 #%map = (UNIMARC => UNIMARC,
67 #       INTERMARC => INTERMARC,
68 #       CCF => CCF,
69 #       USMARC => USMARC,
70 #       UKMARC => UKMARC,
71 #       NORMARC => NORMARC,
72 #       LIBRISMARC => LIBRISMARC,
73 #       DANMARC => DANMARC,
74 #       FINMARC => FINMARC,
75 #       MAB => MAB,
76 #       CANMARC => CANMARC,
77 #       SBN => SBN,
78 #       PICAMARC => PICAMARC,
79 #       AUSMARC => AUSMARC,
80 #       IBERMARC => IBERMARC,
81 #       CATMARC => CATMARC,
82 #       MALMARC => MALMARC,
83 #       EXPLAIN => EXPLAIN,
84 #       SUTRS => SUTRS,
85 #       OPAC => OPAC,
86 #       SUMMARY => SUMMARY,
87 #       GRS0 => GRS0,
88 #       GRS1 => GRS1,
89 #       EXTENDED => EXTENDED,
90 #       TEXT_HTML => TEXT_HTML,
91 #       XML => XML,
92 #       TEXT_XML => TEXT_XML,
93 #       APPLICATION_XML => APPLICATION_XML,
94 #       );
95 #package Net::Z3950;
96 #
97 #
98 ## Define the reason-for-decodeAPDU()-failure enumeration.  This must
99 ## be kept synchronised with the values #defined in "yazwrap/yazwrap.h"
100 #package Net::Z3950::Reason;
101 #sub EOF        { 23951 }       # read EOF from connection (server gone)
102 #sub Incomplete { 23952 }       # read bytes, but not yet a whole APDU
103 #sub Malformed  { 23953 }       # couldn't decode APDU (malformed)
104 #sub BadAPDU    { 23954 }       # APDU was well-formed but unrecognised
105 #sub Error      { 23955 }       # some other error (consult errno)
106 #package Net::Z3950;
107 #
108 #
109 ## Define the query-type enumeration.  This must be kept synchronised
110 ## with the values #defined in "yazwrap/yazwrap.h"
111 #package Net::Z3950::QueryType;
112 #sub Prefix  { 39501 }          # Yaz's "@attr"-ish forward-Polish notation
113 #sub CCL     { 39502 }          # Send CCL string to server ``as is''
114 #sub CCL2RPN { 39503 }          # Convert CCL to RPN (type-1) locally
115 #sub CQL     { 39504 }          # Send CQL string to server ``as is''
116 #package Net::Z3950;
117 #
118 #
119 ## Define the result-set-status enumeration, used by the
120 ## `resultSetStatus' field in the Net::Z3950::APDU::SearchResponse
121 ## class in cases where `searchStatus' is false (indicating failure).
122 ## This must be kept synchronised with the ASN.1 for the structure
123 ## described in section 3.2.2.1.11 of the Z39.50 standard itself.
124 #package Net::Z3950::ResultSetStatus;
125 #sub Subset  { 1 }
126 #sub Interim { 2 }
127 #sub None    { 3 }
128 #package Net::Z3950;
129 #
130 #
131 ## Define the present-status enumeration, used by the `presentStatus'
132 ## field in the Net::Z3950::APDU::SearchResponse class in cases where
133 ## `searchStatus' is true (indicating success).  This must be kept
134 ## synchronised with the ASN.1 for the structure described in section
135 ## 3.2.2.1.11 of the Z39.50 standard itself.
136 #package Net::Z3950::PresentStatus;
137 #sub Success  { 0 }
138 #sub Partial1 { 1 }
139 #sub Partial2 { 2 }
140 #sub Partial3 { 3 }
141 #sub Partial4 { 4 }
142 #sub Failure  { 5 }
143 #package Net::Z3950;
144 #
145 #
146 ## Define the scan-status enumeration, used by the `scanStatus'
147 ## field in the Net::Z3950::APDU::ScanResponse class.  This must be
148 ## kept synchronised with the ASN.1 for the structure described in
149 ## section 3.2.8.1.6 of the Z39.50 standard itself.
150 #package Net::Z3950::ScanStatus;
151 #sub Success  { 0 }
152 #sub Partial1 { 1 }
153 #sub Partial2 { 2 }
154 #sub Partial3 { 3 }
155 #sub Partial4 { 4 }
156 #sub Partial5 { 5 }
157 #sub Failure  { 6 }
158 #package Net::Z3950;
159
160 # ----------------------------------------------------------------------------
161
162 package Net::Z3950;
163
164 sub errstr {
165     my($errcode) = @_;
166     # This is not 100% compatible, because it will translate
167     # ZOOM-level errors as well as BIB-1 diagnostic codes.
168     return Net::Z3950::ZOOM::diag_str($errcode)
169 }
170
171 sub opstr {
172     my($op) = @_;
173     return "error" if $op == Net::Z3950::Op::Error;
174     return "init" if $op == Net::Z3950::Op::Init;
175     return "search" if $op == Net::Z3950::Op::Search;
176     return "get" if $op == Net::Z3950::Op::Get;
177     return "deleteRS" if $op == Net::Z3950::Op::DeleteRS;
178     return "scan" if $op == Net::Z3950::Op::Scan;
179     return "unknown op " . $op;
180 }
181
182
183 # ----------------------------------------------------------------------------
184
185 package Net::Z3950::Manager;
186 sub new { Net::Z3950::Connection->new() }
187
188
189 # ----------------------------------------------------------------------------
190
191 package Net::Z3950::Connection;
192
193 sub new {
194     die "The Net::Z3950::ZOOM distribution does not yet support the Net::Z3950 'Classic' API.  A subsequent version will do so; until then, please continue using Net::Z3950 itself if you need its API."
195 }
196
197
198 1;