Starting to use RCS in princeton again. Not behind a firewall anymore.

This commit is contained in:
Diego Nehab 2003-08-31 00:58:07 +00:00
parent c51d4acf1c
commit 6789b83ff5
6 changed files with 58 additions and 60 deletions

20
LICENSE Normal file
View File

@ -0,0 +1,20 @@
LuaSocket 2.0 license
Copyright © 2003 Tecgraf, PUC-Rio.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

23
TODO
View File

@ -1,24 +1,8 @@
URL e URI eh a mesma coisa?
Check spelling
Fazer uma página com os exemplos.
Ajeitar links pras RFCs.
Usar DFN no lugar de <i> pra definiccoes.
Usar VAR pra argumentos?
Usar CODE pros trechos? funciona como PRE?
Usar PRE { margin-botton: 1em; } pra pular linha antes do </pre>
Trocar todos os <a name=bla> por <... id=bla>?
Make sure all .html are STRICT 4.01
Add license.txt.
Check RFC links.
Add lots of hyperlinks
Check all function names (must use . or :)
Make sure IPv4 goes away
The words function and method should follow the convention
Adjust dates in all files
Test the library on every system possible
Document socket.time and socket.sleep
Create the windows executable.
Implement time critical stuff from code module in C.
Add service name translation.
@ -26,7 +10,6 @@ Add service name translation.
Ajeitar o protocolo da lua_socketlibopen()...
- testar os options!
- testar em várias plataformas
- adicionar exemplos de expansão: pipe, local, named pipe
* O location do "redirect" pode ser relativo ao servidor atual (não pode,
@ -47,7 +30,6 @@ Ajeitar o protocolo da lua_socketlibopen()...
- checar operações em closed sockets
- checar teste de writable socket com select
- trocar IPv4 para networking ou ipc
- checar todos os metodos
- checar options em UDP
@ -58,4 +40,3 @@ Ajeitar o protocolo da lua_socketlibopen()...
- unix 92 bytes maximo no endereço, incluindo o zero
- unix 9216 maximo de datagram size

View File

@ -602,10 +602,12 @@ function Public.put_cb(request)
local control, err = Private.open(parsed)
if not control then return err end
local segment = Private.parse_path(parsed)
return Private.change_dir(control, segment) or
err = Private.change_dir(control, segment) or
Private.change_type(control, parsed.params) or
Private.upload(control, request, segment) or
Private.close(control)
if err then return nil, err
else return 1 end
end
-----------------------------------------------------------------------------
@ -616,15 +618,15 @@ end
-- type: "i" for "image" mode, "a" for "ascii" mode or "d" for directory
-- user: account user name
-- password: account password)
-- content: file contents
-- content: file contents
-- Returns
-- err: error message if any
-----------------------------------------------------------------------------
function Public.put(url_or_request, content)
local request = Private.build_request(url_or_request)
request.content_cb = function()
return content, string.len(content)
end
request.content = request.content or content
request.content_cb = socket.callback.send_string(request.content)
return Public.put_cb(request)
end
@ -641,12 +643,9 @@ end
-- err: error message in case of error, nil otherwise
-----------------------------------------------------------------------------
function Public.get(url_or_request)
local cat = socket.concat.create()
local concat = socket.concat.create()
local request = Private.build_request(url_or_request)
request.content_cb = function(chunk, err)
if chunk then cat:addstring(chunk) end
return 1
end
request.content_cb = socket.callback.receive_concat(concat)
local err = Public.get_cb(request)
return cat:getresult(), err
return concat:getresult(), err
end

View File

