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