Asterisk - The Open Source Telephony Project  21.4.1
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"

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.
 
#define ARI_AUTH_REALM_LEN   256
 
#define ARI_PASSWORD_LEN   256
 User's password mx length. More...
 
enum  ast_ari_password_format { ARI_PASSWORD_FORMAT_PLAIN, ARI_PASSWORD_FORMAT_CRYPT }
 Password format. More...
 
int ast_ari_config_init (void)
 Initialize the ARI configuration.
 
int ast_ari_config_reload (void)
 Reload the ARI configuration.
 
void ast_ari_config_destroy (void)
 Destroy the ARI configuration.
 
struct ast_ari_confast_ari_config_get (void)
 Get the current ARI configuration. More...
 
struct ast_ari_conf_userast_ari_config_validate_user (const char *username, const char *password)
 Validated a user's credentials. 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

#define ARI_AUTH_REALM_LEN   256

Max length for auth_realm field

Definition at line 62 of file internal.h.

Referenced by ast_ari_config_init().

#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.

Referenced by ast_ari_config_init().

Enumeration Type Documentation

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 };
Plaintext password.
Definition: internal.h:83

Function Documentation

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.

References ast_http_uri::data.

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 }
Definition of a URI handler.
Definition: http.h:102
void * data
Definition: http.h:116
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.

References ast_cli_register_multiple.

431  {
432  return ast_cli_register_multiple(cli_ari, ARRAY_LEN(cli_ari));
433 }
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
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.

References ao2_global_obj_ref.

Referenced by ast_ari_config_validate_user(), ast_ari_json_format(), ast_ari_websocket_session_create(), is_enabled(), and process_config().

228 {
229  struct ast_ari_conf *res = ao2_global_obj_ref(confs);
230  if (!res) {
231  ast_log(LOG_ERROR,
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)
Get a reference to the object stored in the global holder.
Definition: astobj2.h:918
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.

References ao2_ref, ARI_PASSWORD_FORMAT_CRYPT, ARI_PASSWORD_FORMAT_PLAIN, ast_ari_config_get(), ast_crypt_validate(), OBJ_SEARCH_KEY, and RAII_VAR.

Referenced by authenticate_api_key(), and authenticate_user().

239 {
240  RAII_VAR(struct ast_ari_conf *, conf, NULL, ao2_cleanup);
241  RAII_VAR(struct ast_ari_conf_user *, user, NULL, ao2_cleanup);
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)) {
255  ast_log(LOG_WARNING,
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 }
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:1101
All configuration options for ARI.
Definition: internal.h:54
Plaintext password.
Definition: internal.h:83
All configuration options for http media cache.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
Per-user configuration options.
Definition: internal.h:96
structure to hold users read from users.conf
int ast_crypt_validate(const char *key, const char *expected)
Asterisk wrapper around crypt(3) for validating passwords.
Definition: crypt.c:136
#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