6 use Net::Z3950::SimpleServer;
18 my $max_records = 3; # XXX configure this
19 my $max_result_sets = 10;
29 $this->{HANDLE} = $session;
30 $this->{IMP_NAME} = "Biblio Z39.50";
31 $this->{IMP_VER} = "0.2";
32 $session->{SETS} = {};
38 diag "SearchHandle ",Dumper($this);
40 my $session = $this->{HANDLE};
41 my $rpn = $this->{RPN};
44 my $database = $this->{DATABASES}->[0];
45 my $module = $databases->{$database} || 'COBISS';
46 my $from = $module->new;
48 diag "using $module for $database ", Dumper( $from );
50 eval { $query = $rpn->{query}->render( $from->usemap ); };
51 warn "ERROR: $@" if $@;
52 if ( $@ && ref($@) ) { ## Did someone/something report any errors?
53 $this->{ERR_CODE} = $@->{errcode};
54 $this->{ERR_STR} = $@->{errstr};
58 diag "search for $query";
60 my $setname = $this->{SETNAME};
61 my $repl_set = $this->{REPL_SET};
62 diag "SETNAME $setname REPL_SET $repl_set";
64 unless ( $hits = $from->search( $query ) ) {
65 $this->{ERR_CODE} = 108;
68 diag "got $hits hits";
71 upper => $hits < $max_records ? $max_records : $hits,
75 my $sets = $session->{SETS};
77 if ( defined( $sets->{$setname} ) && !$repl_set ) {
78 $this->{ERR_CODE} = 21;
81 if ( scalar keys %$sets >= $max_result_sets ) {
82 $this->{ERR_CODE} = 112;
83 $this->{ERR_STR} = "Max number is $max_result_sets";
86 $sets->{$setname} = $rs;
87 $this->{HITS} = $session->{HITS} = $hits;
88 $session->{QUERY} = $query;
93 my $session = $this->{HANDLE};
94 my $setname = $this->{SETNAME};
95 my $req_form = $this->{REQ_FORM};
96 my $offset = $this->{OFFSET};
97 my $sets = $session->{SETS};
98 my $hits = $session->{HITS};
102 if ( !defined( $rs = $sets->{$setname} ) ) {
103 $this->{ERR_CODE} = 30;
106 if ( $offset > $hits ) {
107 $this->{ERR_CODE} = 13;
111 my $from = $rs->{from} || die "no from?";
113 $this->{BASENAME} = "HtmlZ3950";
115 # if ( !defined($req_form) || ( $req_form eq &Net::Z3950::OID::xml ) )
118 $this->{REP_FORM} = &Net::Z3950::OID::xml;
119 $this->{RECORD} = '<xml>FIXME: not implementd</xml>';
121 elsif ( $req_form eq &Net::Z3950::OID::unimarc ) { # FIXME convert to usmarc
122 $this->{REP_FORM} = &Net::Z3950::OID::unimarc;
123 $this->{RECORD} = $from->next_marc('unimarc');
125 elsif ( $req_form eq &Net::Z3950::OID::usmarc ) { # FIXME convert to usmarc
126 $this->{REP_FORM} = &Net::Z3950::OID::usmarc;
127 $this->{RECORD} = $from->next_marc('usmarc');
129 else { ## Unsupported record format
130 $this->{ERR_CODE} = 239;
131 $this->{ERR_STR} = $req_form;
134 if ( $offset == $hits ) {
146 my $z = new Net::Z3950::SimpleServer(
147 INIT => \&InitHandle,
148 SEARCH => \&SearchHandle,
149 FETCH => \&FetchHandle,
150 CLOSE => \&CloseHandle
152 $z->launch_server( $0, @ARGV );
154 package Net::Z3950::RPN::And;
158 return $this->[0]->render() . ' AND ' . $this->[1]->render();
161 package Net::Z3950::RPN::Or;
165 return $this->[0]->render() . ' OR ' . $this->[1]->render();
168 package Net::Z3950::RPN::AndNot;
172 return $this->[0]->render() . ' AND NOT ' . $this->[1]->render();
175 package Net::Z3950::RPN::Term;
177 use Data::Dump qw(dump);
181 my ($this,$usemap) = @_;
183 warn "# render ", dump($this);
184 warn "# usemap ", dump($usemap);
188 foreach my $attr ( @{ $this->{attributes} } ) {
189 my $type = $attr->{attributeType};
190 my $value = $attr->{attributeValue};
191 $attributes->{$type} = $value;
193 if ( defined( my $use = $attributes->{1} ) ) {
194 if ( defined( my $field = $usemap->{$use} ) ) {
198 die { errcode => 114, errstr => $use }; ## Unsupported use attribute
201 if ( defined( my $rel = $attributes->{2} ) )
202 { ## No relation attributes supported
204 die { errcode => 117, errstr => $rel };
207 if ( defined( my $pos = $attributes->{3} ) )
208 { ## No position attributes either
210 die { errcode => 119, errstr => $pos };
213 if ( defined( my $struc = $attributes->{4} ) ) { ## No structure
214 if ( ( $struc != 1 ) && ( $struc != 2 ) ) {
215 die { errcode => 118, errstr => $struc };
218 if ( defined( $attributes->{5} ) ) { ## No truncation
219 die { errcode => 113, errstr => 5 };
221 my $comp = $attributes->{6};
223 if ( defined($comp) && ( $comp >= 2 ) ) {
224 $prefix = "all$prefix= ";
227 $prefix = "$prefix=";
231 my $q = $prefix . $this->{term};