void mtvm_menu_preference(switch_core_session_t *session, vmivr_profile_t *profile) { switch_channel_t *channel = switch_core_session_get_channel(session); int retry; vmivr_menu_profile_t menu = { "std_preference" }; /* Initialize Menu Configs */ populate_profile_menu_event(profile, &menu); if (!menu.event_keys_dtmf || !menu.event_phrases) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases and Keys\n"); return; } for (retry = MAX_ATTEMPT; switch_channel_ready(channel) && retry > 0; retry--) { dtmf_ss_t loc; char *dtmfa[16] = { 0 }; switch_event_t *phrase_params = NULL; switch_event_create(&phrase_params, SWITCH_EVENT_REQUEST_PARAMS); append_event_profile(phrase_params, profile, menu); populate_dtmfa_from_event(phrase_params, profile, menu, dtmfa); captureMenuInitialize(&loc, dtmfa); captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, phrase_params, NULL, DEFAULT_IVR_TIMEOUT); if (loc.result == RES_TIMEOUT) { /* TODO Ask for the prompt Again IF retry != 0 */ } else if (loc.result == RES_INVALID) { /* TODO Say invalid option, and ask for the prompt again IF retry != 0 */ } else if (loc.result == RES_FOUND) { /* Matching DTMF Key Pressed */ const char *action = switch_event_get_header(menu.event_keys_dtmf, loc.dtmf_stored); /* Reset the try count */ retry = MAX_ATTEMPT; if (action) { if (!strcasecmp(action, "return")) { /* Return to the previous menu */ retry = -1; } else if (!strncasecmp(action, "menu:", 5)) { /* Sub Menu */ void (*fPtr)(switch_core_session_t *session, vmivr_profile_t *profile) = mtvm_get_menu_function(action+5); if (fPtr) { fPtr(session, profile); } } } } switch_event_destroy(&phrase_params); } free_profile_menu_event(&menu); }
void vmivr_menu_preference(switch_core_session_t *session, vmivr_profile_t *profile) { switch_channel_t *channel = switch_core_session_get_channel(session); int retry; vmivr_menu_t menu = { "std_preference" }; /* Initialize Menu Configs */ menu_init(profile, &menu); if (!menu.event_keys_dtmf || !menu.event_phrases) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases or Keys in menu '%s'\n", menu.name); goto end; } for (retry = menu.ivr_maximum_attempts; switch_channel_ready(channel) && retry > 0; retry--) { menu_instance_init(&menu); switch_event_add_header(menu.phrase_params, SWITCH_STACK_BOTTOM, "IVR-Retry-Left", "%d", retry); ivre_init(&menu.ivre_d, menu.dtmfa); ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, menu.phrase_params, NULL, menu.ivr_entry_timeout); if (menu.ivre_d.result == RES_TIMEOUT) { ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "timeout"), NULL, NULL, NULL, 0); } else if (menu.ivre_d.result == RES_INVALID) { ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "invalid"), NULL, NULL, NULL, 0); } else if (menu.ivre_d.result == RES_FOUND) { /* Matching DTMF Key Pressed */ const char *action = switch_event_get_header(menu.event_keys_dtmf, menu.ivre_d.dtmf_stored); /* Reset the try count */ retry = menu.ivr_maximum_attempts; if (action) { if (!strcasecmp(action, "return")) { /* Return to the previous menu */ retry = -1; } else if (!strncasecmp(action, "menu:", 5)) { /* Sub Menu */ void (*fPtr)(switch_core_session_t *session, vmivr_profile_t *profile) = vmivr_get_menu_function(action+5); if (fPtr) { fPtr(session, profile); } } } } menu_instance_free(&menu); } end: menu_free(&menu); }
switch_status_t vmivr_menu_record(switch_core_session_t *session, vmivr_profile_t *profile, vmivr_menu_t *menu, const char *file_name) { switch_status_t status = SWITCH_STATUS_FALSE; switch_channel_t *channel = switch_core_session_get_channel(session); int retry; switch_bool_t record_prompt = SWITCH_TRUE; switch_bool_t listen_recording = SWITCH_FALSE; switch_bool_t play_instruction = SWITCH_TRUE; if (!menu->event_keys_dtmf || !menu->event_phrases) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases or Keys in menu '%s'\n", menu->name); goto end; } for (retry = menu->ivr_maximum_attempts; switch_channel_ready(channel) && retry > 0; retry--) { switch_file_handle_t fh = { 0 }; const char *rec_silence_hits = switch_event_get_header(menu->event_settings, "Record-Silence-Hits"); const char *rec_silence_threshold = switch_event_get_header(menu->event_settings, "Record-Silence-Threshold"); const char *rec_silence_samplerate = switch_event_get_header(menu->event_settings, "Record-Sample-Rate"); const char *rec_maximum_length = switch_event_get_header(menu->event_settings, "Record-Maximum-Length"); const char *rec_minimum_length = switch_event_get_header(menu->event_settings, "Record-Minimum-Length"); switch_size_t record_length = 0; /* Prepare Recording File Handle */ fh.thresh = atoi(rec_silence_threshold); fh.silence_hits = atoi(rec_silence_hits); if (rec_silence_samplerate) { fh.samplerate = atoi(rec_silence_samplerate); } menu_instance_init(menu); switch_event_add_header(menu->phrase_params, SWITCH_STACK_BOTTOM, "IVR-Retry-Left", "%d", retry); ivre_init(&menu->ivre_d, menu->dtmfa); if (record_prompt) { if (play_instruction) { ivre_playback(session, &menu->ivre_d, switch_event_get_header(menu->event_phrases, "instructions"), NULL, menu->phrase_params, NULL, 0); } play_instruction = SWITCH_TRUE; ivre_record(session, &menu->ivre_d, menu->phrase_params, file_name, &fh, atoi(rec_maximum_length), &record_length); } else { if (listen_recording) { switch_event_add_header(menu->phrase_params, SWITCH_STACK_BOTTOM, "VM-Record-File-Path", "%s", file_name); ivre_playback(session, &menu->ivre_d, switch_event_get_header(menu->event_phrases, "play_recording"), NULL, menu->phrase_params, NULL, 0); listen_recording = SWITCH_FALSE; } ivre_playback(session, &menu->ivre_d, switch_event_get_header(menu->event_phrases, "menu_options"), NULL, menu->phrase_params, NULL, menu->ivr_entry_timeout); } if (menu->ivre_d.recorded_audio) { /* Reset the try count */ retry = menu->ivr_maximum_attempts; if (rec_minimum_length && record_length < atoi(rec_minimum_length)) { ivre_playback_dtmf_buffered(session, switch_event_get_header(menu->event_phrases, "too_short"), NULL, NULL, NULL, 0); unlink(file_name); } else { record_prompt = SWITCH_FALSE; } } else if (menu->ivre_d.result == RES_TIMEOUT) { ivre_playback_dtmf_buffered(session, switch_event_get_header(menu->event_phrases, "timeout"), NULL, NULL, NULL, 0); } else if (menu->ivre_d.result == RES_INVALID) { ivre_playback_dtmf_buffered(session, switch_event_get_header(menu->event_phrases, "invalid"), NULL, NULL, NULL, 0); } else if (menu->ivre_d.result == RES_FOUND) { /* Matching DTMF Key Pressed */ const char *action = switch_event_get_header(menu->event_keys_dtmf, menu->ivre_d.dtmf_stored); /* Reset the try count */ retry = menu->ivr_maximum_attempts; if (action) { if (!strcasecmp(action, "listen")) { /* Listen */ listen_recording = SWITCH_TRUE; } else if (!strcasecmp(action, "save")) { retry = -1; status = SWITCH_STATUS_SUCCESS; } else if (!strcasecmp(action, "rerecord")) { record_prompt = SWITCH_TRUE; } else if (!strcasecmp(action, "skip_instruction")) { /* Skip Recording Greeting */ play_instruction = SWITCH_FALSE; } else if (!strncasecmp(action, "menu:", 5)) { /* Sub Menu */ void (*fPtr)(switch_core_session_t *session, vmivr_profile_t *profile) = vmivr_get_menu_function(action+5); if (fPtr) { fPtr(session, profile); } } else if (!strcasecmp(action, "return")) { /* Return */ retry = -1; } } } menu_instance_free(menu); } end: return status; }
void vmivr_menu_main(switch_core_session_t *session, vmivr_profile_t *profile) { switch_channel_t *channel = switch_core_session_get_channel(session); vmivr_menu_t menu = { "std_main_menu" }; int retry; switch_bool_t action_on_new_message_occured = SWITCH_FALSE; /* Initialize Menu Configs */ menu_init(profile, &menu); if (!menu.event_keys_dtmf || !menu.event_phrases) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases or Keys in menu '%s'\n", menu.name); goto end; } for (retry = menu.ivr_maximum_attempts; switch_channel_ready(channel) && retry > 0; retry--) { char *cmd = NULL; const char *action = NULL; const char *action_on_new_message = switch_event_get_header(menu.event_settings, "Action-On-New-Message"); menu_instance_init(&menu); switch_event_add_header(menu.phrase_params, SWITCH_STACK_BOTTOM, "IVR-Retry-Left", "%d", retry); ivre_init(&menu.ivre_d, menu.dtmfa); cmd = switch_core_session_sprintf(session, "json %s %s %s %s", profile->api_profile, profile->domain, profile->id, profile->folder_name); jsonapi_populate_event(session, menu.phrase_params, profile->api_msg_count, cmd); /* Verify that phrases returned values, if not, exit */ if (!switch_event_get_header(menu.phrase_params, "VM-Total-New-Messages")) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Return from API is invalid. Check that the context exist on your DB backend\n"); menu_instance_free(&menu); break; } ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "msg_count"), NULL, menu.phrase_params, NULL, 0); if (atoi(switch_event_get_header(menu.phrase_params, "VM-Total-New-Messages")) > 0 && menu.ivre_d.result == RES_WAITFORMORE && !action_on_new_message_occured && action_on_new_message) { menu.ivre_d.result = RES_FOUND; action = action_on_new_message; action_on_new_message_occured = SWITCH_TRUE; } else { ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, menu.phrase_params, NULL, menu.ivr_entry_timeout); } if (menu.ivre_d.result == RES_TIMEOUT) { ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "timeout"), NULL, NULL, NULL, 0); } else if (menu.ivre_d.result == RES_INVALID) { ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "invalid"), NULL, NULL, NULL, 0); } else if (menu.ivre_d.result == RES_FOUND) { /* Matching DTMF Key Pressed */ if (!action) { action = switch_event_get_header(menu.event_keys_dtmf, menu.ivre_d.dtmf_stored); } /* Reset the try count */ retry = menu.ivr_maximum_attempts; if (action) { if (!strncasecmp(action, "new_msg:", 8)) { void (*fPtr)(switch_core_session_t *session, vmivr_profile_t *profile) = vmivr_get_menu_function(action+8); profile->folder_filter = VM_MSG_NEW; if (fPtr) { fPtr(session, profile); } } else if (!strncasecmp(action, "saved_msg:", 10)) { void (*fPtr)(switch_core_session_t *session, vmivr_profile_t *profile) = vmivr_get_menu_function(action+10); profile->folder_filter = VM_MSG_SAVED; if (fPtr) { fPtr(session, profile); } } else if (!strcasecmp(action, "return")) { /* Return to the previous menu */ retry = -1; } else if (!strncasecmp(action, "menu:", 5)) { /* Sub Menu */ void (*fPtr)(switch_core_session_t *session, vmivr_profile_t *profile) = vmivr_get_menu_function(action+5); if (fPtr) { fPtr(session, profile); } } } } menu_instance_free(&menu); } end: menu_free(&menu); }
void vmivr_menu_forward(switch_core_session_t *session, vmivr_profile_t *profile) { vmivr_menu_t menu = { "std_forward_ask_prepend" }; switch_channel_t *channel = switch_core_session_get_channel(session); const char *prepend_filepath = NULL; int retry; switch_bool_t forward_msg = SWITCH_FALSE; /* Initialize Menu Configs */ menu_init(profile, &menu); if (!menu.event_keys_dtmf || !menu.event_phrases) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases or Keys in menu '%s'\n", menu.name); goto end; } for (retry = menu.ivr_maximum_attempts; switch_channel_ready(channel) && retry > 0; retry--) { menu_instance_init(&menu); switch_event_add_header(menu.phrase_params, SWITCH_STACK_BOTTOM, "IVR-Retry-Left", "%d", retry); ivre_init(&menu.ivre_d, menu.dtmfa); ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, menu.phrase_params, NULL, menu.ivr_entry_timeout); if (menu.ivre_d.result == RES_TIMEOUT) { ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "timeout"), NULL, NULL, NULL, 0); } else if (menu.ivre_d.result == RES_INVALID) { ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "invalid"), NULL, NULL, NULL, 0); } else if (menu.ivre_d.result == RES_FOUND) { /* Matching DTMF Key Pressed */ const char *action = switch_event_get_header(menu.event_keys_dtmf, menu.ivre_d.dtmf_stored); /* Reset the try count */ retry = menu.ivr_maximum_attempts; if (action) { if (!strcasecmp(action, "return")) { /* Return to the previous menu */ retry = -1; forward_msg = SWITCH_FALSE; } else if (!strcasecmp(action, "prepend")) { /* Prepend record msg */ vmivr_menu_t sub_menu = { "std_record_message" }; const char *tmp_filepath = NULL; const char *record_format = NULL; switch_status_t status; /* Initialize Menu Configs */ menu_init(profile, &sub_menu); record_format = switch_event_get_header(sub_menu.event_settings, "Record-Format"); tmp_filepath = generate_random_file_name(session, "voicemail_ivr", record_format); status = vmivr_menu_record(session, profile, &sub_menu, tmp_filepath); if (status == SWITCH_STATUS_SUCCESS) { //char *cmd = switch_core_session_sprintf(session, "%s %s %s %d %s", profile->api_profile, profile->domain, profile->id, gnum, tmp_filepath); //char *str_num = switch_core_session_sprintf(session, "%d", gnum); //vmivr_api_execute(session, profile->api_pref_greeting_set, cmd); //ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "selected_slot"), str_num, NULL, NULL, 0); prepend_filepath = tmp_filepath; retry = -1; forward_msg = SWITCH_TRUE; } else { ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "record_failed"), NULL, NULL, NULL, 0); } menu_free(&sub_menu); } else if (!strcasecmp(action, "forward")) { /* Forward without prepend msg */ retry = -1; forward_msg = SWITCH_TRUE; } else if (!strncasecmp(action, "menu:", 5)) { /* Sub Menu */ void (*fPtr)(switch_core_session_t *session, vmivr_profile_t *profile) = vmivr_get_menu_function(action+5); if (fPtr) { fPtr(session, profile); } } } } menu_instance_free(&menu); } /* Ask Extension to Forward */ if (forward_msg) { for (retry = menu.ivr_maximum_attempts; switch_channel_ready(channel) && retry > 0; retry--) { const char *id = NULL; vmivr_menu_t sub_menu = { "std_forward_ask_extension" }; /* Initialize Menu Configs */ menu_init(profile, &sub_menu); switch_event_add_header(sub_menu.phrase_params, SWITCH_STACK_BOTTOM, "IVR-Retry-Left", "%d", retry); id = vmivr_menu_get_input_set(session, profile, &sub_menu, "X."); if (id) { const char *cmd = switch_core_session_sprintf(session, "%s %s %s %s %s %s %s%s%s", profile->api_profile, profile->domain, profile->id, profile->current_msg_uuid, profile->domain, id, prepend_filepath?" ":"", prepend_filepath?prepend_filepath:"" ); if (vmivr_api_execute(session, profile->api_msg_forward, cmd) == SWITCH_STATUS_SUCCESS) { ivre_playback_dtmf_buffered(session, switch_event_get_header(sub_menu.event_phrases, "ack"), "saved", NULL, NULL, 0); retry = -1; } else { ivre_playback_dtmf_buffered(session, switch_event_get_header(sub_menu.event_phrases, "invalid_extension"), NULL, NULL, NULL, 0); } } else { ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "invalid_input"), NULL, NULL, NULL, 0); } menu_free(&sub_menu); /* TODO add Confirmation of the transfered number */ } /* TODO Ask if we want to transfer the msg to more person */ } end: menu_free(&menu); }
void vmivr_menu_navigator(switch_core_session_t *session, vmivr_profile_t *profile) { switch_channel_t *channel = switch_core_session_get_channel(session); switch_event_t *msg_list_params = NULL; size_t msg_count = 0; size_t current_msg = 1; size_t next_msg = current_msg; size_t previous_msg = current_msg; char *cmd = NULL; int retry; /* Different switch to control playback of phrases */ switch_bool_t initial_count_played = SWITCH_FALSE; switch_bool_t skip_header = SWITCH_FALSE; switch_bool_t skip_playback = SWITCH_FALSE; switch_bool_t msg_deleted = SWITCH_FALSE; switch_bool_t msg_undeleted = SWITCH_FALSE; switch_bool_t msg_saved = SWITCH_FALSE; vmivr_menu_t menu = { "std_navigator" }; /* Initialize Menu Configs */ menu_init(profile, &menu); if (!menu.event_keys_dtmf || !menu.event_phrases) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases or Keys in menu '%s'\n", menu.name); goto done; } /* Get VoiceMail List And update msg count */ cmd = switch_core_session_sprintf(session, "json %s %s %s %s %s", profile->api_profile, profile->domain, profile->id, profile->folder_name, profile->folder_filter); msg_list_params = jsonapi2event(session, profile->api_msg_list, cmd); if (msg_list_params) { msg_count = atol(switch_event_get_header(msg_list_params,"VM-List-Count")); if (msg_count == 0) { goto done; } } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "API message list return invalid result : %s(%s)\n", profile->api_msg_list, cmd); goto done; } /* TODO Add Detection of new message and notify the user */ for (retry = menu.ivr_maximum_attempts; switch_channel_ready(channel) && retry > 0; retry--) { switch_core_session_message_t msg = { 0 }; char cid_buf[1024] = ""; menu_instance_init(&menu); switch_event_add_header(menu.phrase_params, SWITCH_STACK_BOTTOM, "IVR-Retry-Left", "%d", retry); previous_msg = current_msg; ivre_init(&menu.ivre_d, menu.dtmfa); /* Prompt related to previous Message here */ append_event_message(session, profile, menu.phrase_params, msg_list_params, previous_msg); if (msg_deleted) { msg_deleted = SWITCH_FALSE; ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "ack"), "deleted", menu.phrase_params, NULL, 0); } if (msg_undeleted) { msg_undeleted = SWITCH_FALSE; ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "ack"), "undeleted", menu.phrase_params, NULL, 0); } if (msg_saved) { msg_saved = SWITCH_FALSE; ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "ack"), "saved", menu.phrase_params, NULL, 0); } switch_event_del_header(menu.phrase_params, "VM-Message-Flags"); /* Simple Protection to not go out of msg list scope */ if (next_msg == 0) { next_msg = 1; } else if (next_msg > msg_count) { next_msg = msg_count; ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "no_more_messages"), NULL, NULL, NULL, 0); } current_msg = next_msg; /* Prompt related the current message */ append_event_message(session, profile, menu.phrase_params, msg_list_params, current_msg); /* Used for extra control in phrases */ switch_event_add_header(menu.phrase_params, SWITCH_STACK_BOTTOM, "VM-List-Count", "%"SWITCH_SIZE_T_FMT, msg_count); /* Display MSG CID/Name to caller */ switch_snprintf(cid_buf, sizeof(cid_buf), "%s|%s", switch_str_nil(switch_event_get_header(menu.phrase_params, "VM-Message-Caller-Number")), switch_str_nil(switch_event_get_header(menu.phrase_params, "VM-Message-Caller-Name"))); msg.from = __FILE__; msg.string_arg = cid_buf; msg.message_id = SWITCH_MESSAGE_INDICATE_DISPLAY; switch_core_session_receive_message(session, &msg); /* Save in profile the current msg info for other menu processing AND restoration of our current position */ profile->current_msg = current_msg; profile->current_msg_uuid = switch_core_session_strdup(session, switch_event_get_header(menu.phrase_params, "VM-Message-UUID")); /* TODO check if msg is gone (purged by another session, notify user and auto jump to next message or something) */ if (!skip_header) { if (!initial_count_played) { cmd = switch_core_session_sprintf(session, "json %s %s %s", profile->api_profile, profile->domain, profile->id); jsonapi_populate_event(session, menu.phrase_params, profile->api_msg_count, cmd); initial_count_played = SWITCH_TRUE; // TODO ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "msg_count"), NULL, menu.phrase_params, NULL, 0); } if (msg_count > 0) { ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "say_msg_number"), NULL, menu.phrase_params, NULL, 0); ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "say_date"), NULL, menu.phrase_params, NULL, 0); } } if (msg_count > 0 && !skip_playback) { /* TODO Update the Read date of a message (When msg start, or when it listen compleatly ??? To be determined */ ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "play_message"), NULL, menu.phrase_params, NULL, 0); } skip_header = SWITCH_FALSE; skip_playback = SWITCH_FALSE; ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, menu.phrase_params, NULL, menu.ivr_entry_timeout); if (menu.ivre_d.result == RES_TIMEOUT) { ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "timeout"), NULL, NULL, NULL, 0); } else if (menu.ivre_d.result == RES_INVALID) { ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "invalid"), NULL, NULL, NULL, 0); } else if (menu.ivre_d.result == RES_FOUND) { /* Matching DTMF Key Pressed */ const char *action = switch_event_get_header(menu.event_keys_dtmf, menu.ivre_d.dtmf_stored); /* Reset the try count */ retry = menu.ivr_maximum_attempts; action: if (action) { if (!strcasecmp(action, "skip_intro")) { /* Skip Header / Play the recording again */ skip_header = SWITCH_TRUE; } else if (!strcasecmp(action, "next_msg")) { /* Next Message */ next_msg++; } else if (!strcasecmp(action, "prev_msg")) { /* Previous Message */ next_msg--; } else if (!strcasecmp(action, "delete_msg")) { /* Delete / Undelete Message */ const char *msg_flags = switch_event_get_header(menu.phrase_params, "VM-Message-Flags"); if (!msg_flags || strncasecmp(msg_flags, "delete", 6)) { const char *action_on_delete = switch_event_get_header(menu.event_settings, "Nav-Action-On-Delete"); cmd = switch_core_session_sprintf(session, "%s %s %s %s", profile->api_profile, profile->domain, profile->id, switch_event_get_header(menu.phrase_params, "VM-Message-UUID")); vmivr_api_execute(session, profile->api_msg_delete, cmd); msg_deleted = SWITCH_TRUE; if (action_on_delete) { action = action_on_delete; goto action; } else { skip_header = skip_playback = SWITCH_TRUE; } } else { cmd = switch_core_session_sprintf(session, "%s %s %s %s", profile->api_profile, profile->domain, profile->id, switch_event_get_header(menu.phrase_params, "VM-Message-UUID")); vmivr_api_execute(session, profile->api_msg_undelete, cmd); msg_undeleted = SWITCH_TRUE; } } else if (!strcasecmp(action, "save_msg")) { /* Save Message */ cmd = switch_core_session_sprintf(session, "%s %s %s %s", profile->api_profile, profile->domain, profile->id, switch_event_get_header(menu.phrase_params, "VM-Message-UUID")); vmivr_api_execute(session, profile->api_msg_save, cmd); msg_saved = SWITCH_TRUE; } else if (!strcasecmp(action, "callback")) { /* CallBack caller */ const char *cid_num = switch_event_get_header(menu.phrase_params, "VM-Message-Caller-Number"); if (cid_num) { /* TODO add detection for private number */ switch_core_session_execute_exten(session, cid_num, "XML", profile->domain); } else { /* TODO Some error msg that the msg doesn't contain a caller number */ } } else if (!strncasecmp(action, "menu:", 5)) { /* Sub Menu */ void (*fPtr)(switch_core_session_t *session, vmivr_profile_t *profile) = vmivr_get_menu_function(action+5); if (fPtr) { fPtr(session, profile); } } else if (!strcasecmp(action, "return")) { /* Return */ retry = -1; } } } /* IF the API to get the message returned us a COPY of the file menu.ivre_dally (temp file create from a DB or from a web server), delete it */ if (switch_true(switch_event_get_header(menu.phrase_params, "VM-Message-Private-Local-Copy"))) { const char *file_path = switch_event_get_header(menu.phrase_params, "VM-Message-File-Path"); if (file_path && unlink(file_path) != 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Failed to delete temp file [%s]\n", file_path); } } menu_instance_free(&menu); } done: switch_event_destroy(&msg_list_params); menu_free(&menu); return; }
bool MshFileImporter::doRead(hHybridMesh * mesh) { if(Init(_file_name)) { assert(_file.good()); hHybridMesh & m(*mesh); std::string txt; const int bufS=1024; char buf[bufS]={0}; assert(_vert_count > 0); assert(_elem_count > 0); _file >> std::skipws; // VERTS out_stream << "\nMshFileImporter: reading verts:\n"; _file.ignore(1000,eol); // ignore first line _file >> _vert_count; // read number of vertices m.vertices_.reserve(_vert_count); assert(_file.good()); while(_vert_readed < _vert_count) { int tmp0(0); Vertex & v = *m.vertices_.newObj(NULL); _file >> tmp0; // vert number _file >> v.coords_[0] >> v.coords_[1] >> v.coords_[2]; ++_vert_readed; out_stream << "\r" << _vert_readed; assert(_file.good()); } // !VERTS // ELEMENTS _file.ignore(1000,eol); // ignore line $ENDNOD _file.ignore(1000,eol); // ignore line $ELM _file >> _elem_count; m.elements_.reserve(_elem_count, _elem_count * sizeof(ElemPrism)); m.faces_.reserve(_elem_count*5, _elem_count*5* sizeof(Face4)); m.edges_.reserve(_elem_count*9, _elem_count*9*sizeof(Edge)); assert(!_file.eof()); assert(!_file.bad()); if(_file.fail()) { _file.clear(); } assert(_file.good()); do { // for each element block do { // find block begining _file >> txt; _file.ignore(bufS,eol); //out_stream << txt << std::endl; } while((txt != "EBLOCK") && !_file.eof()); _file.getline(buf,bufS); //out_stream << buf << std::endl; out_stream << "\nInFileImporter: reading elements:" << std::endl; register EBlockLine block; char nextChar(0); _file >> nextChar; while( (nextChar != '-') && !_file.eof()) { // read block elems assert(_file.good()); _file.putback(nextChar); _file >> block; if(block.good) { hObj * obj(NULL); switch(block.N) { case 2: // 2 -this is number of nodes when an edge is in .in file { //if(block.nNodes == Edge::nVerts) { // obj = m.edges_.newObj<Edge>(block.nodes); //} } case 4: // 4 - this is number of nodes when a face is in .in file { //switch(block.nNodes) { //case Face3::nVerts: // obj = m.faces_.newObj<Face3>(block.nodes); // break; //case Face4::nVerts: // obj = m.faces_.newObj<Face4>(block.nodes); // break; // //} } //// !switch(block.N) //faces break; case 8: // 8 - this is number of nodes when an element is in .in file. switch(block.nNodes) { case ElemT4::nVerts: std::swap(block.nodes[0],block.nodes[1]); obj = m.elements_.newObj<ElemT4>(block.nodes); break; case ElemPrism::nVerts: obj = m.elements_.newObj<ElemPrism>(block.nodes); break; defualt: throw "Unsupported element type readed from .in file"; break; }// !switch(block.nNodes) //elements break; }// !switch(block.N) if(obj != NULL) { for(int i(0);i < obj->typeSpecyfic_.nFaces_; ++i) { m.faces_.getById(obj->components(i)).flags(B_COND)= block.field[0]; } } ++_elem_readed; out_stream << "\r" << _elem_readed; } _file >> nextChar; } // we and at "-1" at end of elements block out_stream << "/" << _elem_count; }while( !_file.eof()); // elements blocks // !ELEMENTS // CMBLOCK - boundary definitions _file.clear(); _file.seekg(elemPos_); do { // find block begining _file >> txt; _file.ignore(bufS,eol); //out_stream << txt << std::endl; } while((txt != cmBlockBegin) && !_file.eof()); // !CMBLOCK // checking faces neighbours { Memory::Field<2,ID> * faceNeighs( new Memory::Field<2,ID>[mesh->faces_.last()+1] ); for(hHybridMesh::ElemPool::Iterator<hHybridMesh::ElemPool::allObj> it(& mesh->elements_); !it.done(); ++it) { for(uTind f(0); f < it->typeSpecyfic_.nFaces_; ++f) { if(faceNeighs[hObj::posFromId(it->components(f))][0]==0) { faceNeighs[hObj::posFromId(it->components(f))][0]=it->id_; } else { faceNeighs[hObj::posFromId(it->components(f))][1]=it->id_; } } } Face * fPtr(& mesh->faces_.at(FIRST)); for(unsigned int i(FIRST); i <= mesh->faces_.last(); ++i) { if(fPtr->neighs(0) != faceNeighs[i][0]) { fPtr->neighs(0) = faceNeighs[i][0]; } if(fPtr->neighs(1) != faceNeighs[i][1]) { fPtr->neighs(1) = faceNeighs[i][1]; } // If both neighs are zero, than Face pointed by fPtr (teoretycally) isn't belonging to any element! assert(fPtr->neighs(0) != fPtr->neighs(1)); fPtr=fPtr->next(); } delete [] faceNeighs; } // end of checking faces neighs } return true; }
void testPointerToStaticMemberCall() { int (*fPtr)(int) = &A::staticMemberFunction; if (fPtr != 0) { // no-crash clang_analyzer_eval(fPtr(2) == 3); // expected-warning{{TRUE}} } }
bool NasFileImporter::doRead(hHybridMesh * mesh) { if(_file.good()) { // GRID mmv_out_stream<< "\n Reading vertices..."; _file.seekg(gridPos_); mesh->vertices_.reserve(_vert_count); Vertex * vPtr(nullptr); std::string s_tmp; while(_vert_readed < _vert_count && _file.good()) { double val(0); //char tmp[12]={0}; _file >> s_tmp; vPtr = mesh->vertices_.newObj<Vertex>(nullptr); _file >> val >> vPtr->coords_[0] >> vPtr->coords_[1] >> vPtr->coords_[2] >> val; ++_vert_readed; } assert(_vert_count == _vert_readed); mmv_out_stream << " Vertices readed: " << _vert_readed << "\n Reading faces... "; // FACES int quad_readed(0); _file.seekg(0/*facePos_*/); mesh->faces_.reserve(_face_count+_quads, sizeof(Face3) * _face_count+sizeof(Face4)*_quads); mesh->edges_.reserve(_elem_count*6+_prisms*9,sizeof(Edge) * (_elem_count*6+_prisms*9)); hObj * fPtr(nullptr); uTind vertices[6]={UNKNOWN,UNKNOWN,UNKNOWN,UNKNOWN,UNKNOWN,UNKNOWN}; while(_face_readed+quad_readed < (_face_count+_quads) && _file.good()) { double val(0); //char tmp[12]={0}; //_file.getline(tmp,11,' '); //tmp[6]=0; _file >> s_tmp; int face_type(0); if(0 == s_tmp.compare("CTRIAX")) //if(0 == strcmp("CTRIAX",tmp )) { face_type = 3; if(face_type < 2 && face_type > 4) { throw "\nNasFileImporter::GetNextFace: wrong face_type.\n Make sure that file has platform-specyfic file endings (Win/Linux)."; } _file >> val; // number - ignore it int bc; _file >> bc; // element group no. = bc no. _file >> vertices[0];// fPtr->verts(0) = tmp2; // vertices no. !!! (not edges) _file >> vertices[1]; //fPtr->verts(1) = tmp2; _file >> vertices[2]; //fPtr->verts(2) = tmp2; std::sort(vertices, vertices+3); fPtr = mesh->faces_.newObj<Face3>(vertices); fPtr->flags(B_COND)= bc; fPtr->components(0) = mesh->edge(vertices[0],vertices[1]).id_; fPtr->components(1) = mesh->edge(vertices[0],vertices[2]).id_; fPtr->components(2) = mesh->edge(vertices[1],vertices[2]).id_; fPtr->neighs(0) = UNKNOWN; fPtr->neighs(1) = UNKNOWN; ++_face_readed; } else if(0 == s_tmp.compare("CQUADX")) // quads
void mtvm_menu_main(switch_core_session_t *session, vmivr_profile_t *profile) { switch_channel_t *channel = switch_core_session_get_channel(session); switch_event_t *msg_list_params = NULL; size_t msg_count = 0; size_t current_msg = 1; size_t next_msg = current_msg; size_t previous_msg = current_msg; char *cmd = NULL; int retry; /* Different switch to control playback of phrases */ switch_bool_t initial_count_played = SWITCH_FALSE; switch_bool_t skip_header = SWITCH_FALSE; switch_bool_t msg_deleted = SWITCH_FALSE; switch_bool_t msg_undeleted = SWITCH_FALSE; switch_bool_t msg_saved = SWITCH_FALSE; vmivr_menu_profile_t menu = { "std_navigator" }; /* Initialize Menu Configs */ populate_profile_menu_event(profile, &menu); if (!menu.event_keys_dtmf || !menu.event_phrases) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases and Keys\n"); return; } /* Get VoiceMail List And update msg count */ cmd = switch_core_session_sprintf(session, "json %s %s %s", profile->api_profile, profile->domain, profile->id); msg_list_params = jsonapi2event(session, NULL, profile->api_msg_list, cmd); msg_count = atol(switch_event_get_header(msg_list_params,"VM-List-Count")); /* TODO Add Detection of new message and notify the user */ for (retry = MAX_ATTEMPT; switch_channel_ready(channel) && retry > 0; retry--) { dtmf_ss_t loc; char *dtmfa[16] = { 0 }; switch_event_t *phrase_params = NULL; switch_event_create(&phrase_params, SWITCH_EVENT_REQUEST_PARAMS); append_event_profile(phrase_params, profile, menu); populate_dtmfa_from_event(phrase_params, profile, menu, dtmfa); previous_msg = current_msg; /* Simple Protection to not go out of msg list scope */ /* TODO: Add Prompt to notify they reached the begining or the end */ if (next_msg == 0) { next_msg = 1; } else if (next_msg > msg_count) { next_msg = msg_count; } current_msg = next_msg; captureMenuInitialize(&loc, dtmfa); /* Prompt related to previous Message here */ append_event_message(session, profile, phrase_params, msg_list_params, previous_msg); if (msg_deleted) { msg_deleted = SWITCH_FALSE; captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "ack"), "deleted", phrase_params, NULL, 0); } if (msg_undeleted) { msg_undeleted = SWITCH_FALSE; captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "ack"), "undeleted", phrase_params, NULL, 0); } if (msg_saved) { msg_saved = SWITCH_FALSE; captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "ack"), "saved", phrase_params, NULL, 0); } /* Prompt related the current message */ append_event_message(session, profile, phrase_params, msg_list_params, current_msg); /* TODO check if msg is gone (purged by another session, notify user and auto jump to next message or something) */ if (!skip_header) { if (!initial_count_played) { cmd = switch_core_session_sprintf(session, "json %s %s %s", profile->api_profile, profile->domain, profile->id); jsonapi2event(session, phrase_params, profile->api_msg_count, cmd); initial_count_played = SWITCH_TRUE; captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "msg_count"), NULL, phrase_params, NULL, 0); } if (msg_count > 0) { captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "say_msg_number"), NULL, phrase_params, NULL, 0); captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "say_date"), NULL, phrase_params, NULL, 0); } } if (msg_count > 0) { /* TODO Update the Read date of a message (When msg start, or when it listen compleatly ??? To be determined */ captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "play_message"), NULL, phrase_params, NULL, 0); } skip_header = SWITCH_FALSE; captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, phrase_params, NULL, DEFAULT_IVR_TIMEOUT); if (loc.result == RES_TIMEOUT) { /* TODO Ask for the prompt Again IF retry != 0 */ } else if (loc.result == RES_INVALID) { /* TODO Say invalid option, and ask for the prompt again IF retry != 0 */ } else if (loc.result == RES_FOUND) { /* Matching DTMF Key Pressed */ const char *action = switch_event_get_header(menu.event_keys_dtmf, loc.dtmf_stored); /* Reset the try count */ retry = MAX_ATTEMPT; if (action) { if (!strcasecmp(action, "skip_intro")) { /* Skip Header / Play the recording again */ skip_header = SWITCH_TRUE; } else if (!strcasecmp(action, "next_msg")) { /* Next Message */ next_msg++; } else if (!strcasecmp(action, "prev_msg")) { /* Previous Message */ next_msg--; } else if (!strcasecmp(action, "delete_msg")) { /* Delete / Undelete Message */ if (strncasecmp(switch_event_get_header(phrase_params, "VM-Message-Flags"), "delete", 6)) { cmd = switch_core_session_sprintf(session, "%s %s %s %s", profile->api_profile, profile->domain, profile->id, switch_event_get_header(phrase_params, "VM-Message-UUID")); mt_api_execute(session, profile->api_msg_delete, cmd); msg_deleted = SWITCH_TRUE; /* TODO Option for auto going to next message or just return to the menu (So user used to do 76 to delete and next message wont be confused) */ next_msg++; } else { cmd = switch_core_session_sprintf(session, "%s %s %s %s", profile->api_profile, profile->domain, profile->id, switch_event_get_header(phrase_params, "VM-Message-UUID")); mt_api_execute(session, profile->api_msg_undelete, cmd); msg_undeleted = SWITCH_TRUE; } } else if (!strcasecmp(action, "save_msg")) { /* Save Message */ cmd = switch_core_session_sprintf(session, "%s %s %s %s", profile->api_profile, profile->domain, profile->id, switch_event_get_header(phrase_params, "VM-Message-UUID")); mt_api_execute(session, profile->api_msg_save, cmd); msg_saved = SWITCH_TRUE; } else if (!strncasecmp(action, "menu:", 5)) { /* Sub Menu */ void (*fPtr)(switch_core_session_t *session, vmivr_profile_t *profile) = mtvm_get_menu_function(action+5); if (fPtr) { fPtr(session, profile); } } else if (!strcasecmp(action, "return")) { /* Return */ retry = -1; } } } /* IF the API to get the message returned us a COPY of the file locally (temp file create from a DB or from a web server), delete it */ if (switch_true(switch_event_get_header(phrase_params, "VM-Message-Private-Local-Copy"))) { const char *file_path = switch_event_get_header(phrase_params, "VM-Message-File-Path"); if (file_path && unlink(file_path) != 0) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Failed to delete temp file [%s]\n", file_path); } } switch_event_destroy(&phrase_params); } switch_event_destroy(&msg_list_params); free_profile_menu_event(&menu); return; }
switch_status_t mtvm_menu_record(switch_core_session_t *session, vmivr_profile_t *profile, vmivr_menu_profile_t menu, const char *file_name) { switch_status_t status = SWITCH_STATUS_FALSE; switch_channel_t *channel = switch_core_session_get_channel(session); int retry; switch_bool_t record_prompt = SWITCH_TRUE; switch_bool_t listen_recording = SWITCH_FALSE; switch_bool_t play_instruction = SWITCH_TRUE; if (!menu.event_keys_dtmf || !menu.event_phrases) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases and Keys\n"); return status; } for (retry = MAX_ATTEMPT; switch_channel_ready(channel) && retry > 0; retry--) { dtmf_ss_t loc; char *dtmfa[16] = { 0 }; switch_event_t *phrase_params = NULL; switch_file_handle_t fh = { 0 }; /* TODO Make the following configurable */ fh.thresh = 200; fh.silence_hits = 4; //fh.samplerate = 8000; switch_event_create(&phrase_params, SWITCH_EVENT_REQUEST_PARAMS); append_event_profile(phrase_params, profile, menu); populate_dtmfa_from_event(phrase_params, profile, menu, dtmfa); captureMenuInitialize(&loc, dtmfa); if (record_prompt) { if (play_instruction) { captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "instructions"), NULL, phrase_params, NULL, 0); } play_instruction = SWITCH_TRUE; captureMenuRecord(session, &loc, phrase_params, file_name, &fh, 30 /* TODO Make max recording configurable */); } else { if (listen_recording) { switch_event_add_header(phrase_params, SWITCH_STACK_BOTTOM, "VM-Record-File-Path", "%s", file_name); captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "play_recording"), NULL, phrase_params, NULL, 0); listen_recording = SWITCH_FALSE; } captureMenu(session, &loc, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, phrase_params, NULL, DEFAULT_IVR_TIMEOUT); } if (loc.recorded_audio) { /* Reset the try count */ retry = MAX_ATTEMPT; /* TODO Check if message is too short */ record_prompt = SWITCH_FALSE; } else if (loc.result == RES_TIMEOUT) { /* TODO Ask for the prompt Again IF retry != 0 */ } else if (loc.result == RES_INVALID) { /* TODO Say invalid option, and ask for the prompt again IF retry != 0 */ } else if (loc.result == RES_FOUND) { /* Matching DTMF Key Pressed */ const char *action = switch_event_get_header(menu.event_keys_dtmf, loc.dtmf_stored); /* Reset the try count */ retry = MAX_ATTEMPT; if (action) { if (!strcasecmp(action, "listen")) { /* Listen */ listen_recording = SWITCH_TRUE; } else if (!strcasecmp(action, "save")) { retry = -1; /* TODO ALLOW SAVE ONLY IF FILE IS RECORDED AND HIGHER THAN MIN SIZE */ status = SWITCH_STATUS_SUCCESS; } else if (!strcasecmp(action, "rerecord")) { record_prompt = SWITCH_TRUE; } else if (!strcasecmp(action, "skip_instruction")) { /* Skip Recording Greeting */ play_instruction = SWITCH_FALSE; } else if (!strncasecmp(action, "menu:", 5)) { /* Sub Menu */ void (*fPtr)(switch_core_session_t *session, vmivr_profile_t *profile) = mtvm_get_menu_function(action+5); if (fPtr) { fPtr(session, profile); } } else if (!strcasecmp(action, "return")) { /* Return */ retry = -1; } } } switch_event_destroy(&phrase_params); } return status; }
void vmivr_menu_main(switch_core_session_t *session, vmivr_profile_t *profile) { switch_channel_t *channel = switch_core_session_get_channel(session); vmivr_menu_t menu = { "std_main_menu" }; int retry; /* Initialize Menu Configs */ menu_init(profile, &menu); if (!menu.event_keys_dtmf || !menu.event_phrases) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Menu Phrases or Keys in menu '%s'\n", menu.name); goto end; } for (retry = menu.ivr_maximum_attempts; switch_channel_ready(channel) && retry > 0; retry--) { char *cmd = NULL; menu_instance_init(&menu); switch_event_add_header(menu.phrase_params, SWITCH_STACK_BOTTOM, "IVR-Retry-Left", "%d", retry); ivre_init(&menu.ivre_d, menu.dtmfa); cmd = switch_core_session_sprintf(session, "json %s %s %s %s", profile->api_profile, profile->domain, profile->id, profile->folder_name); jsonapi2event(session, menu.phrase_params, profile->api_msg_count, cmd); //initial_count_played = SWITCH_TRUE; ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "msg_count"), NULL, menu.phrase_params, NULL, 0); ivre_playback(session, &menu.ivre_d, switch_event_get_header(menu.event_phrases, "menu_options"), NULL, menu.phrase_params, NULL, menu.ivr_entry_timeout); if (menu.ivre_d.result == RES_TIMEOUT) { ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "timeout"), NULL, NULL, NULL, 0); } else if (menu.ivre_d.result == RES_INVALID) { ivre_playback_dtmf_buffered(session, switch_event_get_header(menu.event_phrases, "invalid"), NULL, NULL, NULL, 0); } else if (menu.ivre_d.result == RES_FOUND) { /* Matching DTMF Key Pressed */ const char *action = switch_event_get_header(menu.event_keys_dtmf, menu.ivre_d.dtmf_stored); /* Reset the try count */ retry = menu.ivr_maximum_attempts; if (action) { if (!strncasecmp(action, "new_msg:", 8)) { void (*fPtr)(switch_core_session_t *session, vmivr_profile_t *profile) = vmivr_get_menu_function(action+8); profile->folder_filter = VM_MSG_NEW; if (fPtr) { fPtr(session, profile); } } else if (!strncasecmp(action, "saved_msg:", 10)) { void (*fPtr)(switch_core_session_t *session, vmivr_profile_t *profile) = vmivr_get_menu_function(action+10); profile->folder_filter = VM_MSG_SAVED; if (fPtr) { fPtr(session, profile); } } else if (!strcasecmp(action, "return")) { /* Return to the previous menu */ retry = -1; } else if (!strncasecmp(action, "menu:", 5)) { /* Sub Menu */ void (*fPtr)(switch_core_session_t *session, vmivr_profile_t *profile) = vmivr_get_menu_function(action+5); if (fPtr) { fPtr(session, profile); } } } } menu_instance_free(&menu); } end: menu_free(&menu); }