The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Enumerations | Functions
dict_tokenize.c File Reference

Parse dictionary files. More...

#include <freeradius-devel/radius/defs.h>
#include <freeradius-devel/util/conf.h>
#include <freeradius-devel/util/dict_fixup_priv.h>
#include <freeradius-devel/util/file.h>
#include <freeradius-devel/util/rand.h>
#include <freeradius-devel/util/strerror.h>
#include <freeradius-devel/util/syserror.h>
#include <freeradius-devel/util/value.h>
#include <sys/stat.h>
+ Include dependency graph for dict_tokenize.c:

Go to the source code of this file.

Data Structures

struct  dict_tokenize_ctx_t
 
struct  dict_tokenize_frame_t
 

Macros

#define CURRENT_FRAME(_dctx)   (&(_dctx)->stack[(_dctx)->stack_depth])
 
#define MAX_ARGV   (16)
 
#define MAX_STACK   (32)
 Parser context for dict_from_file. More...
 

Enumerations

enum  dict_nest_t {
  NEST_NONE = 0 ,
  NEST_ROOT ,
  NEST_PROTOCOL ,
  NEST_VENDOR ,
  NEST_TLV
}
 

Functions

static int _dict_from_file (dict_tokenize_ctx_t *ctx, char const *dir_name, char const *filename, char const *src_file, int src_line)
 Parse a dictionary file. More...
 
static int dict_finalise (dict_tokenize_ctx_t *ctx)
 
static int dict_from_file (fr_dict_t *dict, char const *dir_name, char const *filename, char const *src_file, int src_line)
 
static dict_tokenize_frame_t const * dict_gctx_find_frame (dict_tokenize_ctx_t *ctx, dict_nest_t nest)
 
static int dict_gctx_push (dict_tokenize_ctx_t *ctx, fr_dict_attr_t const *da)
 
static fr_dict_attr_t const * dict_gctx_unwind (dict_tokenize_ctx_t *ctx)
 
static int dict_process_flag_field (dict_tokenize_ctx_t *ctx, char *name, fr_type_t type, fr_dict_attr_flags_t *flags, char **ref)
 
static int dict_process_ref (dict_tokenize_ctx_t *ctx, fr_dict_attr_t const *parent, fr_dict_attr_t const *da, char *ref)
 
static int dict_process_type_field (dict_tokenize_ctx_t *ctx, char const *name, fr_type_t *type_p, fr_dict_attr_flags_t *flags)
 
static int dict_read_parse_format (char const *format, int *ptype, int *plength, bool *pcontinuation)
 
static int dict_read_process_alias (dict_tokenize_ctx_t *ctx, char **argv, int argc)
 
static int dict_read_process_attribute (dict_tokenize_ctx_t *ctx, char **argv, int argc, fr_dict_attr_flags_t const *base_flags)
 
static int dict_read_process_define (dict_tokenize_ctx_t *ctx, char **argv, int argc, fr_dict_attr_flags_t const *base_flags)
 
static int dict_read_process_enum (dict_tokenize_ctx_t *ctx, char **argv, int argc, fr_dict_attr_flags_t const *base_flags)
 
static int dict_read_process_flags (UNUSED fr_dict_t *dict, char **argv, int argc, fr_dict_attr_flags_t *base_flags)
 
static int dict_read_process_include (dict_tokenize_ctx_t *ctx, char **argv, int argc, char const *dir, char *fn, int line)
 
static int dict_read_process_member (dict_tokenize_ctx_t *ctx, char **argv, int argc, fr_dict_attr_flags_t const *base_flags)
 
static int dict_read_process_protocol (char **argv, int argc)
 Register the specified dictionary as a protocol dictionary. More...
 
static int dict_read_process_struct (dict_tokenize_ctx_t *ctx, char **argv, int argc)
 Process a STRUCT name attr value. More...
 
static int dict_read_process_value (dict_tokenize_ctx_t *ctx, char **argv, int argc)
 Process a value alias. More...
 
