diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-06-16 01:02:07 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-06-16 01:02:07 +0000 |
commit | d46f7a09a768b146f2f3cdc9a6a50357832bd1c7 (patch) | |
tree | d4f7ca1e677d06446245691d5ece6dab51915f16 | |
parent | 843a431ef98fd541d98fd3898463985d9bfcde28 (diff) | |
download | luasocket-d46f7a09a768b146f2f3cdc9a6a50357832bd1c7.tar.gz luasocket-d46f7a09a768b146f2f3cdc9a6a50357832bd1c7.tar.bz2 luasocket-d46f7a09a768b146f2f3cdc9a6a50357832bd1c7.zip |
Fixed smtp.lua loading.
Adjusted tftp module.
Added some comments.
-rw-r--r-- | TODO | 76 | ||||
-rw-r--r-- | etc/tftp.lua | 134 | ||||
-rw-r--r-- | samples/cddb.lua | 2 | ||||
-rw-r--r-- | src/except.c | 10 | ||||
-rw-r--r-- | src/ftp.lua | 3 | ||||
-rw-r--r-- | src/http.lua | 7 | ||||
-rw-r--r-- | src/ltn12.lua | 2 | ||||
-rw-r--r-- | src/mime.c | 4 | ||||
-rw-r--r-- | src/mime.h | 2 | ||||
-rw-r--r-- | src/mime.lua | 2 | ||||
-rw-r--r-- | src/options.c | 10 | ||||
-rw-r--r-- | src/options.h | 9 | ||||
-rw-r--r-- | src/select.h | 11 | ||||
-rw-r--r-- | src/smtp.lua | 6 | ||||
-rw-r--r-- | src/socket.lua | 2 | ||||
-rw-r--r-- | src/tp.lua | 4 | ||||
-rw-r--r-- | src/url.lua | 3 | ||||
-rw-r--r-- | test/stufftest.lua | 6 | ||||
-rw-r--r-- | test/testmesg.lua | 4 | ||||
-rw-r--r-- | test/tftptest.lua | 4 |
20 files changed, 162 insertions, 139 deletions
@@ -1,52 +1,31 @@ | |||
1 | ajeitar os README.* | 1 | ajeitar os README.* |
2 | ajeitar select. upvalue nao tem nada a ver... | ||
3 | make sure filter.chain fails gracefully. | ||
4 | ajeitar o manual sobre select, mais liberal agora | ||
5 | falar sobre o novo esquema de namespace | ||
6 | tirar socket.url socket.ftp etc do manual. agora os namespaces estao | ||
7 | liberados. | ||
8 | ajeitar as referencias a RFCS e LTNS em todos os arquivos. | 2 | ajeitar as referencias a RFCS e LTNS em todos os arquivos. |
9 | proxy no ftp | ||
10 | ajeitar < e-mail > no smtp? | ||
11 | ajeitar referencias a LTN12 nos manuais | ||
12 | 3 | ||
13 | make sure sockets are closed when exceptions are raised | 4 | make sure sockets are closed when exceptions are raised |
14 | 5 | ||
15 | falar sobre encodet/wrapt/decodet no manual sobre mime | ||
16 | |||
17 | RECEIVE MUDOU!!! (partial stuff) COLOCAR NO MANUAL. | ||
18 | HTTP.lua mudou bastante também. | ||
19 | pump.step usado em todo mundo que recebe source ou sink | ||
20 | |||
21 | sources ans sinks are always simple in http and ftp and smtp | ||
22 | expose encode/decode tables to provide extensibility for mime module | ||
23 | use coroutines instead of fancy filters | ||
24 | |||
25 | check garbage collection in test*.lua | 6 | check garbage collection in test*.lua |
26 | 7 | ||
27 | add socket.TIMEOUT to be default timeout? | ||
28 | 8 | ||
29 | manual | 9 | manual |
30 | compatibility: select sets are associative | 10 | * compatibility: select sets are associative |
31 | add socket.connect and socket.bind to the manual | 11 | * add socket.connect and socket.bind to the manual |
32 | say what a nil callback does for http | 12 | * add shutdown |
13 | * add gethostname | ||
33 | check all occurences of it's | 14 | check all occurences of it's |
34 | - add shutdown | 15 | * the need of a content-length header in the post method... |
35 | - add gethostname | 16 | * notice the change in callback conventions |
36 | the need of a content-length header in the post method... | 17 | * the callback.lua module and the new mime module. |
37 | notice the change in callback conventions | 18 | * escape and unescape in url, not in code! |
38 | the callback.lua module and the new mime module. | 19 | * add timeout and proxy to request table |
39 | escape and unescape in url, not in code! | 20 | * change stay to redirect |
40 | add timeout and proxy to request table | 21 | * socket.time and socket.sleep |
41 | change stay to redirect | 22 | * - connect with timeout |
42 | socket.time and socket.sleep | ||
43 | - connect with timeout | ||
44 | local connect | 23 | local connect |
45 | add thanks to 'carlos cassino' and 'david burgess' | 24 | * add thanks to 'carlos cassino' and 'david burgess' |
46 | add new ip- options and reuseaddr option | 25 | * add new ip- options and reuseaddr option |
47 | - add listen to manual | 26 | * - add listen to manual |
48 | bind method doesn't do listen anymore | 27 | * bind method doesn't do listen anymore |
49 | bind doesn't turn an object into a server object: listen does. | 28 | * bind doesn't turn an object into a server object: listen does. |
50 | 29 | ||
51 | tests | 30 | tests |
52 | checar todos os metodos | 31 | checar todos os metodos |
@@ -59,9 +38,6 @@ wrp can't break lines in the middle of a line break. | |||
59 | add comments into each C module. | 38 | add comments into each C module. |
60 | testar os options! | 39 | testar os options! |
61 | 40 | ||
62 | use gethostname it in SMTP | ||
63 | |||
64 | make sure modules know if their dependencies are there. | ||
65 | 41 | ||
66 | Read about | 42 | Read about |
67 | 250-ENHANCEDSTATUSCODES | 43 | 250-ENHANCEDSTATUSCODES |
@@ -108,6 +84,12 @@ Ajeitar o protocolo da luaopen_socket()... sei lá qual é. | |||
108 | these are done | 84 | these are done |
109 | -------------- | 85 | -------------- |
110 | 86 | ||
87 | * tirar socket.url socket.ftp etc do manual. agora os namespaces | ||
88 | estao liberados. | ||
89 | * falar sobre o novo esquema de namespace | ||
90 | * ajeitar o manual sobre select, mais liberal agora | ||
91 | * make sure filter.chain fails gracefully. | ||
92 | * ajeitar select. upvalue nao tem nada a ver... | ||
111 | * should be interrupt-safe | 93 | * should be interrupt-safe |
112 | * notice the change in callback conventions | 94 | * notice the change in callback conventions |
113 | * new mime module replacing old code module (faster, more functionality) | 95 | * new mime module replacing old code module (faster, more functionality) |
@@ -161,3 +143,15 @@ these are done | |||
161 | * change all modules to use the new namespace scheme | 143 | * change all modules to use the new namespace scheme |
162 | * write some utilities that use the code.lua module and put them | 144 | * write some utilities that use the code.lua module and put them |
163 | * in etc, modify the README.etc file and makefile.dist (eol.lua is done) | 145 | * in etc, modify the README.etc file and makefile.dist (eol.lua is done) |
146 | * proxy no ftp? no | ||
147 | * ajeitar < e-mail > no smtp? no | ||
148 | * ajeitar referencias a LTN12 nos manuais | ||
149 | * RECEIVE MUDOU!!! (partial stuff) COLOCAR NO MANUAL. | ||
150 | * HTTP.lua mudou bastante também. | ||
151 | * falar sobre encodet/wrapt/decodet no manual sobre mime? no. | ||
152 | * pump.step usado em todo mundo que recebe source ou sink | ||
153 | * sources ans sinks are always simple in http and ftp and smtp | ||
154 | * expose encode/decode tables to provide extensibility for mime module | ||
155 | * use coroutines instead of fancy filters | ||
156 | * add socket.TIMEOUT to be default timeout? no. | ||
157 | * use gethostname it in SMTP | ||
diff --git a/etc/tftp.lua b/etc/tftp.lua index 4113034..5238de0 100644 --- a/etc/tftp.lua +++ b/etc/tftp.lua | |||
@@ -2,13 +2,20 @@ | |||
2 | -- TFTP support for the Lua language | 2 | -- TFTP support for the Lua language |
3 | -- LuaSocket toolkit. | 3 | -- LuaSocket toolkit. |
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- Conforming to: RFC 783, LTN7 | ||
6 | -- RCS ID: $Id$ | 5 | -- RCS ID: $Id$ |
7 | ----------------------------------------------------------------------------- | 6 | ----------------------------------------------------------------------------- |
8 | 7 | ||
9 | local Public, Private = {}, {} | 8 | ----------------------------------------------------------------------------- |
10 | local socket = _G[LUASOCKET_LIBNAME] -- get LuaSocket namespace | 9 | -- Load required files |
11 | socket.tftp = Public -- create tftp sub namespace | 10 | ----------------------------------------------------------------------------- |
11 | local socket = require("socket") | ||
12 | local ltn12 = require("ltn12") | ||
13 | local url = require("url") | ||
14 | |||
15 | ----------------------------------------------------------------------------- | ||
16 | -- Setup namespace | ||
17 | ----------------------------------------------------------------------------- | ||
18 | _LOADED["tftp"] = getfenv(1) | ||
12 | 19 | ||
13 | ----------------------------------------------------------------------------- | 20 | ----------------------------------------------------------------------------- |
14 | -- Program constants | 21 | -- Program constants |
@@ -16,33 +23,33 @@ socket.tftp = Public -- create tftp sub namespace | |||
16 | local char = string.char | 23 | local char = string.char |
17 | local byte = string.byte | 24 | local byte = string.byte |
18 | 25 | ||
19 | Public.PORT = 69 | 26 | PORT = 69 |
20 | Private.OP_RRQ = 1 | 27 | local OP_RRQ = 1 |
21 | Private.OP_WRQ = 2 | 28 | local OP_WRQ = 2 |
22 | Private.OP_DATA = 3 | 29 | local OP_DATA = 3 |
23 | Private.OP_ACK = 4 | 30 | local OP_ACK = 4 |
24 | Private.OP_ERROR = 5 | 31 | local OP_ERROR = 5 |
25 | Private.OP_INV = {"RRQ", "WRQ", "DATA", "ACK", "ERROR"} | 32 | local OP_INV = {"RRQ", "WRQ", "DATA", "ACK", "ERROR"} |
26 | 33 | ||
27 | ----------------------------------------------------------------------------- | 34 | ----------------------------------------------------------------------------- |
28 | -- Packet creation functions | 35 | -- Packet creation functions |
29 | ----------------------------------------------------------------------------- | 36 | ----------------------------------------------------------------------------- |
30 | function Private.RRQ(source, mode) | 37 | local function RRQ(source, mode) |
31 | return char(0, Private.OP_RRQ) .. source .. char(0) .. mode .. char(0) | 38 | return char(0, OP_RRQ) .. source .. char(0) .. mode .. char(0) |
32 | end | 39 | end |
33 | 40 | ||
34 | function Private.WRQ(source, mode) | 41 | local function WRQ(source, mode) |
35 | return char(0, Private.OP_RRQ) .. source .. char(0) .. mode .. char(0) | 42 | return char(0, OP_RRQ) .. source .. char(0) .. mode .. char(0) |
36 | end | 43 | end |
37 | 44 | ||
38 | function Private.ACK(block) | 45 | local function ACK(block) |
39 | local low, high | 46 | local low, high |
40 | low = math.mod(block, 256) | 47 | low = math.mod(block, 256) |
41 | high = (block - low)/256 | 48 | high = (block - low)/256 |
42 | return char(0, Private.OP_ACK, high, low) | 49 | return char(0, OP_ACK, high, low) |
43 | end | 50 | end |
44 | 51 | ||
45 | function Private.get_OP(dgram) | 52 | local function get_OP(dgram) |
46 | local op = byte(dgram, 1)*256 + byte(dgram, 2) | 53 | local op = byte(dgram, 1)*256 + byte(dgram, 2) |
47 | return op | 54 | return op |
48 | end | 55 | end |
@@ -50,13 +57,13 @@ end | |||
50 | ----------------------------------------------------------------------------- | 57 | ----------------------------------------------------------------------------- |
51 | -- Packet analysis functions | 58 | -- Packet analysis functions |
52 | ----------------------------------------------------------------------------- | 59 | ----------------------------------------------------------------------------- |
53 | function Private.split_DATA(dgram) | 60 | local function split_DATA(dgram) |
54 | local block = byte(dgram, 3)*256 + byte(dgram, 4) | 61 | local block = byte(dgram, 3)*256 + byte(dgram, 4) |
55 | local data = string.sub(dgram, 5) | 62 | local data = string.sub(dgram, 5) |
56 | return block, data | 63 | return block, data |
57 | end | 64 | end |
58 | 65 | ||
59 | function Private.get_ERROR(dgram) | 66 | local function get_ERROR(dgram) |
60 | local code = byte(dgram, 3)*256 + byte(dgram, 4) | 67 | local code = byte(dgram, 3)*256 + byte(dgram, 4) |
61 | local msg | 68 | local msg |
62 | _,_, msg = string.find(dgram, "(.*)\000", 5) | 69 | _,_, msg = string.find(dgram, "(.*)\000", 5) |
@@ -64,68 +71,81 @@ function Private.get_ERROR(dgram) | |||
64 | end | 71 | end |
65 | 72 | ||
66 | ----------------------------------------------------------------------------- | 73 | ----------------------------------------------------------------------------- |
67 | -- Downloads and returns a file pointed to by url | 74 | -- High level TFTP API |
68 | ----------------------------------------------------------------------------- | 75 | ----------------------------------------------------------------------------- |
69 | function Public.get(url) | 76 | local function tget(gett) |
70 | local parsed = socket.url.parse(url, { | ||
71 | host = "", | ||
72 | port = Public.PORT, | ||
73 | path ="/", | ||
74 | scheme = "tftp" | ||
75 | }) | ||
76 | if parsed.scheme ~= "tftp" then | ||
77 | return nil, string.format("unknown scheme '%s'", parsed.scheme) | ||
78 | end | ||
79 | local retries, dgram, sent, datahost, dataport, code | 77 | local retries, dgram, sent, datahost, dataport, code |
80 | local cat = socket.concat.create() | ||
81 | local last = 0 | 78 | local last = 0 |
82 | local udp, err = socket.udp() | 79 | local con = socket.try(socket.udp()) |
83 | if not udp then return nil, err end | ||
84 | -- convert from name to ip if needed | 80 | -- convert from name to ip if needed |
85 | parsed.host = socket.dns.toip(parsed.host) | 81 | gett.host = socket.try(socket.dns.toip(gett.host)) |
86 | udp:settimeout(1) | 82 | con:settimeout(1) |
87 | -- first packet gives data host/port to be used for data transfers | 83 | -- first packet gives data host/port to be used for data transfers |
88 | retries = 0 | 84 | retries = 0 |
89 | repeat | 85 | repeat |
90 | sent, err = udp:sendto(Private.RRQ(parsed.path, "octet"), | 86 | sent = socket.try(con:sendto(RRQ(gett.path, "octet"), |
91 | parsed.host, parsed.port) | 87 | gett.host, gett.port)) |
92 | if err then return nil, err end | 88 | dgram, datahost, dataport = con:receivefrom() |
93 | dgram, datahost, dataport = udp:receivefrom() | ||
94 | retries = retries + 1 | 89 | retries = retries + 1 |
95 | until dgram or datahost ~= "timeout" or retries > 5 | 90 | until dgram or datahost ~= "timeout" or retries > 5 |
96 | if not dgram then return nil, datahost end | 91 | socket.try(dgram, datahost) |
97 | -- associate socket with data host/port | 92 | -- associate socket with data host/port |
98 | udp:setpeername(datahost, dataport) | 93 | socket.try(con:setpeername(datahost, dataport)) |
94 | -- default sink | ||
95 | local sink = gett.sink or ltn12.sink.null() | ||
99 | -- process all data packets | 96 | -- process all data packets |
100 | while 1 do | 97 | while 1 do |
101 | -- decode packet | 98 | -- decode packet |
102 | code = Private.get_OP(dgram) | 99 | code = get_OP(dgram) |
103 | if code == Private.OP_ERROR then | 100 | socket.try(code ~= OP_ERROR, get_ERROR(dgram)) |
104 | return nil, Private.get_ERROR(dgram) | 101 | socket.try(code == OP_DATA, "unhandled opcode " .. code) |
105 | end | ||
106 | if code ~= Private.OP_DATA then | ||
107 | return nil, "unhandled opcode " .. code | ||
108 | end | ||
109 | -- get data packet parts | 102 | -- get data packet parts |
110 | local block, data = Private.split_DATA(dgram) | 103 | local block, data = split_DATA(dgram) |
111 | -- if not repeated, write | 104 | -- if not repeated, write |
112 | if block == last+1 then | 105 | if block == last+1 then |
113 | cat:addstring(data) | 106 | socket.try(sink(data)) |
114 | last = block | 107 | last = block |
115 | end | 108 | end |
116 | -- last packet brings less than 512 bytes of data | 109 | -- last packet brings less than 512 bytes of data |
117 | if string.len(data) < 512 then | 110 | if string.len(data) < 512 then |
118 | sent, err = udp:send(Private.ACK(block)) | 111 | socket.try(con:send(ACK(block))) |
119 | return cat:getresult() | 112 | socket.try(con:close()) |
113 | socket.try(sink(nil)) | ||
114 | return 1 | ||
120 | end | 115 | end |
121 | -- get the next packet | 116 | -- get the next packet |
122 | retries = 0 | 117 | retries = 0 |
123 | repeat | 118 | repeat |
124 | sent, err = udp:send(Private.ACK(last)) | 119 | sent = socket.try(con:send(ACK(last))) |
125 | if err then return err end | 120 | dgram, err = con:receive() |
126 | dgram, err = udp:receive() | ||
127 | retries = retries + 1 | 121 | retries = retries + 1 |
128 | until dgram or err ~= "timeout" or retries > 5 | 122 | until dgram or err ~= "timeout" or retries > 5 |
129 | if not dgram then return err end | 123 | socket.try(dgram, err) |
130 | end | 124 | end |
131 | end | 125 | end |
126 | |||
127 | local default = { | ||
128 | port = PORT, | ||
129 | path ="/", | ||
130 | scheme = "tftp" | ||
131 | } | ||
132 | |||
133 | local function parse(u) | ||
134 | local t = socket.try(url.parse(u, default)) | ||
135 | socket.try(t.scheme == "tftp", "invalid scheme '" .. t.scheme .. "'") | ||
136 | socket.try(t.host, "invalid host") | ||
137 | return t | ||
138 | end | ||
139 | |||
140 | local function sget(u) | ||
141 | local gett = parse(u) | ||
142 | local t = {} | ||
143 | gett.sink = ltn12.sink.table(t) | ||
144 | tget(gett) | ||
145 | return table.concat(t) | ||
146 | end | ||
147 | |||
148 | get = socket.protect(function(gett) | ||
149 | if type(gett) == "string" then return sget(gett) | ||
150 | else return tget(gett) end | ||
151 | end) | ||
diff --git a/samples/cddb.lua b/samples/cddb.lua index 0ceba09..aefa04e 100644 --- a/samples/cddb.lua +++ b/samples/cddb.lua | |||
@@ -32,7 +32,7 @@ end | |||
32 | local host = socket.dns.gethostname() | 32 | local host = socket.dns.gethostname() |
33 | local query = "%s?cmd=cddb+read+%s+%s&hello=LuaSocket+%s+LuaSocket+2.0&proto=6" | 33 | local query = "%s?cmd=cddb+read+%s+%s&hello=LuaSocket+%s+LuaSocket+2.0&proto=6" |
34 | local url = string.format(query, server, arg[1], arg[2], host) | 34 | local url = string.format(query, server, arg[1], arg[2], host) |
35 | local body, headers, code, error = http.get(url) | 35 | local body, headers, code = http.get(url) |
36 | 36 | ||
37 | if code == 200 then | 37 | if code == 200 then |
38 | local data, code, error = parse(body) | 38 | local data, code, error = parse(body) |
diff --git a/src/except.c b/src/except.c index c9eb20e..0482e1c 100644 --- a/src/except.c +++ b/src/except.c | |||
@@ -1,12 +1,22 @@ | |||
1 | /*=========================================================================*\ | ||
2 | * Simple exception support | ||
3 | * LuaSocket toolkit | ||
4 | * | ||
5 | * RCS ID: $Id$ | ||
6 | \*=========================================================================*/ | ||
1 | #include <lauxlib.h> | 7 | #include <lauxlib.h> |
2 | #include <stdio.h> | 8 | #include <stdio.h> |
3 | 9 | ||
4 | #include "except.h" | 10 | #include "except.h" |
5 | 11 | ||
12 | /*=========================================================================*\ | ||
13 | * Internal function prototypes. | ||
14 | \*=========================================================================*/ | ||
6 | static int global_try(lua_State *L); | 15 | static int global_try(lua_State *L); |
7 | static int global_protect(lua_State *L); | 16 | static int global_protect(lua_State *L); |
8 | static int protected(lua_State *L); | 17 | static int protected(lua_State *L); |
9 | 18 | ||
19 | /* except functions */ | ||
10 | static luaL_reg func[] = { | 20 | static luaL_reg func[] = { |
11 | {"try", global_try}, | 21 | {"try", global_try}, |
12 | {"protect", global_protect}, | 22 | {"protect", global_protect}, |
diff --git a/src/ftp.lua b/src/ftp.lua index c130d1a..87a1e4e 100644 --- a/src/ftp.lua +++ b/src/ftp.lua | |||
@@ -2,7 +2,6 @@ | |||
2 | -- FTP support for the Lua language | 2 | -- FTP support for the Lua language |
3 | -- LuaSocket toolkit. | 3 | -- LuaSocket toolkit. |
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- Conforming to: RFC 959, LTN7 | ||
6 | -- RCS ID: $Id$ | 5 | -- RCS ID: $Id$ |
7 | ----------------------------------------------------------------------------- | 6 | ----------------------------------------------------------------------------- |
8 | 7 | ||
@@ -244,5 +243,3 @@ get = socket.protect(function(gett) | |||
244 | if type(gett) == "string" then return sget(gett) | 243 | if type(gett) == "string" then return sget(gett) |
245 | else return tget(gett) end | 244 | else return tget(gett) end |
246 | end) | 245 | end) |
247 | |||
248 | return ftp | ||
diff --git a/src/http.lua b/src/http.lua index 129b562..8f3fdb9 100644 --- a/src/http.lua +++ b/src/http.lua | |||
@@ -2,7 +2,6 @@ | |||
2 | -- HTTP/1.1 client support for the Lua language. | 2 | -- HTTP/1.1 client support for the Lua language. |
3 | -- LuaSocket toolkit. | 3 | -- LuaSocket toolkit. |
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- Conforming to RFC 2616 | ||
6 | -- RCS ID: $Id$ | 5 | -- RCS ID: $Id$ |
7 | ----------------------------------------------------------------------------- | 6 | ----------------------------------------------------------------------------- |
8 | 7 | ||
@@ -23,7 +22,7 @@ _LOADED["http"] = getfenv(1) | |||
23 | -- Program constants | 22 | -- Program constants |
24 | ----------------------------------------------------------------------------- | 23 | ----------------------------------------------------------------------------- |
25 | -- connection timeout in seconds | 24 | -- connection timeout in seconds |
26 | TIMEOUT = 4 | 25 | TIMEOUT = 60 |
27 | -- default port for document retrieval | 26 | -- default port for document retrieval |
28 | PORT = 80 | 27 | PORT = 80 |
29 | -- user agent field sent in request | 28 | -- user agent field sent in request |
@@ -146,7 +145,7 @@ end | |||
146 | 145 | ||
147 | local function adjustrequest(reqt) | 146 | local function adjustrequest(reqt) |
148 | -- parse url with default fields | 147 | -- parse url with default fields |
149 | local parsed = url.parse(reqt.url, { | 148 | local parsed = url.parse(reqt.url or "", { |
150 | host = "", | 149 | host = "", |
151 | port = PORT, | 150 | port = PORT, |
152 | path ="/", | 151 | path ="/", |
@@ -258,5 +257,3 @@ post = socket.protect(function(u, body) | |||
258 | return (table.getn(t) > 0 or nil) and table.concat(t), | 257 | return (table.getn(t) > 0 or nil) and table.concat(t), |
259 | respt.headers, respt.code | 258 | respt.headers, respt.code |
260 | end) | 259 | end) |
261 | |||
262 | return http | ||
diff --git a/src/ltn12.lua b/src/ltn12.lua index 6228247..bb527bd 100644 --- a/src/ltn12.lua +++ b/src/ltn12.lua | |||
@@ -254,5 +254,3 @@ function pump.all(src, snk, step) | |||
254 | if not ret then return not err, err end | 254 | if not ret then return not err, err end |
255 | end | 255 | end |
256 | end | 256 | end |
257 | |||
258 | return ltn12 | ||
@@ -1,5 +1,5 @@ | |||
1 | /*=========================================================================*\ | 1 | /*=========================================================================*\ |
2 | * Encoding support functions | 2 | * MIME support functions |
3 | * LuaSocket toolkit | 3 | * LuaSocket toolkit |
4 | * | 4 | * |
5 | * RCS ID: $Id$ | 5 | * RCS ID: $Id$ |
@@ -653,7 +653,7 @@ static int mime_global_eol(lua_State *L) | |||
653 | const char *marker = luaL_optstring(L, 3, CRLF); | 653 | const char *marker = luaL_optstring(L, 3, CRLF); |
654 | luaL_Buffer buffer; | 654 | luaL_Buffer buffer; |
655 | luaL_buffinit(L, &buffer); | 655 | luaL_buffinit(L, &buffer); |
656 | /* if the last character was a candidate, we output a new line */ | 656 | /* end of input blackhole */ |
657 | if (!input) { | 657 | if (!input) { |
658 | lua_pushnil(L); | 658 | lua_pushnil(L); |
659 | lua_pushnumber(L, 0); | 659 | lua_pushnumber(L, 0); |
@@ -1,7 +1,7 @@ | |||
1 | #ifndef MIME_H | 1 | #ifndef MIME_H |
2 | #define MIME_H | 2 | #define MIME_H |
3 | /*=========================================================================*\ | 3 | /*=========================================================================*\ |
4 | * Mime support functions | 4 | * MIME support functions |
5 | * LuaSocket toolkit | 5 | * LuaSocket toolkit |
6 | * | 6 | * |
7 | * This module provides functions to implement transfer content encodings | 7 | * This module provides functions to implement transfer content encodings |
diff --git a/src/mime.lua b/src/mime.lua index 000404f..4fade3b 100644 --- a/src/mime.lua +++ b/src/mime.lua | |||
@@ -73,5 +73,3 @@ wrap = choose(wrapt) | |||
73 | function normalize(marker) | 73 | function normalize(marker) |
74 | return ltn12.filter.cycle(eol, 0, marker) | 74 | return ltn12.filter.cycle(eol, 0, marker) |
75 | end | 75 | end |
76 | |||
77 | return mime | ||
diff --git a/src/options.c b/src/options.c index 972844f..c9e69f0 100644 --- a/src/options.c +++ b/src/options.c | |||
@@ -1,3 +1,9 @@ | |||
1 | /*=========================================================================*\ | ||
2 | * Common option interface | ||
3 | * LuaSocket toolkit | ||
4 | * | ||
5 | * RCS ID: $Id$ | ||
6 | \*=========================================================================*/ | ||
1 | #include <lauxlib.h> | 7 | #include <lauxlib.h> |
2 | #include <string.h> | 8 | #include <string.h> |
3 | 9 | ||
@@ -5,6 +11,10 @@ | |||
5 | #include "options.h" | 11 | #include "options.h" |
6 | #include "inet.h" | 12 | #include "inet.h" |
7 | 13 | ||
14 | |||
15 | /*=========================================================================*\ | ||
16 | * Internal functions prototypes | ||
17 | \*=========================================================================*/ | ||
8 | static int opt_setmembership(lua_State *L, p_sock ps, int level, int name); | 18 | static int opt_setmembership(lua_State *L, p_sock ps, int level, int name); |
9 | static int opt_setboolean(lua_State *L, p_sock ps, int level, int name); | 19 | static int opt_setboolean(lua_State *L, p_sock ps, int level, int name); |
10 | static int opt_set(lua_State *L, p_sock ps, int level, int name, | 20 | static int opt_set(lua_State *L, p_sock ps, int level, int name, |
diff --git a/src/options.h b/src/options.h index ec75fc0..d57bfaa 100644 --- a/src/options.h +++ b/src/options.h | |||
@@ -1,5 +1,14 @@ | |||
1 | #ifndef OPTIONS_H | 1 | #ifndef OPTIONS_H |
2 | #define OPTIONS_H | 2 | #define OPTIONS_H |
3 | /*=========================================================================*\ | ||
4 | * Common option interface | ||
5 | * LuaSocket toolkit | ||
6 | * | ||
7 | * This module provides a common interface to socket options, used mainly by | ||
8 | * modules UDP and TCP. | ||
9 | * | ||
10 | * RCS ID: $Id$ | ||
11 | \*=========================================================================*/ | ||
3 | 12 | ||
4 | #include <lua.h> | 13 | #include <lua.h> |
5 | #include "socket.h" | 14 | #include "socket.h" |
diff --git a/src/select.h b/src/select.h index b58f082..f2d2cc2 100644 --- a/src/select.h +++ b/src/select.h | |||
@@ -4,13 +4,10 @@ | |||
4 | * Select implementation | 4 | * Select implementation |
5 | * LuaSocket toolkit | 5 | * LuaSocket toolkit |
6 | * | 6 | * |
7 | * To make the code as simple as possible, the select function is | 7 | * Each object that can be passed to the select function has to export |
8 | * implemented int Lua, with a few helper functions written in C. | 8 | * method getfd() which returns the descriptor to be passed to the |
9 | * | 9 | * underlying select function. Another method, dirty(), should return |
10 | * Each object that can be passed to the select function has to export two | 10 | * true if there is data ready for reading (required for buffered input). |
11 | * methods: fd() and dirty(). Fd returns the descriptor to be passed to the | ||
12 | * select function. Dirty() should return true if there is data ready for | ||
13 | * reading (required for buffered input). | ||
14 | * | 11 | * |
15 | * RCS ID: $Id$ | 12 | * RCS ID: $Id$ |
16 | \*=========================================================================*/ | 13 | \*=========================================================================*/ |
diff --git a/src/smtp.lua b/src/smtp.lua index dc80c35..fb76ea4 100644 --- a/src/smtp.lua +++ b/src/smtp.lua | |||
@@ -2,14 +2,13 @@ | |||
2 | -- SMTP client support for the Lua language. | 2 | -- SMTP client support for the Lua language. |
3 | -- LuaSocket toolkit. | 3 | -- LuaSocket toolkit. |
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- Conforming to RFC 2821 | ||
6 | -- RCS ID: $Id$ | 5 | -- RCS ID: $Id$ |
7 | ----------------------------------------------------------------------------- | 6 | ----------------------------------------------------------------------------- |
8 | 7 | ||
9 | ----------------------------------------------------------------------------- | 8 | ----------------------------------------------------------------------------- |
10 | -- Load required modules | 9 | -- Load required modules |
11 | ----------------------------------------------------------------------------- | 10 | ----------------------------------------------------------------------------- |
12 | local smtp = requirelib("smtp") | 11 | local smtp = requirelib("smtp", "luaopen_smtp", getfenv(1)) |
13 | local socket = require("socket") | 12 | local socket = require("socket") |
14 | local ltn12 = require("ltn12") | 13 | local ltn12 = require("ltn12") |
15 | local tp = require("tp") | 14 | local tp = require("tp") |
@@ -206,6 +205,7 @@ end | |||
206 | --------------------------------------------------------------------------- | 205 | --------------------------------------------------------------------------- |
207 | -- High level SMTP API | 206 | -- High level SMTP API |
208 | ----------------------------------------------------------------------------- | 207 | ----------------------------------------------------------------------------- |
208 | socket.protect = function(a) return a end | ||
209 | send = socket.protect(function(mailt) | 209 | send = socket.protect(function(mailt) |
210 | local con = open(mailt.server, mailt.port) | 210 | local con = open(mailt.server, mailt.port) |
211 | con:greet(mailt.domain) | 211 | con:greet(mailt.domain) |
@@ -213,5 +213,3 @@ send = socket.protect(function(mailt) | |||
213 | con:quit() | 213 | con:quit() |
214 | return con:close() | 214 | return con:close() |
215 | end) | 215 | end) |
216 | |||
217 | return smtp | ||
diff --git a/src/socket.lua b/src/socket.lua index 9aa6437..f73d167 100644 --- a/src/socket.lua +++ b/src/socket.lua | |||
@@ -166,5 +166,3 @@ end | |||
166 | socket.sourcet["default"] = socket.sourcet["until-closed"] | 166 | socket.sourcet["default"] = socket.sourcet["until-closed"] |
167 | 167 | ||
168 | socket.source = socket.choose(socket.sourcet) | 168 | socket.source = socket.choose(socket.sourcet) |
169 | |||
170 | return socket | ||
@@ -49,7 +49,6 @@ local metat = { __index = {} } | |||
49 | 49 | ||
50 | function metat.__index:check(ok) | 50 | function metat.__index:check(ok) |
51 | local code, reply = get_reply(self.control) | 51 | local code, reply = get_reply(self.control) |
52 | print(reply) | ||
53 | if not code then return nil, reply end | 52 | if not code then return nil, reply end |
54 | if type(ok) ~= "function" then | 53 | if type(ok) ~= "function" then |
55 | if type(ok) == "table" then | 54 | if type(ok) == "table" then |
@@ -65,7 +64,6 @@ print(reply) | |||
65 | end | 64 | end |
66 | 65 | ||
67 | function metat.__index:command(cmd, arg) | 66 | function metat.__index:command(cmd, arg) |
68 | print(cmd, arg) | ||
69 | if arg then return self.control:send(cmd .. " " .. arg.. "\r\n") | 67 | if arg then return self.control:send(cmd .. " " .. arg.. "\r\n") |
70 | else return self.control:send(cmd .. "\r\n") end | 68 | else return self.control:send(cmd .. "\r\n") end |
71 | end | 69 | end |
@@ -113,5 +111,3 @@ connect = socket.protect(function(host, port, timeout) | |||
113 | socket.try(control:connect(host, port)) | 111 | socket.try(control:connect(host, port)) |
114 | return setmetatable({control = control}, metat) | 112 | return setmetatable({control = control}, metat) |
115 | end) | 113 | end) |
116 | |||
117 | return tp | ||
diff --git a/src/url.lua b/src/url.lua index aac2a47..960a248 100644 --- a/src/url.lua +++ b/src/url.lua | |||
@@ -2,7 +2,6 @@ | |||
2 | -- URI parsing, composition and relative URL resolution | 2 | -- URI parsing, composition and relative URL resolution |
3 | -- LuaSocket toolkit. | 3 | -- LuaSocket toolkit. |
4 | -- Author: Diego Nehab | 4 | -- Author: Diego Nehab |
5 | -- Conforming to: RFC 2396, LTN7 | ||
6 | -- RCS ID: $Id$ | 5 | -- RCS ID: $Id$ |
7 | ----------------------------------------------------------------------------- | 6 | ----------------------------------------------------------------------------- |
8 | 7 | ||
@@ -269,5 +268,3 @@ function build_path(parsed, unsafe) | |||
269 | if parsed.is_absolute then path = "/" .. path end | 268 | if parsed.is_absolute then path = "/" .. path end |
270 | return path | 269 | return path |
271 | end | 270 | end |
272 | |||
273 | return url | ||
diff --git a/test/stufftest.lua b/test/stufftest.lua index 5eb8005..6bd1f91 100644 --- a/test/stufftest.lua +++ b/test/stufftest.lua | |||
@@ -1,11 +1,13 @@ | |||
1 | smtp = require("smtp") | ||
2 | |||
1 | function test_dot(original, right) | 3 | function test_dot(original, right) |
2 | local result, n = socket.smtp.dot(2, original) | 4 | local result, n = smtp.dot(2, original) |
3 | assert(result == right, "->" .. result .. "<-") | 5 | assert(result == right, "->" .. result .. "<-") |
4 | print("ok") | 6 | print("ok") |
5 | end | 7 | end |
6 | 8 | ||
7 | function test_stuff(original, right) | 9 | function test_stuff(original, right) |
8 | local result, n = socket.smtp.dot(2, original) | 10 | local result, n = smtp.dot(2, original) |
9 | assert(result == right, "->" .. result .. "<-") | 11 | assert(result == right, "->" .. result .. "<-") |
10 | print("ok") | 12 | print("ok") |
11 | end | 13 | end |
diff --git a/test/testmesg.lua b/test/testmesg.lua index 449f4c2..3e4c28f 100644 --- a/test/testmesg.lua +++ b/test/testmesg.lua | |||
@@ -14,7 +14,7 @@ source = smtp.message{ | |||
14 | }, | 14 | }, |
15 | body = { | 15 | body = { |
16 | preamble = "If your client doesn't understand attachments, \r\n" .. | 16 | preamble = "If your client doesn't understand attachments, \r\n" .. |
17 | "it will still display the preamble and the epilogue.\r\n", | 17 | "it will still display the preamble and the epilogue.\r\n" .. |
18 | "Preamble might show up even in a MIME enabled client.", | 18 | "Preamble might show up even in a MIME enabled client.", |
19 | -- first part: No headers means plain text, us-ascii. | 19 | -- first part: No headers means plain text, us-ascii. |
20 | -- The mime.eol low-level filter normalizes end-of-line markers. | 20 | -- The mime.eol low-level filter normalizes end-of-line markers. |
@@ -55,3 +55,5 @@ r, e = smtp.send{ | |||
55 | source = source, | 55 | source = source, |
56 | server = "mail.cs.princeton.edu" | 56 | server = "mail.cs.princeton.edu" |
57 | } | 57 | } |
58 | |||
59 | print(r, e) | ||
diff --git a/test/tftptest.lua b/test/tftptest.lua index a478ed8..f0dbd82 100644 --- a/test/tftptest.lua +++ b/test/tftptest.lua | |||
@@ -1,5 +1,5 @@ | |||
1 | -- load tftpclnt.lua | 1 | -- load tftpclnt.lua |
2 | dofile("tftp.lua") | 2 | local tftp = require("tftp") |
3 | 3 | ||
4 | -- needs tftp server running on localhost, with root pointing to | 4 | -- needs tftp server running on localhost, with root pointing to |
5 | -- a directory with index.html in it | 5 | -- a directory with index.html in it |
@@ -13,7 +13,7 @@ function readfile(file) | |||
13 | end | 13 | end |
14 | 14 | ||
15 | host = host or "localhost" | 15 | host = host or "localhost" |
16 | retrieved, err = socket.tftp.get("tftp://" .. host .."/index.html") | 16 | retrieved, err = tftp.get("tftp://" .. host .."/index.html") |
17 | assert(not err, err) | 17 | assert(not err, err) |
18 | original = readfile("test/index.html") | 18 | original = readfile("test/index.html") |
19 | assert(original == retrieved, "files differ!") | 19 | assert(original == retrieved, "files differ!") |