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