diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-06-17 06:23:13 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-06-17 06:23:13 +0000 |
commit | 613534c79526e313d6bfd5ffa514797b364dc185 (patch) | |
tree | c46efc0b1d147258ae0c65a4615e872f1de5edbe | |
parent | 94b97bdc0039c78a213e0a6170f3037eeb00122e (diff) | |
download | luasocket-613534c79526e313d6bfd5ffa514797b364dc185.tar.gz luasocket-613534c79526e313d6bfd5ffa514797b364dc185.tar.bz2 luasocket-613534c79526e313d6bfd5ffa514797b364dc185.zip |
smtp.c was eatten by mime.c
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | doc/mime.html | 29 | ||||
-rw-r--r-- | etc/eol.lua | 6 | ||||
-rw-r--r-- | etc/tftp.lua | 5 | ||||
-rw-r--r-- | src/ftp.lua | 5 | ||||
-rw-r--r-- | src/http.lua | 5 | ||||
-rw-r--r-- | src/ltn12.lua | 5 | ||||
-rw-r--r-- | src/mime.c | 48 | ||||
-rw-r--r-- | src/mime.lua | 10 | ||||
-rw-r--r-- | src/smtp.lua | 13 | ||||
-rw-r--r-- | src/tp.lua | 5 | ||||
-rw-r--r-- | src/url.lua | 5 | ||||
-rw-r--r-- | test/httptest.lua | 2 |
13 files changed, 92 insertions, 48 deletions
@@ -1,6 +1,8 @@ | |||
1 | |||
1 | ajeitar os README.* | 2 | ajeitar os README.* |
2 | ajeitar as referencias a RFCS e LTNS em todos os arquivos. | 3 | ajeitar as referencias a RFCS e LTNS em todos os arquivos. |
3 | 4 | ||
5 | smtp.o goes to mime.dll | ||
4 | make sure sockets are closed when exceptions are raised | 6 | make sure sockets are closed when exceptions are raised |
5 | 7 | ||
6 | check garbage collection in test*.lua | 8 | check garbage collection in test*.lua |
diff --git a/doc/mime.html b/doc/mime.html index e7211fa..fe15df3 100644 --- a/doc/mime.html +++ b/doc/mime.html | |||
@@ -230,6 +230,35 @@ print((mime.b64("diego:password"))) | |||
230 | --> ZGllZ286cGFzc3dvcmQ= | 230 | --> ZGllZ286cGFzc3dvcmQ= |
231 | </pre> | 231 | </pre> |
232 | 232 | ||
233 | <!-- dot +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | ||
234 | <p class=name id="dot"> | ||
235 | A, B = mime.<b>dot(</b>C [, D]<b>)</b> | ||
236 | </p> | ||
237 | |||
238 | <p class=description> | ||
239 | Low-level filter to perform Base64 encoding. | ||
240 | </p> | ||
241 | |||
242 | <p class=description> | ||
243 | <tt>A</tt> is the encoded version of the largest prefix of | ||
244 | <tt>C..D</tt> | ||
245 | that can be encoded unambiguously. <tt>B</tt> has the remaining bytes of | ||
246 | <tt>C..D</tt>, <em>before</em> encoding. | ||
247 | If <tt>D</tt> is <tt><b>nil</b></tt>, <tt>A</tt> is padded with | ||
248 | the encoding of the remaining bytes of <tt>C</tt>. | ||
249 | </p> | ||
250 | |||
251 | <p class=note> | ||
252 | Note: The simplest use of this function is to encode a string into it's | ||
253 | Base64 transfer content encoding. Notice the extra parenthesis around the | ||
254 | call to <tt>mime.b64</tt>, to discard the second return value. | ||
255 | </p> | ||
256 | |||
257 | <pre class=example> | ||
258 | print((mime.b64("diego:password"))) | ||
259 | --> ZGllZ286cGFzc3dvcmQ= | ||
260 | </pre> | ||
261 | |||
233 | <!-- eol ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> | 262 | <!-- eol ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ --> |
234 | 263 | ||
235 | <p class=name id="eol"> | 264 | <p class=name id="eol"> |
diff --git a/etc/eol.lua b/etc/eol.lua index d3da776..01dba67 100644 --- a/etc/eol.lua +++ b/etc/eol.lua | |||
@@ -1,3 +1,9 @@ | |||
1 | ----------------------------------------------------------------------------- | ||
2 | -- Little program to adjust end of line markers. | ||
3 | -- LuaSocket sample files | ||
4 | -- Author: Diego Nehab | ||
5 | -- RCS ID: $Id$ | ||
6 | ----------------------------------------------------------------------------- | ||
1 | local mime = require("mime") | 7 | local mime = require("mime") |
2 | local ltn12 = require("ltn12") | 8 | local ltn12 = require("ltn12") |
3 | local marker = '\n' | 9 | local marker = '\n' |
diff --git a/etc/tftp.lua b/etc/tftp.lua index 6a1a093..2fc914e 100644 --- a/etc/tftp.lua +++ b/etc/tftp.lua | |||
@@ -13,11 +13,6 @@ local ltn12 = require("ltn12") | |||
13 | local url = require("url") | 13 | local url = require("url") |
14 | 14 | ||
15 | ----------------------------------------------------------------------------- | 15 | ----------------------------------------------------------------------------- |
16 | -- Setup namespace | ||
17 | ----------------------------------------------------------------------------- | ||
18 | _LOADED["tftp"] = getfenv(1) | ||
19 | |||
20 | ----------------------------------------------------------------------------- | ||
21 | -- Program constants | 16 | -- Program constants |
22 | ----------------------------------------------------------------------------- | 17 | ----------------------------------------------------------------------------- |
23 | local char = string.char | 18 | local char = string.char |
diff --git a/src/ftp.lua b/src/ftp.lua index 87a1e4e..f3b8a5e 100644 --- a/src/ftp.lua +++ b/src/ftp.lua | |||
@@ -14,11 +14,6 @@ local url = require("url") | |||
14 | local tp = require("tp") | 14 | local tp = require("tp") |
15 | 15 | ||
16 | ----------------------------------------------------------------------------- | 16 | ----------------------------------------------------------------------------- |
17 | -- Setup namespace | ||
18 | ----------------------------------------------------------------------------- | ||
19 | _LOADED["ftp"] = getfenv(1) | ||
20 | |||
21 | ----------------------------------------------------------------------------- | ||
22 | -- Program constants | 17 | -- Program constants |
23 | ----------------------------------------------------------------------------- | 18 | ----------------------------------------------------------------------------- |
24 | -- timeout in seconds before the program gives up on a connection | 19 | -- timeout in seconds before the program gives up on a connection |
diff --git a/src/http.lua b/src/http.lua index b341ebb..3bd4d6a 100644 --- a/src/http.lua +++ b/src/http.lua | |||
@@ -14,11 +14,6 @@ local mime = require("mime") | |||
14 | local url = require("url") | 14 | local url = require("url") |
15 | 15 | ||
16 | ----------------------------------------------------------------------------- | 16 | ----------------------------------------------------------------------------- |
17 | -- Setup namespace | ||
18 | ------------------------------------------------------------------------------- | ||
19 | _LOADED["http"] = getfenv(1) | ||
20 | |||
21 | ----------------------------------------------------------------------------- | ||
22 | -- Program constants | 17 | -- Program constants |
23 | ----------------------------------------------------------------------------- | 18 | ----------------------------------------------------------------------------- |
24 | -- connection timeout in seconds | 19 | -- connection timeout in seconds |
diff --git a/src/ltn12.lua b/src/ltn12.lua index 09771d4..04656cb 100644 --- a/src/ltn12.lua +++ b/src/ltn12.lua | |||
@@ -5,11 +5,6 @@ | |||
5 | -- RCS ID: $Id$ | 5 | -- RCS ID: $Id$ |
6 | ----------------------------------------------------------------------------- | 6 | ----------------------------------------------------------------------------- |
7 | 7 | ||
8 | ----------------------------------------------------------------------------- | ||
9 | -- Setup namespace | ||
10 | ----------------------------------------------------------------------------- | ||
11 | _LOADED["ltn12"] = getfenv(1) | ||
12 | |||
13 | filter = {} | 8 | filter = {} |
14 | source = {} | 9 | source = {} |
15 | sink = {} | 10 | sink = {} |
@@ -28,7 +28,9 @@ static int mime_global_qp(lua_State *L); | |||
28 | static int mime_global_unqp(lua_State *L); | 28 | static int mime_global_unqp(lua_State *L); |
29 | static int mime_global_qpwrp(lua_State *L); | 29 | static int mime_global_qpwrp(lua_State *L); |
30 | static int mime_global_eol(lua_State *L); | 30 | static int mime_global_eol(lua_State *L); |
31 | static int mime_global_dot(lua_State *L); | ||
31 | 32 | ||
33 | static size_t dot(int c, size_t state, luaL_Buffer *buffer); | ||
32 | static void b64setup(UC *b64unbase); | 34 | static void b64setup(UC *b64unbase); |
33 | static size_t b64encode(UC c, UC *input, size_t size, luaL_Buffer *buffer); | 35 | static size_t b64encode(UC c, UC *input, size_t size, luaL_Buffer *buffer); |
34 | static size_t b64pad(const UC *input, size_t size, luaL_Buffer *buffer); | 36 | static size_t b64pad(const UC *input, size_t size, luaL_Buffer *buffer); |
@@ -43,6 +45,7 @@ static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer); | |||
43 | 45 | ||
44 | /* code support functions */ | 46 | /* code support functions */ |
45 | static luaL_reg func[] = { | 47 | static luaL_reg func[] = { |
48 | { "dot", mime_global_dot }, | ||
46 | { "b64", mime_global_b64 }, | 49 | { "b64", mime_global_b64 }, |
47 | { "eol", mime_global_eol }, | 50 | { "eol", mime_global_eol }, |
48 | { "qp", mime_global_qp }, | 51 | { "qp", mime_global_qp }, |
@@ -659,3 +662,48 @@ static int mime_global_eol(lua_State *L) | |||
659 | lua_pushnumber(L, ctx); | 662 | lua_pushnumber(L, ctx); |
660 | return 2; | 663 | return 2; |
661 | } | 664 | } |
665 | |||
666 | /*-------------------------------------------------------------------------*\ | ||
667 | * Takes one byte and stuff it if needed. | ||
668 | \*-------------------------------------------------------------------------*/ | ||
669 | static size_t dot(int c, size_t state, luaL_Buffer *buffer) | ||
670 | { | ||
671 | luaL_putchar(buffer, c); | ||
672 | switch (c) { | ||
673 | case '\r': | ||
674 | return 1; | ||
675 | case '\n': | ||
676 | return (state == 1)? 2: 0; | ||
677 | case '.': | ||
678 | if (state == 2) | ||
679 | luaL_putchar(buffer, '.'); | ||
680 | default: | ||
681 | return 0; | ||
682 | } | ||
683 | } | ||
684 | |||
685 | /*-------------------------------------------------------------------------*\ | ||
686 | * Incrementally applies smtp stuffing to a string | ||
687 | * A, n = dot(l, D) | ||
688 | \*-------------------------------------------------------------------------*/ | ||
689 | static int mime_global_dot(lua_State *L) | ||
690 | { | ||
691 | size_t isize = 0, state = (size_t) luaL_checknumber(L, 1); | ||
692 | const char *input = luaL_optlstring(L, 2, NULL, &isize); | ||
693 | const char *last = input + isize; | ||
694 | luaL_Buffer buffer; | ||
695 | /* end-of-input blackhole */ | ||
696 | if (!input) { | ||
697 | lua_pushnil(L); | ||
698 | lua_pushnumber(L, 2); | ||
699 | return 2; | ||
700 | } | ||
701 | /* process all input */ | ||
702 | luaL_buffinit(L, &buffer); | ||
703 | while (input < last) | ||
704 | state = dot(*input++, state, &buffer); | ||
705 | luaL_pushresult(&buffer); | ||
706 | lua_pushnumber(L, state); | ||
707 | return 2; | ||
708 | } | ||
709 | |||
diff --git a/src/mime.lua b/src/mime.lua index 4fade3b..345bd25 100644 --- a/src/mime.lua +++ b/src/mime.lua | |||
@@ -11,11 +11,6 @@ | |||
11 | local mime = requirelib("mime", "luaopen_mime", getfenv(1)) | 11 | local mime = requirelib("mime", "luaopen_mime", getfenv(1)) |
12 | local ltn12 = require("ltn12") | 12 | local ltn12 = require("ltn12") |
13 | 13 | ||
14 | ----------------------------------------------------------------------------- | ||
15 | -- Setup namespace | ||
16 | ----------------------------------------------------------------------------- | ||
17 | _LOADED["mime"] = mime | ||
18 | |||
19 | -- encode, decode and wrap algorithm tables | 14 | -- encode, decode and wrap algorithm tables |
20 | encodet = {} | 15 | encodet = {} |
21 | decodet = {} | 16 | decodet = {} |
@@ -73,3 +68,8 @@ wrap = choose(wrapt) | |||
73 | function normalize(marker) | 68 | function normalize(marker) |
74 | return ltn12.filter.cycle(eol, 0, marker) | 69 | return ltn12.filter.cycle(eol, 0, marker) |
75 | end | 70 | end |
71 | |||
72 | -- high level stuffing filter | ||
73 | function stuff() | ||
74 | return ltn12.filter.cycle(dot, 2) | ||
75 | end | ||
diff --git a/src/smtp.lua b/src/smtp.lua index 2ea6097..1708053 100644 --- a/src/smtp.lua +++ b/src/smtp.lua | |||
@@ -8,17 +8,11 @@ | |||
8 | ----------------------------------------------------------------------------- | 8 | ----------------------------------------------------------------------------- |
9 | -- Load required modules | 9 | -- Load required modules |
10 | ----------------------------------------------------------------------------- | 10 | ----------------------------------------------------------------------------- |
11 | local smtp = requirelib("smtp", "luaopen_smtp", getfenv(1)) | ||
12 | local socket = require("socket") | 11 | local socket = require("socket") |
13 | local ltn12 = require("ltn12") | 12 | local ltn12 = require("ltn12") |
14 | local mime = require("mime") | 13 | local mime = require("mime") |
15 | local tp = require("tp") | 14 | local tp = require("tp") |
16 | 15 | ||
17 | ----------------------------------------------------------------------------- | ||
18 | -- Setup namespace | ||
19 | ----------------------------------------------------------------------------- | ||
20 | _LOADED["smtp"] = smtp | ||
21 | |||
22 | -- timeout for connection | 16 | -- timeout for connection |
23 | TIMEOUT = 60 | 17 | TIMEOUT = 60 |
24 | -- default server used to send e-mails | 18 | -- default server used to send e-mails |
@@ -31,11 +25,6 @@ DOMAIN = os.getenv("SERVER_NAME") or "localhost" | |||
31 | -- default time zone (means we don't know) | 25 | -- default time zone (means we don't know) |
32 | ZONE = "-0000" | 26 | ZONE = "-0000" |
33 | 27 | ||
34 | -- high level stuffing filter | ||
35 | function stuff() | ||
36 | return ltn12.filter.cycle(dot, 2) | ||
37 | end | ||
38 | |||
39 | --------------------------------------------------------------------------- | 28 | --------------------------------------------------------------------------- |
40 | -- Low level SMTP API | 29 | -- Low level SMTP API |
41 | ----------------------------------------------------------------------------- | 30 | ----------------------------------------------------------------------------- |
@@ -110,7 +99,7 @@ function metat.__index:send(mailt) | |||
110 | else | 99 | else |
111 | self:rcpt(mailt.rcpt) | 100 | self:rcpt(mailt.rcpt) |
112 | end | 101 | end |
113 | self:data(ltn12.source.chain(mailt.source, stuff()), mailt.step) | 102 | self:data(ltn12.source.chain(mailt.source, mime.stuff()), mailt.step) |
114 | end | 103 | end |
115 | 104 | ||
116 | function open(server, port) | 105 | function open(server, port) |
@@ -12,11 +12,6 @@ local socket = require("socket") | |||
12 | local ltn12 = require("ltn12") | 12 | local ltn12 = require("ltn12") |
13 | 13 | ||
14 | ----------------------------------------------------------------------------- | 14 | ----------------------------------------------------------------------------- |
15 | -- Setup namespace | ||
16 | ----------------------------------------------------------------------------- | ||
17 | _LOADED["tp"] = getfenv(1) | ||
18 | |||
19 | ----------------------------------------------------------------------------- | ||
20 | -- Program constants | 15 | -- Program constants |
21 | ----------------------------------------------------------------------------- | 16 | ----------------------------------------------------------------------------- |
22 | TIMEOUT = 60 | 17 | TIMEOUT = 60 |
diff --git a/src/url.lua b/src/url.lua index c708e19..3fd0aa6 100644 --- a/src/url.lua +++ b/src/url.lua | |||
@@ -6,11 +6,6 @@ | |||
6 | ----------------------------------------------------------------------------- | 6 | ----------------------------------------------------------------------------- |
7 | 7 | ||
8 | ----------------------------------------------------------------------------- | 8 | ----------------------------------------------------------------------------- |
9 | -- Setup namespace | ||
10 | ----------------------------------------------------------------------------- | ||
11 | _LOADED["url"] = getfenv(1) | ||
12 | |||
13 | ----------------------------------------------------------------------------- | ||
14 | -- Encodes a string into its escaped hexadecimal representation | 9 | -- Encodes a string into its escaped hexadecimal representation |
15 | -- Input | 10 | -- Input |
16 | -- s: binary string to be encoded | 11 | -- s: binary string to be encoded |
diff --git a/test/httptest.lua b/test/httptest.lua index a171dd9..45d7e8d 100644 --- a/test/httptest.lua +++ b/test/httptest.lua | |||
@@ -390,7 +390,7 @@ local r, c, h = http.request { | |||
390 | method = "HEAD", | 390 | method = "HEAD", |
391 | url = "http://www.cs.princeton.edu/~diego/" | 391 | url = "http://www.cs.princeton.edu/~diego/" |
392 | } | 392 | } |
393 | assert(r and h and c == 200) | 393 | assert(r and h and (c == 200), c) |
394 | print("ok") | 394 | print("ok") |
395 | 395 | ||
396 | ------------------------------------------------------------------------ | 396 | ------------------------------------------------------------------------ |