From 7ba8ca8f843ab94328212ca3a701a39d6009f04c Mon Sep 17 00:00:00 2001 From: Mark Crane Date: Sat, 18 Apr 2015 19:59:50 +0000 Subject: [PATCH] Additional work on base64 optional storage in the database. --- .../resources/functions/choose_greeting.lua | 25 +++++++++++++++---- .../functions/forward_to_extension.lua | 6 +++-- .../functions/listen_to_recording.lua | 4 +++ .../resources/functions/record_greeting.lua | 6 ++++- .../resources/functions/record_message.lua | 7 +++--- .../resources/functions/record_name.lua | 4 +++ 6 files changed, 40 insertions(+), 12 deletions(-) diff --git a/resources/install/scripts/app/voicemail/resources/functions/choose_greeting.lua b/resources/install/scripts/app/voicemail/resources/functions/choose_greeting.lua index 227ce1ef39..28bf9c73ab 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/choose_greeting.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/choose_greeting.lua @@ -36,11 +36,26 @@ end --check to see if the greeting file exists - if (greeting_id ~= "0") then - if (not file_exists(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav")) then - --invalid greeting_id file does not exist + if (storage_type == "base64" or storage_type == "http_cache") then + greeting_invalid = true; + sql = [[SELECT * FROM v_voicemail_greetings + WHERE domain_uuid = ']] .. domain_uuid ..[[' + AND voicemail_id = ']].. voicemail_id.. [[' + AND greeting_id = ']].. greeting_id.. [[' ]]; + status = dbh:query(sql, function(row) + --greeting found + greeting_invalid = false; + end); + if (greeting_invalid) then greeting_id = "invalid"; end + else + if (greeting_id ~= "0") then + if (not file_exists(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav")) then + --invalid greeting_id file does not exist + greeting_id = "invalid"; + end + end end --validate the greeting_id @@ -77,9 +92,9 @@ WHERE domain_uuid = ']] .. domain_uuid ..[[' AND voicemail_id = ']].. voicemail_id.. [[' AND greeting_id = ']].. greeting_id.. [[' ]]; - --if (debug["sql"]) then + if (debug["sql"]) then freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n"); - --end + end status = dbh:query(sql, function(row) --add functions dofile(scripts_dir.."/resources/functions/base64.lua"); diff --git a/resources/install/scripts/app/voicemail/resources/functions/forward_to_extension.lua b/resources/install/scripts/app/voicemail/resources/functions/forward_to_extension.lua index fe3922a2fb..efca1a1a2a 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/forward_to_extension.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/forward_to_extension.lua @@ -144,8 +144,10 @@ event:fire(); --if local after email is true then copy the recording file - mkdir(voicemail_dir.."/"..forward_voicemail_id); - copy(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext, voicemail_dir.."/"..forward_voicemail_id.."/msg_"..voicemail_message_uuid.."."..vm_message_ext); + if (storage_type ~= "base64") then + mkdir(voicemail_dir.."/"..forward_voicemail_id); + copy(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext, voicemail_dir.."/"..forward_voicemail_id.."/msg_"..voicemail_message_uuid.."."..vm_message_ext); + end --send the email with the voicemail recording attached send_email(forward_voicemail_id, voicemail_message_uuid); diff --git a/resources/install/scripts/app/voicemail/resources/functions/listen_to_recording.lua b/resources/install/scripts/app/voicemail/resources/functions/listen_to_recording.lua index 05a9fdf184..89e0925ff5 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/listen_to_recording.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/listen_to_recording.lua @@ -105,6 +105,10 @@ session:streamFile("silence_stream://1000"); end end + --remove the voicemail message + if (storage_type == "base64") then + os.remove(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext); + end --to listen to the recording press 1 if (session:ready()) then if (string.len(dtmf_digits) == 0) then diff --git a/resources/install/scripts/app/voicemail/resources/functions/record_greeting.lua b/resources/install/scripts/app/voicemail/resources/functions/record_greeting.lua index 4650a6faac..f4cb07cdea 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/record_greeting.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/record_greeting.lua @@ -69,7 +69,7 @@ dofile(scripts_dir.."/resources/functions/base64.lua"); --show the storage type - freeswitch.consoleLog("notice", "[voicemail] ".. storage_type .. "\n"); + --freeswitch.consoleLog("notice", "[voicemail] ".. storage_type .. "\n"); --base64 encode the file local f = io.open(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", "rb"); @@ -163,6 +163,10 @@ if (session:ready()) then timeouts = 0; record_menu("greeting", voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"); + if (storage_type == "base64") then + --delete the greeting + os.remove(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"); + end end else --invalid greeting_id diff --git a/resources/install/scripts/app/voicemail/resources/functions/record_message.lua b/resources/install/scripts/app/voicemail/resources/functions/record_message.lua index 9620e42ce9..2a599daa60 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/record_message.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/record_message.lua @@ -81,7 +81,7 @@ pos = string.find(row.voicemail_option_param, " ", 0, true); action = string.sub( row.voicemail_option_param, 0, pos-1); data = string.sub( row.voicemail_option_param, pos+1); - + --check if the option uses a regex regex = string.find(row.voicemail_option_digits, "(", 0, true); if (regex) then @@ -91,14 +91,14 @@ freeswitch.consoleLog("notice", "[voicemail] regex m:~"..digits.."~"..row.voicemail_option_digits.."~$1\n"); freeswitch.consoleLog("notice", "[voicemail] result: "..result.."\n"); end - + --replace the $1 and the domain name data = data:gsub("$1", result); data = data:gsub("${domain_name}", domain_name); end --if regex end --if menu-exex-app end --if regex match - + --execute if (action) then if (string.len(action) > 0) then @@ -128,7 +128,6 @@ end end end - end end end diff --git a/resources/install/scripts/app/voicemail/resources/functions/record_name.lua b/resources/install/scripts/app/voicemail/resources/functions/record_name.lua index 28b7436b78..fa4f039902 100644 --- a/resources/install/scripts/app/voicemail/resources/functions/record_name.lua +++ b/resources/install/scripts/app/voicemail/resources/functions/record_name.lua @@ -97,6 +97,10 @@ if (session:ready()) then timeouts = 0; record_menu("name", voicemail_dir.."/"..voicemail_id.."/recorded_name.wav"); + if (storage_type == "base64") then + --delete the greeting + os.remove(voicemail_dir.."/"..voicemail_id.."/recorded_name.wav"); + end end end end