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