diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-11-28 02:36:07 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2004-11-28 02:36:07 +0000 |
| commit | 297b32e828b76ee544c9d4f89f996eda78830cc0 (patch) | |
| tree | 312ca3a296b1e959acddeca9303cb238ac8324dc /src | |
| parent | 05e8f243851049cebda6c5b690d3cde0f1e2c874 (diff) | |
| download | luasocket-297b32e828b76ee544c9d4f89f996eda78830cc0.tar.gz luasocket-297b32e828b76ee544c9d4f89f996eda78830cc0.tar.bz2 luasocket-297b32e828b76ee544c9d4f89f996eda78830cc0.zip | |
LTN12 bug removed.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ltn12.lua | 26 | ||||
| -rw-r--r-- | src/mime.c | 7 | ||||
| -rw-r--r-- | src/mime.lua | 9 |
3 files changed, 29 insertions, 13 deletions
diff --git a/src/ltn12.lua b/src/ltn12.lua index 5216ff6..1a13a43 100644 --- a/src/ltn12.lua +++ b/src/ltn12.lua | |||
| @@ -40,30 +40,27 @@ end | |||
| 40 | function filter.chain(...) | 40 | function filter.chain(...) |
| 41 | local n = table.getn(arg) | 41 | local n = table.getn(arg) |
| 42 | local top, index = 1, 1 | 42 | local top, index = 1, 1 |
| 43 | local retry = "" | ||
| 43 | return function(chunk) | 44 | return function(chunk) |
| 45 | retry = chunk and retry | ||
| 44 | while true do | 46 | while true do |
| 45 | if index == top then | 47 | if index == top then |
| 46 | chunk = arg[index](chunk) | 48 | chunk = arg[index](chunk) |
| 47 | if chunk == "" or top == n then | 49 | if chunk == "" or top == n then return chunk |
| 48 | return chunk | 50 | elseif chunk then index = index + 1 |
| 49 | elseif chunk then | ||
| 50 | index = index + 1 | ||
| 51 | else | 51 | else |
| 52 | top = top+1 | 52 | top = top+1 |
| 53 | index = top | 53 | index = top |
| 54 | end | 54 | end |
| 55 | else | 55 | else |
| 56 | local original = chunk | 56 | chunk = arg[index](chunk or "") |
| 57 | chunk = arg[index](original or "") | ||
| 58 | if chunk == "" then | 57 | if chunk == "" then |
| 59 | index = index - 1 | 58 | index = index - 1 |
| 60 | chunk = original and chunk | 59 | chunk = retry |
| 61 | elseif chunk then | 60 | elseif chunk then |
| 62 | if index == n then return chunk | 61 | if index == n then return chunk |
| 63 | else index = index + 1 end | 62 | else index = index + 1 end |
| 64 | else | 63 | else base.error("filter returned inappropriate nil") end |
| 65 | base.error("filter returned inappropriate nil") | ||
| 66 | end | ||
| 67 | end | 64 | end |
| 68 | end | 65 | end |
| 69 | end | 66 | end |
| @@ -138,6 +135,8 @@ function source.rewind(src) | |||
| 138 | end | 135 | end |
| 139 | end | 136 | end |
| 140 | 137 | ||
| 138 | local print = print | ||
| 139 | |||
| 141 | -- chains a source with a filter | 140 | -- chains a source with a filter |
| 142 | function source.chain(src, f) | 141 | function source.chain(src, f) |
| 143 | base.assert(src and f) | 142 | base.assert(src and f) |
| @@ -151,13 +150,16 @@ function source.chain(src, f) | |||
| 151 | last_out = f(last_in) | 150 | last_out = f(last_in) |
| 152 | if last_out ~= "" then return last_out end | 151 | if last_out ~= "" then return last_out end |
| 153 | if not last_in then | 152 | if not last_in then |
| 154 | error('filter returned inappropriate ""') | 153 | base.error('filter returned inappropriate ""') |
| 155 | end | 154 | end |
| 156 | end | 155 | end |
| 157 | elseif last_out then | 156 | elseif last_out then |
| 158 | last_out = f(last_in and "") | 157 | last_out = f(last_in and "") |
| 159 | if last_in and not last_out then | 158 | if last_in and not last_out then |
| 160 | error('filter returned inappropriate nil') | 159 | base.error('filter returned inappropriate nil') |
| 160 | end | ||
| 161 | if last_out == "" and not last_in then | ||
| 162 | base.error(base.tostring(f) .. ' returned inappropriate ""') | ||
| 161 | end | 163 | end |
| 162 | return last_out | 164 | return last_out |
| 163 | else | 165 | else |
| @@ -267,6 +267,7 @@ static int mime_global_b64(lua_State *L) | |||
| 267 | if (!input) { | 267 | if (!input) { |
| 268 | asize = b64pad(atom, asize, &buffer); | 268 | asize = b64pad(atom, asize, &buffer); |
| 269 | luaL_pushresult(&buffer); | 269 | luaL_pushresult(&buffer); |
| 270 | if (!(*lua_tostring(L, -1))) lua_pushnil(L); | ||
| 270 | lua_pushnil(L); | 271 | lua_pushnil(L); |
| 271 | return 2; | 272 | return 2; |
| 272 | } | 273 | } |
| @@ -306,6 +307,7 @@ static int mime_global_unb64(lua_State *L) | |||
| 306 | /* if second is nil, we are done */ | 307 | /* if second is nil, we are done */ |
| 307 | if (!input) { | 308 | if (!input) { |
| 308 | luaL_pushresult(&buffer); | 309 | luaL_pushresult(&buffer); |
| 310 | if (!(*lua_tostring(L, -1))) lua_pushnil(L); | ||
| 309 | lua_pushnil(L); | 311 | lua_pushnil(L); |
| 310 | return 2; | 312 | return 2; |
| 311 | } | 313 | } |
| @@ -418,7 +420,7 @@ static size_t qppad(UC *input, size_t size, luaL_Buffer *buffer) | |||
| 418 | if (qpclass[input[i]] == QP_PLAIN) luaL_putchar(buffer, input[i]); | 420 | if (qpclass[input[i]] == QP_PLAIN) luaL_putchar(buffer, input[i]); |
| 419 | else qpquote(input[i], buffer); | 421 | else qpquote(input[i], buffer); |
| 420 | } | 422 | } |
| 421 | luaL_addstring(buffer, EQCRLF); | 423 | if (size > 0) luaL_addstring(buffer, EQCRLF); |
| 422 | return 0; | 424 | return 0; |
| 423 | } | 425 | } |
| 424 | 426 | ||
| @@ -454,7 +456,9 @@ static int mime_global_qp(lua_State *L) | |||
| 454 | if (!input) { | 456 | if (!input) { |
| 455 | asize = qppad(atom, asize, &buffer); | 457 | asize = qppad(atom, asize, &buffer); |
| 456 | luaL_pushresult(&buffer); | 458 | luaL_pushresult(&buffer); |
| 459 | if (!(*lua_tostring(L, -1))) lua_pushnil(L); | ||
| 457 | lua_pushnil(L); | 460 | lua_pushnil(L); |
| 461 | return 2; | ||
| 458 | } | 462 | } |
| 459 | /* otherwise process rest of input */ | 463 | /* otherwise process rest of input */ |
| 460 | last = input + isize; | 464 | last = input + isize; |
| @@ -531,6 +535,7 @@ static int mime_global_unqp(lua_State *L) | |||
| 531 | /* if second part is nil, we are done */ | 535 | /* if second part is nil, we are done */ |
| 532 | if (!input) { | 536 | if (!input) { |
| 533 | luaL_pushresult(&buffer); | 537 | luaL_pushresult(&buffer); |
| 538 | if (!(*lua_tostring(L, -1))) lua_pushnil(L); | ||
| 534 | lua_pushnil(L); | 539 | lua_pushnil(L); |
| 535 | return 2; | 540 | return 2; |
| 536 | } | 541 | } |
diff --git a/src/mime.lua b/src/mime.lua index 712600c..42d0b3c 100644 --- a/src/mime.lua +++ b/src/mime.lua | |||
| @@ -49,6 +49,15 @@ mime.decodet['quoted-printable'] = function() | |||
| 49 | return ltn12.filter.cycle(unqp, "") | 49 | return ltn12.filter.cycle(unqp, "") |
| 50 | end | 50 | end |
| 51 | 51 | ||
| 52 | local io, string = io, string | ||
| 53 | |||
| 54 | local function format(chunk) | ||
| 55 | if chunk then | ||
| 56 | if chunk == "" then return "''" | ||
| 57 | else return string.len(chunk) end | ||
| 58 | else return "nil" end | ||
| 59 | end | ||
| 60 | |||
| 52 | -- define the line-wrap filters | 61 | -- define the line-wrap filters |
| 53 | mime.wrapt['text'] = function(length) | 62 | mime.wrapt['text'] = function(length) |
| 54 | length = length or 76 | 63 | length = length or 76 |
