]> git.sesse.net Git - vlc/blobdiff - modules/control/telnet.c
Todo for prefs widgets
[vlc] / modules / control / telnet.c
index 81e4cbf1728f6fec6c5788b189cdd5769fb44574..ce0f45c250115e2b6e4732a3af0fbd19e9f98d80 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * telnet.c: VLM interface plugin
  *****************************************************************************
- * Copyright (C) 2000-2005 the VideoLAN team
+ * Copyright (C) 2000-2006 the VideoLAN team
  * $Id$
  *
  * Authors: Simon Latapie <garf@videolan.org>
@@ -19,7 +19,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
 #   include <unistd.h>
 #endif
 
-#if defined( UNDER_CE )
-#   include <winsock.h>
-#elif defined( WIN32 )
-#   include <winsock2.h>
-#else
-#   include <sys/socket.h>
-#endif
-
 #include "network.h"
+#include "vlc_url.h"
 
 #include "vlc_vlm.h"
 
 static int  Open ( vlc_object_t * );
 static void Close( vlc_object_t * );
 
-#define TELNETHOST_TEXT N_( "Telnet Interface host" )
-#define TELNETHOST_LONGTEXT N_( "Default to listen on all network interfaces" )
-#define TELNETHOST_DEFAULT "0.0.0.0"
-#define TELNETPORT_TEXT N_( "Telnet Interface port" )
-#define TELNETPORT_LONGTEXT N_( "Default to 4212" )
+#define TELNETHOST_TEXT N_( "Host" )
+#define TELNETHOST_LONGTEXT N_( "This is the host on which the " \
+    "interface will listen. It defaults to all network interfaces (0.0.0.0)." \
+    " If you want this interface to be available only on the local " \
+    "machine, enter \"127.0.0.1\"." )
+#define TELNETPORT_TEXT N_( "Port" )
+#define TELNETPORT_LONGTEXT N_( "This is the TCP port on which this " \
+    "interface will listen. It defaults to 4212." )
 #define TELNETPORT_DEFAULT 4212
-#define TELNETPWD_TEXT N_( "Telnet Interface password" )
-#define TELNETPWD_LONGTEXT N_( "Default to admin" )
+#define TELNETPWD_TEXT N_( "Password" )
+#define TELNETPWD_LONGTEXT N_( "A single administration password is used " \
+    "to protect this interface. The default value is \"admin\"." )
 #define TELNETPWD_DEFAULT "admin"
 
 vlc_module_begin();
     set_shortname( "Telnet" );
     set_category( CAT_INTERFACE );
