Browse Source

Update luasocket to lunarmodules/luasocket@98be8d9

Fixes #1663.
Sasha Szpakowski 1 year ago
parent
commit
5907a7efe7

+ 15 - 9
src/libraries/luasocket/libluasocket/http.lua

@@ -54,7 +54,7 @@ local function receiveheaders(sock, headers)
     while line ~= "" do
         -- get field-name and value
         name, value = socket.skip(2, string.find(line, "^(.-):%s*(.*)"))
-        if not (name and value) then return nil, "malformed reponse headers" end
+        if not (name and value) then return nil, "malformed response headers" end
         name = string.lower(name)
         -- get next line (value might be folded)
         line, err  = sock:receive()
@@ -62,7 +62,7 @@ local function receiveheaders(sock, headers)
         -- unfold any folded values
         while string.find(line, "^%s") do
             value = value .. line
-            line = sock:receive()
+            line, err = sock:receive()
             if err then return nil, err end
         end
         -- save pair in table
@@ -81,7 +81,7 @@ socket.sourcet["http-chunked"] = function(sock, headers)
         dirty = function() return sock:dirty() end
     }, {
         __call = function()
-            -- get chunk size, skip extention
+            -- get chunk size, skip extension
             local line, err = sock:receive()
             if err then return nil, err end
             local size = base.tonumber(string.gsub(line, ";.*", ""), 16)
@@ -219,9 +219,11 @@ local function adjustproxy(reqt)
     local proxy = reqt.proxy or _M.PROXY
     if proxy then
         proxy = url.parse(proxy)
-        return proxy.host, proxy.port or 3128
+        proxy.port = proxy.port or 3128
+        proxy.create = SCHEMES[proxy.scheme].create(reqt)
+        return proxy.host, proxy.port, proxy.create
     else
-        return reqt.host, reqt.port
+        return reqt.host, reqt.port, reqt.create
     end
 end
 
@@ -279,7 +281,7 @@ local function adjustrequest(reqt)
     if not (host and host ~= "") then
         socket.try(nil, "invalid host '" .. base.tostring(nreqt.host) .. "'")
     end
-    -- compute uri if user hasn't overriden
+    -- compute uri if user hasn't overridden
     nreqt.uri = reqt.uri or adjusturi(nreqt)
     -- adjust headers in request
     nreqt.headers = adjustheaders(nreqt)
@@ -291,7 +293,10 @@ local function adjustrequest(reqt)
     end
 
     -- ajust host and port if there is a proxy
-    nreqt.host, nreqt.port = adjustproxy(nreqt)
+    local proxy_create
+    nreqt.host, nreqt.port, proxy_create = adjustproxy(nreqt)
+    if not reqt.create then nreqt.create = proxy_create end
+
     return nreqt
 end
 
@@ -300,6 +305,8 @@ local function shouldredirect(reqt, code, headers)
     if not location then return false end
     location = string.gsub(location, "%s", "")
     if location == "" then return false end
+    -- the RFC says the redirect URL may be relative
+    location = url.absolute(reqt.url, location)
     local scheme = url.parse(location).scheme
     if scheme and (not SCHEMES[scheme]) then return false end
     -- avoid https downgrades
@@ -323,8 +330,7 @@ end
 local trequest, tredirect
 
 --[[local]] function tredirect(reqt, location)
-    -- the RFC says the redirect URL has to be absolute, but some
-    -- servers do not respect that
+    -- the RFC says the redirect URL may be relative
     local newurl = url.absolute(reqt.url, location)
     -- if switching schemes, reset port and create function
     if url.parse(newurl).scheme ~= reqt.scheme then

+ 34 - 14
src/libraries/luasocket/libluasocket/http.lua.h

@@ -167,8 +167,8 @@ const unsigned char http_lua[] =
 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x28, 0x6e, 0x61, 
 	0x6d, 0x65, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x29, 0x20, 0x74, 0x68, 0x65, 0x6e, 
 	0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x2c, 0x20, 0x22, 0x6d, 0x61, 0x6c, 0x66, 
-	0x6f, 0x72, 0x6d, 0x65, 0x64, 0x20, 0x72, 0x65, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x20, 0x68, 0x65, 0x61, 0x64, 
-	0x65, 0x72, 0x73, 0x22, 0x20, 0x65, 0x6e, 0x64, 0x0a,
+	0x6f, 0x72, 0x6d, 0x65, 0x64, 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x20, 0x68, 0x65, 0x61, 
+	0x64, 0x65, 0x72, 0x73, 0x22, 0x20, 0x65, 0x6e, 0x64, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 
 	0x69, 0x6e, 0x67, 0x2e, 0x6c, 0x6f, 0x77, 0x65, 0x72, 0x28, 0x6e, 0x61, 0x6d, 0x65, 0x29, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x67, 0x65, 0x74, 0x20, 0x6e, 0x65, 0x78, 
@@ -186,8 +186,9 @@ const unsigned char http_lua[] =
 	0x22, 0x29, 0x20, 0x64, 0x6f, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 
 	0x3d, 0x20, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x20, 0x2e, 0x2e, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x0a,
-	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x3d, 
-	0x20, 0x73, 0x6f, 0x63, 0x6b, 0x3a, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x28, 0x29, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x20, 
+	0x65, 0x72, 0x72, 0x20, 0x3d, 0x20, 0x73, 0x6f, 0x63, 0x6b, 0x3a, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 
+	0x28, 0x29, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x65, 0x72, 0x72, 
 	0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x69, 0x6c, 0x2c, 0x20, 
 	0x65, 0x72, 0x72, 0x20, 0x65, 0x6e, 0x64, 0x0a,
@@ -235,7 +236,7 @@ const unsigned char http_lua[] =
 	0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x29, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x67, 0x65, 0x74, 
 	0x20, 0x63, 0x68, 0x75, 0x6e, 0x6b, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x2c, 0x20, 0x73, 0x6b, 0x69, 0x70, 0x20, 
-	0x65, 0x78, 0x74, 0x65, 0x6e, 0x74, 0x69, 0x6f, 0x6e, 0x0a,
+	0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 
 	0x6c, 0x69, 0x6e, 0x65, 0x2c, 0x20, 0x65, 0x72, 0x72, 0x20, 0x3d, 0x20, 0x73, 0x6f, 0x63, 0x6b, 0x3a, 0x72, 
 	0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x28, 0x29, 0x0a,
@@ -570,12 +571,20 @@ const unsigned char http_lua[] =
 	0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x20, 0x3d, 0x20, 0x75, 0x72, 
 	0x6c, 0x2e, 0x70, 0x61, 0x72, 0x73, 0x65, 0x28, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x29, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x70, 0x6f, 0x72, 0x74, 
+	0x20, 0x3d, 0x20, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x20, 0x6f, 0x72, 0x20, 0x33, 
+	0x31, 0x32, 0x38, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x63, 0x72, 0x65, 0x61, 
+	0x74, 0x65, 0x20, 0x3d, 0x20, 0x53, 0x43, 0x48, 0x45, 0x4d, 0x45, 0x53, 0x5b, 0x70, 0x72, 0x6f, 0x78, 0x79, 
+	0x2e, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x65, 0x5d, 0x2e, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x28, 0x72, 0x65, 
+	0x71, 0x74, 0x29, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x70, 0x72, 0x6f, 
 	0x78, 0x79, 0x2e, 0x68, 0x6f, 0x73, 0x74, 0x2c, 0x20, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x70, 0x6f, 0x72, 
-	0x74, 0x20, 0x6f, 0x72, 0x20, 0x33, 0x31, 0x32, 0x38, 0x0a,
+	0x74, 0x2c, 0x20, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x2e, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x72, 0x65, 0x71, 
-	0x74, 0x2e, 0x68, 0x6f, 0x73, 0x74, 0x2c, 0x20, 0x72, 0x65, 0x71, 0x74, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x0a,
+	0x74, 0x2e, 0x68, 0x6f, 0x73, 0x74, 0x2c, 0x20, 0x72, 0x65, 0x71, 0x74, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x2c, 
+	0x20, 0x72, 0x65, 0x71, 0x74, 0x2e, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a,
 	0x65, 0x6e, 0x64, 0x0a,
 	0x0a,
@@ -710,7 +719,7 @@ const unsigned char http_lua[] =
 	0x20, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x63, 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x65, 0x20, 0x75, 0x72, 0x69, 
 	0x20, 0x69, 0x66, 0x20, 0x75, 0x73, 0x65, 0x72, 0x20, 0x68, 0x61, 0x73, 0x6e, 0x27, 0x74, 0x20, 0x6f, 0x76, 
-	0x65, 0x72, 0x72, 0x69, 0x64, 0x65, 0x6e, 0x0a,
+	0x65, 0x72, 0x72, 0x69, 0x64, 0x64, 0x65, 0x6e, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x6e, 0x72, 0x65, 0x71, 0x74, 0x2e, 0x75, 0x72, 0x69, 0x20, 0x3d, 0x20, 0x72, 0x65, 
 	0x71, 0x74, 0x2e, 0x75, 0x72, 0x69, 0x20, 0x6f, 0x72, 0x20, 0x61, 0x64, 0x6a, 0x75, 0x73, 0x74, 0x75, 0x72, 
 	0x69, 0x28, 0x6e, 0x72, 0x65, 0x71, 0x74, 0x29, 0x0a,
@@ -736,9 +745,17 @@ const unsigned char http_lua[] =
 	0x20, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x61, 0x6a, 0x75, 0x73, 0x74, 0x20, 0x68, 0x6f, 0x73, 0x74, 0x20, 
 	0x61, 0x6e, 0x64, 0x20, 0x70, 0x6f, 0x72, 0x74, 0x20, 0x69, 0x66, 0x20, 0x74, 0x68, 0x65, 0x72, 0x65, 0x20, 
 	0x69, 0x73, 0x20, 0x61, 0x20, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x5f, 0x63, 0x72, 
+	0x65, 0x61, 0x74, 0x65, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x6e, 0x72, 0x65, 0x71, 0x74, 0x2e, 0x68, 0x6f, 0x73, 0x74, 0x2c, 0x20, 0x6e, 0x72, 
-	0x65, 0x71, 0x74, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x20, 0x3d, 0x20, 0x61, 0x64, 0x6a, 0x75, 0x73, 0x74, 0x70, 
-	0x72, 0x6f, 0x78, 0x79, 0x28, 0x6e, 0x72, 0x65, 0x71, 0x74, 0x29, 0x0a,
+	0x65, 0x71, 0x74, 0x2e, 0x70, 0x6f, 0x72, 0x74, 0x2c, 0x20, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x5f, 0x63, 0x72, 
+	0x65, 0x61, 0x74, 0x65, 0x20, 0x3d, 0x20, 0x61, 0x64, 0x6a, 0x75, 0x73, 0x74, 0x70, 0x72, 0x6f, 0x78, 0x79, 
+	0x28, 0x6e, 0x72, 0x65, 0x71, 0x74, 0x29, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x72, 0x65, 0x71, 0x74, 0x2e, 0x63, 0x72, 
+	0x65, 0x61, 0x74, 0x65, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x6e, 0x72, 0x65, 0x71, 0x74, 0x2e, 0x63, 0x72, 
+	0x65, 0x61, 0x74, 0x65, 0x20, 0x3d, 0x20, 0x70, 0x72, 0x6f, 0x78, 0x79, 0x5f, 0x63, 0x72, 0x65, 0x61, 0x74, 
+	0x65, 0x20, 0x65, 0x6e, 0x64, 0x0a,
+	0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6e, 0x72, 0x65, 0x71, 0x74, 0x0a,
 	0x65, 0x6e, 0x64, 0x0a,
 	0x0a,
@@ -757,6 +774,12 @@ const unsigned char http_lua[] =
 	0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x3d, 
 	0x20, 0x22, 0x22, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x66, 0x61, 
 	0x6c, 0x73, 0x65, 0x20, 0x65, 0x6e, 0x64, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x52, 0x46, 0x43, 0x20, 0x73, 0x61, 0x79, 
+	0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x72, 0x65, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x20, 0x55, 0x52, 0x4c, 
+	0x20, 0x6d, 0x61, 0x79, 0x20, 0x62, 0x65, 0x20, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x76, 0x65, 0x0a,
+	0x20, 0x20, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x75, 0x72, 0x6c, 
+	0x2e, 0x61, 0x62, 0x73, 0x6f, 0x6c, 0x75, 0x74, 0x65, 0x28, 0x72, 0x65, 0x71, 0x74, 0x2e, 0x75, 0x72, 0x6c, 
+	0x2c, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x29, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x65, 0x20, 0x3d, 
 	0x20, 0x75, 0x72, 0x6c, 0x2e, 0x70, 0x61, 0x72, 0x73, 0x65, 0x28, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 
 	0x6e, 0x29, 0x2e, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x65, 0x0a,
@@ -820,10 +843,7 @@ const unsigned char http_lua[] =
 	0x20, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x29, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x68, 0x65, 0x20, 0x52, 0x46, 0x43, 0x20, 0x73, 0x61, 0x79, 
 	0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x72, 0x65, 0x64, 0x69, 0x72, 0x65, 0x63, 0x74, 0x20, 0x55, 0x52, 0x4c, 
-	0x20, 0x68, 0x61, 0x73, 0x20, 0x74, 0x6f, 0x20, 0x62, 0x65, 0x20, 0x61, 0x62, 0x73, 0x6f, 0x6c, 0x75, 0x74, 
-	0x65, 0x2c, 0x20, 0x62, 0x75, 0x74, 0x20, 0x73, 0x6f, 0x6d, 0x65, 0x0a,
-	0x20, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x20, 0x64, 0x6f, 0x20, 
-	0x6e, 0x6f, 0x74, 0x20, 0x72, 0x65, 0x73, 0x70, 0x65, 0x63, 0x74, 0x20, 0x74, 0x68, 0x61, 0x74, 0x0a,
+	0x20, 0x6d, 0x61, 0x79, 0x20, 0x62, 0x65, 0x20, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x76, 0x65, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x20, 0x6e, 0x65, 0x77, 0x75, 0x72, 0x6c, 0x20, 0x3d, 
 	0x20, 0x75, 0x72, 0x6c, 0x2e, 0x61, 0x62, 0x73, 0x6f, 0x6c, 0x75, 0x74, 0x65, 0x28, 0x72, 0x65, 0x71, 0x74, 
 	0x2e, 0x75, 0x72, 0x6c, 0x2c, 0x20, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x29, 0x0a,

+ 1 - 1
src/libraries/luasocket/libluasocket/inet.c

@@ -290,7 +290,7 @@ int inet_meth_getsockname(lua_State *L, p_socket ps, int family)
         return 2;
     }
     lua_pushstring(L, name);
