[vlc-commits] commit: luatelnet: really add the possibility to pipe commands into the telnet interface. ( Rémi Duraffort )

git at videolan.org git at videolan.org
Thu Jul 15 18:41:25 CEST 2010


vlc/vlc-1.1 | branch: master | Rémi Duraffort <ivoire at videolan.org> | Sat Jul 10 20:05:58 2010 +0200| [62fccadace3b443232a6aaa13dab71ab88d8204c] | committer: Rémi Duraffort 

luatelnet: really add the possibility to pipe commands into the telnet interface.
(cherry picked from commit 71ed5a7b8e5844d54c2279e06993b5161b6f2689)

Signed-off-by: Rémi Duraffort <ivoire at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-1.1.git/?a=commit;h=62fccadace3b443232a6aaa13dab71ab88d8204c
---

 share/lua/intf/modules/host.lua |    1 +
 share/lua/intf/telnet.lua       |   31 +++++++++++++++++++------------
 2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/share/lua/intf/modules/host.lua b/share/lua/intf/modules/host.lua
index b6c06ba..46e422b 100644
--- a/share/lua/intf/modules/host.lua
+++ b/share/lua/intf/modules/host.lua
@@ -159,6 +159,7 @@ function host()
                          wfd = wfd or fd,
                          status = status.init,
                          buffer = "",
+                         cmds = "",
                          type = t,
                          -- methods
                          fd = fd_client,
diff --git a/share/lua/intf/telnet.lua b/share/lua/intf/telnet.lua
index a72d4b1..67cc0cc 100644
--- a/share/lua/intf/telnet.lua
+++ b/share/lua/intf/telnet.lua
@@ -183,27 +183,33 @@ while not vlc.misc.should_die() do
 
     -- Handle reads
     for _, client in pairs(r) do
-        local str = client:recv(1000)
-        local done = false
+        local str = client.cmds .. string.gsub(client:recv(1000), "\r", "\n")
+
         if not str then -- the telnet client program has leave
-            client.buffer = "quit"
-            done = true
-        elseif string.match(str,"\n$") then
-            client.buffer = string.gsub(client.buffer..str,"\r?\n$","")
-            done = true
+            client.cmds = "quit"
+        elseif string.match(str,"\n") then
+            client.cmds = str
         elseif client.buffer == ""
            and ((client.type == host.client_type.stdio and str == "")
            or  (client.type == host.client_type.net and str == "\004")) then
             -- Caught a ^D
-            client.buffer = "quit"
-            done = true
-        else
-            client.buffer = client.buffer .. str
+            client.cmds = "quit"
         end
         if client.type == host.client_type.net then
             telnet_commands( client )
         end
-        if done then
+
+        client.buffer = ""
+        -- split the command at the first '\n'
+        while string.find(client.cmds, "\n") do
+            -- save the buffer to send to the client
+            local saved_buffer = client.buffer
+
+            -- get the next command
+            local index = string.find(client.cmds, "\n")
+            client.buffer = string.gsub(string.sub(client.cmds, 0, index - 1), "^%s*(.-)%s*$", "%1")
+            client.cmds = string.sub(client.cmds, index + 1)
+
             if client.status == host.status.password then
                 if client.buffer == password then
                     client:send( IAC..WONT..ECHO.."\r\nWelcome, Master\r\n" )
@@ -216,6 +222,7 @@ while not vlc.misc.should_die() do
             elseif client_command( client ) then
                 client:switch_status( host.status.write )
             end
+            client.buffer = saved_buffer .. client.buffer
         end
     end
 end



More information about the vlc-commits mailing list