Changeset

4869:1fac86aab90b

Merge with Zash
author Matthew Wild <mwild1@gmail.com>
date Sat, 12 May 2012 03:36:15 +0100
parents 4867:b4219d987d05 (diff) 4868:550f0a5e85c5 (current diff)
children 4870:ca39f9b4cc8e
files
diffstat 3 files changed, 12 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/core/stanza_router.lua	Sat May 12 02:17:08 2012 +0200
+++ b/core/stanza_router.lua	Sat May 12 03:36:15 2012 +0100
@@ -28,13 +28,13 @@
 			return true;
 		end
 	end
-	if stanza.attr.xmlns == nil then
+	if stanza.attr.xmlns == nil and origin.send then
 		log("debug", "Unhandled %s stanza: %s; xmlns=%s", origin.type, stanza.name, xmlns); -- we didn't handle it
 		if stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then
 			origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
 		end
 	elseif not((name == "features" or name == "error") and xmlns == "http://etherx.jabber.org/streams") then -- FIXME remove check once we handle S2S features
-		log("warn", "Unhandled %s stream element: %s; xmlns=%s: %s", origin.type, stanza.name, xmlns, tostring(stanza)); -- we didn't handle it
+		log("warn", "Unhandled %s stream element or stanza: %s; xmlns=%s: %s", origin.type, stanza.name, xmlns, tostring(stanza)); -- we didn't handle it
 		origin:close("unsupported-stanza-type");
 	end
 end
@@ -111,8 +111,8 @@
 				log("warn", "Received a stanza claiming to be from %s, over a stream authed for %s!", from_host, origin.from_host);
 				origin:close("not-authorized");
 				return;
-			elseif not hosts[to_host] then
-				log("warn", "Remote server %s sent us a stanza for %s, closing stream", origin.from_host, to_host);
+			elseif not hosts[host] then
+				log("warn", "Remote server %s sent us a stanza for %s, closing stream", origin.from_host, host);
 				origin:close("host-unknown");
 				return;
 			end
--- a/net/http.lua	Sat May 12 02:17:08 2012 +0200
+++ b/net/http.lua	Sat May 12 03:36:15 2012 +0100
@@ -68,7 +68,7 @@
 	requests[conn] = nil;
 end
 
-function urlencode(s) return s and (s:gsub("%W", function (c) return format("%%%02x", c:byte()); end)); end
+function urlencode(s) return s and (s:gsub("[^a-zA-Z0-9.~_-]", function (c) return format("%%%02x", c:byte()); end)); end
 function urldecode(s) return s and (s:gsub("%%(%x%x)", function (c) return char(tonumber(c,16)); end)); end
 
 local function _formencodepart(s)
--- a/net/http/parser.lua	Sat May 12 02:17:08 2012 +0200
+++ b/net/http/parser.lua	Sat May 12 03:36:15 2012 +0100
@@ -1,8 +1,11 @@
 
 local tonumber = tonumber;
 local assert = assert;
+local url_parse = require "socket.url".parse;
+local urldecode = require "net.http".urldecode;
 
 local function preprocess_path(path)
+	path = urldecode(path);
 	if path:sub(1,1) ~= "/" then
 		path = "/"..path;
 	end
@@ -88,15 +91,14 @@
 							responseheaders = headers;
 						};
 					else
-						-- path normalization
-						if path:match("^https?://") then
-							headers.host, path = path:match("^https?://([^/]*)(.*)");
-						end
-						path = preprocess_path(path);
+						local parsed_url = url_parse(path);
+						path = preprocess_path(parsed_url.path);
+						headers.host = parsed_url.host;
 
 						len = len or 0;
 						packet = {
 							method = method;
+							url = parsed_url;
 							path = path;
 							httpversion = httpversion;
 							headers = headers;