@ -338,16 +338,16 @@ function Private.send_request(sock, method, uri, headers, body_cb)
err = Private.try_send(sock, method .. " " .. uri .. " HTTP/1.1\r\n")
if err then return err end
-- if there is a request message body, add content-length header
if body_cb then
chunk, size = body_cb()
if type(chunk) == "string" and type(size) == "number" then
headers["content-length"] = tostring(size)
else
sock:close()
if not chunk and type(size) == "string" then return size
else return "invalid callback return" end
end
end
chunk, size = body_cb()
if type(chunk) == "string" and type(size) == "number" then
if size > 0 then
headers["content-length"] = tostring(size)
end
else
sock:close()
if not chunk and type(size) == "string" then return size
else return "invalid callback return" end
end
-- send request headers
err = Private.send_headers(sock, headers)
if err then return err end
@ -505,7 +505,10 @@ end
-----------------------------------------------------------------------------
function Private.build_request(data)
local request = {}
if type(data) == "table" then for i, v in data do request[i] = v end
if type(data) == "table" then
for i, v in data
do request[i] = v
end
else request.url = data end
return request
end
@ -613,18 +616,11 @@ end
-----------------------------------------------------------------------------
function Public.request(request)
local response = {}
if request.body then
request.body_cb = function()
return request.body, string.len(request.body)
end
end
local cat = socket.concat.create()
response.body_cb = function(chunk, err)
if chunk then cat:addstring(chunk) end
return 1
end
request.body_cb = socket.callback.send_string(request.body)
local concat = socket.concat.create()
response.body_cb = socket.callback.receive_concat(concat)
response = Public.request_cb(request, response)
response.body = cat:getresult()
response.body = concat:getresult()
response.body_cb = nil
return response
end

View File

@ -56,6 +56,7 @@ LUASOCKET_API int luaopen_socket(lua_State *L)
#include "concat.lch"
#include "code.lch"
#include "url.lch"
#include "callback.lch"
#include "smtp.lch"
#include "ftp.lch"
#include "http.lch"
@ -64,6 +65,7 @@ LUASOCKET_API int luaopen_socket(lua_State *L)
lua_dofile(L, "concat.lua");
lua_dofile(L, "code.lua");
lua_dofile(L, "url.lua");
lua_dofile(L, "callback.lua");
lua_dofile(L, "smtp.lua");
lua_dofile(L, "ftp.lua");
lua_dofile(L, "http.lua");

View File

@ -47,9 +47,9 @@ check(not back and err == e, err)
io.write("testing anonymous file upload: ")
os.remove("/var/ftp/pub/index.up.html")
err = socket.ftp.put("ftp://localhost/pub/index.up.html;type=i", index)
ret, err = socket.ftp.put("ftp://localhost/pub/index.up.html;type=i", index)
saved = readfile("/var/ftp/pub/index.up.html")
check(not err and saved == index, err)
check(ret and not err and saved == index, err)
io.write("testing anonymous file download: ")
back, err = socket.ftp.get("ftp://localhost/pub/index.up.html;type=i")
@ -65,9 +65,9 @@ check(not err and back == index, err)
io.write("testing authenticated upload: ")
os.remove("/home/luasocket/index.up.html")
err = socket.ftp.put("ftp://luasocket:password@localhost/index.up.html;type=i", index)
ret, err = socket.ftp.put("ftp://luasocket:password@localhost/index.up.html;type=i", index)
saved = readfile("/home/luasocket/index.up.html")
check(not err and saved == index, err)
check(ret and not err and saved == index, err)
io.write("testing authenticated download: ")
back, err = socket.ftp.get("ftp://luasocket:password@localhost/index.up.html;type=i")
@ -97,13 +97,13 @@ back, err = socket.ftp.get("ftp://localhost/pub;type=d")
check(similar(back, expected))
io.write("testing upload denial: ")
err = socket.ftp.put("ftp://localhost/index.up.html;type=a", index)
ret, err = socket.ftp.put("ftp://localhost/index.up.html;type=a", index)
check(err, err)
io.write("testing authentication failure: ")
err = socket.ftp.put("ftp://luasocket:wrong@localhost/index.html;type=a", index)
ret, err = socket.ftp.put("ftp://luasocket:wrong@localhost/index.html;type=a", index)
print(err)
check(err, err)
check(not ret and err, err)
io.write("testing wrong file: ")
back, err = socket.ftp.get("ftp://localhost/index.wrong.html;type=a")