1) Replaced trim with luci.util.trim in pbx-calls.lua

2) Slight code cleanup in pbx.lua
This commit is contained in:
Iordan Iordanov 2011-11-05 16:50:14 +00:00
parent 0abb1420e7
commit 773de62fd3
2 changed files with 7 additions and 13 deletions

View file

@ -37,11 +37,6 @@ function is_valid_extension(exten)
return (exten:match("[#*+0-9NXZ]+$") ~= nil) return (exten:match("[#*+0-9NXZ]+$") ~= nil)
end end
-- Gets rid of leading and trailing whitespace.
function trim(s)
return (s:gsub("^%s*(.-)%s*$", "%1"))
end
m = Map (modulename, translate("Call Routing"), m = Map (modulename, translate("Call Routing"),
translate("This is where you indicate which Google/SIP accounts are used to call what \ translate("This is where you indicate which Google/SIP accounts are used to call what \
@ -98,7 +93,7 @@ m.uci:foreach(googlemodulename, "gtalk_jabber",
newvalue = {} newvalue = {}
nindex = 1 nindex = 1
for index, field in ipairs(value) do for index, field in ipairs(value) do
val = trim(value[index]) val = luci.util.trim(value[index])
if is_valid_extension(val) == true then if is_valid_extension(val) == true then
newvalue[nindex] = val newvalue[nindex] = val
nindex = nindex + 1 nindex = nindex + 1
@ -135,7 +130,7 @@ m.uci:foreach(voipmodulename, "voip_provider",
newvalue = {} newvalue = {}
nindex = 1 nindex = 1
for index, field in ipairs(value) do for index, field in ipairs(value) do
val = trim(value[index]) val = luci.util.trim(value[index])
if is_valid_extension(val) == true then if is_valid_extension(val) == true then
newvalue[nindex] = val newvalue[nindex] = val
nindex = nindex + 1 nindex = nindex + 1
@ -180,7 +175,7 @@ m.uci:foreach(googlemodulename, "gtalk_jabber",
newvalue = {} newvalue = {}
nindex = 1 nindex = 1
for index, field in ipairs(value) do for index, field in ipairs(value) do
trimuser = trim(value[index]) trimuser = luci.util.trim(value[index])
if allvalidusers[trimuser] == true then if allvalidusers[trimuser] == true then
newvalue[nindex] = trimuser newvalue[nindex] = trimuser
nindex = nindex + 1 nindex = nindex + 1
@ -215,7 +210,7 @@ m.uci:foreach(voipmodulename, "voip_provider",
newvalue = {} newvalue = {}
nindex = 1 nindex = 1
for index, field in ipairs(value) do for index, field in ipairs(value) do
trimuser = trim(value[index]) trimuser = luci.util.trim(value[index])
if allvalidusers[trimuser] == true then if allvalidusers[trimuser] == true then
newvalue[nindex] = trimuser newvalue[nindex] = trimuser
nindex = nindex + 1 nindex = nindex + 1
@ -268,7 +263,7 @@ m.uci:foreach(usersmodulename, "local_user",
cookedvalue = {} cookedvalue = {}
cindex = 1 cindex = 1
for index, field in ipairs(value) do for index, field in ipairs(value) do
cooked = string.gsub(trim(value[index]), "%W", "_") cooked = string.gsub(luci.util.trim(value[index]), "%W", "_")
if validoutaccounts[cooked] ~= nil then if validoutaccounts[cooked] ~= nil then
cookedvalue[cindex] = cooked cookedvalue[cindex] = cooked
cindex = cindex + 1 cindex = cindex + 1
@ -298,7 +293,7 @@ user = s:option(Value, "defaultuser", translate("User Name"),
translate("The number(s) specified above will be able to dial out with this user's providers.\ translate("The number(s) specified above will be able to dial out with this user's providers.\
Invalid usernames are dropped silently, please verify that the entry was accepted.")) Invalid usernames are dropped silently, please verify that the entry was accepted."))
function user.write(self, section, value) function user.write(self, section, value)
trimuser = trim(value) trimuser = luci.util.trim(value)
if allvalidusers[trimuser] == true then if allvalidusers[trimuser] == true then
Value.write(self, section, trimuser) Value.write(self, section, trimuser)
end end

View file

@ -49,13 +49,12 @@ function format_indices(string, indices)
end end
-- Split input into separate lines. -- Split input into separate lines.
lines = {}
lines = mysplit(string, "\n") lines = mysplit(string, "\n")
-- Split lines into separate words. -- Split lines into separate words.
splitlines = {} splitlines = {}
for lpos,line in ipairs(lines) do for lpos,line in ipairs(lines) do
splitlines[lpos] = mysplit(line) splitlines[lpos] = mysplit(line, " ")
end end
-- For each split line, if the word at all indices specified -- For each split line, if the word at all indices specified