45#define OWC_STATES_BUCKETS 13
52 ast_debug(3,
"%s: Disposing of outbound websocket config\n",
73 ast_debug(2,
"%s: Allocated outbound websocket config\n",
id);
89 ast_log(
LOG_ERROR,
"%s: Outbound websocket invalid websocket client id '%s'\n",
120 ast_debug(3,
"%s: Initializing outbound websocket\n",
id);
151 ast_debug(3,
"%s: Outbound websocket configuration succeeded\n",
id);
178 ast_debug(2,
"%s: Validating outbound websocket\n",
id);
207 strcpy(
state->id,
id);
208 ast_debug(3,
"%s: Created new outbound websocket state\n",
id);
210 ast_debug(3,
"%s: Outbound websocket state already exists\n",
id);
227 "%s: Outbound websocket '%s' is also trying to register app '%s'\n",
253 ast_log(
LOG_WARNING,
"%s: Outbound websocket ARI user '%s' password MUST be plain text\n",
280 ast_debug(3,
"%s: Cleaning up orphaned outbound websocket state\n",
state->id);
318 const char *
app_name,
unsigned int ws_type)
332 ast_debug(3,
"No outbound websockets found\n");
340 ast_debug(3,
"%s: Checking outbound websocket apps '%s' for app '%s'\n",
344 ast_debug(3,
"%s: Found correct websocket type for apps '%s' for app '%s'\n",
367 return "per_call_config";
386 int changes_found = 0;
388 ast_debug(2,
"%s: Detecting changes\n", new_id);
396 for (v = changes; v; v = v->
next) {
411 if (!changes_found) {
412 ast_debug(2,
"%s: No changes found %p %p\n", new_id,
457 ast_debug(2,
"Initializing general config\n");
529 ast_debug(2,
"%s: Initializing user\n",
id);
545 if (strcasecmp(
var->value,
"plain") == 0) {
547 }
else if (strcasecmp(
var->value,
"crypt") == 0) {
606 switch (
user->password_format) {
661 ast_debug(2,
"Initializing ARI configuration\n");
665 outbound_websocket_state_hash_fn,
NULL,
666 outbound_websocket_state_cmp_fn);
678 "ari.conf,criteria=type=general,single_object=yes,explicit_name=general");
680 "ari.conf,criteria=type=user");
682 "ari.conf,criteria=type=outbound_websocket");
700 ast_log(
LOG_ERROR,
"Failed to register ARI outbound_websocket object with sorcery\n");
707 ast_log(
LOG_ERROR,
"Failed to register ARI outbound_websocket observer with sorcery\n");
748 const char *msg_prefix;
752 msg_prefix=
"Reloading";
756 msg_prefix=
"Loading";
772 ast_debug(2,
"%s ARI '%s' configuration\n", msg_prefix,
"general");
777 ast_debug(2,
"%s ARI '%s' configuration\n", msg_prefix,
"user");
782 ast_debug(2,
"%s ARI '%s' configuration\n", msg_prefix,
"outbound_websocket");
783 loader(
sorcery,
"outbound_websocket");
#define ARI_MAX_APP_NAME_LEN
Asterisk main include file. File version handling, generic pbx functions.
#define ast_strdup(str)
A wrapper for strdup()
#define ast_strdupa(s)
duplicate a string in memory from the stack
void ast_free_ptr(void *ptr)
free() wrapper
#define ao2_iterator_next(iter)
#define ao2_link(container, obj)
Add an object to a container.
@ AO2_ALLOC_OPT_LOCK_MUTEX
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
#define AO2_STRING_FIELD_CMP_FN(stype, field)
Creates a compare function for a structure string field.
#define ao2_find(container, arg, flags)
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define AO2_STRING_FIELD_HASH_FN(stype, field)
Creates a hash function for a structure string field.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
#define ao2_alloc(data_size, destructor_fn)
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
@ AO2_CONTAINER_ALLOC_OPT_DUPS_REPLACE
Replace objects with duplicate keys in container.
General Asterisk PBX channel definitions.
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.
Configuration option-handling.
@ OPT_NOOP_T
Type for a default handler that should do nothing.
Support for WebSocket connections within the Asterisk HTTP server and client WebSocket connections to...
#define AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT
Default websocket write timeout, in ms.
ast_websocket_type
WebSocket connection/configuration types.
@ AST_WS_TYPE_CLIENT_PER_CALL_CONFIG
@ AST_WS_TYPE_CLIENT_PERSISTENT
@ AST_WS_TYPE_CLIENT_PER_CALL
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
#define ast_debug(level,...)
Log a DEBUG message.
Internal API's for res_ari.
@ ARI_PASSWORD_FORMAT_CRYPT
@ ARI_PASSWORD_FORMAT_PLAIN
Plaintext password.
@ ARI_OWC_FIELD_LOCAL_ARI_PASSWORD
@ ARI_OWC_FIELD_LOCAL_ARI_USER
@ ARI_OWC_FIELD_SUBSCRIBE_ALL
static int subscribe_all(void)
const char * app_name(struct ast_app *app)
struct ari_conf_outbound_websocket * ari_conf_get_owc_for_app(const char *app_name, unsigned int ws_type)
Get the outbound websocket configuration for a Stasis app.
static struct ast_sorcery_observer observer_callbacks
static void outbound_websockets_validate(const char *name)
static int outbound_websocket_apply(const struct ast_sorcery *sorcery, void *obj)
Callback to initialize an outbound websocket object.
int ari_sorcery_observer_remove(const char *object_type, const struct ast_sorcery_observer *callbacks)
static int ari_conf_init(void)
static int user_apply(const struct ast_sorcery *sorcery, void *obj)
enum ari_conf_owc_fields ari_conf_owc_get_invalid_fields(const char *id)
struct ao2_container * ari_conf_get_owcs(void)
static void * general_alloc(const char *name)
static void * user_alloc(const char *cat)
Allocate an ast_ari_conf_user for config parsing.
struct ao2_container * ari_conf_get_users(void)
enum ari_conf_owc_fields ari_conf_owc_detect_changes(struct ari_conf_outbound_websocket *old_owc, struct ari_conf_outbound_websocket *new_owc)
Detect changes between two outbound websocket configurations.
static void * outbound_websocket_alloc(const char *id)
int ari_conf_load(enum ari_conf_load_flags flags)
(Re)load the ARI configuration
static void general_dtor(void *obj)
ast_ari_conf destructor.
static int general_pretty_from_str(const struct aco_option *opt, struct ast_variable *var, void *obj)
Encoding format handler converts from boolean to enum.
static int user_password_format_to_str(const void *obj, const intptr_t *args, char **buf)
static int outbound_websocket_validate_cb(void *obj, void *args, int flags)
static int general_pretty_to_str(const void *obj, const intptr_t *args, char **buf)
#define OWC_STATES_BUCKETS
static int general_apply(const struct ast_sorcery *sorcery, void *obj)
static struct ast_sorcery_observer ws_client_observer_callbacks
static struct ast_sorcery * sorcery
static int outbound_websocket_websocket_client_id_from_str(const struct aco_option *opt, struct ast_variable *var, void *obj)
struct ao2_container * owc_states
static int outbound_websocket_state_cleanup(void *obj, void *arg, int flags)
const char * ari_websocket_type_to_str(enum ast_websocket_type type)
int ari_sorcery_observer_add(const char *object_type, const struct ast_sorcery_observer *callbacks)
static void ws_client_load(const char *name)
struct ari_conf_general * ari_conf_get_general(void)
static int user_password_format_from_str(const struct aco_option *opt, struct ast_variable *var, void *obj)
Parses the ast_ari_password_format enum from a config file.
static void user_dtor(void *obj)
Destructor for ast_ari_conf_user.
static void outbound_websocket_dtor(void *obj)
struct ari_conf_outbound_websocket * ari_conf_get_owc(const char *id)
struct ari_conf_user * ari_conf_get_user(const char *username)
struct ari_conf_user * ari_conf_validate_user(const char *username, const char *password)
Validated a user's credentials.
static int outbound_websocket_websocket_client_id_to_str(const void *obj, const intptr_t *args, char **buf)
void ari_conf_destroy(void)
Destroy the ARI configuration.
Sorcery Data Access Layer API.
#define ast_sorcery_unref(sorcery)
Decrease the reference count of a sorcery structure.
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
#define ast_sorcery_object_field_register_nodoc(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object without documentation.
void ast_sorcery_observer_remove(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)
Remove an observer from a specific object type.
#define ast_sorcery_register_cust(object, option, def_value)
Register a custom field within an object.
@ AST_RETRIEVE_FLAG_MULTIPLE
Return all matching objects.
@ AST_RETRIEVE_FLAG_ALL
Perform no matching, return all objects.
int ast_sorcery_diff(const struct ast_sorcery *sorcery, const void *original, const void *modified, struct ast_variable **changes)
Create a changeset of two objects.
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
int ast_sorcery_observer_add(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)
Add an observer to a specific object type.
void ast_sorcery_load_object(const struct ast_sorcery *sorcery, const char *type)
Inform any wizards of a specific object type to load persistent objects.
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
#define ast_sorcery_register_int(object, structure, option, field, def_value)
Register an int field as type OPT_INT_T within an object.
#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
void ast_sorcery_force_reload_object(const struct ast_sorcery *sorcery, const char *type)
Inform any wizards of a specific object type to reload persistent objects even if no changes determin...
#define ast_sorcery_apply_default(sorcery, type, name, data)
#define ast_sorcery_register_bool(object, structure, option, field, def_value)
Register a boolean field as type OPT_YESNO_T within an object.
#define ast_sorcery_open()
Open a new sorcery structure.
void ast_sorcery_reload_object(const struct ast_sorcery *sorcery, const char *type)
Inform any wizards of a specific object type to reload persistent objects.
void * ast_sorcery_retrieve_by_fields(const struct ast_sorcery *sorcery, const char *type, unsigned int flags, struct ast_variable *fields)
Retrieve an object or multiple objects using specific fields.
#define ast_sorcery_register_sf(object, structure, option, field, def_value)
Register a stringfield field as type OPT_STRINGFIELD_T within an object.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
int ast_strings_equal(const char *str1, const char *str2)
Compare strings for equality checking for NULL.
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
static force_inline int attribute_pure ast_strlen_zero(const char *s)
int ast_in_delimited_string(const char *needle, const char *haystack, char delim)
Check if there is an exact match for 'needle' between delimiters in 'haystack'.
char * ast_strsep(char **s, const char sep, uint32_t flags)
Act like strsep but ignore separators inside quotes.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Registered applications container.
Global configuration options for ARI.
const ast_string_field channelvars
enum ast_json_encoding_format format
const ast_string_field apps
struct ast_websocket_client * websocket_client
const ast_string_field local_ari_user
const ast_string_field websocket_client_id
Per-user configuration options.
const ast_string_field password
Interface for a sorcery object type observer.
void(* loaded)(const char *object_type)
Callback for when an object type is loaded/reloaded.
Full structure for sorcery.
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
String vector definitions.
enum ast_websocket_type connection_type
enum ari_conf_owc_fields invalid_fields
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.
int ast_crypt_validate(const char *key, const char *expected)
Asterisk wrapper around crypt(3) for validating passwords.
Vector container support.
#define AST_VECTOR_RESET(vec, cleanup)
Reset vector.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
int ast_vector_string_split(struct ast_vector_string *dest, const char *input, const char *delim, int flags, int(*excludes_cmp)(const char *s1, const char *s2))
Append a string vector by splitting a string.
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
int ast_websocket_client_reload(void)
Force res_websocket_client to reload its configuration.
enum ast_ws_client_fields ast_websocket_client_get_field_diff(struct ast_websocket_client *old_wc, struct ast_websocket_client *new_wc)
Detect changes between two websocket client configurations.
struct ast_websocket_client * ast_websocket_client_retrieve_by_id(const char *id)
Retrieve a websocket client object by ID.
void ast_websocket_client_observer_remove(const struct ast_sorcery_observer *callbacks)
Remove sorcery observers for websocket client events.
int ast_websocket_client_observer_add(const struct ast_sorcery_observer *callbacks)
Add sorcery observers for websocket client events.