diff options
author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-08-31 00:58:07 +0000 |
---|---|---|
committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-08-31 00:58:07 +0000 |
commit | 6789b83ff5c15296267f880d3b98cf8a1800c30a (patch) | |
tree | 9571dc81cb0147218332cda34b7ccdfed37ddbbc /src | |
parent | c51d4acf1c2a8675a3bb043e799ff4390cef47d6 (diff) | |
download | luasocket-6789b83ff5c15296267f880d3b98cf8a1800c30a.tar.gz luasocket-6789b83ff5c15296267f880d3b98cf8a1800c30a.tar.bz2 luasocket-6789b83ff5c15296267f880d3b98cf8a1800c30a.zip |
Starting to use RCS in princeton again. Not behind a firewall anymore.
Diffstat (limited to 'src')
-rw-r--r-- | src/ftp.lua | 19 | ||||
-rw-r--r-- | src/http.lua | 40 | ||||
-rw-r--r-- | src/luasocket.c | 2 |
3 files changed, 29 insertions, 32 deletions
diff --git a/src/ftp.lua b/src/ftp.lua index 25226a6..bfc4ece 100644 --- a/src/ftp.lua +++ b/src/ftp.lua | |||
@@ -602,10 +602,12 @@ function Public.put_cb(request) | |||
602 | local control, err = Private.open(parsed) | 602 | local control, err = Private.open(parsed) |
603 | if not control then return err end | 603 | if not control then return err end |
604 | local segment = Private.parse_path(parsed) | 604 | local segment = Private.parse_path(parsed) |
605 | return Private.change_dir(control, segment) or | 605 | err = Private.change_dir(control, segment) or |
606 | Private.change_type(control, parsed.params) or | 606 | Private.change_type(control, parsed.params) or |
607 | Private.upload(control, request, segment) or | 607 | Private.upload(control, request, segment) or |
608 | Private.close(control) | 608 | Private.close(control) |
609 | if err then return nil, err | ||
610 | else return 1 end | ||
609 | end | 611 | end |
610 | 612 | ||
611 | ----------------------------------------------------------------------------- | 613 | ----------------------------------------------------------------------------- |
@@ -616,15 +618,15 @@ end | |||
616 | -- type: "i" for "image" mode, "a" for "ascii" mode or "d" for directory | 618 | -- type: "i" for "image" mode, "a" for "ascii" mode or "d" for directory |
617 | -- user: account user name | 619 | -- user: account user name |
618 | -- password: account password) | 620 | -- password: account password) |
621 | -- content: file contents | ||
619 | -- content: file contents | 622 | -- content: file contents |
620 | -- Returns | 623 | -- Returns |
621 | -- err: error message if any | 624 | -- err: error message if any |
622 | ----------------------------------------------------------------------------- | 625 | ----------------------------------------------------------------------------- |
623 | function Public.put(url_or_request, content) | 626 | function Public.put(url_or_request, content) |
624 | local request = Private.build_request(url_or_request) | 627 | local request = Private.build_request(url_or_request) |
625 | request.content_cb = function() | 628 | request.content = request.content or content |
626 | return content, string.len(content) | 629 | request.content_cb = socket.callback.send_string(request.content) |
627 | end | ||
628 | return Public.put_cb(request) | 630 | return Public.put_cb(request) |
629 | end | 631 | end |
630 | 632 | ||
@@ -641,12 +643,9 @@ end | |||
641 | -- err: error message in case of error, nil otherwise | 643 | -- err: error message in case of error, nil otherwise |
642 | ----------------------------------------------------------------------------- | 644 | ----------------------------------------------------------------------------- |
643 | function Public.get(url_or_request) | 645 | function Public.get(url_or_request) |
644 | local cat = socket.concat.create() | 646 | local concat = socket.concat.create() |
645 | local request = Private.build_request(url_or_request) | 647 | local request = Private.build_request(url_or_request) |
646 | request.content_cb = function(chunk, err) | 648 | request.content_cb = socket.callback.receive_concat(concat) |
647 | if chunk then cat:addstring(chunk) end | ||
648 | return 1 | ||
649 | end | ||
650 | local err = Public.get_cb(request) | 649 | local err = Public.get_cb(request) |
651 | return cat:getresult(), err | 650 | return concat:getresult(), err |
652 | end | 651 | end |
diff --git a/src/http.lua b/src/http.lua index 212e8f6..252285a 100644 --- a/src/http.lua +++ b/src/http.lua | |||
@@ -338,16 +338,16 @@ function Private.send_request(sock, method, uri, headers, body_cb) | |||
338 | err = Private.try_send(sock, method .. " " .. uri .. " HTTP/1.1\r\n") | 338 | err = Private.try_send(sock, method .. " " .. uri .. " HTTP/1.1\r\n") |
339 | if err then return err end | 339 | if err then return err end |
340 | -- if there is a request message body, add content-length header | 340 | -- if there is a request message body, add content-length header |
341 | if body_cb then | 341 | chunk, size = body_cb() |
342 | chunk, size = body_cb() | 342 | if type(chunk) == "string" and type(size) == "number" then |
343 | if type(chunk) == "string" and type(size) == "number" then | 343 | if size > 0 then |
344 | headers["content-length"] = tostring(size) | 344 | headers["content-length"] = tostring(size) |
345 | else | 345 | end |
346 | sock:close() | 346 | else |
347 | if not chunk and type(size) == "string" then return size | 347 | sock:close() |
348 | else return "invalid callback return" end | 348 | if not chunk and type(size) == "string" then return size |
349 | end | 349 | else return "invalid callback return" end |
350 | end | 350 | end |
351 | -- send request headers | 351 | -- send request headers |
352 | err = Private.send_headers(sock, headers) | 352 | err = Private.send_headers(sock, headers) |
353 | if err then return err end | 353 | if err then return err end |
@@ -505,7 +505,10 @@ end | |||
505 | ----------------------------------------------------------------------------- | 505 | ----------------------------------------------------------------------------- |
506 | function Private.build_request(data) | 506 | function Private.build_request(data) |
507 | local request = {} | 507 | local request = {} |
508 | if type(data) == "table" then for i, v in data do request[i] = v end | 508 | if type(data) == "table" then |
509 | for i, v in data | ||
510 | do request[i] = v | ||
511 | end | ||
509 | else request.url = data end | 512 | else request.url = data end |
510 | return request | 513 | return request |
511 | end | 514 | end |
@@ -613,18 +616,11 @@ end | |||
613 | ----------------------------------------------------------------------------- | 616 | ----------------------------------------------------------------------------- |
614 | function Public.request(request) | 617 | function Public.request(request) |
615 | local response = {} | 618 | local response = {} |
616 | if request.body then | 619 | request.body_cb = socket.callback.send_string(request.body) |
617 | request.body_cb = function() | 620 | local concat = socket.concat.create() |
618 | return request.body, string.len(request.body) | 621 | response.body_cb = socket.callback.receive_concat(concat) |
619 | end | ||
620 | end | ||
621 | local cat = socket.concat.create() | ||
622 | response.body_cb = function(chunk, err) | ||
623 | if chunk then cat:addstring(chunk) end | ||
624 | return 1 | ||
625 | end | ||
626 | response = Public.request_cb(request, response) | 622 | response = Public.request_cb(request, response) |
627 | response.body = cat:getresult() | 623 | response.body = concat:getresult() |
628 | response.body_cb = nil | 624 | response.body_cb = nil |
629 | return response | 625 | return response |
630 | end | 626 | end |
diff --git a/src/luasocket.c b/src/luasocket.c index 96deac1..9be5595 100644 --- a/src/luasocket.c +++ b/src/luasocket.c | |||
@@ -56,6 +56,7 @@ LUASOCKET_API int luaopen_socket(lua_State *L) | |||
56 | #include "concat.lch" | 56 | #include "concat.lch" |
57 | #include "code.lch" | 57 | #include "code.lch" |
58 | #include "url.lch" | 58 | #include "url.lch" |
59 | #include "callback.lch" | ||
59 | #include "smtp.lch" | 60 | #include "smtp.lch" |
60 | #include "ftp.lch" | 61 | #include "ftp.lch" |
61 | #include "http.lch" | 62 | #include "http.lch" |
@@ -64,6 +65,7 @@ LUASOCKET_API int luaopen_socket(lua_State *L) | |||
64 | lua_dofile(L, "concat.lua"); | 65 | lua_dofile(L, "concat.lua"); |
65 | lua_dofile(L, "code.lua"); | 66 | lua_dofile(L, "code.lua"); |
66 | lua_dofile(L, "url.lua"); | 67 | lua_dofile(L, "url.lua"); |
68 | lua_dofile(L, "callback.lua"); | ||
67 | lua_dofile(L, "smtp.lua"); | 69 | lua_dofile(L, "smtp.lua"); |
68 | lua_dofile(L, "ftp.lua"); | 70 | lua_dofile(L, "ftp.lua"); |
69 | lua_dofile(L, "http.lua"); | 71 | lua_dofile(L, "http.lua"); |