Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions | Variables
res/ari/config.c File Reference

Config framework stuffz for ARI. More...

#include "asterisk.h"
#include "asterisk/config_options.h"
#include "asterisk/http_websocket.h"
#include "asterisk/app.h"
#include "asterisk/channel.h"
#include "internal.h"
Include dependency graph for res/ari/config.c:

Go to the source code of this file.

Macros

#define CONF_FILENAME   "ari.conf"
 
#define MAX_VARS   128
 

Functions

static AO2_GLOBAL_OBJ_STATIC (confs)
 Locking container for safe configuration access. More...
 
void ast_ari_config_destroy (void)
 Destroy the ARI configuration. More...
 
struct ast_ari_confast_ari_config_get (void)
 Get the current ARI configuration. More...
 
int ast_ari_config_init (void)
 Initialize the ARI configuration. More...
 
int ast_ari_config_reload (void)
 Reload the ARI configuration. More...
 
struct ast_ari_conf_userast_ari_config_validate_user (const char *username, const char *password)
 Validated a user's credentials. More...
 
static int channelvars_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static void * conf_alloc (void)
 Allocate an ast_ari_conf for config parsing. More...
 
static void conf_destructor (void *obj)
 ast_ari_conf destructor. More...
 
static void conf_general_dtor (void *obj)
 
 CONFIG_INFO_STANDARD (cfg_info, confs, conf_alloc,.files=ACO_FILES(&conf_file))
 
static int encoding_format_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Encoding format handler converts from boolean to enum. More...
 
static int password_format_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 Parses the ast_ari_password_format enum from a config file. More...
 
static int process_config (int reload)
 Load (or reload) configuration. More...
 
static void * user_alloc (const char *cat)
 Allocate an ast_ari_conf_user for config parsing. More...
 
static void user_dtor (void *obj)
 Destructor for ast_ari_conf_user. More...
 
static void * user_find (struct ao2_container *tmp_container, const char *cat)
 aco_type item_find function More...
 
static int user_sort_cmp (const void *obj_left, const void *obj_right, int flags)
 Sorting function for use with red/black tree. More...
 
static int validate_user_cb (void *obj, void *arg, int flags)
 Callback to validate a user object. More...
 

Variables

static struct aco_file conf_file
 The conf file that's processed for the module. More...
 
static struct aco_type general_option
 Mapping of the ARI conf struct's globals to the general context in the config file. More...
 
static struct aco_typegeneral_options [] = ACO_TYPES(&general_option)
 
static struct aco_typeglobal_user [] = ACO_TYPES(&user_option)
 
static struct aco_type user_option
 

Detailed Description

Config framework stuffz for ARI.

Author
David M. Lee, II dlee@.nosp@m.digi.nosp@m.um.co.nosp@m.m

Definition in file res/ari/config.c.

Macro Definition Documentation

◆ CONF_FILENAME

#define CONF_FILENAME   "ari.conf"

Definition at line 214 of file res/ari/config.c.

Referenced by ast_ari_config_get().

◆ MAX_VARS

#define MAX_VARS   128

Definition at line 321 of file res/ari/config.c.

Referenced by channelvars_handler().

Function Documentation

◆ AO2_GLOBAL_OBJ_STATIC()

static AO2_GLOBAL_OBJ_STATIC ( confs  )
static

Locking container for safe configuration access.

◆ ast_ari_config_destroy()

void ast_ari_config_destroy ( void  )

Destroy the ARI configuration.

Definition at line 383 of file res/ari/config.c.

References aco_info_destroy(), and ao2_global_obj_release.

Referenced by unload_module().

384 {
385  aco_info_destroy(&cfg_info);
387 }
void aco_info_destroy(struct aco_info *info)
Destroy an initialized aco_info struct.
#define ao2_global_obj_release(holder)
Definition: astobj2.h:865

◆ ast_ari_config_get()

struct ast_ari_conf* ast_ari_config_get ( void  )

Get the current ARI configuration.

This is an immutable object, so don't modify it. It is AO2 managed, so ao2_cleanup() when you're done with it.

Returns
ARI configuration object.
NULL on error.