static int dict_read_process_vendor (fr_dict_t *dict, char **argv, int argc)
 
static int dict_read_sscanf_i (unsigned int *pvalue, char const *str)
 
static int dict_root_set (fr_dict_t *dict, char const *name, unsigned int proto_number)
 Set a new root dictionary attribute. More...
 
fr_dict_tfr_dict_alloc (char const *proto_name, unsigned int proto_number)
 
int fr_dict_internal_afrom_file (fr_dict_t **out, char const *dict_subdir, char const *dependent)
 (Re-)Initialize the special internal dictionary More...
 
int fr_dict_parse_str (fr_dict_t *dict, char *buf, fr_dict_attr_t const *parent)
 
int fr_dict_protocol_afrom_file (fr_dict_t **out, char const *proto_name, char const *proto_dir, char const *dependent)
 (Re)-initialize a protocol dictionary More...
 
int fr_dict_read (fr_dict_t *dict, char const *dir, char const *filename)
 Read supplementary attribute definitions into an existing dictionary. More...
 
int fr_dict_str_to_argv (char *str, char **argv, int max_argc)
 

Detailed Description

Parse dictionary files.

Definition in file dict_tokenize.c.


Data Structure Documentation

◆ dict_tokenize_ctx_t

struct dict_tokenize_ctx_t

Definition at line 61 of file dict_tokenize.c.

+ Collaboration diagram for dict_tokenize_ctx_t:
Data Fields
fr_dict_t * dict Protocol dictionary we're inserting attributes into.
dict_fixup_ctx_t fixup
fr_dict_attr_t const * relative_attr for ".82" instead of "1.2.3.82".

only for parents of type "tlv"

dict_tokenize_frame_t stack[MAX_STACK] stack of attributes to track
int stack_depth points to the last used stack frame
fr_dict_attr_t * value_attr Cache of last attribute to speed up value processing.

◆ dict_tokenize_frame_t

struct dict_tokenize_frame_t

Definition at line 51 of file dict_tokenize.c.

+ Collaboration diagram for dict_tokenize_frame_t:
Data Fields
fr_dict_attr_t const * da the da we care about
fr_dict_t * dict The dictionary before the current BEGIN-PROTOCOL block.
char * filename name of the file we're reading
int line line number of this file
int member_num structure member numbers
dict_nest_t nest for manual vs automatic begin / end things
ssize_t struct_size size of the struct.

Macro Definition Documentation

◆ CURRENT_FRAME

#define CURRENT_FRAME (   _dctx)    (&(_dctx)->stack[(_dctx)->stack_depth])

Definition at line 74 of file dict_tokenize.c.

◆ MAX_ARGV

#define MAX_ARGV   (16)

Definition at line 36 of file dict_tokenize.c.

◆ MAX_STACK

#define MAX_STACK   (32)

Parser context for dict_from_file.

Allows vendor and TLV context to persist across $INCLUDEs

Definition at line 50 of file dict_tokenize.c.

Enumeration Type Documentation

◆ dict_nest_t

Enumerator
NEST_NONE 
NEST_ROOT 
NEST_PROTOCOL 
NEST_VENDOR 
NEST_TLV 

Definition at line 38 of file dict_tokenize.c.

Function Documentation

◆ _dict_from_file()

static int _dict_from_file ( dict_tokenize_ctx_t ctx,
char const *  dir_name,
char const *  filename,
char const *  src_file,
int  src_line 
)
static

Parse a dictionary file.

Parameters
[in]ctxContains the current state of the dictionary parser. Used to track what PROTOCOL, VENDOR or TLV block we're in. Block context changes in $INCLUDEs should not affect the context of the including file.
[in]dir_nameDirectory containing the dictionary we're loading.
[in]filenamewe're parsing.
[in]src_fileThe including file.
[in]src_lineLine on which the $INCLUDE or $NCLUDE- statement was found.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 2016 of file dict_tokenize.c.

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

◆ dict_finalise()

static int dict_finalise ( dict_tokenize_ctx_t ctx)
static

