Пример #1
0
static int mvcp_remote_read_response( mvcp_socket socket, mvcp_response response )
{
	char temp[ 10240 ];
	int length;
	int terminated = 0;

	temp[ 0 ] = '\0';
	while ( !terminated && ( length = mvcp_socket_read_data( socket, temp, sizeof( temp ) - 1 ) ) >= 0 )
	{
		int position = 0;
		temp[ length ] = '\0';
		mvcp_response_write( response, temp, length );
		position = mvcp_response_count( response ) - 1;
		if ( position < 0 || temp[ strlen( temp ) - 1 ] != '\n' )
			continue;
		switch( mvcp_response_get_error_code( response ) )
		{
			case 201:
			case 500:
				terminated = !strcmp( mvcp_response_get_line( response, position ), "" );
				break;
			case 202:
				terminated = mvcp_response_count( response ) >= 2;
				break;
			default:
				terminated = 1;
				break;
		}
	}

	return 0;
}
Пример #2
0
void report( mvcp_response response )
{
	int index = 0;
	if ( response != NULL )
		for ( index = 0; index < mvcp_response_count( response ); index ++ )
			printf( "%4d: %s\n", index, mvcp_response_get_line( response, index ) );
}
Пример #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
response_codes melted_run( command_argument cmd_arg )
{
	mvcp_response temp = mvcp_parser_run( cmd_arg->parser, (char *)cmd_arg->argument );

	if ( temp != NULL )
	{
		int index = 0;

		mvcp_response_set_error( cmd_arg->response, 
							   mvcp_response_get_error_code( temp ),
							   mvcp_response_get_error_string( temp ) );

		for ( index = 1; index < mvcp_response_count( temp ); index ++ )
			mvcp_response_printf( cmd_arg->response, 10240, "%s\n", mvcp_response_get_line( temp, index ) );

		mvcp_response_close( temp );
	}

	return mvcp_response_get_error_code( cmd_arg->response );
}
Пример #5
0
mvcp_error_code client_execute( client demo )
{
	mvcp_error_code error = mvcp_ok;
	char command[ 10240 ];
	int terminated = 0;

	printf( "Melted Shell\n" );
	printf( "Enter an empty command to exit.\n\n" );

	while ( !terminated )
	{
		terminated = 1;
		printf( "Command> " );

		if ( chomp( io_get_string( command, 10240, "" ) ) != NULL )
		{
			if ( strcmp( command, "" ) )
			{
				int index = 0;
				mvcp_response response = NULL;
				error = mvcp_execute( demo->dv, 10240, command );
				printf( "\n" );
				response = mvcp_get_last_response( demo->dv );
				for ( index = 0; index < mvcp_response_count( response ); index ++ )
				{
					char *line = mvcp_response_get_line( response, index );
					printf( "%4d: %s\n", index, line );
				}
				printf( "\n" );
				terminated = 0;
			}
		}
	}

	printf( "\n" );

	return error;
}
Пример #6
0
mvcp_error_code client_add_unit( client demo )
{
	mvcp_error_code error = mvcp_ok;
	mvcp_nodes nodes = mvcp_nodes_init( demo->dv );
	mvcp_units units = mvcp_units_init( demo->dv );

	if ( mvcp_nodes_count( nodes ) != -1 && mvcp_units_count( units ) != -1 )
	{
		char pressed;
		mvcp_node_entry_t node;
		mvcp_unit_entry_t unit;
		int node_index = 0;
		int unit_index = 0;

		printf( "Select a Node\n\n" );

		for ( node_index = 0; node_index < mvcp_nodes_count( nodes ); node_index ++ )
		{
			mvcp_nodes_get( nodes, node_index, &node );
			printf( "%d: %s - %s ", node_index + 1, node.guid, node.name );
			for ( unit_index = 0; unit_index < mvcp_units_count( units ); unit_index ++ )
			{
				mvcp_units_get( units, unit_index, &unit );
				if ( !strcmp( unit.guid, node.guid ) )
					printf( "[U%d] ", unit.unit );
			}
			printf( "\n" );
		}

		printf( "0. Exit\n\n" );

		printf( "Node: " );

		while ( ( pressed = get_keypress( ) ) != '0' )
		{
			node_index = pressed - '1';
			if ( node_index >= 0 && node_index < mvcp_nodes_count( nodes ) )
			{
				int unit;
				printf( "%c\n\n", pressed );
				mvcp_nodes_get( nodes, node_index, &node );
				if ( mvcp_unit_add( demo->dv, node.guid, &unit ) == mvcp_ok )
				{
					printf( "Unit added as U%d\n", unit );
					demo->selected_unit = unit;
				}
				else
				{
					int index = 0;
					mvcp_response response = mvcp_get_last_response( demo->dv );
					printf( "Failed to add unit:\n\n" );
					for( index = 1; index < mvcp_response_count( response ) - 1; index ++ )
						printf( "%s\n", mvcp_response_get_line( response, index ) );
				}
				printf( "\n" );
				wait_for_any_key( NULL );
				break;
			}
			else
			{
				beep( );
			}
		}
	}
	else
	{
		printf( "Invalid response from the server.\n\n" );
		wait_for_any_key( NULL );
	}

	mvcp_nodes_close( nodes );
	mvcp_units_close( units );

	return error;
}