Permalink
Browse files

luasocket-2.0.3-rc2

  • Loading branch information...
1 parent 80593da commit f6d24463c7e2b94415f6dbf5bbed10ec9f9d2d34 @sam-github committed Feb 1, 2012
Showing with 531 additions and 443 deletions.
  1. +20 −16 NEW
  2. +0 −60 config
  3. +1 −1 doc/http.html
  4. +11 −6 doc/index.html
  5. +22 −22 etc/dict.lua
  6. +53 −53 etc/get.lua
  7. +4 −4 etc/lp.lua
  8. +34 −34 etc/tftp.lua
  9. +8 −45 makefile
  10. +11 −5 src/buffer.c
  11. +2 −2 src/buffer.h
  12. +2 −2 src/ftp.lua
  13. +1 −1 src/http.lua
  14. +1 −1 src/inet.c
  15. +196 −59 src/makefile
  16. +1 −1 src/mime.c
  17. +1 −1 src/options.c
  18. +1 −1 src/select.c
  19. +1 −1 src/smtp.lua
  20. +1 −1 src/tcp.c
  21. +1 −1 src/timeout.c
  22. +2 −2 src/tp.lua
  23. +1 −1 src/udp.c
  24. +6 −6 src/unix.c
  25. +56 −56 src/url.lua
  26. +3 −3 src/usocket.c
  27. +4 −4 src/wsocket.c
  28. +2 −0 test/README
  29. +3 −0 test/hello.lua
  30. +75 −47 test/testclnt.lua
  31. +7 −7 test/testsupport.lua
