1-- Part of FusionPBX 2-- Copyright (C) 2013-2016 Mark J Crane <markjcrane@fusionpbx.com> 3-- All rights reserved. 4-- 5-- Redistribution and use in source and binary forms, with or without 6-- modification, are permitted provided that the following conditions are met: 7-- 8-- 1. Redistributions of source code must retain the above copyright notice, 9-- this list of conditions and the following disclaimer. 10-- 11-- 2. Redistributions in binary form must reproduce the above copyright 12-- notice, this list of conditions and the following disclaimer in the 13-- documentation and/or other materials provided with the distribution. 14-- 15-- THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 16-- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 17-- AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 18-- AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 19-- OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24-- POSSIBILITY OF SUCH DAMAGE. 25 26--delete the message 27 function delete_recording(voicemail_id, uuid) 28 --message deleted 29 if (session ~= nil) then 30 if (session:ready()) then 31 dtmf_digits = ''; 32 macro(session, "message_deleted", 1, 100, ''); 33 end 34 end 35 36 --get the voicemail_uuid 37 local sql = [[SELECT * FROM v_voicemails 38 WHERE domain_uuid = :domain_uuid 39 AND voicemail_id = :voicemail_id]]; 40 local params = {domain_uuid = domain_uuid, voicemail_id = voicemail_id}; 41 dbh:query(sql, params, function(row) 42 db_voicemail_uuid = row["voicemail_uuid"]; 43 end); 44 --flush dtmf digits from the input buffer 45 session:flushDigits(); 46 --delete the file 47 os.remove(voicemail_dir.."/"..voicemail_id.."/intro_"..uuid.."."..vm_message_ext); 48 os.remove(voicemail_dir.."/"..voicemail_id.."/msg_"..uuid.."."..vm_message_ext); 49 --delete from the database 50 sql = [[DELETE FROM v_voicemail_messages 51 WHERE domain_uuid = :domain_uuid 52 AND voicemail_uuid = :voicemail_uuid 53 AND voicemail_message_uuid = :uuid]]; 54 params = {domain_uuid = domain_uuid, voicemail_uuid = db_voicemail_uuid, uuid = uuid}; 55 if (debug["sql"]) then 56 freeswitch.consoleLog("notice", "[voicemail] SQL: " .. sql .. "; params:" .. json.encode(params) .. "\n"); 57 end 58 dbh:query(sql, params); 59 --log to console 60 if (debug["info"]) then 61 freeswitch.consoleLog("notice", "[voicemail][deleted] message: " .. uuid .. "\n"); 62 end 63 --clear the variable 64 db_voicemail_uuid = ''; 65 end 66