Commit 635d823d authored by Gildas Bazin's avatar Gildas Bazin

* src/misc/vlm.c: reformat help message.

* modules/control/telnet.c: "\n" -> "\r\n" + cleanup.
parent b0e65984
......@@ -110,8 +110,8 @@ typedef struct
} telnet_client_t;
static char* MessageToString( vlm_message_t* , int );
static void Write_message( telnet_client_t * , vlm_message_t* , char * , int );
static char *MessageToString( vlm_message_t *, int );
static void Write_message( telnet_client_t *, vlm_message_t *, char *, int );
struct intf_sys_t
{
......@@ -325,7 +325,7 @@ static void Run( intf_thread_t *p_intf )
if( cl->p_buffer_read - cl->buffer_read == 999 )
{
Write_message( cl, NULL, "Line too long\n",
Write_message( cl, NULL, "Line too long\r\n",
cl->i_mode + 2 );
}
}
......@@ -392,8 +392,8 @@ static void Run( intf_thread_t *p_intf )
}
}
static void Write_message( telnet_client_t * client, vlm_message_t * message,
char * string_message, int i_mode )
static void Write_message( telnet_client_t *client, vlm_message_t *message,
char *string_message, int i_mode )
{
char *psz_message;
......@@ -402,73 +402,75 @@ static void Write_message( telnet_client_t * client, vlm_message_t * message,
if( client->buffer_write ) free( client->buffer_write );
/* generate the psz_message string */
if( message != NULL ) /* ok, look for vlm_message_t */
if( message )
{
psz_message = MessageToString( message , 0 );
psz_message = realloc( psz_message , strlen( psz_message ) +
strlen( "\r\n> " ) + 1 );
strcat( psz_message , "\r\n> " );
/* ok, look for vlm_message_t */
psz_message = MessageToString( message, 0 );
}
else /* it is a basic string_message */
else
{
/* it is a basic string_message */
psz_message = strdup( string_message );
}
client->buffer_write = malloc( strlen( psz_message ) + 1 );
strcpy( client->buffer_write , psz_message );
client->p_buffer_write = client->buffer_write;
client->buffer_write = client->p_buffer_write = psz_message;
client->i_buffer_write = strlen( psz_message );
client->i_mode = i_mode;
free( psz_message );
}
/* we need the level of the message to put a beautiful indentation.
first level is 0 */
static char* MessageToString( vlm_message_t* message , int i_level )
/* We need the level of the message to put a beautiful indentation.
* first level is 0 */
static char *MessageToString( vlm_message_t *message, int i_level )
{
int i;
#define STRING_CR "\r\n"
#define STRING_TAIL "> "
char *psz_message;
int i, i_message = sizeof( STRING_TAIL );
if( message == NULL )
if( !message || !message->psz_name )
{
return strdup( "" );
return strdup( STRING_CR STRING_TAIL );
}
else if( i_level == 0 && message->i_child == 0 &&
message->psz_value == NULL ) /* a command is successful */
else if( !i_level && !message->i_child && !message->psz_value )
{
/* don't write anything */
return strdup( "" );
/* A command is successful. Don't write anything */
return strdup( STRING_CR STRING_TAIL );
}
i_message += strlen( message->psz_name ) + i_level * sizeof( " " ) + 1;
psz_message = malloc( i_message ); *psz_message = 0;
for( i = 0; i < i_level; i++ ) strcat( psz_message, " " );
strcat( psz_message, message->psz_name );
if( message->psz_value )
{
i_message += sizeof( " : " ) + strlen( message->psz_value ) +
sizeof( STRING_CR );
psz_message = realloc( psz_message, i_message );
strcat( psz_message, " : " );
strcat( psz_message, message->psz_value );
strcat( psz_message, STRING_CR );
}
else
{
psz_message = strdup( "" );
psz_message = realloc( psz_message, strlen( psz_message ) +
strlen( message->psz_name ) + i_level * 4 + 1 );
for( i = 0 ; i < i_level ; i++ )
{
strcat( psz_message , " " );
}
strcat( psz_message , message->psz_name );
if( message->psz_value )
{
psz_message = realloc( psz_message, strlen( psz_message ) +
strlen( message->psz_value ) + 3 + 1 );
strcat( psz_message, " : " );
strcat( psz_message, message->psz_value );
}
i_message += sizeof( STRING_CR );
psz_message = realloc( psz_message, i_message );
strcat( psz_message, STRING_CR );
}
for( i = 0 ; i < message->i_child ; i++ )
{
char *child_message =
MessageToString( message->child[i], i_level + 1 );
psz_message = realloc( psz_message, strlen( psz_message ) +
strlen( child_message ) + 2 + 1 );
strcat( psz_message, "\r\n" );
strcat( psz_message, child_message );
free( child_message );
}
for( i = 0; i < message->i_child; i++ )
{
char *child_message =
MessageToString( message->child[i], i_level + 1 );
return psz_message;
i_message += strlen( child_message );
psz_message = realloc( psz_message, i_message );
strcat( psz_message, child_message );
free( child_message );
}
if( i_level == 0 ) strcat( psz_message, STRING_TAIL );
return psz_message;
}
......@@ -659,8 +659,8 @@ static int ExecuteCommand(vlm_t *vlm, char *command, vlm_message_t **p_message)
else
{
vlm_MediaSetup( vlm, media, p_command[i],
p_command[i+1] );
i++;
p_command[i+1] );
i++;
}
}
else if( strcmp( p_command[i], "loop" ) == 0 ||
......@@ -1715,37 +1715,48 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_t *media,
static vlm_message_t *vlm_Help( vlm_t *vlm, char *psz_filter )
{
vlm_message_t *message;
vlm_message_t *message, *message_child;
#define MessageAdd( a ) \
vlm_MessageAdd( message, vlm_MessageNew( a, NULL ) );
#define MessageAddChild( a ) \
vlm_MessageAdd( message_child, vlm_MessageNew( a, NULL ) );
if( psz_filter == NULL )
{
char *help= strdup(
"Commands Syntax:"
"\n new (name) vod|broadcast|schedule [properties]"
"\n setup (name) (properties)"
"\n show [(name)|media|schedule]"
"\n del (name)|all|media|schedule"
"\n control (name) (command)"
"\n save (config_file)"
"\n load (config_file)"
"\nMedia Proprieties Syntax:"
"\n input (input_name)"
"\n output (output_name)"
"\n option (option_name)[=value]"
"\n enabled|disabled"
"\n loop|unloop (broadcast only)"
"\nSchedule Proprieties Syntax:"
"\n enabled|disabled"
"\n append (command_until_rest_of_the_line)"
"\n date (year)/(month)/(day)-(hour):(minutes):(seconds)|now"
"\n period (years_aka_12_months)/(months_aka_30_days)/(days)-(hours):(minutes):(seconds)"
"\n repeat (number_of_repetitions)"
"\nControl Commands Syntax:"
"\n play\n pause\n stop\n seek (percentage)\n" );
message = vlm_MessageNew( "help", NULL );
vlm_MessageAdd( message, vlm_MessageNew( "Help", help ) );
free( help );
message_child = MessageAdd( "Commands Syntax:" );
MessageAddChild( "new (name) vod|broadcast|schedule [properties]" );
MessageAddChild( "setup (name) (properties)" );
MessageAddChild( "show [(name)|media|schedule]" );
MessageAddChild( "del (name)|all|media|schedule" );
MessageAddChild( "control (name) [instance_name] (command)" );
MessageAddChild( "save (config_file)" );
MessageAddChild( "load (config_file)" );
message_child = MessageAdd( "Media Proprieties Syntax:" );
MessageAddChild( "input (input_name)" );
MessageAddChild( "output (output_name)" );
MessageAddChild( "enabled|disabled" );
MessageAddChild( "loop|unloop (broadcast only)" );
MessageAddChild( "mux (mux_name)" );
message_child = MessageAdd( "Schedule Proprieties Syntax:" );
MessageAddChild( "enabled|disabled" );
MessageAddChild( "append (command_until_rest_of_the_line)" );
MessageAddChild( "date (year)/(month)/(day)-(hour):(minutes):"
"(seconds)|now" );
MessageAddChild( "period (years_aka_12_months)/(months_aka_30_days)/"
"(days)-(hours):(minutes):(seconds)" );
MessageAddChild( "repeat (number_of_repetitions)" );
message_child = MessageAdd( "Control Commands Syntax:" );
MessageAddChild( "play" );
MessageAddChild( "pause" );
MessageAddChild( "stop" );
MessageAddChild( "seek (percentage)" );
return message;
}
......
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