/usr/share/ettercap/lua/third-party/xml.lua is in ettercap-common 1:0.8.2-10build4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | -- XML extensions to string module.
-- @class module
-- @name xml
require "base"
require "string_ext"
--- Write a table as XML.
-- The input format is assumed to be that output by luaexpat.
-- @param t table to print.
-- In each element, tag is its name, attr is the table of attributes,
-- and the sub-elements are held in the integer keys
-- @param indent indent between levels (default: <code>"\t"</code>)
-- @param spacing space before every line
-- @returns XML string
function string.writeXML (t, indent, spacing)
indent = indent or "\t"
spacing = spacing or ""
return render (t,
function (x)
spacing = spacing .. indent
if x.tag then
local s = "<" .. x.tag
if type (x.attr) == "table" then
for i, v in pairs (x.attr) do
if type (i) ~= "number" then
-- luaexpat gives names of attributes in list elements
s = s .. " " .. tostring (i) .. "=" .. string.format ("%q", tostring (v))
end
end
end
if #x == 0 then
s = s .. " /"
end
s = s .. ">"
return s
end
return ""
end,
function (x)
spacing = string.gsub (spacing, indent .. "$", "")
if x.tag and #x > 0 then
return spacing .. "</" .. x.tag .. ">"
end
return ""
end,
function (s)
s = tostring (s)
s = string.gsub (s, "&([%S]+)",
function (s)
if not string.match (s, "^#?%w+;") then
return "&" .. s
else
return "&" .. s
end
end)
s = string.gsub (s, "<", "<")
s = string.gsub (s, ">", ">")
return s
end,
function (x, i, v, is, vs)
local s = ""
if type (i) == "number" then
s = spacing .. vs
end
return s
end,
function (_, i, _, j)
if type (i) == "number" or type (j) == "number" then
return "\n"
end
return ""
end)
end
|