aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authormatthew <devnull@localhost>2008-08-24 01:51:02 +0000
committermatthew <devnull@localhost>2008-08-24 01:51:02 +0000
commit78739d9638b857bf5c8ce249036818a92eceae46 (patch)
tree09811ab5053a1aaf15fac37d6ac9e065611d6189 /util
parentd0a4f8f2fb4b0927a67ebc7428d6c5cb66d2fbd4 (diff)
downloadprosody-78739d9638b857bf5c8ce249036818a92eceae46.tar.gz
prosody-78739d9638b857bf5c8ce249036818a92eceae46.zip
Switched to new connection framework, courtesy of the luadch project
Now supports SSL on 5223 Beginning support for presence (aka. the proper routing of stanzas)
Diffstat (limited to 'util')
-rw-r--r--util/stanza.lua34
1 files changed, 24 insertions, 10 deletions
diff --git a/util/stanza.lua b/util/stanza.lua
index 88d0609f..f41ba699 100644
--- a/util/stanza.lua
+++ b/util/stanza.lua
@@ -1,10 +1,11 @@
-local t_insert = table.insert;
-local t_remove = table.remove;
-local format = string.format;
-local tostring = tostring;
-local setmetatable= setmetatable;
-local pairs = pairs;
-local ipairs = ipairs;
+local t_insert = table.insert;
+local t_remove = table.remove;
+local format = string.format;
+local tostring = tostring;
+local setmetatable = setmetatable;
+local pairs = pairs;
+local ipairs = ipairs;
+local type = type;
module "stanza"
@@ -12,7 +13,7 @@ stanza_mt = {};
stanza_mt.__index = stanza_mt;
function stanza(name, attr)
- local stanza = { name = name, attr = attr or {}, last_add = {}};
+ local stanza = { name = name, attr = attr or {}, tags = {}, last_add = {}};
return setmetatable(stanza, stanza_mt);
end
@@ -46,6 +47,9 @@ function stanza_mt:up()
end
function stanza_mt:add_child(child)
+ if type(child) == "table" then
+ t_insert(self.tags, child);
+ end
t_insert(self, child);
end
@@ -55,6 +59,16 @@ function stanza_mt:child_with_name(name)
end
end
+function stanza_mt:children()
+ local i = 0;
+ return function (a)
+ i = i + 1
+ local v = a[i]
+ if v then return v; end
+ end, self, i;
+
+end
+
function stanza_mt.__tostring(t)
local children_text = "";
for n, child in ipairs(t) do
@@ -63,14 +77,14 @@ function stanza_mt.__tostring(t)
local attr_string = "";
if t.attr then
- for k, v in pairs(t.attr) do attr_string = attr_string .. format(" %s='%s'", k, tostring(v)); end
+ for k, v in pairs(t.attr) do if type(k) == "string" then attr_string = attr_string .. format(" %s='%s'", k, tostring(v)); end end
end
return format("<%s%s>%s</%s>", t.name, attr_string, children_text, t.name);
end
function stanza_mt.__add(s1, s2)
- return s:add_child(s2);
+ return s1:add_child(s2);
end