]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/parse_conf.h
First cut of adding .mod to the run command.
[bacula/bacula] / bacula / src / lib / parse_conf.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version two of the GNU General Public
10    License as published by the Free Software Foundation plus additions
11    that are listed in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of John Walker.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  *
30  *     Kern Sibbald, January MM
31  *
32  *   Version $Id$
33  *
34  */
35
36 struct RES_ITEM;                    /* Declare forward referenced structure */
37 class RES;                         /* Declare forware referenced structure */
38 typedef void (MSG_RES_HANDLER)(LEX *lc, RES_ITEM *item, int index, int pass);
39
40 /* This is the structure that defines
41  * the record types (items) permitted within each
42  * resource. It is used to define the configuration
43  * tables.
44  */
45 struct RES_ITEM {
46    const char *name;                  /* Resource name i.e. Director, ... */
47    MSG_RES_HANDLER *handler;          /* Routine storing the resource item */
48    union {
49       char **value;                   /* Where to store the item */
50       char **charvalue;
51       uint32_t ui32value;
52       int32_t i32value;
53       uint64_t ui64value;
54       int64_t i64value;
55       bool boolvalue;
56       utime_t utimevalue;
57       RES *resvalue;
58       RES **presvalue;
59    };
60    int  code;                         /* item code/additional info */
61    int  flags;                        /* flags: default, required, ... */
62    int  default_value;                /* default value */
63 };
64
65 /* For storing name_addr items in res_items table */
66 #define ITEM(x) {(char **)&res_all.x}
67
68 #define MAX_RES_ITEMS 70              /* maximum resource items per RES */
69
70 /* This is the universal header that is
71  * at the beginning of every resource
72  * record.
73  */
74 class RES {
75 public:
76    RES *next;                         /* pointer to next resource of this type */
77    char *name;                        /* resource name */
78    char *desc;                        /* resource description */
79    int   rcode;                       /* resource id or type */
80    int   refcnt;                      /* reference count for releasing */
81    char  item_present[MAX_RES_ITEMS]; /* set if item is present in conf file */
82 };
83
84
85 /*
86  * Master Resource configuration structure definition
87  * This is the structure that defines the
88  * resources that are available to this daemon.
89  */
90 struct RES_TABLE {
91    const char *name;                  /* resource name */
92    RES_ITEM *items;                   /* list of resource keywords */
93    int rcode;                         /* code if needed */
94 };
95
96 /* Common Resource definitions */
97
98 #define MAX_RES_NAME_LENGTH MAX_NAME_LENGTH-1       /* maximum resource name length */
99
100 #define ITEM_REQUIRED    0x1          /* item required */
101 #define ITEM_DEFAULT     0x2          /* default supplied */
102 #define ITEM_NO_EQUALS   0x4          /* Don't scan = after name */
103
104 /* Message Resource */
105 class MSGS {
106 public:
107    RES   hdr;
108    char *mail_cmd;                    /* mail command */
109    char *operator_cmd;                /* Operator command */
110    DEST *dest_chain;                  /* chain of destinations */
111    char send_msg[nbytes_for_bits(M_MAX+1)];  /* bit array of types */
112
113    /* Methods */
114    char *name() const;
115 };
116
117 inline char *MSGS::name() const { return hdr.name; }
118
119
120 /* Define the Union of all the above common
121  * resource structure definitions.
122  */
123 union CURES {
124    MSGS  res_msgs;
125    RES hdr;
126 };
127
128
129 /* Configuration routines */
130 int   parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error = NULL, int err_type=M_ERROR_TERM);
131 void    free_config_resources(void);
132 RES   **save_config_resources(void);
133 RES   **new_res_head();
134
135
136 /* Resource routines */
137 RES *GetResWithName(int rcode, char *name);
138 RES *GetNextRes(int rcode, RES *res);
139 void b_LockRes(const char *file, int line);
140 void b_UnlockRes(const char *file, int line);
141 void dump_resource(int type, RES *res, void sendmsg(void *sock, const char *fmt, ...), void *sock);
142 void free_resource(RES *res, int type);
143 void init_resource(int type, RES_ITEM *item);
144 void save_resource(int type, RES_ITEM *item, int pass);
145 const char *res_to_str(int rcode);
146
147 /* Loop through each resource of type, returning in var */
148 #ifdef HAVE_TYPEOF
149 #define foreach_res(var, type) \
150         for((var)=NULL; ((var)=(typeof(var))GetNextRes((type), (RES *)var));)
151 #else 
152 #define foreach_res(var, type) \
153     for(var=NULL; (*((void **)&(var))=(void *)GetNextRes((type), (RES *)var));)
154 #endif
155
156
157
158 void store_str(LEX *lc, RES_ITEM *item, int index, int pass);
159 void store_dir(LEX *lc, RES_ITEM *item, int index, int pass);
160 void store_password(LEX *lc, RES_ITEM *item, int index, int pass);
161 void store_name(LEX *lc, RES_ITEM *item, int index, int pass);
162 void store_strname(LEX *lc, RES_ITEM *item, int index, int pass);
163 void store_res(LEX *lc, RES_ITEM *item, int index, int pass);
164 void store_alist_res(LEX *lc, RES_ITEM *item, int index, int pass);
165 void store_alist_str(LEX *lc, RES_ITEM *item, int index, int pass);
166 void store_int(LEX *lc, RES_ITEM *item, int index, int pass);
167 void store_pint(LEX *lc, RES_ITEM *item, int index, int pass);
168 void store_msgs(LEX *lc, RES_ITEM *item, int index, int pass);
169 void store_int64(LEX *lc, RES_ITEM *item, int index, int pass);
170 void store_bit(LEX *lc, RES_ITEM *item, int index, int pass);
171 void store_bool(LEX *lc, RES_ITEM *item, int index, int pass);
172 void store_time(LEX *lc, RES_ITEM *item, int index, int pass);
173 void store_size(LEX *lc, RES_ITEM *item, int index, int pass);
174 void store_defs(LEX *lc, RES_ITEM *item, int index, int pass);
175 void store_label(LEX *lc, RES_ITEM *item, int index, int pass);