X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcontrol%2Ftelnet.c;h=4efdfc9b43012bdfbd2c083befecad4ac34f876a;hb=70db1cf54fadb21898f5228e83e3aaefdae463e4;hp=6f1c2dc0359e1c8a27ff2a1f4b5836e45166f083;hpb=fdf8881ad94f565c0540161469613bc69ed821a8;p=vlc diff --git a/modules/control/telnet.c b/modules/control/telnet.c index 6f1c2dc035..4efdfc9b43 100644 --- a/modules/control/telnet.c +++ b/modules/control/telnet.c @@ -26,7 +26,12 @@ * Preamble *****************************************************************************/ -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include #include #include @@ -43,7 +48,7 @@ #ifdef HAVE_UNISTD_H # include #endif -#ifdef HAVE_POLL_H +#ifdef HAVE_POLL # include #endif @@ -89,13 +94,13 @@ vlc_module_begin(); set_category( CAT_INTERFACE ); set_subcategory( SUBCAT_INTERFACE_CONTROL ); add_string( "telnet-host", "", NULL, TELNETHOST_TEXT, - TELNETHOST_LONGTEXT, VLC_TRUE ); + TELNETHOST_LONGTEXT, true ); add_integer( "telnet-port", TELNETPORT_DEFAULT, NULL, TELNETPORT_TEXT, - TELNETPORT_LONGTEXT, VLC_TRUE ); + TELNETPORT_LONGTEXT, true ); add_password( "telnet-password", TELNETPWD_DEFAULT, NULL, TELNETPWD_TEXT, - TELNETPWD_LONGTEXT, VLC_TRUE ); - set_description( _("VLM remote control interface") ); - add_category_hint( "VLM", NULL, VLC_FALSE ); + TELNETPWD_LONGTEXT, true ); + set_description( N_("VLM remote control interface") ); + add_category_hint( "VLM", NULL, false ); set_capability( "interface", 0 ); set_callbacks( Open , Close ); vlc_module_end(); @@ -181,18 +186,24 @@ static int Open( vlc_object_t *p_this ) psz_address = config_GetPsz( p_intf, "telnet-host" ); vlc_UrlParse(&url, psz_address, 0); + free( psz_address ); // There might be two ports given, resolve any potentially // conflict url.i_port = getPort(p_intf, url, i_telnetport); p_intf->p_sys = malloc( sizeof( intf_sys_t ) ); - if( ( p_intf->p_sys->pi_fd = net_ListenTCP( p_intf, url.psz_host, url.i_port ) ) - == NULL ) + if( !p_intf->p_sys ) + { + vlm_Delete( p_intf->p_sys->mediatheque ); + vlc_UrlClean( &url ); + return VLC_ENOMEM; + } + if( ( p_intf->p_sys->pi_fd = net_ListenTCP( p_intf, url.psz_host, url.i_port ) ) == NULL ) { msg_Err( p_intf, "cannot listen for telnet" ); - vlc_UrlClean(&url); - free( psz_address ); + vlm_Delete( p_intf->p_sys->mediatheque ); + vlc_UrlClean( &url ); free( p_intf->p_sys ); return VLC_EGENERIC; } @@ -205,8 +216,7 @@ static int Open( vlc_object_t *p_this ) p_intf->p_sys->mediatheque = mediatheque; p_intf->pf_run = Run; - vlc_UrlClean(&url); - free( psz_address ); + vlc_UrlClean( &url ); return VLC_SUCCESS; } @@ -223,10 +233,10 @@ static void Close( vlc_object_t *p_this ) { telnet_client_t *cl = p_sys->clients[i]; net_Close( cl->fd ); + free( cl->buffer_write ); free( cl ); - p_sys->clients[i] = NULL; } - if( p_sys->clients != NULL ) free( p_sys->clients ); + free( p_sys->clients ); net_ListenClose( p_sys->pi_fd ); @@ -371,7 +381,7 @@ static void Run( intf_thread_t *p_intf ) cl->i_mode + 2 ); } - if (i_recv <= 0) + if (i_recv <= 0 && ( end || errno != EAGAIN ) ) goto drop; } } @@ -414,6 +424,7 @@ static void Run( intf_thread_t *p_intf ) net_Close( cl->fd ); TAB_REMOVE( p_intf->p_sys->i_clients , p_intf->p_sys->clients , cl ); + free( cl->buffer_write ); free( cl ); } else if( !strncmp( cl->buffer_read, "shutdown", 8 ) ) @@ -477,7 +488,6 @@ static void Run( intf_thread_t *p_intf ) } Write_message( cl, message, NULL, WRITE_MODE_CMD ); vlm_MessageDelete( message ); - } } } @@ -490,7 +500,7 @@ static void Run( intf_thread_t *p_intf ) if (ufd[ncli + i].revents == 0) continue; - fd = accept (ufd[ncli + i].fd, NULL, NULL); + fd = net_AcceptSingle (VLC_OBJECT(p_intf), ufd[ncli + i].fd); if (fd == -1) continue; @@ -511,8 +521,7 @@ static void Run( intf_thread_t *p_intf ) TAB_APPEND( p_sys->i_clients, p_sys->clients, cl ); } } - if( psz_password ) - free( psz_password ); + free( psz_password ); } static void Write_message( telnet_client_t *client, vlm_message_t *message, @@ -522,7 +531,7 @@ static void Write_message( telnet_client_t *client, vlm_message_t *message, client->p_buffer_read = client->buffer_read; (client->p_buffer_read)[0] = 0; // if (cl->p_buffer_read)[0] = '\n' - if( client->buffer_write ) free( client->buffer_write ); + free( client->buffer_write ); /* generate the psz_message string */ if( message )