aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2003-08-31 00:58:07 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2003-08-31 00:58:07 +0000
commit6789b83ff5c15296267f880d3b98cf8a1800c30a (patch)
tree9571dc81cb0147218332cda34b7ccdfed37ddbbc
parentc51d4acf1c2a8675a3bb043e799ff4390cef47d6 (diff)
downloadluasocket-6789b83ff5c15296267f880d3b98cf8a1800c30a.tar.gz
luasocket-6789b83ff5c15296267f880d3b98cf8a1800c30a.tar.bz2
luasocket-6789b83ff5c15296267f880d3b98cf8a1800c30a.zip
Starting to use RCS in princeton again. Not behind a firewall anymore.
-rw-r--r--LICENSE20
-rw-r--r--TODO23
-rw-r--r--src/ftp.lua19
-rw-r--r--src/http.lua40
-rw-r--r--src/luasocket.c2
-rw-r--r--test/ftptest.lua14
6 files changed, 58 insertions, 60 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..2dfc82b
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,20 @@
1LuaSocket 2.0 license
2Copyright © 2003 Tecgraf, PUC-Rio.
3
4Permission is hereby granted, free of charge, to any person obtaining a
5copy of this software and associated documentation files (the "Software"),
6to deal in the Software without restriction, including without limitation
7the rights to use, copy, modify, merge, publish, distribute, sublicense,
8and/or sell copies of the Software, and to permit persons to whom the
9Software is furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20DEALINGS IN THE SOFTWARE.
diff --git a/TODO b/TODO
index d36f6ea..35a5225 100644
--- a/TODO
+++ b/TODO
@@ -1,24 +1,8 @@
1URL e URI eh a mesma coisa?
2
3Check spelling
4Fazer uma página com os exemplos.
5Ajeitar links pras RFCs.
6Usar DFN no lugar de <i> pra definiccoes.
7Usar VAR pra argumentos?
8Usar CODE pros trechos? funciona como PRE?
9Usar PRE { margin-botton: 1em; } pra pular linha antes do </pre>
10Trocar todos os <a name=bla> por <... id=bla>?
11Make sure all .html are STRICT 4.01
12Add license.txt.
13Check RFC links.
14Add lots of hyperlinks
15Check all function names (must use . or :)
16Make sure IPv4 goes away
17The words function and method should follow the convention
18Adjust dates in all files 1Adjust dates in all files
2
19Test the library on every system possible 3Test the library on every system possible
4
20Document socket.time and socket.sleep 5Document socket.time and socket.sleep
21Create the windows executable.
22 6
23Implement time critical stuff from code module in C. 7Implement time critical stuff from code module in C.
24Add service name translation. 8Add service name translation.
@@ -26,7 +10,6 @@ Add service name translation.
26Ajeitar o protocolo da lua_socketlibopen()... 10Ajeitar o protocolo da lua_socketlibopen()...
27 11
28- testar os options! 12- testar os options!
29- testar em várias plataformas
30- adicionar exemplos de expansão: pipe, local, named pipe 13- adicionar exemplos de expansão: pipe, local, named pipe
31 14
32* O location do "redirect" pode ser relativo ao servidor atual (não pode, 15* O location do "redirect" pode ser relativo ao servidor atual (não pode,
@@ -47,7 +30,6 @@ Ajeitar o protocolo da lua_socketlibopen()...
47- checar operações em closed sockets 30- checar operações em closed sockets
48- checar teste de writable socket com select 31- checar teste de writable socket com select
49 32
50- trocar IPv4 para networking ou ipc
51 33
52- checar todos os metodos 34- checar todos os metodos
53- checar options em UDP 35- checar options em UDP
@@ -58,4 +40,3 @@ Ajeitar o protocolo da lua_socketlibopen()...
58- unix 92 bytes maximo no endereço, incluindo o zero 40- unix 92 bytes maximo no endereço, incluindo o zero
59- unix 9216 maximo de datagram size 41- unix 9216 maximo de datagram size
60 42
61
diff --git a/src/ftp.lua b/src/ftp.lua
index 25226a6..bfc4ece 100644
--- a/src/ftp.lua
+++ b/src/ftp.lua
@@ -602,10 +602,12 @@ function Public.put_cb(request)
602 local control, err = Private.open(parsed) 602 local control, err = Private.open(parsed)
603 if not control then return err end 603 if not control then return err end
604 local segment = Private.parse_path(parsed) 604 local segment = Private.parse_path(parsed)
605 return Private.change_dir(control, segment) or 605 err = Private.change_dir(control, segment) or
606 Private.change_type(control, parsed.params) or 606 Private.change_type(control, parsed.params) or
607 Private.upload(control, request, segment) or 607 Private.upload(control, request, segment) or
608 Private.close(control) 608 Private.close(control)
609 if err then return nil, err
610 else return 1 end
609end 611end
610 612
611----------------------------------------------------------------------------- 613-----------------------------------------------------------------------------
@@ -616,15 +618,15 @@ end
616-- type: "i" for "image" mode, "a" for "ascii" mode or "d" for directory 618-- type: "i" for "image" mode, "a" for "ascii" mode or "d" for directory
617-- user: account user name 619-- user: account user name
618-- password: account password) 620-- password: account password)
621-- content: file contents
619-- content: file contents 622-- content: file contents
620-- Returns 623-- Returns
621-- err: error message if any 624-- err: error message if any
622----------------------------------------------------------------------------- 625-----------------------------------------------------------------------------
623function Public.put(url_or_request, content) 626function Public.put(url_or_request, content)
624 local request = Private.build_request(url_or_request) 627 local request = Private.build_request(url_or_request)
625 request.content_cb = function() 628 request.content = request.content or content
626 return content, string.len(content) 629 request.content_cb = socket.callback.send_string(request.content)
627 end
628 return Public.put_cb(request) 630 return Public.put_cb(request)
629end 631end
630 632
@@ -641,12 +643,9 @@ end
641-- err: error message in case of error, nil otherwise 643-- err: error message in case of error, nil otherwise
642----------------------------------------------------------------------------- 644-----------------------------------------------------------------------------
643function Public.get(url_or_request) 645function Public.get(url_or_request)
644 local cat = socket.concat.create() 646 local concat = socket.concat.create()
645 local request = Private.build_request(url_or_request) 647 local request = Private.build_request(url_or_request)
646 request.content_cb = function(chunk, err) 648 request.content_cb = socket.callback.receive_concat(concat)
647 if chunk then cat:addstring(chunk) end
648 return 1
649 end
650 local err = Public.get_cb(request) 649 local err = Public.get_cb(request)
651 return cat:getresult(), err 650 return concat:getresult(), err
652end 651end
diff --git a/src/http.lua b/src/http.lua
index 212e8f6..252285a 100644
--- a/src/http.lua
+++ b/src/http.lua
@@ -338,16 +338,16 @@ function Private.send_request(sock, method, uri, headers, body_cb)
338 err = Private.try_send(sock, method .. " " .. uri .. " HTTP/1.1\r\n") 338 err = Private.try_send(sock, method .. " " .. uri .. " HTTP/1.1\r\n")
339 if err then return err end 339 if err then return err end
340 -- if there is a request message body, add content-length header 340 -- if there is a request message body, add content-length header
341 if body_cb then 341 chunk, size = body_cb()
342 chunk, size = body_cb() 342 if type(chunk) == "string" and type(size) == "number" then
343 if type(chunk) == "string" and type(size) == "number" then 343 if size > 0 then
344 headers["content-length"] = tostring(size) 344 headers["content-length"] = tostring(size)
345 else 345 end
346 sock:close() 346 else
347 if not chunk and type(size) == "string" then return size 347 sock:close()
348 else return "invalid callback return" end 348 if not chunk and type(size) == "string" then return size
349 end 349 else return "invalid callback return" end
350 end 350 end
351 -- send request headers 351 -- send request headers
352 err = Private.send_headers(sock, headers) 352 err = Private.send_headers(sock, headers)
353 if err then return err end 353 if err then return err end
@@ -505,7 +505,10 @@ end
505----------------------------------------------------------------------------- 505-----------------------------------------------------------------------------
506function Private.build_request(data) 506function Private.build_request(data)
507 local request = {} 507 local request = {}
508 if type(data) == "table" then for i, v in data do request[i] = v end 508 if type(data) == "table" then
509 for i, v in data
510 do request[i] = v
511 end
509 else request.url = data end 512 else request.url = data end
510 return request 513 return request
511end 514end
@@ -613,18 +616,11 @@ end
613----------------------------------------------------------------------------- 616-----------------------------------------------------------------------------
614function Public.request(request) 617function Public.request(request)
615 local response = {} 618 local response = {}
616 if request.body then 619 request.body_cb = socket.callback.send_string(request.body)
617 request.body_cb = function() 620 local concat = socket.concat.create()
618 return request.body, string.len(request.body) 621 response.body_cb = socket.callback.receive_concat(concat)
619 end
620 end
621 local cat = socket.concat.create()
622 response.body_cb = function(chunk, err)
623 if chunk then cat:addstring(chunk) end
624 return 1
625 end
626 response = Public.request_cb(request, response) 622 response = Public.request_cb(request, response)
627 response.body = cat:getresult() 623 response.body = concat:getresult()
628 response.body_cb = nil 624 response.body_cb = nil
629 return response 625 return response
630end 626end
diff --git a/src/luasocket.c b/src/luasocket.c
index 96deac1..9be5595 100644
--- a/src/luasocket.c
+++ b/src/luasocket.c
@@ -56,6 +56,7 @@ LUASOCKET_API int luaopen_socket(lua_State *L)
56#include "concat.lch" 56#include "concat.lch"
57#include "code.lch" 57#include "code.lch"
58#include "url.lch" 58#include "url.lch"
59#include "callback.lch"
59#include "smtp.lch" 60#include "smtp.lch"
60#include "ftp.lch" 61#include "ftp.lch"
61#include "http.lch" 62#include "http.lch"
@@ -64,6 +65,7 @@ LUASOCKET_API int luaopen_socket(lua_State *L)
64 lua_dofile(L, "concat.lua"); 65 lua_dofile(L, "concat.lua");
65 lua_dofile(L, "code.lua"); 66 lua_dofile(L, "code.lua");
66 lua_dofile(L, "url.lua"); 67 lua_dofile(L, "url.lua");
68 lua_dofile(L, "callback.lua");
67 lua_dofile(L, "smtp.lua"); 69 lua_dofile(L, "smtp.lua");
68 lua_dofile(L, "ftp.lua"); 70 lua_dofile(L, "ftp.lua");
69 lua_dofile(L, "http.lua"); 71 lua_dofile(L, "http.lua");
diff --git a/test/ftptest.lua b/test/ftptest.lua
index 6ba61a4..37e3edc 100644
--- a/test/ftptest.lua
+++ b/test/ftptest.lua
@@ -47,9 +47,9 @@ check(not back and err == e, err)
47 47
48io.write("testing anonymous file upload: ") 48io.write("testing anonymous file upload: ")
49os.remove("/var/ftp/pub/index.up.html") 49os.remove("/var/ftp/pub/index.up.html")
50err = socket.ftp.put("ftp://localhost/pub/index.up.html;type=i", index) 50ret, err = socket.ftp.put("ftp://localhost/pub/index.up.html;type=i", index)
51saved = readfile("/var/ftp/pub/index.up.html") 51saved = readfile("/var/ftp/pub/index.up.html")
52check(not err and saved == index, err) 52check(ret and not err and saved == index, err)
53 53
54io.write("testing anonymous file download: ") 54io.write("testing anonymous file download: ")
55back, err = socket.ftp.get("ftp://localhost/pub/index.up.html;type=i") 55back, err = socket.ftp.get("ftp://localhost/pub/index.up.html;type=i")
@@ -65,9 +65,9 @@ check(not err and back == index, err)
65 65
66io.write("testing authenticated upload: ") 66io.write("testing authenticated upload: ")
67os.remove("/home/luasocket/index.up.html") 67os.remove("/home/luasocket/index.up.html")
68err = socket.ftp.put("ftp://luasocket:password@localhost/index.up.html;type=i", index) 68ret, err = socket.ftp.put("ftp://luasocket:password@localhost/index.up.html;type=i", index)
69saved = readfile("/home/luasocket/index.up.html") 69saved = readfile("/home/luasocket/index.up.html")
70check(not err and saved == index, err) 70check(ret and not err and saved == index, err)
71 71
72io.write("testing authenticated download: ") 72io.write("testing authenticated download: ")
73back, err = socket.ftp.get("ftp://luasocket:password@localhost/index.up.html;type=i") 73back, err = socket.ftp.get("ftp://luasocket:password@localhost/index.up.html;type=i")
@@ -97,13 +97,13 @@ back, err = socket.ftp.get("ftp://localhost/pub;type=d")
97check(similar(back, expected)) 97check(similar(back, expected))
98 98
99io.write("testing upload denial: ") 99io.write("testing upload denial: ")
100err = socket.ftp.put("ftp://localhost/index.up.html;type=a", index) 100ret, err = socket.ftp.put("ftp://localhost/index.up.html;type=a", index)
101check(err, err) 101check(err, err)
102 102
103io.write("testing authentication failure: ") 103io.write("testing authentication failure: ")
104err = socket.ftp.put("ftp://luasocket:wrong@localhost/index.html;type=a", index) 104ret, err = socket.ftp.put("ftp://luasocket:wrong@localhost/index.html;type=a", index)
105print(err) 105print(err)
106check(err, err) 106check(not ret and err, err)
107 107
108io.write("testing wrong file: ") 108io.write("testing wrong file: ")
109back, err = socket.ftp.get("ftp://localhost/index.wrong.html;type=a") 109back, err = socket.ftp.get("ftp://localhost/index.wrong.html;type=a")