Asterisk - The Open Source Telephony Project GIT-master-f36a736
Data Structures | Functions
internal.h File Reference

Internal API's for res_ari. More...

#include "asterisk/http.h"
#include "asterisk/json.h"
#include "asterisk/stringfields.h"
Include dependency graph for internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_ari_conf
 All configuration options for ARI. More...
 
struct  ast_ari_conf_general
 Global configuration options for ARI. More...
 
struct  ast_ari_conf_user
 Per-user configuration options. More...
 

Functions

void ari_handle_websocket (struct ast_websocket_server *ws_server, struct ast_tcptls_session_instance *ser, const char *uri, enum ast_http_method method, struct ast_variable *get_params, struct ast_variable *headers)
 Wrapper for invoking the websocket code for an incoming connection. More...
 
int ast_ari_cli_register (void)
 Register CLI commands for ARI. More...
 
void ast_ari_cli_unregister (void)
 Unregister CLI commands for ARI. More...
 
#define ARI_AUTH_REALM_LEN   256
 
#define ARI_PASSWORD_LEN   256
 User's password mx length. 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...
 
enum  ast_ari_password_format { ARI_PASSWORD_FORMAT_PLAIN , ARI_PASSWORD_FORMAT_CRYPT }
 Password format. More...
 

Detailed Description

Internal API's for res_ari.

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

Definition in file internal.h.

Macro Definition Documentation

◆ ARI_AUTH_REALM_LEN

#define ARI_AUTH_REALM_LEN   256

Max length for auth_realm field

Definition at line 62 of file internal.h.

◆ ARI_PASSWORD_LEN

#define ARI_PASSWORD_LEN   256

User's password mx length.

If 256 seems like a lot, a crypt SHA-512 has over 106 characters.

Definition at line 93 of file internal.h.

Enumeration Type Documentation

◆ ast_ari_password_format

Password format.

Enumerator
ARI_PASSWORD_FORMAT_PLAIN 

Plaintext password.

ARI_PASSWORD_FORMAT_CRYPT 

crypt(3) password

Definition at line 81 of file internal.h.

81 {
82 /*! \brief Plaintext password */
84 /*! crypt(3) password */
86};
@ ARI_PASSWORD_FORMAT_CRYPT
Definition: internal.h:85
@ ARI_PASSWORD_FORMAT_PLAIN
Plaintext password.
Definition: internal.h:83

Function Documentation

◆ ari_handle_websocket()

void ari_handle_websocket ( struct ast_websocket_server ws_server,
struct ast_tcptls_session_instance ser,
const char *  uri,
enum ast_http_method  method,
struct ast_variable get_params,
struct ast_variable headers 
)

Wrapper for invoking the websocket code for an incoming connection.

Parameters
ws_serverWebSocket server to invoke.
serHTTP session.
uriRequested URI.
methodRequested HTTP method.
get_paramsParsed query parameters.
headersParsed HTTP headers.

Definition at line 191 of file ari_websockets.c.

195{
196 struct ast_http_uri fake_urih = {
197 .data = ws_server,
198 };
199 ast_websocket_uri_cb(ser, &fake_urih, uri, method, get_params,
200 headers);
201}
int ast_websocket_uri_cb(struct ast_tcptls_session_instance *ser, const struct ast_http_uri *urih, const char *uri, enum ast_http_method method, struct ast_variable *get_vars, struct ast_variable *headers)
Callback suitable for use with a ast_http_uri.
const char * method
Definition: res_pjsip.c:1279
Definition of a URI handler.
Definition: http.h:102
const char * uri
Definition: http.h:105
void * data
Definition: http.h:116

References ast_websocket_uri_cb(), ast_http_uri::data, method, and ast_http_uri::uri.

Referenced by ast_ari_invoke().

◆ ast_ari_cli_register()

int ast_ari_cli_register ( void  )

Register CLI commands for ARI.

Returns
0 on success.
Non-zero on error.

Definition at line 431 of file res/ari/cli.c.

431 {
433}
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
static struct ast_cli_entry cli_ari[]
Definition: res/ari/cli.c:421
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, ast_cli_register_multiple, and cli_ari.

