Exemplo n.º 1
0
static void *mvcp_remote_status_thread( void *arg )
{
	mvcp_remote remote = arg;
	char temp[ 10240 ];
	int length = 0;
	int offset = 0;
	mvcp_tokeniser tokeniser = mvcp_tokeniser_init( );
	mvcp_notifier notifier = mvcp_parser_get_notifier( remote->parser );
	mvcp_status_t status;
	int index = 0;

	mvcp_socket_write_data( remote->status, "STATUS\r\n", 8 );
	temp[ 0 ] = '\0';
	while ( !remote->terminated && 
			( length = mvcp_socket_read_data( remote->status, temp + offset, sizeof( temp ) - 1 ) ) >= 0 )
	{
		if ( length < 0 )
			break;
		temp[ length ] = '\0';
		if ( strchr( temp, '\n' ) == NULL )
		{
			offset = length;
			continue;
		}
		offset = 0;
		mvcp_tokeniser_parse_new( tokeniser, temp, "\n" );
		for ( index = 0; index < mvcp_tokeniser_count( tokeniser ); index ++ )
		{
			char *line = mvcp_tokeniser_get_string( tokeniser, index );
			if ( line[ strlen( line ) - 1 ] == '\r' )
			{
				mvcp_util_chomp( line );
				mvcp_status_parse( &status, line );
				mvcp_notifier_put( notifier, &status );
			}
			else
			{
				strcpy( temp, line );
				offset = strlen( temp );
			}
		}
	}

	mvcp_notifier_disconnected( notifier );
	mvcp_tokeniser_close( tokeniser );
	remote->terminated = 1;

	return NULL;
}
Exemplo n.º 2
0
static mvcp_response melted_local_push( melted_local local, char *command, mlt_service service )
{
	command_argument_t cmd;
	cmd.parser = local->parser;
	cmd.response = mvcp_response_init( );
	cmd.tokeniser = mvcp_tokeniser_init( );
	cmd.command = command;
	cmd.unit = -1;
	cmd.argument = NULL;
	cmd.root_dir = local->root_dir;

	/* Set the default error */
	melted_command_set_error( &cmd, RESPONSE_SUCCESS );

	/* Parse the command */
	if ( mvcp_tokeniser_parse_new( cmd.tokeniser, command, " " ) > 0 )
	{
		int index = 0;
		int position = 1;

		/* Strip quotes from all tokens */
		for ( index = 0; index < mvcp_tokeniser_count( cmd.tokeniser ); index ++ )
			mvcp_util_strip( mvcp_tokeniser_get_string( cmd.tokeniser, index ), '\"' );

		cmd.unit = melted_command_parse_unit( &cmd, position );
		if ( cmd.unit == -1 )
			melted_command_set_error( &cmd, RESPONSE_MISSING_ARG );
		position ++;

		melted_push( &cmd, service );
		melted_command_set_error( &cmd, RESPONSE_SUCCESS );

		free( cmd.argument );
	}

	mvcp_tokeniser_close( cmd.tokeniser );

	return cmd.response;
}
Exemplo n.º 3
0
static mvcp_response melted_local_execute( melted_local local, char *command )
{
	command_argument_t cmd;
	cmd.parser = local->parser;
	cmd.response = mvcp_response_init( );
	cmd.tokeniser = mvcp_tokeniser_init( );
	cmd.command = command;
	cmd.unit = -1;
	cmd.argument = NULL;
	cmd.root_dir = local->root_dir;

	/* Set the default error */
	melted_command_set_error( &cmd, RESPONSE_UNKNOWN_COMMAND );

	/* Parse the command */
	if ( mvcp_tokeniser_parse_new( cmd.tokeniser, command, " " ) > 0 )
	{
		int index = 0;
		char *value = mvcp_tokeniser_get_string( cmd.tokeniser, 0 );
		int found = 0;

		/* Strip quotes from all tokens */
		for ( index = 0; index < mvcp_tokeniser_count( cmd.tokeniser ); index ++ )
			mvcp_util_strip( mvcp_tokeniser_get_string( cmd.tokeniser, index ), '\"' );

		/* Search the vocabulary array for value */
		for ( index = 1; !found && vocabulary[ index ].command != NULL; index ++ )
			if ( ( found = !strcasecmp( vocabulary[ index ].command, value ) ) )
				break;

		/* If we found something, the handle the args and call the handler. */
		if ( found )
		{
			int position = 1;

			melted_command_set_error( &cmd, RESPONSE_SUCCESS );

			if ( vocabulary[ index ].is_unit )
			{
				cmd.unit = melted_command_parse_unit( &cmd, position );
				if ( cmd.unit == -1 )
					melted_command_set_error( &cmd, RESPONSE_MISSING_ARG );
				position ++;
			}

			if ( melted_command_get_error( &cmd ) == RESPONSE_SUCCESS )
			{
				cmd.argument = melted_command_parse_argument( &cmd, position, vocabulary[ index ].type, command );
				if ( cmd.argument == NULL && vocabulary[ index ].type != ATYPE_NONE )
					melted_command_set_error( &cmd, RESPONSE_MISSING_ARG );
				position ++;
			}

			if ( melted_command_get_error( &cmd ) == RESPONSE_SUCCESS )
			{
				response_codes error = vocabulary[ index ].operation( &cmd );
				melted_command_set_error( &cmd, error );
			}

			free( cmd.argument );
		}
	}

	mvcp_tokeniser_close( cmd.tokeniser );

	return cmd.response;
}