Definition at line 227 of file res/ari/config.c.

References ao2_global_obj_ref, ast_log, CONF_FILENAME, and LOG_ERROR.

Referenced by ari_show(), ari_show_user(), ari_show_users(), ast_ari_callback(), ast_ari_config_validate_user(), ast_ari_json_format(), ast_ari_websocket_session_create(), complete_ari_user(), is_enabled(), origin_allowed(), and process_config().

228 {
229  struct ast_ari_conf *res = ao2_global_obj_ref(confs);
230  if (!res) {
232  "Error obtaining config from " CONF_FILENAME "\n");
233  }
234  return res;
235 }
All configuration options for ARI.
Definition: internal.h:54
#define ao2_global_obj_ref(holder)
Definition: astobj2.h:925
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
#define CONF_FILENAME

◆ ast_ari_config_init()

int ast_ari_config_init ( void  )

Initialize the ARI configuration.

Definition at line 337 of file res/ari/config.c.

References ACO_EXACT, aco_info_destroy(), aco_info_init(), aco_option_register, aco_option_register_custom, ARI_AUTH_REALM_LEN, ARI_PASSWORD_LEN, AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT_STR, channelvars_handler(), enabled, encoding_format_handler(), FLDSET, NULL, OPT_BOOL_T, OPT_CHAR_ARRAY_T, OPT_INT_T, OPT_NOOP_T, OPT_STRINGFIELD_T, PARSE_IN_RANGE, password, password_format_handler(), process_config(), ast_ari_conf_user::read_only, and STRFLDSET.

Referenced by load_module().

