diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/dataforms.lua | 4 | ||||
-rw-r--r-- | util/dependencies.lua | 8 | ||||
-rw-r--r-- | util/jid.lua | 13 | ||||
-rw-r--r-- | util/sasl.lua | 2 | ||||
-rw-r--r-- | util/stanza.lua | 28 |
5 files changed, 43 insertions, 12 deletions
diff --git a/util/dataforms.lua b/util/dataforms.lua index a3bde8ca..56671347 100644 --- a/util/dataforms.lua +++ b/util/dataforms.lua @@ -23,8 +23,8 @@ function new(layout) return setmetatable(layout, form_mt); end -function form_t.form(layout, data) - local form = st.stanza("x", { xmlns = xmlns_forms, type = "form" }); +function form_t.form(layout, data, formtype) + local form = st.stanza("x", { xmlns = xmlns_forms, type = formtype or "form" }); if layout.title then form:tag("title"):text(layout.title):up(); end diff --git a/util/dependencies.lua b/util/dependencies.lua index a0535e5c..cb022644 100644 --- a/util/dependencies.lua +++ b/util/dependencies.lua @@ -17,8 +17,12 @@ local function missingdep(name, sources, msg) print("Prosody was unable to find "..tostring(name)); print("This package can be obtained in the following ways:"); print(""); - for k,v in pairs(sources) do - print("", k, v); + local longest_platform = 0; + for platform in pairs(sources) do + longest_platform = math.max(longest_platform, #platform); + end + for platform, source in pairs(sources) do + print("", platform..":"..(" "):rep(4+longest_platform-#platform)..source); end print(""); print(msg or (name.." is required for Prosody to run, so we will now exit.")); diff --git a/util/jid.lua b/util/jid.lua index ccc8309c..b43247cc 100644 --- a/util/jid.lua +++ b/util/jid.lua @@ -65,4 +65,17 @@ function prep(jid) return host; end +function join(node, host, resource) + if node and host and resource then + return node.."@"..host.."/"..resource; + elseif node and host then + return node.."@"..host; + elseif host and resource then + return host.."/"..resource; + elseif host then + return host; + end + return nil; -- Invalid JID +end + return _M; diff --git a/util/sasl.lua b/util/sasl.lua index 402f05b4..5bc6db75 100644 --- a/util/sasl.lua +++ b/util/sasl.lua @@ -38,7 +38,7 @@ local function new_plain(realm, credentials_handler) function object.feed(self, message) if message == "" or message == nil then return "failure", "malformed-request" end local response = message - local authorization = s_match(response, "([^%z]+)") + local authorization = s_match(response, "([^%z]*)") local authentication = s_match(response, "%z([^%z]+)%z") local password = s_match(response, "%z[^%z]+%z([^%z]+)") diff --git a/util/stanza.lua b/util/stanza.lua index d295d5cc..069daa53 100644 --- a/util/stanza.lua +++ b/util/stanza.lua @@ -93,6 +93,17 @@ function stanza_mt:add_child(child) return self; end +function stanza_mt:get_child(name, xmlns) + for _, child in ipairs(self.tags) do + if (not name or child.name == name) + and ((not xmlns and self.attr.xmlns == child.attr.xmlns) + or child.attr.xmlns == xmlns) then + + return child; + end + end +end + function stanza_mt:child_with_name(name) for _, child in ipairs(self.tags) do if child.name == name then return child; end @@ -280,13 +291,16 @@ function reply(orig) return stanza(orig.name, orig.attr and { to = orig.attr.from, from = orig.attr.to, id = orig.attr.id, type = ((orig.name == "iq" and "result") or orig.attr.type) }); end -function error_reply(orig, type, condition, message) - local t = reply(orig); - t.attr.type = "error"; - t:tag("error", {type = type}) - :tag(condition, {xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas"}):up(); - if (message) then t:tag("text"):text(message):up(); end - return t; -- stanza ready for adding app-specific errors +do + local xmpp_stanzas_attr = { xmlns = xmlns_stanzas }; + function error_reply(orig, type, condition, message) + local t = reply(orig); + t.attr.type = "error"; + t:tag("error", {type = type}) --COMPAT: Some day xmlns:stanzas goes here + :tag(condition, xmpp_stanzas_attr):up(); + if (message) then t:tag("text", xmpp_stanzas_attr):text(message):up(); end + return t; -- stanza ready for adding app-specific errors + end end function presence(attr) |