From 52fb0337ae6962e7b40666796219906bb93596d9 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 3 Jun 2010 17:27:49 +0500 Subject: mod_presence: Removed unnecessary parameter 'core_route_stanza' from various functions. --- plugins/mod_presence.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index 9071ae4c..20afc2da 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -31,7 +31,7 @@ function core_route_stanza(origin, stanza) local node, host = jid_split(stanza.attr.to); host = hosts[host]; if node and host and host.type == "local" then - handle_inbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to), core_route_stanza); + handle_inbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to)); return; end end @@ -64,7 +64,7 @@ end local ignore_presence_priority = module:get_option("ignore_presence_priority"); -function handle_normal_presence(origin, stanza, core_route_stanza) +function handle_normal_presence(origin, stanza) if ignore_presence_priority then local priority = stanza:child_with_name("priority"); if priority and priority[1] ~= "0" then @@ -159,7 +159,7 @@ function handle_normal_presence(origin, stanza, core_route_stanza) stanza.attr.to = nil; -- reset it end -function send_presence_of_available_resources(user, host, jid, recipient_session, core_route_stanza, stanza) +function send_presence_of_available_resources(user, host, jid, recipient_session, stanza) local h = hosts[host]; local count = 0; if h and h.type == "local" then @@ -181,7 +181,7 @@ function send_presence_of_available_resources(user, host, jid, recipient_session return count; end -function handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza) +function handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare) local node, host = jid_split(from_bare); if to_bare == origin.username.."@"..origin.host then return; end -- No self contacts local st_from, st_to = stanza.attr.from, stanza.attr.to; @@ -209,7 +209,7 @@ function handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_ rostermanager.roster_push(node, host, to_bare); end core_route_stanza(origin, stanza); - send_presence_of_available_resources(node, host, to_bare, origin, core_route_stanza); + send_presence_of_available_resources(node, host, to_bare, origin); elseif stanza.attr.type == "unsubscribed" then -- 1. route stanza -- 2. roster push (subscription = none or to) @@ -221,7 +221,7 @@ function handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_ stanza.attr.from, stanza.attr.to = st_from, st_to; end -function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare, core_route_stanza) +function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare) local node, host = jid_split(to_bare); local st_from, st_to = stanza.attr.from, stanza.attr.to; stanza.attr.from, stanza.attr.to = from_bare, to_bare; @@ -230,7 +230,7 @@ function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_b if stanza.attr.type == "probe" then local result, err = rostermanager.is_contact_subscribed(node, host, from_bare); if result then - if 0 == send_presence_of_available_resources(node, host, st_from, origin, core_route_stanza) then + if 0 == send_presence_of_available_resources(node, host, st_from, origin) then core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="unavailable"})); -- TODO send last activity end elseif not err then @@ -240,7 +240,7 @@ function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_b if rostermanager.is_contact_subscribed(node, host, from_bare) then core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="subscribed"})); -- already subscribed -- Sending presence is not clearly stated in the RFC, but it seems appropriate - if 0 == send_presence_of_available_resources(node, host, from_bare, origin, core_route_stanza) then + if 0 == send_presence_of_available_resources(node, host, from_bare, origin) then core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="unavailable"})); -- TODO send last activity end else @@ -278,7 +278,7 @@ local outbound_presence_handler = function(data) if to then local t = stanza.attr.type; if t ~= nil and t ~= "unavailable" and t ~= "error" then -- check for subscriptions and probes - handle_outbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to), core_route_stanza); + handle_outbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to)); return true; end @@ -306,7 +306,7 @@ module:hook("presence/bare", function(data) local t = stanza.attr.type; if to then if t ~= nil and t ~= "unavailable" and t ~= "error" then -- check for subscriptions and probes sent to bare JID - handle_inbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to), core_route_stanza); + handle_inbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to)); return true; end @@ -319,7 +319,7 @@ module:hook("presence/bare", function(data) end end -- no resources not online, discard elseif not t or t == "unavailable" then - handle_normal_presence(origin, stanza, core_route_stanza); + handle_normal_presence(origin, stanza); end return true; end); @@ -329,7 +329,7 @@ module:hook("presence/full", function(data) local t = stanza.attr.type; if t ~= nil and t ~= "unavailable" and t ~= "error" then -- check for subscriptions and probes sent to full JID - handle_inbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to), core_route_stanza); + handle_inbound_presence_subscriptions_and_probes(origin, stanza, jid_bare(stanza.attr.from), jid_bare(stanza.attr.to)); return true; end -- cgit v1.2.3 From ff82c8510b8b301b09ca095fd3eceddaa3582677 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 3 Jun 2010 17:47:51 +0500 Subject: util.sasl.scram: Fixed a log level. --- util/sasl/scram.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/sasl/scram.lua b/util/sasl/scram.lua index 52656a89..1340423c 100644 --- a/util/sasl/scram.lua +++ b/util/sasl/scram.lua @@ -105,7 +105,7 @@ function saltedPasswordSHA1(password, salt, iteration_count) return false, "inappropriate argument types" end if iteration_count < 4096 then - log("warning", "Iteration count < 4096 which is the suggested minimum according to RFC 5802.") + log("warn", "Iteration count < 4096 which is the suggested minimum according to RFC 5802.") end return true, Hi(hmac_sha1, password, salt, iteration_count); -- cgit v1.2.3 From 27869c5ecb1a8a0e0c969bc9ecc829cb61f186d4 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 3 Jun 2010 17:48:50 +0500 Subject: SASL: Minor cleanup. --- util/sasl.lua | 7 ++----- util/sasl/anonymous.lua | 2 +- util/sasl/plain.lua | 2 +- util/sasl/scram.lua | 6 ++---- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/util/sasl.lua b/util/sasl.lua index 306acc0c..c9225f0d 100644 --- a/util/sasl.lua +++ b/util/sasl.lua @@ -108,11 +108,8 @@ function method:select(mechanism) return false; end - self.mech_i = mechanisms[mechanism] - if self.mech_i == nil then - return false; - end - return true; + self.mech_i = mechanisms[mechanism]; + return (self.mech_i ~= nil); end -- feed new messages to process into the library diff --git a/util/sasl/anonymous.lua b/util/sasl/anonymous.lua index f3e31a7f..6e6f0949 100644 --- a/util/sasl/anonymous.lua +++ b/util/sasl/anonymous.lua @@ -35,7 +35,7 @@ local function anonymous(self, message) repeat username = generate_uuid(); until self.profile.anonymous(username, self.realm); - self["username"] = username; + self.username = username; return "success" end diff --git a/util/sasl/plain.lua b/util/sasl/plain.lua index 39821182..eaf03d83 100644 --- a/util/sasl/plain.lua +++ b/util/sasl/plain.lua @@ -58,7 +58,7 @@ local function plain(self, message) if self.profile.plain then local correct_password; correct_password, state = self.profile.plain(authentication, self.realm); - if correct_password == password then correct = true; else correct = false; end + correct = (correct_password == password); elseif self.profile.plain_test then correct, state = self.profile.plain_test(authentication, self.realm, password); end diff --git a/util/sasl/scram.lua b/util/sasl/scram.lua index 1340423c..c366a152 100644 --- a/util/sasl/scram.lua +++ b/util/sasl/scram.lua @@ -93,10 +93,8 @@ local function validate_username(username) return username; end -local function hashprep( hashname ) - local hash = hashname:lower() - hash = hash:gsub("-", "_") - return hash +local function hashprep(hashname) + return hashname:lower():gsub("-", "_"); end function saltedPasswordSHA1(password, salt, iteration_count) -- cgit v1.2.3 From bc5b27f0981edf60d864a54f83037925b43518a7 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 3 Jun 2010 18:01:05 +0500 Subject: mod_presence: Send unavailable presence in response to probes to the sender's full JID, not bare JID. --- plugins/mod_presence.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/mod_presence.lua b/plugins/mod_presence.lua index 20afc2da..943e318f 100644 --- a/plugins/mod_presence.lua +++ b/plugins/mod_presence.lua @@ -231,7 +231,7 @@ function handle_inbound_presence_subscriptions_and_probes(origin, stanza, from_b local result, err = rostermanager.is_contact_subscribed(node, host, from_bare); if result then if 0 == send_presence_of_available_resources(node, host, st_from, origin) then - core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="unavailable"})); -- TODO send last activity + core_route_stanza(hosts[host], st.presence({from=to_bare, to=st_from, type="unavailable"})); -- TODO send last activity end elseif not err then core_route_stanza(hosts[host], st.presence({from=to_bare, to=from_bare, type="unsubscribed"})); -- cgit v1.2.3 From fc73419e7ff7542af2ee837ec2eff8e3fea6bbc0 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 3 Jun 2010 18:09:02 +0500 Subject: util.sasl_cyrus: Log the textual representation of unknown Cyrus SASL errors, not just the error code. --- util/sasl_cyrus.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/sasl_cyrus.lua b/util/sasl_cyrus.lua index b5f505eb..add7fe45 100644 --- a/util/sasl_cyrus.lua +++ b/util/sasl_cyrus.lua @@ -127,7 +127,7 @@ function method:process(message) elseif (err == -13) then -- SASL_BADAUTH return "failure", "not-authorized", cyrussasl.get_message( self.cyrus ) else - log("debug", "Got SASL error condition %d", err) + log("debug", "Got SASL error condition %d: %s", err, cyrussasl.get_message( self.cyrus )) return "failure", "undefined-condition", cyrussasl.get_message( self.cyrus ) end end -- cgit v1.2.3