34 #include "res_aeap/general.h"
73 SORCERY_OBJECT(details);
84 static void client_config_destructor(
void *obj)
92 static void *client_config_alloc(
const char *name)
114 static int client_config_apply(
const struct ast_sorcery *sorcery,
void *obj)
118 if (ast_strlen_zero(cfg->
url)) {
137 const char *protocol)
139 return !strcmp(protocol, cfg->
protocol);
147 var = protocol ? ast_variable_new(
"protocol ==", protocol,
"") : NULL;
166 int wordlen = strlen(word);
170 while ((obj = ao2_iterator_next(&it))) {
187 static int aeap_cli_show(
void *obj,
void *arg,
int flags)
194 ast_cli(a->fd,
"No AEAP configuration found\n");
206 for (i = options; i; i = i->
next) {
207 ast_cli(a->fd,
"\t%s: %s\n", i->
name, i->
value);
210 ast_cli(a->fd,
"\n");
223 e->
command =
"aeap show client";
225 "Usage: aeap show client <id>\n"
226 " Show the AEAP settings for a given client\n";
237 return CLI_SHOWUSAGE;
240 cfg = client_config_get(a->argv[3]);
241 aeap_cli_show(cfg, a, 0);
253 e->
command =
"aeap show clients";
255 "Usage: aeap show clients\n"
256 " Show all configured AEAP clients\n";
263 return CLI_SHOWUSAGE;
268 ast_cli(a->fd,
"No AEAP clients found\n");
269 ao2_cleanup(container);
280 AST_CLI_DEFINE(client_config_show,
"Show AEAP client configuration by id"),
281 AST_CLI_DEFINE(client_config_show_all,
"Show all AEAP client configurations"),
285 int connect,
int timeout)
289 const char *url = NULL;
290 const char *protocol = NULL;
292 cfg = client_config_get(
id);
298 #ifdef TEST_FRAMEWORK
300 url =
"ws://127.0.0.1:8088/ws";
305 if (!url && !protocol) {
306 ast_log(LOG_ERROR,
"AEAP: unable to get configuration for '%s'\n",
id);
319 return aeap_create(
id, params, 0, 0);
325 return aeap_create(
id, params, 1, timeout);
333 cfg = client_config_get(
id);
335 ast_log(LOG_WARNING,
"AEAP: no client configuration '%s' to get fields\n",
id);
345 static int reload_module(
void)
352 static int unload_module(
void)
359 aeap_general_finalize();
364 static int load_module(
void)
366 if (aeap_general_initialize()) {
372 ast_log(LOG_ERROR,
"AEAP - failed to open sorcery\n");
376 ast_sorcery_apply_default(aeap_sorcery, AEAP_CONFIG_CLIENT,
"config",
"aeap.conf,criteria=type=client");
379 NULL, client_config_apply)) {
380 ast_log(LOG_ERROR,
"AEAP - failed to register client sorcery object\n");
396 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER,
397 "Asterisk External Application Protocol Module for Asterisk",
398 .support_level = AST_MODULE_SUPPORT_CORE,
400 .unload = unload_module,
401 .reload = reload_module,
403 .requires =
"res_http_websocket",
const ast_string_field url
struct ast_variable * next
Type for default option handler for format capabilities.
Asterisk External Application Protocol API.
Callbacks and other parameters used by an Asterisk external application object.
struct ast_variable * ast_variable_list_sort(struct ast_variable *head)
Performs an in-place sort on the variable list by ascending name.
Asterisk main include file. File version handling, generic pbx functions.
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
int ast_aeap_client_config_has_protocol(const struct ast_aeap_client_config *cfg, const char *protocol)
Check a given protocol against that in an Asterisk external application configuration.
descriptor for a cli entry.
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container, as described below.
Structure for variables, used for configurations and for channel variables.
Perform no matching, return all objects.
Full structure for sorcery.
Type for a default handler that should do nothing.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
Return all matching objects.
#define ast_strdup(str)
A wrapper for strdup()
struct ast_sorcery * ast_aeap_sorcery(void)
Retrieve the AEAP sorcery object.
struct ast_aeap * ast_aeap_create(const char *type, const struct ast_aeap_params *params)
Create an Asterisk external application object.
const char * ast_sorcery_object_get_type(const void *object)
Get the type of a sorcery object.
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_unref(sorcery)
Decrease the reference count of a sorcery structure.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
static struct ao2_container * codecs
Registered codecs.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define AST_STRING_FIELD(name)
Declare a string field.
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
struct ao2_container * container
struct ast_aeap * ast_aeap_create_by_id(const char *id, const struct ast_aeap_params *params)
Create an Asterisk external application object by sorcery id.
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
const struct ast_aeap_params * params
struct ast_aeap * ast_aeap_create_and_connect(const char *type, const struct ast_aeap_params *params, const char *url, const char *protocol, int timeout)
Create and connect to an Asterisk external application.
struct ast_aeap * ast_aeap_create_and_connect_by_id(const char *id, const struct ast_aeap_params *params, int timeout)
Create and connect to an Asterisk external application by sorcery id.
struct ast_variable * ast_aeap_custom_fields_get(const char *id)
Retrieve a list of custom configuration fields.
#define ast_sorcery_objectset_create(sorcery, object)
Create an object set (KVP list) for an object.
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
Module has failed to load, may be in an inconsistent state.
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_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
void ast_sorcery_load(const struct ast_sorcery *sorcery)
Inform any wizards to load persistent objects.
void ast_sorcery_reload(const struct ast_sorcery *sorcery)
Inform any wizards to reload persistent objects.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Standard Command Line Interface.
#define ast_sorcery_open()
Open a new sorcery structure.
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
Checks whether a string begins with another.
Type for default option handler for stringfields.
const ast_string_field protocol
const struct ast_format_cap * ast_aeap_client_config_codecs(const struct ast_aeap_client_config *cfg)
Retrieve codec capabilities from the configuration.
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
struct ao2_container * ast_aeap_client_configs_get(const char *protocol)
Retrieve a listing of all client configuration objects by protocol.
int ast_cli_completion_add(char *value)
Add a result to a request for completion options.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
struct ast_format_cap * codecs
Sorcery Data Access Layer API.