The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
Macros | Functions | Variables
token.c File Reference

Tokenisation code and constants. More...

#include <stdio.h>
#include <freeradius-devel/util/skip.h>
#include <freeradius-devel/util/token.h>
+ Include dependency graph for token.c:

Go to the source code of this file.

Macros

#define T(_x)   [T_OP_ ## _x] = true
 
#define T(_x)   [T_ ## _x] = true
 
#define T(_x)   [T_## _x] = true
 
#define TOKEN_MATCH(bptr, tptr)
 

Functions

fr_token_t fr_token_from_quote_enum_str (char const *s, fr_token_t dflt)
 Look up a quote token by its source-identifier name.
 
char const * fr_token_name (int token)
 
char const * fr_token_to_enum_str (fr_token_t t)
 Return the source-identifier name for a token (e.g.
 
fr_token_t getop (char const **ptr)
 
fr_token_t getstring (char const **ptr, char *buf, int buflen, bool unescape)
 
static fr_token_t getthing (char const **ptr, char *buf, int buflen, bool tok, fr_table_num_ordered_t const *tokenlist, size_t tokenlist_len, bool unescape)
 
fr_token_t gettoken (char const **ptr, char *buf, int buflen, bool unescape)
 
int getword (char const **ptr, char *buf, int buflen, bool unescape)
 

Variables

const bool fr_assignment_op [T_TOKEN_LAST]
 
const bool fr_binary_op [T_TOKEN_LAST]
 
const bool fr_comparison_op [T_TOKEN_LAST]
 
const bool fr_list_assignment_op [T_TOKEN_LAST]
 
const bool fr_str_tok [T_TOKEN_LAST]
 
static fr_table_num_sorted_t const fr_token_from_quote_enum_str_table []
 Quote-token names that radconf2json's JSON output uses.
 
static size_t fr_token_from_quote_enum_str_table_len = NUM_ELEMENTS(fr_token_from_quote_enum_str_table)
 
const char fr_token_quote [T_TOKEN_LAST]
 Convert tokens back to a quoting character.
 
fr_table_num_sorted_t const fr_token_quotes_table []
 
size_t fr_token_quotes_table_len = NUM_ELEMENTS(fr_token_quotes_table)
 
static fr_table_num_indexed_t const fr_token_to_enum_str_table []
 Map each fr_token_t to the C identifier of its enum constant.
 
static size_t fr_token_to_enum_str_table_len = NUM_ELEMENTS(fr_token_to_enum_str_table)
 
char const * fr_tokens [T_TOKEN_LAST]
 
fr_table_num_ordered_t const fr_tokens_table []
 
size_t fr_tokens_table_len = NUM_ELEMENTS(fr_tokens_table)
 

Detailed Description

Tokenisation code and constants.

This is mostly for the attribute filter and user files.

Definition in file token.c.

Macro Definition Documentation

◆ T [1/3]

#define T (   _x)    [T_OP_ ## _x] = true

Definition at line 234 of file token.c.

◆ T [2/3]

#define T (   _x)    [T_ ## _x] = true

Definition at line 234 of file token.c.

◆ T [3/3]

#define T (   _x)    [T_## _x] = true

Definition at line 234 of file token.c.

◆ TOKEN_MATCH

#define TOKEN_MATCH (   bptr,
  tptr 
)
Value:
( (tptr)[0] == (bptr)[0] && \
((tptr)[1] == (bptr)[1] || (tptr)[1] == 0))

Definition at line 310 of file token.c.

Function Documentation

◆ fr_token_from_quote_enum_str()

fr_token_t fr_token_from_quote_enum_str ( char const *  s,
fr_token_t  dflt 
)

Look up a quote token by its source-identifier name.

Inverse of fr_token_to_enum_str restricted to the five quote-typed tokens (T_BARE_WORD, T_DOUBLE_QUOTED_STRING, ...) - the only forms radconf2json emits as lhs_quote / rhs_quote JSON values.

Parameters
[in]senum-identifier name (e.g. "T_DOUBLE_QUOTED_STRING"), or NULL.
[in]dfltvalue to return if s is NULL or unrecognised.
Returns
the matching fr_token_t, or dflt.

Definition at line 137 of file token.c.

◆ fr_token_name()

char const * fr_token_name ( int  token)

Definition at line 579 of file token.c.

+ Here is the caller graph for this function:

◆ fr_token_to_enum_str()

char const * fr_token_to_enum_str ( fr_token_t  t)

Return the source-identifier name for a token (e.g.

"T_BARE_WORD", "T_OP_SET").

Counterpart to fr_tokens[] which returns the operator-character / human-display form (":=", "<BARE-WORD>", ...). Tooling that wants to emit grep-friendly enum identifiers (radconf2json, radmod2json) uses this.

Parameters
[in]ttoken to look up.
Returns
the enum-identifier name, or "T_INVALID" if t is out of range / has no symbolic entry.

Definition at line 117 of file token.c.

◆ getop()

fr_token_t getop ( char const **  ptr)

Definition at line 544 of file token.c.

+ Here is the call graph for this function:

◆ getstring()

fr_token_t getstring ( char const **  ptr,
char *  buf,
int  buflen,
bool  unescape 
)

Definition at line 560 of file token.c.

+ Here is the call graph for this function:

◆ getthing()

static fr_token_t getthing ( char const **  ptr,
char *  buf,
int  buflen,
bool  tok,
fr_table_num_ordered_t const *  tokenlist,
size_t  tokenlist_len,
bool  unescape 
)
static

Definition at line 321 of file token.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ gettoken()

