+ return ok, err;
+end
+
+function handle_stanza(host, origin, stanza)
+ local name, xmlns, origin_type = stanza.name, stanza.attr.xmlns, origin.type;
+ if name == "iq" and xmlns == "jabber:client" then
+ if stanza.attr.type == "get" or stanza.attr.type == "set" then
+ xmlns = stanza.tags[1].attr.xmlns;
+ log("debug", "Stanza of type %s from %s has xmlns: %s", name, origin_type, xmlns);
+ else
+ log("debug", "Discarding %s from %s of type: %s", name, origin_type, stanza.attr.type);
+ return true;
+ end
+ end
+ local handlers = stanza_handlers:get(host, origin_type, name, xmlns);
+ if handlers then
+ log("debug", "Passing stanza to mod_%s", handler_info[handlers[1]].name);
+ (handlers[1])(origin, stanza);
+ return true;
+ else
+ log("debug", "Stanza unhandled by any modules, xmlns: %s", stanza.attr.xmlns); -- we didn't handle it
+ end
+end
+
+function module_has_method(module, method)
+ return type(module.module[method]) == "function";
+end
+
+function call_module_method(module, method, ...)
+ if module_has_method(module, method) then
+ local f = module.module[method];
+ return pcall(f, ...);
+ else
+ return false, "no-such-method";
+ end
+end
+
+local _modulepath = { plugin_dir, "mod_", nil, ".lua"};
+function get_module_filename(name)
+ _modulepath[3] = name;
+ return t_concat(_modulepath);