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