Definition at line 1992 of file dict_tokenize.c.

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

◆ dict_from_file()

static int dict_from_file ( fr_dict_t dict,
char const *  dir_name,
char const *  filename,
char const *  src_file,
int  src_line 
)
static

Definition at line 2706 of file dict_tokenize.c.

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

◆ dict_gctx_find_frame()

static dict_tokenize_frame_t const* dict_gctx_find_frame ( dict_tokenize_ctx_t ctx,
dict_nest_t  nest 
)
static

Definition at line 644 of file dict_tokenize.c.

+ Here is the caller graph for this function:

◆ dict_gctx_push()

static int dict_gctx_push ( dict_tokenize_ctx_t ctx,
fr_dict_attr_t const *  da 
)
static

Definition at line 656 of file dict_tokenize.c.

+ Here is the caller graph for this function:

◆ dict_gctx_unwind()

static fr_dict_attr_t const* dict_gctx_unwind ( dict_tokenize_ctx_t ctx)
static

Definition at line 674 of file dict_tokenize.c.

+ Here is the caller graph for this function:

◆ dict_process_flag_field()

static int dict_process_flag_field ( dict_tokenize_ctx_t ctx,
char *  name,
fr_type_t  type,
fr_dict_attr_flags_t flags,
char **  ref 
)
static

Definition at line 298 of file dict_tokenize.c.

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

◆ dict_process_ref()

static int dict_process_ref ( dict_tokenize_ctx_t ctx,
fr_dict_attr_t const *  parent,
fr_dict_attr_t const *  da,
char *  ref 
)
static

Definition at line 775 of file dict_tokenize.c.

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

◆ dict_process_type_field()

static int dict_process_type_field ( dict_tokenize_ctx_t ctx,
char const *  name,
fr_type_t type_p,
fr_dict_attr_flags_t flags 
)
static

Definition at line 186 of file dict_tokenize.c.

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

◆ dict_read_parse_format()

static int dict_read_parse_format ( char const *  format,
int *  ptype,
int *  plength,
bool pcontinuation 
)
static

Definition at line 1734 of file dict_tokenize.c.

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

◆ dict_read_process_alias()

static int dict_read_process_alias ( dict_tokenize_ctx_t ctx,
char **  argv,
int  argc 
)
static

Definition at line 692 of file dict_tokenize.c.

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

◆ dict_read_process_attribute()

static int dict_read_process_attribute ( dict_tokenize_ctx_t ctx,
char **  argv,
int  argc,
fr_dict_attr_flags_t const *  base_flags 
)
static

Definition at line 848 of file dict_tokenize.c.

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

◆ dict_read_process_define()

static int dict_read_process_define ( dict_tokenize_ctx_t ctx,
char **  argv,
int  argc,
fr_dict_attr_flags_t const *  base_flags 
)
static

Definition at line 1010 of file dict_tokenize.c.

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

◆ dict_read_process_enum()

static int dict_read_process_enum ( dict_tokenize_ctx_t ctx,
char **  argv,
int  argc,
fr_dict_attr_flags_t const *  base_flags 
)
static

Definition at line 1120 of file dict_tokenize.c.

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

◆ dict_read_process_flags()

static int dict_read_process_flags ( UNUSED fr_dict_t dict,
char **  argv,
int  argc,
fr_dict_attr_flags_t base_flags 
)
static

Definition at line 1579 of file dict_tokenize.c.

+ Here is the caller graph for this function:

◆ dict_read_process_include()

static int dict_read_process_include ( dict_tokenize_ctx_t ctx,
char **  argv,
int  argc,
char const *  dir,
char *  fn,
int  line 
)
static

Definition at line 1216 of file dict_tokenize.c.

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

◆ dict_read_process_member()

static int dict_read_process_member ( dict_tokenize_ctx_t ctx,
char **  argv,
int  argc,
fr_dict_attr_flags_t const *  base_flags 
)
static

Definition at line 1284 of file dict_tokenize.c.

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

◆ dict_read_process_protocol()

