Add. Handler for SUBSCRIBE method for call flow application. (#1701)

* Add. Handler for SUBSCRIBE method for call flow application.

Usage:
1. Run form fs_cli `luarun call_flow_subscribe`
2. Create new call flow extension and set feature code to `flow+<EXTENSION>`(e.g. `flow+401`).
3. Set on the phone BLF key to `flow+401`

This code based on `mod_valet_parking`.

* Add. prevent running 2 copy of script.

Remove some unused vars and simplify implementation.

* Fix. Use correct protocol for send event.

* Fix. Do escape SQL arguments

* Fix. escape `+` sign in call flow extension.
This commit is contained in:
Alexey Melnichuk
2016-06-24 10:32:19 -06:00
committed by FusionPBX
parent 628c825201
commit 61d6f0be6c
4 changed files with 143 additions and 3 deletions
@@ -77,6 +77,14 @@ local function new_database(backend, backend_name)
return result
end
function Database:escape(str)
return (string.gsub(str, "'", "''"))
end
function Database:quote(str)
return "'" .. self:escape(str) .. "'"
end
function Database.__self_test__(...)
log.info('self_test Database - ' .. Database._backend_name)
local db = Database.new(...)
@@ -151,6 +159,16 @@ local function new_database(backend, backend_name)
local a = assert(db:first_value("select NULL as a"))
assert(a == "")
-- escape
local values = {"hello';select 'world", "hello'"}
for _, value in ipairs(values) do
local a = assert(db:first_value(
string.format("select '%s' as a", db:escape(value))
))
assert(a == value)
end
-- close
db:release()
assert(not db:connected())
@@ -1,6 +1,17 @@
require "resources.functions.split"
local function turn_lamp(on, user, uuid)
local userid, domain, proto = split_first(user, "@", true)
proto, userid = split_first(userid, "+", true)
if userid then
user = userid .. "@" .. domain
else
proto = "sip"
end
local event = freeswitch.Event("PRESENCE_IN");
event:addHeader("proto", "sip");
event:addHeader("proto", proto);
event:addHeader("event_type", "presence");
event:addHeader("alt_event_type", "dialog");
event:addHeader("Presence-Call-Direction", "outbound");