aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-06-16 01:02:07 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-06-16 01:02:07 +0000
commitd46f7a09a768b146f2f3cdc9a6a50357832bd1c7 (patch)
treed4f7ca1e677d06446245691d5ece6dab51915f16
parent843a431ef98fd541d98fd3898463985d9bfcde28 (diff)
downloadluasocket-d46f7a09a768b146f2f3cdc9a6a50357832bd1c7.tar.gz
luasocket-d46f7a09a768b146f2f3cdc9a6a50357832bd1c7.tar.bz2
luasocket-d46f7a09a768b146f2f3cdc9a6a50357832bd1c7.zip
Fixed smtp.lua loading.
Adjusted tftp module. Added some comments.
-rw-r--r--TODO76
-rw-r--r--etc/tftp.lua134
-rw-r--r--samples/cddb.lua2
-rw-r--r--src/except.c10
-rw-r--r--src/ftp.lua3
-rw-r--r--src/http.lua7
-rw-r--r--src/ltn12.lua2
-rw-r--r--src/mime.c4
-rw-r--r--src/mime.h2
-rw-r--r--src/mime.lua2
-rw-r--r--src/options.c10
-rw-r--r--src/options.h9
-rw-r--r--src/select.h11
-rw-r--r--src/smtp.lua6
-rw-r--r--src/socket.lua2
-rw-r--r--src/tp.lua4
-rw-r--r--src/url.lua3
-rw-r--r--test/stufftest.lua6
-rw-r--r--test/testmesg.lua4
-rw-r--r--test/tftptest.lua4
20 files changed, 162 insertions, 139 deletions
diff --git a/TODO b/TODO
index 69cfc6b..33e9a43 100644
--- a/TODO
+++ b/TODO
@@ -1,52 +1,31 @@
1ajeitar os README.* 1ajeitar os README.*
2ajeitar select. upvalue nao tem nada a ver...
3make sure filter.chain fails gracefully.
4ajeitar o manual sobre select, mais liberal agora
5falar sobre o novo esquema de namespace
6tirar socket.url socket.ftp etc do manual. agora os namespaces estao
7liberados.
8ajeitar as referencias a RFCS e LTNS em todos os arquivos. 2ajeitar as referencias a RFCS e LTNS em todos os arquivos.
9proxy no ftp
10ajeitar < e-mail > no smtp?
11ajeitar referencias a LTN12 nos manuais
12 3
13make sure sockets are closed when exceptions are raised 4make sure sockets are closed when exceptions are raised
14 5
15falar sobre encodet/wrapt/decodet no manual sobre mime
16
17RECEIVE MUDOU!!! (partial stuff) COLOCAR NO MANUAL.
18HTTP.lua mudou bastante também.
19pump.step usado em todo mundo que recebe source ou sink
20
21sources ans sinks are always simple in http and ftp and smtp
22expose encode/decode tables to provide extensibility for mime module
23use coroutines instead of fancy filters
24
25check garbage collection in test*.lua 6check garbage collection in test*.lua
26 7
27add socket.TIMEOUT to be default timeout?
28 8
29manual 9manual
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
51tests 30tests
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.
59add comments into each C module. 38add comments into each C module.
60testar os options! 39testar os options!
61 40
62use gethostname it in SMTP
63
64make sure modules know if their dependencies are there.
65 41
66Read about 42Read about
67250-ENHANCEDSTATUSCODES 43250-ENHANCEDSTATUSCODES
@@ -108,6 +84,12 @@ Ajeitar o protocolo da luaopen_socket()... sei lá qual é.
108these are done 84these 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
9local Public, Private = {}, {} 8-----------------------------------------------------------------------------
10local socket = _G[LUASOCKET_LIBNAME] -- get LuaSocket namespace 9-- Load required files
11socket.tftp = Public -- create tftp sub namespace 10-----------------------------------------------------------------------------
11local socket = require("socket")
12local ltn12 = require("ltn12")
13local 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
16local char = string.char 23local char = string.char
17local byte = string.byte 24local byte = string.byte
18 25
19Public.PORT = 69 26PORT = 69
20Private.OP_RRQ = 1 27local OP_RRQ = 1
21Private.OP_WRQ = 2 28local OP_WRQ = 2
22Private.OP_DATA = 3 29local OP_DATA = 3
23Private.OP_ACK = 4 30local OP_ACK = 4
24Private.OP_ERROR = 5 31local OP_ERROR = 5
25Private.OP_INV = {"RRQ", "WRQ", "DATA", "ACK", "ERROR"} 32local OP_INV = {"RRQ", "WRQ", "DATA", "ACK", "ERROR"}
26 33
27----------------------------------------------------------------------------- 34-----------------------------------------------------------------------------
28-- Packet creation functions 35-- Packet creation functions
29----------------------------------------------------------------------------- 36-----------------------------------------------------------------------------
30function Private.RRQ(source, mode) 37local 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)
32end 39end
33 40
34function Private.WRQ(source, mode) 41local 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)
36end 43end
37 44
38function Private.ACK(block) 45local 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)
43end 50end
44 51
45function Private.get_OP(dgram) 52local 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
48end 55end
@@ -50,13 +57,13 @@ end
50----------------------------------------------------------------------------- 57-----------------------------------------------------------------------------
51-- Packet analysis functions 58-- Packet analysis functions
52----------------------------------------------------------------------------- 59-----------------------------------------------------------------------------
53function Private.split_DATA(dgram) 60local 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
57end 64end
58 65
59function Private.get_ERROR(dgram) 66local 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)
64end 71end
65 72
66----------------------------------------------------------------------------- 73-----------------------------------------------------------------------------
67-- Downloads and returns a file pointed to by url 74-- High level TFTP API
68----------------------------------------------------------------------------- 75-----------------------------------------------------------------------------
69function Public.get(url) 76local 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
131end 125end
126
127local default = {
128 port = PORT,
129 path ="/",
130 scheme = "tftp"
131}
132
133local 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
138end
139
140local 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)
146end
147
148get = socket.protect(function(gett)
149 if type(gett) == "string" then return sget(gett)
150 else return tget(gett) end
151end)
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
32local host = socket.dns.gethostname() 32local host = socket.dns.gethostname()
33local query = "%s?cmd=cddb+read+%s+%s&hello=LuaSocket+%s+LuaSocket+2.0&proto=6" 33local query = "%s?cmd=cddb+read+%s+%s&hello=LuaSocket+%s+LuaSocket+2.0&proto=6"
34local url = string.format(query, server, arg[1], arg[2], host) 34local url = string.format(query, server, arg[1], arg[2], host)
35local body, headers, code, error = http.get(url) 35local body, headers, code = http.get(url)
36 36
37if code == 200 then 37if 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\*=========================================================================*/
6static int global_try(lua_State *L); 15static int global_try(lua_State *L);
7static int global_protect(lua_State *L); 16static int global_protect(lua_State *L);
8static int protected(lua_State *L); 17static int protected(lua_State *L);
9 18
19/* except functions */
10static luaL_reg func[] = { 20static 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
246end) 245end)
247
248return 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
26TIMEOUT = 4 25TIMEOUT = 60
27-- default port for document retrieval 26-- default port for document retrieval
28PORT = 80 27PORT = 80
29-- user agent field sent in request 28-- user agent field sent in request
@@ -146,7 +145,7 @@ end
146 145
147local function adjustrequest(reqt) 146local 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
260end) 259end)
261
262return 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
256end 256end
257
258return ltn12
diff --git a/src/mime.c b/src/mime.c
index 5750714..825b666 100644
--- a/src/mime.c
+++ b/src/mime.c
@@ -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);
diff --git a/src/mime.h b/src/mime.h
index b82d61a..be16920 100644
--- a/src/mime.h
+++ b/src/mime.h
@@ -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)
73function normalize(marker) 73function normalize(marker)
74 return ltn12.filter.cycle(eol, 0, marker) 74 return ltn12.filter.cycle(eol, 0, marker)
75end 75end
76
77return 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\*=========================================================================*/
8static int opt_setmembership(lua_State *L, p_sock ps, int level, int name); 18static int opt_setmembership(lua_State *L, p_sock ps, int level, int name);
9static int opt_setboolean(lua_State *L, p_sock ps, int level, int name); 19static int opt_setboolean(lua_State *L, p_sock ps, int level, int name);
10static int opt_set(lua_State *L, p_sock ps, int level, int name, 20static 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-----------------------------------------------------------------------------
12local smtp = requirelib("smtp") 11local smtp = requirelib("smtp", "luaopen_smtp", getfenv(1))
13local socket = require("socket") 12local socket = require("socket")
14local ltn12 = require("ltn12") 13local ltn12 = require("ltn12")
15local tp = require("tp") 14local tp = require("tp")
@@ -206,6 +205,7 @@ end
206--------------------------------------------------------------------------- 205---------------------------------------------------------------------------
207-- High level SMTP API 206-- High level SMTP API
208----------------------------------------------------------------------------- 207-----------------------------------------------------------------------------
208socket.protect = function(a) return a end
209send = socket.protect(function(mailt) 209send = 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()
215end) 215end)
216
217return 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
166socket.sourcet["default"] = socket.sourcet["until-closed"] 166socket.sourcet["default"] = socket.sourcet["until-closed"]
167 167
168socket.source = socket.choose(socket.sourcet) 168socket.source = socket.choose(socket.sourcet)
169
170return socket
diff --git a/src/tp.lua b/src/tp.lua
index 56dd8bc..731191e 100644
--- a/src/tp.lua
+++ b/src/tp.lua
@@ -49,7 +49,6 @@ local metat = { __index = {} }
49 49
50function metat.__index:check(ok) 50function metat.__index:check(ok)
51 local code, reply = get_reply(self.control) 51 local code, reply = get_reply(self.control)
52print(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)
65end 64end
66 65
67function metat.__index:command(cmd, arg) 66function metat.__index:command(cmd, arg)
68print(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
71end 69end
@@ -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)
115end) 113end)
116
117return 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
271end 270end
272
273return 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 @@
1smtp = require("smtp")
2
1function test_dot(original, right) 3function 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")
5end 7end
6 8
7function test_stuff(original, right) 9function 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")
11end 13end
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
59print(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
2dofile("tftp.lua") 2local 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)
13end 13end
14 14
15host = host or "localhost" 15host = host or "localhost"
16retrieved, err = socket.tftp.get("tftp://" .. host .."/index.html") 16retrieved, err = tftp.get("tftp://" .. host .."/index.html")
17assert(not err, err) 17assert(not err, err)
18original = readfile("test/index.html") 18original = readfile("test/index.html")
19assert(original == retrieved, "files differ!") 19assert(original == retrieved, "files differ!")