aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/array.lua4
-rw-r--r--util/broadcast.lua4
-rw-r--r--util/dataforms.lua4
-rw-r--r--util/datamanager.lua4
-rw-r--r--util/datetime.lua4
-rw-r--r--util/dependencies.lua4
-rw-r--r--util/events.lua4
-rw-r--r--util/helpers.lua4
-rw-r--r--util/hmac.lua4
-rw-r--r--util/import.lua4
-rw-r--r--util/iterators.lua4
-rw-r--r--util/jid.lua4
-rw-r--r--util/logger.lua4
-rw-r--r--util/multitable.lua4
-rw-r--r--util/pluginloader.lua4
-rw-r--r--util/prosodyctl.lua4
-rw-r--r--util/sasl/digest-md5.lua2
-rw-r--r--util/sasl_cyrus.lua31
-rw-r--r--util/serialization.lua4
-rw-r--r--util/set.lua4
-rw-r--r--util/stanza.lua4
-rw-r--r--util/termcolours.lua4
-rw-r--r--util/timer.lua9
-rw-r--r--util/uuid.lua6
-rw-r--r--util/xmlrpc.lua4
-rw-r--r--util/xmppstream.lua150
-rw-r--r--util/ztact.lua4
27 files changed, 222 insertions, 64 deletions
diff --git a/util/array.lua b/util/array.lua
index 686f55b1..98c0ebe8 100644
--- a/util/array.lua
+++ b/util/array.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
diff --git a/util/broadcast.lua b/util/broadcast.lua
index 8f6af2fd..c74bf4e1 100644
--- a/util/broadcast.lua
+++ b/util/broadcast.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
diff --git a/util/dataforms.lua b/util/dataforms.lua
index 56671347..5a3b1fb5 100644
--- a/util/dataforms.lua
+++ b/util/dataforms.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
diff --git a/util/datamanager.lua b/util/datamanager.lua
index a2da0aa3..01c7aab2 100644
--- a/util/datamanager.lua
+++ b/util/datamanager.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
diff --git a/util/datetime.lua b/util/datetime.lua
index c582a424..cf00e4c3 100644
--- a/util/datetime.lua
+++ b/util/datetime.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
diff --git a/util/dependencies.lua b/util/dependencies.lua
index baa0cee2..6024dd63 100644
--- a/util/dependencies.lua
+++ b/util/dependencies.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
diff --git a/util/events.lua b/util/events.lua
index ef8fc30a..363d2ac6 100644
--- a/util/events.lua
+++ b/util/events.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
diff --git a/util/helpers.lua b/util/helpers.lua
index e69f1d98..11356176 100644
--- a/util/helpers.lua
+++ b/util/helpers.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
diff --git a/util/hmac.lua b/util/hmac.lua
index 18c559b2..66dd41d8 100644
--- a/util/hmac.lua
+++ b/util/hmac.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
diff --git a/util/import.lua b/util/import.lua
index d5e72eb9..81401e8b 100644
--- a/util/import.lua
+++ b/util/import.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
diff --git a/util/iterators.lua b/util/iterators.lua
index ba33bc80..318c1a96 100644
--- a/util/iterators.lua
+++ b/util/iterators.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
diff --git a/util/jid.lua b/util/jid.lua
index b43247cc..ba9730fa 100644
--- a/util/jid.lua
+++ b/util/jid.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
diff --git a/util/logger.lua b/util/logger.lua
index a73c7eec..fb0bc37b 100644
--- a/util/logger.lua
+++ b/util/logger.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
diff --git a/util/multitable.lua b/util/multitable.lua
index 49659605..66b9bd8a 100644
--- a/util/multitable.lua
+++ b/util/multitable.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
diff --git a/util/pluginloader.lua b/util/pluginloader.lua
index 8c22c204..90138a3e 100644
--- a/util/pluginloader.lua
+++ b/util/pluginloader.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua
index 0776fc76..04d58d1d 100644
--- a/util/prosodyctl.lua
+++ b/util/prosodyctl.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
diff --git a/util/sasl/digest-md5.lua b/util/sasl/digest-md5.lua
index 73b310bc..8986ca45 100644
--- a/util/sasl/digest-md5.lua
+++ b/util/sasl/digest-md5.lua
@@ -50,8 +50,6 @@ local function digest(self, message)
local function serialize(message)
local data = ""
- if type(message) ~= "table" then error("serialize needs an argument of type table.") end
-
-- testing all possible values
if message["realm"] then data = data..[[realm="]]..message.realm..[[",]] end
if message["nonce"] then data = data..[[nonce="]]..message.nonce..[[",]] end
diff --git a/util/sasl_cyrus.lua b/util/sasl_cyrus.lua
index 980af598..b5b0e08d 100644
--- a/util/sasl_cyrus.lua
+++ b/util/sasl_cyrus.lua
@@ -39,7 +39,7 @@ local function init(service_name)
if st then
initialized = true;
else
- log("error", "Failed to initialize CyrusSASL: %s", errmsg);
+ log("error", "Failed to initialize Cyrus SASL: %s", errmsg);
end
end
end
@@ -52,11 +52,24 @@ function new(realm, service_name)
sasl_i.realm = realm;
sasl_i.service_name = service_name;
- sasl_i.cyrus = cyrussasl.server_new(service_name, nil, nil, nil, nil)
- if sasl_i.cyrus == 0 then
- log("error", "got NULL return value from server_new")
+
+ local st, ret = pcall(cyrussasl.server_new, service_name, nil, realm, nil, nil)
+ if st then
+ sasl_i.cyrus = ret;
+ else
+ log("error", "Creating SASL server connection failed: %s", ret);
return nil;
end
+
+ if cyrussasl.set_canon_cb then
+ local c14n_cb = function (user)
+ local node = s_match(user, "^([^@]+)");
+ log("debug", "Canonicalizing username %s to %s", user, node)
+ return node
+ end
+ cyrussasl.set_canon_cb(sasl_i.cyrus, c14n_cb);
+ end
+
cyrussasl.setssf(sasl_i.cyrus, 0, 0xffffffff)
local s = setmetatable(sasl_i, method);
return s;
@@ -69,7 +82,7 @@ end
-- set the forbidden mechanisms
function method:forbidden( restrict )
- log("debug", "Called method:forbidden. NOT IMPLEMENTED.")
+ log("warn", "Called method:forbidden. NOT IMPLEMENTED.")
return {}
end
@@ -110,16 +123,12 @@ function method:process(message)
return "challenge", data
elseif (err == -4) then -- SASL_NOMECH
log("debug", "SASL mechanism not available from remote end")
- return "failure",
- "undefined-condition",
- "SASL mechanism not available"
+ return "failure", "invalid-mechanism", "SASL mechanism not available"
elseif (err == -13) then -- SASL_BADAUTH
return "failure", "not-authorized", cyrussasl.get_message( self.cyrus )
else
log("debug", "Got SASL error condition %d", err)
- return "failure",
- "undefined-condition",
- cyrussasl.get_message( self.cyrus )
+ return "failure", "undefined-condition", cyrussasl.get_message( self.cyrus )
end
end
diff --git a/util/serialization.lua b/util/serialization.lua
index 7071d3f7..bad2fe43 100644
--- a/util/serialization.lua
+++ b/util/serialization.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
diff --git a/util/set.lua b/util/set.lua
index 5f7a9ae2..ee154ece 100644
--- a/util/set.lua
+++ b/util/set.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
diff --git a/util/stanza.lua b/util/stanza.lua
index ad982d42..08ef2c9a 100644
--- a/util/stanza.lua
+++ b/util/stanza.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
diff --git a/util/termcolours.lua b/util/termcolours.lua
index 905b70a6..4e267bee 100644
--- a/util/termcolours.lua
+++ b/util/termcolours.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
diff --git a/util/timer.lua b/util/timer.lua
index c52d9c68..fa1dd7c5 100644
--- a/util/timer.lua
+++ b/util/timer.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
@@ -55,11 +55,12 @@ if not event then
else
local EVENT_LEAVE = (event.core and event.core.LEAVE) or -1;
function _add_task(delay, func)
- event_base:addevent(nil, 0, function ()
+ local event_handle;
+ event_handle = event_base:addevent(nil, 0, function ()
local ret = func();
if ret then
return 0, ret;
- else
+ elseif event_handle then
return EVENT_LEAVE;
end
end
diff --git a/util/uuid.lua b/util/uuid.lua
index 19bf2234..796c8ee4 100644
--- a/util/uuid.lua
+++ b/util/uuid.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
@@ -32,7 +32,7 @@ local function _seed(x)
buffer = new_random(buffer..x);
end
local function get_nibbles(n)
- if #buffer < n then seed(uniq_time()); end
+ if #buffer < n then _seed(uniq_time()); end
local r = buffer:sub(0, n);
buffer = buffer:sub(n+1);
return r;
diff --git a/util/xmlrpc.lua b/util/xmlrpc.lua
index 4855b323..29815b0d 100644
--- a/util/xmlrpc.lua
+++ b/util/xmlrpc.lua
@@ -1,6 +1,6 @@
-- Prosody IM
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
diff --git a/util/xmppstream.lua b/util/xmppstream.lua
new file mode 100644
index 00000000..f7744fea
--- /dev/null
+++ b/util/xmppstream.lua
@@ -0,0 +1,150 @@
+-- Prosody IM
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
+--
+-- This project is MIT/X11 licensed. Please see the
+-- COPYING file in the source package for more information.
+--
+
+
+local lxp = require "lxp";
+local st = require "util.stanza";
+
+local tostring = tostring;
+local t_insert = table.insert;
+local t_concat = table.concat;
+
+local default_log = require "util.logger".init("xmlhandlers");
+
+local error = error;
+
+module "xmppstream"
+
+local new_parser = lxp.new;
+
+local ns_prefixes = {
+ ["http://www.w3.org/XML/1998/namespace"] = "xml";
+};
+
+local xmlns_streams = "http://etherx.jabber.org/streams";
+
+local ns_separator = "\1";
+local ns_pattern = "^([^"..ns_separator.."]*)"..ns_separator.."?(.*)$";
+
+function new_sax_handlers(session, stream_callbacks)
+ local chardata = {};
+ local xml_handlers = {};
+ local log = session.log or default_log;
+
+ local cb_streamopened = stream_callbacks.streamopened;
+ local cb_streamclosed = stream_callbacks.streamclosed;
+ local cb_error = stream_callbacks.error or function(session, e) error("XML stream error: "..tostring(e)); end;
+ local cb_handlestanza = stream_callbacks.handlestanza;
+
+ local stream_ns = stream_callbacks.stream_ns or xmlns_streams;
+ local stream_tag = stream_ns..ns_separator..(stream_callbacks.stream_tag or "stream");
+ local stream_error_tag = stream_ns..ns_separator..(stream_callbacks.error_tag or "error");
+
+ local stream_default_ns = stream_callbacks.default_ns;
+
+ local stanza;
+ function xml_handlers:StartElement(tagname, attr)
+ if stanza and #chardata > 0 then
+ -- We have some character data in the buffer
+ stanza:text(t_concat(chardata));
+ chardata = {};
+ end
+ local curr_ns,name = tagname:match(ns_pattern);
+ if name == "" then
+ curr_ns, name = "", curr_ns;
+ end
+
+ if curr_ns ~= stream_default_ns then
+ attr.xmlns = curr_ns;
+ end
+
+ -- FIXME !!!!!
+ for i=1,#attr do
+ local k = attr[i];
+ attr[i] = nil;
+ local ns, nm = k:match(ns_pattern);
+ if nm ~= "" then
+ ns = ns_prefixes[ns];
+ if ns then
+ attr[ns..":"..nm] = attr[k];
+ attr[k] = nil;
+ end
+ end
+ end
+
+ if not stanza then --if we are not currently inside a stanza
+ if session.notopen then
+ if tagname == stream_tag then
+ if cb_streamopened then
+ cb_streamopened(session, attr);
+ end
+ else
+ -- Garbage before stream?
+ cb_error(session, "no-stream");
+ end
+ return;
+ end
+ if curr_ns == "jabber:client" and name ~= "iq" and name ~= "presence" and name ~= "message" then
+ cb_error(session, "invalid-top-level-element");
+ end
+
+ stanza = st.stanza(name, attr);
+ else -- we are inside a stanza, so add a tag
+ attr.xmlns = nil;
+ if curr_ns ~= stream_default_ns then
+ attr.xmlns = curr_ns;
+ end
+ stanza:tag(name, attr);
+ end
+ end
+ function xml_handlers:CharacterData(data)
+ if stanza then
+ t_insert(chardata, data);
+ end
+ end
+ function xml_handlers:EndElement(tagname)
+ if stanza then
+ if #chardata > 0 then
+ -- We have some character data in the buffer
+ stanza:text(t_concat(chardata));
+ chardata = {};
+ end
+ -- Complete stanza
+ if #stanza.last_add == 0 then
+ if tagname ~= stream_error_tag then
+ cb_handlestanza(session, stanza);
+ else
+ cb_error(session, "stream-error", stanza);
+ end
+ stanza = nil;
+ else
+ stanza:up();
+ end
+ else
+ if tagname == stream_tag then
+ if cb_streamclosed then
+ cb_streamclosed(session);
+ end
+ else
+ local curr_ns,name = tagname:match(ns_pattern);
+ if name == "" then
+ curr_ns, name = "", curr_ns;
+ end
+ cb_error(session, "parse-error", "unexpected-element-close", name);
+ end
+ stanza, chardata = nil, {};
+ end
+ end
+ return xml_handlers;
+end
+
+function new(session, stream_callbacks)
+ return new_parser(new_sax_handlers(session, stream_callbacks), ns_separator);
+end
+
+return _M;
diff --git a/util/ztact.lua b/util/ztact.lua
index 35902ba1..2507bf8e 100644
--- a/util/ztact.lua
+++ b/util/ztact.lua
@@ -114,7 +114,7 @@ function tohex (s) -- - - - - - - - - - - - - - - - - - - - - - - - - tohex
function tostring_r (d, indent, tab0) -- - - - - - - - - - - - - tostring_r
- tab1 = tab0 or {}
+ local tab1 = tab0 or {}
local rep = string.rep (' ', indent or 0)
if type (d) == 'table' then
for k,v in pairs (d) do
@@ -210,7 +210,7 @@ function enqueue (queue, element) -- - - - - - - - - - - - - - - - - enqueue
local function test_queue ()
- t = {}
+ local t = {}
enqueue (t, 1)
enqueue (t, 2)
enqueue (t, 3)