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