Beispiel #1
0
int transport_read(rdpTransport* transport, STREAM* s)
{
	int status = -1;

	while (True)
	{
		if (transport->layer == TRANSPORT_LAYER_TLS)
			status = tls_read(transport->tls, stream_get_tail(s), stream_get_left(s));
		else if (transport->layer == TRANSPORT_LAYER_TCP)
			status = tcp_read(transport->tcp, stream_get_tail(s), stream_get_left(s));

		if (status == 0 && transport->blocking)
		{
			freerdp_usleep(transport->usleep_interval);
			continue;
		}

		break;
	}

#ifdef WITH_DEBUG_TRANSPORT
	if (status > 0)
	{
		printf("Local < Remote\n");
		freerdp_hexdump(s->data, status);
	}
#endif

	return status;
}
Beispiel #2
0
int transport_write(rdpTransport* transport, STREAM* s)
{
	int status = -1;
	int length;

	length = stream_get_length(s);
	stream_set_pos(s, 0);

#ifdef WITH_DEBUG_TRANSPORT
	if (length > 0)
	{
		printf("Local > Remote\n");
		freerdp_hexdump(s->data, length);
	}
#endif

	while (length > 0)
	{
		if (transport->layer == TRANSPORT_LAYER_TLS)
			status = tls_write(transport->tls, stream_get_tail(s), length);
		else if (transport->layer == TRANSPORT_LAYER_TCP)
			status = tcp_write(transport->tcp, stream_get_tail(s), length);
		else if (transport->layer == TRANSPORT_LAYER_TSG)
			status = tsg_write(transport->tsg, stream_get_tail(s), length);

		if (status < 0)
			break; /* error occurred */

		if (status == 0)
		{
			/* blocking while sending */
			freerdp_usleep(transport->usleep_interval);

			/* when sending is blocked in nonblocking mode, the receiving buffer should be checked */
			if (!transport->blocking)
			{
				/* and in case we do have buffered some data, we set the event so next loop will get it */
				if (transport_read_nonblocking(transport) > 0)
					wait_obj_set(transport->recv_event);
			}
		}

		length -= status;
		stream_seek(s, status);
	}

	if (status < 0)
	{
		/* A write error indicates that the peer has dropped the connection */
		transport->layer = TRANSPORT_LAYER_CLOSED;
	}

	return status;
}
Beispiel #3
0
void freerdp_thread_stop(freerdp_thread* thread)
{
	int i = 0;

	wait_obj_set(thread->signals[0]);

	while (thread->status > 0 && i < 1000)
	{
		i++;
		freerdp_usleep(100000);
	}
}
Beispiel #4
0
int transport_write(rdpTransport* transport, STREAM* s)
{
    int status = -1;
    int length;

    length = stream_get_length(s);
    stream_set_pos(s, 0);

#ifdef WITH_DEBUG_TRANSPORT
    if (length > 0)
    {
        printf("Local > Remote\n");
        freerdp_hexdump(s->data, length);
    }
#endif

    while (length > 0)
    {
        if (transport->layer == TRANSPORT_LAYER_TLS)
            status = tls_write(transport->tls, stream_get_tail(s), length);
        else if (transport->layer == TRANSPORT_LAYER_TCP)
            status = tcp_write(transport->tcp, stream_get_tail(s), length);

        if (status < 0)
            break; /* error occurred */

        if (status == 0)
        {
            /* blocking while sending */
            freerdp_usleep(transport->usleep_interval);

        }

        length -= status;
        stream_seek(s, status);
    }

    if (status < 0)
    {
        /* A write error indicates that the peer has dropped the connection */
        transport->layer = TRANSPORT_LAYER_CLOSED;
    }

    return status;
}
Beispiel #5
0
static boolean test_sleep_tsdiff(uint32 *old_sec, uint32 *old_usec, uint32 new_sec, uint32 new_usec)
{
	sint32 sec, usec;

	if (*old_sec==0 && *old_usec==0)
	{
		*old_sec = new_sec;
		*old_usec = new_usec;
		return true;
	}

	sec = new_sec - *old_sec;
	usec = new_usec - *old_usec;

	if (sec<0 || (sec==0 && usec<0))
	{
		printf("Invalid time stamp detected.\n");
		return false;
	}

	*old_sec = new_sec;
	*old_usec = new_usec;
	
	while (usec < 0) 
	{
		usec += 1000000;
		sec--;
	}
	
	if (sec > 0)
		freerdp_sleep(sec);
	
	if (usec > 0)
		freerdp_usleep(usec);
	
	return true;
}
Beispiel #6
0
static BOOL test_sleep_tsdiff(UINT32 *old_sec, UINT32 *old_usec, UINT32 new_sec, UINT32 new_usec)
{
	INT32 sec, usec;

	if (*old_sec==0 && *old_usec==0)
	{
		*old_sec = new_sec;
		*old_usec = new_usec;
		return TRUE;
	}

	sec = new_sec - *old_sec;
	usec = new_usec - *old_usec;

	if (sec<0 || (sec==0 && usec<0))
	{
		printf("Invalid time stamp detected.\n");
		return FALSE;
	}

	*old_sec = new_sec;
	*old_usec = new_usec;
	
	while (usec < 0) 
	{
		usec += 1000000;
		sec--;
	}
	
	if (sec > 0)
		freerdp_sleep(sec);
	
	if (usec > 0)
		freerdp_usleep(usec);
	
	return TRUE;
}
Beispiel #7
0
int transport_read_layer(rdpTransport* transport, uint8* data, int bytes)
{
    int read = 0;
    int status = -1;

    while (read < bytes)
    {
        if (transport->layer == TRANSPORT_LAYER_TLS)
            status = tls_read(transport->tls, data + read, bytes - read);
        else if (transport->layer == TRANSPORT_LAYER_TCP)
            status = tcp_read(transport->tcp, data + read, bytes - read);
        //else if (transport->layer == TRANSPORT_LAYER_TSG)
        //	status = tsg_read(transport->tsg, data + read, bytes - read);

        /* blocking means that we can't continue until this is read */

        if (!transport->blocking)
            return status;

        if (status < 0)
            return status;

        read += status;

        if (status == 0)
        {
            /*
             * instead of sleeping, we should wait timeout on the
             * socket but this only happens on initial connection
             */
            freerdp_usleep(transport->usleep_interval);
        }
    }

    return read;
}
Beispiel #8
0
void* xf_frame_rate_thread(void* param)
{
	xfInfo* xfi;
	xfEvent* event;
	xfPeerContext* xfp;
	freerdp_peer* client;
	uint32 wait_interval;

	client = (freerdp_peer*) param;
	xfp = (xfPeerContext*) client->context;
	xfi = xfp->info;

	wait_interval = 1000000 / xfp->fps;

	while (1)
	{
		// check if we should terminate
		pthread_testcancel();
		
		event = xf_event_new(XF_EVENT_TYPE_FRAME_TICK);
		xf_event_push(xfp->event_queue, (xfEvent*) event);
		freerdp_usleep(wait_interval);
	}
}
Beispiel #9
0
tbool rdp_client_connect(rdpRdp* rdp)
{
	tbool status;
	uint32 selectedProtocol;
	rdpSettings* settings = rdp->settings;

	nego_init(rdp->nego);
	nego_set_target(rdp->nego, settings->hostname, settings->port);
	nego_set_cookie(rdp->nego, settings->username);
	nego_enable_rdp(rdp->nego, settings->rdp_security);
	nego_enable_nla(rdp->nego, settings->nla_security);
	nego_enable_tls(rdp->nego, settings->tls_security);

	if (nego_connect(rdp->nego) == false)
	{
		printf("Error: protocol security negotiation failure\n");
		return false;
	}

	selectedProtocol = rdp->nego->selected_protocol;

	if ((selectedProtocol & PROTOCOL_TLS) || (selectedProtocol == PROTOCOL_RDP))
	{
		if ((settings->username != NULL) && ((settings->password != NULL) || (settings->password_cookie != NULL && settings->password_cookie->length > 0)))
			settings->autologon = true;
	}

	status = false;
	if (selectedProtocol & PROTOCOL_NLA)
	{
		status = transport_connect_nla(rdp->transport);
	}
	else if (selectedProtocol & PROTOCOL_TLS)
	{
		status = transport_connect_tls(rdp->transport);
	}
	else if (selectedProtocol == PROTOCOL_RDP) /* 0 */
	{
		status = transport_connect_rdp(rdp->transport);
	}

	if (status == false)
	{
		return false;
	}

	rdp_set_blocking_mode(rdp, false);
	rdp->state = CONNECTION_STATE_NEGO;
	rdp->finalize_sc_pdus = 0;

	LLOGLN(10, ("rdp_client_connect: calling mcs_send_connect_initial"));

	//freerdp_usleep(1000 * 1000 * 10);

	if (mcs_send_connect_initial(rdp->mcs) == false)
	{
		printf("Error: unable to send MCS Connect Initial\n");
		return false;
	}

	//freerdp_usleep(1000 * 1000 * 10);

	while (rdp->state != CONNECTION_STATE_ACTIVE)
	{
		/* TODO: don't use sleep here */
		freerdp_usleep(1000 * 100);
		if (rdp_check_fds(rdp) < 0)
		{
			LLOGLN(0, ("rdp_client_connect: error rdp_check_fds failed"));
			return false;
		}
	}

	return true;
}