static int dict_read_process_protocol ( char **  argv,
int  argc 
)
static

Register the specified dictionary as a protocol dictionary.

Allows vendor and TLV context to persist across $INCLUDEs

Definition at line 1801 of file dict_tokenize.c.

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

◆ dict_read_process_struct()

static int dict_read_process_struct ( dict_tokenize_ctx_t ctx,
char **  argv,
int  argc 
)
static

Process a STRUCT name attr value.

Define struct 'name' when key 'attr' has 'value'.

Which MUST be a sub-structure of another struct

Definition at line 1610 of file dict_tokenize.c.

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

◆ dict_read_process_value()

static int dict_read_process_value ( dict_tokenize_ctx_t ctx,
char **  argv,
int  argc 
)
static

Process a value alias.

Definition at line 1486 of file dict_tokenize.c.

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

◆ dict_read_process_vendor()

static int dict_read_process_vendor ( fr_dict_t dict,
char **  argv,
int  argc 
)
static

Definition at line 1944 of file dict_tokenize.c.

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

◆ dict_read_sscanf_i()

static int dict_read_sscanf_i ( unsigned int *  pvalue,
char const *  str 
)
static

Definition at line 117 of file dict_tokenize.c.

+ Here is the caller graph for this function:

◆ dict_root_set()

static int dict_root_set ( fr_dict_t dict,
char const *  name,
unsigned int  proto_number 
)
static

Set a new root dictionary attribute.

Note
Must only be called once per dictionary.
Parameters
[in]dictto modify.
[in]nameof dictionary root.
[in]proto_numberThe artificial (or IANA allocated) number for the protocol. This is only used for
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 160 of file dict_tokenize.c.

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

◆ fr_dict_alloc()

fr_dict_t* fr_dict_alloc ( char const *  proto_name,
unsigned int  proto_number 
)

Definition at line 2997 of file dict_tokenize.c.

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

◆ fr_dict_internal_afrom_file()

int fr_dict_internal_afrom_file ( fr_dict_t **  out,
char const *  dict_subdir,
char const *  dependent 
)

(Re-)Initialize the special internal dictionary

This dictionary has additional programmatically generated attributes added to it, and is checked in addition to the protocol specific dictionaries.

Note
The dictionary pointer returned in out must have its reference counter decremented with fr_dict_free when no longer used.
Parameters
[out]outWhere to write pointer to the internal dictionary.
[in]dict_subdirname of the internal dictionary dir (may be NULL).
[in]dependentEither C src file, or another dictionary.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 2751 of file dict_tokenize.c.

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

◆ fr_dict_parse_str()

int fr_dict_parse_str ( fr_dict_t dict,
char *  buf,
fr_dict_attr_t const *  parent 
)

Definition at line 3052 of file dict_tokenize.c.

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

◆ fr_dict_protocol_afrom_file()

int fr_dict_protocol_afrom_file ( fr_dict_t **  out,
char const *  proto_name,
char const *  proto_dir,
char const *  dependent 
)

(Re)-initialize a protocol dictionary

Initialize the directory, then fix the attr number of all attributes.

Parameters
[out]outWhere to write a pointer to the new dictionary. Will free existing dictionary if files have changed and *out is not NULL.
[in]proto_namethat we're loading the dictionary for.
[in]proto_dirExplicitly set where to hunt for the dictionary files. May be NULL.
[in]dependentEither C src file, or another dictionary.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 2888 of file dict_tokenize.c.

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

◆ fr_dict_read()

int fr_dict_read ( fr_dict_t dict,
char const *  dir,
char const *  filename 
)

Read supplementary attribute definitions into an existing dictionary.

Parameters
[in]dictExisting dictionary.
[in]dirdictionary is located in.
[in]filenameof the dictionary.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 3032 of file dict_tokenize.c.

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

◆ fr_dict_str_to_argv()

int fr_dict_str_to_argv ( char *  str,
char **  argv,
int  max_argc 
)

Definition at line 80 of file dict_tokenize.c.

+ Here is the caller graph for this function: