Commit 17a89393 authored by Simon Latapie's avatar Simon Latapie

* vlm.c,vlm.h, telnet.c: new vlm message system, independant from

   telnet interface (will be useful for http vlm interface).
parent d756feeb
...@@ -125,7 +125,8 @@ typedef struct ...@@ -125,7 +125,8 @@ typedef struct
int i_tel_cmd; // for specific telnet commands int i_tel_cmd; // for specific telnet commands
} telnet_client_t; } telnet_client_t;
static void Write_message( telnet_client_t * , char * , int ); static char* MessageToString( vlm_message_t* , int );
static void Write_message( telnet_client_t * , vlm_message_t* , char * , int );
static int SocketListen( intf_thread_t * , int ); static int SocketListen( intf_thread_t * , int );
struct intf_sys_t struct intf_sys_t
...@@ -242,7 +243,7 @@ static void Run( intf_thread_t *p_intf ) ...@@ -242,7 +243,7 @@ static void Run( intf_thread_t *p_intf )
cl->fd = fd; cl->fd = fd;
cl->buffer_write = NULL; cl->buffer_write = NULL;
cl->p_buffer_write = cl->buffer_write; cl->p_buffer_write = cl->buffer_write;
Write_message( cl, "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 ); TAB_APPEND( p_sys->i_clients, p_sys->clients, cl );
} }
...@@ -350,7 +351,7 @@ static void Run( intf_thread_t *p_intf ) ...@@ -350,7 +351,7 @@ static void Run( intf_thread_t *p_intf )
if( cl->p_buffer_read - cl->buffer_read == 999 ) // too long ! if( cl->p_buffer_read - cl->buffer_read == 999 ) // too long !
{ {
Write_message( cl , "Line too long\n" , cl->i_mode + 2 ); Write_message( cl , NULL, "Line too long\n" , cl->i_mode + 2 );
} }
} }
} }
...@@ -369,12 +370,12 @@ static void Run( intf_thread_t *p_intf ) ...@@ -369,12 +370,12 @@ static void Run( intf_thread_t *p_intf )
*cl->p_buffer_read = '\0'; *cl->p_buffer_read = '\0';
if( strcmp( s_password, cl->buffer_read ) == 0 ) if( strcmp( s_password, cl->buffer_read ) == 0 )
{ {
Write_message( cl , "\xff\xfc\x01\nWelcome, Master\n> ", WRITE_MODE_CMD ); Write_message( cl , NULL, "\xff\xfc\x01\nWelcome, Master\n> ", WRITE_MODE_CMD );
} }
else else
{ {
/* wrong password */ /* wrong password */
Write_message( cl , "\n\rTry again, you polio:\n" , WRITE_MODE_PWD ); Write_message( cl , NULL, "\n\rTry again, you polio:\n" , WRITE_MODE_PWD );
} }
} }
else if( cl->i_mode == READ_MODE_CMD && *cl->p_buffer_read == '\n' ) else if( cl->i_mode == READ_MODE_CMD && *cl->p_buffer_read == '\n' )
...@@ -395,32 +396,48 @@ static void Run( intf_thread_t *p_intf ) ...@@ -395,32 +396,48 @@ static void Run( intf_thread_t *p_intf )
} }
else else
{ {
char *message; vlm_message_t *message;
/* create a standard string */ /* create a standard string */
*cl->p_buffer_read = '\0'; *cl->p_buffer_read = '\0';
vlm_ExecuteCommand( p_sys->mediatheque, cl->buffer_read , &message); vlm_ExecuteCommand( p_sys->mediatheque, cl->buffer_read , &message);
Write_message( cl , message , WRITE_MODE_CMD ); Write_message( cl , message, NULL , WRITE_MODE_CMD );
free( message ); vlm_MessageDelete( message );
} }
} }
} }
} }
} }
static void Write_message( telnet_client_t * client, char * 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;
client->p_buffer_read = client->buffer_read; client->p_buffer_read = client->buffer_read;
(client->p_buffer_read)[0] = 0; // if (cl->p_buffer_read)[0] = '\n' (client->p_buffer_read)[0] = 0; // if (cl->p_buffer_read)[0] = '\n'
if( client->buffer_write ) free( client->buffer_write ); if( client->buffer_write ) free( client->buffer_write );
client->buffer_write = malloc( strlen( message ) + 1 );
strcpy( client->buffer_write , message ); /* generate the psz_message string */
if( message != NULL ) /* ok, look for vlm_message_t */
{
psz_message = MessageToString( message , 0 );
psz_message = realloc( psz_message , strlen( psz_message ) + strlen( "\n> " ) + 1 );
strcat( psz_message , "\n> " );
}
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->p_buffer_write = client->buffer_write;
client->i_buffer_write = strlen( message ); client->i_buffer_write = strlen( psz_message );
client->i_mode = i_mode; client->i_mode = i_mode;
free( psz_message );
} }
/* Does what we want except select and accept */ /* Does what we want except select and accept */
...@@ -498,3 +515,48 @@ socket_failed: ...@@ -498,3 +515,48 @@ socket_failed:
return -1; return -1;
} }
/* 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;
char *psz_message;
if( message == NULL )
{
return strdup( "" );
}
else if( i_level == 0 && message->i_child == 0 && 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 + 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 );
}
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 ) + 1 + 1 );
strcat( psz_message, "\n" );
strcat( psz_message, child_message );
free( child_message );
}
return psz_message;
}
}
...@@ -48,15 +48,18 @@ static int vlm_MediaDelete( vlm_t *, vlm_media_t *, char * ); ...@@ -48,15 +48,18 @@ static int vlm_MediaDelete( vlm_t *, vlm_media_t *, char * );
static vlm_media_t *vlm_MediaSearch( vlm_t *, char * ); static vlm_media_t *vlm_MediaSearch( vlm_t *, char * );
static int vlm_MediaSetup( vlm_media_t *, char *, char * ); static int vlm_MediaSetup( vlm_media_t *, char *, char * );
static int vlm_MediaControl( vlm_t *, vlm_media_t *, char *, char * ); static int vlm_MediaControl( vlm_t *, vlm_media_t *, char *, char * );
static char *vlm_Show( vlm_t *, vlm_media_t *, vlm_schedule_t *, char * ); static vlm_message_t *vlm_Show( vlm_t *, vlm_media_t *, vlm_schedule_t *, char * );
static char *vlm_Help( vlm_t *, char * ); static vlm_message_t *vlm_Help( vlm_t *, char * );
static vlm_message_t* vlm_MessageNew( char * , char * );
static vlm_message_t* vlm_MessageAdd( vlm_message_t*, vlm_message_t* );
static vlm_schedule_t *vlm_ScheduleNew( vlm_t *, char *); static vlm_schedule_t *vlm_ScheduleNew( vlm_t *, char *);
static int vlm_ScheduleDelete( vlm_t *, vlm_schedule_t *, char *); static int vlm_ScheduleDelete( vlm_t *, vlm_schedule_t *, char *);
static int vlm_ScheduleSetup( vlm_schedule_t *, char *, char *); static int vlm_ScheduleSetup( vlm_schedule_t *, char *, char *);
static vlm_schedule_t *vlm_ScheduleSearch( vlm_t *, char *); static vlm_schedule_t *vlm_ScheduleSearch( vlm_t *, char *);
static int ExecuteCommand( vlm_t *, char * , char **); static int ExecuteCommand( vlm_t *, char * , vlm_message_t **);
static int Manage( vlc_object_t* ); static int Manage( vlc_object_t* );
...@@ -180,7 +183,7 @@ static char *FindEndCommand( char *psz ) ...@@ -180,7 +183,7 @@ static char *FindEndCommand( char *psz )
#endif #endif
int vlm_ExecuteCommand( vlm_t *vlm, char *command, char **message) int vlm_ExecuteCommand( vlm_t *vlm, char *command, vlm_message_t **message)
{ {
int result; int result;
...@@ -192,13 +195,14 @@ int vlm_ExecuteCommand( vlm_t *vlm, char *command, char **message) ...@@ -192,13 +195,14 @@ int vlm_ExecuteCommand( vlm_t *vlm, char *command, char **message)
} }
/* Execute a command which ends by '\0' (string) */ /* Execute a command which ends by '\0' (string) */
int ExecuteCommand( vlm_t *vlm, char *command , char **message) int ExecuteCommand( vlm_t *vlm, char *command , vlm_message_t **p_message)
{ {
int i_return = 0; int i_return = 0;
int i_command = 0; int i_command = 0;
char **p_command = NULL; char **p_command = NULL;
char *cmd = command; char *cmd = command;
int i; int i;
vlm_message_t * message = NULL;
/* First, parse the line and cut it */ /* First, parse the line and cut it */
while( *cmd != '\0' ) while( *cmd != '\0' )
...@@ -237,7 +241,7 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -237,7 +241,7 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
if( i_command == 0 ) if( i_command == 0 )
{ {
*message = strdup( "" ); message = vlm_MessageNew( "" , NULL );
i_return = 0; i_return = 0;
goto end_seq; goto end_seq;
} }
...@@ -260,8 +264,10 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -260,8 +264,10 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
/* new vlm_schedule */ /* new vlm_schedule */
if( vlm_ScheduleSearch( vlm , p_command[1] ) != NULL || strcmp(p_command[1] , "schedule") == 0 ) if( vlm_ScheduleSearch( vlm , p_command[1] ) != NULL || strcmp(p_command[1] , "schedule") == 0 )
{ {
*message = malloc( (strlen(p_command[1]) + 18) * sizeof(char) ); char *error_message = malloc( strlen(p_command[1]) + strlen(" is already used") + 1 );
sprintf( *message , "%s is already used\n" , p_command[1] ); sprintf( error_message, "%s is already used" , p_command[1] );
message = vlm_MessageNew( "new" , error_message );
free( error_message );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
...@@ -306,19 +312,19 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -306,19 +312,19 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
else else
{ {
vlm_ScheduleDelete( vlm, schedule, NULL ); vlm_ScheduleDelete( vlm, schedule, NULL );
*message = strdup( "Wrong properties syntax\n" ); message = vlm_MessageNew( p_command[i], "Wrong properties syntax" );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
} }
} }
*message = strdup( "" ); message = vlm_MessageNew( "new" , NULL );
i_return = 0; i_return = 0;
goto end_seq; goto end_seq;
} }
*message = strdup( "" ); message = vlm_MessageNew( "new" , NULL );
i_return = 0; i_return = 0;
goto end_seq; goto end_seq;
} }
...@@ -333,7 +339,10 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -333,7 +339,10 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
} }
else else
{ {
*message = strdup( "Choose between vod or broadcast\n" ); char *error_message = malloc( strlen(p_command[1]) + strlen(": Choose between vod or broadcast") + 1 );
sprintf( error_message, "%s: Choose between vod or broadcast" , p_command[1] );
message = vlm_MessageNew( "new" , error_message );
free( error_message );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
...@@ -341,8 +350,10 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -341,8 +350,10 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
/* new vlm_media */ /* new vlm_media */
if( vlm_MediaSearch( vlm , p_command[1] ) != NULL || strcmp(p_command[1] , "media") == 0 ) if( vlm_MediaSearch( vlm , p_command[1] ) != NULL || strcmp(p_command[1] , "media") == 0 )
{ {
*message = malloc( (strlen(p_command[1]) + 18) * sizeof(char) ); char *error_message = malloc( strlen(p_command[1]) + strlen(" is already used") + 1 );
sprintf( *message , "%s is already used\n" , p_command[1] ); sprintf( error_message, "%s is already used" , p_command[1] );
message = vlm_MessageNew( "new" , error_message );
free( error_message );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
...@@ -367,25 +378,25 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -367,25 +378,25 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
else else
{ {
vlm_MediaDelete( vlm, media, NULL ); vlm_MediaDelete( vlm, media, NULL );
*message = strdup( "Wrong properties syntax\n" ); message = vlm_MessageNew( p_command[i] , "Wrong properties syntax" );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
} }
} }
*message = strdup( "" ); message = vlm_MessageNew( "new" , NULL );
i_return = 0; i_return = 0;
goto end_seq; goto end_seq;
} }
*message = strdup( "" ); message = vlm_MessageNew( "new" , NULL );
i_return = 0; i_return = 0;
goto end_seq; goto end_seq;
} }
else else
{ {
*message = strdup( "Wrong new command syntax\n" ); message = vlm_MessageNew( "new" , "Wrong command syntax" );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
...@@ -403,14 +414,14 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -403,14 +414,14 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
if( schedule != NULL ) if( schedule != NULL )
{ {
vlm_ScheduleDelete( vlm, schedule, NULL ); vlm_ScheduleDelete( vlm, schedule, NULL );
*message = strdup( "" ); message = vlm_MessageNew( "del" , NULL );
i_return = 0; i_return = 0;
goto end_seq; goto end_seq;
} }
else if( media != NULL ) else if( media != NULL )
{ {
vlm_MediaDelete( vlm, media, NULL ); vlm_MediaDelete( vlm, media, NULL );
*message = strdup( "" ); message = vlm_MessageNew( "del" , NULL );
i_return = 0; i_return = 0;
goto end_seq; goto end_seq;
} }
...@@ -442,15 +453,17 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -442,15 +453,17 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
} }
else else
{ {
*message = malloc( (strlen(p_command[1]) + 16) * sizeof(char) ); char *error_message = malloc( strlen(p_command[1]) + strlen(": media unknown") + 1 );
sprintf( *message , "%s media unknown\n" , p_command[1] ); sprintf( error_message, "%s: media unknown" , p_command[1] );
message = vlm_MessageNew( "del" , error_message );
free( error_message );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
} }
else else
{ {
*message = strdup( "Wrong setup command syntax\n" ); message = vlm_MessageNew( "setup" , "Wrong command syntax" );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
...@@ -459,7 +472,7 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -459,7 +472,7 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
{ {
if( i_command == 1 ) if( i_command == 1 )
{ {
*message = vlm_Show( vlm, NULL , NULL, NULL ); message = vlm_Show( vlm, NULL , NULL, NULL );
i_return = 0; i_return = 0;
goto end_seq; goto end_seq;
} }
...@@ -473,15 +486,15 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -473,15 +486,15 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
if( schedule != NULL ) if( schedule != NULL )
{ {
*message = vlm_Show( vlm, NULL, schedule, NULL ); message = vlm_Show( vlm, NULL, schedule, NULL );
} }
else if( media != NULL ) else if( media != NULL )
{ {
*message = vlm_Show( vlm, media, NULL, NULL ); message = vlm_Show( vlm, media, NULL, NULL );
} }
else else
{ {
*message = vlm_Show( vlm, NULL, NULL, p_command[1] ); message = vlm_Show( vlm, NULL, NULL, p_command[1] );
} }
i_return = 0; i_return = 0;
...@@ -489,7 +502,7 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -489,7 +502,7 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
} }
else else
{ {
*message = strdup( "Wrong show command syntax\n" ); message = vlm_MessageNew( "show" , "Wrong command syntax" );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
...@@ -498,13 +511,13 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -498,13 +511,13 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
{ {
if( i_command == 1 ) if( i_command == 1 )
{ {
*message = vlm_Help( vlm, NULL ); message = vlm_Help( vlm, NULL );
i_return = 0; i_return = 0;
goto end_seq; goto end_seq;
} }
else else
{ {
*message = strdup( "Wrong help command syntax\n" ); message = vlm_MessageNew( "help" , "Wrong command syntax" );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
...@@ -556,14 +569,14 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -556,14 +569,14 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
else else
{ {
vlm_ScheduleDelete( vlm, schedule, NULL ); vlm_ScheduleDelete( vlm, schedule, NULL );
*message = strdup( "Wrong properties syntax\n" ); message = vlm_MessageNew( "setup" , "Wrong properties syntax" );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
} }
} }
*message = strdup( "" ); message = vlm_MessageNew( "setup" , NULL );
i_return = 0; i_return = 0;
goto end_seq; goto end_seq;
} }
...@@ -579,7 +592,7 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -579,7 +592,7 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
{ {
if( media->i_type != BROADCAST_TYPE ) if( media->i_type != BROADCAST_TYPE )
{ {
*message = strdup( "loop is only available for broadcast\n" ); message = vlm_MessageNew( "setup" , "lool only available for broadcast" );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
...@@ -598,21 +611,23 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -598,21 +611,23 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
else else
{ {
vlm_MediaDelete( vlm, media, NULL ); vlm_MediaDelete( vlm, media, NULL );
*message = strdup( "Wrong properties syntax\n" ); message = vlm_MessageNew( "setup" , "Wrong properties syntax" );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
} }
} }
*message = strdup( "" ); message = vlm_MessageNew( "setup" , NULL );
i_return = 0; i_return = 0;
goto end_seq; goto end_seq;
} }
else else
{ {
*message = malloc( (strlen(p_command[1]) + 28) * sizeof(char) ); char *error_message = malloc( strlen(p_command[1]) + strlen(" unknown") + 1 );
sprintf( *message , "%s media or schedule unknown\n" , p_command[1] ); sprintf( error_message, "%s unknown" , p_command[1] );
message = vlm_MessageNew( "setup" , error_message );
free( error_message );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
...@@ -620,7 +635,7 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -620,7 +635,7 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
} }
else else
{ {
*message = strdup( "Wrong setup command syntax\n" ); message = vlm_MessageNew( "setup" , "Wrong command syntax" );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
...@@ -636,8 +651,10 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -636,8 +651,10 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
if( media == NULL ) if( media == NULL )
{ {
*message = malloc( (strlen(p_command[1]) + 16) * sizeof(char) ); char *error_message = malloc( strlen(p_command[1]) + strlen(": media unknown") + 1 );
sprintf( *message , "%s media unknown\n" , p_command[1] ); sprintf( error_message, "%s: media unknown" , p_command[1] );
message = vlm_MessageNew( "control" , error_message );
free( error_message );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
...@@ -656,14 +673,14 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -656,14 +673,14 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
/* for now */ /* for now */
vlm_MediaControl( vlm, media, p_command[2], psz_args ); vlm_MediaControl( vlm, media, p_command[2], psz_args );
*message = strdup( "" ); message = vlm_MessageNew( "control" , NULL );
i_return = 0; i_return = 0;
goto end_seq; goto end_seq;
} }
} }
else else
{ {
*message = strdup( "Wrong control command syntax\n" ); message = vlm_MessageNew( "control" , "Wrong command syntax" );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
...@@ -679,7 +696,7 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -679,7 +696,7 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
if( file == NULL ) if( file == NULL )
{ {
*message = strdup( "Unable to save file\n" ); message = vlm_MessageNew( "save" , "Unable to save file" );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
...@@ -692,14 +709,14 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -692,14 +709,14 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
fwrite( save, strlen( save ) , 1 , file ); fwrite( save, strlen( save ) , 1 , file );
fclose( file ); fclose( file );
free( save ); free( save );
*message = strdup( "" ); message = vlm_MessageNew( "save" , NULL );
i_return = 0; i_return = 0;
goto end_seq; goto end_seq;
} }
} }
else else
{ {
*message = strdup( "Wrong save command\n" ); message = vlm_MessageNew( "save" , "Wrong command" );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
...@@ -715,7 +732,7 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -715,7 +732,7 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
if( file == NULL ) if( file == NULL )
{ {
*message = strdup( "Unable to load file\n" ); message = vlm_MessageNew( "load" , "Unable to load file" );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
...@@ -734,7 +751,7 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -734,7 +751,7 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
if( vlm_Load( vlm, buffer ) ) if( vlm_Load( vlm, buffer ) )
{ {
free( buffer ); free( buffer );
*message = strdup( "error while loading file\n" ); message = vlm_MessageNew( "load" , "error while loading file" );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
...@@ -742,26 +759,26 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message) ...@@ -742,26 +759,26 @@ int ExecuteCommand( vlm_t *vlm, char *command , char **message)
} }
else else
{ {
*message = strdup( "read file error\n" ); message = vlm_MessageNew( "load" , "read file error" );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
fclose( file ); fclose( file );
*message = strdup( "" ); message = vlm_MessageNew( "load" , NULL );
i_return = 0; i_return = 0;
goto end_seq; goto end_seq;
} }
} }
else else
{ {
*message = strdup( "Wrong save command\n" ); message = vlm_MessageNew( "load" , "Wrong command" );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
} }
else else
{ {
*message = strdup( "Unknown comand\n" ); message = vlm_MessageNew( p_command[0] , "Unknown comand" );
i_return = 1; i_return = 1;
goto end_seq; goto end_seq;
} }
...@@ -773,15 +790,12 @@ end_seq: ...@@ -773,15 +790,12 @@ end_seq:
free( p_command[i] ); free( p_command[i] );
} }
/* Add the prompt */ *p_message = message;
*message = realloc( *message , strlen(*message) + 4 );
sprintf( *message , "%s\n> " , *message );
return i_return; return i_return;
} }
static vlm_media_t *vlm_MediaSearch( vlm_t *vlm, char *psz_name ) static vlm_media_t *vlm_MediaSearch( vlm_t *vlm, char *psz_name )
{ {
int i; int i;
...@@ -1045,77 +1059,61 @@ static int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, char *psz_name, cha ...@@ -1045,77 +1059,61 @@ static int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, char *psz_name, cha
return 1; return 1;
} }
static char *vlm_Show( vlm_t *vlm, vlm_media_t *media, vlm_schedule_t *schedule, char *psz_filter ) static vlm_message_t *vlm_Show( vlm_t *vlm, vlm_media_t *media, vlm_schedule_t *schedule, char *psz_filter )
{ {
if( media != NULL ) if( media != NULL )
{ {
char *show;
int i; int i;
vlm_message_t *message;
vlm_message_t *message_media;
vlm_message_t *message_child;
show = malloc( strlen( media->psz_name ) + 1 + 1 ); message = vlm_MessageNew( "show" , NULL );
sprintf( show, "\n%s" , media->psz_name ); message_media = vlm_MessageAdd( message , vlm_MessageNew( media->psz_name , NULL ) );
if( media->i_type == VOD_TYPE ) if( media->i_type == VOD_TYPE )
{ {
show = realloc( show, strlen( show ) + 4 + 1 ); // don't forget the '\0' vlm_MessageAdd( message_media , vlm_MessageNew( "type" , "vod" ) );
strcat( show , "\nvod" );
} }
else else
{ {
show = realloc( show, strlen( show ) + 10 + 1 ); // don't forget the '\0' vlm_MessageAdd( message_media , vlm_MessageNew( "type" , "broadcast" ) );
strcat( show , "\nbroadcast" );
} }
if( media->b_enabled == VLC_TRUE ) if( media->b_enabled == VLC_TRUE )
{ {
show = realloc( show, strlen( show ) + 8 + 1 ); // don't forget the '\0' vlm_MessageAdd( message_media , vlm_MessageNew( "enabled" , "yes" ) );
strcat( show , "\nenabled" );
} }
else else
{ {
show = realloc( show, strlen( show ) + 9 + 1 ); // don't forget the '\0' vlm_MessageAdd( message_media , vlm_MessageNew( "enabled" , "no" ) );
strcat( show , "\ndisabled" );
} }
if( media->b_loop == VLC_TRUE ) if( media->b_loop == VLC_TRUE )
{ {
show = realloc( show, strlen( show ) + 5 + 1 ); // don't forget the '\0' vlm_MessageAdd( message_media , vlm_MessageNew( "loop" , "yes" ) );
strcat( show , "\nloop" );
} }
show = realloc( show, strlen( show ) + 9 + 1 ); // don't forget the '\0' message_child = vlm_MessageAdd( message_media , vlm_MessageNew( "inputs" , NULL ) );
strcat( show , "\ninputs: " );
for( i=0 ; i < (media->i_input) ; i++ ) for( i=0 ; i < (media->i_input) ; i++ )
{ {
show = realloc( show, strlen( show ) + strlen( media->input[i] ) + 2 + 1 ); // don't forget the '\0' and '\n' vlm_MessageAdd( message_child , vlm_MessageNew( media->input[i] , NULL ) );
strcat( show , "\n " );
strcat( show , media->input[i] );
} }
show = realloc( show, strlen( show ) + 10 + 1 ); // don't forget the '\0'
strcat( show , "\noutput: " );
if( media->psz_output != NULL ) if( media->psz_output != NULL )
{ {
show = realloc( show, strlen( show ) + strlen( media->psz_output ) + 1 ); // don't forget the '\0' and '\n' vlm_MessageAdd( message_media , vlm_MessageNew( "output" , media->psz_output ) );
strcat( show , media->psz_output );
} }
show = realloc( show, strlen( show ) + 9 + 1 ); // don't forget the '\0' message_child = vlm_MessageAdd( message_media , vlm_MessageNew( "options" , NULL ) );
strcat( show , "\noptions:" );
for( i=0 ; i < (media->i_option) ; i++ ) for( i=0 ; i < (media->i_option) ; i++ )
{ {
show = realloc( show, strlen( show ) + strlen( media->option[i] ) + 2 + 1 ); // don't forget the '\0' and '\n' vlm_MessageAdd( message_child , vlm_MessageNew( media->option[i] , NULL ) );
strcat( show , "\n " );
strcat( show , media->option[i] );
} }
show = realloc( show, strlen( show ) + 8 + 1 ); // don't forget the '\0'
strcat( show , "\nstate: " );
if( media->p_input != NULL ) if( media->p_input != NULL )
{ {
vlc_value_t val; vlc_value_t val;
...@@ -1124,54 +1122,46 @@ static char *vlm_Show( vlm_t *vlm, vlm_media_t *media, vlm_schedule_t *schedule, ...@@ -1124,54 +1122,46 @@ static char *vlm_Show( vlm_t *vlm, vlm_media_t *media, vlm_schedule_t *schedule,
if( val.i_int == PLAYING_S ) if( val.i_int == PLAYING_S )
{ {
show = realloc( show, strlen( show ) + 8 + 1 ); // don't forget the '\0' vlm_MessageAdd( message_media , vlm_MessageNew( "state" , "playing" ) );
strcat( show , "playing\n" );
} }
else if( val.i_int == PAUSE_S ) else if( val.i_int == PAUSE_S )
{ {
show = realloc( show, strlen( show ) + 7 + 1 ); // don't forget the '\0' vlm_MessageAdd( message_media , vlm_MessageNew( "state" , "paused" ) );
strcat( show , "paused\n" );
} }
else else
{ {
show = realloc( show, strlen( show ) + 5 + 1 ); // don't forget the '\0' vlm_MessageAdd( message_media , vlm_MessageNew( "state" , "stop" ) );
strcat( show , "stop\n" );
} }
} }
else else
{ {
show = realloc( show, strlen( show ) + 5 + 1 ); // don't forget the '\0' vlm_MessageAdd( message_media , vlm_MessageNew( "state" , "stop" ) );
strcat( show , "stop\n" );
} }
return show; return message;
} }
else if( schedule != NULL ) else if( schedule != NULL )
{ {
char *show;
int i; int i;
vlm_message_t *message;
vlm_message_t *message_schedule;
vlm_message_t *message_child;
show = malloc( strlen( schedule->psz_name ) + 1 + 1 ); message = vlm_MessageNew( "show" , NULL );
sprintf( show, "\n%s" , schedule->psz_name ); message_schedule = vlm_MessageAdd( message , vlm_MessageNew( schedule->psz_name , NULL ) );
show = realloc( show, strlen( show ) + 9 + 1 ); // don't forget the '\0' vlm_MessageAdd( message_schedule , vlm_MessageNew( "type" , "schedule" ) );
strcat( show , "\nschedule" );
if( schedule->b_enabled == VLC_TRUE ) if( schedule->b_enabled == VLC_TRUE )
{ {
show = realloc( show, strlen( show ) + 8 + 1 ); // don't forget the '\0' vlm_MessageAdd( message_schedule , vlm_MessageNew( "enabled" , "yes" ) );
strcat( show , "\nenabled" );
} }
else else
{ {
show = realloc( show, strlen( show ) + 9 + 1 ); // don't forget the '\0' vlm_MessageAdd( message_schedule , vlm_MessageNew( "enabled" , "no" ) );
strcat( show , "\ndisabled" );
} }
show = realloc( show, strlen( show ) + 7 + 1 ); // don't forget the '\0'
strcat( show , "\ndate: " );
if( schedule->i_date != 0 ) if( schedule->i_date != 0 )
{ {
time_t i_time = schedule->i_date / (int64_t)1000000; time_t i_time = schedule->i_date / (int64_t)1000000;
...@@ -1182,13 +1172,11 @@ static char *vlm_Show( vlm_t *vlm, vlm_media_t *media, vlm_schedule_t *schedule, ...@@ -1182,13 +1172,11 @@ static char *vlm_Show( vlm_t *vlm, vlm_media_t *media, vlm_schedule_t *schedule,
#else #else
char *psz_date = ctime( &i_time ); char *psz_date = ctime( &i_time );
#endif #endif
show = realloc( show, strlen( show ) + strlen( psz_date ) + 1 ); vlm_MessageAdd( message_schedule , vlm_MessageNew( "date" , psz_date ) );
strcat( show , psz_date );
} }
else else
{ {
show = realloc( show, strlen( show ) + 4 + 1 ); vlm_MessageAdd( message_schedule , vlm_MessageNew( "date" , "now" ) );
strcat( show , "now!" );
} }
if( schedule->i_period != 0 ) if( schedule->i_period != 0 )
...@@ -1210,81 +1198,62 @@ static char *vlm_Show( vlm_t *vlm, vlm_media_t *media, vlm_schedule_t *schedule, ...@@ -1210,81 +1198,62 @@ static char *vlm_Show( vlm_t *vlm, vlm_media_t *media, vlm_schedule_t *schedule,
i_time = i_time / 12; i_time = i_time / 12;
date.tm_year = (int)i_time; date.tm_year = (int)i_time;
sprintf( buffer, "\nperiod: %d years %d months %d days %d hours %d minutes %d seconds", date.tm_year , sprintf( buffer, "%d years %d months %d days %d hours %d minutes %d seconds", date.tm_year ,
date.tm_mon, date.tm_mon,
date.tm_mday, date.tm_mday,
date.tm_hour, date.tm_hour,
date.tm_min, date.tm_min,
date.tm_sec); date.tm_sec);
show = realloc( show, strlen( show ) + strlen( buffer ) + 1 ); // don't forget the '\0' vlm_MessageAdd( message_schedule , vlm_MessageNew( "period" , buffer ) );
strcat( show , buffer );
if( schedule->i_repeat >= 0 ) if( schedule->i_repeat >= 0 )
{ {
show = realloc( show, strlen( show ) + 9 + 1 ); // don't forget the '\0'
strcat( show , " repeat: " );
sprintf( buffer, "%d" , schedule->i_repeat ); sprintf( buffer, "%d" , schedule->i_repeat );
vlm_MessageAdd( message_schedule , vlm_MessageNew( "repeat" , buffer ) );
show = realloc( show, strlen( show ) + strlen( buffer ) + 1 ); // don't forget the '\0'
strcat( show , buffer );
} }
} }
show = realloc( show, strlen( show ) + 10 + 1 ); message_child = vlm_MessageAdd( message_schedule , vlm_MessageNew( "commands" , NULL ) );
strcat( show , "\ncommands:" );
for( i=0 ; i < (schedule->i_command) ; i++ ) for( i=0 ; i < (schedule->i_command) ; i++ )
{ {
show = realloc( show, strlen(show) + 2 + vlm_MessageAdd( message_child , vlm_MessageNew( schedule->command[i] , NULL ) );
strlen(schedule->command[i]) + 1 );
strcat( show, "\n " );
strcat( show , schedule->command[i] );
} }
show = realloc( show, strlen( show ) + 1 + 1 ); return message;
strcat( show , "\n" );
return show;
} }
else if( psz_filter && strcmp( psz_filter , "media") == 0 ) else if( psz_filter && strcmp( psz_filter , "media") == 0 )
{ {
char *show;
int i; int i;
vlm_message_t *message;
vlm_message_t *message_child;
show = malloc( strlen( "\nlist medias:" ) + 1 ); message = vlm_MessageNew( "show" , NULL );
sprintf( show, "\nlist medias:" ); message_child = vlm_MessageAdd( message , vlm_MessageNew( "media" , NULL ) );
for( i = 0; i < vlm->i_media; i++ ) for( i = 0; i < vlm->i_media; i++ )
{ {
vlm_media_t *m = vlm->media[i]; vlm_media_t *m = vlm->media[i];
vlm_message_t *message_media = vlm_MessageAdd( message_child , vlm_MessageNew( m->psz_name , NULL ) );
show = realloc( show, strlen( show ) + strlen( m->psz_name ) + 2 + 1 );
strcat( show, "\n " );
strcat( show, m->psz_name );
if( m->i_type == VOD_TYPE ) if( m->i_type == VOD_TYPE )
{ {
show = realloc( show, strlen( show ) + strlen( " vod " ) + 1 ); vlm_MessageAdd( message_media , vlm_MessageNew( "type" , "vod" ) );
strcat( show, " vod " );
} }
else else
{ {
show = realloc( show, strlen( show ) + strlen( " broadcast " ) + 1 ); vlm_MessageAdd( message_media , vlm_MessageNew( "type" , "broadcast" ) );
strcat( show, " broadcast " );
} }
if( m->b_enabled == VLC_TRUE ) if( m->b_enabled == VLC_TRUE )
{ {
show = realloc( show, strlen( show ) + 8 + 1 ); // don't forget the '\0' vlm_MessageAdd( message_media , vlm_MessageNew( "enabled" , "yes" ) );
strcat( show , "enabled " );
} }
else else
{ {
show = realloc( show, strlen( show ) + 9 + 1 ); // don't forget the '\0' vlm_MessageAdd( message_media , vlm_MessageNew( "enabled" , "no" ) );
strcat( show , "disabled " );
} }
if( m->p_input != NULL ) if( m->p_input != NULL )
...@@ -1295,55 +1264,45 @@ static char *vlm_Show( vlm_t *vlm, vlm_media_t *media, vlm_schedule_t *schedule, ...@@ -1295,55 +1264,45 @@ static char *vlm_Show( vlm_t *vlm, vlm_media_t *media, vlm_schedule_t *schedule,
if( val.i_int == PLAYING_S ) if( val.i_int == PLAYING_S )
{ {
show = realloc( show, strlen( show ) + 7 + 1 ); // don't forget the '\0' vlm_MessageAdd( message_media , vlm_MessageNew( "state" , "playing" ) );
strcat( show , "playing" );
} }
else if( val.i_int == PAUSE_S ) else if( val.i_int == PAUSE_S )
{ {
show = realloc( show, strlen( show ) + 6 + 1 ); // don't forget the '\0' vlm_MessageAdd( message_media , vlm_MessageNew( "state" , "paused" ) );
strcat( show , "paused" );
} }
else else
{ {
show = realloc( show, strlen( show ) + 4 + 1 ); // don't forget the '\0' vlm_MessageAdd( message_media , vlm_MessageNew( "state" , "stop" ) );
strcat( show , "stop" );
} }
} }
else else
{ {
show = realloc( show, strlen( show ) + 4 + 1 ); // don't forget the '\0' vlm_MessageAdd( message_media , vlm_MessageNew( "state" , "stop" ) );
strcat( show , "stop" );
} }
} }
show = realloc( show, strlen( show ) + 1 + 1 ); // don't forget the '\0' return message;
strcat( show , "\n" );
return show;
} }
else if( psz_filter && strcmp( psz_filter , "schedule") == 0 ) else if( psz_filter && strcmp( psz_filter , "schedule") == 0 )
{ {
char *show;
int i; int i;
vlm_message_t *message;
vlm_message_t *message_child;
show = malloc( strlen( "\nlist schedules:" ) + 1 ); message = vlm_MessageNew( "show" , NULL );
sprintf( show, "\nlist schedules:" ); message_child = vlm_MessageAdd( message , vlm_MessageNew( "schedule" , NULL ) );
for( i = 0; i < vlm->i_schedule; i++ ) for( i = 0; i < vlm->i_schedule; i++ )
{ {
vlm_schedule_t *s = vlm->schedule[i]; vlm_schedule_t *s = vlm->schedule[i];
vlm_message_t *message_schedule = vlm_MessageAdd( message_child , vlm_MessageNew( s->psz_name , NULL ) );
show = realloc( show, strlen( show ) + strlen( s->psz_name ) + 2 + 1 );
strcat( show, "\n " );
strcat( show, s->psz_name );
if( s->b_enabled == VLC_TRUE ) if( s->b_enabled == VLC_TRUE )
{ {
mtime_t i_time; mtime_t i_time;
mtime_t i_next_date; mtime_t i_next_date;
show = realloc( show, strlen( show ) + 8 + 1 ); // don't forget the '\0' vlm_MessageAdd( message_schedule , vlm_MessageNew( "enabled" , "yes" ) );
strcat( show , " enabled" );
/* calculate next date */ /* calculate next date */
i_time = mdate(); i_time = mdate();
...@@ -1372,49 +1331,43 @@ static char *vlm_Show( vlm_t *vlm, vlm_media_t *media, vlm_schedule_t *schedule, ...@@ -1372,49 +1331,43 @@ static char *vlm_Show( vlm_t *vlm, vlm_media_t *media, vlm_schedule_t *schedule,
char *psz_date = ctime( &i_date ); char *psz_date = ctime( &i_date );
#endif #endif
show = realloc( show, strlen( show ) + strlen( psz_date ) + vlm_MessageAdd( message_schedule , vlm_MessageNew( "next launch" , psz_date ) );
14 + 1 );
strcat( show , " next launch: " );
strcat( show , psz_date );
} }
} }
else else
{ {
show = realloc( show, strlen( show ) + 9 + 1 ); // don't forget the '\0' vlm_MessageAdd( message_schedule , vlm_MessageNew( "enabled" , "no" ) );
strcat( show , " disabled" );
} }
} }
show = realloc( show, strlen( show ) + 1 + 1 ); // don't forget the '\0' return message;
strcat( show , "\n" );
return show;
} }
else if( psz_filter == NULL && media == NULL && schedule == NULL ) else if( psz_filter == NULL && media == NULL && schedule == NULL )
{ {
char *show1 = vlm_Show( vlm, NULL, NULL, "media" ); vlm_message_t *show1 = vlm_Show( vlm, NULL, NULL, "media" );
char *show2 = vlm_Show( vlm, NULL, NULL, "schedule" ); vlm_message_t *show2 = vlm_Show( vlm, NULL, NULL, "schedule" );
show1 = realloc( show1, strlen( show1 ) + strlen( show2 ) + 1 + 1 );
strcat( show1, "\n" ); vlm_MessageAdd( show1 , show2->child[0] );
strcat( show1, show2 );
/* we must destroy the parent node "show" of show2, and not the children */
free( show2->psz_name );
free( show2 ); free( show2 );
return show1; return show1;
} }
else else
{ {
return strdup( "" ); return vlm_MessageNew( "show" , NULL );
} }
} }
static char *vlm_Help( vlm_t *vlm, char *psz_filter ) static vlm_message_t *vlm_Help( vlm_t *vlm, char *psz_filter )
{ {
vlm_message_t *message;
if( psz_filter == NULL ) if( psz_filter == NULL )
{ {
char *help = malloc( strlen( "\nHelp:\nCommands Syntax:" ) + char *help = malloc( strlen( "Commands Syntax:" ) +
strlen( "\n new (name) vod|broadcast|schedule [properties]" ) + strlen( "\n new (name) vod|broadcast|schedule [properties]" ) +
strlen( "\n setup (name) (properties)" ) + strlen( "\n setup (name) (properties)" ) +
strlen( "\n show [(name)|media|schedule]" ) + strlen( "\n show [(name)|media|schedule]" ) +
...@@ -1438,7 +1391,7 @@ static char *vlm_Help( vlm_t *vlm, char *psz_filter ) ...@@ -1438,7 +1391,7 @@ static char *vlm_Help( vlm_t *vlm, char *psz_filter )
strlen( "\n play\n pause\n stop\n seek (percentage)\n" ) + 1 ); strlen( "\n play\n pause\n stop\n seek (percentage)\n" ) + 1 );
sprintf( help, sprintf( help,
"\nHelp:\nCommands Syntax:" "Commands Syntax:"
"\n new (name) vod|broadcast|schedule [properties]" "\n new (name) vod|broadcast|schedule [properties]"
"\n setup (name) (properties)" "\n setup (name) (properties)"
"\n show [(name)|media|schedule]" "\n show [(name)|media|schedule]"
...@@ -1461,10 +1414,13 @@ static char *vlm_Help( vlm_t *vlm, char *psz_filter ) ...@@ -1461,10 +1414,13 @@ static char *vlm_Help( vlm_t *vlm, char *psz_filter )
"\nControl Commands Syntax:" "\nControl Commands Syntax:"
"\n play\n pause\n stop\n seek (percentage)\n" ); "\n play\n pause\n stop\n seek (percentage)\n" );
return help; message = vlm_MessageNew( "help" , NULL );
vlm_MessageAdd( message , vlm_MessageNew( "Help" , help ) );
free( help );
return message;
} }
return strdup( "" ); return vlm_MessageNew( "help" , NULL );
} }
/* file must end by '\0' */ /* file must end by '\0' */
...@@ -1474,7 +1430,7 @@ static int vlm_Load( vlm_t *vlm, char *file ) ...@@ -1474,7 +1430,7 @@ static int vlm_Load( vlm_t *vlm, char *file )
while( *pf != '\0' ) while( *pf != '\0' )
{ {
char *message = NULL; vlm_message_t *message = NULL;
int i_temp = 0; int i_temp = 0;
int i_next; int i_next;
...@@ -2105,7 +2061,7 @@ static int Manage( vlc_object_t* p_object ) ...@@ -2105,7 +2061,7 @@ static int Manage( vlc_object_t* p_object )
{ {
for( j = 0 ; j < vlm->schedule[i]->i_command ; j++ ) for( j = 0 ; j < vlm->schedule[i]->i_command ; j++ )
{ {
char *message = NULL; vlm_message_t *message = NULL;
ExecuteCommand( vlm, vlm->schedule[i]->command[j] , &message ); ExecuteCommand( vlm, vlm->schedule[i]->command[j] , &message );
...@@ -2126,3 +2082,60 @@ static int Manage( vlc_object_t* p_object ) ...@@ -2126,3 +2082,60 @@ static int Manage( vlc_object_t* p_object )
return VLC_SUCCESS; return VLC_SUCCESS;
} }
void vlm_MessageDelete( vlm_message_t* message )
{
int i;
if( message->psz_name ) free( message->psz_name );
if( message->psz_value ) free( message->psz_value );
for( i = 0; i < message->i_child; i++)
{
vlm_MessageDelete( message->child[i] );
}
free( message );
}
static vlm_message_t* vlm_MessageNew( char *psz_name , char *psz_value )
{
vlm_message_t *message = malloc( sizeof(vlm_message_t) );
if( psz_name )
{
message->psz_name = strdup( psz_name );
}
else
{
return NULL;
}
if( psz_value )
{
message->psz_value = strdup( psz_value );
}
else
{
message->psz_value = NULL;
}
message->i_child = 0;
message->child = NULL;
return message;
}
/* add a child */
static vlm_message_t* vlm_MessageAdd( vlm_message_t* message , vlm_message_t* child )
{
if( message == NULL ) return NULL;
if( child )
{
TAB_APPEND( message->i_child , message->child , child );
}
return child;
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* .c: VLM interface plugin * .c: VLM interface plugin
***************************************************************************** *****************************************************************************
* Copyright (C) 2000, 2001 VideoLAN * Copyright (C) 2000, 2001 VideoLAN
* $Id: vlm.h,v 1.1 2004/03/05 14:03:20 garf Exp $ * $Id$
* *
* Authors: Simon Latapie <garf@videolan.org> * Authors: Simon Latapie <garf@videolan.org>
* Laurent Aimar <fenrir@videolan.org> * Laurent Aimar <fenrir@videolan.org>
...@@ -79,6 +79,21 @@ typedef struct ...@@ -79,6 +79,21 @@ typedef struct
} vlm_schedule_t; } vlm_schedule_t;
/* ok, here is the structure of a vlm_message:
The parent node is ( name_of_the_command , NULL ), or
( name_of_the_command , message_error ) on error.
If a node has children, it should not have a value (=NULL).*/
typedef struct vlm_message
{
char *psz_name;
char *psz_value;
int i_child;
struct vlm_message **child;
} vlm_message_t;
typedef struct typedef struct
{ {
...@@ -106,4 +121,5 @@ typedef struct ...@@ -106,4 +121,5 @@ typedef struct
vlm_t *__vlm_New ( vlc_object_t * ); vlm_t *__vlm_New ( vlc_object_t * );
void vlm_Delete( vlm_t * ); void vlm_Delete( vlm_t * );
int vlm_ExecuteCommand( vlm_t *, char *, char **); int vlm_ExecuteCommand( vlm_t *, char *, vlm_message_t **);
void vlm_MessageDelete( vlm_message_t* );
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