-    lua_pushstring(L, port);
+    lua_pushinteger(L, (int) strtol(port, (char **) NULL, 10));
     switch (family) {
         case AF_INET: lua_pushliteral(L, "inet"); break;
         case AF_INET6: lua_pushliteral(L, "inet6"); break;

+ 1 - 1
src/libraries/luasocket/libluasocket/luasocket.h

@@ -10,7 +10,7 @@
 /*-------------------------------------------------------------------------* \
 * Current socket library version
 \*-------------------------------------------------------------------------*/
-#define LUASOCKET_VERSION    "LuaSocket 3.0.0"
+#define LUASOCKET_VERSION    "LuaSocket 3.1.0"
 #define LUASOCKET_COPYRIGHT  "Copyright (C) 1999-2013 Diego Nehab"
 
 /*-------------------------------------------------------------------------*\

+ 2 - 2
src/libraries/luasocket/libluasocket/makefile

@@ -1,6 +1,6 @@
 # luasocket src/makefile
 #
-# Definitions in this section can be overriden on the command line or in the
+# Definitions in this section can be overridden on the command line or in the
 # environment.
 #
 # These are equivalent:
@@ -272,7 +272,7 @@ SOCKET_win64=wsocket.obj
 #
 SO=$(SO_$(PLAT))
 O=$(O_$(PLAT))
-SOCKET_V=3.0.0
+SOCKET_V=3.1.0
 MIME_V=1.0.3
 SOCKET_SO=socket-$(SOCKET_V).$(SO)
 MIME_SO=mime-$(MIME_V).$(SO)

+ 28 - 1
src/libraries/luasocket/libluasocket/options.c

@@ -54,6 +54,33 @@ int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps)
     return opt->func(L, ps);
 }
 
+/*------------------------------------------------------*/
+/* binds socket to network interface */
+int opt_set_bindtodevice(lua_State *L, p_socket ps)
+{
+#ifndef SO_BINDTODEVICE
+    return luaL_error(L, "SO_BINDTODEVICE is not supported on this operating system");
+#else
+    const char *dev = luaL_checkstring(L, 3);
+    return opt_set(L, ps, SOL_SOCKET, SO_BINDTODEVICE, (char*)dev, strlen(dev)+1);
+#endif
+}
+
+int opt_get_bindtodevice(lua_State *L, p_socket ps)
+{
+#ifndef SO_BINDTODEVICE
+    return luaL_error(L, "SO_BINDTODEVICE is not supported on this operating system");
+#else
+    char dev[IFNAMSIZ];
+    int len = sizeof(dev);
+    int err = opt_get(L, ps, SOL_SOCKET, SO_BINDTODEVICE, &dev, &len);
+    if (err)
+        return err;
+    lua_pushstring(L, dev);
+    return 1;
+#endif
+}
+
 /*------------------------------------------------------*/
 /* enables reuse of local address */
 int opt_set_reuseaddr(lua_State *L, p_socket ps)
@@ -190,7 +217,7 @@ int opt_set_send_buf_size(lua_State *L, p_socket ps)
 	return opt_setint(L, ps, SOL_SOCKET, SO_SNDBUF);
 }
 
