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 /src | |
| 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.
Diffstat (limited to 'src')
| -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 |
14 files changed, 40 insertions, 35 deletions
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 | ||
