The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
token.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17 
18 /** Tokenisation code and constants
19  *
20  * This is mostly for the attribute filter and user files.
21  *
22  * @file src/lib/util/token.h
23  *
24  * @copyright 2001,2006 The FreeRADIUS server project
25  */
26 RCSIDH(token_h, "$Id: 068b34d09657a9312968e0aae7baf9dc2bbbb5a3 $")
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <freeradius-devel/build.h>
33 #include <freeradius-devel/missing.h>
34 #include <freeradius-devel/util/table.h>
35 #include <stdbool.h>
36 #include <stdint.h>
37 
38 typedef enum fr_token {
39  T_INVALID = 0, /* invalid token */
40  T_EOL, /* end of line */
41  T_LCBRACE, /* { */
42  T_RCBRACE, /* } */
43  T_LBRACE, /* ( */
44  T_RBRACE, /* ) */
45  T_COMMA, /* , */
46  T_SEMICOLON, /* ; */
47 
48  /*
49  * Binary operations
50  */
51  T_ADD, /* + */
52  T_SUB, /* - */
53  T_MUL, /* * */
54  T_DIV, /* / */
55  T_AND, /* & */
56  T_OR, /* | */
57  T_NOT, /* ! */
58  T_XOR, /* ^ */
59  T_COMPLEMENT, /* ~ */
60  T_MOD, /* % */
61 
62  T_RSHIFT, /* >> */
63  T_LSHIFT, /* << */
64 
65  /*
66  * Assignment operators associated with binary
67  * operations.
68  */
69  T_OP_ADD_EQ, /* += */
70  T_OP_SUB_EQ, /* -= */
71  T_OP_MUL_EQ, /* *= */
72  T_OP_DIV_EQ, /* /= */
73  T_OP_OR_EQ, /* |= */
74  T_OP_AND_EQ, /* &= */
75 
76  T_OP_RSHIFT_EQ, /* >>= */
77  T_OP_LSHIFT_EQ, /* <<= */
78 
79  /*
80  * Assignment operators associated with
81  * other operations.
82  */
83  T_OP_EQ, /* = */
84  T_OP_SET, /* := */
85  T_OP_PREPEND, /* ^= */
86 #define T_OP_XOR_EQ T_OP_PREPEND
87 
88  /*
89  * Logical / short-circuit operators.
90  */
91  T_LAND, /* && */
92  T_LOR, /* || */
93 
94  /*
95  * Comparison operators.
96  */
97  T_OP_NE, /* != */
98  T_OP_GE, /* >= */
99  T_OP_GT, /* > */
100  T_OP_LE, /* <= */
101  T_OP_LT, /* < */
102  T_OP_REG_EQ, /* =~ */
103  T_OP_REG_NE, /* !~ */
104  T_OP_CMP_TRUE, /* =* */
105  T_OP_CMP_FALSE, /* !* */
106  T_OP_CMP_EQ, /* == */
107  T_OP_CMP_EQ_TYPE, /* === */
108  T_OP_CMP_NE_TYPE, /* !== */
109 
110  /*
111  * Only used by LDAP ???
112  */
113  T_OP_INCRM, /* ++ */
114 
115  /*
116  * T_HASH MUST be after all of various assignment
117  * operators. See fr_token_quote[].
118  */
119  T_HASH, /* # */
120  T_BARE_WORD, /* bare word */
123  T_BACK_QUOTED_STRING, /* `foo` */
126 /*
127  * This must be manually updated, and is never part of the ENUM.
128  */
129 #define T_TOKEN_LAST (T_SOLIDUS_QUOTED_STRING + 1)
130 
131 #define T_EQSTART T_OP_ADD_EQ
132 #define T_EQEND (T_HASH)
133 
134 /** Macro to use as dflt
135  *
136  */
137 #define FR_TABLE_NOT_FOUND INT32_MIN
138 
140 extern size_t fr_tokens_table_len;
142 extern size_t fr_token_quotes_table_len;
143 extern const char *fr_tokens[T_TOKEN_LAST];
144 extern const char fr_token_quote[T_TOKEN_LAST];
145 extern const bool fr_assignment_op[T_TOKEN_LAST];
146 extern const bool fr_comparison_op[T_TOKEN_LAST];
147 extern const bool fr_binary_op[T_TOKEN_LAST];
148 extern const bool fr_str_tok[T_TOKEN_LAST];
149 extern const bool fr_list_assignment_op[T_TOKEN_LAST];
150 
151 int getword (char const **ptr, char *buf, int buflen, bool unescape);
152 fr_token_t gettoken(char const **ptr, char *buf, int buflen, bool unescape);
153 fr_token_t getop(char const **ptr);
154 fr_token_t getstring(char const **ptr, char *buf, int buflen, bool unescape);
155 char const *fr_token_name(int);
156 ssize_t fr_skip_string(char const *start, char const *end);
157 
158 #ifdef __cplusplus
159 }
160 #endif
#define RCSIDH(h, id)
Definition: build.h:445
long int ssize_t
Definition: merged_model.c:24
An element in an arbitrarily ordered array of name to num mappings.
Definition: table.h:53
An element in a lexicographically sorted array of name to num mappings.
Definition: table.h:45
const bool fr_assignment_op[T_TOKEN_LAST]
Definition: token.c:168
enum fr_token fr_token_t
const bool fr_list_assignment_op[T_TOKEN_LAST]
Definition: token.c:185
const char * fr_tokens[T_TOKEN_LAST]
Definition: token.c:78
fr_token
Definition: token.h:38
@ T_AND
Definition: token.h:55
@ T_OP_SUB_EQ
Definition: token.h:70
@ T_INVALID
Definition: token.h:39
@ T_SUB
Definition: token.h:52
@ T_RSHIFT
Definition: token.h:62
@ T_RCBRACE
Definition: token.h:42
@ T_NOT
Definition: token.h:57
@ T_OP_DIV_EQ
Definition: token.h:72
@ T_XOR
Definition: token.h:58
@ T_RBRACE
Definition: token.h:44
@ T_EOL
Definition: token.h:40
@ T_SEMICOLON
Definition: token.h:46
@ T_DIV
Definition: token.h:54
@ T_SINGLE_QUOTED_STRING
Definition: token.h:122
@ T_MOD
Definition: token.h:60
@ T_OP_AND_EQ
Definition: token.h:74
@ T_OP_CMP_TRUE
Definition: token.h:104
@ T_BARE_WORD
Definition: token.h:120
@ T_OP_EQ
Definition: token.h:83
@ T_OP_MUL_EQ
Definition: token.h:71
@ T_LAND
Definition: token.h:91
@ T_COMPLEMENT
Definition: token.h:59
@ T_ADD
Definition: token.h:51
@ T_BACK_QUOTED_STRING
Definition: token.h:123
@ T_HASH
Definition: token.h:119
@ T_OP_SET
Definition: token.h:84
@ T_OP_NE
Definition: token.h:97
@ T_OP_ADD_EQ
Definition: token.h:69
@ T_OP_CMP_FALSE
Definition: token.h:105
@ T_OP_LSHIFT_EQ
Definition: token.h:77
@ T_LOR
Definition: token.h:92
@ T_LCBRACE
Definition: token.h:41
@ T_LSHIFT
Definition: token.h:63
@ T_OP_RSHIFT_EQ
Definition: token.h:76
@ T_OP_REG_EQ
Definition: token.h:102
@ T_OP_CMP_EQ_TYPE
Definition: token.h:107
@ T_DOUBLE_QUOTED_STRING
Definition: token.h:121
@ T_OP_CMP_EQ
Definition: token.h:106
@ T_OP_INCRM
Definition: token.h:113
@ T_LBRACE
Definition: token.h:43
@ T_MUL
Definition: token.h:53
@ T_OP_LE
Definition: token.h:100
@ T_OP_CMP_NE_TYPE
Definition: token.h:108
@ T_OP_GE
Definition: token.h:98
@ T_OP_GT
Definition: token.h:99
@ T_OP_OR_EQ
Definition: token.h:73
@ T_SOLIDUS_QUOTED_STRING
Definition: token.h:124
@ T_OP_LT
Definition: token.h:101
@ T_OP_REG_NE
Definition: token.h:103
@ T_COMMA
Definition: token.h:45
@ T_OR
Definition: token.h:56
@ T_OP_PREPEND
Definition: token.h:85
ssize_t fr_skip_string(char const *start, char const *end)
Skip a quoted string.
Definition: token.c:504
fr_token_t gettoken(char const **ptr, char *buf, int buflen, bool unescape)
Definition: token.c:447
fr_table_num_ordered_t const fr_tokens_table[]
Definition: token.c:33
char const * fr_token_name(int)
Definition: token.c:490
const bool fr_str_tok[T_TOKEN_LAST]
Definition: token.c:231
fr_table_num_sorted_t const fr_token_quotes_table[]
Definition: token.c:66
size_t fr_token_quotes_table_len
Definition: token.c:73
size_t fr_tokens_table_len
Definition: token.c:64
fr_token_t getop(char const **ptr)
Definition: token.c:455
#define T_TOKEN_LAST
Definition: token.h:129
const char fr_token_quote[T_TOKEN_LAST]
Convert tokens back to a quoting character.
Definition: token.c:156
fr_token_t getstring(char const **ptr, char *buf, int buflen, bool unescape)
Definition: token.c:471
int getword(char const **ptr, char *buf, int buflen, bool unescape)
Definition: token.c:438
const bool fr_comparison_op[T_TOKEN_LAST]
Definition: token.c:198
const bool fr_binary_op[T_TOKEN_LAST]
Definition: token.c:216