fr_token_t gettoken ( char const **  ptr,
char *  buf,
int  buflen,
bool  unescape 
)

Definition at line 536 of file token.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getword()

int getword ( char const **  ptr,
char *  buf,
int  buflen,
bool  unescape 
)

Definition at line 527 of file token.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ fr_assignment_op

const bool fr_assignment_op[T_TOKEN_LAST]
Initial value:
= {
T(INCRM),
T(ADD_EQ),
T(SUB_EQ),
T(MUL_EQ),
T(DIV_EQ),
T(AND_EQ),
T(OR_EQ),
T(RSHIFT_EQ),
T(LSHIFT_EQ),
T(SET),
T(EQ),
T(PREPEND),
}
#define T(_x)
Definition token.c:234

Definition at line 236 of file token.c.

◆ fr_binary_op

const bool fr_binary_op[T_TOKEN_LAST]
Initial value:
= {
T(ADD),
T(SUB),
T(MUL),
T(DIV),
T(AND),
T(OR),
T(MOD),
T(RSHIFT),
T(LSHIFT),
}
#define MOD(a, b)

Definition at line 284 of file token.c.

◆ fr_comparison_op

const bool fr_comparison_op[T_TOKEN_LAST]
Initial value:
= {
T(NE),
T(GE),
T(GT),
T(LE),
T(LT),
T(REG_EQ),
T(REG_NE),
T(CMP_TRUE),
T(CMP_FALSE),
T(CMP_EQ),
T(CMP_EQ_TYPE),
T(CMP_NE_TYPE),
}

Definition at line 266 of file token.c.

◆ fr_list_assignment_op

const bool fr_list_assignment_op[T_TOKEN_LAST]
Initial value:
= {
T(ADD_EQ),
T(SUB_EQ),
T(AND_EQ),
T(OR_EQ),
T(LE),
T(GE),
T(SET),
T(EQ),
T(PREPEND),
}

Definition at line 253 of file token.c.

◆ fr_str_tok

const bool fr_str_tok[T_TOKEN_LAST]
Initial value:
= {
T(BARE_WORD),
T(DOUBLE_QUOTED_STRING),
T(SINGLE_QUOTED_STRING),
T(BACK_QUOTED_STRING),
}

Definition at line 299 of file token.c.

◆ fr_token_from_quote_enum_str_table

fr_table_num_sorted_t const fr_token_from_quote_enum_str_table[]
static
Initial value:
= {
{ L("T_BACK_QUOTED_STRING"), T_BACK_QUOTED_STRING },
{ L("T_BARE_WORD"), T_BARE_WORD },
{ L("T_DOUBLE_QUOTED_STRING"), T_DOUBLE_QUOTED_STRING },
{ L("T_SINGLE_QUOTED_STRING"), T_SINGLE_QUOTED_STRING },
{ L("T_SOLIDUS_QUOTED_STRING"), T_SOLIDUS_QUOTED_STRING },
}
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:228
@ T_SINGLE_QUOTED_STRING
Definition token.h:120
@ T_BARE_WORD
Definition token.h:118
@ T_BACK_QUOTED_STRING
Definition token.h:121
@ T_DOUBLE_QUOTED_STRING
Definition token.h:119
@ T_SOLIDUS_QUOTED_STRING
Definition token.h:122

Quote-token names that radconf2json's JSON output uses.

Only the five quote-typed tokens, kept sorted by name so the fr_table_value_by_str binary search can find them. Used by radjson2conf when rebuilding a CF tree from JSON.

Definition at line 128 of file token.c.

◆ fr_token_from_quote_enum_str_table_len

size_t fr_token_from_quote_enum_str_table_len = NUM_ELEMENTS(fr_token_from_quote_enum_str_table)
static

Definition at line 135 of file token.c.

◆ fr_token_quote

const char fr_token_quote[T_TOKEN_LAST]
Initial value:
= {
[ 0 ... T_HASH ] = '?',
[T_BARE_WORD] = '\0',
}
@ T_HASH
Definition token.h:117

Convert tokens back to a quoting character.

Non-string types convert to '?' to screw ups can be identified easily

Definition at line 224 of file token.c.

◆ fr_token_quotes_table

fr_table_num_sorted_t const fr_token_quotes_table[]
Initial value:
= {
{ L(""), T_BARE_WORD },
}

Definition at line 68 of file token.c.

◆ fr_token_quotes_table_len

size_t fr_token_quotes_table_len = NUM_ELEMENTS(fr_token_quotes_table)

Definition at line 75 of file token.c.

◆ fr_token_to_enum_str_table

fr_table_num_indexed_t const fr_token_to_enum_str_table[]
static

Map each fr_token_t to the C identifier of its enum constant.

Complement of fr_tokens[] (the operator-character / human-display form like ":=" / "<BARE-WORD>") - this one returns the source-identical T_OP_SET / T_BARE_WORD form so tooling (radconf2json, etc.) can round-trip enum names through a JSON intermediate.

Definition at line 84 of file token.c.

◆ fr_token_to_enum_str_table_len

size_t fr_token_to_enum_str_table_len = NUM_ELEMENTS(fr_token_to_enum_str_table)
static

Definition at line 115 of file token.c.

◆ fr_tokens

char const* fr_tokens[T_TOKEN_LAST]

Definition at line 146 of file token.c.

◆ fr_tokens_table

fr_table_num_ordered_t const fr_tokens_table[]

Definition at line 33 of file token.c.

◆ fr_tokens_table_len

size_t fr_tokens_table_len = NUM_ELEMENTS(fr_tokens_table)

Definition at line 66 of file token.c.