Additional work on base64 optional storage in the database.

This commit is contained in:
Mark Crane
2015-04-18 19:59:50 +00:00
parent 911bbe32b9
commit e716be53d6
6 changed files with 40 additions and 12 deletions
@@ -36,11 +36,26 @@
end end
--check to see if the greeting file exists --check to see if the greeting file exists
if (greeting_id ~= "0") then if (storage_type == "base64" or storage_type == "http_cache") then
if (not file_exists(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav")) then greeting_invalid = true;
--invalid greeting_id file does not exist 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"; greeting_id = "invalid";
end 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 end
--validate the greeting_id --validate the greeting_id
@@ -77,9 +92,9 @@
WHERE domain_uuid = ']] .. domain_uuid ..[[' WHERE domain_uuid = ']] .. domain_uuid ..[['
AND voicemail_id = ']].. voicemail_id.. [[' AND voicemail_id = ']].. voicemail_id.. [['
AND greeting_id = ']].. greeting_id.. [[' ]]; AND greeting_id = ']].. greeting_id.. [[' ]];
--if (debug["sql"]) then if (debug["sql"]) then
freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n"); freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "\n");
--end end
status = dbh:query(sql, function(row) status = dbh:query(sql, function(row)
--add functions --add functions
dofile(scripts_dir.."/resources/functions/base64.lua"); dofile(scripts_dir.."/resources/functions/base64.lua");
@@ -144,8 +144,10 @@
event:fire(); event:fire();
--if local after email is true then copy the recording file --if local after email is true then copy the recording file
mkdir(voicemail_dir.."/"..forward_voicemail_id); if (storage_type ~= "base64") then
copy(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext, voicemail_dir.."/"..forward_voicemail_id.."/msg_"..voicemail_message_uuid.."."..vm_message_ext); 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 the email with the voicemail recording attached
send_email(forward_voicemail_id, voicemail_message_uuid); send_email(forward_voicemail_id, voicemail_message_uuid);
@@ -105,6 +105,10 @@
session:streamFile("silence_stream://1000"); session:streamFile("silence_stream://1000");
end end
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 --to listen to the recording press 1
if (session:ready()) then if (session:ready()) then
if (string.len(dtmf_digits) == 0) then if (string.len(dtmf_digits) == 0) then
@@ -69,7 +69,7 @@
dofile(scripts_dir.."/resources/functions/base64.lua"); dofile(scripts_dir.."/resources/functions/base64.lua");
--show the storage type --show the storage type
freeswitch.consoleLog("notice", "[voicemail] ".. storage_type .. "\n"); --freeswitch.consoleLog("notice", "[voicemail] ".. storage_type .. "\n");
--base64 encode the file --base64 encode the file
local f = io.open(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", "rb"); local f = io.open(voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav", "rb");
@@ -163,6 +163,10 @@
if (session:ready()) then if (session:ready()) then
timeouts = 0; timeouts = 0;
record_menu("greeting", voicemail_dir.."/"..voicemail_id.."/greeting_"..greeting_id..".wav"); 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 end
else else
--invalid greeting_id --invalid greeting_id
@@ -81,7 +81,7 @@
pos = string.find(row.voicemail_option_param, " ", 0, true); pos = string.find(row.voicemail_option_param, " ", 0, true);
action = string.sub( row.voicemail_option_param, 0, pos-1); action = string.sub( row.voicemail_option_param, 0, pos-1);
data = string.sub( row.voicemail_option_param, pos+1); data = string.sub( row.voicemail_option_param, pos+1);
--check if the option uses a regex --check if the option uses a regex
regex = string.find(row.voicemail_option_digits, "(", 0, true); regex = string.find(row.voicemail_option_digits, "(", 0, true);
if (regex) then if (regex) then
@@ -91,14 +91,14 @@
freeswitch.consoleLog("notice", "[voicemail] regex m:~"..digits.."~"..row.voicemail_option_digits.."~$1\n"); freeswitch.consoleLog("notice", "[voicemail] regex m:~"..digits.."~"..row.voicemail_option_digits.."~$1\n");
freeswitch.consoleLog("notice", "[voicemail] result: "..result.."\n"); freeswitch.consoleLog("notice", "[voicemail] result: "..result.."\n");
end end
--replace the $1 and the domain name --replace the $1 and the domain name
data = data:gsub("$1", result); data = data:gsub("$1", result);
data = data:gsub("${domain_name}", domain_name); data = data:gsub("${domain_name}", domain_name);
end --if regex end --if regex
end --if menu-exex-app end --if menu-exex-app
end --if regex match end --if regex match
--execute --execute
if (action) then if (action) then
if (string.len(action) > 0) then if (string.len(action) > 0) then
@@ -128,7 +128,6 @@
end end
end end
end end
end end
end end
end end
@@ -97,6 +97,10 @@
if (session:ready()) then if (session:ready()) then
timeouts = 0; timeouts = 0;
record_menu("name", voicemail_dir.."/"..voicemail_id.."/recorded_name.wav"); 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 end
end end