# HG changeset patch # User Matthew Wild # Date 1259786131 0 # Node ID a67d06338db09933676aa5b83ca48ab9cf844bed # Parent 90e4941ea8b69b735a1764866bb1832a964474db# Parent 23e84604fb0088b30ae0cdebdb7c2df56bde6baa Merge with Tobias diff -r 23e84604fb00 -r a67d06338db0 core/modulemanager.lua --- a/core/modulemanager.lua Tue Dec 01 23:23:51 2009 +0100 +++ b/core/modulemanager.lua Wed Dec 02 20:35:31 2009 +0000 @@ -175,7 +175,7 @@ end function unload(host, name, ...) - local mod = get_module(host, name); + local mod = get_module(host, name); if not mod then return nil, "module-not-loaded"; end if module_has_method(mod, "unload") then @@ -282,7 +282,7 @@ end function call_module_method(module, method, ...) - if module_has_method(module, method) then + if module_has_method(module, method) then local f = module.module[method]; return pcall(f, ...); else @@ -291,7 +291,7 @@ end ----- API functions exposed to modules ----------- --- Must all be in api.* +-- Must all be in api.* -- Returns the name of the current module function api:get_name() diff -r 23e84604fb00 -r a67d06338db0 net/dns.lua --- a/net/dns.lua Tue Dec 01 23:23:51 2009 +0100 +++ b/net/dns.lua Wed Dec 02 20:35:31 2009 +0000 @@ -726,7 +726,7 @@ local packet = sock:receive(); if packet then response = self:decode(packet); - if response and self.active[response.header.id] + if response and self.active[response.header.id] and self.active[response.header.id][response.question.raw] then --print('received response'); --self.print(response); diff -r 23e84604fb00 -r a67d06338db0 net/httpserver.lua --- a/net/httpserver.lua Tue Dec 01 23:23:51 2009 +0100 +++ b/net/httpserver.lua Wed Dec 02 20:35:31 2009 +0000 @@ -23,6 +23,9 @@ local log = require "util.logger".init("httpserver"); +-- TODO: Should we read this from /etc/mime.types if it exists? (startup time...?) +local mime_map = { html = "text/html", txt = "plain/text; charset=utf-8", js = "text/javascript" }; + local http_servers = {}; module "httpserver" @@ -65,6 +68,9 @@ resp = { "HTTP/1.0 200 OK\r\n" }; t_insert(resp, "Connection: close\r\n"); + t_insert(resp, "Content-Type: "); + t_insert(resp, mime_map[request.url.path:match("%.(%w+)")] or "application/octet-stream"); + t_insert(resp, "\r\n"); t_insert(resp, "Content-Length: "); t_insert(resp, #response); t_insert(resp, "\r\n\r\n"); @@ -210,7 +216,7 @@ function new_request(handler) return { handler = handler, conn = handler.socket, write = function (...) return handler:write(...); end, state = "request", - server = http_servers[handler.serverport()], + server = http_servers[handler:serverport()], send = send_response, destroy = destroy_request, id = tostring{}:match("%x+$") diff -r 23e84604fb00 -r a67d06338db0 prosodyctl --- a/prosodyctl Tue Dec 01 23:23:51 2009 +0100 +++ b/prosodyctl Wed Dec 02 20:35:31 2009 +0000 @@ -462,6 +462,28 @@ return 1; end +function commands.addplugin(arg) + local url = arg[1]; + if url:match("^http://") then + local http = require "socket.http"; + show_message("Fetching..."); + local code, err = http.request(url); + if not code then + show_message("Failed: "..err); + return 1; + end + if url:match("%.lua$") then + local ok, err = datamanager.store(url:match("/mod_([^/]+)$"), "*", "plugins", {code}); + if not ok then + show_message("Failed to save to data store: "..err); + return 1; + end + end + show_message("Saved. Don't forget to load the module using the config file or admin console!"); + else + show_message("Sorry, I don't understand how to fetch plugins from there."); + end +end --------------------- diff -r 23e84604fb00 -r a67d06338db0 util/pluginloader.lua --- a/util/pluginloader.lua Tue Dec 01 23:23:51 2009 +0100 +++ b/util/pluginloader.lua Wed Dec 02 20:35:31 2009 +0000 @@ -9,11 +9,19 @@ local plugin_dir = CFG_PLUGINDIR or "./plugins/"; -local io_open = io.open; -local loadstring = loadstring; +local io_open, os_time = io.open, os.time; +local loadstring, pairs = loadstring, pairs; + +local datamanager = require "util.datamanager"; module "pluginloader" +local function load_from_datastore(name) + local content = datamanager.load(name, "*", "plugins"); + if not content or not content[1] then return nil, "Resource not found"; end + return content[1], name; +end + local function load_file(name) local file, err = io_open(plugin_dir..name); if not file then return file, err; end @@ -22,16 +30,36 @@ return content, name; end -function load_resource(plugin, resource) +function load_resource(plugin, resource, loader) if not resource then resource = "mod_"..plugin..".lua"; end - local content, err = load_file(plugin.."/"..resource); - if not content then content, err = load_file(resource); end + loader = loader or load_file; + + local content, err = loader(plugin.."/"..resource); + if not content then content, err = loader(resource); end -- TODO add support for packed plugins + + if not content and loader == load_file then + return load_resource(plugin, resource, load_from_datastore); + end + return content, err; end +function store_resource(plugin, resource, content, metadata) + if not resource then + resource = "mod_"..plugin..".lua"; + end + local store = { content }; + if metadata then + for k,v in pairs(metadata) do + store[k] = v; + end + end + datamanager.store(plugin.."/"..resource, "*", "plugins", store); +end + function load_code(plugin, resource) local content, err = load_resource(plugin, resource); if not content then return content, err; end