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 /src | |
| parent | 94b97bdc0039c78a213e0a6170f3037eeb00122e (diff) | |
| download | luasocket-613534c79526e313d6bfd5ffa514797b364dc185.tar.gz luasocket-613534c79526e313d6bfd5ffa514797b364dc185.tar.bz2 luasocket-613534c79526e313d6bfd5ffa514797b364dc185.zip | |
smtp.c was eatten by mime.c
Diffstat (limited to 'src')
| -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 |
8 files changed, 54 insertions, 42 deletions
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 |