View
@@ -2,19 +2,23 @@ What's New
This is just a bug-fix/update release.
- * Fixed: manual links to home.html changed to index.html (Robert Hahn)
- * Fixed: mime.unb64() returns empty string on results that start
- with a null character (Robert Raschke)
- * Fixed: HTTP now automatically redirecting on 303 and 307 (Jonathan Gray)
- * Fixed: sleep(-1) could sleep forever wasting CPU. Now it
- returns immediately (MPB);
-
- * Improved: FTP commands are now sent in upper case to
- help buggy servers (Anders Eurenius)
- * Improved: known headers now sent in canonic
- capitalization to help buggy servers (Joseph Stewart);
- * Improved: Clarified tcp:receive() in the manual (MPB);
-
- * Fixed: multicast didn't work on Windows (Herbert Leuwer, Adrian Sietsma)
- * Fixed: select() reports an error when called with more
- sockets than FD_SETSIZE (Lorenzo Leonini)
+ * Fixed: manual sample of HTTP authentication now uses correct
+ "authorization" header (Alexandre Ittner);
+ * Fixed: receive() returns immediatelly if prefix can satisfy
+ bytes requested (M Joonas Pihlaja);
+ * Fixed: multicast didn't work on Windows, or anywhere
+ else for that matter (Herbert Leuwer, Adrian Sietsma);
+ * Fixed: select() now reports an error when called with more
+ sockets than FD_SETSIZE (Lorenzo Leonini);
+ * Fixed: manual links to home.html changed to index.html (Robert Hahn);
+ * Fixed: mime.unb64() would return an empty string on results that started
+ with a null character (Robert Raschke);
+ * Fixed: HTTP now automatically redirects on 303 and 307 (Jonathan Gray);
+ * Fixed: calling sleep() with negative numbers could
+ block forever, wasting CPU. Now it returns immediately (MPB);
+ * Improved: FTP commands are now sent in upper case to
+ help buggy servers (Anders Eurenius);
+ * Improved: known headers now sent in canonic
+ capitalization to help buggy servers (Joseph Stewart);
+ * Improved: Clarified tcp:receive() in the manual (MPB);
+ * Improved: Decent makefiles (LHF).
View
@@ -1,60 +0,0 @@
-#------
-# LuaSocket makefile configuration
-#
-
-#------
-# Output file names
-#
-EXT=so
-SOCKET_V=2.0.3
-MIME_V=1.0.3
-SOCKET_SO=socket.$(EXT).$(SOCKET_V)
-MIME_SO=mime.$(EXT).$(MIME_V)
-UNIX_SO=unix.$(EXT)
-
-#------
-# Lua includes and libraries
-#
-#LUAINC=-I/usr/local/include/lua50
-#LUAINC=-I/usr/local/include/lua5.1
-LUAINC=-I/opt/local/include
-
-#------
-# Compat-5.1 directory
-#
-#COMPAT=-Icompat-5.1r5
-
-#------
-# Top of your Lua installation
-# Relative paths will be inside the src tree
-#
-#INSTALL_TOP_SHARE=/usr/local/share/lua/5.0
-#INSTALL_TOP_LIB=/usr/local/lib/lua/5.0
-INSTALL_TOP_SHARE=/opt/local/share/lua/5.1
-INSTALL_TOP_LIB=/opt/local/lib/lua/5.1
-
-INSTALL_DATA=cp
-INSTALL_EXEC=cp
-
-#------
-# Compiler and linker settings
-# for Mac OS X
-#
-CC=gcc
-DEF= -DLUASOCKET_DEBUG -DUNIX_HAS_SUN_LEN
-CFLAGS= $(LUAINC) $(COMPAT) $(DEF) -pedantic -Wall -O2 -fno-common
-LDFLAGS=-bundle -undefined dynamic_lookup
-LD=export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc
-
-#------
-# Compiler and linker settings
-# for Linux
-#CC=gcc
-#DEF=-DLUASOCKET_DEBUG
-#CFLAGS= $(LUAINC) $(DEF) -pedantic -Wall -O2 -fpic
-#LDFLAGS=-O -shared -fpic
-#LD=gcc
-
-#------
-# End of makefile configuration
-#
View
@@ -304,7 +304,7 @@ <h2 id=http>HTTP</h2>
-- the request directly.
r, c = http.request {
url = "http://www.example.com/private/index.html",
- headers = { authentication = "Basic " .. (mime.b64("fulano:silva")) }
+ headers = { authorization = "Basic " .. (mime.b64("fulano:silva")) }
}
</pre>
View
@@ -138,21 +138,26 @@ <h2 id=new>What's New</h2>
</p>
<ul>
+<li> Fixed: manual sample of HTTP authentication now uses correct
+ "authorization" header (Alexandre Ittner);
+<li> Fixed: receive() returns immediatelly if prefix can satisfy
+ bytes requested (M Joonas Pihlaja);
<li> Fixed: multicast didn't work on Windows, or anywhere
- else for that matter (Herbert Leuwer, Adrian Sietsma)
+ else for that matter (Herbert Leuwer, Adrian Sietsma);
<li> Fixed: select() now reports an error when called with more
- sockets than FD_SETSIZE (Lorenzo Leonini)
-<li> Fixed: manual links to home.html changed to index.html (Robert Hahn)
+ sockets than FD_SETSIZE (Lorenzo Leonini);
+<li> Fixed: manual links to home.html changed to index.html (Robert Hahn);
<li> Fixed: mime.unb64() would return an empty string on results that started
- with a null character (Robert Raschke)
-<li> Fixed: HTTP now automatically redirects on 303 and 307 (Jonathan Gray)
+ with a null character (Robert Raschke);
+<li> Fixed: HTTP now automatically redirects on 303 and 307 (Jonathan Gray);
<li> Fixed: calling sleep() with negative numbers could
block forever, wasting CPU. Now it returns immediately (MPB);
<li> Improved: FTP commands are now sent in upper case to
- help buggy servers (Anders Eurenius)
+ help buggy servers (Anders Eurenius);
<li> Improved: known headers now sent in canonic
capitalization to help buggy servers (Joseph Stewart);
<li> Improved: Clarified tcp:receive() in the manual (MPB);
+<li> Improved: Decent makefiles (LHF).
</ul>
<!-- old ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
View
@@ -44,48 +44,48 @@ function metat.__index:check(ok)
end
function metat.__index:getdef()
- local line = socket.try(self.tp:receive())
- local def = {}
- while line ~= "." do
- table.insert(def, line)
- line = socket.try(self.tp:receive())
- end
- return table.concat(def, "\n")
+ local line = socket.try(self.tp:receive())
+ local def = {}
+ while line ~= "." do
+ table.insert(def, line)
+ line = socket.try(self.tp:receive())
+ end
+ return table.concat(def, "\n")
end
function metat.__index:define(database, word)
database = database or "!"
- socket.try(self.tp:command("DEFINE", database .. " " .. word))
+ socket.try(self.tp:command("DEFINE", database .. " " .. word))
local code, count = self:check(150)
- local defs = {}
- for i = 1, count do
- self:check(151)
- table.insert(defs, self:getdef())
- end
- self:check(250)
+ local defs = {}
+ for i = 1, count do
+ self:check(151)
+ table.insert(defs, self:getdef())
+ end
+ self:check(250)
return defs
end
function metat.__index:match(database, strat, word)
database = database or "!"
strat = strat or "."
- socket.try(self.tp:command("MATCH", database .." ".. strat .." ".. word))
+ socket.try(self.tp:command("MATCH", database .." ".. strat .." ".. word))
self:check(152)
- local mat = {}
- local line = socket.try(self.tp:receive())
+ local mat = {}
+ local line = socket.try(self.tp:receive())
while line ~= '.' do
database, word = socket.skip(2, string.find(line, "(%S+) (.*)"))
if not mat[database] then mat[database] = {} end
table.insert(mat[database], word)
- line = socket.try(self.tp:receive())
- end
- self:check(250)
+ line = socket.try(self.tp:receive())
+ end
+ self:check(250)
return mat
end
function metat.__index:quit()
- self.tp:command("QUIT")
- return self:check(221)
+ self.tp:command("QUIT")
+ return self:check(221)
end
function metat.__index:close()
View
@@ -12,53 +12,53 @@ local ltn12 = require("ltn12")
-- formats a number of seconds into human readable form
function nicetime(s)
- local l = "s"
- if s > 60 then
- s = s / 60
- l = "m"
- if s > 60 then
- s = s / 60
- l = "h"
- if s > 24 then
- s = s / 24
- l = "d" -- hmmm
- end
- end
- end
- if l == "s" then return string.format("%5.0f%s", s, l)
- else return string.format("%5.2f%s", s, l) end
+ local l = "s"
+ if s > 60 then
+ s = s / 60
+ l = "m"
+ if s > 60 then
+ s = s / 60
+ l = "h"
+ if s > 24 then
+ s = s / 24
+ l = "d" -- hmmm
+ end
+ end
+ end
+ if l == "s" then return string.format("%5.0f%s", s, l)
+ else return string.format("%5.2f%s", s, l) end
end
-- formats a number of bytes into human readable form
function nicesize(b)
- local l = "B"
- if b > 1024 then
- b = b / 1024
- l = "KB"
- if b > 1024 then
- b = b / 1024
- l = "MB"
- if b > 1024 then
- b = b / 1024
- l = "GB" -- hmmm
- end
- end
- end
- return string.format("%7.2f%2s", b, l)
+ local l = "B"
+ if b > 1024 then
+ b = b / 1024
+ l = "KB"
+ if b > 1024 then
+ b = b / 1024
+ l = "MB"
+ if b > 1024 then
+ b = b / 1024
+ l = "GB" -- hmmm
+ end
+ end
+ end
+ return string.format("%7.2f%2s", b, l)
end
-- returns a string with the current state of the download
local remaining_s = "%s received, %s/s throughput, %2.0f%% done, %s remaining"
local elapsed_s = "%s received, %s/s throughput, %s elapsed "
function gauge(got, delta, size)
- local rate = got / delta
- if size and size >= 1 then
- return string.format(remaining_s, nicesize(got), nicesize(rate),
- 100*got/size, nicetime((size-got)/rate))
- else
- return string.format(elapsed_s, nicesize(got),
- nicesize(rate), nicetime(delta))
- end
+ local rate = got / delta
+ if size and size >= 1 then
+ return string.format(remaining_s, nicesize(got), nicesize(rate),
+ 100*got/size, nicetime((size-got)/rate))
+ else
+ return string.format(elapsed_s, nicesize(got),
+ nicesize(rate), nicetime(delta))
+ end
end
-- creates a new instance of a receive_cb that saves to disk
@@ -89,10 +89,10 @@ end
-- determines the size of a http file
function gethttpsize(u)
- local r, c, h = http.request {method = "HEAD", url = u}
- if c == 200 then
- return tonumber(h["content-length"])
- end
+ local r, c, h = http.request {method = "HEAD", url = u}
+ if c == 200 then
+ return tonumber(h["content-length"])
+ end
end
-- downloads a file using the http protocol
@@ -101,7 +101,7 @@ function getbyhttp(u, file)
-- only print feedback if output is not stdout
if file then save = ltn12.sink.chain(stats(gethttpsize(u)), save) end
local r, c, h, s = http.request {url = u, sink = save }
- if c ~= 200 then io.stderr:write(s or c, "\n") end
+ if c ~= 200 then io.stderr:write(s or c, "\n") end
end
-- downloads a file using the ftp protocol
@@ -114,29 +114,29 @@ function getbyftp(u, file)
gett.sink = save
gett.type = "i"
local ret, err = ftp.get(gett)
- if err then print(err) end
+ if err then print(err) end
end
-- determines the scheme
function getscheme(u)
- -- this is an heuristic to solve a common invalid url poblem
- if not string.find(u, "//") then u = "//" .. u end
- local parsed = url.parse(u, {scheme = "http"})
- return parsed.scheme
+ -- this is an heuristic to solve a common invalid url poblem
+ if not string.find(u, "//") then u = "//" .. u end
+ local parsed = url.parse(u, {scheme = "http"})
+ return parsed.scheme
end
-- gets a file either by http or ftp, saving as <name>
function get(u, name)
local fout = name and io.open(name, "wb")
- local scheme = getscheme(u)
- if scheme == "ftp" then getbyftp(u, fout)
- elseif scheme == "http" then getbyhttp(u, fout)
- else print("unknown scheme" .. scheme) end
+ local scheme = getscheme(u)
+ if scheme == "ftp" then getbyftp(u, fout)
+ elseif scheme == "http" then getbyhttp(u, fout)
+ else print("unknown scheme" .. scheme) end
end
-- main program
arg = arg or {}
if table.getn(arg) < 1 then
- io.write("Usage:\n lua get.lua <remote-url> [<local-file>]\n")
- os.exit(1)
+ io.write("Usage:\n lua get.lua <remote-url> [<local-file>]\n")
+ os.exit(1)
else get(arg[1], arg[2]) end
View
@@ -268,11 +268,11 @@ send = socket.protect(function(option)
local class = string.sub(option.class or localip or localhost,1,31)
local _,_,ctlfn = string.find(file,".*[%/%\\](.*)")
ctlfn = string.sub(ctlfn or file,1,131)
- local cfile =
- string.format("H%-s\nC%-s\nJ%-s\nP%-s\n%.1s%-s\nU%-s\nN%-s\n",
- localhost,
+ local cfile =
+ string.format("H%-s\nC%-s\nJ%-s\nP%-s\n%.1s%-s\nU%-s\nN%-s\n",
+ localhost,
class,
- option.job or "LuaSocket",
+ option.job or "LuaSocket",
user,
fmt, lpfile,
lpfile,
Oops, something went wrong.

0 comments on commit f6d2446

Please sign in to comment.