338 {
339  if (aco_info_init(&cfg_info)) {
340  aco_info_destroy(&cfg_info);
341  return -1;
342  }
343 
344  /* ARI general category options */
345  aco_option_register(&cfg_info, "enabled", ACO_EXACT, general_options,
346  "yes", OPT_BOOL_T, 1,
348  aco_option_register_custom(&cfg_info, "pretty", ACO_EXACT,
350  aco_option_register(&cfg_info, "auth_realm", ACO_EXACT, general_options,
351  "Asterisk REST Interface", OPT_CHAR_ARRAY_T, 0,
352  FLDSET(struct ast_ari_conf_general, auth_realm),
354  aco_option_register(&cfg_info, "allowed_origins", ACO_EXACT, general_options,
355  "", OPT_STRINGFIELD_T, 0,
356  STRFLDSET(struct ast_ari_conf_general, allowed_origins));
357  aco_option_register(&cfg_info, "websocket_write_timeout", ACO_EXACT, general_options,
359  FLDSET(struct ast_ari_conf_general, write_timeout), 1, INT_MAX);
360  aco_option_register_custom(&cfg_info, "channelvars", ACO_EXACT, general_options,
361  "", channelvars_handler, 0);
362 
363  /* ARI type=user category options */
364  aco_option_register(&cfg_info, "type", ACO_EXACT, global_user, NULL,
365  OPT_NOOP_T, 0, 0);
366  aco_option_register(&cfg_info, "read_only", ACO_EXACT, global_user,
367  "no", OPT_BOOL_T, 1,
368  FLDSET(struct ast_ari_conf_user, read_only));
369  aco_option_register(&cfg_info, "password", ACO_EXACT, global_user,
370  "", OPT_CHAR_ARRAY_T, 0,
372  aco_option_register_custom(&cfg_info, "password_format", ACO_EXACT,
373  global_user, "plain", password_format_handler, 0);
374 
375  return process_config(0);
376 }
static int password_format_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Parses the ast_ari_password_format enum from a config file.
#define aco_option_register_custom(info, name, matchtype, types, default_val, handler, flags)
Register a config option.
static struct aco_type * general_options[]
#define aco_option_register(info, name, matchtype, types, default_val, opt_type, flags,...)
Register a config option.
static int process_config(int reload)
Load (or reload) configuration.
#define ARI_PASSWORD_LEN
User's password mx length.
Definition: internal.h:93
Type for a default handler that should do nothing.
#define NULL
Definition: resample.c:96
static struct ast_str * password
Definition: cdr_mysql.c:77
Type for default option handler for character array strings.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
Global configuration options for ARI.
Definition: internal.h:65
static int channelvars_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
int aco_info_init(struct aco_info *info)
Initialize an aco_info structure.
#define ARI_AUTH_REALM_LEN
Definition: internal.h:62
Per-user configuration options.
Definition: internal.h:96
void aco_info_destroy(struct aco_info *info)
Destroy an initialized aco_info struct.
Type for default option handler for bools (ast_true/ast_false)
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
#define AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT_STR
Default websocket write timeout, in ms (as a string)
Type for default option handler for stringfields.
Type for default option handler for signed integers.
static int encoding_format_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Encoding format handler converts from boolean to enum.
static struct aco_type * global_user[]
static int enabled
Definition: dnsmgr.c:91

◆ ast_ari_config_reload()

int ast_ari_config_reload ( void  )

Reload the ARI configuration.

Definition at line 378 of file res/ari/config.c.

References process_config().

Referenced by reload_module().

379 {
380  return process_config(1);
381 }
static int process_config(int reload)
Load (or reload) configuration.

◆ ast_ari_config_validate_user()

struct ast_ari_conf_user* ast_ari_config_validate_user ( const char *  username,
const char *  password 
)

Validated a user's credentials.

Parameters
usernameName of the user.
passwordUser's password.
Returns
User object.
NULL if username or password is invalid.

Definition at line 237 of file res/ari/config.c.

References ao2_cleanup, ao2_find, ao2_ref, ARI_PASSWORD_FORMAT_CRYPT, ARI_PASSWORD_FORMAT_PLAIN, ast_ari_config_get(), ast_crypt_validate(), ast_log, ast_strlen_zero, LOG_WARNING, NULL, OBJ_SEARCH_KEY, RAII_VAR, and user.

Referenced by authenticate_api_key(), and authenticate_user().

239 {
242  int is_valid = 0;
243 
245  if (!conf) {
246  return NULL;
247  }
248 
249  user = ao2_find(conf->users, username, OBJ_SEARCH_KEY);
250  if (!user) {
251  return NULL;
252  }
253 
254  if (ast_strlen_zero(user->password)) {
256  "User '%s' missing password; authentication failed\n",
257  user->username);
258  return NULL;
259  }
260 
261  switch (user->password_format) {
263  is_valid = strcmp(password, user->password) == 0;
264  break;
266  is_valid = ast_crypt_validate(password, user->password);
267  break;
268  }
269 
270  if (!is_valid) {
271  return NULL;
272  }
273 
274  ao2_ref(user, +1);
275  return user;
276 }
static char user[512]
struct ast_ari_conf * ast_ari_config_get(void)
Get the current ARI configuration.
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
#define LOG_WARNING
Definition: logger.h:274
All configuration options for ARI.
Definition: internal.h:54
Plaintext password.
Definition: internal.h:83
#define NULL
Definition: resample.c:96
static struct ast_str * password
Definition: cdr_mysql.c:77
#define ast_strlen_zero(foo)
Definition: strings.h:52
All configuration options for statsd client.
Definition: res_statsd.c:95
#define ast_log
Definition: astobj2.c:42
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ao2_ref(o, delta)
Definition: astobj2.h:464
Per-user configuration options.
Definition: internal.h:96
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
structure to hold users read from users.conf
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
int ast_crypt_validate(const char *key, const char *expected)
Asterisk wrapper around crypt(3) for validating passwords.
Definition: crypt.c:136

◆ channelvars_handler()

static int channelvars_handler ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
)
static

Definition at line 323 of file res/ari/config.c.

References args, AST_APP_ARG, ast_channel_set_ari_vars(), AST_DECLARE_APP_ARGS, AST_STANDARD_APP_ARGS, ast_strdupa, MAX_VARS, NULL, parse(), and ast_variable::value.

Referenced by ast_ari_config_init().

324 {
325  char *parse = NULL;
327  AST_APP_ARG(vars)[MAX_VARS];
328  );
329 
330  parse = ast_strdupa(var->value);
331  AST_STANDARD_APP_ARGS(args, parse);
332 
333  ast_channel_set_ari_vars(args.argc, args.vars);
334  return 0;
335 }
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
const char * args
#define NULL
Definition: resample.c:96
void ast_channel_set_ari_vars(size_t varc, char **vars)
Sets the variables to be stored in the ari_vars field of all snapshots.
Definition: channel.c:7994
#define MAX_VARS
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1872
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ conf_alloc()

static void* conf_alloc ( void  )
static

Allocate an ast_ari_conf for config parsing.

Definition at line 187 of file res/ari/config.c.

References aco_set_defaults(), AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, AO2_CONTAINER_ALLOC_OPT_DUPS_REPLACE, ao2_container_alloc_rbtree, ao2_ref, ast_string_field_init, conf_destructor(), conf_general_dtor(), ast_ari_conf::general, NULL, user_sort_cmp(), and ast_ari_conf::users.

188 {
189  struct ast_ari_conf *cfg;
190 
191  cfg = ao2_alloc_options(sizeof(*cfg), conf_destructor,
193  if (!cfg) {
194  return NULL;
195  }
196 
197  cfg->general = ao2_alloc_options(sizeof(*cfg->general), conf_general_dtor,
199 
202 
203  if (!cfg->users
204  || !cfg->general
205  || ast_string_field_init(cfg->general, 64)
206  || aco_set_defaults(&general_option, "general", cfg->general)) {
207  ao2_ref(cfg, -1);
208  return NULL;
209  }
210 
211  return cfg;
212 }
static struct aco_type general_option
Mapping of the ARI conf struct's globals to the general context in the config file.
struct ast_ari_conf_general * general
Definition: internal.h:56
All configuration options for ARI.
Definition: internal.h:54
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
#define NULL
Definition: resample.c:96
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static int user_sort_cmp(const void *obj_left, const void *obj_right, int flags)
Sorting function for use with red/black tree.
int aco_set_defaults(struct aco_type *type, const char *category, void *obj)
Set all default options of obj.
Replace objects with duplicate keys in container.
Definition: astobj2.h:1215
#define ao2_container_alloc_rbtree(ao2_options, container_options, sort_fn, cmp_fn)
Definition: astobj2.h:1358
static void conf_destructor(void *obj)
ast_ari_conf destructor.
static void conf_general_dtor(void *obj)
struct ao2_container * users
Definition: internal.h:58

◆ conf_destructor()

static void conf_destructor ( void *  obj)
static

ast_ari_conf destructor.

Definition at line 178 of file res/ari/config.c.

References ao2_cleanup, ast_ari_conf::general, and ast_ari_conf::users.

Referenced by conf_alloc().

179 {
180  struct ast_ari_conf *cfg = obj;
181 
182  ao2_cleanup(cfg->general);
183  ao2_cleanup(cfg->users);
184 }
struct ast_ari_conf_general * general
Definition: internal.h:56
All configuration options for ARI.
Definition: internal.h:54
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct ao2_container * users
Definition: internal.h:58

◆ conf_general_dtor()

static void conf_general_dtor ( void *  obj)
static

Definition at line 170 of file res/ari/config.c.

References ast_string_field_free_memory.

Referenced by conf_alloc().

171 {
172  struct ast_ari_conf_general *general = obj;
173 
175 }
Global configuration options for ARI.
Definition: internal.h:65
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:368

◆ CONFIG_INFO_STANDARD()

CONFIG_INFO_STANDARD ( cfg_info  ,
confs  ,
conf_alloc  ,
files = ACO_FILES(&conf_file) 
)

◆ encoding_format_handler()

static int encoding_format_handler ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
)
static

Encoding format handler converts from boolean to enum.

Definition at line 49 of file res/ari/config.c.

References AST_JSON_COMPACT, AST_JSON_PRETTY, ast_true(), ast_ari_conf_general::format, ast_variable::name, and ast_variable::value.

Referenced by ast_ari_config_init().

51 {
52  struct ast_ari_conf_general *general = obj;
53 
54  if (!strcasecmp(var->name, "pretty")) {
55  general->format = ast_true(var->value) ?
57  } else {
58  return -1;
59  }
60 
61  return 0;
62 }
Global configuration options for ARI.
Definition: internal.h:65
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: main/utils.c:1951
enum ast_json_encoding_format format
Definition: internal.h:71

◆ password_format_handler()

static int password_format_handler ( const struct aco_option opt,
struct ast_variable var,
void *  obj 
)
static

Parses the ast_ari_password_format enum from a config file.

Definition at line 65 of file res/ari/config.c.

References ARI_PASSWORD_FORMAT_CRYPT, ARI_PASSWORD_FORMAT_PLAIN, ast_ari_conf_user::password_format, and ast_variable::value.

Referenced by ast_ari_config_init().

67 {
68  struct ast_ari_conf_user *user = obj;
69 
70  if (strcasecmp(var->value, "plain") == 0) {
72  } else if (strcasecmp(var->value, "crypt") == 0) {
74  } else {
75  return -1;
76  }
77 
78  return 0;
79 }
Plaintext password.
Definition: internal.h:83
Per-user configuration options.
Definition: internal.h:96
structure to hold users read from users.conf
enum ast_ari_password_format password_format
Definition: internal.h:102

◆ process_config()

static int process_config ( int  reload)
static

Load (or reload) configuration.

Definition at line 292 of file res/ari/config.c.

References aco_process_config(), ACO_PROCESS_ERROR, ACO_PROCESS_OK, ACO_PROCESS_UNCHANGED, ao2_callback, ao2_cleanup, ao2_container_count(), ast_ari_config_get(), ast_assert, ast_log, LOG_ERROR, NULL, OBJ_NODATA, RAII_VAR, and validate_user_cb().

Referenced by ast_ari_config_init(), and ast_ari_config_reload().

293 {
295 
296  switch (aco_process_config(&cfg_info, reload)) {
297  case ACO_PROCESS_ERROR:
298  return -1;
299  case ACO_PROCESS_OK:
301  break;
302  }
303 
305  if (!conf) {
306  ast_assert(0); /* We just configured; it should be there */
307  return -1;
308  }
309 
310  if (conf->general->enabled) {
311  if (ao2_container_count(conf->users) == 0) {
312  ast_log(LOG_ERROR, "No configured users for ARI\n");
313  } else {
315  }
316  }
317 
318  return 0;
319 }
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
struct ast_ari_conf * ast_ari_config_get(void)
Get the current ARI configuration.
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
All configuration options for ARI.
Definition: internal.h:54
enum aco_process_status aco_process_config(struct aco_info *info, int reload)
Process a config info via the options registered with an aco_info.
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
All configuration options for statsd client.
Definition: res_statsd.c:95
#define ast_log
Definition: astobj2.c:42
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
The config had not been edited and no changes applied.
Their was an error and no changes were applied.
#define LOG_ERROR
Definition: logger.h:285
static int validate_user_cb(void *obj, void *arg, int flags)
Callback to validate a user object.
static int reload(void)
Definition: cdr_mysql.c:741
The config was processed and applied.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ user_alloc()

static void* user_alloc ( const char *  cat)
static

Allocate an ast_ari_conf_user for config parsing.

Definition at line 90 of file res/ari/config.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_cleanup, ao2_ref, ast_debug, ast_strdup, NULL, RAII_VAR, user, and user_dtor().

91 {
93 
94  if (!cat) {
95  return NULL;
96  }
97 
98  ast_debug(3, "Allocating user %s\n", cat);
99 
100  user = ao2_alloc_options(sizeof(*user), user_dtor,
102  if (!user) {
103  return NULL;
104  }
105 
106  user->username = ast_strdup(cat);
107  if (!user->username) {
108  return NULL;
109  }
110 
111  ao2_ref(user, +1);
112  return user;
113 }
static char user[512]
static void user_dtor(void *obj)
Destructor for ast_ari_conf_user.
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ao2_ref(o, delta)
Definition: astobj2.h:464
Per-user configuration options.
Definition: internal.h:96
structure to hold users read from users.conf
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ user_dtor()

static void user_dtor ( void *  obj)
static

Destructor for ast_ari_conf_user.

Definition at line 82 of file res/ari/config.c.

References ast_debug, ast_free, and ast_ari_conf_user::username.

Referenced by user_alloc().

83 {
84  struct ast_ari_conf_user *user = obj;
85  ast_debug(3, "Disposing of user %s\n", user->username);
86  ast_free(user->username);
87 }
char * username
Definition: internal.h:98
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
Per-user configuration options.
Definition: internal.h:96
#define ast_free(a)
Definition: astmm.h:182
structure to hold users read from users.conf

◆ user_find()

static void* user_find ( struct ao2_container tmp_container,
const char *  cat 
)
static

aco_type item_find function

Definition at line 147 of file res/ari/config.c.

References ao2_find, NULL, and OBJ_SEARCH_KEY.

148 {
149  if (!cat) {
150  return NULL;
151  }
152 
153  return ao2_find(tmp_container, cat, OBJ_SEARCH_KEY);
154 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
#define NULL
Definition: resample.c:96
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756

◆ user_sort_cmp()

static int user_sort_cmp ( const void *  obj_left,
const void *  obj_right,
int  flags 
)
static

Sorting function for use with red/black tree.

Definition at line 116 of file res/ari/config.c.

References ast_assert, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, OBJ_SEARCH_PARTIAL_KEY, and ast_ari_conf_user::username.

Referenced by conf_alloc().

117 {
118  const struct ast_ari_conf_user *user_left = obj_left;
119  const struct ast_ari_conf_user *user_right = obj_right;
120  const char *key_right = obj_right;
121  int cmp;
122 
123  switch (flags & OBJ_SEARCH_MASK) {
124  case OBJ_SEARCH_OBJECT:
125  key_right = user_right->username;
126  /* Fall through */
127  case OBJ_SEARCH_KEY:
128  cmp = strcasecmp(user_left->username, key_right);
129  break;
131  /*
132  * We could also use a partial key struct containing a length
133  * so strlen() does not get called for every comparison instead.
134  */
135  cmp = strncasecmp(user_left->username, key_right, strlen(key_right));
136  break;
137  default:
138  /* Sort can only work on something with a full or partial key. */
139  ast_assert(0);
140  cmp = 0;
141  break;
142  }
143  return cmp;
144 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
char * username
Definition: internal.h:98
#define ast_assert(a)
Definition: utils.h:695
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition: astobj2.h:1120
Per-user configuration options.
Definition: internal.h:96
The arg parameter is an object of the same type.
Definition: astobj2.h:1091
Search option field mask.
Definition: astobj2.h:1076

◆ validate_user_cb()

static int validate_user_cb ( void *  obj,
void *  arg,
int  flags 
)
static

Callback to validate a user object.

Definition at line 279 of file res/ari/config.c.

References ast_log, ast_strlen_zero, LOG_WARNING, ast_ari_conf_user::password, and ast_ari_conf_user::username.

Referenced by process_config().

280 {
281  struct ast_ari_conf_user *user = obj;
282 
283  if (ast_strlen_zero(user->password)) {
284  ast_log(LOG_WARNING, "User '%s' missing password\n",
285  user->username);
286  }
287 
288  return 0;
289 }
#define LOG_WARNING
Definition: logger.h:274
char * username
Definition: internal.h:98
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
Per-user configuration options.
Definition: internal.h:96
char password[ARI_PASSWORD_LEN]
Definition: internal.h:100
structure to hold users read from users.conf

Variable Documentation

◆ conf_file

struct aco_file conf_file
static

The conf file that's processed for the module.

Definition at line 217 of file res/ari/config.c.

◆ general_option

struct aco_type general_option
static

Mapping of the ARI conf struct's globals to the general context in the config file.

Definition at line 38 of file res/ari/config.c.

◆ general_options

struct aco_type* general_options[] = ACO_TYPES(&general_option)
static

Definition at line 46 of file res/ari/config.c.

◆ global_user

struct aco_type* global_user[] = ACO_TYPES(&user_option)
static

Definition at line 168 of file res/ari/config.c.

◆ user_option

struct aco_type user_option
static

Definition at line 156 of file res/ari/config.c.