Imported Upstream version 3.3.2
[debian/amanda] / common-src / conffile.h
1 /*
2  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3  * Copyright (c) 1991-2000 University of Maryland at College Park
4  * All Rights Reserved.
5  *
6  * Permission to use, copy, modify, distribute, and sell this software and its
7  * documentation for any purpose is hereby granted without fee, provided that
8  * the above copyright notice appear in all copies and that both that
9  * copyright notice and this permission notice appear in supporting
10  * documentation, and that the name of U.M. not be used in advertising or
11  * publicity pertaining to distribution of the software without specific,
12  * written prior permission.  U.M. makes no representations about the
13  * suitability of this software for any purpose.  It is provided "as is"
14  * without express or implied warranty.
15  *
16  * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22  *
23  * Author: James da Silva, Systems Design and Analysis Group
24  *                         Computer Science Department
25  *                         University of Maryland at College Park
26  */
27 /*
28  * $Id: conffile.h,v 1.72 2006/07/26 15:17:37 martinea Exp $
29  *
30  * interface for config file reading code
31  */
32 #ifndef CONFFILE_H
33 #define CONFFILE_H
34
35 #include "amanda.h"
36 #include "util.h"
37
38 /* Getting Configuration Values
39  * ============================
40  *
41  * Amanda configurations consist of a number of "global" parameters, as well as
42  * named subsections of several types.  The global parameters are fetched with
43  * the getconf_CONFTYPE functions, keyed by a confparam_t constant (with prefix
44  * CNF_).  The subsection parameters are fetched with SUBSEC_get_PARAM()
45  * macros, e.g., tapetype_get_blocksize(ttyp), where the argument comes from
46  * lookup_SUBSEC(), in this case lookup_tapetype(name).
47  *
48  * Types
49  * =====
50  *
51  * This module juggles two kinds of types: C types and conftypes.  Conftypes include
52  * everything from integers through property lists, and are specific to the needs of
53  * the configuration system.  Each conftype has a corresponding C type, which is of course
54  * necessary to actually use the data.
55  *
56  * The val_t__CONFTYPE macros represent the canonical correspondance of conftypes to C
57  * types, but in general the relationship is obvious: ints, strings, reals, and so forth
58  * are represented directly.  Enumerated conftypes are represented by the corresponding
59  * C enum type.  The 'rate' conftype is represented as a 2-element array of doubles, and
60  * the 'intrange' conftype is represented as a 2-element array of ints.  exincludes are
61  * a exinclude_t *, and a proplist is represented as a GHashTable *.
62  *
63  * Memory
64  * ======
65  * Note that, unless specified, all memory in this module is managed by the module
66  * itself; return strings should not be freed by the caller.
67  *
68  * Error Handling
69  * ==============
70  * All errors and warnings generated by this module are available from get_config_errors().
71  * It is up to the caller to route these messages to the user.  The function
72  * config_print_errors() will print the errors to stderr, as a convenience.
73  */
74
75 /*
76  * Generic values
77  *
78  * This module uses a generic val_t type to hold values of various types -- it's basically
79  * a union with type information and a 'seen' flag.  In a way, it's a very simple equivalent
80  * to Glib's GValue.  It's worth considering rewriting this with GValue, but for the moment,
81  * this works and it's here.
82  */
83
84 /* A "seen" struct.  Rather than allocate strings all over the place, this
85  * string is in the "parsed_filenames" GSList and will be freed when that
86  * GSList is freed.  This struct should be opaque to other modules. */
87 typedef struct seen_s {
88     char *block;
89     char *filename;
90     int linenum;
91 } seen_t;
92
93 /* holdingdisk types */
94 typedef enum {
95     HOLD_NEVER,                 /* Always direct to tape  */
96     HOLD_AUTO,                  /* If possible            */
97     HOLD_REQUIRED               /* Always to holding disk */
98 } dump_holdingdisk_t;
99
100 /* Compression types */
101 typedef enum {
102     COMP_NONE,          /* No compression */
103     COMP_FAST,          /* Fast compression on client */
104     COMP_BEST,          /* Best compression on client */
105     COMP_CUST,          /* Custom compression on client */
106     COMP_SERVER_FAST,   /* Fast compression on server */
107     COMP_SERVER_BEST,   /* Best compression on server */
108     COMP_SERVER_CUST    /* Custom compression on server */
109 } comp_t;
110
111 /* Encryption types */
112 typedef enum {
113     ENCRYPT_NONE,               /* No encryption */
114     ENCRYPT_CUST,               /* Custom encryption on client */
115     ENCRYPT_SERV_CUST           /* Custom encryption on server */
116 } encrypt_t;
117
118 /* Estimate strategies */
119 typedef enum {
120     ES_CLIENT,          /* client estimate */
121     ES_SERVER,          /* server estimate */
122     ES_CALCSIZE,        /* calcsize estimate */
123     ES_ES               /* sentinel */
124 } estimate_t;
125 /* A GSlist where each element is a element_t */
126 typedef GSList *estimatelist_t;
127
128 typedef enum {
129     AL_OTHER_CONFIG = 1<<0,
130     AL_NON_AMANDA   = 1<<1,
131     AL_VOLUME_ERROR = 1<<2,
132     AL_EMPTY        = 1<<3,
133 } autolabel_enum_t;
134 typedef int autolabel_set_t;
135
136 typedef struct autolabel_s {
137     char            *template;
138     autolabel_set_t  autolabel;
139 } autolabel_t;
140
141 /* Dump strategies */
142 typedef enum {
143     DS_SKIP,        /* Don't do any dumps at all */
144     DS_STANDARD,    /* Standard (0 1 1 1 1 2 2 2 ...) */
145     DS_NOFULL,      /* No full's (1 1 1 ...) */
146     DS_NOINC,       /* No inc's (0 0 0 ...) */
147     DS_4,           /* ? (0 1 2 3 4 5 6 7 8 9 10 11 ...) */
148     DS_5,           /* ? (0 1 1 1 1 1 1 1 1 1 1 1 ...) */
149     DS_HANOI,       /* Tower of Hanoi (? ? ? ? ? ...) */
150     DS_INCRONLY,    /* Forced fulls (0 1 1 2 2 FORCE0 1 1 ...) */
151     DS_DS /* sentinel */
152 } strategy_t;
153
154 typedef enum {
155     ALGO_FIRST,
156     ALGO_FIRSTFIT,
157     ALGO_LARGEST,
158     ALGO_LARGESTFIT,
159     ALGO_SMALLEST,
160     ALGO_SMALLESTFIT,   /* for internal use */
161     ALGO_LAST,
162     ALGO_LASTFIT,       /* for internal use */
163     ALGO_ALGO /* sentinel */
164 } taperalgo_t;
165
166 /* execute_on types */
167 #define EXECUTE_ON_PRE_AMCHECK         1<<0
168 #define EXECUTE_ON_PRE_DLE_AMCHECK     1<<1
169 #define EXECUTE_ON_PRE_HOST_AMCHECK    1<<2
170 #define EXECUTE_ON_POST_AMCHECK        1<<3
171 #define EXECUTE_ON_POST_DLE_AMCHECK    1<<4
172 #define EXECUTE_ON_POST_HOST_AMCHECK   1<<5
173 #define EXECUTE_ON_PRE_ESTIMATE        1<<6
174 #define EXECUTE_ON_PRE_DLE_ESTIMATE    1<<7
175 #define EXECUTE_ON_PRE_HOST_ESTIMATE   1<<8
176 #define EXECUTE_ON_POST_ESTIMATE       1<<9
177 #define EXECUTE_ON_POST_DLE_ESTIMATE   1<<10
178 #define EXECUTE_ON_POST_HOST_ESTIMATE  1<<11
179 #define EXECUTE_ON_PRE_BACKUP          1<<12
180 #define EXECUTE_ON_PRE_DLE_BACKUP      1<<13
181 #define EXECUTE_ON_PRE_HOST_BACKUP     1<<14
182 #define EXECUTE_ON_POST_BACKUP         1<<15
183 #define EXECUTE_ON_POST_DLE_BACKUP     1<<16
184 #define EXECUTE_ON_POST_HOST_BACKUP    1<<17
185 #define EXECUTE_ON_PRE_RECOVER         1<<18
186 #define EXECUTE_ON_POST_RECOVER        1<<19
187 #define EXECUTE_ON_PRE_LEVEL_RECOVER   1<<20
188 #define EXECUTE_ON_POST_LEVEL_RECOVER  1<<21
189 #define EXECUTE_ON_INTER_LEVEL_RECOVER 1<<22
190 typedef int execute_on_t;
191
192 typedef int execute_where_t;
193
194 typedef enum {
195     SEND_AMREPORT_ALL,
196     SEND_AMREPORT_STRANGE,
197     SEND_AMREPORT_ERROR,
198     SEND_AMREPORT_NEVER
199 } send_amreport_t;
200
201 typedef enum {
202     DATA_PATH_AMANDA    = 1<<0,
203     DATA_PATH_DIRECTTCP = 1<<1,
204 } data_path_t;
205
206 typedef struct exinclude_s {
207     am_sl_t *sl_list;
208     am_sl_t *sl_file;
209     int  optional;
210 } exinclude_t;
211
212 typedef struct {
213     int append;
214     int priority;
215     GSList* values;
216     seen_t seen;
217 } property_t;
218
219 typedef GHashTable* proplist_t;
220 /* A GSlist where each element is a 'char*' */
221 typedef GSList* identlist_t;
222
223 /* part_cache_types */
224 typedef enum {
225     PART_CACHE_TYPE_NONE,
226     PART_CACHE_TYPE_MEMORY,
227     PART_CACHE_TYPE_DISK,
228 } part_cache_type_t;
229
230 /* host_limit */
231 typedef struct {
232     gboolean server;
233     gboolean same_host;
234     GSList *match_pats;
235 } host_limit_t;
236
237 /* Names for the type of value in a val_t.  Mostly for internal use, but useful
238  * for wrapping val_t's, too. */
239 typedef enum {
240     CONFTYPE_INT,
241     CONFTYPE_INT64,
242     CONFTYPE_REAL,
243     CONFTYPE_STR,
244     CONFTYPE_IDENT,
245     CONFTYPE_TIME,
246     CONFTYPE_SIZE,
247     CONFTYPE_BOOLEAN,
248     CONFTYPE_COMPRESS,
249     CONFTYPE_ENCRYPT,
250     CONFTYPE_HOLDING,
251     CONFTYPE_ESTIMATELIST,
252     CONFTYPE_STRATEGY,
253     CONFTYPE_TAPERALGO,
254     CONFTYPE_PRIORITY,
255     CONFTYPE_RATE,
256     CONFTYPE_INTRANGE,
257     CONFTYPE_EXINCLUDE,
258     CONFTYPE_PROPLIST,
259     CONFTYPE_APPLICATION,
260     CONFTYPE_EXECUTE_ON,
261     CONFTYPE_EXECUTE_WHERE,
262     CONFTYPE_SEND_AMREPORT_ON,
263     CONFTYPE_IDENTLIST,
264     CONFTYPE_DATA_PATH,
265     CONFTYPE_AUTOLABEL,
266     CONFTYPE_PART_CACHE_TYPE,
267     CONFTYPE_HOST_LIMIT,
268     CONFTYPE_NO_YES_ALL,
269 } conftype_t;
270
271 typedef enum {
272     CONF_UNIT_NONE,
273     CONF_UNIT_K,
274 } confunit_t;
275
276 /* This should be considered an opaque type for any other modules.  The complete
277  * struct is included here to allow quick access via macros. Access it *only* through
278  * those macros. */
279 typedef struct val_s {
280     union {
281         int             i;
282         gint64          int64;
283         double          r;
284         char            *s;
285         ssize_t         size;
286         time_t          t;
287         float           rate[2];
288         exinclude_t     exinclude;
289         int             intrange[2];
290         proplist_t      proplist;
291         estimatelist_t  estimatelist;
292         identlist_t     identlist;
293         autolabel_t     autolabel;
294         host_limit_t    host_limit;
295     } v;
296     seen_t seen;
297     conftype_t type;
298     confunit_t unit;
299 } val_t;
300
301 /* Functions to typecheck and extract a particular type of
302  * value from a val_t.  All call error() if the type is incorrect,
303  * as this is a programming error.  */
304 int                   val_t_to_int      (val_t *);
305 gint64                val_t_to_int64    (val_t *);
306 float                 val_t_to_real     (val_t *);
307 char                 *val_t_to_str      (val_t *); /* (also converts CONFTYPE_IDENT) */
308 char                 *val_t_to_ident    (val_t *); /* (also converts CONFTYPE_STR) */
309 identlist_t           val_t_to_identlist(val_t *);
310 time_t                val_t_to_time     (val_t *);
311 ssize_t               val_t_to_size     (val_t *);
312 int                   val_t_to_boolean  (val_t *);
313 int                   val_t_to_no_yes_all(val_t *);
314 comp_t                val_t_to_compress (val_t *);
315 encrypt_t             val_t_to_encrypt  (val_t *);
316 dump_holdingdisk_t    val_t_to_holding  (val_t *);
317 estimatelist_t        val_t_to_estimatelist (val_t *);
318 strategy_t            val_t_to_strategy (val_t *);
319 taperalgo_t           val_t_to_taperalgo(val_t *);
320 int                   val_t_to_priority (val_t *);
321 float                *val_t_to_rate     (val_t *); /* array of two floats */
322 exinclude_t           val_t_to_exinclude(val_t *);
323 int                  *val_t_to_intrange (val_t *); /* array of two ints */
324 proplist_t            val_t_to_proplist (val_t *);
325 char                 *val_t_to_application(val_t *);
326 execute_on_t          val_t_to_execute_on(val_t *);
327 execute_where_t       val_t_to_execute_where(val_t *);
328 send_amreport_t       val_t_to_send_amreport(val_t *);
329 data_path_t           val_t_to_data_path(val_t *);
330 autolabel_t           val_t_to_autolabel(val_t *);
331 part_cache_type_t     val_t_to_part_cache_type(val_t *);
332 host_limit_t         *val_t_to_host_limit(val_t *);
333
334 /* Has the given val_t been seen in a configuration file or config overwrite?
335  *
336  * @param val: val_t* to examine
337  * @returns: boolean
338  */
339 #define val_t_seen(val) ((val)->seen.linenum)
340
341 /* What is the underlying type of this val_t?
342  *
343  * @param val: val_t* to examine
344  * @returns: conftype_t
345  */
346 #define val_t_type(val) ((val)->type)
347
348 /* Macros to convert val_t's to a particular type without the benefit of
349  * a typecheck.  Use these only if you really know what you're doing!
350  *
351  * Implementation note: these macros encode the relationship of conftypes
352  * (in the macro name) to the corresponding union field.  The macros work
353  * as lvalues, too.
354  */
355 #define val_t__seen(val)          ((val)->seen)
356 #define val_t__int(val)           ((val)->v.i)
357 #define val_t__int64(val)         ((val)->v.int64)
358 #define val_t__real(val)          ((val)->v.r)
359 #define val_t__str(val)           ((val)->v.s)
360 #define val_t__ident(val)         ((val)->v.s)
361 #define val_t__identlist(val)     ((val)->v.identlist)
362 #define val_t__time(val)          ((val)->v.t)
363 #define val_t__size(val)          ((val)->v.size)
364 #define val_t__boolean(val)       ((val)->v.i)
365 #define val_t__no_yes_all(val)    ((val)->v.i)
366 #define val_t__compress(val)      ((val)->v.i)
367 #define val_t__encrypt(val)       ((val)->v.i)
368 #define val_t__holding(val)       ((val)->v.i)
369 #define val_t__estimatelist(val)  ((val)->v.estimatelist)
370 #define val_t__strategy(val)      ((val)->v.i)
371 #define val_t__taperalgo(val)     ((val)->v.i)
372 #define val_t__send_amreport(val) ((val)->v.i)
373 #define val_t__priority(val)      ((val)->v.i)
374 #define val_t__rate(val)          ((val)->v.rate)
375 #define val_t__exinclude(val)     ((val)->v.exinclude)
376 #define val_t__intrange(val)      ((val)->v.intrange)
377 #define val_t__proplist(val)      ((val)->v.proplist)
378 #define val_t__application(val)   ((val)->v.application)
379 #define val_t__execute_on(val)    ((val)->v.i)
380 #define val_t__execute_where(val) ((val)->v.i)
381 #define val_t__data_path(val)     ((val)->v.i)
382 #define val_t__autolabel(val)     ((val)->v.autolabel)
383 #define val_t__part_cache_type(val) ((val)->v.i)
384 #define val_t__host_limit(val)    ((val)->v.host_limit)
385
386 /*
387  * Parameters
388  *
389  * Programs get val_t's by giving the index of the parameters they're interested in.
390  * For global parameters, these start with CNF; for subsections, they start with the
391  * name of the subsection.
392  */
393
394 /*
395  * Global parameter access
396  */
397 typedef enum {
398     CNF_ORG,
399     CNF_CONF,
400     CNF_INDEX_SERVER,
401     CNF_TAPE_SERVER,
402     CNF_AMDUMP_SERVER,
403     CNF_AUTH,
404     CNF_SSH_KEYS,
405     CNF_AMANDAD_PATH,
406     CNF_CLIENT_USERNAME,
407     CNF_CLIENT_PORT,
408     CNF_GNUTAR_LIST_DIR,
409     CNF_AMANDATES,
410     CNF_MAILTO,
411     CNF_DUMPUSER,
412     CNF_TAPEDEV,
413     CNF_DEVICE_PROPERTY,
414     CNF_PROPERTY,
415     CNF_INTERACTIVITY,
416     CNF_APPLICATION,
417     CNF_APPLICATION_TOOL,
418     CNF_EXECUTE_ON,
419     CNF_PP_SCRIPT,
420     CNF_PP_SCRIPT_TOOL,
421     CNF_PLUGIN,
422     CNF_CHANGERDEV,
423     CNF_CHANGERFILE,
424     CNF_LABELSTR,
425     CNF_TAPELIST,
426     CNF_DISKFILE,
427     CNF_INFOFILE,
428     CNF_LOGDIR,
429     CNF_INDEXDIR,
430     CNF_TAPETYPE,
431     CNF_DUMPCYCLE,
432     CNF_RUNSPERCYCLE,
433     CNF_TAPECYCLE,
434     CNF_NETUSAGE,
435     CNF_INPARALLEL,
436     CNF_DUMPORDER,
437     CNF_BUMPPERCENT,
438     CNF_BUMPSIZE,
439     CNF_BUMPMULT,
440     CNF_BUMPDAYS,
441     CNF_TPCHANGER,
442     CNF_RUNTAPES,
443     CNF_MAXDUMPS,
444     CNF_ETIMEOUT,
445     CNF_DTIMEOUT,
446     CNF_CTIMEOUT,
447     CNF_DEVICE_OUTPUT_BUFFER_SIZE,
448     CNF_PRINTER,
449     CNF_MAILER,
450     CNF_AUTOFLUSH,
451     CNF_RESERVE,
452     CNF_MAXDUMPSIZE,
453     CNF_COLUMNSPEC,
454     CNF_AMRECOVER_DO_FSF,
455     CNF_AMRECOVER_CHECK_LABEL,
456     CNF_AMRECOVER_CHANGER,
457     CNF_TAPERALGO,
458     CNF_SEND_AMREPORT_ON,
459     CNF_FLUSH_THRESHOLD_DUMPED,
460     CNF_FLUSH_THRESHOLD_SCHEDULED,
461     CNF_TAPERFLUSH,
462     CNF_DISPLAYUNIT,
463     CNF_KRB5KEYTAB,
464     CNF_KRB5PRINCIPAL,
465     CNF_LABEL_NEW_TAPES,
466     CNF_USETIMESTAMPS,
467     CNF_REP_TRIES,
468     CNF_CONNECT_TRIES,
469     CNF_REQ_TRIES,
470     CNF_DEBUG_AMANDAD,
471     CNF_DEBUG_RECOVERY,
472     CNF_DEBUG_AMIDXTAPED,
473     CNF_DEBUG_AMINDEXD,
474     CNF_DEBUG_AMRECOVER,
475     CNF_DEBUG_AUTH,
476     CNF_DEBUG_EVENT,
477     CNF_DEBUG_HOLDING,
478     CNF_DEBUG_PROTOCOL,
479     CNF_DEBUG_PLANNER,
480     CNF_DEBUG_DRIVER,
481     CNF_DEBUG_DUMPER,
482     CNF_DEBUG_CHUNKER,
483     CNF_DEBUG_TAPER,
484     CNF_DEBUG_SELFCHECK,
485     CNF_DEBUG_SENDSIZE,
486     CNF_DEBUG_SENDBACKUP,
487     CNF_RESERVED_UDP_PORT,
488     CNF_RESERVED_TCP_PORT,
489     CNF_UNRESERVED_TCP_PORT,
490     CNF_HOLDINGDISK,
491     CNF_AUTOLABEL,
492     CNF_META_AUTOLABEL,
493     CNF_DEBUG_DAYS,
494     CNF_TAPER_PARALLEL_WRITE,
495     CNF_RECOVERY_LIMIT,
496     CNF_TAPERSCAN,
497     CNF_MAX_DLE_BY_VOLUME,
498     CNF_EJECT_VOLUME,
499     CNF_TMPDIR,
500     CNF_CNF /* sentinel */
501 } confparm_key;
502
503 /* Given a confparm_key, return a pointer to the corresponding val_t.
504  *
505  * @param key: confparm_key
506  * @returns: pointer to value
507  */
508 val_t *getconf(confparm_key key);
509
510 /* (convenience macro) has this global parameter been seen?
511  *
512  * @param key: confparm_key
513  * @returns: boolean
514  */
515 #define getconf_seen(key)       (val_t_seen(getconf((key))))
516 #define getconf_linenum(key)       (val_t_seen(getconf((key))))
517
518 /* (convenience macros)
519  * Fetch a global parameter of a specific type.  Note that these
520  * convenience macros have a different form from those for the
521  * subsections: here you specify a type and a key, while for the
522  * subsections you specify only a key.  The difference is historical.
523  *
524  * @param key: confparm_key
525  * @returns: various
526  */
527 #define getconf_int(key)          (val_t_to_int(getconf((key))))
528 #define getconf_int64(key)        (val_t_to_int64(getconf((key))))
529 #define getconf_real(key)         (val_t_to_real(getconf((key))))
530 #define getconf_str(key)          (val_t_to_str(getconf((key))))
531 #define getconf_ident(key)        (val_t_to_ident(getconf((key))))
532 #define getconf_identlist(key)    (val_t_to_identlist(getconf((key))))
533 #define getconf_time(key)         (val_t_to_time(getconf((key))))
534 #define getconf_size(key)         (val_t_to_size(getconf((key))))
535 #define getconf_boolean(key)      (val_t_to_boolean(getconf((key))))
536 #define getconf_no_yes_all(key)   (val_t_to_no_yes_all(getconf((key))))
537 #define getconf_compress(key)     (val_t_to_compress(getconf((key))))
538 #define getconf_encrypt(key)      (val_t_to_encrypt(getconf((key))))
539 #define getconf_holding(key)      (val_t_to_holding(getconf((key))))
540 #define getconf_estimatelist(key) (val_t_to_estimatelist(getconf((key))))
541 #define getconf_strategy(key)     (val_t_to_strategy(getconf((key))))
542 #define getconf_taperalgo(key)    (val_t_to_taperalgo(getconf((key))))
543 #define getconf_priority(key)     (val_t_to_priority(getconf((key))))
544 #define getconf_rate(key)         (val_t_to_rate(getconf((key))))
545 #define getconf_exinclude(key)    (val_t_to_exinclude(getconf((key))))
546 #define getconf_intrange(key)     (val_t_to_intrange(getconf((key))))
547 #define getconf_proplist(key)     (val_t_to_proplist(getconf((key))))
548 #define getconf_send_amreport(key) (val_t_to_send_amreport(getconf((key))))
549 #define getconf_autolabel(key)    (val_t_to_autolabel(getconf((key))))
550 #define getconf_part_cache_type(key) (val_t_to_part_cache_type(getconf((key))))
551 #define getconf_recovery_limit(key) (val_t_to_host_limit(getconf((key))))
552
553 /* Get a list of names for subsections of the given type
554  *
555  * @param listname: the desired type of subsection
556  * @returns: list of subsection names; caller is responsible for freeing
557  * this list, but not the strings it points to, using g_slist_free().
558  */
559 GSList *getconf_list(char *listname);
560
561 /* Get a configuration value by name, supporting the TYPE:SUBSEC:KEYWORD.
562  * Returns NULL if the configuration value doesnt exist.
563  */
564 val_t *getconf_byname(char *key);
565
566 /*
567  * Derived values
568  *
569  * Values which aren't directly specified by the configuration, but which
570  * are derived from it.
571  */
572
573 /* Return a divisor which will convert a value in units of kilo-whatevers
574  * to the user's selected display unit.
575  *
576  * @returns: long integer divisor
577  */
578 long int getconf_unit_divisor(void);
579
580 /* If any of these globals are true, the corresponding component will
581  * send verbose debugging output to the debug file.  The options are
582  * set during config_init, but can be modified at will after that if 
583  * desired.  */
584
585 extern int debug_amandad;
586 extern int debug_recovery;
587 extern int debug_amidxtaped;
588 extern int debug_amindexd;
589 extern int debug_amrecover;
590 extern int debug_auth;
591 extern int debug_event;
592 extern int debug_holding;
593 extern int debug_protocol;
594 extern int debug_planner;
595 extern int debug_driver;
596 extern int debug_dumper;
597 extern int debug_chunker;
598 extern int debug_taper;
599 extern int debug_selfcheck;
600 extern int debug_sendsize;
601 extern int debug_sendbackup;
602
603 /*
604  * Tapetype parameter access
605  */
606
607 typedef enum {
608     TAPETYPE_COMMENT,
609     TAPETYPE_LBL_TEMPL,
610     TAPETYPE_BLOCKSIZE,
611     TAPETYPE_READBLOCKSIZE,
612     TAPETYPE_LENGTH,
613     TAPETYPE_FILEMARK,
614     TAPETYPE_SPEED,
615     TAPETYPE_PART_SIZE,
616     TAPETYPE_PART_CACHE_TYPE,
617     TAPETYPE_PART_CACHE_DIR,
618     TAPETYPE_PART_CACHE_MAX_SIZE,
619     TAPETYPE_TAPETYPE /* sentinel */
620 } tapetype_key;
621
622 /* opaque object */
623 typedef struct tapetype_s tapetype_t;
624
625 /* Given the name of the tapetype, return a tapetype object.  Returns NULL
626  * if no matching tapetype exists.  Note that the match is case-insensitive.
627  *
628  * @param identifier: name of the desired tapetype
629  * @returns: object or NULL
630  */
631 tapetype_t *lookup_tapetype(char *identifier);
632
633 /* Given a tapetype and a key, return a pointer to the corresponding val_t.
634  *
635  * @param ttyp: the tapetype to examine
636  * @param key: tapetype_key (one of the TAPETYPE_* constants)
637  * @returns: pointer to value
638  */
639 val_t *tapetype_getconf(tapetype_t *ttyp, tapetype_key key);
640
641 /* Get the name of this tapetype.
642  *
643  * @param ttyp: the tapetype to examine
644  * @returns: name of the tapetype
645  */
646 char *tapetype_name(tapetype_t *ttyp);
647
648 /* (convenience macro) has this parameter been seen in this tapetype?  This
649  * applies to the specific parameter *within* the tapetype.
650  *
651  * @param key: tapetype_key
652  * @returns: boolean
653  */
654 #define tapetype_seen(ttyp, key)       (val_t_seen(tapetype_getconf((ttyp), (key))))
655
656 /* (convenience macros)
657  * fetch a particular parameter; caller must know the correct type.
658  *
659  * @param ttyp: the tapetype to examine
660  * @returns: various
661  */
662 #define tapetype_get_comment(ttyp)             (val_t_to_str(tapetype_getconf((ttyp), TAPETYPE_COMMENT)))
663 #define tapetype_get_lbl_templ(ttyp)           (val_t_to_str(tapetype_getconf((ttyp), TAPETYPE_LBL_TEMPL)))
664 #define tapetype_get_blocksize(ttyp)           (val_t_to_size(tapetype_getconf((ttyp), TAPETYPE_BLOCKSIZE)))
665 #define tapetype_get_readblocksize(ttyp)       (val_t_to_size(tapetype_getconf((ttyp), TAPETYPE_READBLOCKSIZE)))
666 #define tapetype_get_length(ttyp)              (val_t_to_int64(tapetype_getconf((ttyp), TAPETYPE_LENGTH)))
667 #define tapetype_get_filemark(ttyp)            (val_t_to_int64(tapetype_getconf((ttyp), TAPETYPE_FILEMARK)))
668 #define tapetype_get_speed(ttyp)               (val_t_to_int(tapetype_getconf((ttyp), TAPETYPE_SPEED)))
669 #define tapetype_get_part_size(ttyp)           (val_t_to_int64(tapetype_getconf((ttyp), TAPETYPE_PART_SIZE)))
670 #define tapetype_get_part_cache_type(ttyp)     (val_t_to_part_cache_type(tapetype_getconf((ttyp), TAPETYPE_PART_CACHE_TYPE)))
671 #define tapetype_get_part_cache_dir(ttyp)      (val_t_to_str(tapetype_getconf((ttyp), TAPETYPE_PART_CACHE_DIR)))
672 #define tapetype_get_part_cache_max_size(ttyp) (val_t_to_int64(tapetype_getconf((ttyp), TAPETYPE_PART_CACHE_MAX_SIZE)))
673
674 /*
675  * Dumptype parameter access
676  *
677  * Note that some parameters are generic to the host
678  */
679
680 typedef enum {
681     DUMPTYPE_COMMENT,
682     DUMPTYPE_PROGRAM,
683     DUMPTYPE_SRVCOMPPROG,
684     DUMPTYPE_CLNTCOMPPROG,
685     DUMPTYPE_SRV_ENCRYPT,
686     DUMPTYPE_CLNT_ENCRYPT,
687     DUMPTYPE_AMANDAD_PATH,              /* host parameter */
688     DUMPTYPE_CLIENT_USERNAME,           /* host parameter */
689     DUMPTYPE_SSH_KEYS,                  /* host parameter */
690     DUMPTYPE_AUTH,                      /* host parameter */
691     DUMPTYPE_EXCLUDE,
692     DUMPTYPE_INCLUDE,
693     DUMPTYPE_PRIORITY,
694     DUMPTYPE_DUMPCYCLE,
695     DUMPTYPE_MAXDUMPS,                  /* host parameter */
696     DUMPTYPE_MAXPROMOTEDAY,
697     DUMPTYPE_BUMPPERCENT,
698     DUMPTYPE_BUMPSIZE,
699     DUMPTYPE_BUMPDAYS,
700     DUMPTYPE_BUMPMULT,
701     DUMPTYPE_STARTTIME,
702     DUMPTYPE_STRATEGY,
703     DUMPTYPE_ESTIMATELIST,
704     DUMPTYPE_COMPRESS,
705     DUMPTYPE_ENCRYPT,
706     DUMPTYPE_SRV_DECRYPT_OPT,
707     DUMPTYPE_CLNT_DECRYPT_OPT,
708     DUMPTYPE_COMPRATE,
709     DUMPTYPE_TAPE_SPLITSIZE,
710     DUMPTYPE_FALLBACK_SPLITSIZE,
711     DUMPTYPE_SPLIT_DISKBUFFER,
712     DUMPTYPE_RECORD,
713     DUMPTYPE_SKIP_INCR,
714     DUMPTYPE_SKIP_FULL,
715     DUMPTYPE_HOLDINGDISK,
716     DUMPTYPE_KENCRYPT,
717     DUMPTYPE_IGNORE,
718     DUMPTYPE_INDEX,
719     DUMPTYPE_APPLICATION,
720     DUMPTYPE_SCRIPTLIST,
721     DUMPTYPE_PROPERTY,
722     DUMPTYPE_CLIENT_PORT,
723     DUMPTYPE_DATA_PATH,
724     DUMPTYPE_ALLOW_SPLIT,
725     DUMPTYPE_RECOVERY_LIMIT,
726     DUMPTYPE_DUMP_LIMIT,
727     DUMPTYPE_MAX_WARNINGS,
728     DUMPTYPE_DUMPTYPE /* sentinel */
729 } dumptype_key;
730
731 /* opaque object */
732 typedef struct dumptype_s dumptype_t;
733
734 /* Given the name of the dumptype, return a dumptype object.  Returns NULL
735  * if no matching dumptype exists.  Note that the match is case-insensitive.
736  *
737  * @param identifier: name of the desired dumptype
738  * @returns: object or NULL
739  */
740 dumptype_t *lookup_dumptype(char *identifier);
741
742 /* Given a dumptype and a key, return a pointer to the corresponding val_t.
743  *
744  * @param dtyp: the dumptype to examine
745  * @param key: dumptype_key (one of the TAPETYPE_* constants)
746  * @returns: pointer to value
747  */
748 val_t *dumptype_getconf(dumptype_t *dtyp, dumptype_key key);
749
750 /* Get the name of this dumptype.
751  *
752  * @param dtyp: the dumptype to examine
753  * @returns: name of the dumptype
754  */
755 char *dumptype_name(dumptype_t *dtyp);
756
757 /* (convenience macro) has this parameter been seen in this dumptype?  This
758  * applies to the specific parameter *within* the dumptype.
759  *
760  * @param key: dumptype_key
761  * @returns: boolean
762  */
763 #define dumptype_seen(dtyp, key)       (val_t_seen(dumptype_getconf((dtyp), (key))))
764
765 /* (convenience macros)
766  * fetch a particular parameter; caller must know the correct type.
767  *
768  * @param dtyp: the dumptype to examine
769  * @returns: various
770  */
771 #define dumptype_get_comment(dtyp)             (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_COMMENT)))
772 #define dumptype_get_program(dtyp)             (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_PROGRAM)))
773 #define dumptype_get_srvcompprog(dtyp)         (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_SRVCOMPPROG)))
774 #define dumptype_get_clntcompprog(dtyp)        (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_CLNTCOMPPROG)))
775 #define dumptype_get_srv_encrypt(dtyp)         (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_SRV_ENCRYPT)))
776 #define dumptype_get_clnt_encrypt(dtyp)        (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_CLNT_ENCRYPT)))
777 #define dumptype_get_amandad_path(dtyp)        (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_AMANDAD_PATH)))
778 #define dumptype_get_client_username(dtyp)     (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_CLIENT_USERNAME)))
779 #define dumptype_get_ssh_keys(dtyp)            (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_SSH_KEYS)))
780 #define dumptype_get_auth(dtyp)                (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_AUTH)))
781 #define dumptype_get_exclude(dtyp)             (val_t_to_exinclude(dumptype_getconf((dtyp), DUMPTYPE_EXCLUDE)))
782 #define dumptype_get_include(dtyp)             (val_t_to_exinclude(dumptype_getconf((dtyp), DUMPTYPE_INCLUDE)))
783 #define dumptype_get_priority(dtyp)            (val_t_to_priority(dumptype_getconf((dtyp), DUMPTYPE_PRIORITY)))
784 #define dumptype_get_dumpcycle(dtyp)           (val_t_to_int(dumptype_getconf((dtyp), DUMPTYPE_DUMPCYCLE)))
785 #define dumptype_get_maxcycle(dtyp)            (val_t_to_int(dumptype_getconf((dtyp), DUMPTYPE_MAXCYCLE)))
786 #define dumptype_get_frequency(dtyp)           (val_t_to_int(dumptype_getconf((dtyp), DUMPTYPE_FREQUENCY)))
787 #define dumptype_get_maxdumps(dtyp)            (val_t_to_int(dumptype_getconf((dtyp), DUMPTYPE_MAXDUMPS)))
788 #define dumptype_get_maxpromoteday(dtyp)       (val_t_to_int(dumptype_getconf((dtyp), DUMPTYPE_MAXPROMOTEDAY)))
789 #define dumptype_get_bumppercent(dtyp)         (val_t_to_int(dumptype_getconf((dtyp), DUMPTYPE_BUMPPERCENT)))
790 #define dumptype_get_bumpsize(dtyp)            (val_t_to_int64(dumptype_getconf((dtyp), DUMPTYPE_BUMPSIZE)))
791 #define dumptype_get_bumpdays(dtyp)            (val_t_to_int(dumptype_getconf((dtyp), DUMPTYPE_BUMPDAYS)))
792 #define dumptype_get_bumpmult(dtyp)            (val_t_to_real(dumptype_getconf((dtyp), DUMPTYPE_BUMPMULT)))
793 #define dumptype_get_starttime(dtyp)           (val_t_to_time(dumptype_getconf((dtyp), DUMPTYPE_STARTTIME)))
794 #define dumptype_get_strategy(dtyp)            (val_t_to_strategy(dumptype_getconf((dtyp), DUMPTYPE_STRATEGY)))
795 #define dumptype_get_estimatelist(dtyp)        (val_t_to_estimatelist(dumptype_getconf((dtyp), DUMPTYPE_ESTIMATELIST)))
796 #define dumptype_get_compress(dtyp)            (val_t_to_compress(dumptype_getconf((dtyp), DUMPTYPE_COMPRESS)))
797 #define dumptype_get_encrypt(dtyp)             (val_t_to_encrypt(dumptype_getconf((dtyp), DUMPTYPE_ENCRYPT)))
798 #define dumptype_get_srv_decrypt_opt(dtyp)     (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_SRV_DECRYPT_OPT)))
799 #define dumptype_get_clnt_decrypt_opt(dtyp)    (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_CLNT_DECRYPT_OPT)))
800 #define dumptype_get_comprate(dtyp)            (val_t_to_rate(dumptype_getconf((dtyp), DUMPTYPE_COMPRATE)))
801 #define dumptype_get_tape_splitsize(dtyp)      (val_t_to_int64(dumptype_getconf((dtyp), DUMPTYPE_TAPE_SPLITSIZE)))
802 #define dumptype_get_fallback_splitsize(dtyp)  (val_t_to_int64(dumptype_getconf((dtyp), DUMPTYPE_FALLBACK_SPLITSIZE)))
803 #define dumptype_get_split_diskbuffer(dtyp)    (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_SPLIT_DISKBUFFER)))
804 #define dumptype_get_record(dtyp)              (val_t_to_boolean(dumptype_getconf((dtyp), DUMPTYPE_RECORD)))
805 #define dumptype_get_skip_incr(dtyp)           (val_t_to_boolean(dumptype_getconf((dtyp), DUMPTYPE_SKIP_INCR)))
806 #define dumptype_get_skip_full(dtyp)           (val_t_to_boolean(dumptype_getconf((dtyp), DUMPTYPE_SKIP_FULL)))
807 #define dumptype_get_to_holdingdisk(dtyp)      (val_t_to_holding(dumptype_getconf((dtyp), DUMPTYPE_HOLDINGDISK)))
808 #define dumptype_get_kencrypt(dtyp)            (val_t_to_boolean(dumptype_getconf((dtyp), DUMPTYPE_KENCRYPT)))
809 #define dumptype_get_ignore(dtyp)              (val_t_to_boolean(dumptype_getconf((dtyp), DUMPTYPE_IGNORE)))
810 #define dumptype_get_index(dtyp)               (val_t_to_boolean(dumptype_getconf((dtyp), DUMPTYPE_INDEX)))
811 #define dumptype_get_application(dtyp)         (val_t_to_application(dumptype_getconf((dtyp), DUMPTYPE_APPLICATION)))
812 #define dumptype_get_scriptlist(dtyp)          (val_t_to_identlist(dumptype_getconf((dtyp), DUMPTYPE_SCRIPTLIST)))
813 #define dumptype_get_property(dtyp)            (val_t_to_proplist(dumptype_getconf((dtyp), DUMPTYPE_PROPERTY)))
814 #define dumptype_get_client_port(dtyp)         (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_CLIENT_PORT)))
815 #define dumptype_get_data_path(dtyp)           (val_t_to_data_path(dumptype_getconf((dtyp), DUMPTYPE_DATA_PATH)))
816 #define dumptype_get_allow_split(dtyp)         (val_t_to_boolean(dumptype_getconf((dtyp), DUMPTYPE_ALLOW_SPLIT)))
817 #define dumptype_get_recovery_limit(dtyp)      (val_t_to_host_limit(dumptype_getconf((dtyp), DUMPTYPE_RECOVERY_LIMIT)))
818 #define dumptype_get_dump_limit(dtyp)          (val_t_to_host_limit(dumptype_getconf((dtyp), DUMPTYPE_DUMP_LIMIT)))
819 #define dumptype_get_max_warnings(dtyp)        (val_t_to_int(dumptype_getconf((dtyp), DUMPTYPE_MAX_WARNINGS)))
820
821 /*
822  * Interface parameter access
823  */
824
825 typedef enum {
826     INTER_COMMENT,
827     INTER_MAXUSAGE,
828     INTER_INTER /* sentinel */
829 } interface_key;
830
831 /* opaque object */
832 typedef struct interface_s interface_t;
833
834 /* Given the name of the interface, return a interface object.  Returns NULL
835  * if no matching interface exists.  Note that the match is case-insensitive.
836  *
837  * @param identifier: name of the desired interface
838  * @returns: object or NULL
839  */
840 interface_t *lookup_interface(char *identifier);
841
842 /* Given a interface and a key, return a pointer to the corresponding val_t.
843  *
844  * @param iface: the interface to examine
845  * @param key: interface_key (one of the TAPETYPE_* constants)
846  * @returns: pointer to value
847  */
848 val_t *interface_getconf(interface_t *iface, interface_key key);
849
850 /* Get the name of this interface.
851  *
852  * @param iface: the interface to examine
853  * @returns: name of the interface
854  */
855 char *interface_name(interface_t *iface);
856
857 /* (convenience macro) has this parameter been seen in this interface?  This
858  * applies to the specific parameter *within* the interface.
859  *
860  * @param key: interface_key
861  * @returns: boolean
862  */
863 #define interface_seen(iface, key)       (val_t_seen(interface_getconf((iface), (key))))
864
865 /* (convenience macros)
866  * fetch a particular parameter; caller must know the correct type.
867  *
868  * @param iface: the interface to examine
869  * @returns: various
870  */
871 #define interface_get_comment(iface)    (val_t_to_str(interface_getconf((iface), INTER_COMMENT)))
872 #define interface_get_maxusage(iface)   (val_t_to_int(interface_getconf((iface), INTER_MAXUSAGE)))
873
874 /*
875  * Holdingdisk parameter access
876  */
877
878 typedef enum {
879     HOLDING_COMMENT,
880     HOLDING_DISKDIR,
881     HOLDING_DISKSIZE,
882     HOLDING_CHUNKSIZE,
883     HOLDING_HOLDING /* sentinel */
884 } holdingdisk_key;
885
886 /* opaque object */
887 typedef struct holdingdisk_s holdingdisk_t;
888
889 /* Given the name of the holdingdisk, return a holdingdisk object.  Returns NULL
890  * if no matching holdingdisk exists.  Note that the match is case-insensitive.
891  *
892  * @param identifier: name of the desired holdingdisk
893  * @returns: object or NULL
894  */
895 holdingdisk_t *lookup_holdingdisk(char *identifier);
896
897 /* Return the whole linked list of holdingdisks.
898  *
899  * @returns: first holding disk
900  */
901 GSList *getconf_holdingdisks(void);
902
903 /* Given a holdingdisk and a key, return a pointer to the corresponding val_t.
904  *
905  * @param hdisk: the holdingdisk to examine
906  * @param key: holdingdisk_key (one of the TAPETYPE_* constants)
907  * @returns: pointer to value
908  */
909 val_t *holdingdisk_getconf(holdingdisk_t *hdisk, holdingdisk_key key);
910
911 /* Get the name of this holdingdisk.
912  *
913  * @param hdisk: the holdingdisk to examine
914  * @returns: name of the holdingdisk
915  */
916 char *holdingdisk_name(holdingdisk_t *hdisk);
917
918 /* (convenience macro) has this parameter been seen in this holdingdisk?  This
919  * applies to the specific parameter *within* the holdingdisk.
920  *
921  * @param key: holdingdisk_key
922  * @returns: boolean
923  */
924 #define holdingdisk_seen(hdisk, key)       (val_t_seen(holdingdisk_getconf((hdisk), (key))))
925
926 /* (convenience macros)
927  * fetch a particular parameter; caller must know the correct type.
928  *
929  * @param hdisk: the holdingdisk to examine
930  * @returns: various
931  */
932 #define holdingdisk_get_comment(hdisk)   (val_t_to_str(holdingdisk_getconf((hdisk), HOLDING_COMMENT)))
933 #define holdingdisk_get_diskdir(hdisk)   (val_t_to_str(holdingdisk_getconf((hdisk), HOLDING_DISKDIR)))
934 #define holdingdisk_get_disksize(hdisk)  (val_t_to_int64(holdingdisk_getconf((hdisk), HOLDING_DISKSIZE)))
935 #define holdingdisk_get_chunksize(hdisk) (val_t_to_int64(holdingdisk_getconf((hdisk), HOLDING_CHUNKSIZE)))
936
937 /* A application-tool interface */
938 typedef enum application_e  {
939     APPLICATION_COMMENT,
940     APPLICATION_PLUGIN,
941     APPLICATION_PROPERTY,
942     APPLICATION_CLIENT_NAME,
943     APPLICATION_APPLICATION
944 } application_key;
945
946 /* opaque object */
947 typedef struct application_s application_t;
948
949 /* Given the name of the application, return a application object.  Returns NULL
950  * if no matching application exists.  Note that the match is case-insensitive.
951  *
952  * @param identifier: name of the desired application
953  * @returns: object or NULL
954  */
955
956 application_t *lookup_application(char *identifier);
957
958 /* Given a application and a key, return a pointer to the corresponding val_t.
959  *
960  * @param ttyp: the application to examine
961  * @param key: application (one of the APPLICATION_* constants)
962  * @returns: pointer to value
963  */
964 val_t *application_getconf(application_t *app, application_key key);
965
966 /* Get the name of this application.
967  *
968  * @param ttyp: the application to examine
969  * @returns: name of the application
970  */
971 char *application_name(application_t *app);
972
973 /* (convenience macro) has this parameter been seen in this application?  This
974  * applies to the specific parameter *within* the application.
975  *
976  * @param key: application_key
977  * @returns: boolean
978  */
979 #define application_seen(app, key)       (val_t_seen(application_getconf((app), (key))))
980
981 /* (convenience macros)
982  * fetch a particular parameter; caller must know the correct type.
983  *
984  * @param ttyp: the application to examine
985  * @returns: various
986  */
987 #define application_get_comment(application)  (val_t_to_str(application_getconf((application), APPLICATION_COMMENT))
988 #define application_get_plugin(application)   (val_t_to_str(application_getconf((application), APPLICATION_PLUGIN)))
989 #define application_get_property(application) (val_t_to_proplist(application_getconf((application), APPLICATION_PROPERTY)))
990 #define application_get_client_name(application) (val_t_to_str(application_getconf((application), APPLICATION_CLIENT_NAME)))
991
992 /* A pp-script-tool interface */
993 typedef enum pp_script_e  {
994     PP_SCRIPT_COMMENT,
995     PP_SCRIPT_PLUGIN,
996     PP_SCRIPT_PROPERTY,
997     PP_SCRIPT_EXECUTE_ON,
998     PP_SCRIPT_EXECUTE_WHERE,
999     PP_SCRIPT_ORDER,
1000     PP_SCRIPT_SINGLE_EXECUTION,
1001     PP_SCRIPT_CLIENT_NAME,
1002     PP_SCRIPT_PP_SCRIPT
1003 } pp_script_key;
1004
1005 /* opaque object */
1006 typedef struct pp_script_s pp_script_t;
1007
1008 /* Given the name of the pp_script, return a pp_script object.  Returns NULL
1009  * if no matching pp_script exists.  Note that the match is case-insensitive.
1010  *
1011  * @param identifier: name of the desired pp_script
1012  * @returns: object or NULL
1013  */
1014
1015 pp_script_t *lookup_pp_script(char *identifier);
1016
1017 /* Given a pp_script and a key, return a pointer to the corresponding val_t.
1018  *
1019  * @param ttyp: the pp_script to examine
1020  * @param key: pp_script (one of the PP_SCRIPT_* constants)
1021  * @returns: pointer to value
1022  */
1023 val_t *pp_script_getconf(pp_script_t *pps, pp_script_key key);
1024
1025 /* Get the name of this pp_script.
1026  *
1027  * @param ttyp: the pp_script to examine
1028  * @returns: name of the pp_script
1029  */
1030 char *pp_script_name(pp_script_t *pps);
1031
1032 /* (convenience macro) has this parameter been seen in this pp_script?  This
1033  * applies to the specific parameter *within* the pp_script.
1034  *
1035  * @param key: pp_script_key
1036  * @returns: boolean
1037  */
1038 #define pp_script_seen(pps, key)       (val_t_seen(pp_script_getconf((pps), (key))))
1039
1040 /* (convenience macros)
1041  * fetch a particular parameter; caller must know the correct type.
1042  *
1043  * @param ttyp: the pp_script to examine
1044  * @returns: various
1045  */
1046
1047 #define pp_script_get_comment(pp_script)   (val_t_to_str(pp_script_getconf((pp_script), PP_SCRIPT_COMMENT)))
1048 #define pp_script_get_plugin(pp_script)   (val_t_to_str(pp_script_getconf((pp_script), PP_SCRIPT_PLUGIN)))
1049 #define pp_script_get_property(pp_script)   (val_t_to_proplist(pp_script_getconf((pp_script), PP_SCRIPT_PROPERTY)))
1050 #define pp_script_get_execute_on(pp_script)   (val_t_to_execute_on(pp_script_getconf((pp_script), PP_SCRIPT_EXECUTE_ON)))
1051 #define pp_script_get_execute_where(pp_script)   (val_t_to_execute_where(pp_script_getconf((pp_script), PP_SCRIPT_EXECUTE_WHERE)))
1052 #define pp_script_get_order(pp_script)   (val_t_to_int(pp_script_getconf((pp_script), PP_SCRIPT_ORDER)))
1053 #define pp_script_get_single_execution(pp_script)   (val_t_to_boolean(pp_script_getconf((pp_script), PP_SCRIPT_SINGLE_EXECUTION)))
1054 #define pp_script_get_client_name(pp_script)   (val_t_to_str(pp_script_getconf((pp_script), PP_SCRIPT_CLIENT_NAME)))
1055
1056 pp_script_t *lookup_pp_script(char *identifier);
1057
1058 /* A device definition */
1059 typedef enum {
1060     DEVICE_CONFIG_COMMENT,
1061     DEVICE_CONFIG_TAPEDEV,
1062     DEVICE_CONFIG_DEVICE_PROPERTY,
1063     DEVICE_CONFIG_DEVICE_CONFIG
1064 } device_config_key;
1065
1066 /* opaque object */
1067 typedef struct device_config_s device_config_t;
1068
1069 /* Given the name of the device, return a device_config_t object.  Returns NULL
1070  * if no matching device exists.  Note that the match is case-insensitive.
1071  *
1072  * @param identifier: name of the desired device
1073  * @returns: object or NULL
1074  */
1075
1076 device_config_t *lookup_device_config(char *identifier);
1077
1078 /* Given a device_config and a key, return a pointer to the corresponding val_t.
1079  *
1080  * @param ttyp: the device_config to examine
1081  * @param key: device_config (one of the DEVICE_CONFIG_* constants)
1082  * @returns: pointer to value
1083  */
1084 val_t *device_config_getconf(device_config_t *devconf, device_config_key key);
1085
1086 /* Get the name of this device_config.
1087  *
1088  * @param ttyp: the device_config to examine
1089  * @returns: name of the device_config
1090  */
1091 char *device_config_name(device_config_t *devconf);
1092
1093 /* (convenience macro) has this parameter been seen in this device_config?  This
1094  * applies to the specific parameter *within* the device_config.
1095  *
1096  * @param key: device_config_key
1097  * @returns: boolean
1098  */
1099 #define device_config_seen(devconf, key)       (val_t_seen(device_config_getconf((devconf), (key))))
1100
1101 /* (convenience macros)
1102  * fetch a particular parameter; caller must know the correct type.
1103  *
1104  * @param devconf: the device_config to examine
1105  * @returns: various
1106  */
1107
1108 #define device_config_get_comment(devconf)   (val_t_to_str(device_config_getconf((devconf), DEVICE_CONFIG_COMMENT)))
1109 #define device_config_get_tapedev(devconf)   (val_t_to_str(device_config_getconf((devconf), DEVICE_CONFIG_TAPEDEV)))
1110 #define device_config_get_property(devconf)   (val_t_to_proplist(device_config_getconf((devconf), DEVICE_CONFIG_DEVICE_PROPERTY)))
1111
1112 device_config_t *lookup_device_config(char *identifier);
1113
1114 /* A changer definition */
1115 typedef enum {
1116     CHANGER_CONFIG_COMMENT,
1117     CHANGER_CONFIG_TAPEDEV,
1118     CHANGER_CONFIG_TPCHANGER,
1119     CHANGER_CONFIG_CHANGERDEV,
1120     CHANGER_CONFIG_CHANGERFILE,
1121     CHANGER_CONFIG_PROPERTY,
1122     CHANGER_CONFIG_DEVICE_PROPERTY,
1123     CHANGER_CONFIG_CHANGER_CONFIG
1124 } changer_config_key;
1125
1126 /* opaque object */
1127 typedef struct changer_config_s changer_config_t;
1128
1129 /* Given the name of the changer, return a changer_config_t object.  Returns NULL
1130  * if no matching changer exists.  Note that the match is case-insensitive.
1131  *
1132  * @param identifier: name of the desired changer
1133  * @returns: object or NULL
1134  */
1135
1136 changer_config_t *lookup_changer_config(char *identifier);
1137
1138 /* Given a changer_config and a key, return a pointer to the corresponding val_t.
1139  *
1140  * @param ttyp: the changer_config to examine
1141  * @param key: changer_config (one of the DEVICE_CONFIG_* constants)
1142  * @returns: pointer to value
1143  */
1144 val_t *changer_config_getconf(changer_config_t *devconf, changer_config_key key);
1145
1146 /* Get the name of this changer_config.
1147  *
1148  * @param ttyp: the changer_config to examine
1149  * @returns: name of the changer_config
1150  */
1151 char *changer_config_name(changer_config_t *devconf);
1152
1153 /* (convenience macro) has this parameter been seen in this changer_config?  This
1154  * applies to the specific parameter *within* the changer_config.
1155  *
1156  * @param key: changer_config_key
1157  * @returns: boolean
1158  */
1159 #define changer_config_seen(devconf, key)       (val_t_seen(changer_config_getconf((devconf), (key))))
1160
1161 /* (convenience macros)
1162  * fetch a particular parameter; caller must know the correct type.
1163  *
1164  * @param devconf: the changer_config to examine
1165  * @returns: various
1166  */
1167
1168 #define changer_config_get_comment(devconf)   (val_t_to_str(changer_config_getconf((devconf), CHANGER_CONFIG_COMMENT)))
1169 #define changer_config_get_tapedev(devconf)   (val_t_to_str(changer_config_getconf((devconf), CHANGER_CONFIG_TAPEDEV)))
1170 #define changer_config_get_tpchanger(devconf)   (val_t_to_str(changer_config_getconf((devconf), CHANGER_CONFIG_TPCHANGER)))
1171 #define changer_config_get_changerdev(devconf)   (val_t_to_str(changer_config_getconf((devconf), CHANGER_CONFIG_CHANGERDEV)))
1172 #define changer_config_get_changerfile(devconf)   (val_t_to_str(changer_config_getconf((devconf), CHANGER_CONFIG_CHANGERFILE)))
1173
1174 changer_config_t *lookup_changer_config(char *identifier);
1175
1176 /* A interacrtivity interface */
1177 typedef enum interactivity_e  {
1178     INTERACTIVITY_COMMENT,
1179     INTERACTIVITY_PLUGIN,
1180     INTERACTIVITY_PROPERTY,
1181     INTERACTIVITY_INTERACTIVITY
1182 } interactivity_key;
1183
1184 /* opaque object */
1185 typedef struct interactivity_s interactivity_t;
1186
1187 /* Given the name of the interactivity, return a interactivity object.
1188  *  Returns NULL if no matching interactivity exists.
1189  *  Note that the match is case-insensitive.
1190  *
1191  * @param identifier: name of the desired interactivity
1192  * @returns: object or NULL
1193  */
1194
1195 interactivity_t *lookup_interactivity(char *identifier);
1196
1197 /* Given a interactivity and a key, return a pointer to the corresponding val_t.
1198  *
1199  * @param ttyp: the interactivity to examine
1200  * @param key: interactivity (one of the INTERACTIVITY_* constants)
1201  * @returns: pointer to value
1202  */
1203 val_t *interactivity_getconf(interactivity_t *app, interactivity_key key);
1204
1205 /* Get the name of this interactivity.
1206  *
1207  * @param ttyp: the interactivity to examine
1208  * @returns: name of the interactivity
1209  */
1210 char *interactivity_name(interactivity_t *app);
1211
1212 /* (convenience macro) has this parameter been seen in this interactivity?
1213  * This applies to the specific parameter *within* the interactivity.
1214  *
1215  * @param key: interactivity_key
1216  * @returns: boolean
1217  */
1218 #define interactivity_seen(app, key)       (val_t_seen(interactivity_getconf((app), (key))))
1219
1220 /* (convenience macros)
1221  * fetch a particular parameter; caller must know the correct type.
1222  *
1223  * @param ttyp: the interactivity to examine
1224  * @returns: various
1225  */
1226 #define interactivity_get_comment(interactivity)  (val_t_to_str(interactivity_getconf((interactivity), INTERACTIVITY_COMMENT))
1227 #define interactivity_get_plugin(interactivity)   (val_t_to_str(interactivity_getconf((interactivity), INTERACTIVITY_PLUGIN)))
1228 #define interactivity_get_property(interactivity) (val_t_to_proplist(interactivity_getconf((interactivity), INTERACTIVITY_PROPERTY)))
1229
1230 /* A taperscan interface */
1231 typedef enum taperscan_e  {
1232     TAPERSCAN_COMMENT,
1233     TAPERSCAN_PLUGIN,
1234     TAPERSCAN_PROPERTY,
1235     TAPERSCAN_TAPERSCAN
1236 } taperscan_key;
1237
1238 /* opaque object */
1239 typedef struct taperscan_s taperscan_t;
1240
1241 /* Given the name of the taperscan, return a taperscan object.
1242  *  Returns NULL if no matching taperscan exists.
1243  *  Note that the match is case-insensitive.
1244  *
1245  * @param identifier: name of the desired taperscan
1246  * @returns: object or NULL
1247  */
1248
1249 taperscan_t *lookup_taperscan(char *identifier);
1250
1251 /* Given a taperscan and a key, return a pointer to the corresponding val_t.
1252  *
1253  * @param ttyp: the taperscan to examine
1254  * @param key: taperscan (one of the TAPERSCAN_* constants)
1255  * @returns: pointer to value
1256  */
1257 val_t *taperscan_getconf(taperscan_t *app, taperscan_key key);
1258
1259 /* Get the name of this taperscan.
1260  *
1261  * @param ttyp: the taperscan to examine
1262  * @returns: name of the taperscan
1263  */
1264 char *taperscan_name(taperscan_t *app);
1265
1266 /* (convenience macro) has this parameter been seen in this taperscan?
1267  * This applies to the specific parameter *within* the taperscan.
1268  *
1269  * @param key: taperscan_key
1270  * @returns: boolean
1271  */
1272 #define taperscan_seen(app, key)       (val_t_seen(taperscan_getconf((app), (key))))
1273
1274 /* (convenience macros)
1275  * fetch a particular parameter; caller must know the correct type.
1276  *
1277  * @param ttyp: the taperscan to examine
1278  * @returns: various
1279  */
1280 #define taperscan_get_comment(taperscan)  (val_t_to_str(taperscan_getconf((taperscan), TAPERSCAN_COMMENT))
1281 #define taperscan_get_plugin(taperscan)   (val_t_to_str(taperscan_getconf((taperscan), TAPERSCAN_PLUGIN)))
1282 #define taperscan_get_property(taperscan) (val_t_to_proplist(taperscan_getconf((taperscan), TAPERSCAN_PROPERTY)))
1283
1284
1285 /*
1286  * Error Handling
1287  */
1288
1289 typedef enum {
1290     /* No errors or warnings */
1291     CFGERR_OK = 0,
1292
1293     /* warnings were encountered */
1294     CFGERR_WARNINGS = 1,
1295
1296     /* errors (and maybe some warnings too, who knows) were encountered */
1297     CFGERR_ERRORS = 2,
1298 } cfgerr_level_t;
1299
1300 /*
1301  * Errors
1302  */
1303
1304 /* Get a GSList of all error and warning messages accumulated so far.
1305  *
1306  * @param (output) errlist: pointer to the list of error strings; allocated
1307  * memory remains the responsibility of the config module.  If errlist is
1308  * NULL, the list is not returned.
1309  * @returns: current error level
1310  */
1311 cfgerr_level_t config_errors(GSList **errlist);
1312
1313 /* Clear any error conditions.
1314  */
1315 void config_clear_errors(void);
1316
1317 /* Print the list of current error and warning messages, one per line,
1318  * to stderr. This is a convenience function for command-line
1319  * applications.
1320  */
1321 void config_print_errors(void);
1322
1323 /* Add an error message to the list of errors, and make sure tha the
1324  * error level is at least LEVEL.  This is used by the diskfile module
1325  * to insert its errors into this module's error list.
1326  *
1327  * @param level: level for this error
1328  * @param errmsg: error message; conffile takes responsibility for freeing
1329  *   this string.
1330  */
1331 void config_add_error(cfgerr_level_t level, char *errmsg);
1332
1333 /*
1334  * Command-line handling
1335  */
1336
1337 /* opaque type */
1338 typedef struct config_overrides_s config_overrides_t;
1339
1340 /* Create a new, empty config_overrides object.
1341  *
1342  * @param size_estimate: a guess at the number of overwrites; argc/2 is a 
1343  *  good estimate.
1344  * @returns: new object
1345  */
1346 config_overrides_t *new_config_overrides(int size_estimate);
1347
1348 /* Free a config_overrides object.  This usually won't be needed, as
1349  * apply_config_overrides takes ownership of the overwrites for you.
1350  *
1351  * @param co: config_overrides object
1352  */
1353 void free_config_overrides(config_overrides_t *co);
1354
1355 /* Add an overwrite to a config_overrides object.
1356  *
1357  * @param co: the config_overrides object
1358  * @param key: the configuration parameter's key, possibly with the format
1359  * SUBTYPE:NAME:KEYWORD
1360  * @param value: the value for the parameter, as would be seen in amanda.conf
1361  */
1362 void add_config_override(config_overrides_t *co,
1363                          char *key,
1364                          char *value);
1365
1366 /* Add an overwrite option from the command line to a config_overrides
1367  * object.  Calls error() with any errors
1368  *
1369  * @param co: the config_overrides object
1370  * @param optarg: the value of the command-line option
1371  */
1372 void add_config_override_opt(config_overrides_t *co,
1373                               char *optarg);
1374
1375 /* Given a command line, represented as argc/argv, extract any -o options
1376  * as config overwrites.  This function modifies argc and argv in place.
1377  *
1378  * This is the deprecated way to extract config overwrites, for applications
1379  * which do not use getopt.  The preferred method is to use getopt and
1380  * call add_config_override_opt for any -o options.
1381  *
1382  * @param argc: (in/out) command-line length
1383  * @param argv: (in/out) command-line strings
1384  * @returns: newly allocated config_overrides object
1385  */
1386 config_overrides_t *
1387 extract_commandline_config_overrides(int *argc,
1388                                       char ***argv);
1389
1390 /* Set configuration overwrites to the current configuration and take
1391  * ownership of the config_overrides object.
1392  *
1393  * @param co: the config_overrides object
1394  */
1395 void set_config_overrides(config_overrides_t *co);
1396
1397 /*
1398  * Initialization
1399  */
1400
1401 /* Constants for config_init */
1402 typedef enum {
1403     /* Use arg_config_name, if not NULL */
1404     CONFIG_INIT_EXPLICIT_NAME = 1 << 0,
1405
1406     /* Use the current working directory if an explicit name is not available */
1407     CONFIG_INIT_USE_CWD = 1 << 1,
1408
1409     /* This is a client application (server is default) */
1410     CONFIG_INIT_CLIENT = 1 << 2,
1411
1412     /* New configuration should "overlay" existing configuration; this
1413      * is used by clients to load multiple amanda-client.conf files. */
1414     CONFIG_INIT_OVERLAY = 1 << 3,
1415 } config_init_flags;
1416
1417 /* Initialize this application's configuration, with the specific actions
1418  * based on 'flags':
1419  *  - if CONFIG_INIT_OVERLAY is not set, configuration values are reset
1420  *    to their defaults
1421  *  - if CONFIG_INIT_EXPLICIT_NAME and arg_config_name is not NULL,
1422  *    use CONFIG_DIR/arg_config_name as config_dir arg_config_name as 
1423  *    config_name.
1424  *  - otherwise, if CONFIG_USE_CWD is set, use the directory in which 
1425  *    the application was started as config_dir, and its filename as 
1426  *    config_name.
1427  *  - otherwise, for the client only, se config_dir to CONFIG_DIR and
1428  *    config_name to NULL.
1429  *  - depending on CONFIG_INIT_CLIENT, read amanda.conf or amanda-client.conf
1430  *
1431  * @param flags: flags indicating desired behavior, as above
1432  * @param arg_config_name: config name to use (from e.g., argv[1])
1433  * @returns: current error level
1434  */
1435 cfgerr_level_t config_init(
1436          config_init_flags flags,
1437          char *arg_config_name);
1438
1439 /* Free all memory allocated for the configuration.  This effectively
1440  * reverses the effects of config_init().
1441  */
1442 void config_uninit(void);
1443
1444 /* Encode any applied config_overrides into a strv format suitale for
1445  * executing another Amanda tool.
1446  *
1447  * The * result is dynamically allocated and NULL terminated.  There is no
1448  * provision to free the result, as this function is always called just
1449  * before execve(..).
1450  *
1451  * First gives the number of array elements to leave for the caller to
1452  * fill in.  The usual calling pattern is this:
1453  *   command_line = get_config_options(3);
1454  *   command_line[0] = "appname";
1455  *   command_line[1] = config_name;
1456  *   command_line[2] = "--foo";
1457  *   execve(command_line[0], command_line, safe_env());
1458  *
1459  * @param first: number of unused elements to leave at the beginning of
1460  * the array.
1461  * @returns: NULL-terminated string array suitable for execve
1462  */
1463 char **get_config_options(int first);
1464
1465 /* Get the config name */
1466 char *get_config_name(void);
1467
1468 /* Get the config directory */
1469 char *get_config_dir(void);
1470
1471 /* Get the config filename */
1472 char *get_config_filename(void);
1473
1474 /*
1475  * Utilities
1476  */
1477
1478 /* Security plugins get their configuration information through a callback
1479  * with the signature:
1480  *   char *callback(char *key, void *userpointer);
1481  * where key is the name of the desired parameter, which may not match the
1482  * name used in this module.  See the implementations of these functions
1483  * to learn which keys they support, or to add new keys.
1484  */
1485 char *generic_client_get_security_conf(char *, void *);
1486 char *generic_get_security_conf(char *, void *);
1487
1488 /* Dump the current configuration information to stdout, in a format 
1489  * that can be re-read by this module.  The results will include any
1490  * command-line overwrites.
1491  *
1492  * This function only dumps the server configuration, and will fail on
1493  * clients.
1494  */
1495 void dump_configuration(gboolean print_default, gboolean print_source);
1496
1497 void dump_dumptype(dumptype_t *dp, char *prefix, gboolean print_default,
1498                    gboolean print_source);
1499
1500 /* Return a sequence of strings giving the printable representation
1501  * of the given val_t.  If str_needs_quotes is true and each string is
1502  * prefixed by the relevant configuration keyword, these strings will
1503  * be parseable by this module, and will reproduce exactly the same
1504  * configuration value.  See the implementation of dump_configuration
1505  * for details.
1506  *
1507  * If str_needs_quotes is provided, a CONFTYPE_STR value will be returned with 
1508  * quotes.
1509  *
1510  * The result is a NULL-terminated strv, which can be freed with g_strfreev or
1511  * joined with g_strjoinv.  Caller is responsible for freeing the memory.
1512  *
1513  * @param val: the value to analyze
1514  * @param str_needs_quotes: add quotes to CONFTYPE_STR values?
1515  * @returns: NULL-terminated string vector
1516  */
1517 char **val_t_display_strs(val_t *val, int str_needs_quotes, gboolean  print_source,
1518                           gboolean print_unit);
1519
1520 /* Read a dumptype; this is used by this module as well as by diskfile.c to
1521  * read the disklist.  The two are carefully balanced in their parsing process.
1522  *
1523  * Nobody else should use this function.  Seriously.
1524  */
1525 dumptype_t *read_dumptype(char *name, FILE *from, char *fname, int *linenum);
1526
1527 /* Every call return a pointer to a string with an increasing number; this is
1528  * used by this module as well as by diskfile.c to read the disklist.
1529  *
1530  * Nobody else should use this function.  Seriously.
1531  *
1532  * @returns: a pointer to a static string.
1533  */
1534 char *anonymous_value(void);
1535
1536 /* Extend a relative filename with the current config_dir; if filename is already
1537  * absolute, this is equivalent to stralloc.
1538  *
1539  * @param filename: filename to extend
1540  * @returns: newly allocated filename
1541  */
1542 char *config_dir_relative(char *filename);
1543
1544 /* Convert from a symbol back to a name for logging and for dumping
1545  * config values
1546  *
1547  * @param taperalgo: the constant value
1548  * @returns: statically allocated string
1549  */
1550 char *taperalgo2str(taperalgo_t taperalgo);
1551
1552 /* Looks for a unit value like b, byte, bytes, bps, etc. Technically
1553  * the return value should never be < 1, but we return a signed value
1554  * to help mitigate bad C promotion semantics. Returns 0 on error.
1555  *
1556  * This is here in this module because it uses the numb_keytable.
1557  *
1558  * @param casestr: the unit string
1559  * @returns: the corresponding multiplier (e.g., 'M' => 1024*1024)
1560  */
1561 gint64 find_multiplier(char * casestr);
1562
1563 /* Converts a string matching any of Amanda's names for "true" or
1564  * "false" to a boolean value.
1565  *
1566  * @param str: string to match
1567  * @returns: 0 or 1 (boolean) or -1 (no match)
1568  */
1569 int string_to_boolean(const char *str);
1570
1571 /* Return a pointer to a static string for the data_path */
1572 char *data_path_to_string(data_path_t data_path);
1573
1574 /* Return the data_path for the string */
1575 data_path_t data_path_from_string(char *data);
1576
1577 void free_property_t(gpointer p);
1578
1579 /* Converts a string into Amanda property name style.
1580  *
1581  * @param name: The name to convert.
1582  * @returns: A newly allocated string, with name in lowercase and
1583  * any instances of '_' replaced with '-'.
1584  */
1585 gchar *amandaify_property_name(const gchar *name);
1586
1587 #endif /* ! CONFFILE_H */