libamxo  4.3.4
Object Definition Language (ODL) parsing
amxo_ftab_resolver.c File Reference
#include "amxo_parser_priv.h"

Go to the source code of this file.

Data Structures

struct  _amxo_ftab_fn
 

Macros

#define _GNU_SOURCE
 

Typedefs

typedef struct _amxo_ftab_fn amxo_ftab_fn_t
 

Functions

static void amxo_resolver_ftab_defaults (amxo_parser_t *parser, UNUSED void *priv)
 
static amxo_fn_ptr_t amxo_resolver_ftab (amxo_parser_t *parser, const char *fn_name, UNUSED amxo_fn_type_t type, const char *data, UNUSED void *priv)
 
static void amxo_resolver_ftab_clean (amxo_parser_t *parser, UNUSED void *priv)
 
static bool amxo_ftab_func_name_is_valid (const char *name)
 
void amxo_ftab_fn_free (UNUSED const char *key, amxc_htable_it_t *it)
 
int amxo_resolver_ftab_add (amxo_parser_t *parser, const char *fn_name, amxo_fn_ptr_t fn)
 Adds a C function to the function table. More...
 
int amxo_resolver_ftab_remove (amxo_parser_t *parser, const char *fn_name)
 Removes a function from the function table. More...
 
void amxo_resolver_ftab_clear (amxo_parser_t *parser)
 Removes all functions from the function table. More...
 
 CONSTRUCTOR_LVL (110)
 
 DESTRUCTOR_LVL (110)
 

Variables

static amxo_resolver_t ftab
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 56 of file amxo_ftab_resolver.c.

Typedef Documentation

◆ amxo_ftab_fn_t

typedef struct _amxo_ftab_fn amxo_ftab_fn_t

Function Documentation

◆ amxo_ftab_fn_free()

void amxo_ftab_fn_free ( UNUSED const char *  key,
amxc_htable_it_t *  it 
)

Definition at line 163 of file amxo_ftab_resolver.c.

164  {
165  amxo_ftab_fn_t* ftab_fn = amxc_htable_it_get_data(it, amxo_ftab_fn_t, hit);
166  free(ftab_fn);
167 }

◆ amxo_ftab_func_name_is_valid()

static bool amxo_ftab_func_name_is_valid ( const char *  name)
static

Definition at line 143 of file amxo_ftab_resolver.c.

143  {
144  bool retval = false;
145  when_str_empty(name, exit);
146  when_true(isalpha(name[0]) == 0 && name[0] != '_', exit);
147 
148  for(int i = 0; name[i] != 0; i++) {
149  if(isalnum(name[i]) == 0) {
150  if((name[i] != '_') && (name[i] != '-') && (name[i] != '.')) {
151  goto exit;
152  }
153  }
154  }
155 
156  retval = true;
157 
158 exit:
159  return retval;
160 }

◆ amxo_resolver_ftab()

static amxo_fn_ptr_t amxo_resolver_ftab ( amxo_parser_t parser,
const char *  fn_name,
UNUSED amxo_fn_type_t  type,
const char *  data,
UNUSED void *  priv 
)
static

Definition at line 97 of file amxo_ftab_resolver.c.

101  {
102  amxo_fn_ptr_t fn = NULL;
103  amxo_ftab_fn_t* ftab_fn = NULL;
104  amxc_htable_t* ftab_data = NULL;
105  amxc_htable_it_t* it = NULL;
106 
107  ftab_data = amxo_parser_get_resolver_data(parser, "ftab");
108  when_null(ftab_data, exit);
109 
110  if((data != NULL) && (data[0] != 0)) {
111  it = amxc_htable_get(ftab_data, data);
112  } else {
113  amxc_string_t full_name;
114  char* path = amxd_object_get_path(parser->object, AMXD_OBJECT_NAMED);
115  amxc_string_init(&full_name, 0);
116  if((path != NULL) && (*path != 0)) {
117  amxc_string_push_buffer(&full_name, path, strlen(path) + 1);
118  amxc_string_appendf(&full_name, ".%s", fn_name);
119  it = amxc_htable_get(ftab_data, amxc_string_get(&full_name, 0));
120  }
121  amxc_string_clean(&full_name);
122  if(it == NULL) {
123  it = amxc_htable_get(ftab_data, fn_name);
124  }
125  }
126  when_null(it, exit);
127 
128  ftab_fn = amxc_htable_it_get_data(it, amxo_ftab_fn_t, hit);
129  fn = ftab_fn->fn;
130 
131 exit:
132  return fn;
133 }
void(* amxo_fn_ptr_t)(void)
Definition: amxo_types.h:71
amxc_htable_t * amxo_parser_get_resolver_data(amxo_parser_t *parser, const char *resolver_name)
Gets the resolver specific parser data.
amxo_fn_ptr_t fn
amxd_object_t * object
Definition: amxo_types.h:262

