From b679563222f05613194716fa688e964da1263a62 Mon Sep 17 00:00:00 2001 From: Matthew Jordan Date: Tue, 26 Feb 2013 15:24:35 +0000 Subject: [PATCH] Ensure that the default bridge/user profiles are always available ConfBridge and Page require that there always be a default bridge and user profile available. While properties of the default profiles can be overriden in the configuration file, removing them can create situations where neither application can function properly. This patch ensures that if an administrator removes the profiles from the confbridge.conf configuration file, the profiles are added upon load. Documentation clarifying this has been added to the confbridge.conf.sample file. Review: https://reviewboard.asterisk.org/r/2356/ (closes issue AST-1115) Reported by: John Bigelow Tested by: John Bigelow git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/11@382066 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- apps/confbridge/conf_config_parser.c | 37 ++++++++++++++++++++++++++++ configs/confbridge.conf.sample | 4 +++ 2 files changed, 41 insertions(+) diff --git a/apps/confbridge/conf_config_parser.c b/apps/confbridge/conf_config_parser.c index c915b184c2..57166aa8c9 100644 --- a/apps/confbridge/conf_config_parser.c +++ b/apps/confbridge/conf_config_parser.c @@ -46,6 +46,7 @@ struct confbridge_cfg { struct ao2_container *menus; }; +static int verify_default_profiles(void); static void *bridge_profile_alloc(const char *category); static void *bridge_profile_find(struct ao2_container *container, const char *category); static struct bridge_profile_sounds *bridge_profile_sounds_alloc(void); @@ -179,6 +180,7 @@ static void *confbridge_cfg_alloc(void); CONFIG_INFO_STANDARD(cfg_info, cfg_handle, confbridge_cfg_alloc, .files = ACO_FILES(&confbridge_conf), + .pre_apply_config = verify_default_profiles, ); /*! bridge profile container functions */ @@ -1283,6 +1285,41 @@ static int menu_option_handler(const struct aco_option *opt, struct ast_variable return 0; } +static int verify_default_profiles(void) +{ + RAII_VAR(struct user_profile *, user_profile, NULL, ao2_cleanup); + RAII_VAR(struct bridge_profile *, bridge_profile, NULL, ao2_cleanup); + struct confbridge_cfg *cfg = aco_pending_config(&cfg_info); + + if (!cfg) { + return 0; + } + + bridge_profile = ao2_find(cfg->bridge_profiles, DEFAULT_BRIDGE_PROFILE, OBJ_KEY); + if (!bridge_profile) { + bridge_profile = bridge_profile_alloc(DEFAULT_BRIDGE_PROFILE); + if (!bridge_profile) { + return -1; + } + ast_log(AST_LOG_NOTICE, "Adding %s profile to app_confbridge\n", DEFAULT_BRIDGE_PROFILE); + aco_set_defaults(&bridge_type, DEFAULT_BRIDGE_PROFILE, bridge_profile); + ao2_link(cfg->bridge_profiles, bridge_profile); + } + + user_profile = ao2_find(cfg->bridge_profiles, DEFAULT_USER_PROFILE, OBJ_KEY); + if (!user_profile) { + user_profile = user_profile_alloc(DEFAULT_USER_PROFILE); + if (!user_profile) { + return -1; + } + ast_log(AST_LOG_NOTICE, "Adding %s profile to app_confbridge\n", DEFAULT_USER_PROFILE); + aco_set_defaults(&user_type, DEFAULT_USER_PROFILE, user_profile); + ao2_link(cfg->user_profiles, user_profile); + } + + return 0; +} + int conf_load_config(int reload) { if (!reload) { diff --git a/configs/confbridge.conf.sample b/configs/confbridge.conf.sample index 7484b28aeb..0a40ea2fcb 100644 --- a/configs/confbridge.conf.sample +++ b/configs/confbridge.conf.sample @@ -9,6 +9,10 @@ ; automatically to all ConfBridge instances invoked without ; a user, or bridge argument. No menu is applied by default. ; +; Note that while properties of the default_user or default_bridge +; profile can be overridden, if removed, they will be automatically +; added and made available to the dialplan upon module load. +; ; --- ConfBridge User Profile Options --- [default_user]