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