-// /*------------------------------------------------------*/
+/*------------------------------------------------------*/
 
 #ifdef TCP_FASTOPEN
 int opt_set_tcp_fastopen(lua_State *L, p_socket ps)

+ 3 - 0
src/libraries/luasocket/libluasocket/options.h

@@ -53,6 +53,9 @@ int opt_get_tcp_keepintvl(lua_State *L, p_socket ps);
 int opt_set_tcp_defer_accept(lua_State *L, p_socket ps);
 #endif
 
+int opt_set_bindtodevice(lua_State *L, p_socket ps);
+int opt_get_bindtodevice(lua_State *L, p_socket ps);
+
 int opt_set_keepalive(lua_State *L, p_socket ps);
 int opt_get_keepalive(lua_State *L, p_socket ps);
 

+ 2 - 2
src/libraries/luasocket/libluasocket/smtp.lua

@@ -225,7 +225,7 @@ local function adjust_headers(mesgt)
     lower["date"] = lower["date"] or
         os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or _M.ZONE)
     lower["x-mailer"] = lower["x-mailer"] or socket._VERSION
-    -- this can't be overriden
+    -- this can't be overridden
     lower["mime-version"] = "1.0"
     return lower
 end
@@ -253,4 +253,4 @@ _M.send = socket.protect(function(mailt)
     return s:close()
 end)
 
