canonicalize some code

This commit is contained in:
batrick 2011-05-11 14:38:52 +00:00
parent 1cd183014d
commit 186cb2d6a3
3 changed files with 12 additions and 16 deletions

View file

@ -22,8 +22,8 @@ local function check_code(result)
if result:match( "\r?\n\r?\n" ) then
result = result:match( "^(.-)\r?\n\r?\n(.*)$" )
end
if string.match(result:lower(),"^http/%d\.%d%s*200") then return true end
if string.match(result:lower(),"^http/%d\.%d%s*30[12]") then return true end
if result:lower():match("^http/%d\.%d%s*200") then return true end
if result:lower():match("^http/%d\.%d%s*30[12]") then return true end
end
return false
end
@ -34,13 +34,10 @@ end
--@return true if pattern is found, otherwise false
local function check_pattern(result, pattern)
local lines = stdnse.strsplit("\n", result)
local i = 1
local n = table.getn(lines)
while true do
if i > n then return false end
if string.match(lines[i]:lower(),pattern:lower()) then return true end
i = i + 1
for i, line in ipairs(lines) do
if line:lower():match(pattern:lower()) then return true end
end
return false
end
--- check, decides what kind of check should be done on the response,

View file

@ -133,10 +133,9 @@ local function dispatcher()
s_condvar "broadcast"
end
local n = table.getn(threads)
if ( n == 0 ) then break end
for i=1,n do
local status, res = coroutine.resume(threads[i])
if #threads == 0 then break end
for i, thread in ipairs(threads) do
local status, res = coroutine.resume(thread)
if ( not(res) ) then -- thread finished its task?
table.remove(threads, i)
break
@ -336,4 +335,4 @@ function waitFile( filename, timeout )
waitLast()
return false
end
end

View file

@ -257,8 +257,8 @@ function parse_path(path)
path = path or ""
--path = string.gsub(path, "%s", "")
string.gsub(path, "([^/]+)", function (s) table.insert(parsed, s) end)
for i = 1, table.getn(parsed) do
parsed[i] = unescape(parsed[i])
for i, v in ipairs(parsed) do
parsed[i] = unescape(v)
end
if string.sub(path, 1, 1) == "/" then parsed.is_absolute = 1 end
if string.sub(path, -1, -1) == "/" then parsed.is_directory = 1 end
@ -273,7 +273,7 @@ end
-----------------------------------------------------------------------------
function build_path(parsed, unsafe)
local path = ""
local n = table.getn(parsed)
local n = #parsed
if unsafe then
for i = 1, n-1 do
path = path .. parsed[i]