提交 f2cba2aa authored 作者: Marc Olivier Chouinard's avatar Marc Olivier Chouinard

mod_voicemail_ivr: Added a missing menu in the conf.xml config. Also refactor…

mod_voicemail_ivr: Added a missing menu in the conf.xml config.  Also refactor nearly all the function name to something more standard.  Also tried to make the flow as simple as possible in the menu.c
上级 d1364ff5
......@@ -48,12 +48,27 @@
</keys>
</menu>
<menu name="std_main_menu">
<phrases>
<phrase name="msg_count" value="message_count@mtvoicemail" />
<phrase name="say_date" value="say_date_event@mtvoicemail" />
<phrase name="say_msg_number" value="say_message_number@mtvoicemail" />
<phrase name="menu_options" value="menu@mtvoicemail" />
</phrases>
<keys>
<key dtmf="1" action="new_msg:std_navigator" variable="VM-Key-Play-New-Messages" />
<key dtmf="2" action="saved_msg:std_navigator" variable="VM-Key-Play-Saved-Messages" />
<key dtmf="5" action="menu:std_preference" variable="VM-Key-Config-Menu"/>
<key dtmf="#" action="return" variable="VM-Key-Terminator" />
</keys>
</menu>
<menu name="std_navigator">
<!-- Not yet implemented - Open for comments
This will inherit the settings from the top profile settings. So if it global, put it inside the profile <settings>
<settings>
<param name="playback-order" value="newest-first" />
</settings>
<!-- Not yet implemented - Open for comments
This will inherit the settings from the top profile settings. So if it global, put it inside the profile <settings>
<settings>
<param name="playback-order" value="newest-first" />
</settings>
-->
<phrases>
<phrase name="msg_count" value="message_count@voicemail_ivr" />
......
......@@ -35,14 +35,20 @@
const char *global_cf = "voicemail_ivr.conf";
void populate_profile_menu_event(vmivr_profile_t *profile, vmivr_menu_profile_t *menu) {
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) {
switch_xml_t cfg, xml, x_profiles, x_profile, x_keys, x_phrases, x_menus, x_menu, x_settings;
menu->profile = profile;
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"))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No profiles group\n");
goto end;
}
......@@ -63,6 +69,7 @@ void populate_profile_menu_event(vmivr_profile_t *profile, vmivr_menu_profile_t
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))) {
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);
......@@ -85,7 +92,20 @@ end:
}
void free_profile_menu_event(vmivr_menu_profile_t *menu) {
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) {
if (menu->event_keys_dtmf) {
switch_event_destroy(&menu->event_keys_dtmf);
}
......@@ -105,6 +125,41 @@ void free_profile_menu_event(vmivr_menu_profile_t *menu) {
}
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';
}
vmivr_profile_t *get_profile(switch_core_session_t *session, const char *profile_name)
{
vmivr_profile_t *profile = NULL;
......
......@@ -29,6 +29,8 @@
* config.c -- VoiceMail IVR Config
*
*/
#include "ivr.h"
#ifndef _CONFIG_H_
#define _CONFIG_H_
......@@ -75,21 +77,29 @@ struct vmivr_profile {
};
typedef struct vmivr_profile vmivr_profile_t;
struct vmivr_menu_profile {
struct vmivr_menu {
const char *name;
vmivr_profile_t *profile;
switch_event_t *event_keys_action;
switch_event_t *event_keys_dtmf;
switch_event_t *event_keys_varname;
switch_event_t *event_settings;
switch_event_t *event_phrases;
char *dtmfa[16];
switch_event_t *phrase_params;
ivre_data_t ivre_d;
};
typedef struct vmivr_menu_profile vmivr_menu_profile_t;
typedef struct vmivr_menu vmivr_menu_t;
vmivr_profile_t *get_profile(switch_core_session_t *session, const char *profile_name);
void free_profile(vmivr_profile_t *profile);
void free_profile_menu_event(vmivr_menu_profile_t *menu);
void populate_profile_menu_event(vmivr_profile_t *profile, vmivr_menu_profile_t *menu);
void menu_init(vmivr_profile_t *profile, vmivr_menu_t *menu);
void menu_instance_init(vmivr_menu_t *menu);
void menu_instance_free(vmivr_menu_t *menu);
void menu_free(vmivr_menu_t *menu);
#endif /* _CONFIG_H_ */
......@@ -34,7 +34,7 @@
#include "ivr.h"
int match_dtmf(switch_core_session_t *session, dtmf_ss_t *loc) {
static int match_dtmf(switch_core_session_t *session, ivre_data_t *loc) {
switch_bool_t is_invalid[128] = { SWITCH_FALSE };
int i;
loc->potentialMatch = NULL;
......@@ -99,7 +99,7 @@ static switch_status_t cb_on_dtmf_ignore(switch_core_session_t *session, void *i
static switch_status_t cb_on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
{
dtmf_ss_t *loc = (dtmf_ss_t*) buf;
ivre_data_t *loc = (ivre_data_t*) buf;
switch (itype) {
case SWITCH_INPUT_TYPE_DTMF:
......@@ -146,7 +146,7 @@ static switch_status_t cb_on_dtmf(switch_core_session_t *session, void *input, s
return SWITCH_STATUS_SUCCESS;
}
switch_status_t captureMenuInitialize(dtmf_ss_t *loc, char **dtmf_accepted) {
switch_status_t ivre_init(ivre_data_t *loc, char **dtmf_accepted) {
int i;
memset(loc, 0, sizeof(*loc));
......@@ -158,7 +158,7 @@ switch_status_t captureMenuInitialize(dtmf_ss_t *loc, char **dtmf_accepted) {
return SWITCH_STATUS_SUCCESS;
}
switch_status_t playbackBufferDTMF(switch_core_session_t *session, const char *macro_name, const char *data, switch_event_t *event, const char *lang, int timeout) {
switch_status_t ivre_playback_dtmf_buffered(switch_core_session_t *session, const char *macro_name, const char *data, switch_event_t *event, const char *lang, int timeout) {
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_channel_t *channel = switch_core_session_get_channel(session);
......@@ -178,7 +178,7 @@ switch_status_t playbackBufferDTMF(switch_core_session_t *session, const char *m
}
switch_status_t captureMenu(switch_core_session_t *session, dtmf_ss_t *loc, const char *macro_name, const char *data, switch_event_t *event, const char *lang, int timeout) {
switch_status_t ivre_playback(switch_core_session_t *session, ivre_data_t *loc, const char *macro_name, const char *data, switch_event_t *event, const char *lang, int timeout) {
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_channel_t *channel = switch_core_session_get_channel(session);
......@@ -210,7 +210,7 @@ switch_status_t captureMenu(switch_core_session_t *session, dtmf_ss_t *loc, cons
return status;
}
switch_status_t captureMenuRecord(switch_core_session_t *session, dtmf_ss_t *loc, switch_event_t *event, const char *file_path, switch_file_handle_t *fh, int max_record_len) {
switch_status_t ivre_record(switch_core_session_t *session, ivre_data_t *loc, switch_event_t *event, const char *file_path, switch_file_handle_t *fh, int max_record_len) {
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_channel_t *channel = switch_core_session_get_channel(session);
......
......@@ -29,7 +29,11 @@
* ivr.h -- VoiceMail IVR Engine
*
*/
struct dtmf_ss {
#ifndef _IVRE_H_
#define _IVRE_H_
struct ivre_data {
char dtmf_stored[128];
int dtmf_received;
char dtmf_accepted[16][128];
......@@ -41,7 +45,7 @@ struct dtmf_ss {
const char *completeMatch;
char terminate_key;
};
typedef struct dtmf_ss dtmf_ss_t;
typedef struct ivre_data ivre_data_t;
#define RES_WAITFORMORE 0
#define RES_FOUND 1
......@@ -53,9 +57,9 @@ typedef struct dtmf_ss dtmf_ss_t;
#define MAX_DTMF_SIZE_OPTION 32
switch_status_t captureMenu(switch_core_session_t *session, dtmf_ss_t *loc, const char *macro_name, const char *data, switch_event_t *event, const char *lang, int timeout);
switch_status_t captureMenuRecord(switch_core_session_t *session, dtmf_ss_t *loc, switch_event_t *event, const char *file_path, switch_file_handle_t *fh, int max_record_len);
switch_status_t captureMenuInitialize(dtmf_ss_t *loc, char **dtmf_accepted);
switch_status_t playbackBufferDTMF(switch_core_session_t *session, const char *macro_name, const char *data, switch_event_t *event, const char *lang, int timeout);
switch_status_t ivre_init(ivre_data_t *loc, char **dtmf_accepted);
switch_status_t ivre_playback(switch_core_session_t *session, ivre_data_t *loc, const char *macro_name, const char *data, switch_event_t *event, const char *lang, int timeout);
switch_status_t ivre_record(switch_core_session_t *session, ivre_data_t *loc, switch_event_t *event, const char *file_path, switch_file_handle_t *fh, int max_record_len);
switch_status_t ivre_playback_dtmf_buffered(switch_core_session_t *session, const char *macro_name, const char *data, switch_event_t *event, const char *lang, int timeout);
#endif
......@@ -45,8 +45,8 @@ void vmivr_menu_record_greeting_with_slot(switch_core_session_t *session, vmivr_
void vmivr_menu_preference(switch_core_session_t *session, vmivr_profile_t *profile);
void vmivr_menu_forward(switch_core_session_t *session, vmivr_profile_t *profile);
switch_status_t vmivr_menu_record(switch_core_session_t *session, vmivr_profile_t *profile, vmivr_menu_profile_t menu, const char *file_name);
char *vmivr_menu_get_input_set(switch_core_session_t *session, vmivr_profile_t *profile, vmivr_menu_profile_t menu, const char *input_mask);
switch_status_t vmivr_menu_record(switch_core_session_t *session, vmivr_profile_t *profile, vmivr_menu_t menu, const char *file_name);
char *vmivr_menu_get_input_set(switch_core_session_t *session, vmivr_profile_t *profile, vmivr_menu_t menu, const char *input_mask);
struct vmivr_menu_function {
......
......@@ -124,34 +124,6 @@ switch_status_t vmivr_api_execute(switch_core_session_t *session, const char *ap
return status;
}
void append_event_profile(switch_event_t *phrase_params, vmivr_profile_t *profile, vmivr_menu_profile_t menu) {
/* Used for some appending function */
if (profile->name && profile->id && profile->domain) {
switch_event_add_header(phrase_params, SWITCH_STACK_BOTTOM, "VM-Profile", "%s", profile->name);
switch_event_add_header(phrase_params, SWITCH_STACK_BOTTOM, "VM-Account-ID", "%s", profile->id);
switch_event_add_header(phrase_params, SWITCH_STACK_BOTTOM, "VM-Account-Domain", "%s", profile->domain);
}
}
void populate_dtmfa_from_event(switch_event_t *phrase_params, vmivr_profile_t *profile, vmivr_menu_profile_t menu, char **dtmfa) {
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);
dtmfa[i++] = hp->name;
if (varphrasename && !zstr(varphrasename)) {
switch_event_add_header(phrase_params, SWITCH_STACK_BOTTOM, varphrasename, "%s", hp->name);
}
}
}
}
}
void append_event_message(switch_core_session_t *session, vmivr_profile_t *profile, switch_event_t *phrase_params, switch_event_t *msg_list_event, size_t current_msg) {
char *varname;
......
......@@ -37,11 +37,9 @@
switch_status_t vmivr_merge_files(const char** inputs, const char *output);
void append_event_message(switch_core_session_t *session, vmivr_profile_t *profile, switch_event_t *phrase_params, switch_event_t *msg_list_event, size_t current_msg);
void append_event_profile(switch_event_t *phrase_params, vmivr_profile_t *profile, vmivr_menu_profile_t menu);
char *generate_random_file_name(switch_core_session_t *session, const char *mod_name, char *file_extension);
switch_event_t *jsonapi2event(switch_core_session_t *session, switch_event_t *apply_event, const char *api, const char *data);
switch_status_t vmivr_merge_media_files(const char** inputs, const char *output);
switch_status_t vmivr_api_execute(switch_core_session_t *session, const char *apiname, const char *arguments);
void populate_dtmfa_from_event(switch_event_t *phrase_params, vmivr_profile_t *profile, vmivr_menu_profile_t menu, char **dtmfa);
#endif /* _UTIL_H_ */
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论