]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/parse_conf.h
Allow multiple mailcommand+operatorcommand in Messages. Fixes bug #2222
[bacula/bacula] / bacula / src / lib / parse_conf.h
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2016 Kern Sibbald
5
6    The original author of Bacula is Kern Sibbald, with contributions
7    from many others, a complete list can be found in the file AUTHORS.
8
9    You may use this file and others of this release according to the
10    license defined in the LICENSE file, which includes the Affero General
11    Public License, v3.0 ("AGPLv3") and some additional permissions and
12    terms pursuant to its AGPLv3 Section 7.
13
14    This notice must be preserved when any source code is 
15    conveyed and/or propagated.
16
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 /*
20  *
21  *     Kern Sibbald, January MM
22  *
23  */
24
25 /* Used for certain keyword tables */
26 struct s_kw {
27    const char *name;
28    uint32_t token;
29 };
30
31 struct RES_ITEM;                   /* Declare forward referenced structure */
32 struct RES_ITEM2;                  /* Declare forward referenced structure */
33 class RES;                         /* Declare forware referenced structure */
34 typedef void (MSG_RES_HANDLER)(LEX *lc, RES_ITEM *item, int index, int pass);
35 typedef void (INC_RES_HANDLER)(LEX *lc, RES_ITEM2 *item, int index, int pass, bool exclude);
36
37
38
39 /* This is the structure that defines
40  * the record types (items) permitted within each
41  * resource. It is used to define the configuration
42  * tables.
43  */
44 struct RES_ITEM {
45    const char *name;                  /* Resource name i.e. Director, ... */
46    MSG_RES_HANDLER *handler;          /* Routine storing the resource item */
47    union {
48       char **value;                   /* Where to store the item */
49       char **charvalue;
50       uint32_t ui32value;
51       int32_t i32value;
52       uint64_t ui64value;
53       int64_t i64value;
54       bool boolvalue;
55       utime_t utimevalue;
56       RES *resvalue;
57       RES **presvalue;
58    };
59    int32_t  code;                     /* item code/additional info */
60    uint32_t  flags;                   /* flags: default, required, ... */
61    int32_t  default_value;            /* default value */
62 };
63
64 struct RES_ITEM2 {
65    const char *name;                  /* Resource name i.e. Director, ... */
66    INC_RES_HANDLER *handler;          /* Routine storing the resource item */
67    union {
68       char **value;                   /* Where to store the item */
69       char **charvalue;
70       uint32_t ui32value;
71       int32_t i32value;
72       uint64_t ui64value;
73       int64_t i64value;
74       bool boolvalue;
75       utime_t utimevalue;
76       RES *resvalue;
77       RES **presvalue;
78    };
79    int32_t  code;                     /* item code/additional info */
80    uint32_t  flags;                   /* flags: default, required, ... */
81    int32_t  default_value;            /* default value */
82 };
83
84
85 /* For storing name_addr items in res_items table */
86 #define ITEM(x) {(char **)&res_all.x}
87
88 #define MAX_RES_ITEMS 80              /* maximum resource items per RES */
89
90 /* This is the universal header that is
91  * at the beginning of every resource
92  * record.
93  */
94 class RES {
95 public:
96    RES *next;                         /* pointer to next resource of this type */
97    char *name;                        /* resource name */
98    char *desc;                        /* resource description */
99    uint32_t rcode;                    /* resource id or type */
100    int32_t  refcnt;                   /* reference count for releasing */
101    char  item_present[MAX_RES_ITEMS]; /* set if item is present in conf file */
102 };
103
104
105 /*
106  * Master Resource configuration structure definition
107  * This is the structure that defines the
108  * resources that are available to this daemon.
109  */
110 struct RES_TABLE {
111    const char *name;                  /* resource name */
112    RES_ITEM *items;                   /* list of resource keywords */
113    uint32_t rcode;                    /* code if needed */
114 };
115
116
117
118 /* Common Resource definitions */
119
120 #define MAX_RES_NAME_LENGTH MAX_NAME_LENGTH-1       /* maximum resource name length */
121
122 /* Permitted bits in Flags field */
123 #define ITEM_REQUIRED    (1<<0)       /* item required */
124 #define ITEM_DEFAULT     (1<<1)       /* default supplied */
125 #define ITEM_NO_EQUALS   (1<<2)       /* Don't scan = after name */
126 #define ITEM_LAST        (1<<3)       /* Last item in list */
127 #define ITEM_ALLOW_DUPS  (1<<4)       /* Allow duplicate directives */
128
129 /* Message Resource */
130 class MSGS {
131 public:
132    RES   hdr;
133    char *mail_cmd;                    /* mail command */
134    char *operator_cmd;                /* Operator command */
135    DEST *dest_chain;                  /* chain of destinations */
136    char send_msg[nbytes_for_bits(M_MAX+1)];  /* bit array of types */
137
138 private:
139    bool m_in_use;                     /* set when using to send a message */
140    bool m_closing;                    /* set when closing message resource */
141
142 public:
143    /* Methods */
144    char *name() const;
145    void clear_in_use() { lock(); m_in_use=false; unlock(); }
146    void set_in_use() { wait_not_in_use(); m_in_use=true; unlock(); }
147    void set_closing() { m_closing=true; }
148    bool get_closing() { return m_closing; }
149    void clear_closing() { lock(); m_closing=false; unlock(); }
150    bool is_closing() { lock(); bool rtn=m_closing; unlock(); return rtn; }
151
152    void wait_not_in_use();            /* in message.c */
153    void lock();                       /* in message.c */
154    void unlock();                     /* in message.c */
155 };
156
157 inline char *MSGS::name() const { return hdr.name; }
158
159 /*
160  * Old C style configuration routines -- deprecated do not use.
161  */
162 //int   parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error = NULL, int err_type=M_ERROR_TERM);
163 void    free_config_resources(void);
164 RES   **save_config_resources(void);
165 RES   **new_res_head();
166
167 /*
168  * New C++ configuration routines
169  */
170
171 class CONFIG {
172 public:
173    const char *m_cf;                   /* config file */
174    LEX_ERROR_HANDLER *m_scan_error;    /* error handler if non-null */
175    int32_t m_err_type;                 /* the way to terminate on failure */
176    void *m_res_all;                    /* pointer to res_all buffer */
177    int32_t m_res_all_size;             /* length of buffer */
178
179    /* The below are not yet implemented */
180    int32_t m_r_first;                  /* first daemon resource type */
181    int32_t m_r_last;                   /* last daemon resource type */
182    RES_TABLE *m_resources;             /* pointer to table of permitted resources */
183    RES **m_res_head;                   /* pointer to defined resources */
184    brwlock_t m_res_lock;               /* resource lock */
185
186    /* functions */
187    void init(
188       const char *cf,
189       LEX_ERROR_HANDLER *scan_error,
190       int32_t err_type,
191       void *vres_all,
192       int32_t res_all_size,
193       int32_t r_first,
194       int32_t r_last,
195       RES_TABLE *resources,
196       RES **res_head);
197
198    bool parse_config();
199    void free_resources();
200    RES **save_resources();
201    RES **new_res_head();
202 };
203
204 CONFIG *new_config_parser();
205
206
207 /* Resource routines */
208 RES *GetResWithName(int rcode, const char *name);
209 RES *GetNextRes(int rcode, RES *res);
210 void b_LockRes(const char *file, int line);
211 void b_UnlockRes(const char *file, int line);
212 void dump_resource(int type, RES *res, void sendmsg(void *sock, const char *fmt, ...), void *sock);
213 void free_resource(RES *res, int type);
214 void init_resource(int type, RES_ITEM *item);
215 void save_resource(int type, RES_ITEM *item, int pass);
216 const char *res_to_str(int rcode);
217
218 /* Loop through each resource of type, returning in var */
219 #ifdef HAVE_TYPEOF
220 #define foreach_res(var, type) \
221         for((var)=NULL; ((var)=(typeof(var))GetNextRes((type), (RES *)var));)
222 #else
223 #define foreach_res(var, type) \
224     for(var=NULL; (*((void **)&(var))=(void *)GetNextRes((type), (RES *)var));)
225 #endif
226
227
228 /*
229  * Standard global parsers defined in parse_config.c
230  */
231 void store_str(LEX *lc, RES_ITEM *item, int index, int pass);
232 void store_dir(LEX *lc, RES_ITEM *item, int index, int pass);
233 void store_password(LEX *lc, RES_ITEM *item, int index, int pass);
234 void store_name(LEX *lc, RES_ITEM *item, int index, int pass);
235 void store_strname(LEX *lc, RES_ITEM *item, int index, int pass);
236 void store_res(LEX *lc, RES_ITEM *item, int index, int pass);
237 void store_alist_res(LEX *lc, RES_ITEM *item, int index, int pass);
238 void store_alist_str(LEX *lc, RES_ITEM *item, int index, int pass);
239 void store_int32(LEX *lc, RES_ITEM *item, int index, int pass);
240 void store_pint32(LEX *lc, RES_ITEM *item, int index, int pass);
241 void store_msgs(LEX *lc, RES_ITEM *item, int index, int pass);
242 void store_int64(LEX *lc, RES_ITEM *item, int index, int pass);
243 void store_bit(LEX *lc, RES_ITEM *item, int index, int pass);
244 void store_bool(LEX *lc, RES_ITEM *item, int index, int pass);
245 void store_time(LEX *lc, RES_ITEM *item, int index, int pass);
246 void store_size64(LEX *lc, RES_ITEM *item, int index, int pass);
247 void store_size32(LEX *lc, RES_ITEM *item, int index, int pass);
248 void store_speed(LEX *lc, RES_ITEM *item, int index, int pass);
249 void store_defs(LEX *lc, RES_ITEM *item, int index, int pass);
250 void store_label(LEX *lc, RES_ITEM *item, int index, int pass);
251
252 /* ***FIXME*** eliminate these globals */
253 extern int32_t r_first;
254 extern int32_t r_last;
255 extern RES_TABLE resources[];
256 extern RES **res_head;
257 extern int32_t res_all_size;