Merge branch 'devel' of github.com:/neutrinolabs/xrdp into devel

ulab-next
Laxmikant Rashinkar 11 years ago
commit 40ec8a1714

@ -5,6 +5,7 @@ EXTRA_DIST = \
file.h \ file.h \
file_loc.h \ file_loc.h \
list.h \ list.h \
list16.h \
fifo.h \ fifo.h \
log.h \ log.h \
os_calls.h \ os_calls.h \
@ -32,6 +33,7 @@ libcommon_la_SOURCES = \
d3des.c \ d3des.c \
file.c \ file.c \
list.c \ list.c \
list16.c \
fifo.c \ fifo.c \
log.c \ log.c \
os_calls.c \ os_calls.c \

@ -0,0 +1,188 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2014
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* simple list
*/
#include "arch.h"
#include "os_calls.h"
#include "list16.h"
/*****************************************************************************/
struct list16 *APP_CC
list16_create(void)
{
struct list16 *self;
self = (struct list16 *)g_malloc(sizeof(struct list16), 0);
list16_init(self);
return self;
}
/*****************************************************************************/
void APP_CC
list16_delete(struct list16 *self)
{
if (self == 0)
{
return;
}
list16_deinit(self);
g_free(self);
}
/*****************************************************************************/
void APP_CC
list16_init(struct list16* self)
{
g_memset(self, 0, sizeof(struct list16));
self->max_count = 4;
self->items = self->mitems;
}
/*****************************************************************************/
void APP_CC
list16_deinit(struct list16* self)
{
if (self->items != self->mitems)
{
g_free(self->items);
}
}
/*****************************************************************************/
void APP_CC
list16_add_item(struct list16 *self, tui16 item)
{
tui16 *p;
int i;
if (self->count >= self->max_count)
{
i = self->max_count;
self->max_count += 4;
p = (tui16 *)g_malloc(sizeof(tui16) * self->max_count, 1);
g_memcpy(p, self->items, sizeof(tui16) * i);
if (self->items != self->mitems)
{
g_free(self->items);
}
self->items = p;
}
self->items[self->count] = item;
self->count++;
}
/*****************************************************************************/
tui16 APP_CC
list16_get_item(struct list16 *self, int index)
{
if (index < 0 || index >= self->count)
{
return 0;
}
return self->items[index];
}
/*****************************************************************************/
void APP_CC
list16_clear(struct list16 *self)
{
if (self->items != self->mitems)
{
g_free(self->items);
}
self->count = 0;
self->max_count = 4;
self->items = self->mitems;
}
/*****************************************************************************/
int APP_CC
list16_index_of(struct list16 *self, tui16 item)
{
int i;
for (i = 0; i < self->count; i++)
{
if (self->items[i] == item)
{
return i;
}
}
return -1;
}
/*****************************************************************************/
void APP_CC
list16_remove_item(struct list16 *self, int index)
{
int i;
if (index >= 0 && index < self->count)
{
for (i = index; i < (self->count - 1); i++)
{
self->items[i] = self->items[i + 1];
}
self->count--;
}
}
/*****************************************************************************/
void APP_CC
list16_insert_item(struct list16 *self, int index, tui16 item)
{
tui16 *p;
int i;
if (index == self->count)
{
list_add_item(self, item);
return;
}
if (index >= 0 && index < self->count)
{
self->count++;
if (self->count > self->max_count)
{
i = self->max_count;
self->max_count += 4;
p = (tui16 *)g_malloc(sizeof(tui16) * self->max_count, 1);
g_memcpy(p, self->items, sizeof(tui16) * i);
if (self->items != self->mitems)
{
g_free(self->items);
}
self->items = p;
}
for (i = (self->count - 2); i >= index; i--)
{
self->items[i + 1] = self->items[i];
}
self->items[index] = item;
}
}

@ -0,0 +1,56 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2014
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* simple list
*/
#if !defined(LIST16_H)
#define LIST16_H
#include "arch.h"
/* list */
struct list16
{
tui16* items;
int count;
int max_count;
tui16 mitems[4];
};
struct list16* APP_CC
list16_create(void);
void APP_CC
list16_delete(struct list16* self);
void APP_CC
list16_init(struct list16* self);
void APP_CC
list16_deinit(struct list16* self);
void APP_CC
list16_add_item(struct list16* self, tui16 item);
tui16 APP_CC
list16_get_item(struct list16* self, int index);
void APP_CC
list16_clear(struct list16* self);
int APP_CC
list16_index_of(struct list16* self, tui16 item);
void APP_CC
list16_remove_item(struct list16* self, int index);
void APP_CC
list16_insert_item(struct list16* self, int index, tui16 item);
#endif

