From 773e35ced30fa2c03ddb2a332bf8a9aebb56aa44 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Tue, 23 Aug 2005 05:53:14 +0000 Subject: Compiled on Windows. Fixed a bunch of stuff. Almost ready to release. Implemented a nice dispatcher! Non-blocking check-links and forward server use the dispatcher. --- src/auxiliar.c | 8 ++++++++ src/http.lua | 1 - src/luasocket.h | 2 +- src/mime.c | 2 +- src/mime.h | 2 +- src/smtp.lua | 49 +++++++++++++++++++++++++------------------------ src/wsocket.c | 2 +- 7 files changed, 37 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/auxiliar.c b/src/auxiliar.c index 2ebcdd6..b228785 100644 --- a/src/auxiliar.c +++ b/src/auxiliar.c @@ -127,6 +127,9 @@ void aux_setclass(lua_State *L, const char *classname, int objidx) { * otherwise \*-------------------------------------------------------------------------*/ void *aux_getgroupudata(lua_State *L, const char *groupname, int objidx) { +#if 0 + return lua_touserdata(L, objidx); +#else if (!lua_getmetatable(L, objidx)) return NULL; lua_pushstring(L, groupname); @@ -138,6 +141,7 @@ void *aux_getgroupudata(lua_State *L, const char *groupname, int objidx) { lua_pop(L, 2); return lua_touserdata(L, objidx); } +#endif } /*-------------------------------------------------------------------------*\ @@ -145,5 +149,9 @@ void *aux_getgroupudata(lua_State *L, const char *groupname, int objidx) { * otherwise \*-------------------------------------------------------------------------*/ void *aux_getclassudata(lua_State *L, const char *classname, int objidx) { +#if 0 + return lua_touserdata(L, objidx); +#else return luaL_checkudata(L, objidx, classname); +#endif } diff --git a/src/http.lua b/src/http.lua index 9434d97..fe779a3 100644 --- a/src/http.lua +++ b/src/http.lua @@ -325,4 +325,3 @@ request = socket.protect(function(reqt, body) if base.type(reqt) == "string" then return srequest(reqt, body) else return trequest(reqt) end end) - diff --git a/src/luasocket.h b/src/luasocket.h index 34a7693..c7d09d8 100644 --- a/src/luasocket.h +++ b/src/luasocket.h @@ -27,6 +27,6 @@ /*-------------------------------------------------------------------------*\ * Initializes the library. \*-------------------------------------------------------------------------*/ -LUASOCKET_API int luaopen_socketcore(lua_State *L); +LUASOCKET_API int luaopen_socket_core(lua_State *L); #endif /* LUASOCKET_H */ diff --git a/src/mime.c b/src/mime.c index 70e0db9..4539e2c 100644 --- a/src/mime.c +++ b/src/mime.c @@ -78,7 +78,7 @@ static UC b64unbase[256]; /*-------------------------------------------------------------------------*\ * Initializes module \*-------------------------------------------------------------------------*/ -MIME_API int luaopen_mimecore(lua_State *L) +MIME_API int luaopen_mime_core(lua_State *L) { luaL_openlib(L, "mime", func, 0); /* initialize lookup tables */ diff --git a/src/mime.h b/src/mime.h index 34031a1..eda0898 100644 --- a/src/mime.h +++ b/src/mime.h @@ -19,6 +19,6 @@ #define MIME_API extern #endif -MIME_API int luaopen_mimecore(lua_State *L); +MIME_API int luaopen_mime_core(lua_State *L); #endif /* MIME_H */ diff --git a/src/smtp.lua b/src/smtp.lua index 46df1ab..5c485c2 100644 --- a/src/smtp.lua +++ b/src/smtp.lua @@ -137,12 +137,24 @@ end -- send_message forward declaration local send_message +-- yield the headers all at once, it's faster +local function send_headers(headers) + local h = "\r\n" + for i,v in base.pairs(headers) do + h = i .. ': ' .. v .. "\r\n" .. h + end + coroutine.yield(h) +end + -- yield multipart message body from a multipart message table local function send_multipart(mesgt) + -- make sure we have our boundary and send headers local bd = newboundary() - -- define boundary and finish headers - coroutine.yield('content-type: multipart/mixed; boundary="' .. - bd .. '"\r\n\r\n') + local headers = mesgt.headers or {} + headers['content-type'] = headers['content-type'] or 'multipart/mixed' + headers['content-type'] = headers['content-type'] .. + '; boundary="' .. bd .. '"' + send_headers(headers) -- send preamble if mesgt.body.preamble then coroutine.yield(mesgt.body.preamble) @@ -164,11 +176,11 @@ end -- yield message body from a source local function send_source(mesgt) - -- set content-type if user didn't override - if not mesgt.headers or not mesgt.headers["content-type"] then - coroutine.yield('content-type: text/plain; charset="iso-8859-1"\r\n\r\n') - else coroutine.yield("\r\n") end - -- finish headers + -- make sure we have a content-type + local headers = mesgt.headers or {} + headers['content-type'] = headers['content-type'] or + 'text/plain; charset="iso-8859-1"' + send_headers(headers) -- send body from source while true do local chunk, err = mesgt.body() @@ -180,28 +192,17 @@ end -- yield message body from a string local function send_string(mesgt) - -- set content-type if user didn't override - if not mesgt.headers or not mesgt.headers["content-type"] then - coroutine.yield('content-type: text/plain; charset="iso-8859-1"\r\n\r\n') - else coroutine.yield("\r\n") end + -- make sure we have a content-type + local headers = mesgt.headers or {} + headers['content-type'] = headers['content-type'] or + 'text/plain; charset="iso-8859-1"' + send_headers(headers) -- send body from string coroutine.yield(mesgt.body) end --- yield the headers all at once -local function send_headers(mesgt) - if mesgt.headers then - local h = "" - for i,v in base.pairs(mesgt.headers) do - h = i .. ': ' .. v .. "\r\n" .. h - end - coroutine.yield(h) - end -end - -- message source function send_message(mesgt) - send_headers(mesgt) if base.type(mesgt.body) == "table" then send_multipart(mesgt) elseif base.type(mesgt.body) == "function" then send_source(mesgt) else send_string(mesgt) end diff --git a/src/wsocket.c b/src/wsocket.c index c4c51b4..0f6005f 100644 --- a/src/wsocket.c +++ b/src/wsocket.c @@ -75,7 +75,7 @@ int sock_select(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, p_tm tm) { tv.tv_sec = (int) t; tv.tv_usec = (int) ((t - tv.tv_sec) * 1.0e6); if (n <= 0) { - Sleep(1000*t); + Sleep((DWORD) (1000*t)); return 0; } else return select(0, rfds, wfds, efds, t >= 0.0? &tv: NULL); } -- cgit v1.2.3-55-g6feb