aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2007-03-12 04:08:40 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2007-03-12 04:08:40 +0000
commitbe2e467929be9f27fbe92fe7b94783635c920c06 (patch)
tree94054e38f33178d805a6144d3bd9cb76da4a4c76
parent8bf9fb51dd09fb066483247fccbfc979acc84071 (diff)
downloadluasocket-be2e467929be9f27fbe92fe7b94783635c920c06.tar.gz
luasocket-be2e467929be9f27fbe92fe7b94783635c920c06.tar.bz2
luasocket-be2e467929be9f27fbe92fe7b94783635c920c06.zip
Couple bug fixes.
-rw-r--r--NEW25
-rw-r--r--WISH25
-rw-r--r--config33
-rw-r--r--etc/get.lua10
-rw-r--r--makefile1
-rw-r--r--src/http.lua5
-rw-r--r--src/makefile7
-rw-r--r--src/smtp.lua24
-rw-r--r--test/httptest.lua5
-rw-r--r--test/testclnt.lua2
-rw-r--r--test/testmesg.lua12
11 files changed, 76 insertions, 73 deletions
diff --git a/NEW b/NEW
index bc9ba2c..13b6d60 100644
--- a/NEW
+++ b/NEW
@@ -1,24 +1 @@
1What's New Fixed case sensitivity in headers of multipart messages in smtp.message.
2
3This is just a bug-fix/update release.
4
5 * Updated: now using compat-5.1r5;
6
7 * Improved: http.request is more robust to malformed
8 URLs (Adrian Sietsma);
9
10 * Improved: the simple http.request interface sends a
11 "Content-type: application/x-www-form-urlencoded" header
12 (William Trenker);
13
14 * Improved: http.request is robust to evil servers that
15 send inappropriate 100-continue messages (David Burgess);
16
17 * Fixed: http.request was using the old host header during
18 redirects (Florian Berger);
19
20 * Fixed: sample unix.c had fallen through the cracks
21 during development (Matthew Percival);
22
23 * Fixed: error code was not being propagated correctly
24 in ftp.lua (David Burgess).
diff --git a/WISH b/WISH
index 146f797..e7e9c07 100644
--- a/WISH
+++ b/WISH
@@ -1,5 +1,22 @@
1... as an l-value 1... as an l-value to get all results of a function call?
2tupples? 2at least ...[i] and #...
3extend to full tuples?
4
5__and __or __not metamethods
6
7lua_tostring, lua_tonumber, lua_touseradta etc push values in stack
8__tostring,__tonumber, __touserdata metamethods are checked
9and expected to push an object of correct type on stack
10
11lua_rawtostring, lua_rawtonumber, lua_rawtouserdata don't
12push anything on stack, return data of appropriate type,
13skip metamethods and throw error if object not of exact type
14
3package.findfile exported 15package.findfile exported
4assert returns all arguments on success 16module not polluting the global namespace
5module does not pollute the global namespace 17
18coxpcall with a coroutine pool for efficiency (reusing coroutines)
19
20exception mechanism formalized? just like the package system was.
21
22a nice bitlib in the core
diff --git a/config b/config
index 3bed687..5a86f9c 100644
--- a/config
+++ b/config
@@ -15,22 +15,23 @@ UNIX_SO=unix.$(EXT)
15#------ 15#------
16# Lua includes and libraries 16# Lua includes and libraries
17# 17#
18LUAINC=-I/usr/local/include/lua50 18#LUAINC=-I/usr/local/include/lua50
19#LUAINC=-I/usr/local/include/lua5.1 19#LUAINC=-I/usr/local/include/lua5.1
20LUAINC=-Ilua-5.1.1/src
20 21
21#------ 22#------
22# Compat-5.1 directory 23# Compat-5.1 directory
23# 24#
24COMPAT=compat-5.1r5 25#COMPAT=compat-5.1r5
25 26
26#------ 27#------
27# Top of your Lua installation 28# Top of your Lua installation
28# Relative paths will be inside the src tree 29# Relative paths will be inside the src tree
29# 30#
30INSTALL_TOP_SHARE=/usr/local/share/lua/5.0 31#INSTALL_TOP_SHARE=/usr/local/share/lua/5.0
31INSTALL_TOP_LIB=/usr/local/lib/lua/5.0 32#INSTALL_TOP_LIB=/usr/local/lib/lua/5.0
32#INSTALL_TOP_SHARE=/usr/local/share/lua/5.1 33INSTALL_TOP_SHARE=/usr/local/share/lua/5.1
33#INSTALL_TOP_LIB=/usr/local/lib/lua/5.1 34INSTALL_TOP_LIB=/usr/local/lib/lua/5.1
34 35
35INSTALL_DATA=cp 36INSTALL_DATA=cp
36INSTALL_EXEC=cp 37INSTALL_EXEC=cp
@@ -39,20 +40,20 @@ INSTALL_EXEC=cp
39# Compiler and linker settings 40# Compiler and linker settings
40# for Mac OS X 41# for Mac OS X
41# 42#
42#CC=gcc 43CC=gcc
43#DEF=-DLUASOCKET_DEBUG -DUNIX_HAS_SUN_LEN 44DEF=-DLUASOCKET_DEBUG -DUNIX_HAS_SUN_LEN
44#CFLAGS= $(LUAINC) -I$(COMPAT) $(DEF) -pedantic -Wall -O2 -fno-common 45CFLAGS= $(LUAINC) -I$(COMPAT) $(DEF) -pedantic -Wall -O2 -fno-common
45#LDFLAGS=-bundle -undefined dynamic_lookup 46LDFLAGS=-bundle -undefined dynamic_lookup
46#LD=export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc 47LD=export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc
47 48
48#------ 49#------
49# Compiler and linker settings 50# Compiler and linker settings
50# for Linux 51# for Linux
51CC=gcc 52#CC=gcc
52DEF=-DLUASOCKET_DEBUG 53#DEF=-DLUASOCKET_DEBUG
53CFLAGS= $(LUAINC) -I$(COMPAT) $(DEF) -pedantic -Wall -O2 -fpic 54#CFLAGS= $(LUAINC) -I$(COMPAT) $(DEF) -pedantic -Wall -O2 -fpic
54LDFLAGS=-O -shared -fpic 55#LDFLAGS=-O -shared -fpic
55LD=gcc 56#LD=gcc
56 57
57#------ 58#------
58# End of makefile configuration 59# End of makefile configuration
diff --git a/etc/get.lua b/etc/get.lua
index ebf3e75..09f639d 100644
--- a/etc/get.lua
+++ b/etc/get.lua
@@ -65,21 +65,23 @@ end
65-- kind of copied from luasocket's manual callback examples 65-- kind of copied from luasocket's manual callback examples
66function stats(size) 66function stats(size)
67 local start = socket.gettime() 67 local start = socket.gettime()
68 local last = start
68 local got = 0 69 local got = 0
69 return function(chunk) 70 return function(chunk)
70 -- elapsed time since start 71 -- elapsed time since start
71 local delta = socket.gettime() - start 72 local current = socket.gettime()
72 if chunk then 73 if chunk then
73 -- total bytes received 74 -- total bytes received
74 got = got + string.len(chunk) 75 got = got + string.len(chunk)
75 -- not enough time for estimate 76 -- not enough time for estimate
76 if delta > 0.1 then 77 if current - last > 1 then
77 io.stderr:write("\r", gauge(got, delta, size)) 78 io.stderr:write("\r", gauge(got, current - start, size))
78 io.stderr:flush() 79 io.stderr:flush()
80 last = current
79 end 81 end
80 else 82 else
81 -- close up 83 -- close up
82 io.stderr:write("\r", gauge(got, delta), "\n") 84 io.stderr:write("\r", gauge(got, current - start), "\n")
83 end 85 end
84 return chunk 86 return chunk
85 end 87 end
diff --git a/makefile b/makefile
index f77bde5..6d70039 100644
--- a/makefile
+++ b/makefile
@@ -25,7 +25,6 @@ TO_SOCKET_SHARE:= \
25 smtp.lua 25 smtp.lua
26 26
27TO_TOP_SHARE:= \ 27TO_TOP_SHARE:= \
28 $(COMPAT)/compat-5.1.lua \
29 ltn12.lua \ 28 ltn12.lua \
30 socket.lua \ 29 socket.lua \
31 mime.lua 30 mime.lua
diff --git a/src/http.lua b/src/http.lua
index 558f347..9d739a4 100644
--- a/src/http.lua
+++ b/src/http.lua
@@ -107,7 +107,7 @@ local metat = { __index = {} }
107 107
108function open(host, port, create) 108function open(host, port, create)
109 -- create socket with user connect function, or with default 109 -- create socket with user connect function, or with default
110 local c = socket.try(create or socket.tcp)() 110 local c = socket.try((create or socket.tcp)())
111 local h = base.setmetatable({ c = c }, metat) 111 local h = base.setmetatable({ c = c }, metat)
112 -- create finalized try 112 -- create finalized try
113 h.try = socket.newtry(function() h:close() end) 113 h.try = socket.newtry(function() h:close() end)
@@ -228,7 +228,8 @@ local function adjustrequest(reqt)
228 -- explicit components override url 228 -- explicit components override url
229 for i,v in base.pairs(reqt) do nreqt[i] = v end 229 for i,v in base.pairs(reqt) do nreqt[i] = v end
230 if nreqt.port == "" then nreqt.port = 80 end 230 if nreqt.port == "" then nreqt.port = 80 end
231 socket.try(nreqt.host, "invalid host '" .. base.tostring(nreqt.host) .. "'") 231 socket.try(nreqt.host and nreqt.host ~= "",
232 "invalid host '" .. base.tostring(nreqt.host) .. "'")
232 -- compute uri if user hasn't overriden 233 -- compute uri if user hasn't overriden
233 nreqt.uri = reqt.uri or adjusturi(nreqt) 234 nreqt.uri = reqt.uri or adjusturi(nreqt)
234 -- ajust host and port if there is a proxy 235 -- ajust host and port if there is a proxy
diff --git a/src/makefile b/src/makefile
index a21a346..b614f77 100644
--- a/src/makefile
+++ b/src/makefile
@@ -11,8 +11,9 @@ include ../config
11# Modules belonging to socket-core 11# Modules belonging to socket-core
12# 12#
13 13
14#$(COMPAT)/compat-5.1.o \
15
14SOCKET_OBJS:= \ 16SOCKET_OBJS:= \
15 $(COMPAT)/compat-5.1.o \
16 luasocket.o \ 17 luasocket.o \
17 timeout.o \ 18 timeout.o \
18 buffer.o \ 19 buffer.o \
@@ -29,11 +30,11 @@ SOCKET_OBJS:= \
29#------ 30#------
30# Modules belonging mime-core 31# Modules belonging mime-core
31# 32#
33#$(COMPAT)/compat-5.1.o \
34
32MIME_OBJS:=\ 35MIME_OBJS:=\
33 $(COMPAT)/compat-5.1.o \
34 mime.o 36 mime.o
35 37
36
37#------ 38#------
38# Modules belonging unix (local domain sockets) 39# Modules belonging unix (local domain sockets)
39# 40#
diff --git a/src/smtp.lua b/src/smtp.lua
index 2257a69..9a204d8 100644
--- a/src/smtp.lua
+++ b/src/smtp.lua
@@ -122,6 +122,15 @@ function open(server, port, create)
122 return s 122 return s
123end 123end
124 124
125-- convert headers to lowercase
126local function lower_headers(headers)
127 local lower = {}
128 for i,v in base.pairs(headers or lower) do
129 lower[string.lower(i)] = v
130 end
131 return lower
132end
133
125--------------------------------------------------------------------------- 134---------------------------------------------------------------------------
126-- Multipart message source 135-- Multipart message source
127----------------------------------------------------------------------------- 136-----------------------------------------------------------------------------
@@ -149,7 +158,7 @@ end
149local function send_multipart(mesgt) 158local function send_multipart(mesgt)
150 -- make sure we have our boundary and send headers 159 -- make sure we have our boundary and send headers
151 local bd = newboundary() 160 local bd = newboundary()
152 local headers = mesgt.headers or {} 161 local headers = lower_headers(mesgt.headers or {})
153 headers['content-type'] = headers['content-type'] or 'multipart/mixed' 162 headers['content-type'] = headers['content-type'] or 'multipart/mixed'
154 headers['content-type'] = headers['content-type'] .. 163 headers['content-type'] = headers['content-type'] ..
155 '; boundary="' .. bd .. '"' 164 '; boundary="' .. bd .. '"'
@@ -176,7 +185,7 @@ end
176-- yield message body from a source 185-- yield message body from a source
177local function send_source(mesgt) 186local function send_source(mesgt)
178 -- make sure we have a content-type 187 -- make sure we have a content-type
179 local headers = mesgt.headers or {} 188 local headers = lower_headers(mesgt.headers or {})
180 headers['content-type'] = headers['content-type'] or 189 headers['content-type'] = headers['content-type'] or
181 'text/plain; charset="iso-8859-1"' 190 'text/plain; charset="iso-8859-1"'
182 send_headers(headers) 191 send_headers(headers)
@@ -192,7 +201,7 @@ end
192-- yield message body from a string 201-- yield message body from a string
193local function send_string(mesgt) 202local function send_string(mesgt)
194 -- make sure we have a content-type 203 -- make sure we have a content-type
195 local headers = mesgt.headers or {} 204 local headers = lower_headers(mesgt.headers or {})
196 headers['content-type'] = headers['content-type'] or 205 headers['content-type'] = headers['content-type'] or
197 'text/plain; charset="iso-8859-1"' 206 'text/plain; charset="iso-8859-1"'
198 send_headers(headers) 207 send_headers(headers)
@@ -209,20 +218,17 @@ end
209 218
210-- set defaul headers 219-- set defaul headers
211local function adjust_headers(mesgt) 220local function adjust_headers(mesgt)
212 local lower = {} 221 local lower = lower_headers(mesgt.headers)
213 for i,v in base.pairs(mesgt.headers or lower) do
214 lower[string.lower(i)] = v
215 end
216 lower["date"] = lower["date"] or 222 lower["date"] = lower["date"] or
217 os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or ZONE) 223 os.date("!%a, %d %b %Y %H:%M:%S ") .. (mesgt.zone or ZONE)
218 lower["x-mailer"] = lower["x-mailer"] or socket._VERSION 224 lower["x-mailer"] = lower["x-mailer"] or socket._VERSION
219 -- this can't be overriden 225 -- this can't be overriden
220 lower["mime-version"] = "1.0" 226 lower["mime-version"] = "1.0"
221 mesgt.headers = lower 227 return lower
222end 228end
223 229
224function message(mesgt) 230function message(mesgt)
225 adjust_headers(mesgt) 231 mesgt.headers = adjust_headers(mesgt)
226 -- create and return message source 232 -- create and return message source
227 local co = coroutine.create(function() send_message(mesgt) end) 233 local co = coroutine.create(function() send_message(mesgt) end)
228 return function() 234 return function()
diff --git a/test/httptest.lua b/test/httptest.lua
index ac60787..dd53ec3 100644
--- a/test/httptest.lua
+++ b/test/httptest.lua
@@ -119,9 +119,8 @@ check_request(request, expect, ignore)
119 119
120------------------------------------------------------------------------ 120------------------------------------------------------------------------
121io.write("testing invalid url: ") 121io.write("testing invalid url: ")
122local c, e = socket.connect("", 80) 122local r, e = http.request{url = host .. prefix}
123local r, re = http.request{url = host .. prefix} 123assert(r == nil and e == "invalid host ''")
124assert(r == nil and e == re)
125r, re = http.request(host .. prefix) 124r, re = http.request(host .. prefix)
126assert(r == nil and e == re, tostring(r) ..", " .. tostring(re) .. 125assert(r == nil and e == re, tostring(r) ..", " .. tostring(re) ..
127 " vs " .. tostring(e)) 126 " vs " .. tostring(e))
diff --git a/test/testclnt.lua b/test/testclnt.lua
index cf71c9f..304cfd3 100644
--- a/test/testclnt.lua
+++ b/test/testclnt.lua
@@ -101,7 +101,7 @@ control:setoption("tcp-nodelay", true)
101 101
102------------------------------------------------------------------------ 102------------------------------------------------------------------------
103function test_methods(sock, methods) 103function test_methods(sock, methods)
104 for _, v in methods do 104 for _, v in pairs(methods) do
105 if type(sock[v]) ~= "function" then 105 if type(sock[v]) ~= "function" then
106 fail(sock.class .. " method '" .. v .. "' not registered") 106 fail(sock.class .. " method '" .. v .. "' not registered")
107 end 107 end
diff --git a/test/testmesg.lua b/test/testmesg.lua
index ab85c93..04305f4 100644
--- a/test/testmesg.lua
+++ b/test/testmesg.lua
@@ -12,7 +12,7 @@ source = smtp.message {
12 headers = { ['content-type'] = 'multipart/alternative' }, 12 headers = { ['content-type'] = 'multipart/alternative' },
13 body = { 13 body = {
14 [1] = { 14 [1] = {
15 headers = { ['content-type'] = 'text/html' }, 15 headers = { ['Content-type'] = 'text/html' },
16 body = "<html> <body> Hi, <b>there</b>...</body> </html>" 16 body = "<html> <body> Hi, <b>there</b>...</body> </html>"
17 }, 17 },
18 [2] = { 18 [2] = {
@@ -60,7 +60,7 @@ source = smtp.message{
60 -- chunks are loaded into memory and translation happens on the fly. 60 -- chunks are loaded into memory and translation happens on the fly.
61 [2] = { 61 [2] = {
62 headers = { 62 headers = {
63 ["content-type"] = 'image/png; name="luasocket.png"', 63 ["ConTenT-tYpE"] = 'image/png; name="luasocket.png"',
64 ["content-disposition"] = 'attachment; filename="luasocket.png"', 64 ["content-disposition"] = 'attachment; filename="luasocket.png"',
65 ["content-description"] = 'a beautiful image', 65 ["content-description"] = 'a beautiful image',
66 ["content-transfer-encoding"] = "BASE64" 66 ["content-transfer-encoding"] = "BASE64"
@@ -83,10 +83,10 @@ r, e = smtp.send{
83 "<diego@princeton.edu>" }, 83 "<diego@princeton.edu>" },
84 from = "<diego@princeton.edu>", 84 from = "<diego@princeton.edu>",
85 source = ltn12.source.chain(source, filter), 85 source = ltn12.source.chain(source, filter),
86 server = "mail.cs.princeton.edu", 86 --server = "mail.cs.princeton.edu",
87 --server = "localhost", 87 --port = 25
88 --port = 2525 88 server = "localhost",
89 port = 25 89 port = 2525
90} 90}
91 91
92print(r, e) 92print(r, e)