summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/luatexdir/luasocket/etc
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/luasocket/etc')
-rw-r--r--Build/source/texk/web2c/luatexdir/luasocket/etc/check-links.lua2
-rw-r--r--Build/source/texk/web2c/luatexdir/luasocket/etc/cookie.lua88
-rw-r--r--Build/source/texk/web2c/luatexdir/luasocket/etc/dispatch.lua42
-rw-r--r--Build/source/texk/web2c/luatexdir/luasocket/etc/forward.lua2
-rw-r--r--Build/source/texk/web2c/luatexdir/luasocket/etc/get.lua2
-rw-r--r--Build/source/texk/web2c/luatexdir/luasocket/etc/links17
6 files changed, 132 insertions, 21 deletions
diff --git a/Build/source/texk/web2c/luatexdir/luasocket/etc/check-links.lua b/Build/source/texk/web2c/luatexdir/luasocket/etc/check-links.lua
index d2e4266e809..283f3ac2f63 100644
--- a/Build/source/texk/web2c/luatexdir/luasocket/etc/check-links.lua
+++ b/Build/source/texk/web2c/luatexdir/luasocket/etc/check-links.lua
@@ -11,7 +11,7 @@ dispatch.TIMEOUT = 10
-- make sure the user knows how to invoke us
arg = arg or {}
-if table.getn(arg) < 1 then
+if #arg < 1 then
print("Usage:\n luasocket check-links.lua [-n] {<url>}")
exit()
end
diff --git a/Build/source/texk/web2c/luatexdir/luasocket/etc/cookie.lua b/Build/source/texk/web2c/luatexdir/luasocket/etc/cookie.lua
new file mode 100644
index 00000000000..4adb40317c9
--- /dev/null
+++ b/Build/source/texk/web2c/luatexdir/luasocket/etc/cookie.lua
@@ -0,0 +1,88 @@
+local socket = require"socket"
+local http = require"socket.http"
+local url = require"socket.url"
+local ltn12 = require"ltn12"
+
+local token_class = '[^%c%s%(%)%<%>%@%,%;%:%\\%"%/%[%]%?%=%{%}]'
+
+local function unquote(t, quoted)
+ local n = string.match(t, "%$(%d+)$")
+ if n then n = tonumber(n) end
+ if quoted[n] then return quoted[n]
+ else return t end
+end
+
+local function parse_set_cookie(c, quoted, cookie_table)
+ c = c .. ";$last=last;"
+ local _, __, n, v, i = string.find(c, "(" .. token_class ..
+ "+)%s*=%s*(.-)%s*;%s*()")
+ local cookie = {
+ name = n,
+ value = unquote(v, quoted),
+ attributes = {}
+ }
+ while 1 do
+ _, __, n, v, i = string.find(c, "(" .. token_class ..
+ "+)%s*=?%s*(.-)%s*;%s*()", i)
+ if not n or n == "$last" then break end
+ cookie.attributes[#cookie.attributes+1] = {
+ name = n,
+ value = unquote(v, quoted)
+ }
+ end
+ cookie_table[#cookie_table+1] = cookie
+end
+
+local function split_set_cookie(s, cookie_table)
+ cookie_table = cookie_table or {}
+ -- remove quoted strings from cookie list
+ local quoted = {}
+ s = string.gsub(s, '"(.-)"', function(q)
+ quoted[#quoted+1] = q
+ return "$" .. #quoted
+ end)
+ -- add sentinel
+ s = s .. ",$last="
+ -- split into individual cookies
+ i = 1
+ while 1 do
+ local _, __, cookie, next_token
+ _, __, cookie, i, next_token = string.find(s, "(.-)%s*%,%s*()(" ..
+ token_class .. "+)%s*=", i)
+ if not next_token then break end
+ parse_set_cookie(cookie, quoted, cookie_table)
+ if next_token == "$last" then break end
+ end
+ return cookie_table
+end
+
+local function quote(s)
+ if string.find(s, "[ %,%;]") then return '"' .. s .. '"'
+ else return s end
+end
+
+local _empty = {}
+local function build_cookies(cookies)
+ s = ""
+ for i,v in ipairs(cookies or _empty) do
+ if v.name then
+ s = s .. v.name
+ if v.value and v.value ~= "" then
+ s = s .. '=' .. quote(v.value)
+ end
+ end
+ if v.name and #(v.attributes or _empty) > 0 then s = s .. "; " end
+ for j,u in ipairs(v.attributes or _empty) do
+ if u.name then
+ s = s .. u.name
+ if u.value and u.value ~= "" then
+ s = s .. '=' .. quote(u.value)
+ end
+ end
+ if j < #v.attributes then s = s .. "; " end
+ end
+ if i < #cookies then s = s .. ", " end
+ end
+ return s
+end
+
diff --git a/Build/source/texk/web2c/luatexdir/luasocket/etc/dispatch.lua b/Build/source/texk/web2c/luatexdir/luasocket/etc/dispatch.lua
index cc8cb23c882..24854155408 100644
--- a/Build/source/texk/web2c/luatexdir/luasocket/etc/dispatch.lua
+++ b/Build/source/texk/web2c/luatexdir/luasocket/etc/dispatch.lua
@@ -5,6 +5,7 @@
-----------------------------------------------------------------------------
local base = _G
local table = require("table")
+local string = require("string")
local socket = require("socket")
local coroutine = require("coroutine")
module("dispatch")
@@ -43,26 +44,32 @@ end
-----------------------------------------------------------------------------
-- Mega hack. Don't try to do this at home.
-----------------------------------------------------------------------------
--- we can't yield across calls to protect, so we rewrite it with coxpcall
+-- we can't yield across calls to protect on Lua 5.1, so we rewrite it with
+-- coroutines
-- make sure you don't require any module that uses socket.protect before
-- loading our hack
-function socket.protect(f)
- return function(...)
- local co = coroutine.create(f)
- while true do
- local results = {coroutine.resume(co, base.unpack(arg))}
- local status = table.remove(results, 1)
- if not status then
- if base.type(results[1]) == 'table' then
- return nil, results[1][1]
- else base.error(results[1]) end
- end
- if coroutine.status(co) == "suspended" then
- arg = {coroutine.yield(base.unpack(results))}
+if string.sub(base._VERSION, -3) == "5.1" then
+ local function _protect(co, status, ...)
+ if not status then
+ local msg = ...
+ if base.type(msg) == 'table' then
+ return nil, msg[1]
else
- return base.unpack(results)
+ base.error(msg, 0)
end
end
+ if coroutine.status(co) == "suspended" then
+ return _protect(co, coroutine.resume(co, coroutine.yield(...)))
+ else
+ return ...
+ end
+ end
+
+ function socket.protect(f)
+ return function(...)
+ local co = coroutine.create(f)
+ return _protect(co, coroutine.resume(co, ...))
+ end
end
end
@@ -76,7 +83,7 @@ local function newset()
insert = function(set, value)
if not reverse[value] then
table.insert(set, value)
- reverse[value] = table.getn(set)
+ reverse[value] = #set
end
end,
remove = function(set, value)
@@ -104,8 +111,7 @@ local function cowrap(dispatcher, tcp, error)
-- don't override explicitly.
local metat = { __index = function(table, key)
table[key] = function(...)
- arg[1] = tcp
- return tcp[key](base.unpack(arg))
+ return tcp[key](tcp,select(2,...))
end
return table[key]
end}
diff --git a/Build/source/texk/web2c/luatexdir/luasocket/etc/forward.lua b/Build/source/texk/web2c/luatexdir/luasocket/etc/forward.lua
index 9073ac4d0fa..05ced1aede8 100644
--- a/Build/source/texk/web2c/luatexdir/luasocket/etc/forward.lua
+++ b/Build/source/texk/web2c/luatexdir/luasocket/etc/forward.lua
@@ -3,7 +3,7 @@ local dispatch = require("dispatch")
local handler = dispatch.newhandler()
-- make sure the user knows how to invoke us
-if table.getn(arg) < 1 then
+if #arg < 1 then
print("Usage")
print(" lua forward.lua <iport:ohost:oport> ...")
os.exit(1)
diff --git a/Build/source/texk/web2c/luatexdir/luasocket/etc/get.lua b/Build/source/texk/web2c/luatexdir/luasocket/etc/get.lua
index 4196f000b09..9edc2357027 100644
--- a/Build/source/texk/web2c/luatexdir/luasocket/etc/get.lua
+++ b/Build/source/texk/web2c/luatexdir/luasocket/etc/get.lua
@@ -135,7 +135,7 @@ end
-- main program
arg = arg or {}
-if table.getn(arg) < 1 then
+if #arg < 1 then
io.write("Usage:\n lua get.lua <remote-url> [<local-file>]\n")
os.exit(1)
else get(arg[1], arg[2]) end
diff --git a/Build/source/texk/web2c/luatexdir/luasocket/etc/links b/Build/source/texk/web2c/luatexdir/luasocket/etc/links
new file mode 100644
index 00000000000..087f1c0e4ae
--- /dev/null
+++ b/Build/source/texk/web2c/luatexdir/luasocket/etc/links
@@ -0,0 +1,17 @@
+<a href="http://www.cs.princeton.edu"> bla </a>
+<a href="http://www.princeton.edu"> bla </a>
+<a href="http://www.tecgraf.puc-rio.br"> bla </a>
+<a href="http://www.inf.puc-rio.br"> bla </a>
+<a href="http://www.puc-rio.br"> bla </a>
+<a href="http://www.impa.br"> bla </a>
+<a href="http://www.lua.org"> bla </a>
+<a href="http://www.lua-users.org"> bla </a>
+<a href="http://www.amazon.com"> bla </a>
+<a href="http://www.google.com"> bla </a>
+<a href="http://www.nytimes.com"> bla </a>
+<a href="http://www.bbc.co.uk"> bla </a>
+<a href="http://oglobo.globo.com"> bla </a>
+<a href="http://slate.msn.com"> bla </a>
+<a href="http://www.apple.com"> bla </a>
+<a href="http://www.microsoft.com"> bla </a>
+<a href="http://www.nasa.gov"> bla </a>