From 47761d875a1db3f3f7415e0f137b3b0287c640e2 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 28 Nov 2008 20:17:20 +0500 Subject: Added option core.data_path --- main.lua | 2 ++ util/datamanager.lua | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/main.lua b/main.lua index 3ea97ca4..7e41012c 100644 --- a/main.lua +++ b/main.lua @@ -24,6 +24,8 @@ do end end +require "util.datamanager".set_data_path(config.get("*", "core", "data_path") or "data"); + local server = require "net.server" require "util.dependencies" diff --git a/util/datamanager.lua b/util/datamanager.lua index 80b35733..f25fffb3 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -17,6 +17,8 @@ local indent = function(f, i) end end +local data_path = "data"; + module "datamanager" @@ -70,14 +72,18 @@ end ------- API ------------- +function set_data_path(path) + data_path = path; +end + function getpath(username, host, datastore, ext) ext = ext or "dat"; if username then - return format("data/%s/%s/%s.%s", encode(host), datastore, encode(username), ext); + return format("%s/%s/%s/%s.%s", data_path, encode(host), datastore, encode(username), ext); elseif host then - return format("data/%s/%s.%s", encode(host), datastore, ext); + return format("%s/%s/%s.%s", data_path, encode(host), datastore, ext); else - return format("data/%s.%s", datastore, ext); + return format("%s/%s.%s", data_path, datastore, ext); end end -- cgit v1.2.3 From e26768484b03eaa827f59b85d367fabbb43fdc88 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Fri, 28 Nov 2008 22:47:22 +0500 Subject: Quickfix for dns.lua to not crash on failed connection to name servers --- net/dns.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/dns.lua b/net/dns.lua index 7364161e..ea1d5d96 100644 --- a/net/dns.lua +++ b/net/dns.lua @@ -691,7 +691,8 @@ function resolver:pulse () -- - - - - - - - - - - - - - - - - - - - - pulse if not next (self.active) then return nil end else -- print ('retry', o.server, o.delay) - self.socket[o.server]:send (o.packet) + local _a = self.socket[o.server]; + if _a then _a:send (o.packet) end o.retry = self.time + self.delays[o.delay] end end end end -- cgit v1.2.3 From 34b736f5cf8a7c09f460c982dbf9332989da868e Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sat, 29 Nov 2008 05:53:11 +0500 Subject: Fixed logging in datamanager --- util/datamanager.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/util/datamanager.lua b/util/datamanager.lua index f25fffb3..99eef9f3 100644 --- a/util/datamanager.lua +++ b/util/datamanager.lua @@ -3,7 +3,7 @@ local setmetatable, type = setmetatable, type; local pairs, ipairs = pairs, ipairs; local char = string.char; local loadfile, setfenv, pcall = loadfile, setfenv, pcall; -local log = log; +local log = require "util.logger".init("datamanager"); local io_open = io.open; local os_remove = os.remove; local tostring, tonumber = tostring, tonumber; @@ -25,8 +25,6 @@ module "datamanager" ---- utils ----- local encode, decode; -local log = function (type, msg) return log(type, "datamanager", msg); end - do local urlcodes = setmetatable({}, { __index = function (t, k) t[k] = char(tonumber("0x"..k)); return t[k]; end }); -- cgit v1.2.3 From fa1df6cfe4f7dae1827faf785c40c42f3d00a6db Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sat, 29 Nov 2008 05:56:09 +0500 Subject: Improved the regexp used to parse the client response a bit. Authenticating with non-ascii realm values now works. --- util/sasl.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/sasl.lua b/util/sasl.lua index 001f40fb..a1f36760 100644 --- a/util/sasl.lua +++ b/util/sasl.lua @@ -66,7 +66,7 @@ local function new_digest_md5(realm, password_handler) local function parse(data) message = {} - for k, v in gmatch(data, [[([%w%-]+)="?([%w%-%/%.%+=]+)"?,?]]) do + for k, v in gmatch(data, [[([%w%-]+)="?([^",]*)"?,?]]) do message[k] = v end return message -- cgit v1.2.3 From c070aa7279f57db0e954ca8004f514e4c8afdcaa Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sat, 29 Nov 2008 05:57:57 +0500 Subject: Added a FIXME --- util/sasl.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/sasl.lua b/util/sasl.lua index a1f36760..0f03647f 100644 --- a/util/sasl.lua +++ b/util/sasl.lua @@ -66,7 +66,7 @@ local function new_digest_md5(realm, password_handler) local function parse(data) message = {} - for k, v in gmatch(data, [[([%w%-]+)="?([^",]*)"?,?]]) do + for k, v in gmatch(data, [[([%w%-]+)="?([^",]*)"?,?]]) do -- FIXME The hacky regex makes me shudder message[k] = v end return message -- cgit v1.2.3 From dd37be1f32ea1d3751e5fe6079543d1c359c3c36 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 29 Nov 2008 01:00:04 +0000 Subject: main.lua -> prosody --- main.lua | 103 ------------------------------------------------------- prosody | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 103 deletions(-) delete mode 100644 main.lua create mode 100644 prosody diff --git a/main.lua b/main.lua deleted file mode 100644 index 7e41012c..00000000 --- a/main.lua +++ /dev/null @@ -1,103 +0,0 @@ -pcall(require, "luarocks.require") - -config = require "core.configmanager" -log = require "util.logger".init("general"); - -do - -- TODO: Check for other formats when we add support for them - -- Use lfs? Make a new conf/ dir? - local ok, err = config.load("lxmppd.cfg.lua"); - if not ok then - log("error", "Couldn't load config file: %s", err); - log("info", "Falling back to old config file format...") - ok, err = pcall(dofile, "lxmppd.cfg"); - if not ok then - log("error", "Old config format loading failed too: %s", err); - else - for _, host in ipairs(_G.config.hosts) do - config.set(host, "core", "defined", true); - end - - config.set("*", "core", "modules_enabled", _G.config.modules); - config.set("*", "core", "ssl", _G.config.ssl_ctx); - end - end -end - -require "util.datamanager".set_data_path(config.get("*", "core", "data_path") or "data"); - -local server = require "net.server" - -require "util.dependencies" - --- Maps connections to sessions -- -sessions = {}; -hosts = {}; - -local defined_hosts = config.getconfig(); - -for host, host_config in pairs(defined_hosts) do - if host ~= "*" and (host_config.core.enabled == nil or host_config.core.enabled) then - hosts[host] = {type = "local", connected = true, sessions = {}, host = host, s2sout = {} }; - end -end - --- Load and initialise core modules -- - -require "util.import" -require "core.xmlhandlers" -require "core.rostermanager" -require "core.offlinemessage" -require "core.modulemanager" -require "core.usermanager" -require "core.sessionmanager" -require "core.stanza_router" - ---[[ -pcall(require, "remdebug.engine"); -if remdebug then remdebug.engine.start() end -]] - -local start = require "net.connlisteners".start; -require "util.stanza" -require "util.jid" - ------------------------------------------------------------------------- - --- Initialise modules - -for host in pairs(hosts) do - if host ~= "*" then - local modules_enabled = config.get(host, "core", "modules_enabled"); - if modules_enabled then - for _, module in pairs(modules_enabled) do - modulemanager.load(host, module); - end - end - end -end - --- setup error handling -setmetatable(_G, { __index = function (t, k) print("WARNING: ATTEMPT TO READ A NIL GLOBAL!!!", k); error("Attempt to read a non-existent global. Naughty boy.", 2); end, __newindex = function (t, k, v) print("ATTEMPT TO SET A GLOBAL!!!!", tostring(k).." = "..tostring(v)); error("Attempt to set a global. Naughty boy.", 2); end }) --]][][[]][]; - -local protected_handler = function (conn, data, err) local success, ret = pcall(handler, conn, data, err); if not success then print("ERROR on "..tostring(conn)..": "..ret); conn:close(); end end; -local protected_disconnect = function (conn, err) local success, ret = pcall(disconnect, conn, err); if not success then print("ERROR on "..tostring(conn).." disconnect: "..ret); conn:close(); end end; - - -local global_ssl_ctx = config.get("*", "core", "ssl"); -if global_ssl_ctx then - local default_ssl_ctx = { mode = "server", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none"; }; - setmetatable(global_ssl_ctx, { __index = default_ssl_ctx }); -end - --- start listening on sockets -start("xmppclient", { ssl = global_ssl_ctx }) -start("xmppserver", { ssl = global_ssl_ctx }) - -if config.get("*", "core", "console_enabled") then - start("console") -end - -modulemanager.fire_event("server-started"); - -server.loop(); diff --git a/prosody b/prosody new file mode 100644 index 00000000..6f13decd --- /dev/null +++ b/prosody @@ -0,0 +1,118 @@ +#!/usr/bin/env lua + +-- Config here -- + + + +-- -- -- -- -- -- + +if CFG_SOURCEDIR then + package.path = CFG_SOURCEDIR.."/?.lua;"..package.path + package.cpath = CFG_SOURCEDIR.."/?.lua;"..package.cpath +end + +-- Required to be able to find packages installed with luarocks +pcall(require, "luarocks.require") + + +config = require "core.configmanager" +log = require "util.logger".init("general"); + +do + -- TODO: Check for other formats when we add support for them + -- Use lfs? Make a new conf/ dir? + local ok, err = config.load("lxmppd.cfg.lua"); + if not ok then + log("error", "Couldn't load config file: %s", err); + log("info", "Falling back to old config file format...") + ok, err = pcall(dofile, "lxmppd.cfg"); + if not ok then + log("error", "Old config format loading failed too: %s", err); + else + for _, host in ipairs(_G.config.hosts) do + config.set(host, "core", "defined", true); + end + + config.set("*", "core", "modules_enabled", _G.config.modules); + config.set("*", "core", "ssl", _G.config.ssl_ctx); + end + end +end + +require "util.datamanager".set_data_path(config.get("*", "core", "data_path") or "data"); + +local server = require "net.server" + +require "util.dependencies" + +-- Maps connections to sessions -- +sessions = {}; +hosts = {}; + +local defined_hosts = config.getconfig(); + +for host, host_config in pairs(defined_hosts) do + if host ~= "*" and (host_config.core.enabled == nil or host_config.core.enabled) then + hosts[host] = {type = "local", connected = true, sessions = {}, host = host, s2sout = {} }; + end +end + +-- Load and initialise core modules -- + +require "util.import" +require "core.xmlhandlers" +require "core.rostermanager" +require "core.offlinemessage" +require "core.modulemanager" +require "core.usermanager" +require "core.sessionmanager" +require "core.stanza_router" + +--[[ +pcall(require, "remdebug.engine"); +if remdebug then remdebug.engine.start() end +]] + +local start = require "net.connlisteners".start; +require "util.stanza" +require "util.jid" + +------------------------------------------------------------------------ + +-- Initialise modules + +for host in pairs(hosts) do + if host ~= "*" then + local modules_enabled = config.get(host, "core", "modules_enabled"); + if modules_enabled then + for _, module in pairs(modules_enabled) do + modulemanager.load(host, module); + end + end + end +end + +-- setup error handling +setmetatable(_G, { __index = function (t, k) print("WARNING: ATTEMPT TO READ A NIL GLOBAL!!!", k); error("Attempt to read a non-existent global. Naughty boy.", 2); end, __newindex = function (t, k, v) print("ATTEMPT TO SET A GLOBAL!!!!", tostring(k).." = "..tostring(v)); error("Attempt to set a global. Naughty boy.", 2); end }) --]][][[]][]; + +local protected_handler = function (conn, data, err) local success, ret = pcall(handler, conn, data, err); if not success then print("ERROR on "..tostring(conn)..": "..ret); conn:close(); end end; +local protected_disconnect = function (conn, err) local success, ret = pcall(disconnect, conn, err); if not success then print("ERROR on "..tostring(conn).." disconnect: "..ret); conn:close(); end end; + + +local global_ssl_ctx = config.get("*", "core", "ssl"); +if global_ssl_ctx then + local default_ssl_ctx = { mode = "server", protocol = "sslv23", capath = "/etc/ssl/certs", verify = "none"; }; + setmetatable(global_ssl_ctx, { __index = default_ssl_ctx }); +end + +-- start listening on sockets +start("xmppclient", { ssl = global_ssl_ctx }) +start("xmppserver", { ssl = global_ssl_ctx }) + +if config.get("*", "core", "console_enabled") then + start("console") +end + +modulemanager.fire_event("server-started"); + +server.loop(); -- cgit v1.2.3 From 2ccbc9f3ef7b20bddfa2eb9a785e28245603af4a Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 29 Nov 2008 01:02:32 +0000 Subject: Make prosody executable --- prosody | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 prosody diff --git a/prosody b/prosody old mode 100644 new mode 100755 -- cgit v1.2.3 From 86d586d667c659a6b30d431de1384c8df7eedca4 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sat, 29 Nov 2008 06:08:37 +0500 Subject: Load prosody instead of main.lia in mod_console --- plugins/mod_console.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_console.lua b/plugins/mod_console.lua index b1dc263c..76272f03 100644 --- a/plugins/mod_console.lua +++ b/plugins/mod_console.lua @@ -124,7 +124,7 @@ end def_env.server = {}; function def_env.server:reload() - dofile "main.lua" + dofile "prosody" return true, "Server reloaded"; end -- cgit v1.2.3 From 625abbc37426b1a680128e29599c9f1e8fd4bf48 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 29 Nov 2008 01:49:23 +0000 Subject: Removing pull_from_master.sh. Use hg fetch instead. --- pull_from_master.sh | 3 --- 1 file changed, 3 deletions(-) delete mode 100755 pull_from_master.sh diff --git a/pull_from_master.sh b/pull_from_master.sh deleted file mode 100755 index 3c909b76..00000000 --- a/pull_from_master.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -which hg >/dev/null || echo "You must have Mercurial (the hg command)" -hg pull http://heavy-horse.co.uk:4000/ -- cgit v1.2.3 From dcf87bb7c912e4206aae1fd3c959d87e8f59242f Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 29 Nov 2008 02:07:33 +0000 Subject: Add a top-level Makefile and ./configure script. Update util-src Makefile for this. --- Makefile | 21 +++++ configure | 243 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ util-src/Makefile | 17 ++-- 3 files changed, 274 insertions(+), 7 deletions(-) create mode 100644 Makefile create mode 100755 configure diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..00826f54 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ + +include config.unix + +BIN = $(DESTDIR)$(PREFIX)/bin +CONFIG = $(DESTDIR)$(SYSCONFDIR) +MODULES = $(DESTDIR)$(PREFIX)/lib/prosody/modules + +SOURCEDIR = $(DESTDIR)$(PREFIX)/lib/prosody + +all: + $(MAKE) all -C util-src + +install: prosody + install -d $(BIN) $(CONFIG) $(MODULES) + install ./prosody $(BIN) + install -m644 plugins/* $(MODULES) + install -m644 prosody.cfg.lua $(CONFIG) + $(MAKE) install -C util-src + +clean: + $(MAKE) clean -C util-src diff --git a/configure b/configure new file mode 100755 index 00000000..758e70df --- /dev/null +++ b/configure @@ -0,0 +1,243 @@ +#!/bin/sh + +# Defaults + +PREFIX=/usr/local +SYSCONFDIR="$PREFIX/etc/prosody" +LUA_SUFFIX="" +LUA_DIR="/usr" +LUA_BINDIR="/usr/bin" +LUA_INCDIR="/usr/include" +LUA_LIBDIR="/usr/lib" +IDN_LIB=idn +OPENSSL_LIB=ssl + +# Help + +show_help() { +cat < config.unix +# This file was automatically generated by the configure script. +# Run "./configure --help" for details. + +PREFIX=$PREFIX +SYSCONFDIR=$SYSCONFDIR +LUA_SUFFIX=$LUA_SUFFIX +LUA_DIR=$LUA_DIR +LUA_INCDIR=$LUA_INCDIR +LUA_LIBDIR=$LUA_LIBDIR +LUA_BINDIR=$LUA_BINDIR +REQUIRE_CONFIG=$REQUIRE_CONFIG +IDN_LIB=$IDN_LIB +OPENSSL_LIB=$OPENSSL_LIB + +EOF + +echo "Installation prefix: $PREFIX" +echo "Prosody configuration directory: $SYSCONFDIR" +echo "Using Lua from: $LUA_DIR" + +make clean > /dev/null 2> /dev/null + +echo +echo "Done. You can now run 'make' to build." +echo diff --git a/util-src/Makefile b/util-src/Makefile index a4901c95..90e80aea 100644 --- a/util-src/Makefile +++ b/util-src/Makefile @@ -1,10 +1,12 @@ +include ../config.unix -LUA_INCLUDE=/usr/include/lua5.1 -LUA_LIB=lua5.1 +LUA_SUFFIX?=5.1 +LUA_INCDIR?=/usr/include/lua$(LUA_SUFFIX) +LUA_LIB?=lua$(LUA_SUFFIX) +IDN_LIB?=idn +OPENSSL_LIB?=ssl -IDN_LIB=idn -OPENSSL_LIB=ssl all: encodings.so hashes.so @@ -15,11 +17,12 @@ install: encodings.so hashes.so clean: - rm *.so + rm -f *.so + rm -f ../util/*.so encodings.so: encodings.c - gcc -shared encodings.c -I$(LUA_INCLUDE) -l$(LUA_LIB) -l$(IDN_LIB) -o encodings.so + gcc -shared encodings.c -I$(LUA_INCDIR) -l$(LUA_LIB) -l$(IDN_LIB) -o encodings.so hashes.so: hashes.c - gcc -shared hashes.c -I$(LUA_INCLUDE) -l$(LUA_LIB) -l$(OPENSSL_LIB) -o hashes.so + gcc -shared hashes.c -I$(LUA_INCDIR) -l$(LUA_LIB) -l$(OPENSSL_LIB) -o hashes.so -- cgit v1.2.3