Asterisk - The Open Source Telephony Project  21.4.1
Data Structures | Functions | Variables
conf_config_parser.c File Reference

ConfBridge config parser. More...

#include "asterisk.h"
#include "asterisk/logger.h"
#include "asterisk/config.h"
#include "asterisk/config_options.h"
#include "include/confbridge.h"
#include "asterisk/astobj2.h"
#include "asterisk/cli.h"
#include "asterisk/bridge_features.h"
#include "asterisk/stringfields.h"
#include "asterisk/pbx.h"

Go to the source code of this file.

Data Structures

struct  confbridge_cfg
 
struct  dtmf_menu_hook_pvt
 
struct  func_confbridge_data
 

Functions

static int add_action_to_menu_entry (struct conf_menu_entry *menu_entry, enum conf_menu_action_id id, char *databuf)
 
static int add_menu_entry (struct conf_menu *menu, const char *dtmf, const char *action_names)
 
static int announce_user_count_all_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static AO2_GLOBAL_OBJ_STATIC (cfg_handle)
 
static int apply_menu_to_user (struct confbridge_user *user, struct conf_menu *menu)
 
static int bridge_cmp_cb (void *obj, void *arg, int flags)
 
static int bridge_hash_cb (const void *obj, const int flags)
 
static void * bridge_profile_alloc (const char *category)
 
static void bridge_profile_destructor (void *obj)
 
static void * bridge_profile_find (struct ao2_container *container, const char *category)
 
static struct bridge_profile_soundsbridge_profile_sounds_alloc (void)
 
static void bridge_profile_sounds_destroy_cb (void *obj)
 
static int bridge_template_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static char * complete_bridge_profile_name (const char *line, const char *word, int pos, int state)
 
static char * complete_menu_name (const char *line, const char *word, int pos, int state)
 
static char * complete_user_profile_name (const char *line, const char *word, int pos, int state)
 
void conf_bridge_profile_copy (struct bridge_profile *dst, struct bridge_profile *src)
 copies a bridge profile More...
 
void conf_bridge_profile_destroy (struct bridge_profile *b_profile)
 Destroy a bridge profile found by 'conf_find_bridge_profile'.
 
void conf_destroy_config (void)
 destroy the information loaded from the confbridge.conf file
 
const struct bridge_profileconf_find_bridge_profile (struct ast_channel *chan, const char *bridge_profile_name, struct bridge_profile *result)
 Find a bridge profile given a bridge profile's name and store that profile in result structure. More...
 
int conf_find_menu_entry_by_sequence (const char *dtmf_sequence, struct conf_menu *menu, struct conf_menu_entry *result)
 Finds a menu_entry in a menu structure matched by DTMF sequence. More...
 
const struct user_profileconf_find_user_profile (struct ast_channel *chan, const char *user_profile_name, struct user_profile *result)
 find a user profile given a user profile's name and store that profile in result structure. More...
 
int conf_load_config (void)
 load confbridge.conf file
 
void conf_menu_entry_destroy (struct conf_menu_entry *menu_entry)
 Destroys and frees all the actions stored in a menu_entry structure.
 
static int conf_menu_profile_copy (struct conf_menu *dst, struct conf_menu *src)
 
int conf_reload_config (void)
 reload confbridge.conf file
 
int conf_set_menu_to_user (struct ast_channel *chan, struct confbridge_user *user, const char *menu_profile_name)
 find a menu profile given a menu profile's name and apply the menu in DTMF hooks. More...
 
static void conf_user_profile_copy (struct user_profile *dst, struct user_profile *src)
 
static void * confbridge_cfg_alloc (void)
 
static void confbridge_cfg_destructor (void *obj)
 
 CONFIG_INFO_STANDARD (cfg_info, cfg_handle, confbridge_cfg_alloc,.files=ACO_FILES(&confbridge_conf),.pre_apply_config=verify_default_profiles,)
 
static int copy_menu_entry (struct conf_menu_entry *dst, struct conf_menu_entry *src)
 
