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