Referenced by load_module().

◆ ast_ari_cli_unregister()

void ast_ari_cli_unregister ( void  )

Unregister CLI commands for ARI.

Definition at line 435 of file res/ari/cli.c.

435 {
437}
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30

References ARRAY_LEN, ast_cli_unregister_multiple(), and cli_ari.

Referenced by unload_module().

◆ ast_ari_config_destroy()

void ast_ari_config_destroy ( void  )

Destroy the ARI configuration.

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

384{
385 aco_info_destroy(&cfg_info);
387}
#define ao2_global_obj_release(holder)
Release the ao2 object held in the global holder.
Definition: astobj2.h:859
void aco_info_destroy(struct aco_info *info)
Destroy an initialized aco_info struct.

References aco_info_destroy(), and ao2_global_obj_release.

Referenced by unload_module().

◆ 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.
Return values
NULLon error.

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

228{
230 if (!res) {
232 "Error obtaining config from " CONF_FILENAME "\n");
233 }
234 return res;
235}
#define ast_log
Definition: astobj2.c:42
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
Definition: astobj2.h:918
#define LOG_ERROR
#define CONF_FILENAME
All configuration options for ARI.
Definition: internal.h:54

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().

◆ ast_ari_config_init()

int ast_ari_config_init ( void  )

Initialize the ARI configuration.

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

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,
371 FLDSET(struct ast_ari_conf_user, password), ARI_PASSWORD_LEN);
372 aco_option_register_custom(&cfg_info, "password_format", ACO_EXACT,
374
375 return process_config(0);
376}
@ ACO_EXACT
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
int aco_info_init(struct aco_info *info)
Initialize an aco_info structure.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
#define aco_option_register(info, name, matchtype, types, default_val, opt_type, flags,...)
Register a config option.
@ OPT_NOOP_T
Type for a default handler that should do nothing.
@ OPT_BOOL_T
Type for default option handler for bools (ast_true/ast_false)
@ OPT_CHAR_ARRAY_T
Type for default option handler for character array strings.
@ OPT_INT_T
Type for default option handler for signed integers.
@ OPT_STRINGFIELD_T
Type for default option handler for stringfields.
#define aco_option_register_custom(info, name, matchtype, types, default_val, handler, flags)
Register a config option.
static int enabled
Definition: dnsmgr.c:91
#define AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT_STR
Default websocket write timeout, in ms (as a string)
#define ARI_PASSWORD_LEN
User's password mx length.
Definition: internal.h:93
#define ARI_AUTH_REALM_LEN
Definition: internal.h:62
static int process_config(int reload)
Load (or reload) configuration.
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.
static struct aco_type * global_user[]
static struct aco_type * general_options[]
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 int channelvars_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
#define NULL
Definition: resample.c:96
Global configuration options for ARI.
Definition: internal.h:65
Per-user configuration options.
Definition: internal.h:96

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, general_options, global_user, NULL, OPT_BOOL_T, OPT_CHAR_ARRAY_T, OPT_INT_T, OPT_NOOP_T, OPT_STRINGFIELD_T, PARSE_IN_RANGE, ast_ari_conf_user::password, password_format_handler(), process_config(), ast_ari_conf_user::read_only, and STRFLDSET.

Referenced by load_module().

◆ ast_ari_config_reload()

int ast_ari_config_reload ( void  )

Reload the ARI configuration.

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

379{
380 return process_config(1);
381}

References process_config().

Referenced by reload_module().

◆ 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.
Return values
NULLif username or password is invalid.

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

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}
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1736
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1101
#define LOG_WARNING
struct ast_ari_conf * ast_ari_config_get(void)
Get the current ARI configuration.
static char user[512]
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
All configuration options for http media cache.
structure to hold users read from users.conf
#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:941
int ast_crypt_validate(const char *key, const char *expected)
Asterisk wrapper around crypt(3) for validating passwords.
Definition: crypt.c:136

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, ast_ari_conf_user::password, RAII_VAR, user, and ast_ari_conf_user::username.

Referenced by authenticate_api_key(), and authenticate_user().