-    set_subcategory( SUBCAT_INTERFACE_GENERAL );
-    add_string( "telnet-host", TELNETHOST_DEFAULT, NULL, TELNETHOST_TEXT,
+    set_subcategory( SUBCAT_INTERFACE_CONTROL );
+    add_string( "telnet-host", "", NULL, TELNETHOST_TEXT,
                  TELNETHOST_LONGTEXT, VLC_TRUE );
     add_integer( "telnet-port", TELNETPORT_DEFAULT, NULL, TELNETPORT_TEXT,
                  TELNETPORT_LONGTEXT, VLC_TRUE );
@@ -111,10 +108,10 @@ typedef struct
 {
     int        i_mode; /* read or write */
     int        fd;
-    uint8_t    buffer_read[1000]; // 1000 byte per command should be sufficient
+    char       buffer_read[1000]; // 1000 byte per command should be sufficient
     char      *buffer_write;
-    uint8_t   *p_buffer_read;
-    uint8_t   *p_buffer_write; // the position in the buffer
+    char      *p_buffer_read;
+    char      *p_buffer_write; // the position in the buffer
     int        i_buffer_write; // the number of byte we still have to send
     int        i_tel_cmd; // for specific telnet commands
 
@@ -140,7 +137,7 @@ struct intf_sys_t
  * option is missing from --telnet-host.
  */
 static int getPort(intf_thread_t *p_intf, vlc_url_t url, int i_port)
-    {
+{
     // Print error if two different ports have been specified
     if (url.i_port != 0  &&
         i_port != TELNETPORT_DEFAULT && 
@@ -157,7 +154,6 @@ static int getPort(intf_thread_t *p_intf, vlc_url_t url, int i_port)
     {
            return url.i_port;
     }
-    // return default
     return i_port;
 }
 
@@ -178,7 +174,7 @@ static int Open( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
-    msg_Info( p_intf, "Using the VLM interface plugin..." );
+    msg_Info( p_intf, "using the VLM interface plugin..." );
 
     i_telnetport = config_GetInt( p_intf, "telnet-port" );
     psz_address  = config_GetPsz( p_intf, "telnet-host" );
@@ -194,18 +190,22 @@ static int Open( vlc_object_t *p_this )
                 == NULL )
     {
         msg_Err( p_intf, "cannot listen for telnet" );
+        vlc_UrlClean(&url);
+        free( psz_address );
         free( p_intf->p_sys );
         return VLC_EGENERIC;
     }
     msg_Info( p_intf, 
-              "Telnet interface started on interface %s %d",
-             url.psz_host, url.i_port );
+              "telnet interface started on interface %s %d",
+              url.psz_host, url.i_port );
 
     p_intf->p_sys->i_clients   = 0;
     p_intf->p_sys->clients     = NULL;
     p_intf->p_sys->mediatheque = mediatheque;
     p_intf->pf_run = Run;
 
+    vlc_UrlClean(&url);
+    free( psz_address );
     return VLC_SUCCESS;
 }
 
@@ -271,7 +271,7 @@ static void Run( intf_thread_t *p_intf )
             cl->fd = fd;
             cl->buffer_write = NULL;
             cl->p_buffer_write = cl->buffer_write;
-            Write_message( cl, NULL, "Password:\xff\xfb\x01", WRITE_MODE_PWD );
+            Write_message( cl, NULL, "Password: \xff\xfb\x01", WRITE_MODE_PWD );
 
             TAB_APPEND( p_sys->i_clients, p_sys->clients, cl );
         }
@@ -336,7 +336,7 @@ static void Run( intf_thread_t *p_intf )
                     switch( cl->i_tel_cmd )
                     {
                     case 0:
-                        switch( *cl->p_buffer_read )
+                        switch( *(uint8_t *)cl->p_buffer_read )
                         {
                         case '\r':
                             break;
@@ -354,7 +354,7 @@ static void Run( intf_thread_t *p_intf )
                         }
                         break;
                     case 1:
-                        switch( *cl->p_buffer_read )
+                        switch( *(uint8_t *)cl->p_buffer_read )
                         {
                         case TEL_WILL: case TEL_WONT:
                         case TEL_DO: case TEL_DONT:
@@ -414,7 +414,8 @@ static void Run( intf_thread_t *p_intf )
                 else
                 {
                     /* wrong password */
-                    Write_message( cl, NULL, "\r\nWrong password. ",
+                    Write_message( cl, NULL,
+                                   "\r\nWrong password.\r\nPassword: ",
                                    WRITE_MODE_PWD );
                 }
             }
@@ -496,11 +497,12 @@ static char *MessageToString( vlm_message_t *message, int i_level )
     else if( !i_level && !message->i_child && !message->psz_value  )
     {
         /* A command is successful. Don't write anything */
-        return strdup( STRING_CR STRING_TAIL );
+        return strdup( /*STRING_CR*/ STRING_TAIL );
     }
 
     i_message += strlen( message->psz_name ) + i_level * sizeof( "    " ) + 1;
-    psz_message = malloc( i_message ); *psz_message = 0;
+    psz_message = malloc( i_message );
+    *psz_message = 0;
     for( i = 0; i < i_level; i++ ) strcat( psz_message, "    " );
     strcat( psz_message, message->psz_name );