static void func_confbridge_data_destructor (struct func_confbridge_data *b_data)
 
static void func_confbridge_destroy_cb (void *data)
 
int func_confbridge_helper (struct ast_channel *chan, const char *cmd, char *data, const char *value)
 
static char * handle_cli_confbridge_show_bridge_profile (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_cli_confbridge_show_bridge_profiles (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_cli_confbridge_show_menu (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_cli_confbridge_show_menus (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_cli_confbridge_show_user_profile (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_cli_confbridge_show_user_profiles (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static void * menu_alloc (const char *category)
 
static int menu_cmp_cb (void *obj, void *arg, int flags)
 
static void menu_destructor (void *obj)
 
static void * menu_find (struct ao2_container *container, const char *category)
 
static int menu_hash_cb (const void *obj, const int flags)
 
static int menu_hook_callback (struct ast_bridge_channel *bridge_channel, void *hook_pvt)
 
static void menu_hook_destroy (void *hook_pvt)
 
static int menu_option_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int menu_template_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int mix_interval_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int remb_behavior_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int sample_rate_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int set_sound (const char *sound_name, const char *sound_file, struct bridge_profile *b_profile)
 
static int sound_option_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int user_cmp_cb (void *obj, void *arg, int flags)
 
static int user_hash_cb (const void *obj, const int flags)
 
static void * user_profile_alloc (const char *category)
 
static void user_profile_destructor (void *obj)
 
static void * user_profile_find (struct ao2_container *container, const char *category)
 
static int user_template_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 
static int verify_default_profiles (void)
 
static int video_mode_handler (const struct aco_option *opt, struct ast_variable *var, void *obj)
 

Variables

static struct aco_type bridge_type
 
static struct aco_typebridge_types [] = ACO_TYPES(&bridge_type)
 
static struct ast_cli_entry cli_confbridge_parser []
 
static struct aco_file confbridge_conf
 
static const struct ast_datastore_info confbridge_datastore
 
static struct aco_type general_type
 
static struct aco_type menu_type
 
static struct aco_typemenu_types [] = ACO_TYPES(&menu_type)
 
static struct aco_type user_type
 
static struct aco_typeuser_types [] = ACO_TYPES(&user_type)
 

Detailed Description

ConfBridge config parser.

Author
David Vossel dvoss.nosp@m.el@d.nosp@m.igium.nosp@m..com

Definition in file conf_config_parser.c.

Function Documentation

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

bridge profile container functions

Definition at line 853 of file conf_config_parser.c.

References CMP_MATCH, OBJ_KEY, OBJ_PARTIAL_KEY, and OBJ_POINTER.

854 {
855  const struct bridge_profile *left = obj;
856  const struct bridge_profile *right = arg;
857  const char *right_name = arg;
858  int cmp;
859 
860  switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
861  default:
862  case OBJ_POINTER:
863  right_name = right->name;
864  /* Fall through */
865  case OBJ_KEY:
866  cmp = strcasecmp(left->name, right_name);
867  break;
868  case OBJ_PARTIAL_KEY:
869  cmp = strncasecmp(left->name, right_name, strlen(right_name));
870  break;
871  }
872  return cmp ? 0 : CMP_MATCH;
873 }
#define OBJ_KEY
Definition: astobj2.h:1151
#define OBJ_POINTER
Definition: astobj2.h:1150
#define OBJ_PARTIAL_KEY
Definition: astobj2.h:1152
static void bridge_profile_sounds_destroy_cb ( void *  obj)
static

Bridge Profile Sounds functions

Definition at line 1002 of file conf_config_parser.c.

References ast_string_field_free_memory, and sounds.

1003 {
1004  struct bridge_profile_sounds *sounds = obj;
1006 }
static struct stasis_rest_handlers sounds
REST handler for /api-docs/sounds.json.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:374
void conf_bridge_profile_copy ( struct bridge_profile dst,
struct bridge_profile src 
)

copies a bridge profile

Note
conf_bridge_profile_destroy must be called on the dst structure

Definition at line 2558 of file conf_config_parser.c.

References ao2_ref.

Referenced by conf_find_bridge_profile(), and join_conference_bridge().

2559 {
2560  *dst = *src;
2561  if (src->sounds) {
2562  ao2_ref(src->sounds, +1);
2563  }
2564 }
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
const struct bridge_profile* conf_find_bridge_profile ( struct ast_channel chan,
const char *  bridge_profile_name,
struct bridge_profile result 
)

Find a bridge profile given a bridge profile's name and store that profile in result structure.

Parameters
chanchannel the bridge profile is requested for
bridge_profile_namename of the profile requested (optional)
resultdata contained by the bridge profile will be copied to this struct pointer

If bridge_profile_name is not provided, this function will check for the presence of a bridge profile set by the CONFBRIDGE function on a channel datastore. If that doesn't exist, the default_bridge profile is used.

Return values
bridgeprofile on success
NULLon failure

Definition at line 2574 of file conf_config_parser.c.

References ao2_global_obj_ref, ao2_ref, ast_channel_datastore_find(), func_confbridge_data::b_usable, conf_bridge_profile_copy(), ast_datastore::data, OBJ_KEY, and RAII_VAR.

Referenced by confbridge_exec().

2575 {
2576  struct bridge_profile *tmp2;
2577  struct ast_datastore *datastore = NULL;
2578  struct func_confbridge_data *b_data = NULL;
2579  RAII_VAR(struct confbridge_cfg *, cfg, ao2_global_obj_ref(cfg_handle), ao2_cleanup);
2580 
2581  if (chan && ast_strlen_zero(bridge_profile_name)) {
2582  ast_channel_lock(chan);
2583  datastore = ast_channel_datastore_find(chan, &confbridge_datastore, NULL);
2584  ast_channel_unlock(chan);
2585  if (datastore) {
2586  b_data = datastore->data;
2587  if (b_data->b_usable) {
2588  conf_bridge_profile_copy(result, &b_data->b_profile);
2589  return result;
2590  }
2591  }
2592  }
2593 
2594  if (!cfg) {
2595  return NULL;
2596  }
2597  if (ast_strlen_zero(bridge_profile_name)) {
2598  bridge_profile_name = DEFAULT_BRIDGE_PROFILE;
2599  }
2600  if (!(tmp2 = ao2_find(cfg->bridge_profiles, bridge_profile_name, OBJ_KEY))) {
2601  return NULL;
2602  }
2603  ao2_lock(tmp2);
2604  conf_bridge_profile_copy(result, tmp2);
2605  ao2_unlock(tmp2);
2606  ao2_ref(tmp2, -1);
2607 
2608  return result;
2609 }
#define OBJ_KEY
Definition: astobj2.h:1151
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
Definition: astobj2.h:918
Structure for a data store object.
Definition: datastore.h:64
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition: channel.c:2399
void conf_bridge_profile_copy(struct bridge_profile *dst, struct bridge_profile *src)
copies a bridge profile
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
void * data
Definition: datastore.h:66
#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 conf_find_menu_entry_by_sequence ( const char *  dtmf_sequence,
struct conf_menu menu,
struct conf_menu_entry result 
)

Finds a menu_entry in a menu structure matched by DTMF sequence.

Note
the menu entry found must be destroyed using conf_menu_entry_destroy()
Return values
1success, entry is found and stored in result
0failure, no entry found for given DTMF sequence

Definition at line 2645 of file conf_config_parser.c.

References AST_LIST_TRAVERSE, and conf_menu_entry::dtmf.

2646 {
2647  struct conf_menu_entry *menu_entry = NULL;
2648 
2649  ao2_lock(menu);
2650  AST_LIST_TRAVERSE(&menu->entries, menu_entry, entry) {
2651  if (!strcasecmp(menu_entry->dtmf, dtmf_sequence)) {
2652  copy_menu_entry(result, menu_entry);
2653  ao2_unlock(menu);
2654  return 1;
2655  }
2656  }
2657  ao2_unlock(menu);
2658 
2659  return 0;
2660 }
Definition: confbridge.h:138
char dtmf[MAXIMUM_DTMF_FEATURE_STRING]
Definition: confbridge.h:140
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:491
Definition: search.h:40
const struct user_profile* conf_find_user_profile ( struct ast_channel chan,
const char *  user_profile_name,
struct user_profile result 
)

find a user profile given a user profile's name and store that profile in result structure.

Parameters
chanchannel the user profile is requested for
user_profile_namename of the profile requested (optional)
resultdata contained by the user profile will be copied to this struct pointer

If user_profile_name is not provided, this function will check for the presence of a user profile set by the CONFBRIDGE function on a channel datastore. If that doesn't exist, the default_user profile is used.

Return values
userprofile on success
NULLon failure

Definition at line 2521 of file conf_config_parser.c.

References ao2_global_obj_ref, ao2_ref, ast_channel_datastore_find(), ast_datastore::data, OBJ_KEY, RAII_VAR, and func_confbridge_data::u_usable.

Referenced by conf_send_event_to_participants(), and confbridge_exec().

2522 {
2523  struct user_profile *tmp2;
2524  struct ast_datastore *datastore = NULL;
2525  struct func_confbridge_data *b_data = NULL;
2526  RAII_VAR(struct confbridge_cfg *, cfg, ao2_global_obj_ref(cfg_handle), ao2_cleanup);
2527 
2528  if (chan && ast_strlen_zero(user_profile_name)) {
2529  ast_channel_lock(chan);
2530  datastore = ast_channel_datastore_find(chan, &confbridge_datastore, NULL);
2531  ast_channel_unlock(chan);
2532  if (datastore) {
2533  b_data = datastore->data;
2534  if (b_data->u_usable) {
2535  conf_user_profile_copy(result, &b_data->u_profile);
2536  return result;
2537  }
2538  }
2539  }
2540 
2541  if (!cfg) {
2542  return NULL;
2543  }
2544  if (ast_strlen_zero(user_profile_name)) {
2545  user_profile_name = DEFAULT_USER_PROFILE;
2546  }
2547  if (!(tmp2 = ao2_find(cfg->user_profiles, user_profile_name, OBJ_KEY))) {
2548  return NULL;
2549  }
2550  ao2_lock(tmp2);
2551  conf_user_profile_copy(result, tmp2);
2552  ao2_unlock(tmp2);
2553  ao2_ref(tmp2, -1);
2554 
2555  return result;
2556 }
#define OBJ_KEY
Definition: astobj2.h:1151
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
Definition: astobj2.h:918
Structure for a data store object.
Definition: datastore.h:64
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition: channel.c:2399
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
void * data
Definition: datastore.h:66
#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 conf_set_menu_to_user ( struct ast_channel chan,
struct confbridge_user user,
const char *  menu_profile_name 
)

find a menu profile given a menu profile's name and apply the menu in DTMF hooks.

Parameters
chanchannel the menu profile is requested for
useruser profile the menu is being applied to
menu_profile_namename of the profile requested (optional)

If menu_profile_name is not provided, this function will check for the presence of a menu profile set by the CONFBRIDGE function on a channel datastore. If that doesn't exist, the default_menu profile is used.

Return values
0on success
-1on failure

Definition at line 2691 of file conf_config_parser.c.

References ao2_bump, ao2_global_obj_ref, ast_channel_datastore_find(), ast_datastore::data, func_confbridge_data::m_usable, OBJ_KEY, and RAII_VAR.

Referenced by confbridge_exec().

2692 {
2693  RAII_VAR(struct confbridge_cfg *, cfg, ao2_global_obj_ref(cfg_handle), ao2_cleanup);
2694  RAII_VAR(struct conf_menu *, menu, NULL, ao2_cleanup);
2695 
2696  if (chan && ast_strlen_zero(menu_profile_name)) {
2697  struct ast_datastore *datastore;
2698  struct func_confbridge_data *b_data;
2699 
2700  ast_channel_lock(chan);
2701  datastore = ast_channel_datastore_find(chan, &confbridge_datastore, NULL);
2702  ast_channel_unlock(chan);
2703  if (datastore) {
2704  /* If a menu exists in the CONFBRIDGE function datastore, use it. */
2705  b_data = datastore->data;
2706  if (b_data->m_usable) {
2707  menu = ao2_bump(b_data->menu);
2708  return apply_menu_to_user(user, menu);
2709  }
2710  }
2711  }
2712 
2713  /* Otherwise, we need to get whatever menu profile is specified to use (or default). */
2714  if (!cfg) {
2715  return -1;
2716  }
2717 
2718  if (ast_strlen_zero(menu_profile_name)) {
2719  menu_profile_name = DEFAULT_MENU_PROFILE;
2720  }
2721 
2722  if (!(menu = ao2_find(cfg->menus, menu_profile_name, OBJ_KEY))) {
2723  return -1;
2724  }
2725 
2726  return apply_menu_to_user(user, menu);
2727 }
#define OBJ_KEY
Definition: astobj2.h:1151
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
Definition: astobj2.h:918
Structure for a data store object.
Definition: datastore.h:64
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition: channel.c:2399
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
void * data
Definition: datastore.h:66
#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
static int menu_cmp_cb ( void *  obj,
void *  arg,
int  flags 
)
static

menu container functions

Definition at line 899 of file conf_config_parser.c.

References CMP_MATCH, OBJ_KEY, OBJ_PARTIAL_KEY, and OBJ_POINTER.

900 {
901  const struct conf_menu *left = obj;
902  const struct conf_menu *right = arg;
903  const char *right_name = arg;
904  int cmp;
905 
906  switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
907  default:
908  case OBJ_POINTER:
909  right_name = right->name;
910  /* Fall through */
911  case OBJ_KEY:
912  cmp = strcasecmp(left->name, right_name);
913  break;
914  case OBJ_PARTIAL_KEY:
915  cmp = strncasecmp(left->name, right_name, strlen(right_name));
916  break;
917  }
918  return cmp ? 0 : CMP_MATCH;
919 }
#define OBJ_KEY
Definition: astobj2.h:1151
#define OBJ_POINTER
Definition: astobj2.h:1150
#define OBJ_PARTIAL_KEY
Definition: astobj2.h:1152
static int user_cmp_cb ( void *  obj,
void *  arg,
int  flags 
)
static

User profile container functions

Definition at line 956 of file conf_config_parser.c.

References CMP_MATCH, OBJ_KEY, OBJ_PARTIAL_KEY, and OBJ_POINTER.

957 {
958  const struct user_profile *left = obj;
959  const struct user_profile *right = arg;
960  const char *right_name = arg;
961  int cmp;
962 
963  switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
964  default:
965  case OBJ_POINTER:
966  right_name = right->name;
967  /* Fall through */
968  case OBJ_KEY:
969  cmp = strcasecmp(left->name, right_name);
970  break;
971  case OBJ_PARTIAL_KEY:
972  cmp = strncasecmp(left->name, right_name, strlen(right_name));
973  break;
974  }
975  return cmp ? 0 : CMP_MATCH;
976 }
#define OBJ_KEY
Definition: astobj2.h:1151
#define OBJ_POINTER
Definition: astobj2.h:1150
#define OBJ_PARTIAL_KEY
Definition: astobj2.h:1152

Variable Documentation

struct aco_file confbridge_conf
static
Initial value:
= {
.filename = "confbridge.conf",
.types = ACO_TYPES(&bridge_type, &user_type, &menu_type, &general_type),
}
#define ACO_TYPES(...)
A helper macro to ensure that aco_info types always have a sentinel.

Definition at line 838 of file conf_config_parser.c.

const struct ast_datastore_info confbridge_datastore
static
Initial value:
= {
.type = "confbridge",
.destroy = func_confbridge_destroy_cb
}

Definition at line 1116 of file conf_config_parser.c.