Bug 17179: (follow-up) Correct typos, add default select.
[koha.git] / misc / z3950_responder.pl
blob871fca676f9cf4854e02103a87d1ca777ee07208
1 #!/usr/bin/perl
3 # Copyright ByWater Solutions 2015
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use Modern::Perl;
22 use Carp;
23 use File::Basename;
24 use Getopt::Long qw(:config no_ignore_case);
25 use Pod::Usage;
27 use Koha::Config;
28 use Koha::Z3950Responder;
30 =head1 SYNOPSIS
32 z3950_responder.pl [-h|--help] [--man] [-a <pdufile>] [-v <loglevel>] [-l <logfile>] [-u <user>]
33 [-c <config>] [-t <minutes>] [-k <kilobytes>] [-d <daemon>] [-p <pidfile>]
34 [-C certfile] [-zKiDST1] [-m <time-format>] [-w <directory>] [--debug]
35 [--add-item-status=SUBFIELD] [--prefetch=NUM_RECORDS] [--config-dir=<directory>]
36 [<listener-addr>... ]
38 =head1 OPTIONS
40 See https://software.indexdata.com/yaz/doc/server.invocation.html for more information about YAZ options
41 not described below.
43 =over 8
45 =item B<--help>
47 Prints a brief usage message and exits.
49 =item B<--man>
51 Displays manual page and exits.
53 =item B<--debug>
55 Turns on debug logging to the screen and the single-process mode.
57 =item B<--add-item-status=SUBFIELD>
59 If given, adds item status information to the given subfield.
61 =item B<--add-status-multi-subfield>
63 With the above, instead of putting multiple item statuses in one subfield, adds a subfield for each
64 status string.
66 =item B<--prefetch=NUM_RECORDS>
68 Number of records to prefetch. Defaults to 20.
70 =item B<--config-dir=directory>
72 Directory where to find configuration files required for proper operation. Defaults to z3950 under
73 the Koha config directory.
75 =back
77 =head1 CONFIGURATION
79 The item status strings added by B<--add-item-status> can be configured with the B<Z3950_STATUS>
80 authorized value, using the following keys:
82 =over 4
84 =item AVAILABLE
86 =item CHECKED_OUT
88 =item LOST
90 =item NOT_FOR_LOAN
92 =item DAMAGED
94 =item WITHDRAWN
96 =item IN_TRANSIT
98 =item ON_HOLD
100 =back
102 =cut
104 my $add_item_status_subfield;
105 my $add_status_multi_subfield;
106 my $debug = 0;
107 my $help;
108 my $man;
109 my $prefetch = 20;
110 my $config_dir = '';
112 my @yaz_options;
114 sub add_yaz_option {
115 my ( $opt_name, $opt_value ) = @_;
117 push @yaz_options, "-$opt_name", "$opt_value";
120 sub pass_yaz_option {
121 my ( $opt_name ) = @_;
123 push @yaz_options, "-$opt_name";
126 GetOptions(
127 '-h|help' => \$help,
128 '--man' => \$man,
129 '--debug' => \$debug,
130 '--add-item-status=s' => \$add_item_status_subfield,
131 '--add-status-multi-subfield' => \$add_status_multi_subfield,
132 '--prefetch=i' => \$prefetch,
133 '--config-dir=s' => \$config_dir,
134 # Pass through YAZ options.
135 'a=s' => \&add_yaz_option,
136 'v=s' => \&add_yaz_option,
137 'l=s' => \&add_yaz_option,
138 'u=s' => \&add_yaz_option,
139 'c=s' => \&add_yaz_option,
140 't=s' => \&add_yaz_option,
141 'k=s' => \&add_yaz_option,
142 'd=s' => \&add_yaz_option,
143 'p=s' => \&add_yaz_option,
144 'C=s' => \&add_yaz_option,
145 'm=s' => \&add_yaz_option,
146 'w=s' => \&add_yaz_option,
147 'z' => \&pass_yaz_option,
148 'K' => \&pass_yaz_option,
149 'i' => \&pass_yaz_option,
150 'D' => \&pass_yaz_option,
151 'S' => \&pass_yaz_option,
152 'T' => \&pass_yaz_option,
153 '1' => \&pass_yaz_option
154 ) || pod2usage(2);
156 pod2usage(1) if $help;
157 pod2usage( -verbose => 2 ) if $man;
159 # If config_dir is not defined, default to z3950 under the Koha config directory
160 if (!$config_dir) {
161 (undef, $config_dir) = fileparse(Koha::Config->guess_koha_conf);
162 $config_dir .= 'z3950/';
163 } else {
164 $config_dir .= '/' if ($config_dir !~ /\/$/);
167 # Create and start the server.
169 my $z = Koha::Z3950Responder->new( {
170 add_item_status_subfield => $add_item_status_subfield,
171 add_status_multi_subfield => $add_status_multi_subfield,
172 debug => $debug,
173 num_to_prefetch => $prefetch,
174 config_dir => $config_dir,
175 yaz_options => [ @yaz_options, @ARGV ],
176 } );
178 $z->start();