@ -636,7 +636,7 @@ libxrdp_send_pointer(struct xrdp_session *session, int cache_idx,
out_uint16_le(s, bpp); out_uint16_le(s, bpp);
} }
} }
else else /* slowpath */
{ {
LLOGLN(10, ("libxrdp_send_pointer: slowpath")); LLOGLN(10, ("libxrdp_send_pointer: slowpath"));
xrdp_rdp_init_data((struct xrdp_rdp *)session->rdp, s); xrdp_rdp_init_data((struct xrdp_rdp *)session->rdp, s);

@ -266,8 +266,8 @@ xrdp_caps_process_cache_v3_codec_id(struct xrdp_rdp *self, struct stream *s,
/*****************************************************************************/ /*****************************************************************************/
/* get the number of client cursor cache */ /* get the number of client cursor cache */
static int APP_CC static int APP_CC
xrdp_caps_process_pointercache(struct xrdp_rdp *self, struct stream *s, xrdp_caps_process_pointer(struct xrdp_rdp *self, struct stream *s,
int len) int len)
{ {
int i; int i;
int colorPointerFlag; int colorPointerFlag;
@ -275,7 +275,7 @@ xrdp_caps_process_pointercache(struct xrdp_rdp *self, struct stream *s,
if (len < 2 + 2 + 2) if (len < 2 + 2 + 2)
{ {
g_writeln("xrdp_caps_process_pointercache: error"); g_writeln("xrdp_caps_process_pointer: error");
return 1; return 1;
} }
no_new_cursor = self->client_info.pointer_flags & 2; no_new_cursor = self->client_info.pointer_flags & 2;
@ -286,7 +286,7 @@ xrdp_caps_process_pointercache(struct xrdp_rdp *self, struct stream *s,
self->client_info.pointer_cache_entries = i; self->client_info.pointer_cache_entries = i;
if (colorPointerFlag & 1) if (colorPointerFlag & 1)
{ {
g_writeln("xrdp_caps_process_pointercache: client supports " g_writeln("xrdp_caps_process_pointer: client supports "
"new(color) cursor"); "new(color) cursor");
in_uint16_le(s, i); in_uint16_le(s, i);
i = MIN(i, 32); i = MIN(i, 32);
@ -294,12 +294,12 @@ xrdp_caps_process_pointercache(struct xrdp_rdp *self, struct stream *s,
} }
else else
{ {
g_writeln("xrdp_caps_process_pointercache: client does not support " g_writeln("xrdp_caps_process_pointer: client does not support "
"new(color) cursor"); "new(color) cursor");
} }
if (no_new_cursor) if (no_new_cursor)
{ {
g_writeln("xrdp_caps_process_pointercache: new(color) cursor is " g_writeln("xrdp_caps_process_pointer: new(color) cursor is "
"disabled by config"); "disabled by config");
self->client_info.pointer_flags = 0; self->client_info.pointer_flags = 0;
} }
@ -567,7 +567,7 @@ xrdp_caps_process_confirm_active(struct xrdp_rdp *self, struct stream *s)
break; break;
case RDP_CAPSET_POINTER: /* 8 */ case RDP_CAPSET_POINTER: /* 8 */
DEBUG(("RDP_CAPSET_POINTER")); DEBUG(("RDP_CAPSET_POINTER"));
xrdp_caps_process_pointercache(self, s, len); xrdp_caps_process_pointer(self, s, len);
break; break;
case RDP_CAPSET_SHARE: /* 9 */ case RDP_CAPSET_SHARE: /* 9 */
DEBUG(("RDP_CAPSET_SHARE")); DEBUG(("RDP_CAPSET_SHARE"));

@ -629,24 +629,47 @@ xrdp_rdp_send_data_update_sync(struct xrdp_rdp *self)
init_stream(s, 8192); init_stream(s, 8192);
DEBUG(("in xrdp_rdp_send_data_update_sync")); DEBUG(("in xrdp_rdp_send_data_update_sync"));
if (xrdp_rdp_init_data(self, s) != 0) if (self->client_info.use_fast_path & 1) /* fastpath output supported */
{ {
DEBUG(("out xrdp_rdp_send_data_update_sync error")); LLOGLN(10, ("xrdp_rdp_send_data_update_sync: fastpath"));
free_stream(s); if (xrdp_rdp_init_fastpath(self, s) != 0)
return 1; {
return 1;
}
}
else /* slowpath */
{
if (xrdp_rdp_init_data(self, s) != 0)
{
DEBUG(("out xrdp_rdp_send_data_update_sync error"));
free_stream(s);
return 1;
}
out_uint16_le(s, RDP_UPDATE_SYNCHRONIZE);
} }
out_uint16_le(s, RDP_UPDATE_SYNCHRONIZE); out_uint16_le(s, 0); /* pad */
out_uint8s(s, 2);
s_mark_end(s); s_mark_end(s);
if (xrdp_rdp_send_data(self, s, RDP_DATA_PDU_UPDATE) != 0) if (self->client_info.use_fast_path & 1) /* fastpath output supported */
{ {
DEBUG(("out xrdp_rdp_send_data_update_sync error")); if (xrdp_rdp_send_fastpath(self, s,
free_stream(s); FASTPATH_UPDATETYPE_SYNCHRONIZE) != 0)
return 1; {
return 1;
}
}
else /* slowpath */
{
if (xrdp_rdp_send_data(self, s, RDP_DATA_PDU_UPDATE) != 0)
{
DEBUG(("out xrdp_rdp_send_data_update_sync error"));
free_stream(s);
return 1;
}
} }
DEBUG(("out xrdp_rdp_send_data_update_sync")); DEBUG(("out xrdp_rdp_send_data_update_sync"));
free_stream(s); free_stream(s);
return 0; return 0;
@ -748,8 +771,8 @@ xrdp_rdp_send_synchronise(struct xrdp_rdp *self)
return 1; return 1;
} }
out_uint16_le(s, 1); out_uint16_le(s, 1); /* messageType (2 bytes) */
out_uint16_le(s, 1002); out_uint16_le(s, 1002); /* targetUser (2 bytes) */
s_mark_end(s); s_mark_end(s);
if (xrdp_rdp_send_data(self, s, RDP_DATA_PDU_SYNCHRONISE) != 0) if (xrdp_rdp_send_data(self, s, RDP_DATA_PDU_SYNCHRONISE) != 0)

@ -10,7 +10,7 @@ AllowRootLogin=1
MaxLoginRetry=4 MaxLoginRetry=4
TerminalServerUsers=tsusers TerminalServerUsers=tsusers
TerminalServerAdmins=tsadmins TerminalServerAdmins=tsadmins
# When AlwaysGroupCheck = false access will be permitted # When AlwaysGroupCheck = false access will be permitted
# if the group TerminalServerUsers is not defined. # if the group TerminalServerUsers is not defined.
AlwaysGroupCheck = false AlwaysGroupCheck = false
@ -51,7 +51,9 @@ param7=96
[Xorg] [Xorg]
param1=-config param1=-config
param2=xrdp/xorg.conf param2=xrdp/xorg.conf
param3=-logfile param3=-logfile
param4=/dev/null param4=/dev/null
param5=-noreset param5=-noreset
param6=-ac param6=-ac
param7=-nolisten
param8=tcp

@ -26,6 +26,7 @@
#include "parse.h" #include "parse.h"
#include "trans.h" #include "trans.h"
#include "list.h" #include "list.h"
#include "list16.h"
#include "libxrdpinc.h" #include "libxrdpinc.h"
#include "xrdp_constants.h" #include "xrdp_constants.h"
#include "xrdp_types.h" #include "xrdp_types.h"
@ -206,6 +207,8 @@ xrdp_bitmap_copy_box(struct xrdp_bitmap* self,
struct xrdp_bitmap* dest, struct xrdp_bitmap* dest,
int x, int y, int cx, int cy); int x, int y, int cx, int cy);
int APP_CC int APP_CC
xrdp_bitmap_hash_crc(struct xrdp_bitmap *self);
int APP_CC
xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap* self, xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap* self,
struct xrdp_bitmap* dest, struct xrdp_bitmap* dest,
int x, int y, int cx, int cy); int x, int y, int cx, int cy);
@ -213,9 +216,6 @@ int APP_CC
xrdp_bitmap_compare(struct xrdp_bitmap* self, xrdp_bitmap_compare(struct xrdp_bitmap* self,
struct xrdp_bitmap* b); struct xrdp_bitmap* b);
int APP_CC int APP_CC
xrdp_bitmap_compare_with_crc(struct xrdp_bitmap* self,
struct xrdp_bitmap* b);
int APP_CC
xrdp_bitmap_invalidate(struct xrdp_bitmap* self, struct xrdp_rect* rect); xrdp_bitmap_invalidate(struct xrdp_bitmap* self, struct xrdp_rect* rect);
int APP_CC int APP_CC
xrdp_bitmap_def_proc(struct xrdp_bitmap* self, int msg, xrdp_bitmap_def_proc(struct xrdp_bitmap* self, int msg,

@ -23,9 +23,22 @@
#include "xrdp.h" #include "xrdp.h"
#include "log.h" #include "log.h"
#include "crc16.h"
static int g_crc_seed = 0xffffffff;
static int g_crc_table[256] = #define LLOG_LEVEL 1
#define LLOGLN(_level, _args) \
do \
{ \
if (_level < LLOG_LEVEL) \
{ \
g_write("xrdp:xrdp_bitmap [%10.10u]: ", g_time3()); \
g_writeln _args ; \
} \
} \
while (0)
static const int g_crc_table[256] =
{ {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
@ -72,10 +85,10 @@ static int g_crc_table[256] =
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
}; };
#define CRC_START(in_crc) (in_crc) = g_crc_seed #define CRC_START(in_crc) (in_crc) = 0xFFFFFFFF
#define CRC_PASS(in_pixel, in_crc) \ #define CRC_PASS(in_pixel, in_crc) \
(in_crc) = g_crc_table[((in_crc) ^ (in_pixel)) & 0xff] ^ ((in_crc) >> 8) (in_crc) = g_crc_table[((in_crc) ^ (in_pixel)) & 0xff] ^ ((in_crc) >> 8)
#define CRC_END(in_crc) (in_crc) = ((in_crc) ^ g_crc_seed) #define CRC_END(in_crc) (in_crc) = ((in_crc) ^ 0xFFFFFFFF)
/*****************************************************************************/ /*****************************************************************************/
struct xrdp_bitmap *APP_CC struct xrdp_bitmap *APP_CC
@ -716,11 +729,17 @@ xrdp_bitmap_copy_box(struct xrdp_bitmap *self,
struct xrdp_bitmap *dest, struct xrdp_bitmap *dest,
int x, int y, int cx, int cy) int x, int y, int cx, int cy)
{ {
int i = 0; int i;
int j = 0; int destx;
int destx = 0; int desty;
int desty = 0; int incs;
int pixel = 0; int incd;
tui8 *s8;
tui8 *d8;
tui16 *s16;
tui16 *d16;
tui32 *s32;
tui32 *d32;
if (self == 0) if (self == 0)
{ {
@ -762,35 +781,54 @@ xrdp_bitmap_copy_box(struct xrdp_bitmap *self,
if (self->bpp == 24) if (self->bpp == 24)
{ {
s32 = ((tui32 *)(self->data)) + (self->width * y + x);
d32 = ((tui32 *)(dest->data)) + (dest->width * desty + destx);
incs = self->width - cx;
incd = dest->width - cx;
for (i = 0; i < cy; i++) for (i = 0; i < cy; i++)
{ {
for (j = 0; j < cx; j++) g_memcpy(d32, s32, cx * 4);
{ s32 += cx;
pixel = GETPIXEL32(self->data, j + x, i + y, self->width); d32 += cx;
SETPIXEL32(dest->data, j + destx, i + desty, dest->width, pixel);
} s32 += incs;
d32 += incd;
} }
} }
else if (self->bpp == 15 || self->bpp == 16) else if (self->bpp == 15 || self->bpp == 16)
{ {
s16 = ((tui16 *)(self->data)) + (self->width * y + x);
d16 = ((tui16 *)(dest->data)) + (dest->width * desty + destx);
incs = self->width - cx;
incd = dest->width - cx;
for (i = 0; i < cy; i++) for (i = 0; i < cy; i++)
{ {
for (j = 0; j < cx; j++) g_memcpy(d16, s16, cx * 2);
{ s16 += cx;
pixel = GETPIXEL16(self->data, j + x, i + y, self->width); d16 += cx;
SETPIXEL16(dest->data, j + destx, i + desty, dest->width, pixel);
} s16 += incs;
d16 += incd;
} }
} }
else if (self->bpp == 8) else if (self->bpp == 8)
{ {
s8 = ((tui8 *)(self->data)) + (self->width * y + x);
d8 = ((tui8 *)(dest->data)) + (dest->width * desty + destx);
incs = self->width - cx;
incd = dest->width - cx;
for (i = 0; i < cy; i++) for (i = 0; i < cy; i++)
{ {
for (j = 0; j < cx; j++) g_memcpy(d8, s8, cx);
{ s8 += cx;
pixel = GETPIXEL8(self->data, j + x, i + y, self->width); d8 += cx;
SETPIXEL8(dest->data, j + destx, i + desty, dest->width, pixel);
} s8 += incs;
d8 += incd;
} }
} }
else else
@ -801,6 +839,51 @@ xrdp_bitmap_copy_box(struct xrdp_bitmap *self,
return 0; return 0;
} }
/*****************************************************************************/
int APP_CC
xrdp_bitmap_hash_crc(struct xrdp_bitmap *self)
{
void *hash;
int bytes;
int crc;
int index;
char hash_data[16];
if (self->bpp == 24)
{
bytes = self->width * self->height * 4;
}
else if (self->bpp == 15 || self->bpp == 16)
{
bytes = self->width * self->height * 2;
}
else if (self->bpp == 8)
{
bytes = self->width * self->height;
}
else
{
return 1;
}
hash = ssl_md5_info_create();
ssl_md5_transform(hash, self->data, bytes);
ssl_md5_complete(hash, hash_data);
ssl_md5_info_delete(hash);
CRC_START(crc);
CRC_PASS(self->width, crc);
CRC_PASS(self->width >> 8, crc);
CRC_PASS(self->height, crc);
CRC_PASS(self->height >> 8, crc);
for (index = 0; index < 16; index++)
{
CRC_PASS(hash_data[index], crc);
}
CRC_END(crc);
self->crc32 = crc;
self->crc16 = self->crc32 & 0xffff;
return 0;
}
/*****************************************************************************/ /*****************************************************************************/
/* copy part of self at x, y to 0, 0 in dest */ /* copy part of self at x, y to 0, 0 in dest */
/* returns error */ /* returns error */
@ -809,20 +892,20 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
struct xrdp_bitmap *dest, struct xrdp_bitmap *dest,
int x, int y, int cx, int cy) int x, int y, int cx, int cy)
{ {
int i = 0; int i;
int j = 0; int j;
int destx = 0; int destx;
int desty = 0; int desty;
int pixel = 0; int pixel;
int crc = 0; int crc;
int incs = 0; int incs;
int incd = 0; int incd;
unsigned char *s8 = (unsigned char *)NULL; tui8 *s8;
unsigned char *d8 = (unsigned char *)NULL; tui8 *d8;
unsigned short *s16 = (unsigned short *)NULL; tui16 *s16;
unsigned short *d16 = (unsigned short *)NULL; tui16 *d16;
unsigned int *s32; tui32 *s32;
unsigned int *d32; tui32 *d32;
if (self == 0) if (self == 0)
{ {
@ -864,47 +947,54 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
CRC_START(crc); CRC_START(crc);
CRC_PASS(self->width, crc);
CRC_PASS(self->width >> 8, crc);
CRC_PASS(self->height, crc);
CRC_PASS(self->height >> 8, crc);
if (self->bpp == 24) if (self->bpp == 24)
{ {
s32 = ((unsigned int *)(self->data)) + (self->width * y + x); s32 = ((tui32 *)(self->data)) + (self->width * y + x);
d32 = ((unsigned int *)(dest->data)) + (dest->width * desty + destx); d32 = ((tui32 *)(dest->data)) + (dest->width * desty + destx);
incs = self->width - cx; incs = self->width - cx;
incd = dest->width - cx; incd = dest->width - cx;
for (i = 0; i < cy; i++) for (i = 0; i < cy; i++)
{ {
j = 0; j = 0;
while (j < cx - 4) while (j < cx - 4)
{ {
pixel = *s32; pixel = *s32;
*d32 = pixel;
CRC_PASS(pixel, crc); CRC_PASS(pixel, crc);
CRC_PASS(pixel >> 8, crc); CRC_PASS(pixel >> 8, crc);
CRC_PASS(pixel >> 16, crc); CRC_PASS(pixel >> 16, crc);
*d32 = pixel;
s32++; s32++;
d32++; d32++;
pixel = *s32; pixel = *s32;
*d32 = pixel;
CRC_PASS(pixel, crc); CRC_PASS(pixel, crc);
CRC_PASS(pixel >> 8, crc); CRC_PASS(pixel >> 8, crc);
CRC_PASS(pixel >> 16, crc); CRC_PASS(pixel >> 16, crc);
*d32 = pixel;
s32++; s32++;
d32++; d32++;
pixel = *s32; pixel = *s32;
*d32 = pixel;
CRC_PASS(pixel, crc); CRC_PASS(pixel, crc);
CRC_PASS(pixel >> 8, crc); CRC_PASS(pixel >> 8, crc);
CRC_PASS(pixel >> 16, crc); CRC_PASS(pixel >> 16, crc);
*d32 = pixel;
s32++; s32++;
d32++; d32++;
pixel = *s32; pixel = *s32;
*d32 = pixel;
CRC_PASS(pixel, crc); CRC_PASS(pixel, crc);
CRC_PASS(pixel >> 8, crc); CRC_PASS(pixel >> 8, crc);
CRC_PASS(pixel >> 16, crc); CRC_PASS(pixel >> 16, crc);
*d32 = pixel;
s32++; s32++;
d32++; d32++;
@ -913,10 +1003,10 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
while (j < cx) while (j < cx)
{ {
pixel = *s32; pixel = *s32;
*d32 = pixel;
CRC_PASS(pixel, crc); CRC_PASS(pixel, crc);
CRC_PASS(pixel >> 8, crc); CRC_PASS(pixel >> 8, crc);
CRC_PASS(pixel >> 16, crc); CRC_PASS(pixel >> 16, crc);
*d32 = pixel;
s32++; s32++;
d32++; d32++;
@ -929,8 +1019,8 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
} }
else if (self->bpp == 15 || self->bpp == 16) else if (self->bpp == 15 || self->bpp == 16)
{ {
s16 = ((unsigned short *)(self->data)) + (self->width * y + x); s16 = ((tui16 *)(self->data)) + (self->width * y + x);
d16 = ((unsigned short *)(dest->data)) + (dest->width * desty + destx); d16 = ((tui16 *)(dest->data)) + (dest->width * desty + destx);
incs = self->width - cx; incs = self->width - cx;
incd = dest->width - cx; incd = dest->width - cx;
@ -939,9 +1029,9 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
for (j = 0; j < cx; j++) for (j = 0; j < cx; j++)
{ {
pixel = *s16; pixel = *s16;
*d16 = pixel;
CRC_PASS(pixel, crc); CRC_PASS(pixel, crc);
CRC_PASS(pixel >> 8, crc); CRC_PASS(pixel >> 8, crc);
*d16 = pixel;
s16++; s16++;
d16++; d16++;
} }
@ -952,8 +1042,8 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
} }
else if (self->bpp == 8) else if (self->bpp == 8)
{ {
s8 = ((unsigned char *)(self->data)) + (self->width * y + x); s8 = ((tui8 *)(self->data)) + (self->width * y + x);
d8 = ((unsigned char *)(dest->data)) + (dest->width * desty + destx); d8 = ((tui8 *)(dest->data)) + (dest->width * desty + destx);
incs = self->width - cx; incs = self->width - cx;
incd = dest->width - cx; incd = dest->width - cx;
@ -962,8 +1052,8 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
for (j = 0; j < cx; j++) for (j = 0; j < cx; j++)
{ {
pixel = *s8; pixel = *s8;
CRC_PASS(pixel, crc);
*d8 = pixel; *d8 = pixel;
CRC_PASS(pixel, crc);
s8++; s8++;
d8++; d8++;
} }
@ -978,7 +1068,14 @@ xrdp_bitmap_copy_box_with_crc(struct xrdp_bitmap *self,
} }
CRC_END(crc); CRC_END(crc);
dest->crc = crc; dest->crc32 = crc;
dest->crc16 = dest->crc32 & 0xffff;
LLOGLN(10, ("xrdp_bitmap_copy_box_with_crc: crc16 0x%4.4x",
dest->crc16));
LLOGLN(10, ("xrdp_bitmap_copy_box_with_crc: width %d height %d",
dest->width, dest->height));
return 0; return 0;
} }
@ -988,45 +1085,8 @@ int APP_CC
xrdp_bitmap_compare(struct xrdp_bitmap *self, xrdp_bitmap_compare(struct xrdp_bitmap *self,
struct xrdp_bitmap *b) struct xrdp_bitmap *b)
{ {
if (self == 0) LLOGLN(10, ("xrdp_bitmap_compare:"));
{
return 0;
}
if (b == 0)
{
return 0;
}
if (self->bpp != b->bpp)
{
return 0;
}
if (self->width != b->width)
{
return 0;
}
if (self->height != b->height)
{
return 0;
}
if (g_memcmp(self->data, b->data, b->height * b->line_size) == 0)
{
return 1;
}
return 0;
}
/*****************************************************************************/
/* returns true if they are the same, else returns false */
int APP_CC
xrdp_bitmap_compare_with_crc(struct xrdp_bitmap *self,
struct xrdp_bitmap *b)
{
if (self == 0) if (self == 0)
{ {
return 0; return 0;
@ -1052,7 +1112,7 @@ xrdp_bitmap_compare_with_crc(struct xrdp_bitmap *self,
return 0; return 0;
} }
if (self->crc == b->crc) if (g_memcmp(self->data, b->data, b->height * b->line_size) == 0)
{ {
return 1; return 1;
} }

@ -20,6 +20,7 @@
#include "xrdp.h" #include "xrdp.h"
#include "log.h" #include "log.h"
#include "crc16.h"
#define LLOG_LEVEL 1 #define LLOG_LEVEL 1
#define LLOGLN(_level, _args) \ #define LLOGLN(_level, _args) \
@ -33,6 +34,59 @@
} \ } \
while (0) while (0)
/*****************************************************************************/
static int APP_CC
xrdp_cache_reset_lru(struct xrdp_cache *self)
{
int index;
int jndex;
struct xrdp_lru_item *lru;
for (index = 0; index < XRDP_MAX_BITMAP_CACHE_ID; index++)
{
/* fist item */
lru = &(self->bitmap_lrus[index][0]);
lru->next = 1;
lru->prev = -1;
/* middle items */
for (jndex = 1; jndex < XRDP_MAX_BITMAP_CACHE_IDX - 1; jndex++)
{
lru = &(self->bitmap_lrus[index][jndex]);
lru->next = jndex + 1;
lru->prev = jndex - 1;
}
/* last item */
lru = &(self->bitmap_lrus[index][XRDP_MAX_BITMAP_CACHE_IDX - 1]);
lru->next = -1;
lru->prev = XRDP_MAX_BITMAP_CACHE_IDX - 2;
self->lru_head[index] = 0;
self->lru_tail[index] = XRDP_MAX_BITMAP_CACHE_IDX - 1;
self->lru_reset[index] = 1;
}
return 0;
}
/*****************************************************************************/
static int APP_CC
xrdp_cache_reset_crc(struct xrdp_cache *self)
{
int index;
int jndex;
for (index = 0; index < XRDP_MAX_BITMAP_CACHE_ID; index++)
{
for (jndex = 0; jndex < 64 * 1024; jndex++)
{
/* it's ok it deinit a zero'ed out struct list16 */
list16_deinit(&(self->crc16[index][jndex]));
list16_init(&(self->crc16[index][jndex]));
}
}
return 0;
}
/*****************************************************************************/ /*****************************************************************************/
struct xrdp_cache *APP_CC struct xrdp_cache *APP_CC
xrdp_cache_create(struct xrdp_wm *owner, xrdp_cache_create(struct xrdp_wm *owner,
@ -65,6 +119,8 @@ xrdp_cache_create(struct xrdp_wm *owner,
self->bitmap_cache_version = client_info->bitmap_cache_version; self->bitmap_cache_version = client_info->bitmap_cache_version;
self->pointer_cache_entries = client_info->pointer_cache_entries; self->pointer_cache_entries = client_info->pointer_cache_entries;
self->xrdp_os_del_list = list_create(); self->xrdp_os_del_list = list_create();
xrdp_cache_reset_lru(self);
xrdp_cache_reset_crc(self);
LLOGLN(10, ("xrdp_cache_create: 0 %d 1 %d 2 %d", LLOGLN(10, ("xrdp_cache_create: 0 %d 1 %d 2 %d",
self->cache1_entries, self->cache2_entries, self->cache3_entries)); self->cache1_entries, self->cache2_entries, self->cache3_entries));
return self; return self;
@ -108,6 +164,15 @@ xrdp_cache_delete(struct xrdp_cache *self)
list_delete(self->xrdp_os_del_list); list_delete(self->xrdp_os_del_list);
/* free all crc lists */
for (i = 0; i < XRDP_MAX_BITMAP_CACHE_ID; i++)
{
for (j = 0; j < 64 * 1024; j++)
{
list16_deinit(&(self->crc16[i][j]));
}
}
g_free(self); g_free(self);
} }
@ -157,157 +222,228 @@ xrdp_cache_reset(struct xrdp_cache *self,
self->bitmap_cache_persist_enable = client_info->bitmap_cache_persist_enable; self->bitmap_cache_persist_enable = client_info->bitmap_cache_persist_enable;
self->bitmap_cache_version = client_info->bitmap_cache_version; self->bitmap_cache_version = client_info->bitmap_cache_version;
self->pointer_cache_entries = client_info->pointer_cache_entries; self->pointer_cache_entries = client_info->pointer_cache_entries;
xrdp_cache_reset_lru(self);
xrdp_cache_reset_crc(self);
return 0; return 0;
} }
#define COMPARE_WITH_CRC(_b1, _b2) \ #define COMPARE_WITH_CRC32(_b1, _b2) \
((_b1 != 0) && (_b2 != 0) && (_b1->crc == _b2->crc) && \ ((_b1 != 0) && (_b2 != 0) && (_b1->crc32 == _b2->crc32) && \
(_b1->bpp == _b2->bpp) && \ (_b1->bpp == _b2->bpp) && \
(_b1->width == _b2->width) && (_b1->height == _b2->height)) (_b1->width == _b2->width) && (_b1->height == _b2->height))
/*****************************************************************************/ /*****************************************************************************/
/* returns cache id */ static int APP_CC
int APP_CC xrdp_cache_update_lru(struct xrdp_cache *self, int cache_id, int lru_index)
xrdp_cache_add_bitmap(struct xrdp_cache *self, struct xrdp_bitmap *bitmap,
int hints)
{ {
int i = 0; int tail_index;
int j = 0; struct xrdp_lru_item *nextlru;
int oldest = 0; struct xrdp_lru_item *prevlru;
int cache_id = 0; struct xrdp_lru_item *thislru;
int cache_idx = 0; struct xrdp_lru_item *taillru;
int bmp_size = 0;
int e = 0; LLOGLN(10, ("xrdp_cache_update_lru: lru_index %d", lru_index));
int Bpp = 0; if ((lru_index < 0) || (lru_index >= XRDP_MAX_BITMAP_CACHE_IDX))
{
LLOGLN(0, ("xrdp_cache_update_lru: error"));
return 1;
}
if (self->lru_tail[cache_id] == lru_index)
{
/* nothing to do */
return 0;
}
else if (self->lru_head[cache_id] == lru_index)
{
/* moving head item to tail */
e = bitmap->width % 4; thislru = &(self->bitmap_lrus[cache_id][lru_index]);
nextlru = &(self->bitmap_lrus[cache_id][thislru->next]);
tail_index = self->lru_tail[cache_id];
taillru = &(self->bitmap_lrus[cache_id][tail_index]);
if (e != 0) /* unhook old */
nextlru->prev = -1;
/* set head to next */
self->lru_head[cache_id] = thislru->next;
/* move to tail and hook up */
taillru->next = lru_index;
thislru->prev = tail_index;
thislru->next = -1;
/* update tail */
self->lru_tail[cache_id] = lru_index;
}
else
{ {
e = 4 - e; /* move middle item */
thislru = &(self->bitmap_lrus[cache_id][lru_index]);
prevlru = &(self->bitmap_lrus[cache_id][thislru->prev]);
nextlru = &(self->bitmap_lrus[cache_id][thislru->next]);
tail_index = self->lru_tail[cache_id];
taillru = &(self->bitmap_lrus[cache_id][tail_index]);
/* unhook old */
prevlru->next = thislru->next;
nextlru->prev = thislru->prev;
/* move to tail and hook up */
taillru->next = lru_index;
thislru->prev = tail_index;
thislru->next = -1;
/* update tail */
self->lru_tail[cache_id] = lru_index;
} }
return 0;
}
/*****************************************************************************/
/* returns cache id */
int APP_CC
xrdp_cache_add_bitmap(struct xrdp_cache *self, struct xrdp_bitmap *bitmap,
int hints)
{
int index;
int jndex;
int cache_id;
int cache_idx;
int bmp_size;
int e;
int Bpp;
int crc16;
int iig;
int found;
int cache_entries;
int lru_index;
struct list16 *ll;
struct xrdp_bitmap *lbm;
struct xrdp_lru_item *llru;
LLOGLN(10, ("xrdp_cache_add_bitmap:"));
LLOGLN(10, ("xrdp_cache_add_bitmap: crc16 0x%4.4x",
bitmap->crc16));
e = (4 - (bitmap->width % 4)) & 3;
found = 0;
cache_id = 0;
cache_entries = 0;
/* client Bpp, bmp_size */
Bpp = (bitmap->bpp + 7) / 8; Bpp = (bitmap->bpp + 7) / 8;
bmp_size = (bitmap->width + e) * bitmap->height * Bpp; bmp_size = (bitmap->width + e) * bitmap->height * Bpp;
self->bitmap_stamp++; self->bitmap_stamp++;
/* look for match */
if (bmp_size <= self->cache1_size) if (bmp_size <= self->cache1_size)
{ {
i = 0; cache_id = 0;
cache_entries = self->cache1_entries;
for (j = 0; j < self->cache1_entries; j++)
{
#ifdef USE_CRC
if (COMPARE_WITH_CRC(self->bitmap_items[i][j].bitmap, bitmap))
#else
if (xrdp_bitmap_compare(self->bitmap_items[i][j].bitmap, bitmap))
#endif
{
self->bitmap_items[i][j].stamp = self->bitmap_stamp;
LLOGLN(10, ("found bitmap at %d %d", i, j));
xrdp_bitmap_delete(bitmap);
return MAKELONG(j, i);
}
}
} }
else if (bmp_size <= self->cache2_size) else if (bmp_size <= self->cache2_size)
{ {
i = 1; cache_id = 1;
cache_entries = self->cache2_entries;
for (j = 0; j < self->cache2_entries; j++)
{
#ifdef USE_CRC
if (COMPARE_WITH_CRC(self->bitmap_items[i][j].bitmap, bitmap))
#else
if (xrdp_bitmap_compare(self->bitmap_items[i][j].bitmap, bitmap))
#endif
{
self->bitmap_items[i][j].stamp = self->bitmap_stamp;
LLOGLN(10, ("found bitmap at %d %d", i, j));
xrdp_bitmap_delete(bitmap);
return MAKELONG(j, i);
}
}
} }
else if (bmp_size <= self->cache3_size) else if (bmp_size <= self->cache3_size)
{ {
i = 2; cache_id = 2;
cache_entries = self->cache3_entries;
for (j = 0; j < self->cache3_entries; j++)
{
#ifdef USE_CRC
if (COMPARE_WITH_CRC(self->bitmap_items[i][j].bitmap, bitmap))
#else
if (xrdp_bitmap_compare(self->bitmap_items[i][j].bitmap, bitmap))
#endif
{
self->bitmap_items[i][j].stamp = self->bitmap_stamp;
LLOGLN(10, ("found bitmap at %d %d", i, j));
xrdp_bitmap_delete(bitmap);
return MAKELONG(j, i);
}
}
} }
else else
{ {
log_message(LOG_LEVEL_ERROR,"error in xrdp_cache_add_bitmap, too big(%d) bpp %d", bmp_size, bitmap->bpp); log_message(LOG_LEVEL_ERROR, "error in xrdp_cache_add_bitmap, "
"too big(%d) bpp %d", bmp_size, bitmap->bpp);
return 0;
} }
/* look for oldest */ crc16 = bitmap->crc16;
cache_id = 0; ll = &(self->crc16[cache_id][crc16]);
cache_idx = 0; for (jndex = 0; jndex < ll->count; jndex++)
oldest = 0x7fffffff;
if (bmp_size <= self->cache1_size)
{ {
i = 0; cache_idx = list16_get_item(ll, jndex);
if (COMPARE_WITH_CRC32
for (j = 0; j < self->cache1_entries; j++) (self->bitmap_items[cache_id][cache_idx].bitmap, bitmap))
{ {
if (self->bitmap_items[i][j].stamp < oldest) LLOGLN(10, ("found bitmap at %d %d", index, jndex));
{ found = 1;
oldest = self->bitmap_items[i][j].stamp; break;
cache_id = i;
cache_idx = j;
}
} }
} }
else if (bmp_size <= self->cache2_size) if (found)
{ {
i = 1; lru_index = self->bitmap_items[cache_id][cache_idx].lru_index;
self->bitmap_items[cache_id][cache_idx].stamp = self->bitmap_stamp;
xrdp_bitmap_delete(bitmap);
for (j = 0; j < self->cache2_entries; j++) /* update lru to end */
{ xrdp_cache_update_lru(self, cache_id, lru_index);
if (self->bitmap_items[i][j].stamp < oldest)
{ return MAKELONG(cache_idx, cache_id);
oldest = self->bitmap_items[i][j].stamp;
cache_id = i;
cache_idx = j;
}
}
} }
else if (bmp_size <= self->cache3_size)
/* find lru */
/* check for reset */
if (self->lru_reset[cache_id])
{ {
i = 2; self->lru_reset[cache_id] = 0;
LLOGLN(0, ("xrdp_cache_add_bitmap: reset detected cache_id %d",
cache_id));
self->lru_tail[cache_id] = cache_entries - 1;
index = self->lru_tail[cache_id];
llru = &(self->bitmap_lrus[cache_id][index]);
llru->next = -1;
}
/* lru is item at head */
lru_index = self->lru_head[cache_id];
cache_idx = lru_index;
/* update lru to end */
xrdp_cache_update_lru(self, cache_id, lru_index);
LLOGLN(10, ("xrdp_cache_add_bitmap: oldest %d %d", cache_id, cache_idx));
LLOGLN(10, ("adding bitmap at %d %d old ptr %p new ptr %p",
cache_id, cache_idx,
self->bitmap_items[cache_id][cache_idx].bitmap,
bitmap));
for (j = 0; j < self->cache3_entries; j++) /* remove old, about to be deleted, from crc16 list */
lbm = self->bitmap_items[cache_id][cache_idx].bitmap;
if (lbm != 0)
{
crc16 = lbm->crc16;
ll = &(self->crc16[cache_id][crc16]);
iig = list16_index_of(ll, cache_idx);
if (iig == -1)
{ {
if (self->bitmap_items[i][j].stamp < oldest) LLOGLN(0, ("xrdp_cache_add_bitmap: error removing cache_idx"));
{
oldest = self->bitmap_items[i][j].stamp;
cache_id = i;
cache_idx = j;
}
} }
LLOGLN(10, ("xrdp_cache_add_bitmap: removing index %d from crc16 %d",
iig, crc16));
list16_remove_item(ll, iig);
xrdp_bitmap_delete(lbm);
} }
LLOGLN(10, ("adding bitmap at %d %d ptr %p", cache_id, cache_idx,
self->bitmap_items[cache_id][cache_idx].bitmap));
/* set, send bitmap and return */ /* set, send bitmap and return */
xrdp_bitmap_delete(self->bitmap_items[cache_id][cache_idx].bitmap);
self->bitmap_items[cache_id][cache_idx].bitmap = bitmap; self->bitmap_items[cache_id][cache_idx].bitmap = bitmap;
self->bitmap_items[cache_id][cache_idx].stamp = self->bitmap_stamp; self->bitmap_items[cache_id][cache_idx].stamp = self->bitmap_stamp;
self->bitmap_items[cache_id][cache_idx].lru_index = lru_index;
/* add to crc16 list */
crc16 = bitmap->crc16;
ll = &(self->crc16[cache_id][crc16]);
list16_add_item(ll, cache_idx);
if (ll->count > 1)
{
LLOGLN(10, ("xrdp_cache_add_bitmap: count %d", ll->count));
}
if (self->use_bitmap_comp) if (self->use_bitmap_comp)
{ {

@ -850,7 +850,12 @@ xrdp_painter_copy(struct xrdp_painter *self,
w = MIN(64, ((srcx + cx) - i)); w = MIN(64, ((srcx + cx) - i));
h = MIN(64, ((srcy + cy) - j)); h = MIN(64, ((srcy + cy) - j));
b = xrdp_bitmap_create(w, h, src->bpp, 0, self->wm); b = xrdp_bitmap_create(w, h, src->bpp, 0, self->wm);
#if 1
xrdp_bitmap_copy_box_with_crc(src, b, i, j, w, h); xrdp_bitmap_copy_box_with_crc(src, b, i, j, w, h);
#else
xrdp_bitmap_copy_box(src, b, i, j, w, h);
xrdp_bitmap_hash_crc(b);
#endif
bitmap_id = xrdp_cache_add_bitmap(self->wm->cache, b, self->wm->hints); bitmap_id = xrdp_cache_add_bitmap(self->wm->cache, b, self->wm->hints);
cache_id = HIWORD(bitmap_id); cache_id = HIWORD(bitmap_id);
cache_idx = LOWORD(bitmap_id); cache_idx = LOWORD(bitmap_id);

@ -178,9 +178,16 @@ struct xrdp_palette_item
struct xrdp_bitmap_item struct xrdp_bitmap_item
{ {
int stamp; int stamp;
int lru_index;
struct xrdp_bitmap* bitmap; struct xrdp_bitmap* bitmap;
}; };
struct xrdp_lru_item
{
int next;
int prev;
};
struct xrdp_os_bitmap_item struct xrdp_os_bitmap_item
{ {
int id; int id;
@ -226,6 +233,17 @@ struct xrdp_cache
int bitmap_stamp; int bitmap_stamp;
struct xrdp_bitmap_item bitmap_items[XRDP_MAX_BITMAP_CACHE_ID] struct xrdp_bitmap_item bitmap_items[XRDP_MAX_BITMAP_CACHE_ID]
[XRDP_MAX_BITMAP_CACHE_IDX]; [XRDP_MAX_BITMAP_CACHE_IDX];
/* lru optimize */
struct xrdp_lru_item bitmap_lrus[XRDP_MAX_BITMAP_CACHE_ID]
[XRDP_MAX_BITMAP_CACHE_IDX];
int lru_head[XRDP_MAX_BITMAP_CACHE_ID];
int lru_tail[XRDP_MAX_BITMAP_CACHE_ID];
int lru_reset[XRDP_MAX_BITMAP_CACHE_ID];
/* crc optimize */
struct list16 crc16[XRDP_MAX_BITMAP_CACHE_ID][64 * 1024];
int use_bitmap_comp; int use_bitmap_comp;
int cache1_entries; int cache1_entries;
int cache1_size; int cache1_size;
@ -461,7 +479,8 @@ struct xrdp_bitmap
struct xrdp_bitmap* popped_from; struct xrdp_bitmap* popped_from;
int item_height; int item_height;
/* crc */ /* crc */
int crc; int crc32;
int crc16;
}; };
#define NUM_FONTS 0x4e00 #define NUM_FONTS 0x4e00

Loading…
Cancel
Save