From 242b8f9475a60bf1f9bb574d26269d2d6a10287f Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sun, 19 Dec 2010 20:27:13 +0500 Subject: util.httpstream: A little cleanup of the HTTP path. --- util/httpstream.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/httpstream.lua b/util/httpstream.lua index 4b5060a1..c9f2f691 100644 --- a/util/httpstream.lua +++ b/util/httpstream.lua @@ -46,7 +46,7 @@ local function parser(success_cb, parser_type, options_cb) local status_line = readline(); local method, path, httpversion = status_line:match("^(%S+)%s+(%S+)%s+HTTP/(%S+)$"); if not method then coroutine.yield("invalid-status-line"); end - -- TODO parse url + path = path:gsub("^//+", "/"); -- TODO parse url more local headers = readheaders(); -- read body -- cgit v1.2.3 From e626770ceb54e4526ca2fec6aa59e63ca2cfd27f Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Sun, 19 Dec 2010 20:28:58 +0500 Subject: util.httpstream: For HTTP client responses, changing properties responseversion and responseheaders to httpversion and httpheaders, to match HTTP server requests. --- util/httpstream.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/util/httpstream.lua b/util/httpstream.lua index c9f2f691..bdc3fce7 100644 --- a/util/httpstream.lua +++ b/util/httpstream.lua @@ -104,9 +104,12 @@ local function parser(success_cb, parser_type, options_cb) success_cb({ code = status_code; + httpversion = httpversion; + headers = headers; + body = body; + -- COMPAT the properties below are deprecated responseversion = httpversion; responseheaders = headers; - body = body; }); end else coroutine.yield("unknown-parser-type"); end -- cgit v1.2.3 From 6d96edf726384aa2ce4fd0f5479cf98a39c3b1ef Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 20 Dec 2010 14:06:16 +0000 Subject: prosody, prosodyctl, util.dependencies: Split checking and logging of dependencies so we can check hard deps before the config and logging is loaded --- prosody | 15 +++++++++------ prosodyctl | 9 ++++++--- util/dependencies.lua | 13 ++++++++----- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/prosody b/prosody index 061f3781..d4bf7578 100755 --- a/prosody +++ b/prosody @@ -35,6 +35,12 @@ end prosody = { events = require "util.events".new(); }; local prosody = prosody; +-- Check dependencies +local dependencies = require "util.dependencies"; +if not dependencies.check_dependencies() then + os.exit(1); +end + -- Load the config-parsing module config = require "core.configmanager" @@ -99,11 +105,8 @@ function init_logging() require "core.loggingmanager" end -function check_dependencies() - -- Check runtime dependencies - if not require "util.dependencies".check_dependencies() then - os.exit(1); - end +function log_dependency_warnings() + dependencies.log_warnings(); end function sandbox_require() @@ -442,13 +445,13 @@ end -- previous steps to have already been performed read_config(); init_logging(); -check_dependencies(); sandbox_require(); set_function_metatable(); load_libraries(); init_global_state(); read_version(); log("info", "Hello and welcome to Prosody version %s", prosody.version); +log_dependency_warnings(); load_secondary_libraries(); init_data_store(); init_global_protection(); diff --git a/prosodyctl b/prosodyctl index cfc5ca77..9630a9b8 100755 --- a/prosodyctl +++ b/prosodyctl @@ -41,6 +41,11 @@ prosody = { }; local prosody = prosody; +local dependencies = require "util.dependencies"; +if not dependencies.check_dependencies() then + os.exit(1); +end + config = require "core.configmanager" do @@ -94,9 +99,7 @@ config.set("*", "core", "log", { { levels = { min="info" }, to = "console" } }); require "core.loggingmanager" -if not require "util.dependencies".check_dependencies() then - os.exit(1); -end +dependencies.log_warnings(); local data_path = config.get("*", "core", "data_path") or CFG_DATADIR or "data"; require "util.datamanager".set_data_path(data_path); diff --git a/util/dependencies.lua b/util/dependencies.lua index 6024dd63..9371521c 100644 --- a/util/dependencies.lua +++ b/util/dependencies.lua @@ -78,11 +78,6 @@ function check_dependencies() ["luarocks"] = "luarocks install luasec"; ["Source"] = "http://www.inf.puc-rio.br/~brunoos/luasec/"; }, "SSL/TLS support will not be available"); - else - local major, minor, veryminor, patched = ssl._VERSION:match("(%d+)%.(%d+)%.?(%d*)(M?)"); - if not major or ((tonumber(major) == 0 and (tonumber(minor) or 0) <= 3 and (tonumber(veryminor) or 0) <= 2) and patched ~= "M") then - log("error", "This version of LuaSec contains a known bug that causes disconnects, see http://prosody.im/doc/depends"); - end end local encodings, err = softreq "util.encodings" @@ -121,5 +116,13 @@ function check_dependencies() return not fatal; end +function log_warnings() + if ssl then + local major, minor, veryminor, patched = ssl._VERSION:match("(%d+)%.(%d+)%.?(%d*)(M?)"); + if not major or ((tonumber(major) == 0 and (tonumber(minor) or 0) <= 3 and (tonumber(veryminor) or 0) <= 2) and patched ~= "M") then + log("error", "This version of LuaSec contains a known bug that causes disconnects, see http://prosody.im/doc/depends"); + end + end +end return _M; -- cgit v1.2.3 From 39a38217d871cc9c054909fddb88d9f45d874e0b Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Mon, 20 Dec 2010 14:06:32 +0000 Subject: configmanager: Support for wildcards in Include directives --- core/configmanager.lua | 64 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 15 deletions(-) diff --git a/core/configmanager.lua b/core/configmanager.lua index 52b9fd98..839927df 100644 --- a/core/configmanager.lua +++ b/core/configmanager.lua @@ -7,12 +7,13 @@ -- local _G = _G; -local setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type, pairs, table, format = - setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type, pairs, table, string.format; - +local setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type, pairs, table = + setmetatable, loadfile, pcall, rawget, rawset, io, error, dofile, type, pairs, table; +local format, math_max = string.format, math.max; local fire_event = prosody and prosody.events.fire_event or function () end; +local lfs = require "lfs"; local path_sep = package.config:sub(1,1); module "configmanager" @@ -71,6 +72,10 @@ do local rel_path_start = ".."..path_sep; function resolve_relative_path(parent_path, path) if path then + -- Some normalization + parent_path = parent_path:gsub("%"..path_sep.."+$", ""); + path = path:gsub("^%.%"..path_sep.."+", ""); + local is_relative; if path_sep == "/" and path:sub(1,1) ~= "/" then is_relative = true; @@ -85,6 +90,19 @@ do end end +-- Helper function to convert a glob to a Lua pattern +local function glob_to_pattern(glob) + return "^"..glob:gsub("[%p*?]", function (c) + if c == "*" then + return ".*"; + elseif c == "?" then + return "."; + else + return "%"..c; + end + end).."$"; +end + function load(filename, format) format = format or filename:match("%w+$"); @@ -137,7 +155,7 @@ do local loadstring, pcall, setmetatable = _G.loadstring, _G.pcall, _G.setmetatable; local setfenv, rawget, tostring = _G.setfenv, _G.rawget, _G.tostring; parsers.lua = {}; - function parsers.lua.load(data, filename, config) + function parsers.lua.load(data, config_file, config) local env; -- The ' = true' are needed so as not to set off __newindex when we assign the functions below env = setmetatable({ @@ -199,24 +217,40 @@ do end env.component = env.Component; - function env.Include(file) - local f, err = io.open(file); - if f then - local data = f:read("*a"); - local file = resolve_relative_path(filename:gsub("[^"..path_sep.."]+$", ""), file); - local ret, err = parsers.lua.load(data, file, config); - if not ret then error(err:gsub("%[string.-%]", file), 0); end + function env.Include(file, wildcard) + if file:match("[*?]") then + local path_pos, glob = file:match("()([^"..path_sep.."]+)$"); + local path = file:sub(1, math_max(path_pos-2,0)); + if #path > 0 then + path = resolve_relative_path(config_file:gsub("[^"..path_sep.."]+$", ""), path); + else + path = "."; + end + local patt = glob_to_pattern(glob); + for f in lfs.dir(path) do + if f:sub(1,1) ~= "." and f:match(patt) then + env.Include(path..path_sep..f); + end + end + else + local f, err = io.open(file); + if f then + local data = f:read("*a"); + local file = resolve_relative_path(config_file:gsub("[^"..path_sep.."]+$", ""), file); + local ret, err = parsers.lua.load(data, file, config); + if not ret then error(err:gsub("%[string.-%]", file), 0); end + end + if not f then error("Error loading included "..file..": "..err, 0); end + return f, err; end - if not f then error("Error loading included "..file..": "..err, 0); end - return f, err; end env.include = env.Include; function env.RunScript(file) - return dofile(resolve_relative_path(filename:gsub("[^"..path_sep.."]+$", ""), file)); + return dofile(resolve_relative_path(config_file:gsub("[^"..path_sep.."]+$", ""), file)); end - local chunk, err = loadstring(data, "@"..filename); + local chunk, err = loadstring(data, "@"..config_file); if not chunk then return nil, err; -- cgit v1.2.3 From da58c792b4a86642220ab4234fe98b92783d9582 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 21 Dec 2010 01:30:27 +0000 Subject: prosody.cfg.lua.dist: Update for new logging config format --- prosody.cfg.lua.dist | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/prosody.cfg.lua.dist b/prosody.cfg.lua.dist index e4afce5b..5cfea17f 100644 --- a/prosody.cfg.lua.dist +++ b/prosody.cfg.lua.dist @@ -94,8 +94,11 @@ ssl = { -- Logging configuration -- For advanced logging see http://prosody.im/doc/logging -log = "prosody.log"; -debug = false; -- Log debug messages? +log = { + info = "prosody.log"; -- Change info to debug for verbose logging + error = "prosody.err"; + -- "*syslog"; -- Uncomment this for logging to syslog +} ----------- Virtual hosts ----------- -- You need to add a VirtualHost entry for each domain you wish Prosody to serve. -- cgit v1.2.3 From a8cf2f50055fa9eada83007780d15589ddcdfe27 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 21 Dec 2010 01:47:49 +0000 Subject: prosody.cfg.lua.dist: Add note about external gateways --- prosody.cfg.lua.dist | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/prosody.cfg.lua.dist b/prosody.cfg.lua.dist index 5cfea17f..3134acb6 100644 --- a/prosody.cfg.lua.dist +++ b/prosody.cfg.lua.dist @@ -130,5 +130,10 @@ VirtualHost "example.com" --Component "proxy.example.com" "proxy65" ---Set up an external component (default component port is 5347) +-- +-- External components allow adding various services, such as gateways/ +-- transports to other networks like ICQ, MSN and Yahoo. For more info +-- see: http://prosody.im/doc/components#adding_an_external_component +-- --Component "gateway.example.com" -- component_secret = "password" -- cgit v1.2.3