diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-08-31 00:58:07 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-08-31 00:58:07 +0000 |
commit | 6789b83ff5c15296267f880d3b98cf8a1800c30a (patch) | |
tree | 9571dc81cb0147218332cda34b7ccdfed37ddbbc | |
parent | c51d4acf1c2a8675a3bb043e799ff4390cef47d6 (diff) | |
download | luasocket-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-- | LICENSE | 20 | ||||
-rw-r--r-- | TODO | 23 | ||||
-rw-r--r-- | src/ftp.lua | 19 | ||||
-rw-r--r-- | src/http.lua | 40 | ||||
-rw-r--r-- | src/luasocket.c | 2 | ||||
-rw-r--r-- | test/ftptest.lua | 14 |
6 files changed, 58 insertions, 60 deletions
@@ -0,0 +1,20 @@ | |||
1 | LuaSocket 2.0 license | ||
2 | Copyright © 2003 Tecgraf, PUC-Rio. | ||
3 | |||
4 | Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | copy of this software and associated documentation files (the "Software"), | ||
6 | to deal in the Software without restriction, including without limitation | ||
7 | the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | and/or sell copies of the Software, and to permit persons to whom the | ||
9 | Software is furnished to do so, subject to the following conditions: | ||
10 | |||
11 | The above copyright notice and this permission notice shall be included in | ||
12 | all copies or substantial portions of the Software. | ||
13 | |||
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | DEALINGS IN THE SOFTWARE. | ||
@@ -1,24 +1,8 @@ | |||
1 | URL e URI eh a mesma coisa? | ||
2 | |||
3 | Check spelling | ||
4 | Fazer uma página com os exemplos. | ||
5 | Ajeitar links pras RFCs. | ||
6 | Usar DFN no lugar de <i> pra definiccoes. | ||
7 | Usar VAR pra argumentos? | ||
8 | Usar CODE pros trechos? funciona como PRE? | ||
9 | Usar PRE { margin-botton: 1em; } pra pular linha antes do </pre> | ||
10 | Trocar todos os <a name=bla> por <... id=bla>? | ||
11 | Make sure all .html are STRICT 4.01 | ||
12 | Add license.txt. | ||
13 | Check RFC links. | ||
14 | Add lots of hyperlinks | ||
15 | Check all function names (must use . or :) | ||
16 | Make sure IPv4 goes away | ||
17 | The words function and method should follow the convention | ||
18 | Adjust dates in all files | 1 | Adjust dates in all files |
2 | |||
19 | Test the library on every system possible | 3 | Test the library on every system possible |
4 | |||
20 | Document socket.time and socket.sleep | 5 | Document socket.time and socket.sleep |
21 | Create the windows executable. | ||
22 | 6 | ||
23 | Implement time critical stuff from code module in C. | 7 | Implement time critical stuff from code module in C. |
24 | Add service name translation. | 8 | Add service name translation. |
@@ -26,7 +10,6 @@ Add service name translation. | |||
26 | Ajeitar o protocolo da lua_socketlibopen()... | 10 | Ajeitar 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 | ||
609 | end | 611 | end |
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 | ----------------------------------------------------------------------------- |
623 | function Public.put(url_or_request, content) | 626 | function 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) |
629 | end | 631 | end |
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 | ----------------------------------------------------------------------------- |
643 | function Public.get(url_or_request) | 645 | function 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 |
652 | end | 651 | end |
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 | ----------------------------------------------------------------------------- |
506 | function Private.build_request(data) | 506 | function 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 |
511 | end | 514 | end |
@@ -613,18 +616,11 @@ end | |||
613 | ----------------------------------------------------------------------------- | 616 | ----------------------------------------------------------------------------- |
614 | function Public.request(request) | 617 | function 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 |
630 | end | 626 | end |
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 | ||
48 | io.write("testing anonymous file upload: ") | 48 | io.write("testing anonymous file upload: ") |
49 | os.remove("/var/ftp/pub/index.up.html") | 49 | os.remove("/var/ftp/pub/index.up.html") |
50 | err = socket.ftp.put("ftp://localhost/pub/index.up.html;type=i", index) | 50 | ret, err = socket.ftp.put("ftp://localhost/pub/index.up.html;type=i", index) |
51 | saved = readfile("/var/ftp/pub/index.up.html") | 51 | saved = readfile("/var/ftp/pub/index.up.html") |
52 | check(not err and saved == index, err) | 52 | check(ret and not err and saved == index, err) |
53 | 53 | ||
54 | io.write("testing anonymous file download: ") | 54 | io.write("testing anonymous file download: ") |
55 | back, err = socket.ftp.get("ftp://localhost/pub/index.up.html;type=i") | 55 | back, 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 | ||
66 | io.write("testing authenticated upload: ") | 66 | io.write("testing authenticated upload: ") |
67 | os.remove("/home/luasocket/index.up.html") | 67 | os.remove("/home/luasocket/index.up.html") |
68 | err = socket.ftp.put("ftp://luasocket:password@localhost/index.up.html;type=i", index) | 68 | ret, err = socket.ftp.put("ftp://luasocket:password@localhost/index.up.html;type=i", index) |
69 | saved = readfile("/home/luasocket/index.up.html") | 69 | saved = readfile("/home/luasocket/index.up.html") |
70 | check(not err and saved == index, err) | 70 | check(ret and not err and saved == index, err) |
71 | 71 | ||
72 | io.write("testing authenticated download: ") | 72 | io.write("testing authenticated download: ") |
73 | back, err = socket.ftp.get("ftp://luasocket:password@localhost/index.up.html;type=i") | 73 | back, 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") | |||
97 | check(similar(back, expected)) | 97 | check(similar(back, expected)) |
98 | 98 | ||
99 | io.write("testing upload denial: ") | 99 | io.write("testing upload denial: ") |
100 | err = socket.ftp.put("ftp://localhost/index.up.html;type=a", index) | 100 | ret, err = socket.ftp.put("ftp://localhost/index.up.html;type=a", index) |
101 | check(err, err) | 101 | check(err, err) |
102 | 102 | ||
103 | io.write("testing authentication failure: ") | 103 | io.write("testing authentication failure: ") |
104 | err = socket.ftp.put("ftp://luasocket:wrong@localhost/index.html;type=a", index) | 104 | ret, err = socket.ftp.put("ftp://luasocket:wrong@localhost/index.html;type=a", index) |
105 | print(err) | 105 | print(err) |
106 | check(err, err) | 106 | check(not ret and err, err) |
107 | 107 | ||
108 | io.write("testing wrong file: ") | 108 | io.write("testing wrong file: ") |
109 | back, err = socket.ftp.get("ftp://localhost/index.wrong.html;type=a") | 109 | back, err = socket.ftp.get("ftp://localhost/index.wrong.html;type=a") |