]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/parse_conf.h
99d61ee3694e1f6feb28d062e04584cbc3ee86e1
[bacula/bacula] / bacula / src / lib / parse_conf.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2000-2008 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 and included
11    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 Kern Sibbald.
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 struct RES_ITEM2;                  /* Declare forward referenced structure */
38 class RES;                         /* Declare forware referenced structure */
39 typedef void (MSG_RES_HANDLER)(LEX *lc, RES_ITEM *item, int index, int pass);
40 typedef void (INC_RES_HANDLER)(LEX *lc, RES_ITEM2 *item, int index, int pass, bool exclude);
41
42
43
44 /* This is the structure that defines
45  * the record types (items) permitted within each
46  * resource. It is used to define the configuration
47  * tables.
48  */
49 struct RES_ITEM {
50    const char *name;                  /* Resource name i.e. Director, ... */
51    MSG_RES_HANDLER *handler;          /* Routine storing the resource item */
52    union {
53       char **value;                   /* Where to store the item */
54       char **charvalue;
55       uint32_t ui32value;
56       int32_t i32value;
57       uint64_t ui64value;
58       int64_t i64value;
59       bool boolvalue;
60       utime_t utimevalue;
61       RES *resvalue;
62       RES **presvalue;
63    };
64    int32_t  code;                     /* item code/additional info */
65    uint32_t  flags;                   /* flags: default, required, ... */
66    int32_t  default_value;            /* default value */
67 };
68
69 struct RES_ITEM2 {
70    const char *name;                  /* Resource name i.e. Director, ... */
71    INC_RES_HANDLER *handler;          /* Routine storing the resource item */
72    union {
73       char **value;                   /* Where to store the item */
74       char **charvalue;
75       uint32_t ui32value;
76       int32_t i32value;
77       uint64_t ui64value;
78       int64_t i64value;
79       bool boolvalue;
80       utime_t utimevalue;
81       RES *resvalue;
82       RES **presvalue;
83    };
84    int32_t  code;                     /* item code/additional info */
85    uint32_t  flags;                   /* flags: default, required, ... */
86    int32_t  default_value;            /* default value */
87 };
88
89
90 /* For storing name_addr items in res_items table */
91 #define ITEM(x) {(char **)&res_all.x}
92
93 #define MAX_RES_ITEMS 80              /* maximum resource items per RES */
94
95 /* This is the universal header that is
96  * at the beginning of every resource
97  * record.
98  */
99 class RES {
100 public:
101    RES *next;                         /* pointer to next resource of this type */
102    char *name;                        /* resource name */
103    char *desc;                        /* resource description */
104    uint32_t rcode;                    /* resource id or type */
105    int32_t  refcnt;                   /* reference count for releasing */
106    char  item_present[MAX_RES_ITEMS]; /* set if item is present in conf file */
107 };
108
109
110 /*
111  * Master Resource configuration structure definition
112  * This is the structure that defines the
113  * resources that are available to this daemon.
114  */
115 struct RES_TABLE {
116    const char *name;                  /* resource name */
117    RES_ITEM *items;                   /* list of resource keywords */
118    uint32_t rcode;                    /* code if needed */
119 };
120
121
122
123 /* Common Resource definitions */
124
125 #define MAX_RES_NAME_LENGTH MAX_NAME_LENGTH-1       /* maximum resource name length */
126
127 #define ITEM_REQUIRED    0x1          /* item required */
128 #define ITEM_DEFAULT     0x2          /* default supplied */
129 #define ITEM_NO_EQUALS   0x4          /* Don't scan = after name */
130
131 /* Message Resource */
132 class MSGS {
133 public:
134    RES   hdr;
135    char *mail_cmd;                    /* mail command */
136    char *operator_cmd;                /* Operator command */
137    DEST *dest_chain;                  /* chain of destinations */
138    char send_msg[nbytes_for_bits(M_MAX+1)];  /* bit array of types */
139
140    /* Methods */
141    char *name() const;
142 };
143
144 inline char *MSGS::name() const { return hdr.name; }
145
146 /* 
147  * Old C style configuration routines -- deprecated do not use.
148  */
149 //int   parse_config(const char *cf, LEX_ERROR_HANDLER *scan_error = NULL, int err_type=M_ERROR_TERM);
150 void    free_config_resources(void);
151 RES   **save_config_resources(void);
152 RES   **new_res_head();
153
154 /*
155  * New C++ configuration routines
156  */
157
158 class CONFIG {
159 public:
160    const char *m_cf;                   /* config file */
161    LEX_ERROR_HANDLER *m_scan_error;    /* error handler if non-null */
162    int32_t m_err_type;                 /* the way to terminate on failure */
163    void *m_res_all;                    /* pointer to res_all buffer */
164    int32_t m_res_all_size;             /* length of buffer */
165
166    /* The below are not yet implemented */
167    int32_t m_r_first;                  /* first daemon resource type */
168    int32_t m_r_last;                   /* last daemon resource type */
169    RES_TABLE *m_resources;             /* pointer to table of permitted resources */      
170    RES **m_res_head;                   /* pointer to defined resources */
171    brwlock_t m_res_lock;               /* resource lock */
172
173    /* functions */
174    void init(
175       const char *cf,
176       LEX_ERROR_HANDLER *scan_error,
177       int32_t err_type,
178       void *vres_all,
179       int32_t res_all_size,
180       int32_t r_first,
181       int32_t r_last,
182       RES_TABLE *resources,
183       RES **res_head);
184
185    bool parse_config();
186    void free_resources();
187    RES **save_resources();
188    RES **new_res_head();
189 };
190  
191 CONFIG *new_config_parser();
192
193
194 /* Resource routines */
195 RES *GetResWithName(int rcode, const char *name);
196 RES *GetNextRes(int rcode, RES *res);
197 void b_LockRes(const char *file, int line);
198 void b_UnlockRes(const char *file, int line);
199 void dump_resource(int type, RES *res, void sendmsg(void *sock, const char *fmt, ...), void *sock);
200 void free_resource(RES *res, int type);
201 void init_resource(int type, RES_ITEM *item);
202 void save_resource(int type, RES_ITEM *item, int pass);
203 const char *res_to_str(int rcode);
204
205 /* Loop through each resource of type, returning in var */
206 #ifdef HAVE_TYPEOF
207 #define foreach_res(var, type) \
208         for((var)=NULL; ((var)=(typeof(var))GetNextRes((type), (RES *)var));)
209 #else 
210 #define foreach_res(var, type) \
211     for(var=NULL; (*((void **)&(var))=(void *)GetNextRes((type), (RES *)var));)
212 #endif
213
214
215 /*
216  * Standard global parsers defined in parse_config.c
217  */
218 void store_str(LEX *lc, RES_ITEM *item, int index, int pass);
219 void store_dir(LEX *lc, RES_ITEM *item, int index, int pass);
220 void store_password(LEX *lc, RES_ITEM *item, int index, int pass);
221 void store_name(LEX *lc, RES_ITEM *item, int index, int pass);
222 void store_strname(LEX *lc, RES_ITEM *item, int index, int pass);
223 void store_res(LEX *lc, RES_ITEM *item, int index, int pass);
224 void store_alist_res(LEX *lc, RES_ITEM *item, int index, int pass);
225 void store_alist_str(LEX *lc, RES_ITEM *item, int index, int pass);
226 void store_int32(LEX *lc, RES_ITEM *item, int index, int pass);
227 void store_pint32(LEX *lc, RES_ITEM *item, int index, int pass);
228 void store_msgs(LEX *lc, RES_ITEM *item, int index, int pass);
229 void store_int64(LEX *lc, RES_ITEM *item, int index, int pass);
230 void store_bit(LEX *lc, RES_ITEM *item, int index, int pass);
231 void store_bool(LEX *lc, RES_ITEM *item, int index, int pass);
232 void store_time(LEX *lc, RES_ITEM *item, int index, int pass);
233 void store_size(LEX *lc, RES_ITEM *item, int index, int pass);
234 void store_defs(LEX *lc, RES_ITEM *item, int index, int pass);
235 void store_label(LEX *lc, RES_ITEM *item, int index, int pass);
236
237 /* ***FIXME*** eliminate these globals */
238 extern int32_t r_first;
239 extern int32_t r_last;
240 extern RES_TABLE resources[];
241 extern RES **res_head;
242 extern int32_t res_all_size;