BOOL nego_recv_response(rdpNego* nego) { int status; wStream* s; s = Stream_New(NULL, 1024); if (!s) return FALSE; status = transport_read_pdu(nego->transport, s); if (status < 0) { Stream_Free(s, TRUE); return FALSE; } status = nego_recv(nego->transport, s, nego); Stream_Free(s, TRUE); if (status < 0) return FALSE; return TRUE; }
int nla_recv(rdpNla* nla) { wStream* s; int status; s = Stream_New(NULL, 4096); if (!s) { WLog_ERR(TAG, "Stream_New failed!"); return -1; } status = transport_read_pdu(nla->transport, s); if (status < 0) { WLog_ERR(TAG, "nla_recv() error: %d", status); Stream_Free(s, TRUE); return -1; } if (nla_decode_ts_request(nla, s) < 1) { Stream_Free(s, TRUE); return -1; } Stream_Free(s, TRUE); return 1; }
int transport_check_fds(rdpTransport* transport) { int status; int recv_status; wStream* received; if (!transport) return -1; #ifdef _WIN32 WSAResetEvent(transport->TcpIn->event); #endif ResetEvent(transport->ReceiveEvent); /** * Loop through and read all available PDUs. Since multiple * PDUs can exist, it's important to deliver them all before * returning. Otherwise we run the risk of having a thread * wait for a socket to get signaled that data is available * (which may never happen). */ for (;;) { /** * Note: transport_read_pdu tries to read one PDU from * the transport layer. * The ReceiveBuffer might have a position > 0 in case of a non blocking * transport. If transport_read_pdu returns 0 the pdu couldn't be read at * this point. * Note that transport->ReceiveBuffer is replaced after each iteration * of this loop with a fresh stream instance from a pool. */ if ((status = transport_read_pdu(transport, transport->ReceiveBuffer)) <= 0) { return status; } received = transport->ReceiveBuffer; transport->ReceiveBuffer = StreamPool_Take(transport->ReceivePool, 0); /** * status: * -1: error * 0: success * 1: redirection */ recv_status = transport->ReceiveCallback(transport, received, transport->ReceiveExtra); Stream_Release(received); /* session redirection or activation */ if (recv_status == 1 || recv_status == 2) { return recv_status; } if (recv_status < 0) return -1; } return 0; }
int transport_check_fds(rdpTransport* transport) { int status; int recv_status; wStream* received; HANDLE event; if (!transport) return -1; while(!freerdp_shall_disconnect(transport->context->instance)) { /** * Note: transport_read_pdu tries to read one PDU from * the transport layer. * The ReceiveBuffer might have a position > 0 in case of a non blocking * transport. If transport_read_pdu returns 0 the pdu couldn't be read at * this point. * Note that transport->ReceiveBuffer is replaced after each iteration * of this loop with a fresh stream instance from a pool. */ if ((status = transport_read_pdu(transport, transport->ReceiveBuffer)) <= 0) { if (status < 0) WLog_DBG(TAG, "transport_check_fds: transport_read_pdu() - %i", status); return status; } received = transport->ReceiveBuffer; if (!(transport->ReceiveBuffer = StreamPool_Take(transport->ReceivePool, 0))) return -1; /** * status: * -1: error * 0: success * 1: redirection */ recv_status = transport->ReceiveCallback(transport, received, transport->ReceiveExtra); Stream_Release(received); /* session redirection or activation */ if (recv_status == 1 || recv_status == 2) { return recv_status; } if (recv_status < 0) { WLog_ERR(TAG, "transport_check_fds: transport->ReceiveCallback() - %i", recv_status); return -1; } } return 0; }
int nla_client_authenticate(rdpNla* nla) { wStream* s; int status; s = Stream_New(NULL, 4096); if (!s) { WLog_ERR(TAG, "Stream_New failed!"); return -1; } if (nla_client_begin(nla) < 1) { Stream_Free(s, TRUE); return -1; } while (nla->state < NLA_STATE_AUTH_INFO) { Stream_SetPosition(s, 0); status = transport_read_pdu(nla->transport, s); if (status < 0) { WLog_ERR(TAG, "nla_client_authenticate failure"); Stream_Free(s, TRUE); return -1; } status = nla_recv_pdu(nla, s); if (status < 0) { Stream_Free(s, TRUE); return -1; } } Stream_Free(s, TRUE); return 1; }
int transport_check_fds(rdpTransport* transport) { int status; int recv_status; wStream* received; DWORD now = GetTickCount(); DWORD dueDate = 0; if (!transport) return -1; dueDate = now + transport->settings->MaxTimeInCheckLoop; if (transport->haveMoreBytesToRead) { transport->haveMoreBytesToRead = FALSE; ResetEvent(transport->rereadEvent); } while (now < dueDate) { if (freerdp_shall_disconnect(transport->context->instance)) { return -1; } /** * Note: transport_read_pdu tries to read one PDU from * the transport layer. * The ReceiveBuffer might have a position > 0 in case of a non blocking * transport. If transport_read_pdu returns 0 the pdu couldn't be read at * this point. * Note that transport->ReceiveBuffer is replaced after each iteration * of this loop with a fresh stream instance from a pool. */ if ((status = transport_read_pdu(transport, transport->ReceiveBuffer)) <= 0) { if (status < 0) WLog_Print(transport->log, WLOG_DEBUG, "transport_check_fds: transport_read_pdu() - %i", status); return status; } received = transport->ReceiveBuffer; if (!(transport->ReceiveBuffer = StreamPool_Take(transport->ReceivePool, 0))) return -1; /** * status: * -1: error * 0: success * 1: redirection */ recv_status = transport->ReceiveCallback(transport, received, transport->ReceiveExtra); Stream_Release(received); /* session redirection or activation */ if (recv_status == 1 || recv_status == 2) { return recv_status; } if (recv_status < 0) { WLog_Print(transport->log, WLOG_ERROR, "transport_check_fds: transport->ReceiveCallback() - %i", recv_status); return -1; } now = GetTickCount(); } if (now >= dueDate) { SetEvent(transport->rereadEvent); transport->haveMoreBytesToRead = TRUE; } return 0; }