UPnP = {}
local DebugFlag = false
local Server = "Linux/3.9 DLNADOC/1.50 UPnP/1.0 OctopusNet-DMS/1.0"
if DisableDLNA then
Server = "Linux/3.9 UPnP/1.0 OctopusNet-DMS/1.0"
end
function UPnP:SetDebug(f)
DebugFlag = f
end
UPnP.Server = Server
function UPnP:ParseHTTPHeader(header)
local linenum = 0
local method,path,proto
local attributes = {}
for line in string.gmatch(header,"(.-)\r\n") do
if not line then break end
if DebugFlag then print(string.format("%2d:%s",linenum,line)) end
if linenum == 0 then
method,path,proto = string.match(line,"(.+)%s+(.+)%s+(.+)")
else
local n,v = string.match(line,"([%a%-]+)%s*%:%s*(.*)")
if n and v then
attributes[string.upper(n)] = v
end
end
linenum = linenum + 1
end
return method,path,proto,attributes
end
function UPnP:ReadHTTPHeader(client)
local linenum = 0
local line, err = client:receive()
if err then
if DebugFlag then print("HTTPHeader Error "..err) end
return
end
if DebugFlag then print(string.format("%2d:%s",linenum,line)) end
local method,path,proto = string.match(line,"(.+)%s+(.+)%s+(.+)")
local attributes = {}
while true do
local line, err = client:receive()
if err then
if DebugFlag then print("HTTPHeader Error "..err.." HTTP Line: "..tostring(linenum)) end
return
end
linenum = linenum + 1
if DebugFlag then print(string.format("%2d:%s",linenum,line)) end
if line == "" then break end
if linenum == 30 then
if DebugFlag then print("HTTPHeader Error "..tostring(linenum)) end
return
end
local n,v = string.match(line,"([%a%-]+)%s*%:%s*(.*)")
if n and v then
attributes[string.upper(n)] = v
end
end
-- Add some preparsed params, Note lower case key
if attributes["HOST"] then
local Host,Port = string.match(attributes["HOST"],"(.+)%:(%d+)")
attributes["host"] = Host
attributes["port"] = Port
end
return method,path,proto,attributes
end
function UPnP:ReadHTTPBody(client,clen)
local Body = ""
local linenum = 0
if DebugFlag and clen then print(string.format("---- Length = %d",clen)) end
Body, err = client:receive(clen)
if err then
if DebugFlag then print("HTTPBody Error "..err) end
return
end
-- while true do
-- local line, err = client:receive()
-- if err then
-- if DebugFlag then print("Error "..err) end
-- return
-- end
-- linenum = linenum + 1
-- if DebugFlag then print(string.format("%4d:%s",linenum,line)) end
-- if line == "" then break end
-- if linenum == 300 then
-- if DebugFlag then print("Error "..linenum) end
-- return
-- end
-- Body = Body .. line .. "\n"
-- end
return Body
end
function UPnP:ParseInvocation(soap,Service)
end
function UPnP:CreateResponse(Service,Action,Args)
local n,v
local soap = ''..'\r\n'
.. "