changed bulk compression logic

This commit is contained in:
Laxmikant Rashinkar 2013-11-06 19:48:22 -08:00
parent f51f9ce679
commit 3a074450d7
2 changed files with 45 additions and 25 deletions

View File

@ -573,18 +573,21 @@ compress_rdp_5(struct xrdp_mppc_enc *enc, tui8 *srcData, int len)
outputBuffer = enc->outputBuffer;
g_memset(outputBuffer, 0, len);
enc->flags = PACKET_COMPR_TYPE_64K;
if (enc->first_pkt)
{
enc->first_pkt = 0;
enc->flagsHold |= PACKET_AT_FRONT;
}
if ((enc->historyOffset + len) > enc->buf_len)
if ((enc->historyOffset + len) >= enc->buf_len)
{
/* historyBuffer cannot hold srcData - rewind it */
enc->historyOffset = 0;
enc->flagsHold |= PACKET_AT_FRONT;
g_memset(hash_table, 0, enc->buf_len * 2);
g_memset(enc->historyBuffer, 0, enc->buf_len); // added
enc->first_pkt = 0;
enc->flagsHold |= PACKET_AT_FRONT;
}
/* point to next free byte in historyBuffer */
@ -602,7 +605,7 @@ compress_rdp_5(struct xrdp_mppc_enc *enc, tui8 *srcData, int len)
/* first 2 bytes,because minimum LoM is 3 */
if (historyOffset == 0)
{
/* encode first two bytes are literals */
/* encode first two bytes as literals */
for (x = 0; x < 2; x++)
{
data = *(historyPointer + x);
@ -974,8 +977,14 @@ compress_rdp_5(struct xrdp_mppc_enc *enc, tui8 *srcData, int len)
/* give up */
enc->historyOffset = 0;
g_memset(hash_table, 0, enc->buf_len * 2);
g_memset(enc->historyBuffer, 0, enc->buf_len);
enc->flagsHold |= PACKET_FLUSHED;
enc->first_pkt = 1;
g_memcpy(enc->outputBuffer, srcData, len);
enc->bytes_in_opb = len;
enc->flags = 0x81;
return 1;
}
else if (opb_index + 1 > len)
@ -984,8 +993,14 @@ compress_rdp_5(struct xrdp_mppc_enc *enc, tui8 *srcData, int len)
/* give up */
enc->historyOffset = 0;
g_memset(hash_table, 0, enc->buf_len * 2);
g_memset(enc->historyBuffer, 0, enc->buf_len);
enc->flagsHold |= PACKET_FLUSHED;
enc->first_pkt = 1;
g_memcpy(enc->outputBuffer, srcData, len);
enc->bytes_in_opb = len;
enc->flags = 0x81;
return 1;
}
@ -1000,8 +1015,14 @@ compress_rdp_5(struct xrdp_mppc_enc *enc, tui8 *srcData, int len)
/* give up */
enc->historyOffset = 0;
g_memset(hash_table, 0, enc->buf_len * 2);
g_memset(enc->historyBuffer, 0, enc->buf_len);
enc->flagsHold |= PACKET_FLUSHED;
enc->first_pkt = 1;
g_memcpy(enc->outputBuffer, srcData, len);
enc->bytes_in_opb = len;
enc->flags = 0x81;
return 1;
}
enc->flags |= PACKET_COMPRESSED;
@ -1011,6 +1032,8 @@ compress_rdp_5(struct xrdp_mppc_enc *enc, tui8 *srcData, int len)
enc->flagsHold = 0;
DLOG(("\n"));
//g_writeln("compression ratio: %f", (float) len / (float) enc->bytes_in_opb);
return 1;
}

View File

@ -433,29 +433,26 @@ xrdp_rdp_send_data(struct xrdp_rdp *self, struct stream *s,
"tocomplen %d", mppc_enc->flags, mppc_enc->bytes_in_opb,
mppc_enc->historyOffset, tocomplen));
if (mppc_enc->flags & RDP_MPPC_COMPRESSED)
{
clen = mppc_enc->bytes_in_opb + 18;
pdulen = clen;
ctype = mppc_enc->flags;
iso_offset = (int)(s->iso_hdr - s->data);
mcs_offset = (int)(s->mcs_hdr - s->data);
sec_offset = (int)(s->sec_hdr - s->data);
rdp_offset = (int)(s->rdp_hdr - s->data);
clen = mppc_enc->bytes_in_opb + 18;
pdulen = clen;
ctype = mppc_enc->flags;
iso_offset = (int)(s->iso_hdr - s->data);
mcs_offset = (int)(s->mcs_hdr - s->data);
sec_offset = (int)(s->sec_hdr - s->data);
rdp_offset = (int)(s->rdp_hdr - s->data);
/* outputBuffer has 64 bytes preceding it */
ls.data = mppc_enc->outputBuffer - (rdp_offset + 18);
ls.p = ls.data + rdp_offset;
ls.end = ls.p + clen;
ls.size = clen;
ls.iso_hdr = ls.data + iso_offset;
ls.mcs_hdr = ls.data + mcs_offset;
ls.sec_hdr = ls.data + sec_offset;
ls.rdp_hdr = ls.data + rdp_offset;
ls.channel_hdr = 0;
ls.next_packet = 0;
s = &ls;
}
/* outputBuffer has 64 bytes preceding it */
ls.data = mppc_enc->outputBuffer - (rdp_offset + 18);
ls.p = ls.data + rdp_offset;
ls.end = ls.p + clen;
ls.size = clen;
ls.iso_hdr = ls.data + iso_offset;
ls.mcs_hdr = ls.data + mcs_offset;
ls.sec_hdr = ls.data + sec_offset;
ls.rdp_hdr = ls.data + rdp_offset;
ls.channel_hdr = 0;
ls.next_packet = 0;
s = &ls;
}
else
{