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