-return _M
+return _M

+ 1 - 1
src/libraries/luasocket/libluasocket/smtp.lua.h

@@ -543,7 +543,7 @@ const unsigned char smtp_lua[] =
 	0x6c, 0x65, 0x72, 0x22, 0x5d, 0x20, 0x6f, 0x72, 0x20, 0x73, 0x6f, 0x63, 0x6b, 0x65, 0x74, 0x2e, 0x5f, 0x56, 
 	0x45, 0x52, 0x53, 0x49, 0x4f, 0x4e, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x63, 0x61, 0x6e, 0x27, 0x74, 0x20, 
-	0x62, 0x65, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x72, 0x69, 0x64, 0x65, 0x6e, 0x0a,
+	0x62, 0x65, 0x20, 0x6f, 0x76, 0x65, 0x72, 0x72, 0x69, 0x64, 0x64, 0x65, 0x6e, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x6c, 0x6f, 0x77, 0x65, 0x72, 0x5b, 0x22, 0x6d, 0x69, 0x6d, 0x65, 0x2d, 0x76, 0x65, 
 	0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x5d, 0x20, 0x3d, 0x20, 0x22, 0x31, 0x2e, 0x30, 0x22, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6c, 0x6f, 0x77, 0x65, 0x72, 0x0a,