◆ amxo_resolver_ftab_clean()

static void amxo_resolver_ftab_clean ( amxo_parser_t parser,
UNUSED void *  priv 
)
static

Definition at line 135 of file amxo_ftab_resolver.c.

136  {
137  amxc_htable_t* ftab_data = NULL;
138  ftab_data = amxo_parser_get_resolver_data(parser, "ftab");
139  amxc_htable_clean(ftab_data, amxo_ftab_fn_free);
140  amxo_parser_remove_resolver_data(parser, "ftab");
141 }
void amxo_ftab_fn_free(UNUSED const char *key, amxc_htable_it_t *it)
void amxo_parser_remove_resolver_data(amxo_parser_t *parser, const char *resolver_name)
Removes the resolver specific parser data.

◆ amxo_resolver_ftab_defaults()

static void amxo_resolver_ftab_defaults ( amxo_parser_t parser,
UNUSED void *  priv 
)
static

Definition at line 66 of file amxo_ftab_resolver.c.

67  {
69  "check_minimum",
70  AMXO_FUNC(amxd_action_param_check_minimum));
72  "check_minimum_length",
73  AMXO_FUNC(amxd_action_param_check_minimum));
75  "check_maximum",
76  AMXO_FUNC(amxd_action_param_check_maximum));
78  "check_maximum_length",
79  AMXO_FUNC(amxd_action_param_check_maximum));
81  "check_range",
82  AMXO_FUNC(amxd_action_param_check_range));
84  "check_enum",
85  AMXO_FUNC(amxd_action_param_check_enum));
87  "check_is_in",
88  AMXO_FUNC(amxd_action_param_check_is_in));
90  "hide_value",
91  AMXO_FUNC(amxd_action_param_read_hidden_value));
93  "verify_max_instances",
94  AMXO_FUNC(amxd_action_object_add_inst));
95 }
int amxo_resolver_ftab_add(amxo_parser_t *parser, const char *fn_name, amxo_fn_ptr_t fn)
Adds a C function to the function table.
#define AMXO_FUNC(x)
Function ponter caster macro.
Definition: amxo_types.h:80

◆ CONSTRUCTOR_LVL()

CONSTRUCTOR_LVL ( 110  )

Definition at line 231 of file amxo_ftab_resolver.c.

231  {
232  amxo_register_resolver("ftab", &ftab);
233 }
static amxo_resolver_t ftab
int amxo_register_resolver(const char *name, amxo_resolver_t *resolver)
Registers a function resolver.

◆ DESTRUCTOR_LVL()

DESTRUCTOR_LVL ( 110  )

Definition at line 235 of file amxo_ftab_resolver.c.

235  {
236  amxo_unregister_resolver("ftab");
237 }
int amxo_unregister_resolver(const char *name)
Unregisters a function resolver.

Variable Documentation

◆ ftab

amxo_resolver_t ftab
static
Initial value:
= {
.hit = { .ait = NULL, .key = NULL, .next = NULL },
.resolve = amxo_resolver_ftab,
.priv = NULL
}
static amxo_fn_ptr_t amxo_resolver_ftab(amxo_parser_t *parser, const char *fn_name, UNUSED amxo_fn_type_t type, const char *data, UNUSED void *priv)
static void amxo_resolver_ftab_defaults(amxo_parser_t *parser, UNUSED void *priv)
static void amxo_resolver_ftab_clean(amxo_parser_t *parser, UNUSED void *priv)

Definition at line 223 of file amxo_ftab_resolver.c.