From 6522555bbbde9ee6ae7772ef3ac3607e40595aa0 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 15 Nov 2008 23:09:08 +0000 Subject: Fix mod_roster to use session.send for sending stanzas --- plugins/mod_roster.lua | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/plugins/mod_roster.lua b/plugins/mod_roster.lua index f5dbf742..23a19828 100644 --- a/plugins/mod_roster.lua +++ b/plugins/mod_roster.lua @@ -1,6 +1,5 @@ local st = require "util.stanza" -local send = require "core.sessionmanager".send_to_session local jid_split = require "util.jid".split; local t_concat = table.concat; @@ -29,7 +28,7 @@ add_iq_handler("c2s", "jabber:iq:roster", roster:up(); -- move out from item end end - send(session, roster); + session.send(roster); session.interested = true; -- resource is interested in roster updates return true; elseif stanza.attr.type == "set" then @@ -46,13 +45,13 @@ add_iq_handler("c2s", "jabber:iq:roster", if session.roster[item.attr.jid] then local success, err_type, err_cond, err_msg = rm_remove_from_roster(session, item.attr.jid); if success then - send(session, st.reply(stanza)); + session.send(st.reply(stanza)); rm_roster_push(from_node, from_host, item.attr.jid); else - send(session, st.error_reply(stanza, err_type, err_cond, err_msg)); + session.send(st.error_reply(stanza, err_type, err_cond, err_msg)); end else - send(session, st.error_reply(stanza, "modify", "item-not-found")); + session.send(st.error_reply(stanza, "modify", "item-not-found")); end else local r_item = {name = item.attr.name, groups = {}}; @@ -73,20 +72,20 @@ add_iq_handler("c2s", "jabber:iq:roster", end local success, err_type, err_cond, err_msg = rm_add_to_roster(session, item.attr.jid, r_item); if success then - send(session, st.reply(stanza)); + session.send(st.reply(stanza)); rm_roster_push(from_node, from_host, item.attr.jid); else - send(session, st.error_reply(stanza, err_type, err_cond, err_msg)); + session.send(st.error_reply(stanza, err_type, err_cond, err_msg)); end end else - send(session, st.error_reply(stanza, "cancel", "not-allowed")); + session.send(st.error_reply(stanza, "cancel", "not-allowed")); end else - send(session, st.error_reply(stanza, "modify", "bad-request")); -- FIXME what's the correct error? + session.send(st.error_reply(stanza, "modify", "bad-request")); -- FIXME what's the correct error? end else - send(session, st.error_reply(stanza, "modify", "bad-request")); + session.send(st.error_reply(stanza, "modify", "bad-request")); end return true; end -- cgit v1.2.3 From 35d9765b9aa38ef8b004204452baf9d63eb34154 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 15 Nov 2008 23:10:41 +0000 Subject: If iq child element has no xmlns, use parent's --- core/modulemanager.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/modulemanager.lua b/core/modulemanager.lua index aadd89de..783fea55 100644 --- a/core/modulemanager.lua +++ b/core/modulemanager.lua @@ -10,6 +10,7 @@ local type = type; local tostring, print = tostring, print; local _G = _G; +local debug = debug; module "modulemanager" @@ -89,14 +90,13 @@ function handle_stanza(origin, stanza) log("debug", "Stanza is an "); local child = stanza.tags[1]; if child then - local xmlns = child.attr.xmlns; - log("debug", "Stanza has xmlns: %s", xmlns); + local xmlns = child.attr.xmlns or xmlns; + log("debug", "Stanza of type %s from %s has xmlns: %s", name, origin_type, xmlns); local handler = handlers[origin_type][name][xmlns]; if handler then log("debug", "Passing stanza to mod_%s", handler_info[handler].name); return handler(origin, stanza) or true; end - end elseif handlers[origin_type] then local handler = handlers[origin_type][name]; -- cgit v1.2.3 From 6b834ab79bfb4640a64c3a4919c6b776b3c4436c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 15 Nov 2008 23:11:17 +0000 Subject: Warn when subtest function does not exist --- tests/test.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test.lua b/tests/test.lua index c0a27abd..c028e859 100644 --- a/tests/test.lua +++ b/tests/test.lua @@ -71,6 +71,7 @@ function dotest(unitname) end function runtest(f, msg) + if not f then print("SUBTEST NOT FOUND: "..(msg or "(no description)")); return; end local success, ret = pcall(f); if success and verbosity >= 2 then print("SUBTEST PASSED: "..(msg or "(no description)")); -- cgit v1.2.3 From fa063a029970ee01ce8307643e334fb1d33a8a74 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sat, 15 Nov 2008 23:14:32 +0000 Subject: You can never have too many tests --- tests/test_core_stanza_router.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_core_stanza_router.lua b/tests/test_core_stanza_router.lua index 49c1f90f..a5185c29 100644 --- a/tests/test_core_stanza_router.lua +++ b/tests/test_core_stanza_router.lua @@ -1,6 +1,7 @@ function core_process_stanza(core_process_stanza) local s2sout_session = { to_host = "remotehost", from_host = "localhost", type = "s2sout" } + local s2sin_session = { from_host = "remotehost", to_host = "localhost", type = "s2sin" } local local_host_session = { host = "localhost", type = "local" } local local_user_session = { username = "user", host = "localhost", resource = "resource", full_jid = "user@localhost/resource", type = "c2s" } local hosts = { @@ -123,6 +124,28 @@ function core_process_stanza(core_process_stanza) assert_equal(target_routed, true, "stanza was not routed successfully"); end + local function test_iq_error_to_local_user() + local env = testlib_new_env(); + local msg = stanza.stanza("iq", { to = "user@localhost/resource", from = "user@remotehost", type = "error" }):tag("error", { type = 'cancel' }):tag("item-not-found", { xmlns='urn:ietf:params:xml:ns:xmpp-stanzas' }); + + local target_routed; + + function env.core_route_stanza(p_origin, p_stanza) + assert_equal(p_origin, s2sin_session, "origin of handled stanza is not correct"); + assert_equal(p_stanza, msg, "handled stanza is not correct one: "..p_stanza:pretty_print()); + target_routed = true; + end + + function env.core_handle_stanza(p_origin, p_stanza) + + end + + env.hosts = hosts; + setfenv(core_process_stanza, env); + assert_equal(core_process_stanza(s2sin_session, msg), nil, "core_process_stanza returned incorrect value"); + assert_equal(target_routed, true, "stanza was not routed successfully"); + end + runtest(test_message_full_jid, "Messages with full JID destinations get routed"); runtest(test_message_bare_jid, "Messages with bare JID destinations get routed"); runtest(test_message_no_to, "Messages with no destination are handled by the server"); @@ -130,5 +153,6 @@ function core_process_stanza(core_process_stanza) runtest(test_message_to_remote_server, "Messages to a remote server's JID are routed"); runtest(test_iq_to_remote_server, "iq to a remote server's JID are routed"); + runtest(test_iq_error_to_local_user, "iq type=error to a local user's JID are routed"); end -- cgit v1.2.3