2011-07-25 09:45:25 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Client
|
|
|
|
* Update Data PDUs
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-07-25 09:45:25 +04:00
|
|
|
#include "update.h"
|
2011-08-24 19:31:58 +04:00
|
|
|
#include "surface.h"
|
2012-09-24 12:59:18 +04:00
|
|
|
|
2011-10-03 04:28:20 +04:00
|
|
|
#include <freerdp/codec/bitmap.h>
|
2011-07-25 09:45:25 +04:00
|
|
|
|
2011-12-01 02:40:36 +04:00
|
|
|
/*
|
|
|
|
static const char* const UPDATE_TYPE_STRINGS[] =
|
2011-07-25 09:45:25 +04:00
|
|
|
{
|
|
|
|
"Orders",
|
|
|
|
"Bitmap",
|
|
|
|
"Palette",
|
|
|
|
"Synchronize"
|
|
|
|
};
|
2011-12-01 02:40:36 +04:00
|
|
|
*/
|
2011-07-25 09:45:25 +04:00
|
|
|
|
2012-02-11 17:30:09 +04:00
|
|
|
boolean update_recv_orders(rdpUpdate* update, STREAM* s)
|
2011-07-25 09:45:25 +04:00
|
|
|
{
|
|
|
|
uint16 numberOrders;
|
|
|
|
|
|
|
|
stream_seek_uint16(s); /* pad2OctetsA (2 bytes) */
|
|
|
|
stream_read_uint16(s, numberOrders); /* numberOrders (2 bytes) */
|
|
|
|
stream_seek_uint16(s); /* pad2OctetsB (2 bytes) */
|
2011-07-25 22:50:26 +04:00
|
|
|
|
|
|
|
while (numberOrders > 0)
|
|
|
|
{
|
2012-02-11 17:30:09 +04:00
|
|
|
if (!update_recv_order(update, s))
|
|
|
|
return false;
|
2011-07-25 22:50:26 +04:00
|
|
|
numberOrders--;
|
|
|
|
}
|
2012-02-11 17:30:09 +04:00
|
|
|
|
|
|
|
return true;
|
2011-07-25 09:45:25 +04:00
|
|
|
}
|
|
|
|
|
2011-10-21 01:28:59 +04:00
|
|
|
void update_read_bitmap_data(STREAM* s, BITMAP_DATA* bitmap_data)
|
2011-07-25 09:45:25 +04:00
|
|
|
{
|
2011-10-21 01:28:59 +04:00
|
|
|
stream_read_uint16(s, bitmap_data->destLeft);
|
|
|
|
stream_read_uint16(s, bitmap_data->destTop);
|
|
|
|
stream_read_uint16(s, bitmap_data->destRight);
|
|
|
|
stream_read_uint16(s, bitmap_data->destBottom);
|
2011-07-25 09:45:25 +04:00
|
|
|
stream_read_uint16(s, bitmap_data->width);
|
|
|
|
stream_read_uint16(s, bitmap_data->height);
|
2011-10-21 01:28:59 +04:00
|
|
|
stream_read_uint16(s, bitmap_data->bitsPerPixel);
|
2011-07-25 09:45:25 +04:00
|
|
|
stream_read_uint16(s, bitmap_data->flags);
|
2011-10-21 01:28:59 +04:00
|
|
|
stream_read_uint16(s, bitmap_data->bitmapLength);
|
2011-07-25 09:45:25 +04:00
|
|
|
|
2011-07-25 22:50:26 +04:00
|
|
|
if (bitmap_data->flags & BITMAP_COMPRESSION)
|
|
|
|
{
|
2011-12-20 05:31:37 +04:00
|
|
|
if (!(bitmap_data->flags & NO_BITMAP_COMPRESSION_HDR))
|
|
|
|
{
|
|
|
|
stream_read_uint16(s, bitmap_data->cbCompFirstRowSize); /* cbCompFirstRowSize (2 bytes) */
|
|
|
|
stream_read_uint16(s, bitmap_data->cbCompMainBodySize); /* cbCompMainBodySize (2 bytes) */
|
|
|
|
stream_read_uint16(s, bitmap_data->cbScanWidth); /* cbScanWidth (2 bytes) */
|
|
|
|
stream_read_uint16(s, bitmap_data->cbUncompressedSize); /* cbUncompressedSize (2 bytes) */
|
|
|
|
bitmap_data->bitmapLength = bitmap_data->cbCompMainBodySize;
|
|
|
|
}
|
2011-07-25 22:50:26 +04:00
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
bitmap_data->compressed = true;
|
2011-10-21 01:28:59 +04:00
|
|
|
stream_get_mark(s, bitmap_data->bitmapDataStream);
|
|
|
|
stream_seek(s, bitmap_data->bitmapLength);
|
2011-08-04 11:39:10 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-11-19 21:19:16 +04:00
|
|
|
bitmap_data->compressed = false;
|
2011-10-21 01:28:59 +04:00
|
|
|
stream_get_mark(s, bitmap_data->bitmapDataStream);
|
|
|
|
stream_seek(s, bitmap_data->bitmapLength);
|
2011-08-04 11:39:10 +04:00
|
|
|
}
|
2011-07-25 09:45:25 +04:00
|
|
|
}
|
|
|
|
|
2011-07-28 08:38:25 +04:00
|
|
|
void update_read_bitmap(rdpUpdate* update, STREAM* s, BITMAP_UPDATE* bitmap_update)
|
2011-07-25 09:45:25 +04:00
|
|
|
{
|
2011-07-27 02:32:14 +04:00
|
|
|
int i;
|
2011-07-25 09:45:25 +04:00
|
|
|
|
2011-07-27 02:32:14 +04:00
|
|
|
stream_read_uint16(s, bitmap_update->number); /* numberRectangles (2 bytes) */
|
|
|
|
|
2011-10-03 07:09:13 +04:00
|
|
|
if (bitmap_update->number > bitmap_update->count)
|
|
|
|
{
|
|
|
|
uint16 count;
|
|
|
|
|
|
|
|
count = bitmap_update->number * 2;
|
|
|
|
|
2011-10-21 05:34:55 +04:00
|
|
|
bitmap_update->rectangles = (BITMAP_DATA*) xrealloc(bitmap_update->rectangles,
|
2011-10-21 01:28:59 +04:00
|
|
|
sizeof(BITMAP_DATA) * count);
|
2011-10-03 07:09:13 +04:00
|
|
|
|
2011-10-21 05:34:55 +04:00
|
|
|
memset(&bitmap_update->rectangles[bitmap_update->count], 0,
|
2011-10-21 01:28:59 +04:00
|
|
|
sizeof(BITMAP_DATA) * (count - bitmap_update->count));
|
2011-10-03 07:09:13 +04:00
|
|
|
|
|
|
|
bitmap_update->count = count;
|
|
|
|
}
|
2011-07-25 09:45:25 +04:00
|
|
|
|
|
|
|
/* rectangles */
|
2011-12-04 02:24:18 +04:00
|
|
|
for (i = 0; i < (int) bitmap_update->number; i++)
|
2011-07-25 09:45:25 +04:00
|
|
|
{
|
2011-10-21 05:34:55 +04:00
|
|
|
update_read_bitmap_data(s, &bitmap_update->rectangles[i]);
|
2011-07-25 09:45:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-28 08:38:25 +04:00
|
|
|
void update_read_palette(rdpUpdate* update, STREAM* s, PALETTE_UPDATE* palette_update)
|
2011-07-25 09:45:25 +04:00
|
|
|
{
|
2011-07-27 02:32:14 +04:00
|
|
|
int i;
|
2011-10-21 20:17:04 +04:00
|
|
|
PALETTE_ENTRY* entry;
|
2011-07-27 02:32:14 +04:00
|
|
|
|
2011-07-25 09:45:25 +04:00
|
|
|
stream_seek_uint16(s); /* pad2Octets (2 bytes) */
|
2011-08-05 18:48:36 +04:00
|
|
|
stream_read_uint32(s, palette_update->number); /* numberColors (4 bytes), must be set to 256 */
|
2011-07-27 02:32:14 +04:00
|
|
|
|
|
|
|
if (palette_update->number > 256)
|
|
|
|
palette_update->number = 256;
|
2011-07-25 09:45:25 +04:00
|
|
|
|
|
|
|
/* paletteEntries */
|
2011-08-17 05:08:14 +04:00
|
|
|
for (i = 0; i < (int) palette_update->number; i++)
|
2011-07-27 02:32:14 +04:00
|
|
|
{
|
2011-10-21 20:17:04 +04:00
|
|
|
entry = &palette_update->entries[i];
|
|
|
|
|
|
|
|
stream_read_uint8(s, entry->blue);
|
|
|
|
stream_read_uint8(s, entry->green);
|
|
|
|
stream_read_uint8(s, entry->red);
|
2011-07-27 02:32:14 +04:00
|
|
|
}
|
2011-07-25 09:45:25 +04:00
|
|
|
}
|
|
|
|
|
2011-07-28 08:38:25 +04:00
|
|
|
void update_read_synchronize(rdpUpdate* update, STREAM* s)
|
2011-07-25 09:45:25 +04:00
|
|
|
{
|
|
|
|
stream_seek_uint16(s); /* pad2Octets (2 bytes) */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Synchronize Update is an artifact from the
|
|
|
|
* T.128 protocol and should be ignored.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2011-08-24 10:54:46 +04:00
|
|
|
void update_read_play_sound(STREAM* s, PLAY_SOUND_UPDATE* play_sound)
|
|
|
|
{
|
|
|
|
stream_read_uint32(s, play_sound->duration); /* duration (4 bytes) */
|
|
|
|
stream_read_uint32(s, play_sound->frequency); /* frequency (4 bytes) */
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_recv_play_sound(rdpUpdate* update, STREAM* s)
|
|
|
|
{
|
|
|
|
update_read_play_sound(s, &update->play_sound);
|
2011-11-22 04:41:49 +04:00
|
|
|
IFCALL(update->PlaySound, update->context, &update->play_sound);
|
2011-08-24 10:54:46 +04:00
|
|
|
}
|
|
|
|
|
2011-08-24 10:38:39 +04:00
|
|
|
void update_read_pointer_position(STREAM* s, POINTER_POSITION_UPDATE* pointer_position)
|
|
|
|
{
|
|
|
|
stream_read_uint16(s, pointer_position->xPos); /* xPos (2 bytes) */
|
|
|
|
stream_read_uint16(s, pointer_position->yPos); /* yPos (2 bytes) */
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_read_pointer_system(STREAM* s, POINTER_SYSTEM_UPDATE* pointer_system)
|
|
|
|
{
|
|
|
|
stream_read_uint32(s, pointer_system->type); /* systemPointerType (4 bytes) */
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_read_pointer_color(STREAM* s, POINTER_COLOR_UPDATE* pointer_color)
|
|
|
|
{
|
|
|
|
stream_read_uint16(s, pointer_color->cacheIndex); /* cacheIndex (2 bytes) */
|
2011-09-29 08:33:16 +04:00
|
|
|
stream_read_uint16(s, pointer_color->xPos); /* xPos (2 bytes) */
|
|
|
|
stream_read_uint16(s, pointer_color->yPos); /* yPos (2 bytes) */
|
2011-08-24 10:38:39 +04:00
|
|
|
stream_read_uint16(s, pointer_color->width); /* width (2 bytes) */
|
|
|
|
stream_read_uint16(s, pointer_color->height); /* height (2 bytes) */
|
|
|
|
stream_read_uint16(s, pointer_color->lengthAndMask); /* lengthAndMask (2 bytes) */
|
|
|
|
stream_read_uint16(s, pointer_color->lengthXorMask); /* lengthXorMask (2 bytes) */
|
|
|
|
|
2012-03-18 23:34:08 +04:00
|
|
|
/**
|
|
|
|
* There does not seem to be any documentation on why
|
|
|
|
* xPos / yPos can be larger than width / height
|
|
|
|
* so it is missing in documentation or a bug in implementation
|
|
|
|
* 2.2.9.1.1.4.4 Color Pointer Update (TS_COLORPOINTERATTRIBUTE)
|
|
|
|
*/
|
|
|
|
if (pointer_color->xPos >= pointer_color->width)
|
|
|
|
pointer_color->xPos = 0;
|
|
|
|
if (pointer_color->yPos >= pointer_color->height)
|
|
|
|
pointer_color->yPos = 0;
|
|
|
|
|
2011-08-24 10:38:39 +04:00
|
|
|
if (pointer_color->lengthXorMask > 0)
|
|
|
|
{
|
|
|
|
pointer_color->xorMaskData = (uint8*) xmalloc(pointer_color->lengthXorMask);
|
|
|
|
stream_read(s, pointer_color->xorMaskData, pointer_color->lengthXorMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pointer_color->lengthAndMask > 0)
|
|
|
|
{
|
|
|
|
pointer_color->andMaskData = (uint8*) xmalloc(pointer_color->lengthAndMask);
|
|
|
|
stream_read(s, pointer_color->andMaskData, pointer_color->lengthAndMask);
|
|
|
|
}
|
|
|
|
|
2012-01-09 00:02:02 +04:00
|
|
|
if (stream_get_left(s) > 0)
|
|
|
|
stream_seek_uint8(s); /* pad (1 byte) */
|
2011-08-24 10:38:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void update_read_pointer_new(STREAM* s, POINTER_NEW_UPDATE* pointer_new)
|
|
|
|
{
|
|
|
|
stream_read_uint16(s, pointer_new->xorBpp); /* xorBpp (2 bytes) */
|
|
|
|
update_read_pointer_color(s, &pointer_new->colorPtrAttr); /* colorPtrAttr */
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_read_pointer_cached(STREAM* s, POINTER_CACHED_UPDATE* pointer_cached)
|
|
|
|
{
|
|
|
|
stream_read_uint16(s, pointer_cached->cacheIndex); /* cacheIndex (2 bytes) */
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_recv_pointer(rdpUpdate* update, STREAM* s)
|
|
|
|
{
|
|
|
|
uint16 messageType;
|
2011-11-22 02:48:03 +04:00
|
|
|
rdpContext* context = update->context;
|
|
|
|
rdpPointerUpdate* pointer = update->pointer;
|
2011-08-24 10:38:39 +04:00
|
|
|
|
|
|
|
stream_read_uint16(s, messageType); /* messageType (2 bytes) */
|
|
|
|
stream_seek_uint16(s); /* pad2Octets (2 bytes) */
|
|
|
|
|
|
|
|
switch (messageType)
|
|
|
|
{
|
|
|
|
case PTR_MSG_TYPE_POSITION:
|
2011-11-22 02:48:03 +04:00
|
|
|
update_read_pointer_position(s, &pointer->pointer_position);
|
|
|
|
IFCALL(pointer->PointerPosition, context, &pointer->pointer_position);
|
2011-08-24 10:38:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PTR_MSG_TYPE_SYSTEM:
|
2011-11-22 02:48:03 +04:00
|
|
|
update_read_pointer_system(s, &pointer->pointer_system);
|
|
|
|
IFCALL(pointer->PointerSystem, context, &pointer->pointer_system);
|
2011-08-24 10:38:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PTR_MSG_TYPE_COLOR:
|
2011-11-22 02:48:03 +04:00
|
|
|
update_read_pointer_color(s, &pointer->pointer_color);
|
|
|
|
IFCALL(pointer->PointerColor, context, &pointer->pointer_color);
|
2011-08-24 10:38:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PTR_MSG_TYPE_POINTER:
|
2011-11-22 02:48:03 +04:00
|
|
|
update_read_pointer_new(s, &pointer->pointer_new);
|
|
|
|
IFCALL(pointer->PointerNew, context, &pointer->pointer_new);
|
2011-08-24 10:38:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PTR_MSG_TYPE_CACHED:
|
2011-11-22 02:48:03 +04:00
|
|
|
update_read_pointer_cached(s, &pointer->pointer_cached);
|
|
|
|
IFCALL(pointer->PointerCached, context, &pointer->pointer_cached);
|
2011-08-24 10:38:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-11 17:30:09 +04:00
|
|
|
boolean update_recv(rdpUpdate* update, STREAM* s)
|
2011-07-25 09:45:25 +04:00
|
|
|
{
|
|
|
|
uint16 updateType;
|
2011-11-22 04:41:49 +04:00
|
|
|
rdpContext* context = update->context;
|
2011-07-25 09:45:25 +04:00
|
|
|
|
|
|
|
stream_read_uint16(s, updateType); /* updateType (2 bytes) */
|
|
|
|
|
2011-08-08 05:12:36 +04:00
|
|
|
//printf("%s Update Data PDU\n", UPDATE_TYPE_STRINGS[updateType]);
|
2011-07-25 09:45:25 +04:00
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
IFCALL(update->BeginPaint, context);
|
2011-07-28 21:46:36 +04:00
|
|
|
|
2011-07-25 09:45:25 +04:00
|
|
|
switch (updateType)
|
|
|
|
{
|
|
|
|
case UPDATE_TYPE_ORDERS:
|
2012-02-11 17:30:09 +04:00
|
|
|
if (!update_recv_orders(update, s))
|
|
|
|
{
|
|
|
|
/* XXX: Do we have to call EndPaint? */
|
|
|
|
return false;
|
|
|
|
}
|
2011-07-25 09:45:25 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UPDATE_TYPE_BITMAP:
|
2011-07-28 08:38:25 +04:00
|
|
|
update_read_bitmap(update, s, &update->bitmap_update);
|
2011-11-22 04:41:49 +04:00
|
|
|
IFCALL(update->BitmapUpdate, context, &update->bitmap_update);
|
2011-07-25 09:45:25 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UPDATE_TYPE_PALETTE:
|
2011-07-28 08:38:25 +04:00
|
|
|
update_read_palette(update, s, &update->palette_update);
|
2011-11-22 04:41:49 +04:00
|
|
|
IFCALL(update->Palette, context, &update->palette_update);
|
2011-07-25 09:45:25 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UPDATE_TYPE_SYNCHRONIZE:
|
2011-07-28 08:38:25 +04:00
|
|
|
update_read_synchronize(update, s);
|
2011-11-22 04:41:49 +04:00
|
|
|
IFCALL(update->Synchronize, context);
|
2011-07-25 09:45:25 +04:00
|
|
|
break;
|
|
|
|
}
|
2011-07-28 21:46:36 +04:00
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
IFCALL(update->EndPaint, context);
|
2011-08-07 17:27:52 +04:00
|
|
|
|
2012-02-11 17:30:09 +04:00
|
|
|
return true;
|
2011-07-25 09:45:25 +04:00
|
|
|
}
|
|
|
|
|
2011-08-08 05:12:36 +04:00
|
|
|
void update_reset_state(rdpUpdate* update)
|
|
|
|
{
|
2011-11-22 03:11:43 +04:00
|
|
|
rdpPrimaryUpdate* primary = update->primary;
|
2011-11-22 04:53:38 +04:00
|
|
|
rdpAltSecUpdate* altsec = update->altsec;
|
2011-11-22 03:11:43 +04:00
|
|
|
|
|
|
|
memset(&primary->order_info, 0, sizeof(ORDER_INFO));
|
|
|
|
memset(&primary->dstblt, 0, sizeof(DSTBLT_ORDER));
|
|
|
|
memset(&primary->patblt, 0, sizeof(PATBLT_ORDER));
|
|
|
|
memset(&primary->scrblt, 0, sizeof(SCRBLT_ORDER));
|
|
|
|
memset(&primary->opaque_rect, 0, sizeof(OPAQUE_RECT_ORDER));
|
|
|
|
memset(&primary->draw_nine_grid, 0, sizeof(DRAW_NINE_GRID_ORDER));
|
|
|
|
memset(&primary->multi_dstblt, 0, sizeof(MULTI_DSTBLT_ORDER));
|
|
|
|
memset(&primary->multi_patblt, 0, sizeof(MULTI_PATBLT_ORDER));
|
|
|
|
memset(&primary->multi_scrblt, 0, sizeof(MULTI_SCRBLT_ORDER));
|
|
|
|
memset(&primary->multi_opaque_rect, 0, sizeof(MULTI_OPAQUE_RECT_ORDER));
|
|
|
|
memset(&primary->multi_draw_nine_grid, 0, sizeof(MULTI_DRAW_NINE_GRID_ORDER));
|
|
|
|
memset(&primary->line_to, 0, sizeof(LINE_TO_ORDER));
|
|
|
|
memset(&primary->polyline, 0, sizeof(POLYLINE_ORDER));
|
|
|
|
memset(&primary->memblt, 0, sizeof(MEMBLT_ORDER));
|
|
|
|
memset(&primary->mem3blt, 0, sizeof(MEM3BLT_ORDER));
|
|
|
|
memset(&primary->save_bitmap, 0, sizeof(SAVE_BITMAP_ORDER));
|
|
|
|
memset(&primary->glyph_index, 0, sizeof(GLYPH_INDEX_ORDER));
|
|
|
|
memset(&primary->fast_index, 0, sizeof(FAST_INDEX_ORDER));
|
|
|
|
memset(&primary->fast_glyph, 0, sizeof(FAST_GLYPH_ORDER));
|
|
|
|
memset(&primary->polygon_sc, 0, sizeof(POLYGON_SC_ORDER));
|
|
|
|
memset(&primary->polygon_cb, 0, sizeof(POLYGON_CB_ORDER));
|
|
|
|
memset(&primary->ellipse_sc, 0, sizeof(ELLIPSE_SC_ORDER));
|
|
|
|
memset(&primary->ellipse_cb, 0, sizeof(ELLIPSE_CB_ORDER));
|
|
|
|
|
|
|
|
primary->order_info.orderType = ORDER_TYPE_PATBLT;
|
2011-11-22 04:53:38 +04:00
|
|
|
altsec->switch_surface.bitmapId = SCREEN_BITMAP_SURFACE;
|
|
|
|
IFCALL(altsec->SwitchSurface, update->context, &(altsec->switch_surface));
|
2011-08-08 05:12:36 +04:00
|
|
|
}
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
static void update_begin_paint(rdpContext* context)
|
2011-08-23 16:37:08 +04:00
|
|
|
{
|
2011-09-21 01:01:38 +04:00
|
|
|
|
2011-08-23 16:37:08 +04:00
|
|
|
}
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
static void update_end_paint(rdpContext* context)
|
2011-08-23 16:37:08 +04:00
|
|
|
{
|
2011-11-11 23:02:59 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_write_refresh_rect(STREAM* s, uint8 count, RECTANGLE_16* areas)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
stream_write_uint8(s, count); /* numberOfAreas (1 byte) */
|
|
|
|
stream_seek(s, 3); /* pad3Octets (3 bytes) */
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
2012-09-24 12:59:18 +04:00
|
|
|
{
|
|
|
|
stream_write_uint16(s, areas[i].left); /* left (2 bytes) */
|
|
|
|
stream_write_uint16(s, areas[i].top); /* top (2 bytes) */
|
|
|
|
stream_write_uint16(s, areas[i].right); /* right (2 bytes) */
|
|
|
|
stream_write_uint16(s, areas[i].bottom); /* bottom (2 bytes) */
|
|
|
|
}
|
2011-11-11 23:02:59 +04:00
|
|
|
}
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
static void update_send_refresh_rect(rdpContext* context, uint8 count, RECTANGLE_16* areas)
|
2011-11-11 23:02:59 +04:00
|
|
|
{
|
|
|
|
STREAM* s;
|
2011-11-22 04:41:49 +04:00
|
|
|
rdpRdp* rdp = context->rdp;
|
2011-11-11 23:02:59 +04:00
|
|
|
|
2012-05-28 16:20:42 +04:00
|
|
|
if (rdp->settings->refresh_rect)
|
|
|
|
{
|
|
|
|
s = rdp_data_pdu_init(rdp);
|
|
|
|
update_write_refresh_rect(s, count, areas);
|
2011-11-11 23:02:59 +04:00
|
|
|
|
2012-05-28 16:20:42 +04:00
|
|
|
rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_REFRESH_RECT, rdp->mcs->user_id);
|
|
|
|
}
|
2011-11-11 23:02:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void update_write_suppress_output(STREAM* s, uint8 allow, RECTANGLE_16* area)
|
|
|
|
{
|
|
|
|
stream_write_uint8(s, allow); /* allowDisplayUpdates (1 byte) */
|
|
|
|
stream_seek(s, 3); /* pad3Octets (3 bytes) */
|
|
|
|
|
|
|
|
if (allow > 0)
|
2012-09-24 12:59:18 +04:00
|
|
|
{
|
|
|
|
stream_write_uint16(s, area->left); /* left (2 bytes) */
|
|
|
|
stream_write_uint16(s, area->top); /* top (2 bytes) */
|
|
|
|
stream_write_uint16(s, area->right); /* right (2 bytes) */
|
|
|
|
stream_write_uint16(s, area->bottom); /* bottom (2 bytes) */
|
|
|
|
}
|
2011-11-11 23:02:59 +04:00
|
|
|
}
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
static void update_send_suppress_output(rdpContext* context, uint8 allow, RECTANGLE_16* area)
|
2011-11-11 23:02:59 +04:00
|
|
|
{
|
|
|
|
STREAM* s;
|
2011-11-22 04:41:49 +04:00
|
|
|
rdpRdp* rdp = context->rdp;
|
2011-11-11 23:02:59 +04:00
|
|
|
|
2012-05-28 16:20:42 +04:00
|
|
|
if (rdp->settings->suppress_output)
|
|
|
|
{
|
|
|
|
s = rdp_data_pdu_init(rdp);
|
|
|
|
update_write_suppress_output(s, allow, area);
|
2011-11-11 23:02:59 +04:00
|
|
|
|
2012-05-28 16:20:42 +04:00
|
|
|
rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SUPPRESS_OUTPUT, rdp->mcs->user_id);
|
|
|
|
}
|
2011-08-23 16:37:08 +04:00
|
|
|
}
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
static void update_send_surface_command(rdpContext* context, STREAM* s)
|
2011-08-27 05:44:37 +04:00
|
|
|
{
|
2011-12-03 10:42:13 +04:00
|
|
|
STREAM* update;
|
2011-11-22 04:41:49 +04:00
|
|
|
rdpRdp* rdp = context->rdp;
|
2011-12-03 10:42:13 +04:00
|
|
|
|
|
|
|
update = fastpath_update_pdu_init(rdp->fastpath);
|
|
|
|
stream_check_size(update, stream_get_length(s));
|
|
|
|
stream_write(update, stream_get_head(s), stream_get_length(s));
|
|
|
|
fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, update);
|
2011-08-27 05:44:37 +04:00
|
|
|
}
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
static void update_send_surface_bits(rdpContext* context, SURFACE_BITS_COMMAND* surface_bits_command)
|
2011-08-23 19:28:28 +04:00
|
|
|
{
|
2011-12-03 10:42:13 +04:00
|
|
|
STREAM* s;
|
2011-11-22 04:41:49 +04:00
|
|
|
rdpRdp* rdp = context->rdp;
|
2011-12-03 10:42:13 +04:00
|
|
|
|
|
|
|
s = fastpath_update_pdu_init(rdp->fastpath);
|
2011-12-04 02:24:18 +04:00
|
|
|
stream_check_size(s, SURFCMD_SURFACE_BITS_HEADER_LENGTH + (int) surface_bits_command->bitmapDataLength);
|
2011-12-03 10:42:13 +04:00
|
|
|
update_write_surfcmd_surface_bits_header(s, surface_bits_command);
|
|
|
|
stream_write(s, surface_bits_command->bitmapData, surface_bits_command->bitmapDataLength);
|
|
|
|
fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, s);
|
2011-08-23 19:28:28 +04:00
|
|
|
}
|
|
|
|
|
2011-12-16 03:26:32 +04:00
|
|
|
static void update_send_surface_frame_marker(rdpContext* context, SURFACE_FRAME_MARKER* surface_frame_marker)
|
|
|
|
{
|
|
|
|
STREAM* s;
|
|
|
|
rdpRdp* rdp = context->rdp;
|
|
|
|
|
|
|
|
s = fastpath_update_pdu_init(rdp->fastpath);
|
|
|
|
update_write_surfcmd_frame_marker(s, surface_frame_marker->frameAction, surface_frame_marker->frameId);
|
|
|
|
fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, s);
|
|
|
|
}
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
static void update_send_synchronize(rdpContext* context)
|
2011-08-25 13:03:53 +04:00
|
|
|
{
|
|
|
|
STREAM* s;
|
2011-11-22 04:41:49 +04:00
|
|
|
rdpRdp* rdp = context->rdp;
|
2011-08-25 13:03:53 +04:00
|
|
|
|
|
|
|
s = fastpath_update_pdu_init(rdp->fastpath);
|
2012-02-02 20:34:19 +04:00
|
|
|
stream_write_zero(s, 2); /* pad2Octets (2 bytes) */
|
2011-12-03 10:42:13 +04:00
|
|
|
fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SYNCHRONIZE, s);
|
2011-08-25 13:03:53 +04:00
|
|
|
}
|
|
|
|
|
2011-11-22 04:41:49 +04:00
|
|
|
static void update_send_desktop_resize(rdpContext* context)
|
2011-09-06 13:19:16 +04:00
|
|
|
{
|
2011-11-22 04:41:49 +04:00
|
|
|
rdp_server_reactivate(context->rdp);
|
2011-09-06 13:19:16 +04:00
|
|
|
}
|
|
|
|
|
2011-11-24 20:47:40 +04:00
|
|
|
static void update_send_scrblt(rdpContext* context, SCRBLT_ORDER* scrblt)
|
|
|
|
{
|
|
|
|
STREAM* s;
|
|
|
|
rdpRdp* rdp = context->rdp;
|
|
|
|
|
|
|
|
s = fastpath_update_pdu_init(rdp->fastpath);
|
|
|
|
|
|
|
|
stream_write_uint16(s, 1); /* numberOrders (2 bytes) */
|
|
|
|
stream_write_uint8(s, ORDER_STANDARD | ORDER_TYPE_CHANGE); /* controlFlags (1 byte) */
|
|
|
|
stream_write_uint8(s, ORDER_TYPE_SCRBLT); /* orderType (1 byte) */
|
|
|
|
stream_write_uint8(s, 0x7F); /* fieldFlags (variable) */
|
|
|
|
|
|
|
|
stream_write_uint16(s, scrblt->nLeftRect);
|
|
|
|
stream_write_uint16(s, scrblt->nTopRect);
|
|
|
|
stream_write_uint16(s, scrblt->nWidth);
|
|
|
|
stream_write_uint16(s, scrblt->nHeight);
|
|
|
|
stream_write_uint8(s, scrblt->bRop);
|
|
|
|
stream_write_uint16(s, scrblt->nXSrc);
|
|
|
|
stream_write_uint16(s, scrblt->nYSrc);
|
|
|
|
|
2011-12-03 10:42:13 +04:00
|
|
|
fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_ORDERS, s);
|
2011-11-24 20:47:40 +04:00
|
|
|
}
|
|
|
|
|
2011-11-22 03:11:43 +04:00
|
|
|
static void update_send_pointer_system(rdpContext* context, POINTER_SYSTEM_UPDATE* pointer_system)
|
2011-08-25 13:03:53 +04:00
|
|
|
{
|
|
|
|
STREAM* s;
|
2011-12-03 10:42:13 +04:00
|
|
|
uint8 updateCode;
|
2011-11-22 03:11:43 +04:00
|
|
|
rdpRdp* rdp = context->rdp;
|
2011-08-25 13:03:53 +04:00
|
|
|
|
|
|
|
s = fastpath_update_pdu_init(rdp->fastpath);
|
2012-09-17 05:05:51 +04:00
|
|
|
|
2011-08-25 13:03:53 +04:00
|
|
|
if (pointer_system->type == SYSPTR_NULL)
|
2011-12-03 10:42:13 +04:00
|
|
|
updateCode = FASTPATH_UPDATETYPE_PTR_NULL;
|
2011-08-25 13:03:53 +04:00
|
|
|
else
|
2011-12-03 10:42:13 +04:00
|
|
|
updateCode = FASTPATH_UPDATETYPE_PTR_DEFAULT;
|
2012-09-17 05:05:51 +04:00
|
|
|
|
2011-12-03 10:42:13 +04:00
|
|
|
fastpath_send_update_pdu(rdp->fastpath, updateCode, s);
|
2011-08-25 13:03:53 +04:00
|
|
|
}
|
|
|
|
|
2011-12-03 04:54:02 +04:00
|
|
|
static void update_write_pointer_color(STREAM* s, POINTER_COLOR_UPDATE* pointer_color)
|
|
|
|
{
|
2011-12-04 02:24:18 +04:00
|
|
|
stream_check_size(s, 15 + (int) pointer_color->lengthAndMask + (int) pointer_color->lengthXorMask);
|
2012-09-17 05:05:51 +04:00
|
|
|
|
2011-12-03 04:54:02 +04:00
|
|
|
stream_write_uint16(s, pointer_color->cacheIndex);
|
|
|
|
stream_write_uint16(s, pointer_color->xPos);
|
|
|
|
stream_write_uint16(s, pointer_color->yPos);
|
|
|
|
stream_write_uint16(s, pointer_color->width);
|
|
|
|
stream_write_uint16(s, pointer_color->height);
|
|
|
|
stream_write_uint16(s, pointer_color->lengthAndMask);
|
|
|
|
stream_write_uint16(s, pointer_color->lengthXorMask);
|
2012-09-17 05:05:51 +04:00
|
|
|
|
2011-12-03 04:54:02 +04:00
|
|
|
if (pointer_color->lengthXorMask > 0)
|
|
|
|
stream_write(s, pointer_color->xorMaskData, pointer_color->lengthXorMask);
|
2012-09-17 05:05:51 +04:00
|
|
|
|
2011-12-03 04:54:02 +04:00
|
|
|
if (pointer_color->lengthAndMask > 0)
|
|
|
|
stream_write(s, pointer_color->andMaskData, pointer_color->lengthAndMask);
|
2012-09-17 05:05:51 +04:00
|
|
|
|
2011-12-03 04:54:02 +04:00
|
|
|
stream_write_uint8(s, 0); /* pad (1 byte) */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_send_pointer_color(rdpContext* context, POINTER_COLOR_UPDATE* pointer_color)
|
|
|
|
{
|
|
|
|
STREAM* s;
|
|
|
|
rdpRdp* rdp = context->rdp;
|
|
|
|
|
|
|
|
s = fastpath_update_pdu_init(rdp->fastpath);
|
|
|
|
update_write_pointer_color(s, pointer_color);
|
2011-12-03 10:42:13 +04:00
|
|
|
fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_COLOR, s);
|
2011-12-03 04:54:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void update_send_pointer_new(rdpContext* context, POINTER_NEW_UPDATE* pointer_new)
|
|
|
|
{
|
|
|
|
STREAM* s;
|
|
|
|
rdpRdp* rdp = context->rdp;
|
|
|
|
|
|
|
|
s = fastpath_update_pdu_init(rdp->fastpath);
|
|
|
|
stream_write_uint16(s, pointer_new->xorBpp); /* xorBpp (2 bytes) */
|
|
|
|
update_write_pointer_color(s, &pointer_new->colorPtrAttr);
|
2011-12-03 10:42:13 +04:00
|
|
|
fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_POINTER, s);
|
2011-12-03 04:54:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void update_send_pointer_cached(rdpContext* context, POINTER_CACHED_UPDATE* pointer_cached)
|
|
|
|
{
|
|
|
|
STREAM* s;
|
|
|
|
rdpRdp* rdp = context->rdp;
|
|
|
|
|
|
|
|
s = fastpath_update_pdu_init(rdp->fastpath);
|
|
|
|
stream_write_uint16(s, pointer_cached->cacheIndex); /* cacheIndex (2 bytes) */
|
2011-12-03 10:42:13 +04:00
|
|
|
fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_CACHED, s);
|
2011-12-03 04:54:02 +04:00
|
|
|
}
|
|
|
|
|
2012-05-26 17:34:09 +04:00
|
|
|
boolean update_read_refresh_rect(rdpUpdate* update, STREAM* s)
|
|
|
|
{
|
2012-09-16 01:51:05 +04:00
|
|
|
int index;
|
2012-05-26 17:34:09 +04:00
|
|
|
uint8 numberOfAreas;
|
2012-09-16 01:51:05 +04:00
|
|
|
RECTANGLE_16* areas;
|
2012-05-26 17:34:09 +04:00
|
|
|
|
|
|
|
if (stream_get_left(s) < 4)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
stream_read_uint8(s, numberOfAreas);
|
|
|
|
stream_seek(s, 3); /* pad3Octects */
|
|
|
|
|
2012-09-16 01:51:05 +04:00
|
|
|
areas = (RECTANGLE_16*) malloc(sizeof(RECTANGLE_16) * numberOfAreas);
|
|
|
|
|
|
|
|
for (index = 0; index < numberOfAreas; index++)
|
|
|
|
{
|
|
|
|
stream_read_uint16(s, areas[index].left);
|
|
|
|
stream_read_uint16(s, areas[index].top);
|
|
|
|
stream_read_uint16(s, areas[index].right);
|
|
|
|
stream_read_uint16(s, areas[index].bottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
IFCALL(update->RefreshRect, update->context, numberOfAreas, areas);
|
|
|
|
|
|
|
|
free(areas);
|
2012-05-26 17:34:09 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean update_read_suppress_output(rdpUpdate* update, STREAM* s)
|
|
|
|
{
|
|
|
|
uint8 allowDisplayUpdates;
|
|
|
|
|
|
|
|
if (stream_get_left(s) < 4)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
stream_read_uint8(s, allowDisplayUpdates);
|
|
|
|
stream_seek(s, 3); /* pad3Octects */
|
2012-09-17 05:05:51 +04:00
|
|
|
|
2012-05-26 17:34:09 +04:00
|
|
|
if (allowDisplayUpdates > 0 && stream_get_left(s) < 8)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
IFCALL(update->SuppressOutput, update->context, allowDisplayUpdates,
|
|
|
|
allowDisplayUpdates > 0 ? (RECTANGLE_16*) stream_get_tail(s) : NULL);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-08-23 16:37:08 +04:00
|
|
|
void update_register_server_callbacks(rdpUpdate* update)
|
|
|
|
{
|
|
|
|
update->BeginPaint = update_begin_paint;
|
|
|
|
update->EndPaint = update_end_paint;
|
2011-08-25 13:03:53 +04:00
|
|
|
update->Synchronize = update_send_synchronize;
|
2011-09-06 13:19:16 +04:00
|
|
|
update->DesktopResize = update_send_desktop_resize;
|
2011-08-23 19:28:28 +04:00
|
|
|
update->SurfaceBits = update_send_surface_bits;
|
2011-12-16 03:26:32 +04:00
|
|
|
update->SurfaceFrameMarker = update_send_surface_frame_marker;
|
2011-08-27 05:44:37 +04:00
|
|
|
update->SurfaceCommand = update_send_surface_command;
|
2011-11-24 20:47:40 +04:00
|
|
|
update->primary->ScrBlt = update_send_scrblt;
|
2011-11-22 02:48:03 +04:00
|
|
|
update->pointer->PointerSystem = update_send_pointer_system;
|
2011-12-03 04:54:02 +04:00
|
|
|
update->pointer->PointerColor = update_send_pointer_color;
|
|
|
|
update->pointer->PointerNew = update_send_pointer_new;
|
|
|
|
update->pointer->PointerCached = update_send_pointer_cached;
|
2011-08-23 16:37:08 +04:00
|
|
|
}
|
|
|
|
|
2012-05-26 17:34:09 +04:00
|
|
|
void update_register_client_callbacks(rdpUpdate* update)
|
|
|
|
{
|
|
|
|
update->RefreshRect = update_send_refresh_rect;
|
|
|
|
update->SuppressOutput = update_send_suppress_output;
|
|
|
|
}
|
|
|
|
|
2011-07-28 08:38:25 +04:00
|
|
|
rdpUpdate* update_new(rdpRdp* rdp)
|
2011-07-27 02:32:14 +04:00
|
|
|
{
|
|
|
|
rdpUpdate* update;
|
|
|
|
|
|
|
|
update = (rdpUpdate*) xzalloc(sizeof(rdpUpdate));
|
|
|
|
|
|
|
|
if (update != NULL)
|
|
|
|
{
|
2012-01-01 00:36:04 +04:00
|
|
|
OFFSCREEN_DELETE_LIST* deleteList;
|
|
|
|
|
2011-10-03 07:09:13 +04:00
|
|
|
update->bitmap_update.count = 64;
|
2011-10-21 05:34:55 +04:00
|
|
|
update->bitmap_update.rectangles = (BITMAP_DATA*) xzalloc(sizeof(BITMAP_DATA) * update->bitmap_update.count);
|
2011-11-22 02:48:03 +04:00
|
|
|
|
|
|
|
update->pointer = xnew(rdpPointerUpdate);
|
2011-11-22 03:11:43 +04:00
|
|
|
update->primary = xnew(rdpPrimaryUpdate);
|
2011-11-22 04:41:49 +04:00
|
|
|
update->secondary = xnew(rdpSecondaryUpdate);
|
2011-11-22 04:53:38 +04:00
|
|
|
update->altsec = xnew(rdpAltSecUpdate);
|
2011-11-22 06:07:03 +04:00
|
|
|
update->window = xnew(rdpWindowUpdate);
|
2012-01-01 00:36:04 +04:00
|
|
|
|
|
|
|
deleteList = &(update->altsec->create_offscreen_bitmap.deleteList);
|
|
|
|
deleteList->sIndices = 64;
|
|
|
|
deleteList->indices = xmalloc(deleteList->sIndices * 2);
|
|
|
|
deleteList->cIndices = 0;
|
2012-01-31 20:11:22 +04:00
|
|
|
|
|
|
|
update->SuppressOutput = update_send_suppress_output;
|
2011-07-27 02:32:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return update;
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_free(rdpUpdate* update)
|
|
|
|
{
|
|
|
|
if (update != NULL)
|
|
|
|
{
|
2012-01-01 00:36:04 +04:00
|
|
|
OFFSCREEN_DELETE_LIST* deleteList;
|
|
|
|
deleteList = &(update->altsec->create_offscreen_bitmap.deleteList);
|
|
|
|
xfree(deleteList->indices);
|
|
|
|
|
2011-10-21 05:34:55 +04:00
|
|
|
xfree(update->bitmap_update.rectangles);
|
2011-11-22 06:07:03 +04:00
|
|
|
xfree(update->pointer);
|
2012-03-16 21:12:48 +04:00
|
|
|
xfree(update->primary->polyline.points);
|
|
|
|
xfree(update->primary->polygon_sc.points);
|
2011-11-22 06:07:03 +04:00
|
|
|
xfree(update->primary);
|
|
|
|
xfree(update->secondary);
|
|
|
|
xfree(update->altsec);
|
|
|
|
xfree(update->window);
|
2011-07-27 02:32:14 +04:00
|
|
|
xfree(update);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|