Changeset

305:4ccffcd6e720

Merge from waqas
author Matthew Wild <mwild1@gmail.com>
date Sat, 15 Nov 2008 22:29:24 +0000
parents 298:985710ea308b (current diff) 304:7b28fa8bbfe5 (diff)
children 306:db4ef011512c
files
diffstat 4 files changed, 18 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/core/sessionmanager.lua	Sat Nov 15 22:07:31 2008 +0000
+++ b/core/sessionmanager.lua	Sat Nov 15 22:29:24 2008 +0000
@@ -68,9 +68,13 @@
 	return true;
 end
 
+-- returns true, nil on success
+-- returns nil, err_type, err, err_message on failure
 function bind_resource(session, resource)
-	if not session.username then return false, "auth"; end
-	if session.resource then return false, "constraint"; end -- We don't support binding multiple resources
+	if not session.username then return nil, "auth", "not-authorized", "Cannot bind resource before authentication"; end
+	if session.resource then return nil, "cancel", "already-bound", "Cannot bind multiple resources on a single connection"; end
+	-- We don't support binding multiple resources
+
 	resource = resource or uuid_generate();
 	--FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing
 	
@@ -79,7 +83,7 @@
 	else
 		if hosts[session.host].sessions[session.username].sessions[resource] then
 			-- Resource conflict
-			return false, "conflict"; -- TODO kick old resource
+			return nil, "cancel", "conflict", "Resource already exists"; -- TODO kick old resource
 		end
 	end
 	
--- a/plugins/mod_legacyauth.lua	Sat Nov 15 22:07:31 2008 +0000
+++ b/plugins/mod_legacyauth.lua	Sat Nov 15 22:29:24 2008 +0000
@@ -23,22 +23,10 @@
 					-- Authentication successful!
 					local success, err = sessionmanager.make_authenticated(session, username);
 					if success then
-						success, err = sessionmanager.bind_resource(session, resource);
-						--FIXME: Reply with error
+						local err_type, err_msg;
+						success, err_type, err, err_msg = sessionmanager.bind_resource(session, resource);
 						if not success then
-							local reply = st.reply(stanza);
-							reply.attr.type = "error";
-							if err == "conflict" then
-								reply:tag("error", { code = "409", type = "cancel" })
-									:tag("conflict", { xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas" });
-							elseif err == "constraint" then
-								reply:tag("error", { code = "409", type = "cancel" })
-									:tag("already-bound", { xmlns = "x-lxmppd:extensions:legacyauth" });
-							elseif err == "auth" then
-								reply:tag("error", { code = "401", type = "auth" })
-									:tag("not-authorized", { xmlns = "urn:ietf:params:xml:ns:xmpp-stanzas" });
-							end
-							send(session, reply);
+							session.send(st.error_reply(stanza, err_type, err, err_msg));
 							return true;
 						end
 					end
--- a/plugins/mod_saslauth.lua	Sat Nov 15 22:07:31 2008 +0000
+++ b/plugins/mod_saslauth.lua	Sat Nov 15 22:29:24 2008 +0000
@@ -105,7 +105,6 @@
 			local resource;
 			if stanza.attr.type == "set" then
 				local bind = stanza.tags[1];
-				
 				if bind and bind.attr.xmlns == xmlns_bind then
 					resource = bind:child_with_name("resource");
 					if resource then
@@ -113,26 +112,13 @@
 					end
 				end
 			end
-			local success, err = sm_bind_resource(session, resource);
+			local success, err_type, err, err_msg = sm_bind_resource(session, resource);
 			if not success then
-				local reply = st.reply(stanza);
-				reply.attr.type = "error";
-				if err == "conflict" then
-					reply:tag("error", { type = "modify" })
-						:tag("conflict", { xmlns = xmlns_stanzas });
-				elseif err == "constraint" then
-					reply:tag("error", { type = "cancel" })
-						:tag("resource-constraint", { xmlns = xmlns_stanzas });
-				elseif err == "auth" then
-					reply:tag("error", { type = "cancel" })
-						:tag("not-allowed", { xmlns = xmlns_stanzas });
-				end
-				send(session, reply);
+				session.send(st.error_reply(stanza, err_type, err, err_msg));
 			else
-				local reply = st.reply(stanza);
-				reply:tag("bind", { xmlns = xmlns_bind})
-					:tag("jid"):text(session.full_jid);
-				send(session, reply);
+				session.send(st.reply(stanza)
+					:tag("bind", { xmlns = xmlns_bind})
+					:tag("jid"):text(session.full_jid));
 			end
 		end);
 		
--- a/plugins/mod_tls.lua	Sat Nov 15 22:07:31 2008 +0000
+++ b/plugins/mod_tls.lua	Sat Nov 15 22:29:24 2008 +0000
@@ -1,13 +1,10 @@
 
 local st = require "util.stanza";
 local send = require "core.sessionmanager".send_to_session;
-local sm_bind_resource = require "core.sessionmanager".bind_resource;
-
-local sessions = sessions;
 
-local usermanager_validate_credentials = require "core.usermanager".validate_credentials;
-local t_concat, t_insert = table.concat, table.insert;
-local tostring = tostring;
+--local sessions = sessions;
+
+local t_insert = table.insert;
 
 local log = require "util.logger".init("mod_starttls");