The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
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 */
26RCSIDH(token_h, "$Id: e828d220aae8ee33fec51da5c3503b27da3dde87 $")
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#include <freeradius-devel/build.h>
33#include <freeradius-devel/missing.h>
34#include <freeradius-devel/util/table.h>
35
36typedef enum fr_token {
37 T_INVALID = 0, /* invalid token */
38 T_EOL, /* end of line */
39 T_LCBRACE, /* { */
40 T_RCBRACE, /* } */
41 T_LBRACE, /* ( */
42 T_RBRACE, /* ) */
43 T_COMMA, /* , */
44 T_SEMICOLON, /* ; */
45
46 /*
47 * Binary operations
48 */
49 T_ADD, /* + */
50 T_SUB, /* - */
51 T_MUL, /* * */
52 T_DIV, /* / */
53 T_AND, /* & */
54 T_OR, /* | */
55 T_NOT, /* ! */
56 T_XOR, /* ^ */
57 T_COMPLEMENT, /* ~ */
58 T_MOD, /* % */
59
60 T_RSHIFT, /* >> */
61 T_LSHIFT, /* << */
62
63 /*
64 * Assignment operators associated with binary
65 * operations.
66 */
67 T_OP_ADD_EQ, /* += */
68 T_OP_SUB_EQ, /* -= */
69 T_OP_MUL_EQ, /* *= */
70 T_OP_DIV_EQ, /* /= */
71 T_OP_OR_EQ, /* |= */
72 T_OP_AND_EQ, /* &= */
73
74 T_OP_RSHIFT_EQ, /* >>= */
75 T_OP_LSHIFT_EQ, /* <<= */
76
77 /*
78 * Assignment operators associated with
79 * other operations.
80 */
81 T_OP_EQ, /* = */
82 T_OP_SET, /* := */
83 T_OP_PREPEND, /* ^= */
84#define T_OP_XOR_EQ T_OP_PREPEND
85
86 /*
87 * Logical / short-circuit operators.
88 */
89 T_LAND, /* && */
90 T_LOR, /* || */
91
92 /*
93 * Comparison operators.
94 */
95 T_OP_NE, /* != */
96 T_OP_GE, /* >= */
97 T_OP_GT, /* > */
98 T_OP_LE, /* <= */
99 T_OP_LT, /* < */
100 T_OP_REG_EQ, /* =~ */
101 T_OP_REG_NE, /* !~ */
104 T_OP_CMP_EQ, /* == */
107
108 /*
109 * Unary calc operator.
110 */
111 T_OP_INCRM, /* ++ */
112
113 /*
114 * T_HASH MUST be after all of various assignment
115 * operators. See fr_token_quote[].
116 */
117 T_HASH, /* # */
118 T_BARE_WORD, /* bare word */
124/*
125 * This must be manually updated, and is never part of the ENUM.
126 */
127#define T_TOKEN_LAST (T_SOLIDUS_QUOTED_STRING + 1)
128
129#define T_EQSTART T_OP_ADD_EQ
130#define T_EQEND (T_HASH)
131
132/** Macro to use as dflt
133 *
134 */
135#define FR_TABLE_NOT_FOUND INT32_MIN
136
138extern size_t fr_tokens_table_len;
140extern size_t fr_token_quotes_table_len;
141extern const char *fr_tokens[T_TOKEN_LAST];
142extern const char fr_token_quote[T_TOKEN_LAST];
143extern const bool fr_assignment_op[T_TOKEN_LAST];
144extern const bool fr_comparison_op[T_TOKEN_LAST];
145extern const bool fr_binary_op[T_TOKEN_LAST];
146extern const bool fr_str_tok[T_TOKEN_LAST];
147extern const bool fr_list_assignment_op[T_TOKEN_LAST];
148
149int getword (char const **ptr, char *buf, int buflen, bool unescape);
150fr_token_t gettoken(char const **ptr, char *buf, int buflen, bool unescape);
151fr_token_t getop(char const **ptr);
152fr_token_t getstring(char const **ptr, char *buf, int buflen, bool unescape);
153char const *fr_token_name(int);
154
155#ifdef __cplusplus
156}
157#endif
#define RCSIDH(h, id)
Definition build.h:507
An element in an arbitrarily ordered array of name to num mappings.
Definition table.h:57
An element in a lexicographically sorted array of name to num mappings.
Definition table.h:49
const bool fr_assignment_op[T_TOKEN_LAST]
Definition token.c:170
enum fr_token fr_token_t
const bool fr_list_assignment_op[T_TOKEN_LAST]
Definition token.c:187
const char * fr_tokens[T_TOKEN_LAST]
Definition token.c:80
fr_token
Definition token.h:36
@ T_AND
Definition token.h:53
@ T_OP_SUB_EQ
Definition token.h:68
@ T_INVALID
Definition token.h:37
@ T_SUB
Definition token.h:50
@ T_RSHIFT
Definition token.h:60
@ T_RCBRACE
Definition token.h:40
@ T_NOT
Definition token.h:55
@ T_OP_DIV_EQ
Definition token.h:70
@ T_XOR
Definition token.h:56
@ T_RBRACE
Definition token.h:42
@ T_EOL
Definition token.h:38
@ T_SEMICOLON
Definition token.h:44
@ T_DIV
Definition token.h:52
@ T_SINGLE_QUOTED_STRING
Definition token.h:120
@ T_MOD
Definition token.h:58
@ T_OP_AND_EQ
Definition token.h:72
@ T_OP_CMP_TRUE
Definition token.h:102
@ T_BARE_WORD
Definition token.h:118
@ T_OP_EQ
Definition token.h:81
@ T_OP_MUL_EQ
Definition token.h:69
@ T_LAND
Definition token.h:89
@ T_COMPLEMENT
Definition token.h:57
@ T_ADD
Definition token.h:49
@ T_BACK_QUOTED_STRING
Definition token.h:121
@ T_HASH
Definition token.h:117
@ T_OP_SET
Definition token.h:82
@ T_OP_NE
Definition token.h:95
@ T_OP_ADD_EQ
Definition token.h:67
@ T_OP_CMP_FALSE
Definition token.h:103
@ T_OP_LSHIFT_EQ
Definition token.h:75
@ T_LOR
Definition token.h:90
@ T_LCBRACE
Definition token.h:39
@ T_LSHIFT
Definition token.h:61
@ T_OP_RSHIFT_EQ
Definition token.h:74
@ T_OP_REG_EQ
Definition token.h:100
@ T_OP_CMP_EQ_TYPE
Definition token.h:105
@ T_DOUBLE_QUOTED_STRING
Definition token.h:119
@ T_OP_CMP_EQ
Definition token.h:104
@ T_OP_INCRM
Definition token.h:111
@ T_LBRACE
Definition token.h:41
@ T_MUL
Definition token.h:51
@ T_OP_LE
Definition token.h:98
@ T_OP_CMP_NE_TYPE
Definition token.h:106
@ T_OP_GE
Definition token.h:96
@ T_OP_GT
Definition token.h:97
@ T_OP_OR_EQ
Definition token.h:71
@ T_SOLIDUS_QUOTED_STRING
Definition token.h:122
@ T_OP_LT
Definition token.h:99
@ T_OP_REG_NE
Definition token.h:101
@ T_COMMA
Definition token.h:43
@ T_OR
Definition token.h:54
@ T_OP_PREPEND
Definition token.h:83
char const * fr_token_name(int)
Definition token.c:513
fr_token_t gettoken(char const **ptr, char *buf, int buflen, bool unescape)
Definition token.c:470
fr_table_num_ordered_t const fr_tokens_table[]
Definition token.c:33
const bool fr_str_tok[T_TOKEN_LAST]
Definition token.c:233
fr_table_num_sorted_t const fr_token_quotes_table[]
Definition token.c:68
size_t fr_token_quotes_table_len
Definition token.c:75
size_t fr_tokens_table_len
Definition token.c:66
fr_token_t getop(char const **ptr)
Definition token.c:478
#define T_TOKEN_LAST
Definition token.h:127
const char fr_token_quote[T_TOKEN_LAST]
Convert tokens back to a quoting character.
Definition token.c:158
fr_token_t getstring(char const **ptr, char *buf, int buflen, bool unescape)
Definition token.c:494
int getword(char const **ptr, char *buf, int buflen, bool unescape)
Definition token.c:461
const bool fr_comparison_op[T_TOKEN_LAST]
Definition token.c:200
const bool fr_binary_op[T_TOKEN_LAST]
Definition token.c:218