2011-12-23 19:45:18 -05:00
|
|
|
/*
|
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
* Copyright (C) 2005-2011, Anthony Minessale II <anthm@freeswitch.org>
|
|
|
|
*
|
|
|
|
* Version: MPL 1.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Marc Olivier Chouinard <mochouinard@moctel.com>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* config.c -- VoiceMail IVR Config
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <switch.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
const char *global_cf = "voicemail_ivr.conf";
|
|
|
|
|
2011-12-26 02:52:32 -05:00
|
|
|
static void append_event_profile(vmivr_menu_t *menu);
|
|
|
|
static void populate_dtmfa_from_event(vmivr_menu_t *menu);
|
|
|
|
|
|
|
|
void menu_init(vmivr_profile_t *profile, vmivr_menu_t *menu) {
|
2011-12-25 01:49:22 -05:00
|
|
|
switch_xml_t cfg, xml, x_profiles, x_profile, x_keys, x_phrases, x_menus, x_menu, x_settings;
|
2011-12-23 19:45:18 -05:00
|
|
|
|
2011-12-26 02:52:32 -05:00
|
|
|
menu->profile = profile;
|
|
|
|
|
2011-12-23 19:45:18 -05:00
|
|
|
if (!(xml = switch_xml_open_cfg(global_cf, &cfg, NULL))) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", global_cf);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
if (!(x_profiles = switch_xml_child(cfg, "profiles"))) {
|
2011-12-26 02:52:32 -05:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No profiles group\n");
|
2011-12-23 19:45:18 -05:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2011-12-25 13:37:23 -05:00
|
|
|
if (profile->event_settings && menu->event_settings) {
|
|
|
|
/* TODO Replace this with a switch_event_merge_not_set(...) */
|
|
|
|
switch_event_t *menu_default;
|
|
|
|
switch_event_create(&menu_default, SWITCH_EVENT_REQUEST_PARAMS);
|
|
|
|
switch_event_merge(menu_default, menu->event_settings);
|
|
|
|
switch_event_destroy(&menu->event_settings);
|
|
|
|
|
2011-12-25 01:49:22 -05:00
|
|
|
switch_event_create(&menu->event_settings, SWITCH_EVENT_REQUEST_PARAMS);
|
2011-12-25 13:37:23 -05:00
|
|
|
switch_event_merge(menu->event_settings, profile->event_settings);
|
|
|
|
switch_event_merge(menu->event_settings, menu_default);
|
|
|
|
switch_event_destroy(&menu_default);
|
|
|
|
}
|
2011-12-25 01:49:22 -05:00
|
|
|
|
|
|
|
|
2011-12-23 19:45:18 -05:00
|
|
|
if ((x_profile = switch_xml_find_child(x_profiles, "profile", "name", profile->name))) {
|
|
|
|
if ((x_menus = switch_xml_child(x_profile, "menus"))) {
|
|
|
|
if ((x_menu = switch_xml_find_child(x_menus, "menu", "name", menu->name))) {
|
2011-12-26 02:52:32 -05:00
|
|
|
|
2011-12-23 19:45:18 -05:00
|
|
|
if ((x_keys = switch_xml_child(x_menu, "keys"))) {
|
|
|
|
switch_event_import_xml(switch_xml_child(x_keys, "key"), "dtmf", "action", &menu->event_keys_dtmf);
|
|
|
|
switch_event_import_xml(switch_xml_child(x_keys, "key"), "action", "dtmf", &menu->event_keys_action);
|
|
|
|
switch_event_import_xml(switch_xml_child(x_keys, "key"), "action", "variable", &menu->event_keys_varname);
|
|
|
|
}
|
|
|
|
if ((x_phrases = switch_xml_child(x_menu, "phrases"))) {
|
|
|
|
switch_event_import_xml(switch_xml_child(x_phrases, "phrase"), "name", "value", &menu->event_phrases);
|
|
|
|
}
|
2011-12-25 01:49:22 -05:00
|
|
|
if ((x_settings = switch_xml_child(x_profile, "settings"))) {
|
|
|
|
switch_event_import_xml(switch_xml_child(x_settings, "param"), "name", "value", &menu->event_settings);
|
|
|
|
}
|
|
|
|
|
2011-12-23 19:45:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end:
|
|
|
|
if (xml)
|
|
|
|
switch_xml_free(xml);
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-12-26 02:52:32 -05:00
|
|
|
void menu_instance_init(vmivr_menu_t *menu) {
|
|
|
|
append_event_profile(menu);
|
|
|
|
|
|
|
|
populate_dtmfa_from_event(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
void menu_instance_free(vmivr_menu_t *menu) {
|
|
|
|
if (menu->phrase_params) {
|
|
|
|
switch_event_destroy(&menu->phrase_params);
|
|
|
|
}
|
|
|
|
memset(&menu->ivre_d, 0, sizeof(menu->ivre_d));
|
|
|
|
}
|
|
|
|
|
|
|
|
void menu_free(vmivr_menu_t *menu) {
|
2011-12-23 19:45:18 -05:00
|
|
|
if (menu->event_keys_dtmf) {
|
|
|
|
switch_event_destroy(&menu->event_keys_dtmf);
|
|
|
|
}
|
|
|
|
if (menu->event_keys_action) {
|
|
|
|
switch_event_destroy(&menu->event_keys_action);
|
|
|
|
}
|
|
|
|
if (menu->event_keys_varname) {
|
|
|
|
switch_event_destroy(&menu->event_keys_varname);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (menu->event_phrases) {
|
|
|
|
switch_event_destroy(&menu->event_phrases);
|
|
|
|
}
|
2011-12-25 13:37:23 -05:00
|
|
|
if (menu->event_settings) {
|
|
|
|
switch_event_destroy(&menu->event_settings);
|
|
|
|
}
|
2011-12-25 01:49:22 -05:00
|
|
|
|
2011-12-23 19:45:18 -05:00
|
|
|
}
|
|
|
|
|
2011-12-26 02:52:32 -05:00
|
|
|
static void append_event_profile(vmivr_menu_t *menu) {
|
|
|
|
|
|
|
|
if (!menu->phrase_params) {
|
|
|
|
switch_event_create(&menu->phrase_params, SWITCH_EVENT_REQUEST_PARAMS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Used for some appending function */
|
|
|
|
if (menu->profile && menu->profile->name && menu->profile->id && menu->profile->domain) {
|
|
|
|
switch_event_add_header(menu->phrase_params, SWITCH_STACK_BOTTOM, "VM-Profile", "%s", menu->profile->name);
|
|
|
|
switch_event_add_header(menu->phrase_params, SWITCH_STACK_BOTTOM, "VM-Account-ID", "%s", menu->profile->id);
|
|
|
|
switch_event_add_header(menu->phrase_params, SWITCH_STACK_BOTTOM, "VM-Account-Domain", "%s", menu->profile->domain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void populate_dtmfa_from_event(vmivr_menu_t *menu) {
|
|
|
|
int i = 0;
|
|
|
|
if (menu->event_keys_dtmf) {
|
|
|
|
switch_event_header_t *hp;
|
|
|
|
|
|
|
|
for (hp = menu->event_keys_dtmf->headers; hp; hp = hp->next) {
|
|
|
|
if (strlen(hp->name) < 3 && hp->value) { /* TODO This is a hack to discard default FS Events ! */
|
|
|
|
const char *varphrasename = switch_event_get_header(menu->event_keys_varname, hp->value);
|
|
|
|
menu->dtmfa[i++] = hp->name;
|
|
|
|
|
|
|
|
if (varphrasename && !zstr(varphrasename)) {
|
|
|
|
switch_event_add_header(menu->phrase_params, SWITCH_STACK_BOTTOM, varphrasename, "%s", hp->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
menu->dtmfa[i++] = '\0';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-23 19:45:18 -05:00
|
|
|
vmivr_profile_t *get_profile(switch_core_session_t *session, const char *profile_name)
|
|
|
|
{
|
|
|
|
vmivr_profile_t *profile = NULL;
|
2011-12-25 01:49:22 -05:00
|
|
|
switch_xml_t cfg, xml, x_profiles, x_profile, x_apis, x_settings, param;
|
2011-12-23 19:45:18 -05:00
|
|
|
|
|
|
|
if (!(xml = switch_xml_open_cfg(global_cf, &cfg, NULL))) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of %s failed\n", global_cf);
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
if (!(x_profiles = switch_xml_child(cfg, "profiles"))) {
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((x_profile = switch_xml_find_child(x_profiles, "profile", "name", profile_name))) {
|
|
|
|
if (!(profile = switch_core_session_alloc(session, sizeof(vmivr_profile_t)))) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Alloc Failure\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
profile->name = profile_name;
|
|
|
|
|
|
|
|
profile->current_msg = 0;
|
|
|
|
profile->current_msg_uuid = NULL;
|
|
|
|
|
|
|
|
profile->folder_name = VM_FOLDER_ROOT;
|
|
|
|
profile->folder_filter = VM_MSG_NOT_READ;
|
|
|
|
|
|
|
|
/* TODO Make the following configurable */
|
|
|
|
profile->api_profile = profile->name;
|
|
|
|
profile->menu_check_auth = "std_authenticate";
|
|
|
|
profile->menu_check_main = "std_main_menu";
|
|
|
|
profile->menu_check_terminate = "std_purge";
|
|
|
|
|
2011-12-25 13:37:23 -05:00
|
|
|
/* TODO Create event_settings and add default settings here */
|
|
|
|
|
2011-12-25 01:49:22 -05:00
|
|
|
if ((x_settings = switch_xml_child(x_profile, "settings"))) {
|
|
|
|
switch_event_import_xml(switch_xml_child(x_settings, "param"), "name", "value", &profile->event_settings);
|
|
|
|
}
|
|
|
|
|
2011-12-23 19:45:18 -05:00
|
|
|
if ((x_apis = switch_xml_child(x_profile, "apis"))) {
|
|
|
|
int total_options = 0;
|
|
|
|
int total_invalid_options = 0;
|
|
|
|
for (param = switch_xml_child(x_apis, "api"); param; param = param->next) {
|
|
|
|
char *var, *val;
|
|
|
|
if ((var = (char *) switch_xml_attr_soft(param, "name")) && (val = (char *) switch_xml_attr_soft(param, "value"))) {
|
|
|
|
if (!strcasecmp(var, "msg_undelete") && !profile->api_msg_undelete)
|
|
|
|
profile->api_msg_undelete = switch_core_session_strdup(session, val);
|
|
|
|
else if (!strcasecmp(var, "msg_delete") && !profile->api_msg_delete)
|
|
|
|
profile->api_msg_delete = switch_core_session_strdup(session, val);
|
|
|
|
else if (!strcasecmp(var, "msg_list") && !profile->api_msg_list)
|
|
|
|
profile->api_msg_list = switch_core_session_strdup(session, val);
|
|
|
|
else if (!strcasecmp(var, "msg_count") && !profile->api_msg_count)
|
|
|
|
profile->api_msg_count = switch_core_session_strdup(session, val);
|
|
|
|
else if (!strcasecmp(var, "msg_save") && !profile->api_msg_save)
|
|
|
|
profile->api_msg_save = switch_core_session_strdup(session, val);
|
|
|
|
else if (!strcasecmp(var, "msg_purge") && !profile->api_msg_purge)
|
|
|
|
profile->api_msg_purge = switch_core_session_strdup(session, val);
|
|
|
|
else if (!strcasecmp(var, "msg_get") && !profile->api_msg_get)
|
|
|
|
profile->api_msg_get = switch_core_session_strdup(session, val);
|
|
|
|
else if (!strcasecmp(var, "msg_forward") && !profile->api_msg_forward)
|
|
|
|
profile->api_msg_forward = switch_core_session_strdup(session, val);
|
|
|
|
else if (!strcasecmp(var, "pref_greeting_set") && !profile->api_pref_greeting_set)
|
|
|
|
profile->api_pref_greeting_set = switch_core_session_strdup(session, val);
|
|
|
|
else if (!strcasecmp(var, "pref_recname_set") && !profile->api_pref_recname_set)
|
|
|
|
profile->api_pref_recname_set = switch_core_session_strdup(session, val);
|
|
|
|
else if (!strcasecmp(var, "pref_password_set") && !profile->api_pref_password_set)
|
|
|
|
profile->api_pref_password_set = switch_core_session_strdup(session, val);
|
|
|
|
else if (!strcasecmp(var, "auth_login") && !profile->api_auth_login)
|
|
|
|
profile->api_auth_login = switch_core_session_strdup(session, val);
|
|
|
|
else
|
|
|
|
total_invalid_options++;
|
|
|
|
total_options++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (total_options - total_invalid_options != 12) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing api definition for profile '%s'\n", profile_name);
|
|
|
|
profile = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
switch_xml_free(xml);
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
2011-12-25 13:37:23 -05:00
|
|
|
void free_profile(vmivr_profile_t *profile) {
|
|
|
|
if (profile->event_settings) {
|
|
|
|
switch_event_destroy(&profile->event_settings);
|
|
|
|
}
|
|
|
|
}
|