VoIP Mailing List Archives
Mailing list archives for the VoIP community |
|
View previous topic :: View next topic |
Author |
Message |
olegstolyar at gmail.com Guest
|
Posted: Wed Mar 02, 2016 3:07 pm Post subject: [Freeswitch-users] Finding session variables by name pattern |
|
|
Hi guys,
is there a way to find all the session variable with a certain name pattern in lua?
For example I need to find all the session variables whose names start with "bla_"
As an alternative is there a way to iterate over all the session variables? Then I can just do that and find the variables I need this way. |
|
Back to top |
|
|
msc at freeswitch.org Guest
|
Posted: Wed Mar 02, 2016 6:02 pm Post subject: [Freeswitch-users] Finding session variables by name pattern |
|
|
You can use the uuid_dump command to get all the channel variables and values. Here's some rudimentary code which accepts the uuid as an argument:
-- Lua has no split function, so we need to create one
function string:split( inSplitPattern, outResults )
if not outResults then
outResults = {}
end
local theStart = 1
local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
while theSplitStart do
table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) )
theStart = theSplitEnd + 1
theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
end
table.insert( outResults, string.sub( self, theStart ) )
return outResults
end
api = freeswitch.API()
uuid = argv[1]
-- uuid_dump gets all vars for a particular channel
res = api:execute('uuid_dump',uuid)
freeswitch.consoleLog('INFO',"Complete vars list: " .. res .. "\n")
-- lines is a table, one row per var: val pair
lines = string.split(res,"\n")
for i=1,#lines do
-- check for variable name using pattern match
-- Adjust the pattern to whatever you are trying to find
myPattern = 'variable_'
if string.match(lines[i], myPattern) then
varval = string.split(lines[i],": ")
freeswitch.consoleLog("NOTICE","Variable '" .. varval[1] .. "' contains '" .. varval[2] .. "'\n")
end
end
I don't know if this is the most efficient way of doing what you're trying to do but it does demonstrate the power and flexibility of Lua and FreeSWITCH API's like uuid_dump.
-MC
On Wed, Mar 2, 2016 at 12:05 PM, Oleg Stolyar <olegstolyar@gmail.com (olegstolyar@gmail.com)> wrote:
|
|
Back to top |
|
|
olegstolyar at gmail.com Guest
|
Posted: Wed Mar 02, 2016 6:13 pm Post subject: [Freeswitch-users] Finding session variables by name pattern |
|
|
Thanks Michael, looks like a very workable solution!
On Wed, Mar 2, 2016 at 2:57 PM, Michael Collins <msc@freeswitch.org (msc@freeswitch.org)> wrote:
Quote: | You can use the uuid_dump command to get all the channel variables and values. Here's some rudimentary code which accepts the uuid as an argument:
-- Lua has no split function, so we need to create one
function string:split( inSplitPattern, outResults )
if not outResults then
outResults = {}
end
local theStart = 1
local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
while theSplitStart do
table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) )
theStart = theSplitEnd + 1
theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
end
table.insert( outResults, string.sub( self, theStart ) )
return outResults
end
api = freeswitch.API()
uuid = argv[1]
-- uuid_dump gets all vars for a particular channel
res = api:execute('uuid_dump',uuid)
freeswitch.consoleLog('INFO',"Complete vars list: " .. res .. "\n")
-- lines is a table, one row per var: val pair
lines = string.split(res,"\n")
for i=1,#lines do
-- check for variable name using pattern match
-- Adjust the pattern to whatever you are trying to find
myPattern = 'variable_'
if string.match(lines[i], myPattern) then
varval = string.split(lines[i],": ")
freeswitch.consoleLog("NOTICE","Variable '" .. varval[1] .. "' contains '" .. varval[2] .. "'\n")
end
end
I don't know if this is the most efficient way of doing what you're trying to do but it does demonstrate the power and flexibility of Lua and FreeSWITCH API's like uuid_dump.
-MC
On Wed, Mar 2, 2016 at 12:05 PM, Oleg Stolyar <olegstolyar@gmail.com (olegstolyar@gmail.com)> wrote:
_________________________________________________________________________
Professional FreeSWITCH Consulting Services:
consulting@freeswitch.org (consulting@freeswitch.org)
http://www.freeswitchsolutions.com
Official FreeSWITCH Sites
http://www.freeswitch.org
http://confluence.freeswitch.org
http://www.cluecon.com
FreeSWITCH-users mailing list
FreeSWITCH-users@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
|
|
|
Back to top |
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|