From d46f7a09a768b146f2f3cdc9a6a50357832bd1c7 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Wed, 16 Jun 2004 01:02:07 +0000 Subject: Fixed smtp.lua loading. Adjusted tftp module. Added some comments. --- src/except.c | 10 ++++++++++ src/ftp.lua | 3 --- src/http.lua | 7 ++----- src/ltn12.lua | 2 -- src/mime.c | 4 ++-- src/mime.h | 2 +- src/mime.lua | 2 -- src/options.c | 10 ++++++++++ src/options.h | 9 +++++++++ src/select.h | 11 ++++------- src/smtp.lua | 6 ++---- src/socket.lua | 2 -- src/tp.lua | 4 ---- src/url.lua | 3 --- 14 files changed, 40 insertions(+), 35 deletions(-) (limited to 'src') 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 @@ +/*=========================================================================*\ +* Simple exception support +* LuaSocket toolkit +* +* RCS ID: $Id$ +\*=========================================================================*/ #include #include #include "except.h" +/*=========================================================================*\ +* Internal function prototypes. +\*=========================================================================*/ static int global_try(lua_State *L); static int global_protect(lua_State *L); static int protected(lua_State *L); +/* except functions */ static luaL_reg func[] = { {"try", global_try}, {"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 @@ -- FTP support for the Lua language -- LuaSocket toolkit. -- Author: Diego Nehab --- Conforming to: RFC 959, LTN7 -- RCS ID: $Id$ ----------------------------------------------------------------------------- @@ -244,5 +243,3 @@ get = socket.protect(function(gett) if type(gett) == "string" then return sget(gett) else return tget(gett) end end) - -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 @@ -- HTTP/1.1 client support for the Lua language. -- LuaSocket toolkit. -- Author: Diego Nehab --- Conforming to RFC 2616 -- RCS ID: $Id$ ----------------------------------------------------------------------------- @@ -23,7 +22,7 @@ _LOADED["http"] = getfenv(1) -- Program constants ----------------------------------------------------------------------------- -- connection timeout in seconds -TIMEOUT = 4 +TIMEOUT = 60 -- default port for document retrieval PORT = 80 -- user agent field sent in request @@ -146,7 +145,7 @@ end local function adjustrequest(reqt) -- parse url with default fields - local parsed = url.parse(reqt.url, { + local parsed = url.parse(reqt.url or "", { host = "", port = PORT, path ="/", @@ -258,5 +257,3 @@ post = socket.protect(function(u, body) return (table.getn(t) > 0 or nil) and table.concat(t), respt.headers, respt.code end) - -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) if not ret then return not err, err end end end - -return 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 @@ /*=========================================================================*\ -* Encoding support functions +* MIME support functions * LuaSocket toolkit * * RCS ID: $Id$ @@ -653,7 +653,7 @@ static int mime_global_eol(lua_State *L) const char *marker = luaL_optstring(L, 3, CRLF); luaL_Buffer buffer; luaL_buffinit(L, &buffer); - /* if the last character was a candidate, we output a new line */ + /* end of input blackhole */ if (!input) { lua_pushnil(L); 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 @@ #ifndef MIME_H #define MIME_H /*=========================================================================*\ -* Mime support functions +* MIME support functions * LuaSocket toolkit * * 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) function normalize(marker) return ltn12.filter.cycle(eol, 0, marker) end - -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 @@ +/*=========================================================================*\ +* Common option interface +* LuaSocket toolkit +* +* RCS ID: $Id$ +\*=========================================================================*/ #include #include @@ -5,6 +11,10 @@ #include "options.h" #include "inet.h" + +/*=========================================================================*\ +* Internal functions prototypes +\*=========================================================================*/ static int opt_setmembership(lua_State *L, p_sock ps, int level, int name); static int opt_setboolean(lua_State *L, p_sock ps, int level, int name); 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 @@ #ifndef OPTIONS_H #define OPTIONS_H +/*=========================================================================*\ +* Common option interface +* LuaSocket toolkit +* +* This module provides a common interface to socket options, used mainly by +* modules UDP and TCP. +* +* RCS ID: $Id$ +\*=========================================================================*/ #include #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 @@ * Select implementation * LuaSocket toolkit * -* To make the code as simple as possible, the select function is -* implemented int Lua, with a few helper functions written in C. -* -* Each object that can be passed to the select function has to export two -* methods: fd() and dirty(). Fd returns the descriptor to be passed to the -* select function. Dirty() should return true if there is data ready for -* reading (required for buffered input). +* Each object that can be passed to the select function has to export +* method getfd() which returns the descriptor to be passed to the +* underlying select function. Another method, dirty(), should return +* true if there is data ready for reading (required for buffered input). * * RCS ID: $Id$ \*=========================================================================*/ 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 @@ -- SMTP client support for the Lua language. -- LuaSocket toolkit. -- Author: Diego Nehab --- Conforming to RFC 2821 -- RCS ID: $Id$ ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- -- Load required modules ----------------------------------------------------------------------------- -local smtp = requirelib("smtp") +local smtp = requirelib("smtp", "luaopen_smtp", getfenv(1)) local socket = require("socket") local ltn12 = require("ltn12") local tp = require("tp") @@ -206,6 +205,7 @@ end --------------------------------------------------------------------------- -- High level SMTP API ----------------------------------------------------------------------------- +socket.protect = function(a) return a end send = socket.protect(function(mailt) local con = open(mailt.server, mailt.port) con:greet(mailt.domain) @@ -213,5 +213,3 @@ send = socket.protect(function(mailt) con:quit() return con:close() end) - -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 socket.sourcet["default"] = socket.sourcet["until-closed"] socket.source = socket.choose(socket.sourcet) - -return 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 = {} } function metat.__index:check(ok) local code, reply = get_reply(self.control) -print(reply) if not code then return nil, reply end if type(ok) ~= "function" then if type(ok) == "table" then @@ -65,7 +64,6 @@ print(reply) end function metat.__index:command(cmd, arg) -print(cmd, arg) if arg then return self.control:send(cmd .. " " .. arg.. "\r\n") else return self.control:send(cmd .. "\r\n") end end @@ -113,5 +111,3 @@ connect = socket.protect(function(host, port, timeout) socket.try(control:connect(host, port)) return setmetatable({control = control}, metat) end) - -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 @@ -- URI parsing, composition and relative URL resolution -- LuaSocket toolkit. -- Author: Diego Nehab --- Conforming to: RFC 2396, LTN7 -- RCS ID: $Id$ ----------------------------------------------------------------------------- @@ -269,5 +268,3 @@ function build_path(parsed, unsafe) if parsed.is_absolute then path = "/" .. path end return path end - -return url -- cgit v1.2.3-55-g6feb