Merge from waqas

Thu, 27 Nov 2008 23:36:49 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 27 Nov 2008 23:36:49 +0000
changeset 450
e04c4052742c
parent 444
77485b9b840c (diff)
parent 449
c0a4a1e63d70 (current diff)
child 451
e9f269e5204e

Merge from waqas

util/hashes.lua file | annotate | diff | comparison | revisions
--- a/core/modulemanager.lua	Fri Nov 28 01:16:26 2008 +0500
+++ b/core/modulemanager.lua	Thu Nov 27 23:36:49 2008 +0000
@@ -27,6 +27,9 @@
 
 
 function load(host, module_name, config)
+	if not (host and module_name) then
+		return nil, "insufficient-parameters";
+	end
 	local mod, err = loadfile("plugins/mod_"..module_name..".lua");
 	if not mod then
 		log("error", "Unable to load module '%s': %s", module_name or "nil", err or "nil");
@@ -59,6 +62,23 @@
 	return true;
 end
 
+function is_loaded(host, name)
+	return modulemap[host] and modulemap[host][name] and true;
+end
+
+function unload(host, name, ...)
+	local mod = modulemap[host] and modulemap[host][name];
+	if not mod then return nil, "module-not-loaded"; end
+	
+	if type(mod.unload) == "function" then
+		local ok, err = pcall(mod.unload, ...)
+		if (not ok) and err then
+			log("warn", "Non-fatal error unloading module '%s' from '%s': %s", name, host, err);
+		end
+	end
+	
+end
+
 function handle_stanza(host, origin, stanza)
 	local name, xmlns, origin_type = stanza.name, stanza.attr.xmlns, origin.type;
 	
--- a/plugins/mod_console.lua	Fri Nov 28 01:16:26 2008 +0500
+++ b/plugins/mod_console.lua	Thu Nov 27 23:36:49 2008 +0000
@@ -37,7 +37,7 @@
 		-- Handle new connection
 		session = console:new_session(conn);
 		sessions[conn] = session;
-		session.print("Welcome to the lxmppd admin console!");
+		printbanner(session);
 	end
 	if data then
 		-- Handle data
@@ -129,15 +129,24 @@
 end
 
 def_env.module = {};
-function def_env.module:load(name)
+function def_env.module:load(name, host, config)
 	local mm = require "modulemanager";
-	local ok, err = mm.load(name);
+	local ok, err = mm.load(host or self.env.host, name, config);
 	if not ok then
 		return false, err or "Unknown error loading module";
 	end
 	return true, "Module loaded";
 end
 
+function def_env.module:unload(name, host)
+	local mm = require "modulemanager";
+	local ok, err = mm.unload(host or self.env.host, name);
+	if not ok then
+		return false, err or "Unknown error unloading module";
+	end
+	return true, "Module unloaded";
+end
+
 def_env.config = {};
 function def_env.config:load(filename, format)
 	local config_load = require "core.configmanager".load;
@@ -163,3 +172,20 @@
 
 function def_env.hosts:add(name)
 end
+
+-------------
+
+function printbanner(session)
+session.print [[
+                   ____                \   /     _       
+                    |  _ \ _ __ ___  ___  _-_   __| |_   _ 
+                    | |_) | '__/ _ \/ __|/ _ \ / _` | | | |
+                    |  __/| | | (_) \__ \ |_| | (_| | |_| |
+                    |_|   |_|  \___/|___/\___/ \__,_|\__, |
+                    A study in simplicity            |___/ 
+
+]]
+session.print("Welcome to the Prosody administration console. For a list of commands, type: help");
+session.print("You may find more help on using this console in our online documentation at ");
+session.print("http://prosody.im/doc/console\n");
+end

mercurial