Commit f5b8b43a authored by ivoire's avatar ivoire
Browse files

luatelnet: accept multiple commands seperated by '\n' or '\r'.

It was possible with the oldtelnet interface using something like
(echo admin ; echo help) | nc localhost 4212
That's now working with the lua one (but not the cleanest way).
parent ec87e89b
...@@ -183,39 +183,68 @@ while not vlc.misc.should_die() do ...@@ -183,39 +183,68 @@ while not vlc.misc.should_die() do
-- Handle reads -- Handle reads
for _, client in pairs(r) do for _, client in pairs(r) do
local str = client:recv(1000) local str = string.gsub(client:recv(1000),"\r","\n")
local done = false local done = false
if not str then -- the telnet client program has leave
-- the telnet client program has leave
if not str then
client.buffer = "quit" client.buffer = "quit"
done = true done = true
elseif string.match(str,"\n$") then
client.buffer = string.gsub(client.buffer..str,"\r?\n$","") -- Caught a ^D
done = true
elseif client.buffer == "" elseif client.buffer == ""
and ((client.type == host.client_type.stdio and str == "") and ((client.type == host.client_type.stdio and str == "")
or (client.type == host.client_type.net and str == "\004")) then or (client.type == host.client_type.net and str == "\004")) then
-- Caught a ^D
client.buffer = "quit" client.buffer = "quit"
done = true done = true
-- '\n' found: a command was sent
elseif string.match(str,"\n") then
client.buffer = client.buffer .. str
done = true
-- The command is not finished yet
else else
client.buffer = client.buffer .. str client.buffer = client.buffer .. str
end end
-- Some cleaning for telnet
if client.type == host.client_type.net then if client.type == host.client_type.net then
telnet_commands( client ) telnet_commands( client )
end end
-- If a command must be parsed
if done then if done then
if client.status == host.status.password then -- loop on all commands (might have more than one commands seperated by '\n'
if client.buffer == password then local returned_values = ""
client:send( IAC..WONT..ECHO.."\r\nWelcome, Master\r\n" ) while not (client.buffer == "") do
client.buffer = "" -- pick the first command
local commands = ""
if string.find(client.buffer, "\n") then
commands = string.sub(client.buffer, string.find(client.buffer, "\n") + 1)
client.buffer = string.sub(client.buffer, 0, string.find(client.buffer, "\n") - 1)
end
local cmd = client.buffer
if client.status == host.status.password then
if client.buffer == password then
client:send( IAC..WONT..ECHO.."\r\nWelcome, Master\r\n" )
client.buffer = ""
client:switch_status( host.status.write )
else
client:send( "\r\nWrong password\r\nPassword: " )
client.buffer = ""
end
elseif client_command( client ) then
client:switch_status( host.status.write ) client:switch_status( host.status.write )
else -- special case to exit the loop
client:send( "\r\nWrong password\r\nPassword: " ) if cmd == "quit" or cmd == "shutdown" then break end
client.buffer = ""
end end
elseif client_command( client ) then returned_values = returned_values .. client.buffer
client:switch_status( host.status.write ) client.buffer = commands
end end
vlc.msg.err("end of loop")
client.buffer = returned_values
end end
end end
end end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment