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 ...@@ -110,8 +110,8 @@ typedef struct
} telnet_client_t; } telnet_client_t;
static char* MessageToString( vlm_message_t* , int ); static char *MessageToString( vlm_message_t *, int );
static void Write_message( telnet_client_t * , vlm_message_t* , char * , int ); static void Write_message( telnet_client_t *, vlm_message_t *, char *, int );
struct intf_sys_t struct intf_sys_t
{ {
...@@ -325,7 +325,7 @@ static void Run( intf_thread_t *p_intf ) ...@@ -325,7 +325,7 @@ static void Run( intf_thread_t *p_intf )
if( cl->p_buffer_read - cl->buffer_read == 999 ) 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 ); cl->i_mode + 2 );
} }
} }
...@@ -392,8 +392,8 @@ static void Run( intf_thread_t *p_intf ) ...@@ -392,8 +392,8 @@ static void Run( intf_thread_t *p_intf )
} }
} }
static void Write_message( telnet_client_t * client, vlm_message_t * message, static void Write_message( telnet_client_t *client, vlm_message_t *message,
char * string_message, int i_mode ) char *string_message, int i_mode )
{ {
char *psz_message; char *psz_message;
...@@ -402,73 +402,75 @@ static void Write_message( telnet_client_t * client, vlm_message_t * 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 ); if( client->buffer_write ) free( client->buffer_write );
/* generate the psz_message string */ /* generate the psz_message string */
if( message != NULL ) /* ok, look for vlm_message_t */ if( message )
{ {
psz_message = MessageToString( message , 0 ); /* ok, look for vlm_message_t */
psz_message = realloc( psz_message , strlen( psz_message ) + psz_message = MessageToString( message, 0 );
strlen( "\r\n> " ) + 1 );
strcat( psz_message , "\r\n> " );
} }
else /* it is a basic string_message */ else
{ {
/* it is a basic string_message */
psz_message = strdup( string_message ); psz_message = strdup( string_message );
} }
client->buffer_write = malloc( strlen( psz_message ) + 1 ); client->buffer_write = client->p_buffer_write = psz_message;
strcpy( client->buffer_write , psz_message );
client->p_buffer_write = client->buffer_write;
client->i_buffer_write = strlen( psz_message ); client->i_buffer_write = strlen( psz_message );
client->i_mode = i_mode; client->i_mode = i_mode;
free( psz_message );
} }
/* we need the level of the message to put a beautiful indentation. /* We need the level of the message to put a beautiful indentation.
first level is 0 */ * first level is 0 */
static char* MessageToString( vlm_message_t* message , int i_level ) static char *MessageToString( vlm_message_t *message, int i_level )
{ {
int i; #define STRING_CR "\r\n"
#define STRING_TAIL "> "
char *psz_message; 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 && else if( !i_level && !message->i_child && !message->psz_value )
message->psz_value == NULL ) /* a command is successful */
{
/* don't write anything */
return strdup( "" );
}
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 , " " ); /* A command is successful. Don't write anything */
return strdup( STRING_CR STRING_TAIL );
} }
strcat( psz_message , message->psz_name );
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 ) if( message->psz_value )
{ {
psz_message = realloc( psz_message, strlen( psz_message ) + i_message += sizeof( " : " ) + strlen( message->psz_value ) +
strlen( message->psz_value ) + 3 + 1 ); sizeof( STRING_CR );
psz_message = realloc( psz_message, i_message );
strcat( psz_message, " : " ); strcat( psz_message, " : " );
strcat( psz_message, message->psz_value ); strcat( psz_message, message->psz_value );
strcat( psz_message, STRING_CR );
}
else
{
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++ ) for( i = 0; i < message->i_child; i++ )
{ {
char *child_message = char *child_message =
MessageToString( message->child[i], i_level + 1 ); MessageToString( message->child[i], i_level + 1 );
psz_message = realloc( psz_message, strlen( psz_message ) + i_message += strlen( child_message );
strlen( child_message ) + 2 + 1 ); psz_message = realloc( psz_message, i_message );
strcat( psz_message, "\r\n" );
strcat( psz_message, child_message ); strcat( psz_message, child_message );
free( child_message ); free( child_message );
} }
if( i_level == 0 ) strcat( psz_message, STRING_TAIL );
return psz_message; return psz_message;
}
} }
...@@ -1715,37 +1715,48 @@ static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_t *media, ...@@ -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 ) 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 ) 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 ); 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; 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