libxrdp: work on fastpath, length issue

This commit is contained in:
speidy 2014-03-04 10:19:19 +02:00
parent 1f1e803140
commit 43f4d439ec
7 changed files with 40 additions and 46 deletions

View File

@ -29,6 +29,7 @@ libxrdp_init(tbus id, struct trans *trans)
session = (struct xrdp_session *)g_malloc(sizeof(struct xrdp_session), 1);
session->id = id;
session->trans = trans;
session->rdp = xrdp_rdp_create(session, trans);
session->orders = xrdp_orders_create(session, (struct xrdp_rdp *)session->rdp);
session->client_info = &(((struct xrdp_rdp *)session->rdp)->client_info);

View File

@ -58,22 +58,23 @@ xrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s)
int fp_hdr;
int len = 0;
int byte;
int hdr_len = 2; /* fastpath header lenght - can be 2 or 3 bytes long, depends on length */
int hdr_len = 2; /* fastpath header length - can be 2 or 3 bytes long, depends on length */
DEBUG((" in xrdp_fastpath_recv"));
/* read the first fastpath byte
* (we already received it via iso layer */
// receive fastpath first length packet
init_stream(s, hdr_len);
if (trans_force_read_s(self->trans, s, hdr_len) != 0)
{
return 1;
}
in_uint8(s, fp_hdr); /* fpInputHeader (1 byte) */
self->numEvents = (fp_hdr & 0x3C) >> 2;
self->secFlags = (fp_hdr & 0xC0) >> 6;
// receive fastpath first length packet
if (trans_force_read_s(self->trans, s, 1) != 0)
{
return 1;
}
in_uint8(s, byte); /* length 1 */
if (byte & 0x80)
@ -81,7 +82,8 @@ xrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s)
byte &= ~(0x80);
len = (byte << 8);
// receive fastpath second length packet
if (xrdp_tcp_recv(self->tcp_layer, s, 1) != 0)
init_stream(s, 1);
if (trans_force_read_s(self->trans, s, 1) != 0)
{
return 1;
}
@ -94,10 +96,11 @@ xrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s)
len = byte;
}
//g_writeln("len= %d , numEvents= %d, secFlags= %d, bytesleft: %d", len, self->numEvents, self->secFlags, (s->p - s->data));
g_writeln("len= %d , numEvents= %d, secFlags= %d, bytesleft: %d", len, self->numEvents, self->secFlags, (s->p - s->data));
// receive the left bytes
if (xrdp_tcp_recv(self->tcp_layer, s, len - hdr_len) != 0)
init_stream(s, len - hdr_len);
if (trans_force_read_s(self->trans, s, len - hdr_len) != 0)
{
return 1;
}
@ -166,10 +169,10 @@ xrdp_fastpath_send_update_pdu(struct xrdp_fastpath *self, tui8 updateCode,
// s_copy(s_send, s, len);
s_mark_end(s_send);
if (xrdp_tcp_send(self->tcp_layer, s_send) != 0)
{
return 1;
}
// if (xrdp_tcp_send(self->tcp_layer, s_send) != 0)
// {
// return 1;
// }
}
return 0;
@ -220,12 +223,12 @@ xrdp_fastpath_process_data(struct xrdp_fastpath *self, struct stream *s,
encryptionFlags = (header & 0xc0) >> 6;
numberEvents = (header & 0x3c) >> 2;
xrdp_tcp_recv(self->tcp_layer, s, 1);
// xrdp_tcp_recv(self->tcp_layer, s, 1);
in_uint8(s, length);
if (length & 0x80)
{
xrdp_tcp_recv(self->tcp_layer, s, 1);
// xrdp_tcp_recv(self->tcp_layer, s, 1);
in_uint8(s, length2);
length = (length & 0x7f) << 8 + length2 - 3;
}
@ -234,7 +237,7 @@ xrdp_fastpath_process_data(struct xrdp_fastpath *self, struct stream *s,
length -= 2;
}
xrdp_tcp_recv(self->tcp_layer, s, length);
// xrdp_tcp_recv(self->tcp_layer, s, length);
if (encryptionFlags != 0)
{

View File

@ -111,7 +111,7 @@ xrdp_iso_recv_msg(struct xrdp_iso *self, struct stream *s, int *code, int *len)
if (ver != 3)
{
return 2; // special code for fastpath
return 1;
}
in_uint8s(s, 1);

View File

@ -122,21 +122,11 @@ xrdp_mcs_recv(struct xrdp_mcs *self, struct stream *s, int *chan)
int len;
int userid;
int chanid;
int iso_msg;
DEBUG((" in xrdp_mcs_recv"));
while (1)
{
iso_msg = xrdp_iso_recv(self->iso_layer, s);
if (iso_msg == 2) // non-TPKT header
{
DEBUG((" out xrdp_mcs_recv, non-TPKT header detected, we try fastpath"));
return iso_msg;
}
if (iso_msg == 1) // error
if (xrdp_iso_recv(self->iso_layer, s) != 0)
{
DEBUG((" out xrdp_mcs_recv, xrdp_iso_recv return non zero"));
return 1;

View File

@ -299,20 +299,30 @@ xrdp_rdp_recv(struct xrdp_rdp *self, struct stream *s, int *code)
int len = 0;
int pdu_code = 0;
int chan = 0;
const tui8 *header;
header = (const tui8 *) (self->session->trans->in_s->p);
DEBUG(("in xrdp_rdp_recv"));
/* not fastpath, do tpkt */
if (s->next_packet == 0 || s->next_packet >= s->end)
{
chan = 0;
error = xrdp_sec_recv(self->sec_layer, s, &chan);
/* check for fastpath first */
g_writeln("xrdp_rdp_recv: header= 0x%8.8x", header[0]);
if (error == 2) /* we have fastpath packet! */
if ((header[0] & 0x3) == 0 && (header[0] != 0x3c))
{
*code = 2;
if (xrdp_sec_recv_fastpath(self->sec_layer, s) != 0)
{
return 1;
}
*code = 2; // special code for fastpath
return 0;
}
chan = 0;
error = xrdp_sec_recv(self->sec_layer, s, &chan);
if (error == -1) /* special code for send demand active */
{
s->next_packet = 0;
@ -1691,8 +1701,8 @@ xrdp_rdp_process_fastpath_data_input(struct xrdp_rdp *self, struct stream *s)
eventFlags = (eventHeader & 0x1F);
eventCode = (eventHeader >> 5);
//g_writeln("eventCode= %d, eventFlags= %d, numEvents= %d",
// eventCode, eventFlags, self->sec_layer->fastpath_layer->numEvents);
// g_writeln("eventCode= %d, eventFlags= %d, numEvents= %d",
// eventCode, eventFlags, self->sec_layer->fastpath_layer->numEvents);
switch (eventCode)
{

View File

@ -972,23 +972,12 @@ xrdp_sec_recv(struct xrdp_sec *self, struct stream *s, int *chan)
{
int flags;
int len;
int mcs_msg;
int ver;
int pad;
DEBUG((" in xrdp_sec_recv"));
mcs_msg = xrdp_mcs_recv(self->mcs_layer, s, chan);
if (mcs_msg == 2)
{
xrdp_sec_recv_fastpath(self, s);
DEBUG((" out xrdp_sec_recv : non-TPKT msg detected, we try fastpath"));
return mcs_msg;
}
if (mcs_msg == 1)
if (xrdp_mcs_recv(self->mcs_layer, s, chan) != 0)
{
DEBUG((" out xrdp_sec_recv : error"));
return 1;

View File

@ -123,6 +123,7 @@ xrdp_process_get_pdu_bytes(const char *aheader)
rv = -1;
header = (const tui8 *) aheader;
if (header[0] == 0x03)
{
/* TPKT */