+ 2 - 0
src/libraries/luasocket/libluasocket/tcp.c

@@ -71,6 +71,7 @@ static luaL_Reg tcp_methods[] = {
 
 /* socket option handlers */
 static t_opt optget[] = {
+    {"bindtodevice", opt_get_bindtodevice},
     {"keepalive",   opt_get_keepalive},
     {"reuseaddr",   opt_get_reuseaddr},
     {"reuseport",   opt_get_reuseport},
@@ -92,6 +93,7 @@ static t_opt optget[] = {
 };
 
 static t_opt optset[] = {
+    {"bindtodevice", opt_set_bindtodevice},
     {"keepalive",   opt_set_keepalive},
     {"reuseaddr",   opt_set_reuseaddr},
     {"reuseport",   opt_set_reuseport},

+ 0 - 4
src/libraries/luasocket/libluasocket/unixdgram.c

@@ -12,11 +12,7 @@
 #include <string.h>
 #include <stdlib.h>
 
-#ifdef _WIN32
-#include <afunix.h>
-#else
 #include <sys/un.h>
-#endif
 
 #define UNIXDGRAM_DATAGRAMSIZE 8192
 

+ 0 - 5
src/libraries/luasocket/libluasocket/unixstream.c

@@ -10,12 +10,7 @@
 #include "unixstream.h"
 
 #include <string.h>
-
-#ifdef _WIN32
-#include <afunix.h>
-#else
 #include <sys/un.h>
-#endif
 
 /*=========================================================================*\
 * Internal function prototypes

+ 1 - 1
src/libraries/luasocket/libluasocket/url.lua

@@ -152,7 +152,7 @@ function _M.parse(url, default)
     url = string.gsub(url, "^([%w][%w%+%-%.]*)%:",
         function(s) parsed.scheme = s; return "" end)
     -- get authority
-    url = string.gsub(url, "^//([^/]*)", function(n)
+    url = string.gsub(url, "^//([^/%?#]*)", function(n)
         parsed.authority = n
         return ""
     end)

+ 3 - 2
src/libraries/luasocket/libluasocket/url.lua.h

@@ -402,8 +402,9 @@ const unsigned char url_lua[] =
 	0x20, 0x20, 0x20, 0x20, 0x2d, 0x2d, 0x20, 0x67, 0x65, 0x74, 0x20, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 
 	0x74, 0x79, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x75, 0x72, 0x6c, 0x20, 0x3d, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x67, 
-	0x73, 0x75, 0x62, 0x28, 0x75, 0x72, 0x6c, 0x2c, 0x20, 0x22, 0x5e, 0x2f, 0x2f, 0x28, 0x5b, 0x5e, 0x2f, 0x5d, 
-	0x2a, 0x29, 0x22, 0x2c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x6e, 0x29, 0x0a,
+	0x73, 0x75, 0x62, 0x28, 0x75, 0x72, 0x6c, 0x2c, 0x20, 0x22, 0x5e, 0x2f, 0x2f, 0x28, 0x5b, 0x5e, 0x2f, 0x25, 
+	0x3f, 0x23, 0x5d, 0x2a, 0x29, 0x22, 0x2c, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x6e, 
+	0x29, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x61, 0x72, 0x73, 0x65, 0x64, 0x2e, 0x61, 0x75, 0x74, 
 	0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x20, 0x3d, 0x20, 0x6e, 0x0a,
 	0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x22, 0x22, 0x0a,

+ 1 - 1
src/libraries/luasocket/libluasocket/usocket.c

@@ -236,7 +236,7 @@ int socket_sendto(p_socket ps, const char *data, size_t count, size_t *sent,
     *sent = 0;
     if (*ps == SOCKET_INVALID) return IO_CLOSED;
     for ( ;; ) {
-        long put = (long) sendto(*ps, data, count, 0, addr, len); 
+        long put = (long) sendto(*ps, data, count, 0, addr, len);
         if (put >= 0) {
             *sent = put;
             return IO_DONE;

+ 2 - 0
src/libraries/luasocket/libluasocket/wsocket.c

@@ -262,6 +262,7 @@ int socket_recv(p_socket ps, char *data, size_t count, size_t *got,
         if (err != WSAEWOULDBLOCK) {
             if (err != WSAECONNRESET || prev == WSAECONNRESET) return err;
             prev = err;
+            continue;
         }
         if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
     }
@@ -291,6 +292,7 @@ int socket_recvfrom(p_socket ps, char *data, size_t count, size_t *got,
         if (err != WSAEWOULDBLOCK) {
             if (err != WSAECONNRESET || prev == WSAECONNRESET) return err;
             prev = err;
+            continue;
         }
         if ((err = socket_waitfd(ps, WAITFD_R, tm)) != IO_DONE) return err;
     }