]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/lex.h
Big backport from Enterprise
[bacula/bacula] / bacula / src / lib / lex.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  *   lex.h
21  *
22  *    Lexical scanning of configuration files, used by parsers.
23  *
24  *   Kern Sibbald, MM
25  *
26  */
27
28 #ifndef _LEX_H
29 #define _LEX_H
30
31 /* Lex get_char() return values */
32 #define L_EOF                         (-1)
33 #define L_EOL                         (-2)
34
35 /* Internal tokens */
36 #define T_NONE                        100
37
38 /* Tokens returned by get_token() */
39 #define T_EOF                         101
40 #define T_NUMBER                      102
41 #define T_IPADDR                      103
42 #define T_IDENTIFIER                  104
43 #define T_UNQUOTED_STRING             105
44 #define T_QUOTED_STRING               106
45 #define T_BOB                         108  /* begin block */
46 #define T_EOB                         109  /* end of block */
47 #define T_EQUALS                      110
48 #define T_COMMA                       111
49 #define T_EOL                         112
50 #define T_ERROR                       200
51 #define T_UTF8_BOM                    201 /* File starts with a UTF-8 BOM*/
52 #define T_UTF16_BOM                   202 /* File starts with a UTF-16LE BOM*/
53
54 /*
55  * The following will be returned only if
56  * the appropriate expect flag has been set
57  */
58 #define T_SKIP_EOL                    113  /* scan through EOLs */
59 #define T_PINT32                      114  /* positive integer */
60 #define T_PINT32_RANGE                115  /* positive integer range */
61 #define T_INT32                       116  /* integer */
62 #define T_INT64                       117  /* 64 bit integer */
63 #define T_NAME                        118  /* name max 128 chars */
64 #define T_STRING                      119  /* string */
65 #define T_PINT64_RANGE                120  /* positive integer range */
66 #define T_PINT64                      121  /* positive integer range */
67
68 #define T_ALL                           0  /* no expectations */
69
70 /* Lexical state */
71 enum lex_state {
72    lex_none,
73    lex_comment,
74    lex_number,
75    lex_ip_addr,
76    lex_identifier,
77    lex_string,
78    lex_quoted_string,
79    lex_include_quoted_string,
80    lex_include,
81    lex_utf8_bom,      /* we are parsing out a utf8 byte order mark */
82    lex_utf16_le_bom   /* we are parsing out a utf-16 (little endian) byte order mark */
83 };
84
85 /* Lex scan options */
86 #define LOPT_NO_IDENT            0x1  /* No Identifiers -- use string */
87 #define LOPT_STRING              0x2  /* Force scan for string */
88 #define LOPT_NO_EXTERN           0x4  /* Don't follow @ command */
89 #define LOPT_NO_MD5              0x8  /* Do not encode passwords with MD5 */
90
91 class BPIPE;                          /* forward reference */
92
93 /* Lexical context */
94 typedef struct s_lex_context {
95    struct s_lex_context *next;        /* pointer to next lexical context */
96    int options;                       /* scan options */
97    char *fname;                       /* filename */
98    FILE *fd;                          /* file descriptor */
99    POOLMEM *line;                     /* input line */
100    POOLMEM *str;                      /* string being scanned */
101    int str_len;                       /* length of string */
102    int line_no;                       /* file line number */
103    int col_no;                        /* char position on line */
104    int begin_line_no;                 /* line no of beginning of string */
105    enum lex_state state;              /* lex_state variable */
106    int ch;                            /* last char/L_VAL returned by get_char */
107    int token;
108    uint32_t pint32_val;
109    uint32_t pint32_val2;
110    int32_t int32_val;
111    int64_t int64_val;
112    uint64_t pint64_val;
113    uint64_t pint64_val2;
114    void (*scan_error)(const char *file, int line, struct s_lex_context *lc, const char *msg, ...);
115    int err_type;                      /* message level for scan_error (M_..) */
116    void *caller_ctx;                  /* caller private data */
117    BPIPE *bpipe;                      /* set if we are piping */
118 } LEX;
119
120 typedef void (LEX_ERROR_HANDLER)(const char *file, int line, LEX *lc, const char *msg, ...);
121
122 /* Lexical scanning errors in parsing conf files */
123 #define scan_err0(lc, msg) lc->scan_error(__FILE__, __LINE__, lc, msg)
124 #define scan_err1(lc, msg, a1) lc->scan_error(__FILE__, __LINE__, lc, msg, a1)
125 #define scan_err2(lc, msg, a1, a2) lc->scan_error(__FILE__, __LINE__, lc, msg, a1, a2)
126 #define scan_err3(lc, msg, a1, a2, a3) lc->scan_error(__FILE__, __LINE__, lc, msg, a1, a2, a3)
127 #define scan_err4(lc, msg, a1, a2, a3, a4) lc->scan_error(__FILE__, __LINE__, lc, msg, a1, a2, a3, a4)
128 #define scan_err5(lc, msg, a1, a2, a3, a4, a5) lc->scan_error(__FILE__, __LINE__, lc, msg, a1, a2, a3, a4, a5)
129 #define scan_err6(lc, msg, a1, a2, a3, a4, a5, a6) lc->scan_error(__FILE__, __LINE__, lc, msg, a1, a2, a3, a4, a5, a6)
130
131 void scan_to_eol(LEX *lc);
132 int scan_to_next_not_eol(LEX * lc);
133 void lex_store_clear_passwords(LEX *lf);
134
135 #endif /* _LEX_H */