6573f1b52570568e75ace46f255632fbc381d979
[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., 505 N Mathlida Ave, Suite 120
18  * Sunnyvale, CA 94085, 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 L<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 =item If C<CONFIG_INIT_FATAL> is given, then any errors are considered
81 fatal, and C<config_init> does not return.
82
83 =back
84
85 See C<conffile.h> for more detailed information on these flags and
86 their interactions.
87
88 C<config_uninit()> reverses the effects of C<config_init>.  It is
89 not often used.
90
91 Once the configuration is loaded, the configuration name
92 (e.g., "DailySet1"), directory (C</etc/amanda/DailySet1>),
93 and filename (C</etc/amanda/DailySet1/amanda.conf>) are
94 available from C<get_config_name()>, C<get_config_dir()>, and
95 C<get_config_filename()>, respectively.
96
97 =head2 CONFIG OVERWRITES
98
99 Most Amanda applications accept the command-line option C<-o>
100 to "overwrite" configuration values in C<amanda.conf>.  In Perl
101 applications, these options should be parsed with L<Getopt::Long>, with
102 the action being a call to C<add_config_overwrite_opt>.  For example:
103
104   my $config_overwrites = new_config_overwrites($#ARGV+1);
105     GetOptions(
106         # ...
107         'o=s' => sub { add_config_overwrite_opt($config_overwrites, $_[1]); },
108     ) or usage();
109   my $cfg_ok = config_init($CONFIG_INIT_EXPLICIT_NAME | $CONFIG_INIT_USE_CWD, $config_name);
110   apply_config_overwrites($config_overwrites);
111
112 C<new_config_overwrites($size_estimate)> creates a new
113 overwrites object, using the given size as an estimate of
114 the number of items it will contain (C<$#ARGC/2> is a good
115 estimate).  Individual configuration options are then added via
116 C<add_config_overwrite($co, $key, $value)> (which takes a key/value
117 pair) or C<add_config_overwrite_opt($co, $optarg)>, which parses a
118 string following C<-o> on the command line.
119
120 Once the overwrites are gathered, they are applied with
121 C<apply_config_overwrites($co)>, which applies the overwrites to the
122 active configuration.  No further operations can be performed on the
123 overwrites object after C<apply_config_overwrites> has been called.
124
125 The utility function C<get_config_options()> returns a list of
126 command-line arguments to represent any overwrites that were used
127 to generate the current configuration.  (TODO: this function isn't
128 available yet)
129
130 =head1 PARAMETER ACCESS
131
132 Amanda configurations consist of "global" parameters and several
133 sets of "subsections" -- one set for dumptypes, one for tapetypes,
134 and so on.
135
136 All of the global parameters are represented by a constant beginning
137 with C<$CNF_>, e.g., C<$CNF_LABELSTR>.  The function C<getconf($cnf)>
138 returns the value of parameter C<$cnf>, in whatever format is
139 appropriate for the parameter.  C<getconf_seen($cnf)> returns a true
140 value if C<$cnf> was seen in the configuration file.  If it was not
141 seen, then it will have its default value.
142
143 Some parameters have enumerated types.  The values for those
144 enumerations are available from this module with the same name as
145 in C<conffile.h>.  For example, C<$CNF_TAPERALGO> will yield a value
146 from the enumeration C<taperalgo_t>, the constants for which all
147 begin with C<$ALGO_>.  See C<conffile.h> for the details.
148
149 Each subsection type has the following functions:
150
151 =over
152
153 =item C<lookup_TYP($subsec_name)>, which returns an opaque object
154 (C<$ss>) representing the subsection, or C<undef> if no subsection
155 with that name exists;
156
157 =item C<TYP_name($ss)>, returning the name of the subsection;
158
159 =item C<TYP_getconf($ss, $cnf)>, which fetches a parameter value from
160 C<$ss>; and
161
162 =item C<TYP_seen($ss, $cnf)>, which returns a true value if <$cnf>
163 was seen in the subsection.
164
165 =back
166
167 The subsections are:
168
169 =over
170
171 =item C<tapetype>, with constants beginning with C<$TAPETYPE_>,
172
173 =item C<dumptype>, with constants beginning with C<$DUMPTYPE_>,
174
175 =item C<interface>, with constants beginning with C<$INTER_>, and
176
177 =item C<holdingdisk>, with constants beginning with C<$HOLDING_>.
178
179 =back
180
181 See C<conffile.h> for the names of the constants themselves.
182
183 Parameter values are available by name from C<getconf_byname($name)>.
184 This function implements the C<TYP:NAME:PARAM> syntax advertised by
185 C<amgetconf> to access values in subsections.  C<getconf_list($typ)>
186 returns a list of the names of all subsections of the given type.
187
188 The C<$CNF_DISPLAYUNIT> implies a certain divisor to convert from
189 kilobytes to the desired unit.  This divisor is available from
190 C<getconf_unit_divisor()>.  Note carefully that it is a I<divisor>
191 for a value in I<kilobytes>!
192
193 Finally, various subsections of Amanda enable verbose debugging via
194 configuration parameters.  The status of each parameter is available
195 a similarly-named variable, e.g., C<$debug_auth>.
196
197 All parameter access functions and constants can be imported with
198 the tag C<:getconf>.
199
200 =head1 MISCELLANEOUS
201
202 These functions defy categorization.
203
204 The function C<config_dir_relative> will interpret a path relative to
205 the current configuration directory.  Absolute paths are passed through
206 unchanged, while relative paths are converted to absolute paths.
207
208 C<dump_configuration()> dumps the current configuration, in a format
209 suitable for re-evaluation for this module, to standard output.
210 This function may be revised to return a string.
211
212 Several parts of Amanda need to convert unit modifier value like
213 "gbytes" to a multiplier.  The function C<find_multiplier($str)>
214 returns the unit multiplier for such a string.  For example, "mbytes"
215 is converted to 1048576 (1024*1024).
216
217 =cut
218 %}
219
220 /*
221  * Parameter access
222 */
223
224 /* All of the CNF_ flags from conffile.h */
225
226 amglue_add_enum_tag_fns(confparm_key);
227 amglue_add_constant(CNF_ORG, confparm_key);
228 amglue_add_constant(CNF_CONF, confparm_key);
229 amglue_add_constant(CNF_INDEX_SERVER, confparm_key);
230 amglue_add_constant(CNF_TAPE_SERVER, confparm_key);
231 amglue_add_constant(CNF_AUTH, confparm_key);
232 amglue_add_constant(CNF_SSH_KEYS, confparm_key);
233 amglue_add_constant(CNF_AMANDAD_PATH, confparm_key);
234 amglue_add_constant(CNF_CLIENT_USERNAME, confparm_key);
235 amglue_add_constant(CNF_GNUTAR_LIST_DIR, confparm_key);
236 amglue_add_constant(CNF_AMANDATES, confparm_key);
237 amglue_add_constant(CNF_MAILTO, confparm_key);
238 amglue_add_constant(CNF_DUMPUSER, confparm_key);
239 amglue_add_constant(CNF_TAPEDEV, confparm_key);
240 amglue_add_constant(CNF_DEVICE_PROPERTY, confparm_key);
241 amglue_add_constant(CNF_CHANGERDEV, confparm_key);
242 amglue_add_constant(CNF_CHANGERFILE, confparm_key);
243 amglue_add_constant(CNF_LABELSTR, confparm_key);
244 amglue_add_constant(CNF_TAPELIST, confparm_key);
245 amglue_add_constant(CNF_DISKFILE, confparm_key);
246 amglue_add_constant(CNF_INFOFILE, confparm_key);
247 amglue_add_constant(CNF_LOGDIR, confparm_key);
248 amglue_add_constant(CNF_INDEXDIR, confparm_key);
249 amglue_add_constant(CNF_TAPETYPE, confparm_key);
250 amglue_add_constant(CNF_DUMPCYCLE, confparm_key);
251 amglue_add_constant(CNF_RUNSPERCYCLE, confparm_key);
252 amglue_add_constant(CNF_TAPECYCLE, confparm_key);
253 amglue_add_constant(CNF_NETUSAGE, confparm_key);
254 amglue_add_constant(CNF_INPARALLEL, confparm_key);
255 amglue_add_constant(CNF_DUMPORDER, confparm_key);
256 amglue_add_constant(CNF_BUMPPERCENT, confparm_key);
257 amglue_add_constant(CNF_BUMPSIZE, confparm_key);
258 amglue_add_constant(CNF_BUMPMULT, confparm_key);
259 amglue_add_constant(CNF_BUMPDAYS, confparm_key);
260 amglue_add_constant(CNF_TPCHANGER, confparm_key);
261 amglue_add_constant(CNF_RUNTAPES, confparm_key);
262 amglue_add_constant(CNF_MAXDUMPS, confparm_key);
263 amglue_add_constant(CNF_ETIMEOUT, confparm_key);
264 amglue_add_constant(CNF_DTIMEOUT, confparm_key);
265 amglue_add_constant(CNF_CTIMEOUT, confparm_key);
266 amglue_add_constant(CNF_TAPEBUFS, confparm_key);
267 amglue_add_constant(CNF_DEVICE_OUTPUT_BUFFER_SIZE, confparm_key);
268 amglue_add_constant(CNF_PRINTER, confparm_key);
269 amglue_add_constant(CNF_AUTOFLUSH, confparm_key);
270 amglue_add_constant(CNF_RESERVE, confparm_key);
271 amglue_add_constant(CNF_MAXDUMPSIZE, confparm_key);
272 amglue_add_constant(CNF_COLUMNSPEC, confparm_key);
273 amglue_add_constant(CNF_AMRECOVER_DO_FSF, confparm_key);
274 amglue_add_constant(CNF_AMRECOVER_CHECK_LABEL, confparm_key);
275 amglue_add_constant(CNF_AMRECOVER_CHANGER, confparm_key);
276 amglue_add_constant(CNF_TAPERALGO, confparm_key);
277 amglue_add_constant(CNF_FLUSH_THRESHOLD_DUMPED, confparm_key);
278 amglue_add_constant(CNF_FLUSH_THRESHOLD_SCHEDULED, confparm_key);
279 amglue_add_constant(CNF_TAPERFLUSH, confparm_key);
280 amglue_add_constant(CNF_DISPLAYUNIT, confparm_key);
281 amglue_add_constant(CNF_KRB5KEYTAB, confparm_key);
282 amglue_add_constant(CNF_KRB5PRINCIPAL, confparm_key);
283 amglue_add_constant(CNF_LABEL_NEW_TAPES, confparm_key);
284 amglue_add_constant(CNF_USETIMESTAMPS, confparm_key);
285 amglue_add_constant(CNF_REP_TRIES, confparm_key);
286 amglue_add_constant(CNF_CONNECT_TRIES, confparm_key);
287 amglue_add_constant(CNF_REQ_TRIES, confparm_key);
288 amglue_add_constant(CNF_DEBUG_AMANDAD, confparm_key);
289 amglue_add_constant(CNF_DEBUG_AMIDXTAPED, confparm_key);
290 amglue_add_constant(CNF_DEBUG_AMINDEXD, confparm_key);
291 amglue_add_constant(CNF_DEBUG_AMRECOVER, confparm_key);
292 amglue_add_constant(CNF_DEBUG_AUTH, confparm_key);
293 amglue_add_constant(CNF_DEBUG_EVENT, confparm_key);
294 amglue_add_constant(CNF_DEBUG_HOLDING, confparm_key);
295 amglue_add_constant(CNF_DEBUG_PROTOCOL, confparm_key);
296 amglue_add_constant(CNF_DEBUG_PLANNER, confparm_key);
297 amglue_add_constant(CNF_DEBUG_DRIVER, confparm_key);
298 amglue_add_constant(CNF_DEBUG_DUMPER, confparm_key);
299 amglue_add_constant(CNF_DEBUG_CHUNKER, confparm_key);
300 amglue_add_constant(CNF_DEBUG_TAPER, confparm_key);
301 amglue_add_constant(CNF_DEBUG_SELFCHECK, confparm_key);
302 amglue_add_constant(CNF_DEBUG_SENDSIZE, confparm_key);
303 amglue_add_constant(CNF_DEBUG_SENDBACKUP, confparm_key);
304 amglue_add_constant(CNF_RESERVED_UDP_PORT, confparm_key);
305 amglue_add_constant(CNF_RESERVED_TCP_PORT, confparm_key);
306 amglue_add_constant(CNF_UNRESERVED_TCP_PORT, confparm_key);
307 amglue_copy_to_tag(confparm_key, getconf);
308
309 amglue_add_enum_tag_fns(tapetype_key);
310 amglue_add_constant(TAPETYPE_COMMENT, tapetype_key);
311 amglue_add_constant(TAPETYPE_LBL_TEMPL, tapetype_key);
312 amglue_add_constant(TAPETYPE_BLOCKSIZE, tapetype_key);
313 amglue_add_constant(TAPETYPE_READBLOCKSIZE, tapetype_key);
314 amglue_add_constant(TAPETYPE_LENGTH, tapetype_key);
315 amglue_add_constant(TAPETYPE_FILEMARK, tapetype_key);
316 amglue_add_constant(TAPETYPE_SPEED, tapetype_key);
317 amglue_add_constant(TAPETYPE_FILE_PAD, tapetype_key);
318 amglue_copy_to_tag(tapetype_key, getconf);
319
320 amglue_add_enum_tag_fns(dumptype_key);
321 amglue_add_constant(DUMPTYPE_COMMENT, dumptype_key);
322 amglue_add_constant(DUMPTYPE_PROGRAM, dumptype_key);
323 amglue_add_constant(DUMPTYPE_SRVCOMPPROG, dumptype_key);
324 amglue_add_constant(DUMPTYPE_CLNTCOMPPROG, dumptype_key);
325 amglue_add_constant(DUMPTYPE_SRV_ENCRYPT, dumptype_key);
326 amglue_add_constant(DUMPTYPE_CLNT_ENCRYPT, dumptype_key);
327 amglue_add_constant(DUMPTYPE_AMANDAD_PATH, dumptype_key);
328 amglue_add_constant(DUMPTYPE_CLIENT_USERNAME, dumptype_key);
329 amglue_add_constant(DUMPTYPE_SSH_KEYS, dumptype_key);
330 amglue_add_constant(DUMPTYPE_SECURITY_DRIVER, dumptype_key);
331 amglue_add_constant(DUMPTYPE_EXCLUDE, dumptype_key);
332 amglue_add_constant(DUMPTYPE_INCLUDE, dumptype_key);
333 amglue_add_constant(DUMPTYPE_PRIORITY, dumptype_key);
334 amglue_add_constant(DUMPTYPE_DUMPCYCLE, dumptype_key);
335 amglue_add_constant(DUMPTYPE_MAXDUMPS, dumptype_key);
336 amglue_add_constant(DUMPTYPE_MAXPROMOTEDAY, dumptype_key);
337 amglue_add_constant(DUMPTYPE_BUMPPERCENT, dumptype_key);
338 amglue_add_constant(DUMPTYPE_BUMPSIZE, dumptype_key);
339 amglue_add_constant(DUMPTYPE_BUMPDAYS, dumptype_key);
340 amglue_add_constant(DUMPTYPE_BUMPMULT, dumptype_key);
341 amglue_add_constant(DUMPTYPE_STARTTIME, dumptype_key);
342 amglue_add_constant(DUMPTYPE_STRATEGY, dumptype_key);
343 amglue_add_constant(DUMPTYPE_ESTIMATE, dumptype_key);
344 amglue_add_constant(DUMPTYPE_COMPRESS, dumptype_key);
345 amglue_add_constant(DUMPTYPE_ENCRYPT, dumptype_key);
346 amglue_add_constant(DUMPTYPE_SRV_DECRYPT_OPT, dumptype_key);
347 amglue_add_constant(DUMPTYPE_CLNT_DECRYPT_OPT, dumptype_key);
348 amglue_add_constant(DUMPTYPE_COMPRATE, dumptype_key);
349 amglue_add_constant(DUMPTYPE_TAPE_SPLITSIZE, dumptype_key);
350 amglue_add_constant(DUMPTYPE_FALLBACK_SPLITSIZE, dumptype_key);
351 amglue_add_constant(DUMPTYPE_SPLIT_DISKBUFFER, dumptype_key);
352 amglue_add_constant(DUMPTYPE_RECORD, dumptype_key);
353 amglue_add_constant(DUMPTYPE_SKIP_INCR, dumptype_key);
354 amglue_add_constant(DUMPTYPE_SKIP_FULL, dumptype_key);
355 amglue_add_constant(DUMPTYPE_HOLDINGDISK, dumptype_key);
356 amglue_add_constant(DUMPTYPE_KENCRYPT, dumptype_key);
357 amglue_add_constant(DUMPTYPE_IGNORE, dumptype_key);
358 amglue_add_constant(DUMPTYPE_INDEX, dumptype_key);
359 amglue_copy_to_tag(dumptype_key, getconf);
360
361 amglue_add_enum_tag_fns(interface_key);
362 amglue_add_constant(INTER_COMMENT, interface_key);
363 amglue_add_constant(INTER_MAXUSAGE, interface_key);
364 amglue_copy_to_tag(interface_key, getconf);
365
366 amglue_add_enum_tag_fns(holdingdisk_key);
367 amglue_add_constant(HOLDING_COMMENT, holdingdisk_key);
368 amglue_add_constant(HOLDING_DISKDIR, holdingdisk_key);
369 amglue_add_constant(HOLDING_DISKSIZE, holdingdisk_key);
370 amglue_add_constant(HOLDING_CHUNKSIZE, holdingdisk_key);
371 amglue_copy_to_tag(holdingdisk_key, getconf);
372
373 /*
374  * Various enumerated conftypes
375  */
376
377 amglue_add_enum_tag_fns(dump_holdingdisk_t);
378 amglue_add_constant(HOLD_NEVER, dump_holdingdisk_t);
379 amglue_add_constant(HOLD_AUTO, dump_holdingdisk_t);
380 amglue_add_constant(HOLD_REQUIRED, dump_holdingdisk_t);
381 amglue_copy_to_tag(dump_holdingdisk_t, getconf);
382
383 amglue_add_enum_tag_fns(comp_t);
384 amglue_add_constant(COMP_NONE, comp_t);
385 amglue_add_constant(COMP_FAST, comp_t);
386 amglue_add_constant(COMP_BEST, comp_t);
387 amglue_add_constant(COMP_CUST, comp_t);
388 amglue_add_constant(COMP_SERVER_FAST, comp_t);
389 amglue_add_constant(COMP_SERVER_BEST, comp_t);
390 amglue_add_constant(COMP_SERVER_CUST, comp_t);
391 amglue_copy_to_tag(comp_t, getconf);
392
393 amglue_add_enum_tag_fns(encrypt_t);
394 amglue_add_constant(ENCRYPT_NONE, encrypt_t);
395 amglue_add_constant(ENCRYPT_CUST, encrypt_t);
396 amglue_add_constant(ENCRYPT_SERV_CUST, encrypt_t);
397 amglue_copy_to_tag(encrypt_t, getconf);
398
399 amglue_add_enum_tag_fns(strategy_t);
400 amglue_add_constant(DS_SKIP, strategy_t);
401 amglue_add_constant(DS_STANDARD, strategy_t);
402 amglue_add_constant(DS_NOFULL, strategy_t);
403 amglue_add_constant(DS_NOINC, strategy_t);
404 amglue_add_constant(DS_4, strategy_t);
405 amglue_add_constant(DS_5, strategy_t);
406 amglue_add_constant(DS_HANOI, strategy_t);
407 amglue_add_constant(DS_INCRONLY, strategy_t);
408 amglue_copy_to_tag(strategy_t, getconf);
409
410 amglue_add_enum_tag_fns(estimate_t);
411 amglue_add_constant(ES_CLIENT, estimate_t);
412 amglue_add_constant(ES_SERVER, estimate_t);
413 amglue_add_constant(ES_CALCSIZE, estimate_t);
414 amglue_copy_to_tag(estimate_t, getconf);
415
416 amglue_add_enum_tag_fns(taperalgo_t);
417 amglue_add_constant(ALGO_FIRST, taperalgo_t);
418 amglue_add_constant(ALGO_FIRSTFIT, taperalgo_t);
419 amglue_add_constant(ALGO_LARGEST, taperalgo_t);
420 amglue_add_constant(ALGO_LARGESTFIT, taperalgo_t);
421 amglue_add_constant(ALGO_SMALLEST, taperalgo_t);
422 amglue_add_constant(ALGO_LAST, taperalgo_t);
423 amglue_copy_to_tag(taperalgo_t, getconf);
424
425 /*
426  * val_t typemaps
427  */
428
429 /* Typemap to convert a val_t, the union in which config values are
430  * stored, to a Perl value of the appropriate type.  This converts:
431  *  - CONFTYPE_SIZE, CONFTYPE_INT, CONFTYPE_AM64,
432  *    CONFTYPE_BOOLEAN -> IV
433  *  - CONFTYPE_REAL -> NV
434  *  - CONFTYPE_STR, CONFTYPE_IDENT -> PV
435  *  - CONFTYPE_TIME -> IV (epoch timestamp)
436  *  - CONFTYPE_COMPRESS, CONFTYPE_ENCRYPT, CONFTYPE_ESTIMATE, CONFTYPE_STRATEGY,
437  *    CONFTYPE_TAPERALGO, CONFTYPE_PRIORITY, CONFTYPE_HOLDING -> IV (enums)
438  *  - CONFTYPE_RATE -> list of two NVs
439  *  - CONFTYPE_INTRANGE -> list of two IVs
440  *  - CONFTYPE_EXINCLUDE -> hashref with keys 'list' (listref), 'file' (listref), 
441  *    and 'optional' (int)
442  *  - CONFTYPE_PROPLIST -> hashref
443  */
444 %typemap (out) val_t * {
445     switch ($1->type) {
446         case CONFTYPE_RATE: {
447             $result= sv_newmortal();
448             sv_setnv($result, val_t__rate($1)[0]);
449             argvi++;
450
451             $result= sv_newmortal();
452             sv_setnv($result, val_t__rate($1)[1]);
453             argvi++;
454             break;
455         }
456
457         case CONFTYPE_INTRANGE: {
458             $result= sv_newmortal();
459             sv_setiv($result, val_t__intrange($1)[0]);
460             argvi++;
461
462             $result= sv_newmortal();
463             sv_setiv($result, val_t__intrange($1)[1]);
464             argvi++;
465             break;
466             break;
467         }
468
469         case CONFTYPE_EXINCLUDE: {
470             /* exincludes are represented in perl as {
471              *  'list' : [ 'list1', 'list2', ..],
472              *  'file' : [ 'file1', 'file2', ..],
473              *  'optional' : 1,
474              * }
475              */
476             exinclude_t *ei = &val_t__exinclude($1);
477             AV *list_entries = (AV *)sv_2mortal((SV *)newAV());
478             AV *file_entries = (AV *)sv_2mortal((SV *)newAV());
479             SV *optional = sv_newmortal();
480             HV *hv;
481             sle_t *iter;
482
483             /* first set up each of the hash values */
484
485             if (ei->sl_list) {
486                 for (iter = ei->sl_list->first; iter != NULL; iter = iter->next) {
487                     av_push(list_entries, newSVpv(iter->name, 0));
488                 }
489             }
490
491             if(ei->sl_file) {
492                 for (iter = ei->sl_file->first; iter != NULL; iter = iter->next) {
493                     av_push(file_entries, newSVpv(iter->name, 0));
494                 }
495             }
496
497             sv_setiv(optional, ei->optional);
498
499             /* now build the hash */
500             hv = (HV *)sv_2mortal((SV *)newHV());
501             
502             hv_store(hv, "file", 4, newRV((SV *)file_entries), 0);
503             hv_store(hv, "list", 4, newRV((SV *)list_entries), 0);
504             hv_store(hv, "optional", 8, optional, 0);
505             SvREFCNT_inc(optional);
506
507             $result = sv_2mortal(newRV((SV *)hv));
508             argvi++;
509             break;
510         }
511
512         case CONFTYPE_PROPLIST:
513             $result = sv_2mortal(g_hash_table_to_hashref(val_t__proplist($1)));
514             argvi++;
515             break;
516
517         case CONFTYPE_SIZE:
518             $result = sv_2mortal(amglue_newSVi64(val_t__size($1)));
519             argvi++;
520             break;
521
522         case CONFTYPE_AM64:
523             $result = sv_2mortal(amglue_newSVi64(val_t__am64($1)));
524             argvi++;
525             break;
526
527         case CONFTYPE_BOOLEAN:      /* all same as INT.. */
528         case CONFTYPE_COMPRESS:
529         case CONFTYPE_ENCRYPT:
530         case CONFTYPE_ESTIMATE:
531         case CONFTYPE_STRATEGY:
532         case CONFTYPE_TAPERALGO:
533         case CONFTYPE_PRIORITY:
534         case CONFTYPE_HOLDING:
535         case CONFTYPE_INT:
536             $result = sv_2mortal(amglue_newSVi64(val_t__int($1)));
537             argvi++;
538             break;
539
540         case CONFTYPE_TIME:
541             $result = sv_2mortal(amglue_newSVi64(val_t__time($1)));
542             argvi++;
543             break;
544
545         case CONFTYPE_REAL:
546             $result = sv_newmortal();
547             sv_setnv($result, val_t__real($1));
548             argvi++;
549             break;
550
551         case CONFTYPE_IDENT:        /* same as STRING */
552         case CONFTYPE_STR:
553             $result = sv_newmortal();
554             sv_setpv($result, val_t__str($1));
555             argvi++;
556             break;
557
558         /* No match yet -> not one of the "complex" types */
559         default:
560             SWIG_exception(SWIG_TypeError, "Unknown val_t conftype");
561             break;
562     }
563 }
564
565 /* Typemap for the return value of getconf_list; this assumes that
566  * the GSList contains strings, and that it should be freed; both
567  * are true for getconf_list.
568  */
569 %typemap (out) GSList * {
570     GSList *it = $1;
571
572     while (it) {
573         $result = sv_2mortal(newSVpv(it->data, 0));
574         argvi++;
575         it = it->next;
576     }
577
578     g_slist_free($1);
579 }
580
581 val_t *getconf(confparm_key key);
582 gboolean getconf_seen(confparm_key key);
583 val_t *getconf_byname(char *key);
584 GSList *getconf_list(char *listname);
585 amglue_export_tag(getconf,
586     getconf getconf_seen 
587     getconf_byname getconf_list
588 );
589
590 tapetype_t *lookup_tapetype(char *identifier);
591 val_t *tapetype_getconf(tapetype_t *ttyp, tapetype_key key);
592 char *tapetype_name(tapetype_t *ttyp);
593 gboolean tapetype_seen(tapetype_t *ttyp, tapetype_key key);
594 amglue_export_tag(getconf,
595     lookup_tapetype tapetype_getconf tapetype_name
596     tapetype_seen tapetype_seen
597 );
598
599 dumptype_t *lookup_dumptype(char *identifier);
600 val_t *dumptype_getconf(dumptype_t *dtyp, dumptype_key key);
601 char *dumptype_name(dumptype_t *dtyp);
602 gboolean dumptype_seen(dumptype_t *dtyp, dumptype_key key);
603 amglue_export_tag(getconf,
604     lookup_dumptype dumptype_getconf dumptype_name
605     dumptype_seen dumptype_seen
606 );
607
608 interface_t *lookup_interface(char *identifier);
609 val_t *interface_getconf(interface_t *iface, interface_key key);
610 char *interface_name(interface_t *iface);
611 gboolean interface_seen(interface_t *iface, interface_key key);
612 amglue_export_tag(getconf,
613     lookup_interface interface_getconf interface_name
614     interface_seen interface_seen
615 );
616
617 holdingdisk_t *lookup_holdingdisk(char *identifier);
618 holdingdisk_t *getconf_holdingdisks(void);
619 holdingdisk_t *holdingdisk_next(holdingdisk_t *hdisk);
620 val_t *holdingdisk_getconf(holdingdisk_t *hdisk, holdingdisk_key key);
621 char *holdingdisk_name(holdingdisk_t *hdisk);
622 gboolean holdingdisk_seen(holdingdisk_t *hdisk, holdingdisk_key key);
623 amglue_export_tag(getconf,
624     lookup_holdingdisk holdingdisk_getconf holdingdisk_name
625     getconf_holdingdisks holdingdisk_next
626     holdingdisk_seen holdingdisk_seen
627 );
628
629 long int getconf_unit_divisor(void);
630
631 extern int debug_amandad;
632 extern int debug_amidxtaped;
633 extern int debug_amindexd;
634 extern int debug_amrecover;
635 extern int debug_auth;
636 extern int debug_event;
637 extern int debug_holding;
638 extern int debug_protocol;
639 extern int debug_planner;
640 extern int debug_driver;
641 extern int debug_dumper;
642 extern int debug_chunker;
643 extern int debug_taper;
644 extern int debug_selfcheck;
645 extern int debug_sendsize;
646 extern int debug_sendbackup;
647 amglue_export_tag(getconf,
648     getconf_unit_divisor
649
650     $debug_amandad $debug_amidxtaped $debug_amindexd $debug_amrecover
651     $debug_auth $debug_event $debug_holding $debug_protocol
652     $debug_planner $debug_driver $debug_dumper $debug_chunker
653     $debug_taper $debug_selfcheck $debug_sendsize $debug_sendbackup
654 );
655
656 /*
657  * Initialization
658  */
659
660 config_overwrites_t *new_config_overwrites(int size_estimate);
661 void free_config_overwrites(config_overwrites_t *co);
662 void add_config_overwrite(config_overwrites_t *co,
663                          char *key,
664                          char *value);
665 void add_config_overwrite_opt(config_overwrites_t *co,
666                               char *optarg);
667 void apply_config_overwrites(config_overwrites_t *co);
668 amglue_export_tag(init,
669     new_config_overwrites free_config_overwrites add_config_overwrite
670     add_config_overwrite_opt apply_config_overwrites
671 );
672
673
674
675
676 amglue_add_flag_tag_fns(config_init_flags);
677 amglue_add_constant(CONFIG_INIT_EXPLICIT_NAME, config_init_flags);
678 amglue_add_constant(CONFIG_INIT_USE_CWD, config_init_flags);
679 amglue_add_constant(CONFIG_INIT_CLIENT, config_init_flags);
680 amglue_add_constant(CONFIG_INIT_OVERLAY, config_init_flags);
681 amglue_add_constant(CONFIG_INIT_FATAL, config_init_flags);
682 amglue_copy_to_tag(config_init_flags, init);
683
684 gboolean config_init(config_init_flags flags,
685                      char *arg_config_name);
686 void config_uninit(void);
687 char **get_config_options(int first);
688 amglue_export_tag(init,
689     config_init config_uninit get_config_options
690 );
691
692 /* These are accessor functions, because SWIG's wrapping of global string
693  * variables is no so good -- the resulting strings can't be passed to other
694  * functions expecting char * arguments.  */
695 %inline %{
696     char *get_config_name(void) { return config_name; }
697     char *get_config_dir(void) { return config_dir; }
698     char *get_config_filename(void) { return config_filename; }
699 %}
700 amglue_export_tag(init,
701     get_config_name 
702     get_config_dir 
703     get_config_filename
704 );
705
706 /*
707  * Miscellaneous
708  */
709
710 void dump_configuration(void);
711 char *config_dir_relative(char *filename);
712 char *taperalgo2str(taperalgo_t taperalgo);
713 gint64 find_multiplier(char * casestr);
714 amglue_export_ok(
715     dump_configuration config_dir_relative taperalgo2str find_multiplier
716 );
717