Пример #1
0
static mvcp_response mvcp_remote_connect( mvcp_remote remote )
{
	mvcp_response response = NULL;

	mvcp_remote_disconnect( remote );

	if ( !remote->connected )
	{
#ifndef WIN32
		signal( SIGPIPE, SIG_IGN );
#endif
		remote->socket = mvcp_socket_init( remote->server, remote->port );
		remote->status = mvcp_socket_init( remote->server, remote->port );

		if ( mvcp_socket_connect( remote->socket ) == 0 )
		{
			response = mvcp_response_init( );
			mvcp_remote_read_response( remote->socket, response );
		}

		if ( 0 && response != NULL && mvcp_socket_connect( remote->status ) == 0 )
		{
			mvcp_response status_response = mvcp_response_init( );
			mvcp_remote_read_response( remote->status, status_response );
			if ( mvcp_response_get_error_code( status_response ) == 100 )
				pthread_create( &remote->thread, NULL, mvcp_remote_status_thread, remote );
			mvcp_response_close( status_response );
			remote->connected = 1;
		}
	}

	return response;
}
Пример #2
0
static mvcp_response mvcp_remote_execute( mvcp_remote remote, char *command )
{
	mvcp_response response = NULL;
	pthread_mutex_lock( &remote->mutex );
	if ( (size_t) mvcp_socket_write_data( remote->socket, command, strlen( command ) ) == strlen( command ) )
	{
		response = mvcp_response_init( );
		mvcp_socket_write_data( remote->socket, "\r\n", 2 );
		mvcp_remote_read_response( remote->socket, response );
	}
	pthread_mutex_unlock( &remote->mutex );
	return response;
}
Пример #3
0
mvcp_response mvcp_response_clone( mvcp_response response )
{
	mvcp_response clone = mvcp_response_init( );
	if ( clone != NULL && response != NULL )
	{
		int index = 0;
		for ( index = 0; index < mvcp_response_count( response ); index ++ )
		{
			char *line = mvcp_response_get_line( response, index );
			mvcp_response_printf( clone, strlen( line ) + 2, "%s\n", line );
		}
	}
	return clone;
}
Пример #4
0
static mvcp_response melted_local_connect( melted_local local )
{
	mvcp_response response = mvcp_response_init( );

	self = pthread_self( );

	mvcp_response_set_error( response, 100, "VTR Ready" );

	signal( SIGHUP, signal_handler );
	signal( SIGINT, signal_handler );
	signal( SIGTERM, SIG_DFL );
	signal( SIGSTOP, signal_handler );
	signal( SIGPIPE, signal_handler );
	signal( SIGALRM, signal_handler );
	signal( SIGCHLD, SIG_IGN );
	if ( getenv( "MLT_SIGSEGV" ) )
		signal( SIGSEGV, sigsegv_handler );

	return response;
}
Пример #5
0
static mvcp_response mvcp_remote_receive( mvcp_remote remote, char *command, char *buffer )
{
	mvcp_response response = NULL;
	pthread_mutex_lock( &remote->mutex );
	if ( (size_t) mvcp_socket_write_data( remote->socket, command, strlen( command ) ) == strlen( command ) )
	{
		char temp[ 20 ];
		int length = strlen( buffer );
		response = mvcp_response_init( );
		mvcp_socket_write_data( remote->socket, "\r\n", 2 );
		sprintf( temp, "%d", length );
		mvcp_socket_write_data( remote->socket, temp, strlen( temp ) );
		mvcp_socket_write_data( remote->socket, "\r\n", 2 );
		mvcp_socket_write_data( remote->socket, buffer, length );
		mvcp_socket_write_data( remote->socket, "\r\n", 2 );
		mvcp_remote_read_response( remote->socket, response );
	}
	pthread_mutex_unlock( &remote->mutex );
	return response;
}
Пример #6
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;
}
Пример #7
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;
}