1 /*
2  *   This program is free software; you can redistribute it and/or modify
3  *   it under the terms of the GNU General Public License as published by
4  *   the Free Software Foundation; either version 2 of the License, or
5  *   (at your option) any later version.
6  *
7  *   This program is distributed in the hope that it will be useful,
8  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *   GNU General Public License for more details.
11  *
12  *   You should have received a copy of the GNU General Public License
13  *   along with this program; if not, write to the Free Software
14  *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15  */
16 #ifndef FR_TOKEN_H
17 #define FR_TOKEN_H
18 
19 /**
20  * $Id: c8bb748702f1f90cfb550ea10c23a99ffd88ff40 $
21  *
22  * @file token.h
23  * @brief Tokenisation code and constants.
24  *
25  * @copyright 2001,2006  The FreeRADIUS server project
26  */
27 
28 RCSIDH(token_h, "$Id: c8bb748702f1f90cfb550ea10c23a99ffd88ff40 $")
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 typedef enum fr_token_t {
35 	T_INVALID = 0,			/* invalid token */
36 	T_EOL,				/* end of line */
37 	T_LCBRACE,			/* { */
38 	T_RCBRACE,			/* } */
39 	T_LBRACE,			/* ( */
40 	T_RBRACE,			/* ) 		 5 */
41 	T_COMMA,			/* , */
42 	T_SEMICOLON,			/* ; */
43 
44 	T_OP_INCRM,			/* ++ */
45 	T_OP_ADD,			/* += */
46 	T_OP_SUB,			/* -=  		10 */
47 	T_OP_SET,			/* := */
48 	T_OP_EQ,			/* = */
49 	T_OP_NE,			/* != */
50 	T_OP_GE,			/* >= */
51 	T_OP_GT,			/* > 		15 */
52 	T_OP_LE,			/* <= */
53 	T_OP_LT,			/* < */
54 	T_OP_REG_EQ,			/* =~ */
55 	T_OP_REG_NE,			/* !~ */
56 	T_OP_CMP_TRUE,			/* =* 		20 */
57 	T_OP_CMP_FALSE,			/* !* */
58 	T_OP_CMP_EQ,			/* == */
59 	T_OP_PREPEND,			/* ^= */
60 	T_HASH,				/* # */
61 	T_BARE_WORD,			/* bare word    25 */
62 	T_DOUBLE_QUOTED_STRING,		/* "foo" */
63 	T_SINGLE_QUOTED_STRING,		/* 'foo' */
64 	T_BACK_QUOTED_STRING,		/* `foo` */
65 	T_TOKEN_LAST
66 } FR_TOKEN;
67 
68 #define T_EQSTART	T_OP_ADD
69 #define	T_EQEND		(T_OP_PREPEND + 1)
70 
71 typedef struct FR_NAME_NUMBER {
72 	char const	*name;
73 	int		number;
74 } FR_NAME_NUMBER;
75 
76 extern const FR_NAME_NUMBER fr_tokens[];
77 extern const bool fr_assignment_op[];
78 extern const bool fr_equality_op[];
79 extern const bool fr_str_tok[];
80 
81 int fr_str2int(FR_NAME_NUMBER const *table, char const *name, int def);
82 int fr_substr2int(FR_NAME_NUMBER const *table, char const *name, int def, int len);
83 char const *fr_int2str(FR_NAME_NUMBER const *table, int number, char const *def);
84 
85 int		getword (char const **ptr, char *buf, int buflen, bool unescape);
86 FR_TOKEN	gettoken(char const **ptr, char *buf, int buflen, bool unescape);
87 FR_TOKEN	getop(char const **ptr);
88 FR_TOKEN	getstring(char const **ptr, char *buf, int buflen, bool unescape);
89 char const	*fr_token_name(int);
90 
91 #ifdef __cplusplus
92 }
93 #endif
94 
95 #endif /* FR_TOKEN_H */
96