aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_admin_telnet.lua (renamed from plugins/mod_console.lua)2
-rw-r--r--plugins/mod_bosh.lua15
-rw-r--r--plugins/mod_pep.lua3
-rw-r--r--plugins/mod_pubsub.lua32
-rw-r--r--plugins/mod_saslauth.lua2
-rw-r--r--plugins/mod_storage_sql.lua239
6 files changed, 286 insertions, 7 deletions
diff --git a/plugins/mod_console.lua b/plugins/mod_admin_telnet.lua
index 0b2dd5f8..da40f57e 100644
--- a/plugins/mod_console.lua
+++ b/plugins/mod_admin_telnet.lua
@@ -19,7 +19,7 @@ local console_listener = { default_port = 5582; default_mode = "*l"; default_int
require "util.iterators";
local jid_bare = require "util.jid".bare;
local set, array = require "util.set", require "util.array";
-local cert_verify_identity = require "util.certverification".verify_identity;
+local cert_verify_identity = require "util.x509".verify_identity;
local commands = {};
local def_env = {};
diff --git a/plugins/mod_bosh.lua b/plugins/mod_bosh.lua
index d346f247..58254169 100644
--- a/plugins/mod_bosh.lua
+++ b/plugins/mod_bosh.lua
@@ -33,7 +33,6 @@ local BOSH_DEFAULT_HOLD = tonumber(module:get_option("bosh_default_hold")) or 1;
local BOSH_DEFAULT_INACTIVITY = tonumber(module:get_option("bosh_max_inactivity")) or 60;
local BOSH_DEFAULT_POLLING = tonumber(module:get_option("bosh_max_polling")) or 5;
local BOSH_DEFAULT_REQUESTS = tonumber(module:get_option("bosh_max_requests")) or 2;
-local BOSH_DEFAULT_MAXPAUSE = tonumber(module:get_option("bosh_max_pause")) or 300;
local consider_bosh_secure = module:get_option_boolean("consider_bosh_secure");
@@ -283,9 +282,17 @@ function stream_callbacks.streamopened(request, attr)
fire_event("stream-features", session, features);
--xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh'
local response = st.stanza("body", { xmlns = xmlns_bosh,
- inactivity = tostring(BOSH_DEFAULT_INACTIVITY), polling = tostring(BOSH_DEFAULT_POLLING), requests = tostring(BOSH_DEFAULT_REQUESTS), hold = tostring(session.bosh_hold), maxpause = "120",
- sid = sid, authid = sid, ver = '1.6', from = session.host, secure = 'true', ["xmpp:version"] = "1.0",
- ["xmlns:xmpp"] = "urn:xmpp:xbosh", ["xmlns:stream"] = "http://etherx.jabber.org/streams" }):add_child(features);
+ wait = attr.wait,
+ inactivity = tostring(BOSH_DEFAULT_INACTIVITY),
+ polling = tostring(BOSH_DEFAULT_POLLING),
+ requests = tostring(BOSH_DEFAULT_REQUESTS),
+ hold = tostring(session.bosh_hold),
+ sid = sid, authid = sid,
+ ver = '1.6', from = session.host,
+ secure = 'true', ["xmpp:version"] = "1.0",
+ ["xmlns:xmpp"] = "urn:xmpp:xbosh",
+ ["xmlns:stream"] = "http://etherx.jabber.org/streams"
+ }):add_child(features);
request:send{ headers = default_headers, body = tostring(response) };
request.sid = sid;
diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua
index 28c31294..9ff6cac2 100644
--- a/plugins/mod_pep.lua
+++ b/plugins/mod_pep.lua
@@ -134,7 +134,8 @@ module:hook("presence/bare", function(event)
publish_all(user, recipient, origin);
else
recipients[user][recipient] = hash;
- if self or origin.type ~= "c2s" then
+ local from_bare = origin.type == "c2s" and origin.username.."@"..origin.host;
+ if self or origin.type ~= "c2s" or (recipients[from_bare] and recipients[from_bare][origin.full_jid]) ~= hash then
origin.send(
st.stanza("iq", {from=stanza.attr.to, to=stanza.attr.from, id="disco", type="get"})
:query("http://jabber.org/protocol/disco#info")
diff --git a/plugins/mod_pubsub.lua b/plugins/mod_pubsub.lua
index 0953de28..dc1b1263 100644
--- a/plugins/mod_pubsub.lua
+++ b/plugins/mod_pubsub.lua
@@ -166,8 +166,40 @@ end
module:hook("iq/host/http://jabber.org/protocol/pubsub:pubsub", handle_pubsub_iq);
+local disco_info = st.stanza("query", { xmlns = "http://jabber.org/protocol/disco#info" })
+ :tag("identity", { category = "pubsub", type = "service" }):up()
+ :tag("feature", { var = "http://jabber.org/protocol/pubsub" }):up();
+
+module:hook("iq-get/host/http://jabber.org/protocol/disco#info:query", function (event)
+ event.origin.send(st.reply(event.stanza):add_child(disco_info));
+ return true;
+end);
+
+module:hook("iq-get/host/http://jabber.org/protocol/disco#items:query", function (event)
+ local ok, ret = service:get_nodes(event.stanza.attr.from);
+ if not ok then
+ event.origin.send(pubsub_error_reply(stanza, ret));
+ else
+ local reply = st.reply(event.stanza)
+ :tag("query", { xmlns = "http://jabber.org/protocol/disco#items" });
+ for node, node_obj in pairs(ret) do
+ reply:tag("item", { jid = module.host, node = node, name = node_obj.config.name }):up();
+ end
+ event.origin.send(reply);
+ end
+ return true;
+end);
+
service = pubsub.new({
broadcaster = simple_broadcast
});
module.environment.service = service;
+function module.save()
+ return { service = service };
+end
+
+function module.restore(data)
+ service = data.service;
+ module.environment.service = service;
+end
diff --git a/plugins/mod_saslauth.lua b/plugins/mod_saslauth.lua
index 37b2720b..7f9a27ad 100644
--- a/plugins/mod_saslauth.lua
+++ b/plugins/mod_saslauth.lua
@@ -14,7 +14,7 @@ local sm_make_authenticated = require "core.sessionmanager".make_authenticated;
local s2s_make_authenticated = require "core.s2smanager".make_authenticated;
local base64 = require "util.encodings".base64;
-local cert_verify_identity = require "util.certverification".verify_identity;
+local cert_verify_identity = require "util.x509".verify_identity;
local nodeprep = require "util.encodings".stringprep.nodeprep;
local usermanager_get_sasl_handler = require "core.usermanager".get_sasl_handler;
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua
new file mode 100644
index 00000000..e3eb3c77
--- /dev/null
+++ b/plugins/mod_storage_sql.lua
@@ -0,0 +1,239 @@
+
+--[[
+
+DB Tables:
+ Prosody - key-value, map
+ | host | user | store | key | subkey | type | value |
+ ProsodyArchive - list
+ | host | user | store | key | time | stanzatype | jsonvalue |
+
+Mapping:
+ Roster - Prosody
+ | host | user | "roster" | "contactjid" | item-subkey | type | value |
+ | host | user | "roster" | NULL | NULL | "json" | roster[false] data |
+ Account - Prosody
+ | host | user | "accounts" | "username" | NULL | type | value |
+
+ Offline - ProsodyArchive
+ | host | user | "offline" | "contactjid" | time | "message" | json|XML |
+
+]]
+
+local type = type;
+local tostring = tostring;
+local tonumber = tonumber;
+local pairs = pairs;
+local next = next;
+local setmetatable = setmetatable;
+local json = { stringify = function(s) return require"util.serialization".serialize(s) end, parse = require"util.serialization".deserialze };
+
+local connection = ...;
+local host,user,store = module.host;
+
+do -- process options to get a db connection
+ local DBI = require "DBI";
+
+ local params = module:get_option("sql") or { driver = "SQLite3", database = "prosody.sqlite" };
+ assert(params and params.driver and params.database, "invalid params");
+
+ prosody.unlock_globals();
+ local dbh, err = DBI.Connect(
+ params.driver, params.database,
+ params.username, params.password,
+ params.host, params.port
+ );
+ prosody.lock_globals();
+ assert(dbh, err);
+
+ dbh:autocommit(false); -- don't commit automatically
+ connection = dbh;
+
+ if params.driver == "SQLite3" then -- auto initialize
+ local stmt = assert(connection:prepare("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='Prosody';"));
+ local ok = assert(stmt:execute());
+ local count = stmt:fetch()[1];
+ if count == 0 then
+ local stmt = assert(connection:prepare("CREATE TABLE Prosody (host TEXT, user TEXT, store TEXT, key TEXT, subkey TEXT, type TEXT, value TEXT);"));
+ assert(stmt:execute());
+ assert(connection:commit());
+ module:log("debug", "Initialized new SQLite3 database");
+ end
+ --print("===", json.stringify())
+ end
+end
+
+local function serialize(value)
+ local t = type(value);
+ if t == "string" or t == "boolean" or t == "number" then
+ return t, tostring(value);
+ elseif t == "table" then
+ local value,err = json.stringify(value);
+ if value then return "json", value; end
+ return nil, err;
+ end
+ return nil, "Unhandled value type: "..t;
+end
+local function deserialize(t, value)
+ if t == "string" then return value;
+ elseif t == "boolean" then
+ if value == "true" then return true;
+ elseif value == "false" then return false; end
+ elseif t == "number" then return tonumber(value);
+ elseif value == "json" then
+ return json.parse(value);
+ end
+end
+
+local function getsql(sql, ...)
+ -- do prepared statement stuff
+ local stmt, err = connection:prepare(sql);
+ if not stmt then return nil, err; end
+ -- run query
+ local ok, err = stmt:execute(host, user, store, ...);
+ if not ok then return nil, err; end
+
+ return stmt;
+end
+local function setsql(sql, ...)
+ local stmt, err = getsql(sql, ...);
+ if not stmt then return stmt, err; end
+ return stmt:affected();
+end
+local function transact(...)
+ -- ...
+end
+local function rollback(...)
+ connection:rollback(); -- FIXME check for rollback error?
+ return ...;
+end
+local function commit(...)
+ if not connection:commit() then return nil, "SQL commit failed"; end
+ return ...;
+end
+
+local keyval_store = {};
+keyval_store.__index = keyval_store;
+function keyval_store:get(username)
+ user,store = username,self.store;
+ local stmt, err = getsql("SELECT * FROM Prosody WHERE host IS ? AND user IS ? AND store IS ? AND subkey IS NULL");
+ if not stmt then return nil, err; end
+
+ local haveany;
+ local result = {};
+ for row in stmt:rows(true) do
+ haveany = true;
+ local k = row.key;
+ local v = deserialize(row.type, row.value);
+ if v then
+ if k then result[k] = v; elseif type(v) == "table" then
+ for a,b in pairs(v) do
+ result[a] = b;
+ end
+ end
+ end
+ end
+ return haveany and result or nil;
+end
+function keyval_store:set(username, data)
+ user,store = username,self.store;
+ -- start transaction
+ local affected, err = setsql("DELETE FROM Prosody WHERE host IS ? AND user IS ? AND store IS ? AND subkey IS NULL");
+
+ if data and next(data) ~= nil then
+ local extradata = {};
+ for key, value in pairs(data) do
+ if type(key) == "string" then
+ local t, value = serialize(value);
+ if not t then return rollback(t, value); end
+ local ok, err = setsql("INSERT INTO Prosody (host,user,store,key,type,value) VALUES (?,?,?,?,?,?)", key, t, value);
+ if not ok then return rollback(ok, err); end
+ else
+ extradata[key] = value;
+ end
+ end
+ if next(extradata) ~= nil then
+ local t, extradata = serialize(extradata);
+ if not t then return rollback(t, extradata); end
+ local ok, err = setsql("INSERT INTO Prosody (host,user,store,key,type,value) VALUES (?,?,?,?,?,?)", nil, t, extradata);
+ if not ok then return rollback(ok, err); end
+ end
+ end
+ return commit(true);
+end
+
+local map_store = {};
+map_store.__index = map_store;
+function map_store:get(username, key)
+ user,store = username,self.store;
+ local stmt, err = getsql("SELECT * FROM Prosody WHERE host IS ? AND user IS ? AND store IS ? AND key IS ?", key);
+ if not stmt then return nil, err; end
+
+ local haveany;
+ local result = {};
+ for row in stmt:rows(true) do
+ haveany = true;
+ local k = row.subkey;
+ local v = deserialize(row.type, row.value);
+ if v then
+ if k then result[k] = v; elseif type(v) == "table" then
+ for a,b in pairs(v) do
+ result[a] = b;
+ end
+ end
+ end
+ end
+ return haveany and result or nil;
+end
+function map_store:set(username, key, data)
+ user,store = username,self.store;
+ -- start transaction
+ local affected, err = setsql("DELETE FROM Prosody WHERE host IS ? AND user IS ? AND store IS ? AND key IS ?", key);
+
+ if data and next(data) ~= nil then
+ local extradata = {};
+ for subkey, value in pairs(data) do
+ if type(subkey) == "string" then
+ local t, value = serialize(value);
+ if not t then return rollback(t, value); end
+ local ok, err = setsql("INSERT INTO Prosody (host,user,store,key,subkey,type,value) VALUES (?,?,?,?,?,?)", key, subkey, t, value);
+ if not ok then return rollback(ok, err); end
+ else
+ extradata[subkey] = value;
+ end
+ end
+ if next(extradata) ~= nil then
+ local t, extradata = serialize(extradata);
+ if not t then return rollback(t, extradata); end
+ local ok, err = setsql("INSERT INTO Prosody (host,user,store,key,subkey,type,value) VALUES (?,?,?,?,?,?)", key, nil, t, extradata);
+ if not ok then return rollback(ok, err); end
+ end
+ end
+ return commit(true);
+end
+
+local list_store = {};
+list_store.__index = list_store;
+function list_store:scan(username, from, to, jid, typ)
+ user,store = username,self.store;
+
+ local cols = {"from", "to", "jid", "typ"};
+ local vals = { from , to , jid , typ };
+ local stmt, err;
+ local query = "SELECT * FROM ProsodyArchive WHERE host IS ? AND user IS ? AND store IS ?";
+
+ query = query.." ORDER BY time";
+ --local stmt, err = getsql("SELECT * FROM Prosody WHERE host IS ? AND user IS ? AND store IS ? AND key IS ?", key);
+
+ return nil, "not-implemented"
+end
+
+local driver = { name = "sql" };
+
+function driver:open(store, typ)
+ if not typ then -- default key-value store
+ return setmetatable({ store = store }, keyval_store);
+ end
+ return nil, "unsupported-store";
+end
+
+module:add_item("data-driver", driver);