aboutsummaryrefslogtreecommitdiff
path: root/etc/tftp.lua
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-11-27 07:58:04 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-11-27 07:58:04 +0000
commit7c97e8e40aaa665226fb54449773dc3134e755b2 (patch)
tree47888d4c924fc24bf3b355bf58120ea3cdc74bc4 /etc/tftp.lua
parenteb0fc857ddea6f084d338589e2a33d3e7d4eade6 (diff)
downloadluasocket-7c97e8e40aaa665226fb54449773dc3134e755b2.tar.gz
luasocket-7c97e8e40aaa665226fb54449773dc3134e755b2.tar.bz2
luasocket-7c97e8e40aaa665226fb54449773dc3134e755b2.zip
Almost ready for beta3
Diffstat (limited to 'etc/tftp.lua')
-rw-r--r--etc/tftp.lua17
1 files changed, 12 insertions, 5 deletions
diff --git a/etc/tftp.lua b/etc/tftp.lua
index f4af8bc..83a08b9 100644
--- a/etc/tftp.lua
+++ b/etc/tftp.lua
@@ -8,11 +8,14 @@
8----------------------------------------------------------------------------- 8-----------------------------------------------------------------------------
9-- Load required files 9-- Load required files
10----------------------------------------------------------------------------- 10-----------------------------------------------------------------------------
11local base = require("base")
12local table = require("table")
13local math = require("math")
14local string = require("string")
11local socket = require("socket") 15local socket = require("socket")
12local ltn12 = require("ltn12") 16local ltn12 = require("ltn12")
13local url = require("socket.url") 17local url = require("socket.url")
14 18local tftp = module("socket.tftp")
15module("socket.tftp")
16 19
17----------------------------------------------------------------------------- 20-----------------------------------------------------------------------------
18-- Program constants 21-- Program constants
@@ -73,16 +76,18 @@ end
73local function tget(gett) 76local function tget(gett)
74 local retries, dgram, sent, datahost, dataport, code 77 local retries, dgram, sent, datahost, dataport, code
75 local last = 0 78 local last = 0
79 socket.try(gett.host, "missing host")
76 local con = socket.try(socket.udp()) 80 local con = socket.try(socket.udp())
77 local try = socket.newtry(function() con:close() end) 81 local try = socket.newtry(function() con:close() end)
78 -- convert from name to ip if needed 82 -- convert from name to ip if needed
79 gett.host = try(socket.dns.toip(gett.host)) 83 gett.host = try(socket.dns.toip(gett.host))
80 con:settimeout(1) 84 con:settimeout(1)
81 -- first packet gives data host/port to be used for data transfers 85 -- first packet gives data host/port to be used for data transfers
86 local path = string.gsub(gett.path or "", "^/", "")
87 path = url.unescape(path)
82 retries = 0 88 retries = 0
83 repeat 89 repeat
84 sent = try(con:sendto(RRQ(gett.path, "octet"), 90 sent = try(con:sendto(RRQ(path, "octet"), gett.host, gett.port))
85 gett.host, gett.port))
86 dgram, datahost, dataport = con:receivefrom() 91 dgram, datahost, dataport = con:receivefrom()
87 retries = retries + 1 92 retries = retries + 1
88 until dgram or datahost ~= "timeout" or retries > 5 93 until dgram or datahost ~= "timeout" or retries > 5
@@ -144,6 +149,8 @@ local function sget(u)
144end 149end
145 150
146get = socket.protect(function(gett) 151get = socket.protect(function(gett)
147 if type(gett) == "string" then return sget(gett) 152 if base.type(gett) == "string" then return sget(gett)
148 else return tget(gett) end 153 else return tget(gett) end
149end) 154end)
155
156base.setmetatable(tftp, nil)