06f35641ce2792210fae03484f425b775a95753b
[debian/amanda] / perl / Amanda / Config.swg
1 /*
2  * Copyright (c) Zmanda, Inc.  All Rights Reserved.
3  *
4  * This library is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 2.1
6  * as published by the Free Software Foundation.
7  *
8  * This library is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
11  * License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this library; if not, write to the Free Software Foundation,
15  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA.
16  *
17  * Contact information: Zmanda Inc., 465 S Mathlida Ave, Suite 300
18  * Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
19  */
20
21 %module "Amanda::Config"
22 %include "amglue/amglue.swg"
23 %include "exception.i"
24
25 %{
26 #include "conffile.h"
27 %}
28
29 %perlcode %{
30 =head1 NAME
31
32 Amanda::Config - access to Amanda configuration parameters
33
34 =head1 SYNOPSIS
35
36   use Amanda::Config qw( :init :getconf );
37
38   config_init($CONFIG_INIT_EXPLICIT_NAME, $ARGV[1])
39     or die("errors processing config file " . $Amanda::Config::get_config_filename());
40
41   print "tape device is ", getconf($CNF_TAPEDEV), "\n";
42
43 This API closely parallels the C API.  See F<conffile.h> for details
44 on the functions and constants available here.
45
46 =head1 API STATUS
47
48 Stable
49
50 =head1 INITIALIZATION
51
52 The Amanda configuration is treated as a global state for the
53 application.  It is not possible to load two configurations
54 simultaneously.
55
56 All initialization-related symbols can be imported with the tag
57 C<:init>.
58
59 =head2 LOADING CONFIGURATION
60
61 The Amanda configuration is loaded with the aptly named
62 C<config_init($flags, $name)>.  Because of the great variety in
63 invocation method among Amanda applications, this function has a number
64 of flags that affect its behavior.  These flags can be OR'd together.
65
66 =over
67
68 =item If C<CONFIG_INIT_EXPLICIT_NAME> is given, then the C<$name>
69 parameter can contain the name of a configuration to load.
70
71 =item If C<CONFIG_INIT_USE_CWD> is given, and if the current directory
72 contains C<amanda.conf>, then that file is loaded.
73
74 =item If C<CONFIG_INIT_CLIENT> is given, then a client configuration
75 is loaded.
76
77 =item If C<CONFIG_INIT_OVERLAY> is given, then any existing
78 configuration is not reset.
79
80 =back
81
82 See C<conffile.h> for more detailed information on these flags and
83 their interactions.
84
85 C<config_uninit()> reverses the effects of C<config_init>.  It is
86 not often used.
87
88 Once the configuration is loaded, the configuration name
89 (e.g., "DailySet1"), directory (C</etc/amanda/DailySet1>),
90 and filename (C</etc/amanda/DailySet1/amanda.conf>) are
91 available from C<get_config_name()>, C<get_config_dir()>, and
92 C<get_config_filename()>, respectively.
93
94 =head3 CONFIG ERRORS
95
96 This module collects configuration errors and warnings in a list, and also
97 tracks the overall error level with an enumeration: C<$CFGERR_OK>,
98 C<$CFGERR_WARNINGS>, and C<$CFGERR_ERRORS>.  C<config_init> and
99 C<apply_config_overwrites> both return the current level.  The level and the
100 list of error messages are available from C<config_errors>:
101
102   my ($cfgerr_level, @errors) = Amanda::Configconfig_errors();
103
104 As a convenience, C<config_print_errors> will print all error messages to
105 stderr.  The error state can be cleared with C<config_clear_errors>.
106
107 =head2 CONFIG OVERWRITES
108
109 Most Amanda applications accept the command-line option C<-o>
110 to "overwrite" configuration values in C<amanda.conf>.  In Perl
111 applications, these options should be parsed with L<Getopt::Long|Getopt::Long>, with
112 the action being a call to C<add_config_overwrite_opt>.  For example:
113
114   my $config_overwrites = new_config_overwrites($#ARGV+1);
115     GetOptions(
116         # ...
117         'o=s' => sub { add_config_overwrite_opt($config_overwrites, $_[1]); },
118     ) or usage();
119   my $cfg_ok = config_init($CONFIG_INIT_EXPLICIT_NAME | $CONFIG_INIT_USE_CWD, $config_name);
120   apply_config_overwrites($config_overwrites);
121
122 C<new_config_overwrites($size_estimate)> creates a new
123 overwrites object, using the given size as an estimate of
124 the number of items it will contain (C<$#ARGC/2> is a good
125 estimate).  Individual configuration options are then added via
126 C<add_config_overwrite($co, $key, $value)> (which takes a key/value
127 pair) or C<add_config_overwrite_opt($co, $optarg)>, which parses a
128 string following C<-o> on the command line.
129
130 Once the overwrites are gathered, they are applied with
131 C<apply_config_overwrites($co)>, which applies the overwrites to the
132 active configuration.  No further operations can be performed on the
133 overwrites object after C<apply_config_overwrites> has been called.
134
135 The utility function C<get_config_options()> returns a list of
136 command-line arguments to represent any overwrites that were used
137 to generate the current configuration.  (TODO: this function isn't
138 available yet)
139
140 =head1 PARAMETER ACCESS
141
142 Amanda configurations consist of "global" parameters and several
143 sets of "subsections" -- one set for dumptypes, one for tapetypes,
144 and so on.
145
146 All of the global parameters are represented by a constant beginning
147 with C<$CNF_>, e.g., C<$CNF_LABELSTR>.  The function C<getconf($cnf)>
148 returns the value of parameter C<$cnf>, in whatever format is
149 appropriate for the parameter.  C<getconf_seen($cnf)> returns a true
150 value if C<$cnf> was seen in the configuration file.  If it was not
151 seen, then it will have its default value.
152
153 Some parameters have enumerated types.  The values for those
154 enumerations are available from this module with the same name as
155 in C<conffile.h>.  For example, C<$CNF_TAPERALGO> will yield a value
156 from the enumeration C<taperalgo_t>, the constants for which all
157 begin with C<$ALGO_>.  See C<conffile.h> for the details.
158
159 Each subsection type has the following functions:
160
161 =over
162
163 =item C<lookup_TYP($subsec_name)>
164
165 which returns an opaque object
166 (C<$ss>) representing the subsection, or C<undef> if no subsection
167 with that name exists;
168
169 =item C<TYP_name($ss)>
170
171 returning the name of the subsection;
172
173 =item C<TYP_getconf($ss, $cnf)>
174
175 which fetches a parameter value from C<$ss>; and
176
177 =item C<TYP_seen($ss, $cnf)>
178
179 which returns a true value if <$cnf> was seen in the subsection.
180
181 =back
182
183 The subsections are:
184
185 =over
186
187 =item C<tapetype>
188
189 with constants beginning with C<$TAPETYPE_>
190
191 =item C<dumptype>
192
193 with constants beginning with C<$DUMPTYPE_>
194
195 =item C<interface>
196
197 with constants beginning with C<$INTER_>
198
199 =item C<holdingdisk>
200
201 with constants beginning with C<$HOLDING_>
202
203 =item C<application>
204
205 with constants beginning with C<$APPLICATION_>
206
207 =item C<script>
208
209 with constants beginning with C<$PP_SCRIPT_>
210
211 =item C<device>
212
213 with constants beginning with C<$DEVICE_CONFIG_>.
214
215 =item C<changer>
216
217 with constants beginning with C<$CHANGER_CONFIG_>.
218
219 =back
220
221 See C<conffile.h> for the names of the constants themselves.
222
223 Parameter values are available by name from C<getconf_byname($name)> and
224 C<getconf_byname_strs($name, $str_needs_quotes)>.  These functions implement
225 the C<TYP:NAME:PARAM> syntax advertised by C<amgetconf> to access values in
226 subsections.  The first function returns a perl value, while the second returns
227 a string suitable for use in C<amanda.conf>, including quotes around strings if
228 C<$str_needs_quotes> is true.
229
230 C<getconf_list($typ)> returns a list of the names of all subsections of the
231 given type.  C<%subsection_names> is a hash whose keys are allowed subsection
232 names.
233
234 The C<$CNF_DISPLAYUNIT> implies a certain divisor to convert from
235 kilobytes to the desired unit.  This divisor is available from
236 C<getconf_unit_divisor()>.  Note carefully that it is a I<divisor>
237 for a value in I<kilobytes>!
238
239 Finally, various subsections of Amanda enable verbose debugging via
240 configuration parameters.  The status of each parameter is available
241 a similarly-named variable, e.g., C<$debug_auth>.
242
243 All parameter access functions and constants can be imported with
244 the tag C<:getconf>.
245
246 =head1 MISCELLANEOUS
247
248 These functions defy categorization.
249
250 The function C<config_dir_relative> will interpret a path relative to
251 the current configuration directory.  Absolute paths are passed through
252 unchanged, while relative paths are converted to absolute paths.
253
254 C<dump_configuration()> dumps the current configuration, in a format
255 suitable for re-evaluation for this module, to standard output.
256 This function may be revised to return a string.
257
258 Several parts of Amanda need to convert unit modifier value like
259 "gbytes" to a multiplier.  The function C<find_multiplier($str)>
260 returns the unit multiplier for such a string.  For example, "mbytes"
261 is converted to 1048576 (1024*1024).
262
263 =cut
264 %}
265
266 /*
267  * Parameter access
268 */
269
270 /* All of the CNF_ flags from conffile.h */
271
272 amglue_add_enum_tag_fns(confparm_key);
273 amglue_add_constant(CNF_ORG, confparm_key);
274 amglue_add_constant(CNF_CONF, confparm_key);
275 amglue_add_constant(CNF_INDEX_SERVER, confparm_key);
276 amglue_add_constant(CNF_TAPE_SERVER, confparm_key);
277 amglue_add_constant(CNF_AUTH, confparm_key);
278 amglue_add_constant(CNF_SSH_KEYS, confparm_key);
279 amglue_add_constant(CNF_AMANDAD_PATH, confparm_key);
280 amglue_add_constant(CNF_CLIENT_USERNAME, confparm_key);
281 amglue_add_constant(CNF_GNUTAR_LIST_DIR, confparm_key);
282 amglue_add_constant(CNF_AMANDATES, confparm_key);
283 amglue_add_constant(CNF_MAILER, confparm_key);
284 amglue_add_constant(CNF_MAILTO, confparm_key);
285 amglue_add_constant(CNF_DUMPUSER, confparm_key);
286 amglue_add_constant(CNF_TAPEDEV, confparm_key);
287 amglue_add_constant(CNF_DEVICE_PROPERTY, confparm_key);
288 amglue_add_constant(CNF_PROPERTY, confparm_key);
289 amglue_add_constant(CNF_CHANGERDEV, confparm_key);
290 amglue_add_constant(CNF_CHANGERFILE, confparm_key);
291 amglue_add_constant(CNF_LABELSTR, confparm_key);
292 amglue_add_constant(CNF_TAPELIST, confparm_key);
293 amglue_add_constant(CNF_DISKFILE, confparm_key);
294 amglue_add_constant(CNF_INFOFILE, confparm_key);
295 amglue_add_constant(CNF_LOGDIR, confparm_key);
296 amglue_add_constant(CNF_INDEXDIR, confparm_key);
297 amglue_add_constant(CNF_TAPETYPE, confparm_key);
298 amglue_add_constant(CNF_DUMPCYCLE, confparm_key);
299 amglue_add_constant(CNF_RUNSPERCYCLE, confparm_key);
300 amglue_add_constant(CNF_TAPECYCLE, confparm_key);
301 amglue_add_constant(CNF_NETUSAGE, confparm_key);
302 amglue_add_constant(CNF_INPARALLEL, confparm_key);
303 amglue_add_constant(CNF_DUMPORDER, confparm_key);
304 amglue_add_constant(CNF_BUMPPERCENT, confparm_key);
305 amglue_add_constant(CNF_BUMPSIZE, confparm_key);
306 amglue_add_constant(CNF_BUMPMULT, confparm_key);
307 amglue_add_constant(CNF_BUMPDAYS, confparm_key);
308 amglue_add_constant(CNF_TPCHANGER, confparm_key);
309 amglue_add_constant(CNF_RUNTAPES, confparm_key);
310 amglue_add_constant(CNF_MAXDUMPS, confparm_key);
311 amglue_add_constant(CNF_ETIMEOUT, confparm_key);
312 amglue_add_constant(CNF_DTIMEOUT, confparm_key);
313 amglue_add_constant(CNF_CTIMEOUT, confparm_key);
314 amglue_add_constant(CNF_TAPEBUFS, confparm_key);
315 amglue_add_constant(CNF_DEVICE_OUTPUT_BUFFER_SIZE, confparm_key);
316 amglue_add_constant(CNF_PRINTER, confparm_key);
317 amglue_add_constant(CNF_AUTOFLUSH, confparm_key);
318 amglue_add_constant(CNF_RESERVE, confparm_key);
319 amglue_add_constant(CNF_MAXDUMPSIZE, confparm_key);
320 amglue_add_constant(CNF_COLUMNSPEC, confparm_key);
321 amglue_add_constant(CNF_AMRECOVER_DO_FSF, confparm_key);
322 amglue_add_constant(CNF_AMRECOVER_CHECK_LABEL, confparm_key);
323 amglue_add_constant(CNF_AMRECOVER_CHANGER, confparm_key);
324 amglue_add_constant(CNF_TAPERALGO, confparm_key);
325 amglue_add_constant(CNF_FLUSH_THRESHOLD_DUMPED, confparm_key);
326 amglue_add_constant(CNF_FLUSH_THRESHOLD_SCHEDULED, confparm_key);
327 amglue_add_constant(CNF_TAPERFLUSH, confparm_key);
328 amglue_add_constant(CNF_DISPLAYUNIT, confparm_key);
329 amglue_add_constant(CNF_KRB5KEYTAB, confparm_key);
330 amglue_add_constant(CNF_KRB5PRINCIPAL, confparm_key);
331 amglue_add_constant(CNF_LABEL_NEW_TAPES, confparm_key);
332 amglue_add_constant(CNF_USETIMESTAMPS, confparm_key);
333 amglue_add_constant(CNF_REP_TRIES, confparm_key);
334 amglue_add_constant(CNF_CONNECT_TRIES, confparm_key);
335 amglue_add_constant(CNF_REQ_TRIES, confparm_key);
336 amglue_add_constant(CNF_DEBUG_AMANDAD, confparm_key);
337 amglue_add_constant(CNF_DEBUG_AMIDXTAPED, confparm_key);
338 amglue_add_constant(CNF_DEBUG_AMINDEXD, confparm_key);
339 amglue_add_constant(CNF_DEBUG_AMRECOVER, confparm_key);
340 amglue_add_constant(CNF_DEBUG_AUTH, confparm_key);
341 amglue_add_constant(CNF_DEBUG_EVENT, confparm_key);
342 amglue_add_constant(CNF_DEBUG_HOLDING, confparm_key);
343 amglue_add_constant(CNF_DEBUG_PROTOCOL, confparm_key);
344 amglue_add_constant(CNF_DEBUG_PLANNER, confparm_key);
345 amglue_add_constant(CNF_DEBUG_DRIVER, confparm_key);
346 amglue_add_constant(CNF_DEBUG_DUMPER, confparm_key);
347 amglue_add_constant(CNF_DEBUG_CHUNKER, confparm_key);
348 amglue_add_constant(CNF_DEBUG_TAPER, confparm_key);
349 amglue_add_constant(CNF_DEBUG_SELFCHECK, confparm_key);
350 amglue_add_constant(CNF_DEBUG_SENDSIZE, confparm_key);
351 amglue_add_constant(CNF_DEBUG_SENDBACKUP, confparm_key);
352 amglue_add_constant(CNF_RESERVED_UDP_PORT, confparm_key);
353 amglue_add_constant(CNF_RESERVED_TCP_PORT, confparm_key);
354 amglue_add_constant(CNF_UNRESERVED_TCP_PORT, confparm_key);
355 amglue_copy_to_tag(confparm_key, getconf);
356
357 amglue_add_enum_tag_fns(tapetype_key);
358 amglue_add_constant(TAPETYPE_COMMENT, tapetype_key);
359 amglue_add_constant(TAPETYPE_LBL_TEMPL, tapetype_key);
360 amglue_add_constant(TAPETYPE_BLOCKSIZE, tapetype_key);
361 amglue_add_constant(TAPETYPE_READBLOCKSIZE, tapetype_key);
362 amglue_add_constant(TAPETYPE_LENGTH, tapetype_key);
363 amglue_add_constant(TAPETYPE_FILEMARK, tapetype_key);
364 amglue_add_constant(TAPETYPE_SPEED, tapetype_key);
365 amglue_add_constant(TAPETYPE_FILE_PAD, tapetype_key);
366 amglue_copy_to_tag(tapetype_key, getconf);
367
368 amglue_add_enum_tag_fns(dumptype_key);
369 amglue_add_constant(DUMPTYPE_COMMENT, dumptype_key);
370 amglue_add_constant(DUMPTYPE_PROGRAM, dumptype_key);
371 amglue_add_constant(DUMPTYPE_SRVCOMPPROG, dumptype_key);
372 amglue_add_constant(DUMPTYPE_CLNTCOMPPROG, dumptype_key);
373 amglue_add_constant(DUMPTYPE_SRV_ENCRYPT, dumptype_key);
374 amglue_add_constant(DUMPTYPE_CLNT_ENCRYPT, dumptype_key);
375 amglue_add_constant(DUMPTYPE_AMANDAD_PATH, dumptype_key);
376 amglue_add_constant(DUMPTYPE_CLIENT_USERNAME, dumptype_key);
377 amglue_add_constant(DUMPTYPE_SSH_KEYS, dumptype_key);
378 amglue_add_constant(DUMPTYPE_SECURITY_DRIVER, dumptype_key);
379 amglue_add_constant(DUMPTYPE_EXCLUDE, dumptype_key);
380 amglue_add_constant(DUMPTYPE_INCLUDE, dumptype_key);
381 amglue_add_constant(DUMPTYPE_PRIORITY, dumptype_key);
382 amglue_add_constant(DUMPTYPE_DUMPCYCLE, dumptype_key);
383 amglue_add_constant(DUMPTYPE_MAXDUMPS, dumptype_key);
384 amglue_add_constant(DUMPTYPE_MAXPROMOTEDAY, dumptype_key);
385 amglue_add_constant(DUMPTYPE_BUMPPERCENT, dumptype_key);
386 amglue_add_constant(DUMPTYPE_BUMPSIZE, dumptype_key);
387 amglue_add_constant(DUMPTYPE_BUMPDAYS, dumptype_key);
388 amglue_add_constant(DUMPTYPE_BUMPMULT, dumptype_key);
389 amglue_add_constant(DUMPTYPE_STARTTIME, dumptype_key);
390 amglue_add_constant(DUMPTYPE_STRATEGY, dumptype_key);
391 amglue_add_constant(DUMPTYPE_ESTIMATE, dumptype_key);
392 amglue_add_constant(DUMPTYPE_COMPRESS, dumptype_key);
393 amglue_add_constant(DUMPTYPE_ENCRYPT, dumptype_key);
394 amglue_add_constant(DUMPTYPE_SRV_DECRYPT_OPT, dumptype_key);
395 amglue_add_constant(DUMPTYPE_CLNT_DECRYPT_OPT, dumptype_key);
396 amglue_add_constant(DUMPTYPE_COMPRATE, dumptype_key);
397 amglue_add_constant(DUMPTYPE_TAPE_SPLITSIZE, dumptype_key);
398 amglue_add_constant(DUMPTYPE_FALLBACK_SPLITSIZE, dumptype_key);
399 amglue_add_constant(DUMPTYPE_SPLIT_DISKBUFFER, dumptype_key);
400 amglue_add_constant(DUMPTYPE_RECORD, dumptype_key);
401 amglue_add_constant(DUMPTYPE_SKIP_INCR, dumptype_key);
402 amglue_add_constant(DUMPTYPE_SKIP_FULL, dumptype_key);
403 amglue_add_constant(DUMPTYPE_HOLDINGDISK, dumptype_key);
404 amglue_add_constant(DUMPTYPE_KENCRYPT, dumptype_key);
405 amglue_add_constant(DUMPTYPE_IGNORE, dumptype_key);
406 amglue_add_constant(DUMPTYPE_INDEX, dumptype_key);
407 amglue_add_constant(DUMPTYPE_APPLICATION, dumptype_key);
408 amglue_add_constant(DUMPTYPE_PP_SCRIPTLIST, dumptype_key);
409 amglue_add_constant(DUMPTYPE_PROPERTY, dumptype_key);
410 amglue_copy_to_tag(dumptype_key, getconf);
411
412 amglue_add_enum_tag_fns(interface_key);
413 amglue_add_constant(INTER_COMMENT, interface_key);
414 amglue_add_constant(INTER_MAXUSAGE, interface_key);
415 amglue_copy_to_tag(interface_key, getconf);
416
417 amglue_add_enum_tag_fns(holdingdisk_key);
418 amglue_add_constant(HOLDING_COMMENT, holdingdisk_key);
419 amglue_add_constant(HOLDING_DISKDIR, holdingdisk_key);
420 amglue_add_constant(HOLDING_DISKSIZE, holdingdisk_key);
421 amglue_add_constant(HOLDING_CHUNKSIZE, holdingdisk_key);
422 amglue_copy_to_tag(holdingdisk_key, getconf);
423
424 amglue_add_enum_tag_fns(application_key);
425 amglue_add_constant(APPLICATION_COMMENT, application_key);
426 amglue_add_constant(APPLICATION_PLUGIN, application_key);
427 amglue_add_constant(APPLICATION_PROPERTY, application_key);
428 amglue_copy_to_tag(application_key, getconf);
429
430 amglue_add_enum_tag_fns(pp_script_key);
431 amglue_add_constant(PP_SCRIPT_COMMENT, pp_script_key);
432 amglue_add_constant(PP_SCRIPT_PLUGIN, pp_script_key);
433 amglue_add_constant(PP_SCRIPT_PROPERTY, pp_script_key);
434 amglue_add_constant(PP_SCRIPT_EXECUTE_ON, pp_script_key);
435 amglue_add_constant(PP_SCRIPT_EXECUTE_WHERE, pp_script_key);
436 amglue_copy_to_tag(pp_script_key, getconf);
437
438 amglue_add_enum_tag_fns(device_config_key);
439 amglue_add_constant(DEVICE_CONFIG_COMMENT, device_config_key);
440 amglue_add_constant(DEVICE_CONFIG_TAPEDEV, device_config_key);
441 amglue_add_constant(DEVICE_CONFIG_DEVICE_PROPERTY, device_config_key);
442 amglue_copy_to_tag(device_config_key, getconf);
443
444 amglue_add_enum_tag_fns(changer_config_key);
445 amglue_add_constant(CHANGER_CONFIG_COMMENT, changer_config_key);
446 amglue_add_constant(CHANGER_CONFIG_TAPEDEV, changer_config_key);
447 amglue_add_constant(CHANGER_CONFIG_TPCHANGER, changer_config_key);
448 amglue_add_constant(CHANGER_CONFIG_CHANGERDEV, changer_config_key);
449 amglue_add_constant(CHANGER_CONFIG_CHANGERFILE, changer_config_key);
450 amglue_copy_to_tag(changer_config_key, getconf);
451
452 /*
453  * Various enumerated conftypes
454  */
455
456 amglue_add_enum_tag_fns(dump_holdingdisk_t);
457 amglue_add_constant(HOLD_NEVER, dump_holdingdisk_t);
458 amglue_add_constant(HOLD_AUTO, dump_holdingdisk_t);
459 amglue_add_constant(HOLD_REQUIRED, dump_holdingdisk_t);
460 amglue_copy_to_tag(dump_holdingdisk_t, getconf);
461
462 amglue_add_enum_tag_fns(comp_t);
463 amglue_add_constant(COMP_NONE, comp_t);
464 amglue_add_constant(COMP_FAST, comp_t);
465 amglue_add_constant(COMP_BEST, comp_t);
466 amglue_add_constant(COMP_CUST, comp_t);
467 amglue_add_constant(COMP_SERVER_FAST, comp_t);
468 amglue_add_constant(COMP_SERVER_BEST, comp_t);
469 amglue_add_constant(COMP_SERVER_CUST, comp_t);
470 amglue_copy_to_tag(comp_t, getconf);
471
472 amglue_add_enum_tag_fns(encrypt_t);
473 amglue_add_constant(ENCRYPT_NONE, encrypt_t);
474 amglue_add_constant(ENCRYPT_CUST, encrypt_t);
475 amglue_add_constant(ENCRYPT_SERV_CUST, encrypt_t);
476 amglue_copy_to_tag(encrypt_t, getconf);
477
478 amglue_add_enum_tag_fns(strategy_t);
479 amglue_add_constant(DS_SKIP, strategy_t);
480 amglue_add_constant(DS_STANDARD, strategy_t);
481 amglue_add_constant(DS_NOFULL, strategy_t);
482 amglue_add_constant(DS_NOINC, strategy_t);
483 amglue_add_constant(DS_4, strategy_t);
484 amglue_add_constant(DS_5, strategy_t);
485 amglue_add_constant(DS_HANOI, strategy_t);
486 amglue_add_constant(DS_INCRONLY, strategy_t);
487 amglue_copy_to_tag(strategy_t, getconf);
488
489 amglue_add_enum_tag_fns(estimate_t);
490 amglue_add_constant(ES_CLIENT, estimate_t);
491 amglue_add_constant(ES_SERVER, estimate_t);
492 amglue_add_constant(ES_CALCSIZE, estimate_t);
493 amglue_copy_to_tag(estimate_t, getconf);
494
495 amglue_add_enum_tag_fns(taperalgo_t);
496 amglue_add_constant(ALGO_FIRST, taperalgo_t);
497 amglue_add_constant(ALGO_FIRSTFIT, taperalgo_t);
498 amglue_add_constant(ALGO_LARGEST, taperalgo_t);
499 amglue_add_constant(ALGO_LARGESTFIT, taperalgo_t);
500 amglue_add_constant(ALGO_SMALLEST, taperalgo_t);
501 amglue_add_constant(ALGO_LAST, taperalgo_t);
502 amglue_copy_to_tag(taperalgo_t, getconf);
503
504 amglue_add_enum_tag_fns(execute_on_t);
505 amglue_add_constant(EXECUTE_ON_PRE_DLE_AMCHECK, execute_on_t);
506 amglue_add_constant(EXECUTE_ON_PRE_HOST_AMCHECK, execute_on_t);
507 amglue_add_constant(EXECUTE_ON_POST_DLE_AMCHECK, execute_on_t);
508 amglue_add_constant(EXECUTE_ON_POST_HOST_AMCHECK, execute_on_t);
509 amglue_add_constant(EXECUTE_ON_PRE_DLE_ESTIMATE, execute_on_t);
510 amglue_add_constant(EXECUTE_ON_PRE_HOST_ESTIMATE, execute_on_t);
511 amglue_add_constant(EXECUTE_ON_POST_DLE_ESTIMATE, execute_on_t);
512 amglue_add_constant(EXECUTE_ON_POST_HOST_ESTIMATE, execute_on_t);
513 amglue_add_constant(EXECUTE_ON_PRE_DLE_BACKUP, execute_on_t);
514 amglue_add_constant(EXECUTE_ON_PRE_HOST_BACKUP, execute_on_t);
515 amglue_add_constant(EXECUTE_ON_POST_DLE_BACKUP, execute_on_t);
516 amglue_add_constant(EXECUTE_ON_POST_HOST_BACKUP, execute_on_t);
517 amglue_copy_to_tag(execute_on_t, getconf);
518
519 amglue_add_enum_tag_fns(send_amreport_on_t);
520 amglue_add_constant(SEND_AMREPORT_ALL, send_amreport_on_t);
521 amglue_add_constant(SEND_AMREPORT_STRANGE, send_amreport_on_t);
522 amglue_add_constant(SEND_AMREPORT_ERROR, send_amreport_on_t);
523 amglue_add_constant(SEND_AMREPORT_NEVER, send_amreport_on_t);
524 amglue_copy_to_tag(send_amreport_on_t, getconf);
525
526 /*
527  * val_t typemaps
528  */
529
530 /* Typemap to convert a val_t, the union in which config values are
531  * stored, to a Perl value of the appropriate type.  This converts:
532  *  - CONFTYPE_SIZE, CONFTYPE_INT, CONFTYPE_INT64,
533  *    CONFTYPE_BOOLEAN -> IV
534  *  - CONFTYPE_REAL -> NV
535  *  - CONFTYPE_STR, CONFTYPE_IDENT -> PV
536  *  - CONFTYPE_TIME -> IV (epoch timestamp)
537  *  - CONFTYPE_COMPRESS, CONFTYPE_ENCRYPT, CONFTYPE_ESTIMATE, CONFTYPE_STRATEGY,
538  *    CONFTYPE_TAPERALGO, CONFTYPE_PRIORITY, CONFTYPE_HOLDING, CONFTYPE_EXECUTE_ON,
539  *    CONFTYPE_EXECUTE_WHERE, SEND_AMREPORT_ON -> IV (enums)
540  *  - CONFTYPE_RATE -> list of two NVs
541  *  - CONFTYPE_INTRANGE -> list of two IVs
542  *  - CONFTYPE_EXINCLUDE -> hashref with keys 'list' (listref), 'file' (listref), 
543  *    and 'optional' (int)
544  *  - CONFTYPE_PROPLIST -> hashref of hashref with keys 'append' (IV), 'priority' (IV),
545  *                                                      'values' (listref)
546  */
547 %typemap (out) val_t * {
548     if (!$1) {
549         $result = &PL_sv_undef;
550         argvi++;
551     } else {
552         switch ($1->type) {
553             case CONFTYPE_RATE: {
554                 $result= sv_newmortal();
555                 sv_setnv($result, val_t__rate($1)[0]);
556                 argvi++;
557
558                 $result= sv_newmortal();
559                 sv_setnv($result, val_t__rate($1)[1]);
560                 argvi++;
561                 break;
562             }
563
564             case CONFTYPE_INTRANGE: {
565                 $result= sv_newmortal();
566                 sv_setiv($result, val_t__intrange($1)[0]);
567                 argvi++;
568
569                 $result= sv_newmortal();
570                 sv_setiv($result, val_t__intrange($1)[1]);
571                 argvi++;
572                 break;
573                 break;
574             }
575
576             case CONFTYPE_EXINCLUDE: {
577                 /* exincludes are represented in perl as {
578                  *      'list' : [ 'list1', 'list2', ..],
579                  *      'file' : [ 'file1', 'file2', ..],
580                  *      'optional' : 1,
581                  * }
582                  */
583                 exinclude_t *ei = &val_t__exinclude($1);
584                 AV *list_entries = (AV *)sv_2mortal((SV *)newAV());
585                 AV *file_entries = (AV *)sv_2mortal((SV *)newAV());
586                 SV *optional = sv_newmortal();
587                 HV *hv;
588                 sle_t *iter;
589
590                 /* first set up each of the hash values */
591
592                 if (ei->sl_list) {
593                     for (iter = ei->sl_list->first; iter != NULL; iter = iter->next) {
594                         av_push(list_entries, newSVpv(iter->name, 0));
595                     }
596                 }
597
598                 if(ei->sl_file) {
599                     for (iter = ei->sl_file->first; iter != NULL; iter = iter->next) {
600                         av_push(file_entries, newSVpv(iter->name, 0));
601                     }
602                 }
603
604                 sv_setiv(optional, ei->optional);
605
606                 /* now build the hash */
607                 hv = (HV *)sv_2mortal((SV *)newHV());
608                 
609                 hv_store(hv, "file", 4, newRV((SV *)file_entries), 0);
610                 hv_store(hv, "list", 4, newRV((SV *)list_entries), 0);
611                 hv_store(hv, "optional", 8, optional, 0);
612                 SvREFCNT_inc(optional);
613
614                 $result = sv_2mortal(newRV((SV *)hv));
615                 argvi++;
616                 break;
617             }
618
619             case CONFTYPE_PROPLIST:
620                 $result = sv_2mortal(g_hash_table_to_hashref_property(val_t__proplist($1)));
621                 argvi++;
622                 break;
623
624             case CONFTYPE_SIZE:
625                 $result = sv_2mortal(amglue_newSVi64(val_t__size($1)));
626                 argvi++;
627                 break;
628
629             case CONFTYPE_INT64:
630                 $result = sv_2mortal(amglue_newSVi64(val_t__int64($1)));
631                 argvi++;
632                 break;
633
634             case CONFTYPE_BOOLEAN:          /* all same as INT.. */
635             case CONFTYPE_COMPRESS:
636             case CONFTYPE_ENCRYPT:
637             case CONFTYPE_ESTIMATE:
638             case CONFTYPE_STRATEGY:
639             case CONFTYPE_TAPERALGO:
640             case CONFTYPE_PRIORITY:
641             case CONFTYPE_HOLDING:
642             case CONFTYPE_EXECUTE_ON:
643             case CONFTYPE_EXECUTE_WHERE:
644             case CONFTYPE_SEND_AMREPORT_ON:
645             case CONFTYPE_INT:
646                 $result = sv_2mortal(amglue_newSVi64(val_t__int($1)));
647                 argvi++;
648                 break;
649
650             case CONFTYPE_TIME:
651                 $result = sv_2mortal(amglue_newSVi64(val_t__time($1)));
652                 argvi++;
653                 break;
654
655             case CONFTYPE_REAL:
656                 $result = sv_newmortal();
657                 sv_setnv($result, val_t__real($1));
658                 argvi++;
659                 break;
660
661             case CONFTYPE_IDENT:            /* same as STRING */
662             case CONFTYPE_STR:
663                 $result = sv_newmortal();
664                 sv_setpv($result, val_t__str($1));
665                 argvi++;
666                 break;
667
668             /* No match yet -> not one of the "complex" types */
669             default:
670                 SWIG_exception(SWIG_TypeError, "Unknown val_t conftype");
671                 break;
672         }
673     }
674 }
675
676 /* Typemap for the return value of getconf_list; this assumes that
677  * the GSList contains strings, and that it should be freed; both
678  * are true for getconf_list.
679  */
680 %typemap (out) GSList * {
681     GSList *it = $1;
682
683     while (it) {
684         $result = sv_2mortal(newSVpv(it->data, 0));
685         argvi++;
686         it = it->next;
687     }
688
689     g_slist_free($1);
690 }
691
692 /* typedef and typemap for getconf_byname_strs, which is like getconf_byname, 
693  * but converts the result with val_t_dispaly_strs
694  */
695 %typemap (out) val_t_strs {
696     char **it = $1;
697
698     while (it && *it) {
699         $result = sv_2mortal(newSVpv(*it, 0));
700         argvi++;
701         it++;
702     }
703     g_strfreev($1);
704 }
705
706 val_t *getconf(confparm_key key);
707 gboolean getconf_seen(confparm_key key);
708 val_t *getconf_byname(char *key);
709 GSList *getconf_list(char *listname);
710 %inline %{
711 typedef char **val_t_strs;
712 val_t_strs getconf_byname_strs(char *key, int str_needs_quotes) {
713     val_t *val = getconf_byname(key);
714     if (!val) return NULL;
715     return val_t_display_strs(val, str_needs_quotes);
716 }
717 %}
718
719 amglue_export_tag(getconf,
720     getconf getconf_seen 
721     getconf_byname getconf_byname_strs
722     getconf_list
723 );
724
725 tapetype_t *lookup_tapetype(char *identifier);
726 val_t *tapetype_getconf(tapetype_t *ttyp, tapetype_key key);
727 char *tapetype_name(tapetype_t *ttyp);
728 gboolean tapetype_seen(tapetype_t *ttyp, tapetype_key key);
729 amglue_export_tag(getconf,
730     lookup_tapetype tapetype_getconf tapetype_name
731     tapetype_seen tapetype_seen
732 );
733
734 dumptype_t *lookup_dumptype(char *identifier);
735 val_t *dumptype_getconf(dumptype_t *dtyp, dumptype_key key);
736 char *dumptype_name(dumptype_t *dtyp);
737 gboolean dumptype_seen(dumptype_t *dtyp, dumptype_key key);
738 amglue_export_tag(getconf,
739     lookup_dumptype dumptype_getconf dumptype_name
740     dumptype_seen dumptype_seen
741 );
742
743 interface_t *lookup_interface(char *identifier);
744 val_t *interface_getconf(interface_t *iface, interface_key key);
745 char *interface_name(interface_t *iface);
746 gboolean interface_seen(interface_t *iface, interface_key key);
747 amglue_export_tag(getconf,
748     lookup_interface interface_getconf interface_name
749     interface_seen interface_seen
750 );
751
752 holdingdisk_t *lookup_holdingdisk(char *identifier);
753 holdingdisk_t *getconf_holdingdisks(void);
754 holdingdisk_t *holdingdisk_next(holdingdisk_t *hdisk);
755 val_t *holdingdisk_getconf(holdingdisk_t *hdisk, holdingdisk_key key);
756 char *holdingdisk_name(holdingdisk_t *hdisk);
757 gboolean holdingdisk_seen(holdingdisk_t *hdisk, holdingdisk_key key);
758 amglue_export_tag(getconf,
759     lookup_holdingdisk holdingdisk_getconf holdingdisk_name
760     getconf_holdingdisks holdingdisk_next
761     holdingdisk_seen holdingdisk_seen
762 );
763
764 application_t *lookup_application(char *identifier);
765 val_t *application_getconf(application_t *app, application_key key);
766 char *application_name(application_t *app);
767 gboolean application_seen(application_t *app, application_key key);
768 amglue_export_tag(getconf,
769     lookup_application application_getconf application_name
770     application_seen application_seen
771 );
772
773 pp_script_t *lookup_pp_script(char *identifier);
774 val_t *pp_script_getconf(pp_script_t *pps, pp_script_key key);
775 char *pp_script_name(pp_script_t *pps);
776 gboolean pp_script_seen(pp_script_t *app, pp_script_key key);
777 amglue_export_tag(getconf,
778     lookup_pp_script pp_script_getconf pp_script_name
779     pp_script_seen pp_script_seen
780 );
781
782 device_config_t *lookup_device_config(char *identifier);
783 val_t *device_config_getconf(device_config_t *pps, device_config_key key);
784 char *device_config_name(device_config_t *pps);
785 gboolean device_config_seen(device_config_t *app, device_config_key key);
786 amglue_export_tag(getconf,
787     lookup_device_config device_config_getconf device_config_name
788     device_config_seen device_config_seen
789 );
790
791 changer_config_t *lookup_changer_config(char *identifier);
792 val_t *changer_config_getconf(changer_config_t *pps, changer_config_key key);
793 char *changer_config_name(changer_config_t *pps);
794 gboolean changer_config_seen(changer_config_t *app, changer_config_key key);
795 amglue_export_tag(getconf,
796     lookup_changer_config changer_config_getconf changer_config_name
797     changer_config_seen changer_config_seen
798 );
799
800 %perlcode %{
801 our %subsection_names = (
802     "tapetype" => 1,
803     "dumptype" => 1,
804     "interface" => 1,
805     "holdingdisk" => 1,
806     "application-tool" => 1,
807     "script-tool" => 1,
808     "device" => 1,
809     "changer" => 1,
810 );
811 %}
812 amglue_export_tag(getconf, %subsection_names);
813
814 long int getconf_unit_divisor(void);
815
816 extern int debug_amandad;
817 extern int debug_amidxtaped;
818 extern int debug_amindexd;
819 extern int debug_amrecover;
820 extern int debug_auth;
821 extern int debug_event;
822 extern int debug_holding;
823 extern int debug_protocol;
824 extern int debug_planner;
825 extern int debug_driver;
826 extern int debug_dumper;
827 extern int debug_chunker;
828 extern int debug_taper;
829 extern int debug_selfcheck;
830 extern int debug_sendsize;
831 extern int debug_sendbackup;
832 amglue_export_tag(getconf,
833     getconf_unit_divisor
834
835     $debug_amandad $debug_amidxtaped $debug_amindexd $debug_amrecover
836     $debug_auth $debug_event $debug_holding $debug_protocol
837     $debug_planner $debug_driver $debug_dumper $debug_chunker
838     $debug_taper $debug_selfcheck $debug_sendsize $debug_sendbackup
839 );
840
841 /*
842  * Initialization
843  */
844
845 amglue_add_enum_tag_fns(cfgerr_level_t);
846 amglue_add_constant(CFGERR_OK, cfgerr_level_t);
847 amglue_add_constant(CFGERR_WARNINGS, cfgerr_level_t);
848 amglue_add_constant(CFGERR_ERRORS, cfgerr_level_t);
849 amglue_copy_to_tag(cfgerr_level_t, init);
850
851 amglue_add_flag_tag_fns(config_init_flags);
852 amglue_add_constant(CONFIG_INIT_EXPLICIT_NAME, config_init_flags);
853 amglue_add_constant(CONFIG_INIT_USE_CWD, config_init_flags);
854 amglue_add_constant(CONFIG_INIT_CLIENT, config_init_flags);
855 amglue_add_constant(CONFIG_INIT_OVERLAY, config_init_flags);
856 amglue_copy_to_tag(config_init_flags, init);
857
858 gboolean config_init(config_init_flags flags,
859                      char *arg_config_name);
860 void config_uninit(void);
861 char **get_config_options(int first);
862 char *get_config_name(void);
863 char *get_config_dir(void);
864 char *get_config_filename(void);
865
866 void config_print_errors(void);
867 void config_clear_errors(void);
868
869 /* Typemap for config_errors' result parameter; this is a GSList of strings
870  * which should *not* be freed. */
871 %typemap(in, numinputs=0) GSList **ERRLIST (GSList *templist) {
872    templist = NULL;
873    $1 = &templist;
874 }
875
876 %typemap (argout) GSList **ERRLIST {
877     GSList *it = *$1;
878
879     while (it) {
880         $result = sv_2mortal(newSVpv(it->data, 0));
881         argvi++;
882         it = it->next;
883     }
884 }
885 cfgerr_level_t config_errors(GSList **ERRLIST);
886
887
888 config_overwrites_t *new_config_overwrites(int size_estimate);
889 void free_config_overwrites(config_overwrites_t *co);
890 void add_config_overwrite(config_overwrites_t *co,
891                          char *key,
892                          char *value);
893 void add_config_overwrite_opt(config_overwrites_t *co,
894                               char *optarg);
895 cfgerr_level_t apply_config_overwrites(config_overwrites_t *co);
896
897 amglue_export_tag(init,
898     config_init config_uninit get_config_options
899     get_config_name get_config_dir get_config_filename
900     config_print_errors config_clear_errors config_errors
901     new_config_overwrites free_config_overwrites add_config_overwrite
902     add_config_overwrite_opt apply_config_overwrites
903 );
904
905 /*
906  * Miscellaneous
907  */
908
909 void dump_configuration(void);
910 %newobject config_dir_relative;
911 char *config_dir_relative(char *filename);
912 char *taperalgo2str(taperalgo_t taperalgo);
913 gint64 find_multiplier(char * casestr);
914
915 amglue_export_ok(
916     dump_configuration config_dir_relative taperalgo2str find_multiplier
917 );
918