Blame libfreerdp/core/update.c

Packit 1fb8d4
/**
Packit 1fb8d4
 * FreeRDP: A Remote Desktop Protocol Implementation
Packit 1fb8d4
 * Update Data PDUs
Packit 1fb8d4
 *
Packit 1fb8d4
 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
Packit 1fb8d4
 * Copyright 2016 Armin Novak <armin.novak@thincast.com>
Packit 1fb8d4
 * Copyright 2016 Thincast Technologies GmbH
Packit 1fb8d4
 *
Packit 1fb8d4
 * Licensed under the Apache License, Version 2.0 (the "License");
Packit 1fb8d4
 * you may not use this file except in compliance with the License.
Packit 1fb8d4
 * You may obtain a copy of the License at
Packit 1fb8d4
 *
Packit 1fb8d4
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit 1fb8d4
 *
Packit 1fb8d4
 * Unless required by applicable law or agreed to in writing, software
Packit 1fb8d4
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit 1fb8d4
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit 1fb8d4
 * See the License for the specific language governing permissions and
Packit 1fb8d4
 * limitations under the License.
Packit 1fb8d4
 */
Packit 1fb8d4
Packit 1fb8d4
#ifdef HAVE_CONFIG_H
Packit 1fb8d4
#include "config.h"
Packit 1fb8d4
#endif
Packit 1fb8d4
Packit 1fb8d4
#include <winpr/crt.h>
Packit 1fb8d4
#include <winpr/print.h>
Packit 1fb8d4
#include <winpr/synch.h>
Packit 1fb8d4
#include <winpr/thread.h>
Packit 1fb8d4
#include <winpr/collections.h>
Packit 1fb8d4
Packit 1fb8d4
#include "update.h"
Packit 1fb8d4
#include "surface.h"
Packit 1fb8d4
#include "message.h"
Packit 1fb8d4
#include "info.h"
Packit 1fb8d4
#include "window.h"
Packit 1fb8d4
Packit 1fb8d4
#include <freerdp/log.h>
Packit 1fb8d4
#include <freerdp/peer.h>
Packit 1fb8d4
#include <freerdp/codec/bitmap.h>
Packit 1fb8d4
Packit 1fb8d4
#include "../cache/pointer.h"
Packit 1fb8d4
#include "../cache/palette.h"
Packit 1fb8d4
#include "../cache/bitmap.h"
Packit 1fb8d4
Packit 1fb8d4
#define TAG FREERDP_TAG("core.update")
Packit 1fb8d4
Packit Service 5a9772
static const char* const UPDATE_TYPE_STRINGS[] = { "Orders", "Bitmap", "Palette", "Synchronize" };
Packit 1fb8d4
Packit 1fb8d4
static const char* update_type_to_string(UINT16 updateType)
Packit 1fb8d4
{
Packit 1fb8d4
	if (updateType >= ARRAYSIZE(UPDATE_TYPE_STRINGS))
Packit 1fb8d4
		return "UNKNOWN";
Packit 1fb8d4
Packit 1fb8d4
	return UPDATE_TYPE_STRINGS[updateType];
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL update_recv_orders(rdpUpdate* update, wStream* s)
Packit 1fb8d4
{
Packit 1fb8d4
	UINT16 numberOrders;
Packit 1fb8d4
Packit 1fb8d4
	if (Stream_GetRemainingLength(s) < 6)
Packit 1fb8d4
	{
Packit 1fb8d4
		WLog_ERR(TAG, "Stream_GetRemainingLength(s) < 6");
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit Service 5a9772
	Stream_Seek_UINT16(s);               /* pad2OctetsA (2 bytes) */
Packit 1fb8d4
	Stream_Read_UINT16(s, numberOrders); /* numberOrders (2 bytes) */
Packit Service 5a9772
	Stream_Seek_UINT16(s);               /* pad2OctetsB (2 bytes) */
Packit 1fb8d4
Packit 1fb8d4
	while (numberOrders > 0)
Packit 1fb8d4
	{
Packit 1fb8d4
		if (!update_recv_order(update, s))
Packit 1fb8d4
		{
Packit 1fb8d4
			WLog_ERR(TAG, "update_recv_order() failed");
Packit 1fb8d4
			return FALSE;
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		numberOrders--;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_read_bitmap_data(rdpUpdate* update, wStream* s, BITMAP_DATA* bitmapData)
Packit 1fb8d4
{
Packit Service 5a9772
	WINPR_UNUSED(update);
Packit 1fb8d4
	if (Stream_GetRemainingLength(s) < 18)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Read_UINT16(s, bitmapData->destLeft);
Packit 1fb8d4
	Stream_Read_UINT16(s, bitmapData->destTop);
Packit 1fb8d4
	Stream_Read_UINT16(s, bitmapData->destRight);
Packit 1fb8d4
	Stream_Read_UINT16(s, bitmapData->destBottom);
Packit 1fb8d4
	Stream_Read_UINT16(s, bitmapData->width);
Packit 1fb8d4
	Stream_Read_UINT16(s, bitmapData->height);
Packit 1fb8d4
	Stream_Read_UINT16(s, bitmapData->bitsPerPixel);
Packit 1fb8d4
	Stream_Read_UINT16(s, bitmapData->flags);
Packit 1fb8d4
	Stream_Read_UINT16(s, bitmapData->bitmapLength);
Packit 1fb8d4
Packit 1fb8d4
	if (bitmapData->flags & BITMAP_COMPRESSION)
Packit 1fb8d4
	{
Packit 1fb8d4
		if (!(bitmapData->flags & NO_BITMAP_COMPRESSION_HDR))
Packit 1fb8d4
		{
Packit Service 5a9772
			if (Stream_GetRemainingLength(s) < 8)
Packit Service 5a9772
				return FALSE;
Packit Service 5a9772
Packit 1fb8d4
			Stream_Read_UINT16(s,
Packit 1fb8d4
			                   bitmapData->cbCompFirstRowSize); /* cbCompFirstRowSize (2 bytes) */
Packit 1fb8d4
			Stream_Read_UINT16(s,
Packit 1fb8d4
			                   bitmapData->cbCompMainBodySize); /* cbCompMainBodySize (2 bytes) */
Packit Service 5a9772
			Stream_Read_UINT16(s, bitmapData->cbScanWidth);     /* cbScanWidth (2 bytes) */
Packit 1fb8d4
			Stream_Read_UINT16(s,
Packit 1fb8d4
			                   bitmapData->cbUncompressedSize); /* cbUncompressedSize (2 bytes) */
Packit 1fb8d4
			bitmapData->bitmapLength = bitmapData->cbCompMainBodySize;
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		bitmapData->compressed = TRUE;
Packit 1fb8d4
	}
Packit 1fb8d4
	else
Packit 1fb8d4
		bitmapData->compressed = FALSE;
Packit 1fb8d4
Packit 1fb8d4
	if (Stream_GetRemainingLength(s) < bitmapData->bitmapLength)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	if (bitmapData->bitmapLength > 0)
Packit 1fb8d4
	{
Packit 1fb8d4
		bitmapData->bitmapDataStream = malloc(bitmapData->bitmapLength);
Packit 1fb8d4
Packit 1fb8d4
		if (!bitmapData->bitmapDataStream)
Packit 1fb8d4
			return FALSE;
Packit 1fb8d4
Packit 1fb8d4
		memcpy(bitmapData->bitmapDataStream, Stream_Pointer(s), bitmapData->bitmapLength);
Packit 1fb8d4
		Stream_Seek(s, bitmapData->bitmapLength);
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_write_bitmap_data(rdpUpdate* update, wStream* s, BITMAP_DATA* bitmapData)
Packit 1fb8d4
{
Packit 1fb8d4
	if (!Stream_EnsureRemainingCapacity(s, 64 + bitmapData->bitmapLength))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit Service 5a9772
	if (update->autoCalculateBitmapData)
Packit Service 5a9772
	{
Packit Service 5a9772
		bitmapData->flags = 0;
Packit Service 5a9772
		bitmapData->cbCompFirstRowSize = 0;
Packit 1fb8d4
Packit Service 5a9772
		if (bitmapData->compressed)
Packit Service 5a9772
			bitmapData->flags |= BITMAP_COMPRESSION;
Packit 1fb8d4
Packit Service 5a9772
		if (update->context->settings->NoBitmapCompressionHeader)
Packit Service 5a9772
		{
Packit Service 5a9772
			bitmapData->flags |= NO_BITMAP_COMPRESSION_HDR;
Packit Service 5a9772
			bitmapData->cbCompMainBodySize = bitmapData->bitmapLength;
Packit Service 5a9772
		}
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	Stream_Write_UINT16(s, bitmapData->destLeft);
Packit 1fb8d4
	Stream_Write_UINT16(s, bitmapData->destTop);
Packit 1fb8d4
	Stream_Write_UINT16(s, bitmapData->destRight);
Packit 1fb8d4
	Stream_Write_UINT16(s, bitmapData->destBottom);
Packit 1fb8d4
	Stream_Write_UINT16(s, bitmapData->width);
Packit 1fb8d4
	Stream_Write_UINT16(s, bitmapData->height);
Packit 1fb8d4
	Stream_Write_UINT16(s, bitmapData->bitsPerPixel);
Packit 1fb8d4
	Stream_Write_UINT16(s, bitmapData->flags);
Packit 1fb8d4
	Stream_Write_UINT16(s, bitmapData->bitmapLength);
Packit 1fb8d4
Packit 1fb8d4
	if (bitmapData->flags & BITMAP_COMPRESSION)
Packit 1fb8d4
	{
Packit 1fb8d4
		if (!(bitmapData->flags & NO_BITMAP_COMPRESSION_HDR))
Packit 1fb8d4
		{
Packit 1fb8d4
			Stream_Write_UINT16(s,
Packit 1fb8d4
			                    bitmapData->cbCompFirstRowSize); /* cbCompFirstRowSize (2 bytes) */
Packit 1fb8d4
			Stream_Write_UINT16(s,
Packit 1fb8d4
			                    bitmapData->cbCompMainBodySize); /* cbCompMainBodySize (2 bytes) */
Packit Service 5a9772
			Stream_Write_UINT16(s, bitmapData->cbScanWidth);     /* cbScanWidth (2 bytes) */
Packit 1fb8d4
			Stream_Write_UINT16(s,
Packit 1fb8d4
			                    bitmapData->cbUncompressedSize); /* cbUncompressedSize (2 bytes) */
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		Stream_Write(s, bitmapData->bitmapDataStream, bitmapData->bitmapLength);
Packit 1fb8d4
	}
Packit 1fb8d4
	else
Packit 1fb8d4
	{
Packit 1fb8d4
		Stream_Write(s, bitmapData->bitmapDataStream, bitmapData->bitmapLength);
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
BITMAP_UPDATE* update_read_bitmap_update(rdpUpdate* update, wStream* s)
Packit 1fb8d4
{
Packit 1fb8d4
	UINT32 i;
Packit 1fb8d4
	BITMAP_UPDATE* bitmapUpdate = calloc(1, sizeof(BITMAP_UPDATE));
Packit 1fb8d4
Packit 1fb8d4
	if (!bitmapUpdate)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	if (Stream_GetRemainingLength(s) < 2)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Read_UINT16(s, bitmapUpdate->number); /* numberRectangles (2 bytes) */
Packit Service 5a9772
	WLog_Print(update->log, WLOG_TRACE, "BitmapUpdate: %" PRIu32 "", bitmapUpdate->number);
Packit 1fb8d4
Packit 1fb8d4
	if (bitmapUpdate->number > bitmapUpdate->count)
Packit 1fb8d4
	{
Packit 1fb8d4
		UINT32 count = bitmapUpdate->number * 2;
Packit Service 5a9772
		BITMAP_DATA* newdata =
Packit Service 5a9772
		    (BITMAP_DATA*)realloc(bitmapUpdate->rectangles, sizeof(BITMAP_DATA) * count);
Packit 1fb8d4
Packit 1fb8d4
		if (!newdata)
Packit 1fb8d4
			goto fail;
Packit 1fb8d4
Packit 1fb8d4
		bitmapUpdate->rectangles = newdata;
Packit 1fb8d4
		ZeroMemory(&bitmapUpdate->rectangles[bitmapUpdate->count],
Packit 1fb8d4
		           sizeof(BITMAP_DATA) * (count - bitmapUpdate->count));
Packit 1fb8d4
		bitmapUpdate->count = count;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	/* rectangles */
Packit 1fb8d4
	for (i = 0; i < bitmapUpdate->number; i++)
Packit 1fb8d4
	{
Packit 1fb8d4
		if (!update_read_bitmap_data(update, s, &bitmapUpdate->rectangles[i]))
Packit 1fb8d4
			goto fail;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return bitmapUpdate;
Packit 1fb8d4
fail:
Packit 1fb8d4
	free_bitmap_update(update->context, bitmapUpdate);
Packit 1fb8d4
	return NULL;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL update_write_bitmap_update(rdpUpdate* update, wStream* s,
Packit 1fb8d4
                                       const BITMAP_UPDATE* bitmapUpdate)
Packit 1fb8d4
{
Packit 1fb8d4
	int i;
Packit 1fb8d4
Packit 1fb8d4
	if (!Stream_EnsureRemainingCapacity(s, 32))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit Service 5a9772
	Stream_Write_UINT16(s, UPDATE_TYPE_BITMAP);   /* updateType */
Packit 1fb8d4
	Stream_Write_UINT16(s, bitmapUpdate->number); /* numberRectangles (2 bytes) */
Packit 1fb8d4
Packit 1fb8d4
	/* rectangles */
Packit Service 5a9772
	for (i = 0; i < (int)bitmapUpdate->number; i++)
Packit 1fb8d4
	{
Packit 1fb8d4
		if (!update_write_bitmap_data(update, s, &bitmapUpdate->rectangles[i]))
Packit 1fb8d4
			return FALSE;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
PALETTE_UPDATE* update_read_palette(rdpUpdate* update, wStream* s)
Packit 1fb8d4
{
Packit 1fb8d4
	int i;
Packit 1fb8d4
	PALETTE_ENTRY* entry;
Packit 1fb8d4
	PALETTE_UPDATE* palette_update = calloc(1, sizeof(PALETTE_UPDATE));
Packit 1fb8d4
Packit 1fb8d4
	if (!palette_update)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	if (Stream_GetRemainingLength(s) < 6)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit Service 5a9772
	Stream_Seek_UINT16(s);                         /* pad2Octets (2 bytes) */
Packit Service 5a9772
	Stream_Read_UINT32(s, palette_update->number); /* numberColors (4 bytes), must be set to 256 */
Packit 1fb8d4
Packit 1fb8d4
	if (palette_update->number > 256)
Packit 1fb8d4
		palette_update->number = 256;
Packit 1fb8d4
Packit 1fb8d4
	if (Stream_GetRemainingLength(s) < palette_update->number * 3)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	/* paletteEntries */
Packit Service 5a9772
	for (i = 0; i < (int)palette_update->number; i++)
Packit 1fb8d4
	{
Packit 1fb8d4
		entry = &palette_update->entries[i];
Packit 1fb8d4
		Stream_Read_UINT8(s, entry->red);
Packit 1fb8d4
		Stream_Read_UINT8(s, entry->green);
Packit 1fb8d4
		Stream_Read_UINT8(s, entry->blue);
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return palette_update;
Packit 1fb8d4
fail:
Packit 1fb8d4
	free_palette_update(update->context, palette_update);
Packit 1fb8d4
	return NULL;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_read_synchronize(rdpUpdate* update, wStream* s)
Packit 1fb8d4
{
Packit Service 5a9772
	WINPR_UNUSED(update);
Packit Service 5a9772
	return Stream_SafeSeek(s, 2); /* pad2Octets (2 bytes) */
Packit Service 5a9772
	                              /**
Packit Service 5a9772
	                               * The Synchronize Update is an artifact from the
Packit Service 5a9772
	                               * T.128 protocol and should be ignored.
Packit Service 5a9772
	                               */
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL update_read_play_sound(wStream* s, PLAY_SOUND_UPDATE* play_sound)
Packit 1fb8d4
{
Packit 1fb8d4
	if (Stream_GetRemainingLength(s) < 8)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit Service 5a9772
	Stream_Read_UINT32(s, play_sound->duration);  /* duration (4 bytes) */
Packit 1fb8d4
	Stream_Read_UINT32(s, play_sound->frequency); /* frequency (4 bytes) */
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
BOOL update_recv_play_sound(rdpUpdate* update, wStream* s)
Packit 1fb8d4
{
Packit 1fb8d4
	PLAY_SOUND_UPDATE play_sound;
Packit 1fb8d4
Packit 1fb8d4
	if (!update_read_play_sound(s, &play_sound))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	return IFCALLRESULT(FALSE, update->PlaySound, update->context, &play_sound);
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
POINTER_POSITION_UPDATE* update_read_pointer_position(rdpUpdate* update, wStream* s)
Packit 1fb8d4
{
Packit 1fb8d4
	POINTER_POSITION_UPDATE* pointer_position = calloc(1, sizeof(POINTER_POSITION_UPDATE));
Packit 1fb8d4
Packit 1fb8d4
	if (!pointer_position)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	if (Stream_GetRemainingLength(s) < 4)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Read_UINT16(s, pointer_position->xPos); /* xPos (2 bytes) */
Packit 1fb8d4
	Stream_Read_UINT16(s, pointer_position->yPos); /* yPos (2 bytes) */
Packit 1fb8d4
	return pointer_position;
Packit 1fb8d4
fail:
Packit 1fb8d4
	free_pointer_position_update(update->context, pointer_position);
Packit 1fb8d4
	return NULL;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
POINTER_SYSTEM_UPDATE* update_read_pointer_system(rdpUpdate* update, wStream* s)
Packit 1fb8d4
{
Packit 1fb8d4
	POINTER_SYSTEM_UPDATE* pointer_system = calloc(1, sizeof(POINTER_SYSTEM_UPDATE));
Packit 1fb8d4
Packit 1fb8d4
	if (!pointer_system)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	if (Stream_GetRemainingLength(s) < 4)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Read_UINT32(s, pointer_system->type); /* systemPointerType (4 bytes) */
Packit 1fb8d4
	return pointer_system;
Packit 1fb8d4
fail:
Packit 1fb8d4
	free_pointer_system_update(update->context, pointer_system);
Packit 1fb8d4
	return NULL;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL _update_read_pointer_color(wStream* s, POINTER_COLOR_UPDATE* pointer_color, BYTE xorBpp,
Packit Service 5a9772
                                       UINT32 flags)
Packit 1fb8d4
{
Packit 1fb8d4
	BYTE* newMask;
Packit 1fb8d4
	UINT32 scanlineSize;
Packit Service 5a9772
	UINT32 max = 32;
Packit Service 5a9772
Packit Service 5a9772
	if (flags & LARGE_POINTER_FLAG_96x96)
Packit Service 5a9772
		max = 96;
Packit 1fb8d4
Packit 1fb8d4
	if (!pointer_color)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	if (Stream_GetRemainingLength(s) < 14)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Read_UINT16(s, pointer_color->cacheIndex); /* cacheIndex (2 bytes) */
Packit Service 5a9772
	Stream_Read_UINT16(s, pointer_color->xPos);       /* xPos (2 bytes) */
Packit Service 5a9772
	Stream_Read_UINT16(s, pointer_color->yPos);       /* yPos (2 bytes) */
Packit 1fb8d4
	/**
Packit 1fb8d4
	 *  As stated in 2.2.9.1.1.4.4 Color Pointer Update:
Packit 1fb8d4
	 *  The maximum allowed pointer width/height is 96 pixels if the client indicated support
Packit 1fb8d4
	 *  for large pointers by setting the LARGE_POINTER_FLAG (0x00000001) in the Large
Packit 1fb8d4
	 *  Pointer Capability Set (section 2.2.7.2.7). If the LARGE_POINTER_FLAG was not
Packit 1fb8d4
	 *  set, the maximum allowed pointer width/height is 32 pixels.
Packit 1fb8d4
	 *
Packit Service 5a9772
	 *  So we check for a maximum for CVE-2014-0250.
Packit 1fb8d4
	 */
Packit Service 5a9772
	Stream_Read_UINT16(s, pointer_color->width);  /* width (2 bytes) */
Packit 1fb8d4
	Stream_Read_UINT16(s, pointer_color->height); /* height (2 bytes) */
Packit 1fb8d4
Packit Service 5a9772
	if ((pointer_color->width > max) || (pointer_color->height > max))
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit Service 5a9772
	Stream_Read_UINT16(s, pointer_color->lengthAndMask); /* lengthAndMask (2 bytes) */
Packit Service 5a9772
	Stream_Read_UINT16(s, pointer_color->lengthXorMask); /* lengthXorMask (2 bytes) */
Packit 1fb8d4
Packit 1fb8d4
	/**
Packit 1fb8d4
	 * There does not seem to be any documentation on why
Packit 1fb8d4
	 * xPos / yPos can be larger than width / height
Packit 1fb8d4
	 * so it is missing in documentation or a bug in implementation
Packit 1fb8d4
	 * 2.2.9.1.1.4.4 Color Pointer Update (TS_COLORPOINTERATTRIBUTE)
Packit 1fb8d4
	 */
Packit 1fb8d4
	if (pointer_color->xPos >= pointer_color->width)
Packit 1fb8d4
		pointer_color->xPos = 0;
Packit 1fb8d4
Packit 1fb8d4
	if (pointer_color->yPos >= pointer_color->height)
Packit 1fb8d4
		pointer_color->yPos = 0;
Packit 1fb8d4
Packit 1fb8d4
	if (pointer_color->lengthXorMask > 0)
Packit 1fb8d4
	{
Packit 1fb8d4
		/**
Packit 1fb8d4
		 * Spec states that:
Packit 1fb8d4
		 *
Packit 1fb8d4
		 * xorMaskData (variable): A variable-length array of bytes. Contains the 24-bpp, bottom-up
Packit 1fb8d4
		 * XOR mask scan-line data. The XOR mask is padded to a 2-byte boundary for each encoded
Packit Service 5a9772
		 * scan-line. For example, if a 3x3 pixel cursor is being sent, then each scan-line will
Packit Service 5a9772
		 * consume 10 bytes (3 pixels per scan-line multiplied by 3 bytes per pixel, rounded up to
Packit Service 5a9772
		 * the next even number of bytes).
Packit 1fb8d4
		 *
Packit 1fb8d4
		 * In fact instead of 24-bpp, the bpp parameter is given by the containing packet.
Packit 1fb8d4
		 */
Packit 1fb8d4
		if (Stream_GetRemainingLength(s) < pointer_color->lengthXorMask)
Packit 1fb8d4
			goto fail;
Packit 1fb8d4
Packit 1fb8d4
		scanlineSize = (7 + xorBpp * pointer_color->width) / 8;
Packit 1fb8d4
		scanlineSize = ((scanlineSize + 1) / 2) * 2;
Packit 1fb8d4
Packit 1fb8d4
		if (scanlineSize * pointer_color->height != pointer_color->lengthXorMask)
Packit 1fb8d4
		{
Packit 1fb8d4
			WLog_ERR(TAG,
Packit Service 5a9772
			         "invalid lengthXorMask: width=%" PRIu32 " height=%" PRIu32 ", %" PRIu32
Packit Service 5a9772
			         " instead of %" PRIu32 "",
Packit Service 5a9772
			         pointer_color->width, pointer_color->height, pointer_color->lengthXorMask,
Packit Service 5a9772
			         scanlineSize * pointer_color->height);
Packit 1fb8d4
			goto fail;
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		newMask = realloc(pointer_color->xorMaskData, pointer_color->lengthXorMask);
Packit 1fb8d4
Packit 1fb8d4
		if (!newMask)
Packit 1fb8d4
			goto fail;
Packit 1fb8d4
Packit 1fb8d4
		pointer_color->xorMaskData = newMask;
Packit 1fb8d4
		Stream_Read(s, pointer_color->xorMaskData, pointer_color->lengthXorMask);
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (pointer_color->lengthAndMask > 0)
Packit 1fb8d4
	{
Packit 1fb8d4
		/**
Packit 1fb8d4
		 * andMaskData (variable): A variable-length array of bytes. Contains the 1-bpp, bottom-up
Packit 1fb8d4
		 * AND mask scan-line data. The AND mask is padded to a 2-byte boundary for each encoded
Packit Service 5a9772
		 * scan-line. For example, if a 7x7 pixel cursor is being sent, then each scan-line will
Packit Service 5a9772
		 * consume 2 bytes (7 pixels per scan-line multiplied by 1 bpp, rounded up to the next even
Packit Service 5a9772
		 * number of bytes).
Packit 1fb8d4
		 */
Packit 1fb8d4
		if (Stream_GetRemainingLength(s) < pointer_color->lengthAndMask)
Packit 1fb8d4
			goto fail;
Packit 1fb8d4
Packit 1fb8d4
		scanlineSize = ((7 + pointer_color->width) / 8);
Packit 1fb8d4
		scanlineSize = ((1 + scanlineSize) / 2) * 2;
Packit 1fb8d4
Packit 1fb8d4
		if (scanlineSize * pointer_color->height != pointer_color->lengthAndMask)
Packit 1fb8d4
		{
Packit Service 5a9772
			WLog_ERR(TAG, "invalid lengthAndMask: %" PRIu32 " instead of %" PRIu32 "",
Packit 1fb8d4
			         pointer_color->lengthAndMask, scanlineSize * pointer_color->height);
Packit 1fb8d4
			goto fail;
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		newMask = realloc(pointer_color->andMaskData, pointer_color->lengthAndMask);
Packit 1fb8d4
Packit 1fb8d4
		if (!newMask)
Packit 1fb8d4
			goto fail;
Packit 1fb8d4
Packit 1fb8d4
		pointer_color->andMaskData = newMask;
Packit 1fb8d4
		Stream_Read(s, pointer_color->andMaskData, pointer_color->lengthAndMask);
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (Stream_GetRemainingLength(s) > 0)
Packit 1fb8d4
		Stream_Seek_UINT8(s); /* pad (1 byte) */
Packit 1fb8d4
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
fail:
Packit 1fb8d4
	return FALSE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
POINTER_COLOR_UPDATE* update_read_pointer_color(rdpUpdate* update, wStream* s, BYTE xorBpp)
Packit 1fb8d4
{
Packit 1fb8d4
	POINTER_COLOR_UPDATE* pointer_color = calloc(1, sizeof(POINTER_COLOR_UPDATE));
Packit 1fb8d4
Packit 1fb8d4
	if (!pointer_color)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit Service 5a9772
	if (!_update_read_pointer_color(s, pointer_color, xorBpp,
Packit Service 5a9772
	                                update->context->settings->LargePointerFlag))
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	return pointer_color;
Packit 1fb8d4
fail:
Packit 1fb8d4
	free_pointer_color_update(update->context, pointer_color);
Packit 1fb8d4
	return NULL;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL _update_read_pointer_large(wStream* s, POINTER_LARGE_UPDATE* pointer)
Packit Service 5a9772
{
Packit Service 5a9772
	BYTE* newMask;
Packit Service 5a9772
	UINT32 scanlineSize;
Packit Service 5a9772
Packit Service 5a9772
	if (!pointer)
Packit Service 5a9772
		goto fail;
Packit Service 5a9772
Packit Service 5a9772
	if (Stream_GetRemainingLength(s) < 20)
Packit Service 5a9772
		goto fail;
Packit Service 5a9772
Packit Service 5a9772
	Stream_Read_UINT16(s, pointer->xorBpp);
Packit Service 5a9772
	Stream_Read_UINT16(s, pointer->cacheIndex); /* cacheIndex (2 bytes) */
Packit Service 5a9772
	Stream_Read_UINT16(s, pointer->hotSpotX);   /* xPos (2 bytes) */
Packit Service 5a9772
	Stream_Read_UINT16(s, pointer->hotSpotY);   /* yPos (2 bytes) */
Packit Service 5a9772
Packit Service 5a9772
	Stream_Read_UINT16(s, pointer->width);  /* width (2 bytes) */
Packit Service 5a9772
	Stream_Read_UINT16(s, pointer->height); /* height (2 bytes) */
Packit Service 5a9772
Packit Service 5a9772
	if ((pointer->width > 384) || (pointer->height > 384))
Packit Service 5a9772
		goto fail;
Packit Service 5a9772
Packit Service 5a9772
	Stream_Read_UINT32(s, pointer->lengthAndMask); /* lengthAndMask (4 bytes) */
Packit Service 5a9772
	Stream_Read_UINT32(s, pointer->lengthXorMask); /* lengthXorMask (4 bytes) */
Packit Service 5a9772
Packit Service 5a9772
	if (pointer->hotSpotX >= pointer->width)
Packit Service 5a9772
		pointer->hotSpotX = 0;
Packit Service 5a9772
Packit Service 5a9772
	if (pointer->hotSpotY >= pointer->height)
Packit Service 5a9772
		pointer->hotSpotY = 0;
Packit Service 5a9772
Packit Service 5a9772
	if (pointer->lengthXorMask > 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		/**
Packit Service 5a9772
		 * Spec states that:
Packit Service 5a9772
		 *
Packit Service 5a9772
		 * xorMaskData (variable): A variable-length array of bytes. Contains the 24-bpp, bottom-up
Packit Service 5a9772
		 * XOR mask scan-line data. The XOR mask is padded to a 2-byte boundary for each encoded
Packit Service 5a9772
		 * scan-line. For example, if a 3x3 pixel cursor is being sent, then each scan-line will
Packit Service 5a9772
		 * consume 10 bytes (3 pixels per scan-line multiplied by 3 bytes per pixel, rounded up to
Packit Service 5a9772
		 * the next even number of bytes).
Packit Service 5a9772
		 *
Packit Service 5a9772
		 * In fact instead of 24-bpp, the bpp parameter is given by the containing packet.
Packit Service 5a9772
		 */
Packit Service 5a9772
		if (Stream_GetRemainingLength(s) < pointer->lengthXorMask)
Packit Service 5a9772
			goto fail;
Packit Service 5a9772
Packit Service 5a9772
		scanlineSize = (7 + pointer->xorBpp * pointer->width) / 8;
Packit Service 5a9772
		scanlineSize = ((scanlineSize + 1) / 2) * 2;
Packit Service 5a9772
Packit Service 5a9772
		if (scanlineSize * pointer->height != pointer->lengthXorMask)
Packit Service 5a9772
		{
Packit Service 5a9772
			WLog_ERR(TAG,
Packit Service 5a9772
			         "invalid lengthXorMask: width=%" PRIu32 " height=%" PRIu32 ", %" PRIu32
Packit Service 5a9772
			         " instead of %" PRIu32 "",
Packit Service 5a9772
			         pointer->width, pointer->height, pointer->lengthXorMask,
Packit Service 5a9772
			         scanlineSize * pointer->height);
Packit Service 5a9772
			goto fail;
Packit Service 5a9772
		}
Packit Service 5a9772
Packit Service 5a9772
		newMask = realloc(pointer->xorMaskData, pointer->lengthXorMask);
Packit Service 5a9772
Packit Service 5a9772
		if (!newMask)
Packit Service 5a9772
			goto fail;
Packit Service 5a9772
Packit Service 5a9772
		pointer->xorMaskData = newMask;
Packit Service 5a9772
		Stream_Read(s, pointer->xorMaskData, pointer->lengthXorMask);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if (pointer->lengthAndMask > 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		/**
Packit Service 5a9772
		 * andMaskData (variable): A variable-length array of bytes. Contains the 1-bpp, bottom-up
Packit Service 5a9772
		 * AND mask scan-line data. The AND mask is padded to a 2-byte boundary for each encoded
Packit Service 5a9772
		 * scan-line. For example, if a 7x7 pixel cursor is being sent, then each scan-line will
Packit Service 5a9772
		 * consume 2 bytes (7 pixels per scan-line multiplied by 1 bpp, rounded up to the next even
Packit Service 5a9772
		 * number of bytes).
Packit Service 5a9772
		 */
Packit Service 5a9772
		if (Stream_GetRemainingLength(s) < pointer->lengthAndMask)
Packit Service 5a9772
			goto fail;
Packit Service 5a9772
Packit Service 5a9772
		scanlineSize = ((7 + pointer->width) / 8);
Packit Service 5a9772
		scanlineSize = ((1 + scanlineSize) / 2) * 2;
Packit Service 5a9772
Packit Service 5a9772
		if (scanlineSize * pointer->height != pointer->lengthAndMask)
Packit Service 5a9772
		{
Packit Service 5a9772
			WLog_ERR(TAG, "invalid lengthAndMask: %" PRIu32 " instead of %" PRIu32 "",
Packit Service 5a9772
			         pointer->lengthAndMask, scanlineSize * pointer->height);
Packit Service 5a9772
			goto fail;
Packit Service 5a9772
		}
Packit Service 5a9772
Packit Service 5a9772
		newMask = realloc(pointer->andMaskData, pointer->lengthAndMask);
Packit Service 5a9772
Packit Service 5a9772
		if (!newMask)
Packit Service 5a9772
			goto fail;
Packit Service 5a9772
Packit Service 5a9772
		pointer->andMaskData = newMask;
Packit Service 5a9772
		Stream_Read(s, pointer->andMaskData, pointer->lengthAndMask);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if (Stream_GetRemainingLength(s) > 0)
Packit Service 5a9772
		Stream_Seek_UINT8(s); /* pad (1 byte) */
Packit Service 5a9772
Packit Service 5a9772
	return TRUE;
Packit Service 5a9772
fail:
Packit Service 5a9772
	return FALSE;
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
POINTER_LARGE_UPDATE* update_read_pointer_large(rdpUpdate* update, wStream* s)
Packit Service 5a9772
{
Packit Service 5a9772
	POINTER_LARGE_UPDATE* pointer = calloc(1, sizeof(POINTER_LARGE_UPDATE));
Packit Service 5a9772
Packit Service 5a9772
	if (!pointer)
Packit Service 5a9772
		goto fail;
Packit Service 5a9772
Packit Service 5a9772
	if (!_update_read_pointer_large(s, pointer))
Packit Service 5a9772
		goto fail;
Packit Service 5a9772
Packit Service 5a9772
	return pointer;
Packit Service 5a9772
fail:
Packit Service 5a9772
	free_pointer_large_update(update->context, pointer);
Packit Service 5a9772
	return NULL;
Packit Service 5a9772
}
Packit Service 5a9772
Packit 1fb8d4
POINTER_NEW_UPDATE* update_read_pointer_new(rdpUpdate* update, wStream* s)
Packit 1fb8d4
{
Packit 1fb8d4
	POINTER_NEW_UPDATE* pointer_new = calloc(1, sizeof(POINTER_NEW_UPDATE));
Packit 1fb8d4
Packit 1fb8d4
	if (!pointer_new)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	if (Stream_GetRemainingLength(s) < 2)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Read_UINT16(s, pointer_new->xorBpp); /* xorBpp (2 bytes) */
Packit 1fb8d4
Packit 1fb8d4
	if ((pointer_new->xorBpp < 1) || (pointer_new->xorBpp > 32))
Packit 1fb8d4
	{
Packit Service 5a9772
		WLog_ERR(TAG, "invalid xorBpp %" PRIu32 "", pointer_new->xorBpp);
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit Service 5a9772
	if (!_update_read_pointer_color(s, &pointer_new->colorPtrAttr, pointer_new->xorBpp,
Packit Service 5a9772
	                                update->context->settings->LargePointerFlag)) /* colorPtrAttr */
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	return pointer_new;
Packit 1fb8d4
fail:
Packit 1fb8d4
	free_pointer_new_update(update->context, pointer_new);
Packit 1fb8d4
	return NULL;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
POINTER_CACHED_UPDATE* update_read_pointer_cached(rdpUpdate* update, wStream* s)
Packit 1fb8d4
{
Packit 1fb8d4
	POINTER_CACHED_UPDATE* pointer = calloc(1, sizeof(POINTER_CACHED_UPDATE));
Packit 1fb8d4
Packit 1fb8d4
	if (!pointer)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	if (Stream_GetRemainingLength(s) < 2)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Read_UINT16(s, pointer->cacheIndex); /* cacheIndex (2 bytes) */
Packit 1fb8d4
	return pointer;
Packit 1fb8d4
fail:
Packit 1fb8d4
	free_pointer_cached_update(update->context, pointer);
Packit 1fb8d4
	return NULL;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
BOOL update_recv_pointer(rdpUpdate* update, wStream* s)
Packit 1fb8d4
{
Packit 1fb8d4
	BOOL rc = FALSE;
Packit 1fb8d4
	UINT16 messageType;
Packit 1fb8d4
	rdpContext* context = update->context;
Packit 1fb8d4
	rdpPointerUpdate* pointer = update->pointer;
Packit 1fb8d4
Packit 1fb8d4
	if (Stream_GetRemainingLength(s) < 2 + 2)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Read_UINT16(s, messageType); /* messageType (2 bytes) */
Packit Service 5a9772
	Stream_Seek_UINT16(s);              /* pad2Octets (2 bytes) */
Packit 1fb8d4
Packit 1fb8d4
	switch (messageType)
Packit 1fb8d4
	{
Packit 1fb8d4
		case PTR_MSG_TYPE_POSITION:
Packit Service 5a9772
		{
Packit Service 5a9772
			POINTER_POSITION_UPDATE* pointer_position = update_read_pointer_position(update, s);
Packit 1fb8d4
Packit Service 5a9772
			if (pointer_position)
Packit Service 5a9772
			{
Packit Service 5a9772
				rc = IFCALLRESULT(FALSE, pointer->PointerPosition, context, pointer_position);
Packit Service 5a9772
				free_pointer_position_update(context, pointer_position);
Packit 1fb8d4
			}
Packit Service 5a9772
		}
Packit Service 5a9772
		break;
Packit 1fb8d4
Packit 1fb8d4
		case PTR_MSG_TYPE_SYSTEM:
Packit Service 5a9772
		{
Packit Service 5a9772
			POINTER_SYSTEM_UPDATE* pointer_system = update_read_pointer_system(update, s);
Packit 1fb8d4
Packit Service 5a9772
			if (pointer_system)
Packit Service 5a9772
			{
Packit Service 5a9772
				rc = IFCALLRESULT(FALSE, pointer->PointerSystem, context, pointer_system);
Packit Service 5a9772
				free_pointer_system_update(context, pointer_system);
Packit 1fb8d4
			}
Packit Service 5a9772
		}
Packit Service 5a9772
		break;
Packit 1fb8d4
Packit 1fb8d4
		case PTR_MSG_TYPE_COLOR:
Packit Service 5a9772
		{
Packit Service 5a9772
			POINTER_COLOR_UPDATE* pointer_color = update_read_pointer_color(update, s, 24);
Packit Service 5a9772
Packit Service 5a9772
			if (pointer_color)
Packit 1fb8d4
			{
Packit Service 5a9772
				rc = IFCALLRESULT(FALSE, pointer->PointerColor, context, pointer_color);
Packit Service 5a9772
				free_pointer_color_update(context, pointer_color);
Packit Service 5a9772
			}
Packit Service 5a9772
		}
Packit Service 5a9772
		break;
Packit Service 5a9772
Packit Service 5a9772
		case PTR_MSG_TYPE_POINTER_LARGE:
Packit Service 5a9772
		{
Packit Service 5a9772
			POINTER_LARGE_UPDATE* pointer_large = update_read_pointer_large(update, s);
Packit 1fb8d4
Packit Service 5a9772
			if (pointer_large)
Packit Service 5a9772
			{
Packit Service 5a9772
				rc = IFCALLRESULT(FALSE, pointer->PointerLarge, context, pointer_large);
Packit Service 5a9772
				free_pointer_large_update(context, pointer_large);
Packit 1fb8d4
			}
Packit Service 5a9772
		}
Packit Service 5a9772
		break;
Packit 1fb8d4
Packit 1fb8d4
		case PTR_MSG_TYPE_POINTER:
Packit Service 5a9772
		{
Packit Service 5a9772
			POINTER_NEW_UPDATE* pointer_new = update_read_pointer_new(update, s);
Packit 1fb8d4
Packit Service 5a9772
			if (pointer_new)
Packit Service 5a9772
			{
Packit Service 5a9772
				rc = IFCALLRESULT(FALSE, pointer->PointerNew, context, pointer_new);
Packit Service 5a9772
				free_pointer_new_update(context, pointer_new);
Packit 1fb8d4
			}
Packit Service 5a9772
		}
Packit Service 5a9772
		break;
Packit 1fb8d4
Packit 1fb8d4
		case PTR_MSG_TYPE_CACHED:
Packit Service 5a9772
		{
Packit Service 5a9772
			POINTER_CACHED_UPDATE* pointer_cached = update_read_pointer_cached(update, s);
Packit 1fb8d4
Packit Service 5a9772
			if (pointer_cached)
Packit Service 5a9772
			{
Packit Service 5a9772
				rc = IFCALLRESULT(FALSE, pointer->PointerCached, context, pointer_cached);
Packit Service 5a9772
				free_pointer_cached_update(context, pointer_cached);
Packit 1fb8d4
			}
Packit Service 5a9772
		}
Packit Service 5a9772
		break;
Packit 1fb8d4
Packit 1fb8d4
		default:
Packit 1fb8d4
			break;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return rc;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
BOOL update_recv(rdpUpdate* update, wStream* s)
Packit 1fb8d4
{
Packit 1fb8d4
	BOOL rc = FALSE;
Packit 1fb8d4
	UINT16 updateType;
Packit 1fb8d4
	rdpContext* context = update->context;
Packit 1fb8d4
Packit 1fb8d4
	if (Stream_GetRemainingLength(s) < 2)
Packit 1fb8d4
	{
Packit 1fb8d4
		WLog_ERR(TAG, "Stream_GetRemainingLength(s) < 2");
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	Stream_Read_UINT16(s, updateType); /* updateType (2 bytes) */
Packit Service 5a9772
	WLog_Print(update->log, WLOG_TRACE, "%s Update Data PDU", update_type_to_string(updateType));
Packit 1fb8d4
Packit Service 5a9772
	if (!update_begin_paint(update))
Packit Service 5a9772
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	switch (updateType)
Packit 1fb8d4
	{
Packit 1fb8d4
		case UPDATE_TYPE_ORDERS:
Packit 1fb8d4
			rc = update_recv_orders(update, s);
Packit 1fb8d4
			break;
Packit 1fb8d4
Packit 1fb8d4
		case UPDATE_TYPE_BITMAP:
Packit Service 5a9772
		{
Packit Service 5a9772
			BITMAP_UPDATE* bitmap_update = update_read_bitmap_update(update, s);
Packit 1fb8d4
Packit Service 5a9772
			if (!bitmap_update)
Packit Service 5a9772
			{
Packit Service 5a9772
				WLog_ERR(TAG, "UPDATE_TYPE_BITMAP - update_read_bitmap_update() failed");
Packit Service 5a9772
				goto fail;
Packit 1fb8d4
			}
Packit 1fb8d4
Packit Service 5a9772
			rc = IFCALLRESULT(FALSE, update->BitmapUpdate, context, bitmap_update);
Packit Service 5a9772
			free_bitmap_update(update->context, bitmap_update);
Packit Service 5a9772
		}
Packit Service 5a9772
		break;
Packit 1fb8d4
Packit Service 5a9772
		case UPDATE_TYPE_PALETTE:
Packit Service 5a9772
		{
Packit Service 5a9772
			PALETTE_UPDATE* palette_update = update_read_palette(update, s);
Packit 1fb8d4
Packit Service 5a9772
			if (!palette_update)
Packit Service 5a9772
			{
Packit Service 5a9772
				WLog_ERR(TAG, "UPDATE_TYPE_PALETTE - update_read_palette() failed");
Packit Service 5a9772
				goto fail;
Packit 1fb8d4
			}
Packit Service 5a9772
Packit Service 5a9772
			rc = IFCALLRESULT(FALSE, update->Palette, context, palette_update);
Packit Service 5a9772
			free_palette_update(context, palette_update);
Packit Service 5a9772
		}
Packit Service 5a9772
		break;
Packit 1fb8d4
Packit 1fb8d4
		case UPDATE_TYPE_SYNCHRONIZE:
Packit Service 5a9772
			if (!update_read_synchronize(update, s))
Packit Service 5a9772
				goto fail;
Packit 1fb8d4
			rc = IFCALLRESULT(TRUE, update->Synchronize, context);
Packit 1fb8d4
			break;
Packit 1fb8d4
Packit 1fb8d4
		default:
Packit 1fb8d4
			break;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit Service 5a9772
fail:
Packit Service 5a9772
Packit Service 5a9772
	if (!update_end_paint(update))
Packit Service 5a9772
		rc = FALSE;
Packit Service 5a9772
Packit 1fb8d4
	if (!rc)
Packit 1fb8d4
	{
Packit Service 5a9772
		WLog_ERR(TAG, "UPDATE_TYPE %s [%" PRIu16 "] failed", update_type_to_string(updateType),
Packit Service 5a9772
		         updateType);
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
void update_reset_state(rdpUpdate* update)
Packit 1fb8d4
{
Packit 1fb8d4
	rdpPrimaryUpdate* primary = update->primary;
Packit 1fb8d4
	rdpAltSecUpdate* altsec = update->altsec;
Packit 1fb8d4
Packit 1fb8d4
	if (primary->fast_glyph.glyphData.aj)
Packit 1fb8d4
	{
Packit 1fb8d4
		free(primary->fast_glyph.glyphData.aj);
Packit 1fb8d4
		primary->fast_glyph.glyphData.aj = NULL;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	ZeroMemory(&primary->order_info, sizeof(ORDER_INFO));
Packit 1fb8d4
	ZeroMemory(&primary->dstblt, sizeof(DSTBLT_ORDER));
Packit 1fb8d4
	ZeroMemory(&primary->patblt, sizeof(PATBLT_ORDER));
Packit 1fb8d4
	ZeroMemory(&primary->scrblt, sizeof(SCRBLT_ORDER));
Packit 1fb8d4
	ZeroMemory(&primary->opaque_rect, sizeof(OPAQUE_RECT_ORDER));
Packit 1fb8d4
	ZeroMemory(&primary->draw_nine_grid, sizeof(DRAW_NINE_GRID_ORDER));
Packit 1fb8d4
	ZeroMemory(&primary->multi_dstblt, sizeof(MULTI_DSTBLT_ORDER));
Packit 1fb8d4
	ZeroMemory(&primary->multi_patblt, sizeof(MULTI_PATBLT_ORDER));
Packit 1fb8d4
	ZeroMemory(&primary->multi_scrblt, sizeof(MULTI_SCRBLT_ORDER));
Packit 1fb8d4
	ZeroMemory(&primary->multi_opaque_rect, sizeof(MULTI_OPAQUE_RECT_ORDER));
Packit 1fb8d4
	ZeroMemory(&primary->multi_draw_nine_grid, sizeof(MULTI_DRAW_NINE_GRID_ORDER));
Packit 1fb8d4
	ZeroMemory(&primary->line_to, sizeof(LINE_TO_ORDER));
Packit 1fb8d4
	ZeroMemory(&primary->polyline, sizeof(POLYLINE_ORDER));
Packit 1fb8d4
	ZeroMemory(&primary->memblt, sizeof(MEMBLT_ORDER));
Packit 1fb8d4
	ZeroMemory(&primary->mem3blt, sizeof(MEM3BLT_ORDER));
Packit 1fb8d4
	ZeroMemory(&primary->save_bitmap, sizeof(SAVE_BITMAP_ORDER));
Packit 1fb8d4
	ZeroMemory(&primary->glyph_index, sizeof(GLYPH_INDEX_ORDER));
Packit 1fb8d4
	ZeroMemory(&primary->fast_index, sizeof(FAST_INDEX_ORDER));
Packit 1fb8d4
	ZeroMemory(&primary->fast_glyph, sizeof(FAST_GLYPH_ORDER));
Packit 1fb8d4
	ZeroMemory(&primary->polygon_sc, sizeof(POLYGON_SC_ORDER));
Packit 1fb8d4
	ZeroMemory(&primary->polygon_cb, sizeof(POLYGON_CB_ORDER));
Packit 1fb8d4
	ZeroMemory(&primary->ellipse_sc, sizeof(ELLIPSE_SC_ORDER));
Packit 1fb8d4
	ZeroMemory(&primary->ellipse_cb, sizeof(ELLIPSE_CB_ORDER));
Packit 1fb8d4
	primary->order_info.orderType = ORDER_TYPE_PATBLT;
Packit 1fb8d4
Packit 1fb8d4
	if (!update->initialState)
Packit 1fb8d4
	{
Packit 1fb8d4
		altsec->switch_surface.bitmapId = SCREEN_BITMAP_SURFACE;
Packit 1fb8d4
		IFCALL(altsec->SwitchSurface, update->context, &(altsec->switch_surface));
Packit 1fb8d4
	}
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
BOOL update_post_connect(rdpUpdate* update)
Packit 1fb8d4
{
Packit 1fb8d4
	update->asynchronous = update->context->settings->AsyncUpdate;
Packit 1fb8d4
Packit 1fb8d4
	if (update->asynchronous)
Packit 1fb8d4
		if (!(update->proxy = update_message_proxy_new(update)))
Packit 1fb8d4
			return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	update->altsec->switch_surface.bitmapId = SCREEN_BITMAP_SURFACE;
Packit Service 5a9772
	IFCALL(update->altsec->SwitchSurface, update->context, &(update->altsec->switch_surface));
Packit 1fb8d4
	update->initialState = FALSE;
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
void update_post_disconnect(rdpUpdate* update)
Packit 1fb8d4
{
Packit 1fb8d4
	update->asynchronous = update->context->settings->AsyncUpdate;
Packit 1fb8d4
Packit 1fb8d4
	if (update->asynchronous)
Packit 1fb8d4
		update_message_proxy_free(update->proxy);
Packit 1fb8d4
Packit 1fb8d4
	update->initialState = TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL _update_begin_paint(rdpContext* context)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit 1fb8d4
Packit 1fb8d4
	if (update->us)
Packit Service 5a9772
	{
Packit Service 5a9772
		if (!update_end_paint(update))
Packit Service 5a9772
			return FALSE;
Packit Service 5a9772
	}
Packit 1fb8d4
Packit 1fb8d4
	s = fastpath_update_pdu_init_new(context->rdp->fastpath);
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_SealLength(s);
Packit 1fb8d4
	Stream_Seek(s, 2); /* numberOrders (2 bytes) */
Packit 1fb8d4
	update->combineUpdates = TRUE;
Packit 1fb8d4
	update->numberOrders = 0;
Packit 1fb8d4
	update->us = s;
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL _update_end_paint(rdpContext* context)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	int headerLength;
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit 1fb8d4
Packit 1fb8d4
	if (!update->us)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	s = update->us;
Packit 1fb8d4
	headerLength = Stream_Length(s);
Packit 1fb8d4
	Stream_SealLength(s);
Packit 1fb8d4
	Stream_SetPosition(s, headerLength);
Packit 1fb8d4
	Stream_Write_UINT16(s, update->numberOrders); /* numberOrders (2 bytes) */
Packit 1fb8d4
	Stream_SetPosition(s, Stream_Length(s));
Packit 1fb8d4
Packit 1fb8d4
	if (update->numberOrders > 0)
Packit 1fb8d4
	{
Packit Service 5a9772
		WLog_DBG(TAG, "sending %" PRIu16 " orders", update->numberOrders);
Packit Service 5a9772
		fastpath_send_update_pdu(context->rdp->fastpath, FASTPATH_UPDATETYPE_ORDERS, s, FALSE);
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	update->combineUpdates = FALSE;
Packit 1fb8d4
	update->numberOrders = 0;
Packit 1fb8d4
	update->us = NULL;
Packit 1fb8d4
	Stream_Free(s, TRUE);
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static void update_flush(rdpContext* context)
Packit 1fb8d4
{
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit 1fb8d4
Packit 1fb8d4
	if (update->numberOrders > 0)
Packit 1fb8d4
	{
Packit Service 5a9772
		update_end_paint(update);
Packit Service 5a9772
		update_begin_paint(update);
Packit 1fb8d4
	}
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static void update_force_flush(rdpContext* context)
Packit 1fb8d4
{
Packit Service 5a9772
	update_flush(context);
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL update_check_flush(rdpContext* context, int size)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit 1fb8d4
	s = update->us;
Packit 1fb8d4
Packit 1fb8d4
	if (!update->us)
Packit 1fb8d4
	{
Packit Service 5a9772
		update_begin_paint(update);
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (Stream_GetPosition(s) + size + 64 >= 0x3FFF)
Packit 1fb8d4
	{
Packit 1fb8d4
		update_flush(context);
Packit 1fb8d4
		return TRUE;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return FALSE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_set_bounds(rdpContext* context, const rdpBounds* bounds)
Packit 1fb8d4
{
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit 1fb8d4
	CopyMemory(&update->previousBounds, &update->currentBounds, sizeof(rdpBounds));
Packit 1fb8d4
Packit 1fb8d4
	if (!bounds)
Packit 1fb8d4
		ZeroMemory(&update->currentBounds, sizeof(rdpBounds));
Packit 1fb8d4
	else
Packit 1fb8d4
		CopyMemory(&update->currentBounds, bounds, sizeof(rdpBounds));
Packit 1fb8d4
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_bounds_is_null(rdpBounds* bounds)
Packit 1fb8d4
{
Packit Service 5a9772
	if ((bounds->left == 0) && (bounds->top == 0) && (bounds->right == 0) && (bounds->bottom == 0))
Packit 1fb8d4
		return TRUE;
Packit 1fb8d4
Packit 1fb8d4
	return FALSE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_bounds_equals(rdpBounds* bounds1, rdpBounds* bounds2)
Packit 1fb8d4
{
Packit 1fb8d4
	if ((bounds1->left == bounds2->left) && (bounds1->top == bounds2->top) &&
Packit 1fb8d4
	    (bounds1->right == bounds2->right) && (bounds1->bottom == bounds2->bottom))
Packit 1fb8d4
		return TRUE;
Packit 1fb8d4
Packit 1fb8d4
	return FALSE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static int update_prepare_bounds(rdpContext* context, ORDER_INFO* orderInfo)
Packit 1fb8d4
{
Packit 1fb8d4
	int length = 0;
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit 1fb8d4
	orderInfo->boundsFlags = 0;
Packit 1fb8d4
Packit 1fb8d4
	if (update_bounds_is_null(&update->currentBounds))
Packit 1fb8d4
		return 0;
Packit 1fb8d4
Packit 1fb8d4
	orderInfo->controlFlags |= ORDER_BOUNDS;
Packit 1fb8d4
Packit 1fb8d4
	if (update_bounds_equals(&update->previousBounds, &update->currentBounds))
Packit 1fb8d4
	{
Packit 1fb8d4
		orderInfo->controlFlags |= ORDER_ZERO_BOUNDS_DELTAS;
Packit 1fb8d4
		return 0;
Packit 1fb8d4
	}
Packit 1fb8d4
	else
Packit 1fb8d4
	{
Packit 1fb8d4
		length += 1;
Packit 1fb8d4
Packit 1fb8d4
		if (update->previousBounds.left != update->currentBounds.left)
Packit 1fb8d4
		{
Packit 1fb8d4
			orderInfo->bounds.left = update->currentBounds.left;
Packit 1fb8d4
			orderInfo->boundsFlags |= BOUND_LEFT;
Packit 1fb8d4
			length += 2;
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		if (update->previousBounds.top != update->currentBounds.top)
Packit 1fb8d4
		{
Packit 1fb8d4
			orderInfo->bounds.top = update->currentBounds.top;
Packit 1fb8d4
			orderInfo->boundsFlags |= BOUND_TOP;
Packit 1fb8d4
			length += 2;
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		if (update->previousBounds.right != update->currentBounds.right)
Packit 1fb8d4
		{
Packit 1fb8d4
			orderInfo->bounds.right = update->currentBounds.right;
Packit 1fb8d4
			orderInfo->boundsFlags |= BOUND_RIGHT;
Packit 1fb8d4
			length += 2;
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		if (update->previousBounds.bottom != update->currentBounds.bottom)
Packit 1fb8d4
		{
Packit 1fb8d4
			orderInfo->bounds.bottom = update->currentBounds.bottom;
Packit 1fb8d4
			orderInfo->boundsFlags |= BOUND_BOTTOM;
Packit 1fb8d4
			length += 2;
Packit 1fb8d4
		}
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return length;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static int update_prepare_order_info(rdpContext* context, ORDER_INFO* orderInfo, UINT32 orderType)
Packit 1fb8d4
{
Packit 1fb8d4
	int length = 1;
Packit 1fb8d4
	orderInfo->fieldFlags = 0;
Packit 1fb8d4
	orderInfo->orderType = orderType;
Packit 1fb8d4
	orderInfo->controlFlags = ORDER_STANDARD;
Packit 1fb8d4
	orderInfo->controlFlags |= ORDER_TYPE_CHANGE;
Packit 1fb8d4
	length += 1;
Packit 1fb8d4
	length += PRIMARY_DRAWING_ORDER_FIELD_BYTES[orderInfo->orderType];
Packit 1fb8d4
	length += update_prepare_bounds(context, orderInfo);
Packit 1fb8d4
	return length;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static int update_write_order_info(rdpContext* context, wStream* s, ORDER_INFO* orderInfo,
Packit Service 5a9772
                                   size_t offset)
Packit 1fb8d4
{
Packit 1fb8d4
	size_t position;
Packit Service 5a9772
	WINPR_UNUSED(context);
Packit 1fb8d4
	position = Stream_GetPosition(s);
Packit 1fb8d4
	Stream_SetPosition(s, offset);
Packit 1fb8d4
	Stream_Write_UINT8(s, orderInfo->controlFlags); /* controlFlags (1 byte) */
Packit 1fb8d4
Packit 1fb8d4
	if (orderInfo->controlFlags & ORDER_TYPE_CHANGE)
Packit 1fb8d4
		Stream_Write_UINT8(s, orderInfo->orderType); /* orderType (1 byte) */
Packit 1fb8d4
Packit 1fb8d4
	update_write_field_flags(s, orderInfo->fieldFlags, orderInfo->controlFlags,
Packit 1fb8d4
	                         PRIMARY_DRAWING_ORDER_FIELD_BYTES[orderInfo->orderType]);
Packit 1fb8d4
	update_write_bounds(s, orderInfo);
Packit 1fb8d4
	Stream_SetPosition(s, position);
Packit 1fb8d4
	return 0;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static void update_write_refresh_rect(wStream* s, BYTE count, const RECTANGLE_16* areas)
Packit 1fb8d4
{
Packit 1fb8d4
	int i;
Packit 1fb8d4
	Stream_Write_UINT8(s, count); /* numberOfAreas (1 byte) */
Packit Service 5a9772
	Stream_Seek(s, 3);            /* pad3Octets (3 bytes) */
Packit 1fb8d4
Packit 1fb8d4
	for (i = 0; i < count; i++)
Packit 1fb8d4
	{
Packit Service 5a9772
		Stream_Write_UINT16(s, areas[i].left);   /* left (2 bytes) */
Packit Service 5a9772
		Stream_Write_UINT16(s, areas[i].top);    /* top (2 bytes) */
Packit Service 5a9772
		Stream_Write_UINT16(s, areas[i].right);  /* right (2 bytes) */
Packit 1fb8d4
		Stream_Write_UINT16(s, areas[i].bottom); /* bottom (2 bytes) */
Packit 1fb8d4
	}
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_send_refresh_rect(rdpContext* context, BYTE count, const RECTANGLE_16* areas)
Packit 1fb8d4
{
Packit 1fb8d4
	rdpRdp* rdp = context->rdp;
Packit 1fb8d4
Packit 1fb8d4
	if (rdp->settings->RefreshRect)
Packit 1fb8d4
	{
Packit 1fb8d4
		wStream* s = rdp_data_pdu_init(rdp);
Packit 1fb8d4
Packit 1fb8d4
		if (!s)
Packit 1fb8d4
			return FALSE;
Packit 1fb8d4
Packit 1fb8d4
		update_write_refresh_rect(s, count, areas);
Packit 1fb8d4
		return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_REFRESH_RECT, rdp->mcs->userId);
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static void update_write_suppress_output(wStream* s, BYTE allow, const RECTANGLE_16* area)
Packit 1fb8d4
{
Packit 1fb8d4
	Stream_Write_UINT8(s, allow); /* allowDisplayUpdates (1 byte) */
Packit 1fb8d4
	/* Use zeros for padding (like mstsc) for compatibility with legacy servers */
Packit 1fb8d4
	Stream_Zero(s, 3); /* pad3Octets (3 bytes) */
Packit 1fb8d4
Packit 1fb8d4
	if (allow > 0)
Packit 1fb8d4
	{
Packit Service 5a9772
		Stream_Write_UINT16(s, area->left);   /* left (2 bytes) */
Packit Service 5a9772
		Stream_Write_UINT16(s, area->top);    /* top (2 bytes) */
Packit Service 5a9772
		Stream_Write_UINT16(s, area->right);  /* right (2 bytes) */
Packit 1fb8d4
		Stream_Write_UINT16(s, area->bottom); /* bottom (2 bytes) */
Packit 1fb8d4
	}
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_send_suppress_output(rdpContext* context, BYTE allow, const RECTANGLE_16* area)
Packit 1fb8d4
{
Packit 1fb8d4
	rdpRdp* rdp = context->rdp;
Packit 1fb8d4
Packit 1fb8d4
	if (rdp->settings->SuppressOutput)
Packit 1fb8d4
	{
Packit 1fb8d4
		wStream* s = rdp_data_pdu_init(rdp);
Packit 1fb8d4
Packit 1fb8d4
		if (!s)
Packit 1fb8d4
			return FALSE;
Packit 1fb8d4
Packit 1fb8d4
		update_write_suppress_output(s, allow, area);
Packit Service 5a9772
		return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SUPPRESS_OUTPUT, rdp->mcs->userId);
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL update_send_surface_command(rdpContext* context, wStream* s)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* update;
Packit 1fb8d4
	rdpRdp* rdp = context->rdp;
Packit 1fb8d4
	BOOL ret;
Packit 1fb8d4
	update = fastpath_update_pdu_init(rdp->fastpath);
Packit 1fb8d4
Packit 1fb8d4
	if (!update)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	if (!Stream_EnsureRemainingCapacity(update, Stream_GetPosition(s)))
Packit 1fb8d4
	{
Packit 1fb8d4
		ret = FALSE;
Packit 1fb8d4
		goto out;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	Stream_Write(update, Stream_Buffer(s), Stream_GetPosition(s));
Packit Service 5a9772
	ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, update, FALSE);
Packit 1fb8d4
out:
Packit 1fb8d4
	Stream_Release(update);
Packit 1fb8d4
	return ret;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL update_send_surface_bits(rdpContext* context,
Packit 1fb8d4
                                     const SURFACE_BITS_COMMAND* surfaceBitsCommand)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	rdpRdp* rdp = context->rdp;
Packit 1fb8d4
	BOOL ret = FALSE;
Packit 1fb8d4
	update_force_flush(context);
Packit 1fb8d4
	s = fastpath_update_pdu_init(rdp->fastpath);
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	if (!update_write_surfcmd_surface_bits(s, surfaceBitsCommand))
Packit 1fb8d4
		goto out_fail;
Packit 1fb8d4
Packit 1fb8d4
	if (!fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, s,
Packit 1fb8d4
	                              surfaceBitsCommand->skipCompression))
Packit 1fb8d4
		goto out_fail;
Packit 1fb8d4
Packit 1fb8d4
	update_force_flush(context);
Packit 1fb8d4
	ret = TRUE;
Packit 1fb8d4
out_fail:
Packit 1fb8d4
	Stream_Release(s);
Packit 1fb8d4
	return ret;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL update_send_surface_frame_marker(rdpContext* context,
Packit Service 5a9772
                                             const SURFACE_FRAME_MARKER* surfaceFrameMarker)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	rdpRdp* rdp = context->rdp;
Packit 1fb8d4
	BOOL ret = FALSE;
Packit 1fb8d4
	update_force_flush(context);
Packit 1fb8d4
	s = fastpath_update_pdu_init(rdp->fastpath);
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	if (!update_write_surfcmd_frame_marker(s, surfaceFrameMarker->frameAction,
Packit 1fb8d4
	                                       surfaceFrameMarker->frameId) ||
Packit Service 5a9772
	    !fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, s, FALSE))
Packit 1fb8d4
		goto out_fail;
Packit 1fb8d4
Packit 1fb8d4
	update_force_flush(context);
Packit 1fb8d4
	ret = TRUE;
Packit 1fb8d4
out_fail:
Packit 1fb8d4
	Stream_Release(s);
Packit 1fb8d4
	return ret;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_send_surface_frame_bits(rdpContext* context, const SURFACE_BITS_COMMAND* cmd,
Packit Service 5a9772
                                           BOOL first, BOOL last, UINT32 frameId)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	rdpRdp* rdp = context->rdp;
Packit 1fb8d4
	BOOL ret = FALSE;
Packit 1fb8d4
	update_force_flush(context);
Packit 1fb8d4
	s = fastpath_update_pdu_init(rdp->fastpath);
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	if (first)
Packit 1fb8d4
	{
Packit Service 5a9772
		if (!update_write_surfcmd_frame_marker(s, SURFACECMD_FRAMEACTION_BEGIN, frameId))
Packit 1fb8d4
			goto out_fail;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (!update_write_surfcmd_surface_bits(s, cmd))
Packit 1fb8d4
		goto out_fail;
Packit 1fb8d4
Packit 1fb8d4
	if (last)
Packit 1fb8d4
	{
Packit 1fb8d4
		if (!update_write_surfcmd_frame_marker(s, SURFACECMD_FRAMEACTION_END, frameId))
Packit 1fb8d4
			goto out_fail;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SURFCMDS, s,
Packit 1fb8d4
	                               cmd->skipCompression);
Packit 1fb8d4
	update_force_flush(context);
Packit 1fb8d4
out_fail:
Packit 1fb8d4
	Stream_Release(s);
Packit 1fb8d4
	return ret;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL update_send_frame_acknowledge(rdpContext* context, UINT32 frameId)
Packit 1fb8d4
{
Packit 1fb8d4
	rdpRdp* rdp = context->rdp;
Packit 1fb8d4
Packit 1fb8d4
	if (rdp->settings->ReceivedCapabilities[CAPSET_TYPE_FRAME_ACKNOWLEDGE])
Packit 1fb8d4
	{
Packit 1fb8d4
		wStream* s = rdp_data_pdu_init(rdp);
Packit 1fb8d4
Packit 1fb8d4
		if (!s)
Packit 1fb8d4
			return FALSE;
Packit 1fb8d4
Packit 1fb8d4
		Stream_Write_UINT32(s, frameId);
Packit Service 5a9772
		return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_FRAME_ACKNOWLEDGE, rdp->mcs->userId);
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL update_send_synchronize(rdpContext* context)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	rdpRdp* rdp = context->rdp;
Packit 1fb8d4
	BOOL ret;
Packit 1fb8d4
	s = fastpath_update_pdu_init(rdp->fastpath);
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Zero(s, 2); /* pad2Octets (2 bytes) */
Packit Service 5a9772
	ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_SYNCHRONIZE, s, FALSE);
Packit 1fb8d4
	Stream_Release(s);
Packit 1fb8d4
	return ret;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL update_send_desktop_resize(rdpContext* context)
Packit 1fb8d4
{
Packit 1fb8d4
	return rdp_server_reactivate(context->rdp);
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_send_bitmap_update(rdpContext* context, const BITMAP_UPDATE* bitmapUpdate)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	rdpRdp* rdp = context->rdp;
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit 1fb8d4
	BOOL ret = TRUE;
Packit 1fb8d4
	update_force_flush(context);
Packit 1fb8d4
	s = fastpath_update_pdu_init(rdp->fastpath);
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	if (!update_write_bitmap_update(update, s, bitmapUpdate) ||
Packit 1fb8d4
	    !fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_BITMAP, s,
Packit 1fb8d4
	                              bitmapUpdate->skipCompression))
Packit 1fb8d4
	{
Packit 1fb8d4
		ret = FALSE;
Packit 1fb8d4
		goto out_fail;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	update_force_flush(context);
Packit 1fb8d4
out_fail:
Packit 1fb8d4
	Stream_Release(s);
Packit 1fb8d4
	return ret;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_send_play_sound(rdpContext* context, const PLAY_SOUND_UPDATE* play_sound)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	rdpRdp* rdp = context->rdp;
Packit 1fb8d4
Packit 1fb8d4
	if (!rdp->settings->ReceivedCapabilities[CAPSET_TYPE_SOUND])
Packit 1fb8d4
	{
Packit 1fb8d4
		return TRUE;
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	s = rdp_data_pdu_init(rdp);
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Write_UINT32(s, play_sound->duration);
Packit 1fb8d4
	Stream_Write_UINT32(s, play_sound->frequency);
Packit 1fb8d4
	return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_PLAY_SOUND, rdp->mcs->userId);
Packit 1fb8d4
}
Packit Service 5a9772
Packit 1fb8d4
/**
Packit 1fb8d4
 * Primary Drawing Orders
Packit 1fb8d4
 */
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_send_dstblt(rdpContext* context, const DSTBLT_ORDER* dstblt)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	UINT32 offset;
Packit 1fb8d4
	UINT32 headerLength;
Packit 1fb8d4
	ORDER_INFO orderInfo;
Packit 1fb8d4
	int inf;
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit Service 5a9772
	headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_DSTBLT);
Packit 1fb8d4
	inf = update_approximate_dstblt_order(&orderInfo, dstblt);
Packit 1fb8d4
	update_check_flush(context, headerLength + inf);
Packit 1fb8d4
	s = update->us;
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	offset = Stream_GetPosition(s);
Packit 1fb8d4
Packit 1fb8d4
	if (!Stream_EnsureRemainingCapacity(s, headerLength))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Seek(s, headerLength);
Packit 1fb8d4
Packit 1fb8d4
	if (!update_write_dstblt_order(s, &orderInfo, dstblt))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	update_write_order_info(context, s, &orderInfo, offset);
Packit 1fb8d4
	update->numberOrders++;
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL update_send_patblt(rdpContext* context, PATBLT_ORDER* patblt)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	size_t offset;
Packit 1fb8d4
	int headerLength;
Packit 1fb8d4
	ORDER_INFO orderInfo;
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit Service 5a9772
	headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_PATBLT);
Packit Service 5a9772
	update_check_flush(context, headerLength + update_approximate_patblt_order(&orderInfo, patblt));
Packit 1fb8d4
	s = update->us;
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	offset = Stream_GetPosition(s);
Packit 1fb8d4
Packit 1fb8d4
	if (!Stream_EnsureRemainingCapacity(s, headerLength))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Seek(s, headerLength);
Packit 1fb8d4
	update_write_patblt_order(s, &orderInfo, patblt);
Packit 1fb8d4
	update_write_order_info(context, s, &orderInfo, offset);
Packit 1fb8d4
	update->numberOrders++;
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL update_send_scrblt(rdpContext* context, const SCRBLT_ORDER* scrblt)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	UINT32 offset;
Packit 1fb8d4
	UINT32 headerLength;
Packit 1fb8d4
	ORDER_INFO orderInfo;
Packit 1fb8d4
	int inf;
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit Service 5a9772
	headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_SCRBLT);
Packit 1fb8d4
	inf = update_approximate_scrblt_order(&orderInfo, scrblt);
Packit 1fb8d4
	update_check_flush(context, headerLength + inf);
Packit 1fb8d4
	s = update->us;
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return TRUE;
Packit 1fb8d4
Packit 1fb8d4
	offset = Stream_GetPosition(s);
Packit 1fb8d4
Packit 1fb8d4
	if (!Stream_EnsureRemainingCapacity(s, headerLength))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Seek(s, headerLength);
Packit 1fb8d4
	update_write_scrblt_order(s, &orderInfo, scrblt);
Packit 1fb8d4
	update_write_order_info(context, s, &orderInfo, offset);
Packit 1fb8d4
	update->numberOrders++;
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_send_opaque_rect(rdpContext* context, const OPAQUE_RECT_ORDER* opaque_rect)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	size_t offset;
Packit 1fb8d4
	int headerLength;
Packit 1fb8d4
	ORDER_INFO orderInfo;
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit Service 5a9772
	headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_OPAQUE_RECT);
Packit Service 5a9772
	update_check_flush(context, headerLength +
Packit Service 5a9772
	                                update_approximate_opaque_rect_order(&orderInfo, opaque_rect));
Packit 1fb8d4
	s = update->us;
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	offset = Stream_GetPosition(s);
Packit 1fb8d4
Packit 1fb8d4
	if (!Stream_EnsureRemainingCapacity(s, headerLength))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Seek(s, headerLength);
Packit 1fb8d4
	update_write_opaque_rect_order(s, &orderInfo, opaque_rect);
Packit 1fb8d4
	update_write_order_info(context, s, &orderInfo, offset);
Packit 1fb8d4
	update->numberOrders++;
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_send_line_to(rdpContext* context, const LINE_TO_ORDER* line_to)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	int offset;
Packit 1fb8d4
	int headerLength;
Packit 1fb8d4
	ORDER_INFO orderInfo;
Packit 1fb8d4
	int inf;
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit Service 5a9772
	headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_LINE_TO);
Packit 1fb8d4
	inf = update_approximate_line_to_order(&orderInfo, line_to);
Packit 1fb8d4
	update_check_flush(context, headerLength + inf);
Packit 1fb8d4
	s = update->us;
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	offset = Stream_GetPosition(s);
Packit 1fb8d4
Packit 1fb8d4
	if (!Stream_EnsureRemainingCapacity(s, headerLength))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Seek(s, headerLength);
Packit 1fb8d4
	update_write_line_to_order(s, &orderInfo, line_to);
Packit 1fb8d4
	update_write_order_info(context, s, &orderInfo, offset);
Packit 1fb8d4
	update->numberOrders++;
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL update_send_memblt(rdpContext* context, MEMBLT_ORDER* memblt)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	size_t offset;
Packit 1fb8d4
	int headerLength;
Packit 1fb8d4
	ORDER_INFO orderInfo;
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit Service 5a9772
	headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_MEMBLT);
Packit Service 5a9772
	update_check_flush(context, headerLength + update_approximate_memblt_order(&orderInfo, memblt));
Packit 1fb8d4
	s = update->us;
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	offset = Stream_GetPosition(s);
Packit 1fb8d4
Packit 1fb8d4
	if (!Stream_EnsureRemainingCapacity(s, headerLength))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Seek(s, headerLength);
Packit 1fb8d4
	update_write_memblt_order(s, &orderInfo, memblt);
Packit 1fb8d4
	update_write_order_info(context, s, &orderInfo, offset);
Packit 1fb8d4
	update->numberOrders++;
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_send_glyph_index(rdpContext* context, GLYPH_INDEX_ORDER* glyph_index)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	size_t offset;
Packit 1fb8d4
	int headerLength;
Packit 1fb8d4
	int inf;
Packit 1fb8d4
	ORDER_INFO orderInfo;
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit Service 5a9772
	headerLength = update_prepare_order_info(context, &orderInfo, ORDER_TYPE_GLYPH_INDEX);
Packit 1fb8d4
	inf = update_approximate_glyph_index_order(&orderInfo, glyph_index);
Packit 1fb8d4
	update_check_flush(context, headerLength + inf);
Packit 1fb8d4
	s = update->us;
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	offset = Stream_GetPosition(s);
Packit 1fb8d4
Packit 1fb8d4
	if (!Stream_EnsureRemainingCapacity(s, headerLength))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Seek(s, headerLength);
Packit 1fb8d4
	update_write_glyph_index_order(s, &orderInfo, glyph_index);
Packit 1fb8d4
	update_write_order_info(context, s, &orderInfo, offset);
Packit 1fb8d4
	update->numberOrders++;
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
/*
Packit 1fb8d4
 * Secondary Drawing Orders
Packit 1fb8d4
 */
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_send_cache_bitmap(rdpContext* context, const CACHE_BITMAP_ORDER* cache_bitmap)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	size_t bm, em;
Packit 1fb8d4
	BYTE orderType;
Packit 1fb8d4
	int headerLength;
Packit 1fb8d4
	int inf;
Packit 1fb8d4
	UINT16 extraFlags;
Packit 1fb8d4
	INT16 orderLength;
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit 1fb8d4
	extraFlags = 0;
Packit 1fb8d4
	headerLength = 6;
Packit Service 5a9772
	orderType = cache_bitmap->compressed ? ORDER_TYPE_CACHE_BITMAP_COMPRESSED
Packit Service 5a9772
	                                     : ORDER_TYPE_BITMAP_UNCOMPRESSED;
Packit Service 5a9772
	inf =
Packit Service 5a9772
	    update_approximate_cache_bitmap_order(cache_bitmap, cache_bitmap->compressed, &extraFlags);
Packit 1fb8d4
	update_check_flush(context, headerLength + inf);
Packit 1fb8d4
	s = update->us;
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	bm = Stream_GetPosition(s);
Packit 1fb8d4
Packit 1fb8d4
	if (!Stream_EnsureRemainingCapacity(s, headerLength))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Seek(s, headerLength);
Packit 1fb8d4
Packit Service 5a9772
	if (!update_write_cache_bitmap_order(s, cache_bitmap, cache_bitmap->compressed, &extraFlags))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	em = Stream_GetPosition(s);
Packit 1fb8d4
	orderLength = (em - bm) - 13;
Packit 1fb8d4
	Stream_SetPosition(s, bm);
Packit Service 5a9772
	Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY); /* controlFlags (1 byte) */
Packit Service 5a9772
	Stream_Write_UINT16(s, orderLength);                     /* orderLength (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT16(s, extraFlags);                      /* extraFlags (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT8(s, orderType);                        /* orderType (1 byte) */
Packit 1fb8d4
	Stream_SetPosition(s, em);
Packit 1fb8d4
	update->numberOrders++;
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_send_cache_bitmap_v2(rdpContext* context, CACHE_BITMAP_V2_ORDER* cache_bitmap_v2)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	size_t bm, em;
Packit 1fb8d4
	BYTE orderType;
Packit 1fb8d4
	int headerLength;
Packit 1fb8d4
	UINT16 extraFlags;
Packit 1fb8d4
	INT16 orderLength;
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit 1fb8d4
	extraFlags = 0;
Packit 1fb8d4
	headerLength = 6;
Packit Service 5a9772
	orderType = cache_bitmap_v2->compressed ? ORDER_TYPE_BITMAP_COMPRESSED_V2
Packit Service 5a9772
	                                        : ORDER_TYPE_BITMAP_UNCOMPRESSED_V2;
Packit 1fb8d4
Packit 1fb8d4
	if (context->settings->NoBitmapCompressionHeader)
Packit 1fb8d4
		cache_bitmap_v2->flags |= CBR2_NO_BITMAP_COMPRESSION_HDR;
Packit 1fb8d4
Packit Service 5a9772
	update_check_flush(context, headerLength +
Packit Service 5a9772
	                                update_approximate_cache_bitmap_v2_order(
Packit Service 5a9772
	                                    cache_bitmap_v2, cache_bitmap_v2->compressed, &extraFlags));
Packit 1fb8d4
	s = update->us;
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	bm = Stream_GetPosition(s);
Packit 1fb8d4
Packit 1fb8d4
	if (!Stream_EnsureRemainingCapacity(s, headerLength))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Seek(s, headerLength);
Packit 1fb8d4
Packit Service 5a9772
	if (!update_write_cache_bitmap_v2_order(s, cache_bitmap_v2, cache_bitmap_v2->compressed,
Packit Service 5a9772
	                                        &extraFlags))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	em = Stream_GetPosition(s);
Packit 1fb8d4
	orderLength = (em - bm) - 13;
Packit 1fb8d4
	Stream_SetPosition(s, bm);
Packit Service 5a9772
	Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY); /* controlFlags (1 byte) */
Packit Service 5a9772
	Stream_Write_UINT16(s, orderLength);                     /* orderLength (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT16(s, extraFlags);                      /* extraFlags (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT8(s, orderType);                        /* orderType (1 byte) */
Packit 1fb8d4
	Stream_SetPosition(s, em);
Packit 1fb8d4
	update->numberOrders++;
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_send_cache_bitmap_v3(rdpContext* context, CACHE_BITMAP_V3_ORDER* cache_bitmap_v3)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	size_t bm, em;
Packit 1fb8d4
	BYTE orderType;
Packit 1fb8d4
	int headerLength;
Packit 1fb8d4
	UINT16 extraFlags;
Packit 1fb8d4
	INT16 orderLength;
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit 1fb8d4
	extraFlags = 0;
Packit 1fb8d4
	headerLength = 6;
Packit 1fb8d4
	orderType = ORDER_TYPE_BITMAP_COMPRESSED_V3;
Packit Service 5a9772
	update_check_flush(context, headerLength + update_approximate_cache_bitmap_v3_order(
Packit Service 5a9772
	                                               cache_bitmap_v3, &extraFlags));
Packit 1fb8d4
	s = update->us;
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	bm = Stream_GetPosition(s);
Packit 1fb8d4
Packit 1fb8d4
	if (!Stream_EnsureRemainingCapacity(s, headerLength))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Seek(s, headerLength);
Packit 1fb8d4
Packit 1fb8d4
	if (!update_write_cache_bitmap_v3_order(s, cache_bitmap_v3, &extraFlags))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	em = Stream_GetPosition(s);
Packit 1fb8d4
	orderLength = (em - bm) - 13;
Packit 1fb8d4
	Stream_SetPosition(s, bm);
Packit Service 5a9772
	Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY); /* controlFlags (1 byte) */
Packit Service 5a9772
	Stream_Write_UINT16(s, orderLength);                     /* orderLength (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT16(s, extraFlags);                      /* extraFlags (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT8(s, orderType);                        /* orderType (1 byte) */
Packit 1fb8d4
	Stream_SetPosition(s, em);
Packit 1fb8d4
	update->numberOrders++;
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL update_send_cache_color_table(rdpContext* context,
Packit Service 5a9772
                                          const CACHE_COLOR_TABLE_ORDER* cache_color_table)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	UINT16 flags;
Packit 1fb8d4
	size_t bm, em, inf;
Packit 1fb8d4
	int headerLength;
Packit 1fb8d4
	INT16 orderLength;
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit 1fb8d4
	flags = 0;
Packit 1fb8d4
	headerLength = 6;
Packit 1fb8d4
	inf = update_approximate_cache_color_table_order(cache_color_table, &flags);
Packit 1fb8d4
	update_check_flush(context, headerLength + inf);
Packit 1fb8d4
	s = update->us;
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	bm = Stream_GetPosition(s);
Packit 1fb8d4
Packit 1fb8d4
	if (!Stream_EnsureRemainingCapacity(s, headerLength))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Seek(s, headerLength);
Packit 1fb8d4
Packit 1fb8d4
	if (!update_write_cache_color_table_order(s, cache_color_table, &flags))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	em = Stream_GetPosition(s);
Packit 1fb8d4
	orderLength = (em - bm) - 13;
Packit 1fb8d4
	Stream_SetPosition(s, bm);
Packit Service 5a9772
	Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY); /* controlFlags (1 byte) */
Packit Service 5a9772
	Stream_Write_UINT16(s, orderLength);                     /* orderLength (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT16(s, flags);                           /* extraFlags (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT8(s, ORDER_TYPE_CACHE_COLOR_TABLE);     /* orderType (1 byte) */
Packit 1fb8d4
	Stream_SetPosition(s, em);
Packit 1fb8d4
	update->numberOrders++;
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_send_cache_glyph(rdpContext* context, const CACHE_GLYPH_ORDER* cache_glyph)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	UINT16 flags;
Packit 1fb8d4
	size_t bm, em, inf;
Packit 1fb8d4
	int headerLength;
Packit 1fb8d4
	INT16 orderLength;
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit 1fb8d4
	flags = 0;
Packit 1fb8d4
	headerLength = 6;
Packit 1fb8d4
	inf = update_approximate_cache_glyph_order(cache_glyph, &flags);
Packit 1fb8d4
	update_check_flush(context, headerLength + inf);
Packit 1fb8d4
	s = update->us;
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	bm = Stream_GetPosition(s);
Packit 1fb8d4
Packit 1fb8d4
	if (!Stream_EnsureRemainingCapacity(s, headerLength))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Seek(s, headerLength);
Packit 1fb8d4
Packit 1fb8d4
	if (!update_write_cache_glyph_order(s, cache_glyph, &flags))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	em = Stream_GetPosition(s);
Packit 1fb8d4
	orderLength = (em - bm) - 13;
Packit 1fb8d4
	Stream_SetPosition(s, bm);
Packit Service 5a9772
	Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY); /* controlFlags (1 byte) */
Packit Service 5a9772
	Stream_Write_UINT16(s, orderLength);                     /* orderLength (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT16(s, flags);                           /* extraFlags (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT8(s, ORDER_TYPE_CACHE_GLYPH);           /* orderType (1 byte) */
Packit 1fb8d4
	Stream_SetPosition(s, em);
Packit 1fb8d4
	update->numberOrders++;
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL update_send_cache_glyph_v2(rdpContext* context,
Packit 1fb8d4
                                       const CACHE_GLYPH_V2_ORDER* cache_glyph_v2)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	UINT16 flags;
Packit 1fb8d4
	size_t bm, em, inf;
Packit 1fb8d4
	int headerLength;
Packit 1fb8d4
	INT16 orderLength;
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit 1fb8d4
	flags = 0;
Packit 1fb8d4
	headerLength = 6;
Packit Service 5a9772
	inf = update_approximate_cache_glyph_v2_order(cache_glyph_v2, &flags);
Packit 1fb8d4
	update_check_flush(context, headerLength + inf);
Packit 1fb8d4
	s = update->us;
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	bm = Stream_GetPosition(s);
Packit 1fb8d4
Packit 1fb8d4
	if (!Stream_EnsureRemainingCapacity(s, headerLength))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Seek(s, headerLength);
Packit 1fb8d4
Packit 1fb8d4
	if (!update_write_cache_glyph_v2_order(s, cache_glyph_v2, &flags))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	em = Stream_GetPosition(s);
Packit 1fb8d4
	orderLength = (em - bm) - 13;
Packit 1fb8d4
	Stream_SetPosition(s, bm);
Packit 1fb8d4
	Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY); /* controlFlags (1 byte) */
Packit Service 5a9772
	Stream_Write_UINT16(s, orderLength);                     /* orderLength (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT16(s, flags);                           /* extraFlags (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT8(s, ORDER_TYPE_CACHE_GLYPH);           /* orderType (1 byte) */
Packit 1fb8d4
	Stream_SetPosition(s, em);
Packit 1fb8d4
	update->numberOrders++;
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_send_cache_brush(rdpContext* context, const CACHE_BRUSH_ORDER* cache_brush)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	UINT16 flags;
Packit 1fb8d4
	size_t bm, em, inf;
Packit 1fb8d4
	int headerLength;
Packit 1fb8d4
	INT16 orderLength;
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit 1fb8d4
	flags = 0;
Packit 1fb8d4
	headerLength = 6;
Packit 1fb8d4
	inf = update_approximate_cache_brush_order(cache_brush, &flags);
Packit 1fb8d4
	update_check_flush(context, headerLength + inf);
Packit 1fb8d4
	s = update->us;
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	bm = Stream_GetPosition(s);
Packit 1fb8d4
Packit 1fb8d4
	if (!Stream_EnsureRemainingCapacity(s, headerLength))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Seek(s, headerLength);
Packit 1fb8d4
Packit 1fb8d4
	if (!update_write_cache_brush_order(s, cache_brush, &flags))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	em = Stream_GetPosition(s);
Packit 1fb8d4
	orderLength = (em - bm) - 13;
Packit 1fb8d4
	Stream_SetPosition(s, bm);
Packit Service 5a9772
	Stream_Write_UINT8(s, ORDER_STANDARD | ORDER_SECONDARY); /* controlFlags (1 byte) */
Packit Service 5a9772
	Stream_Write_UINT16(s, orderLength);                     /* orderLength (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT16(s, flags);                           /* extraFlags (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT8(s, ORDER_TYPE_CACHE_BRUSH);           /* orderType (1 byte) */
Packit 1fb8d4
	Stream_SetPosition(s, em);
Packit 1fb8d4
	update->numberOrders++;
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
/**
Packit 1fb8d4
 * Alternate Secondary Drawing Orders
Packit 1fb8d4
 */
Packit 1fb8d4
Packit 1fb8d4
static BOOL update_send_create_offscreen_bitmap_order(
Packit Service 5a9772
    rdpContext* context, const CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	size_t bm, em, inf;
Packit 1fb8d4
	BYTE orderType;
Packit 1fb8d4
	BYTE controlFlags;
Packit 1fb8d4
	int headerLength;
Packit 1fb8d4
	rdpUpdate* update = context->update;
Packit 1fb8d4
	headerLength = 1;
Packit 1fb8d4
	orderType = ORDER_TYPE_CREATE_OFFSCREEN_BITMAP;
Packit 1fb8d4
	controlFlags = ORDER_SECONDARY | (orderType << 2);
Packit Service 5a9772
	inf = update_approximate_create_offscreen_bitmap_order(create_offscreen_bitmap);
Packit 1fb8d4
	update_check_flush(context, headerLength + inf);
Packit 1fb8d4
	s = update->us;
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	bm = Stream_GetPosition(s);
Packit 1fb8d4
Packit 1fb8d4
	if (!Stream_EnsureRemainingCapacity(s, headerLength))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Seek(s, headerLength);
Packit 1fb8d4
Packit 1fb8d4
	if (!update_write_create_offscreen_bitmap_order(s, create_offscreen_bitmap))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	em = Stream_GetPosition(s);
Packit 1fb8d4
	Stream_SetPosition(s, bm);
Packit 1fb8d4
	Stream_Write_UINT8(s, controlFlags); /* controlFlags (1 byte) */
Packit 1fb8d4
	Stream_SetPosition(s, em);
Packit 1fb8d4
	update->numberOrders++;
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_send_switch_surface_order(rdpContext* context,
Packit Service 5a9772
                                             const SWITCH_SURFACE_ORDER* switch_surface)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	size_t bm, em, inf;
Packit 1fb8d4
	BYTE orderType;
Packit 1fb8d4
	BYTE controlFlags;
Packit 1fb8d4
	int headerLength;
Packit 1fb8d4
	rdpUpdate* update;
Packit 1fb8d4
Packit 1fb8d4
	if (!context || !switch_surface || !context->update)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	update = context->update;
Packit 1fb8d4
	headerLength = 1;
Packit 1fb8d4
	orderType = ORDER_TYPE_SWITCH_SURFACE;
Packit 1fb8d4
	controlFlags = ORDER_SECONDARY | (orderType << 2);
Packit Service 5a9772
	inf = update_approximate_switch_surface_order(switch_surface);
Packit 1fb8d4
	update_check_flush(context, headerLength + inf);
Packit 1fb8d4
	s = update->us;
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	bm = Stream_GetPosition(s);
Packit 1fb8d4
Packit 1fb8d4
	if (!Stream_EnsureRemainingCapacity(s, headerLength))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Seek(s, headerLength);
Packit 1fb8d4
Packit 1fb8d4
	if (!update_write_switch_surface_order(s, switch_surface))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	em = Stream_GetPosition(s);
Packit 1fb8d4
	Stream_SetPosition(s, bm);
Packit 1fb8d4
	Stream_Write_UINT8(s, controlFlags); /* controlFlags (1 byte) */
Packit 1fb8d4
	Stream_SetPosition(s, em);
Packit 1fb8d4
	update->numberOrders++;
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL update_send_pointer_system(rdpContext* context,
Packit 1fb8d4
                                       const POINTER_SYSTEM_UPDATE* pointer_system)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	BYTE updateCode;
Packit 1fb8d4
	rdpRdp* rdp = context->rdp;
Packit 1fb8d4
	BOOL ret;
Packit 1fb8d4
	s = fastpath_update_pdu_init(rdp->fastpath);
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	if (pointer_system->type == SYSPTR_NULL)
Packit 1fb8d4
		updateCode = FASTPATH_UPDATETYPE_PTR_NULL;
Packit 1fb8d4
	else
Packit 1fb8d4
		updateCode = FASTPATH_UPDATETYPE_PTR_DEFAULT;
Packit 1fb8d4
Packit 1fb8d4
	ret = fastpath_send_update_pdu(rdp->fastpath, updateCode, s, FALSE);
Packit 1fb8d4
	Stream_Release(s);
Packit 1fb8d4
	return ret;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL update_send_pointer_position(rdpContext* context,
Packit Service 5a9772
                                         const POINTER_POSITION_UPDATE* pointerPosition)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	rdpRdp* rdp = context->rdp;
Packit 1fb8d4
	BOOL ret = FALSE;
Packit 1fb8d4
	s = fastpath_update_pdu_init(rdp->fastpath);
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	if (!Stream_EnsureRemainingCapacity(s, 16))
Packit 1fb8d4
		goto out_fail;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Write_UINT16(s, pointerPosition->xPos); /* xPos (2 bytes) */
Packit 1fb8d4
	Stream_Write_UINT16(s, pointerPosition->yPos); /* yPos (2 bytes) */
Packit Service 5a9772
	ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_PTR_POSITION, s, FALSE);
Packit 1fb8d4
out_fail:
Packit 1fb8d4
	Stream_Release(s);
Packit 1fb8d4
	return ret;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_write_pointer_color(wStream* s, const POINTER_COLOR_UPDATE* pointer_color)
Packit 1fb8d4
{
Packit Service 5a9772
	if (!Stream_EnsureRemainingCapacity(s, 32 + pointer_color->lengthAndMask +
Packit Service 5a9772
	                                           pointer_color->lengthXorMask))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Write_UINT16(s, pointer_color->cacheIndex);
Packit 1fb8d4
	Stream_Write_UINT16(s, pointer_color->xPos);
Packit 1fb8d4
	Stream_Write_UINT16(s, pointer_color->yPos);
Packit 1fb8d4
	Stream_Write_UINT16(s, pointer_color->width);
Packit 1fb8d4
	Stream_Write_UINT16(s, pointer_color->height);
Packit 1fb8d4
	Stream_Write_UINT16(s, pointer_color->lengthAndMask);
Packit 1fb8d4
	Stream_Write_UINT16(s, pointer_color->lengthXorMask);
Packit 1fb8d4
Packit 1fb8d4
	if (pointer_color->lengthXorMask > 0)
Packit 1fb8d4
		Stream_Write(s, pointer_color->xorMaskData, pointer_color->lengthXorMask);
Packit 1fb8d4
Packit 1fb8d4
	if (pointer_color->lengthAndMask > 0)
Packit 1fb8d4
		Stream_Write(s, pointer_color->andMaskData, pointer_color->lengthAndMask);
Packit 1fb8d4
Packit 1fb8d4
	Stream_Write_UINT8(s, 0); /* pad (1 byte) */
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL update_send_pointer_color(rdpContext* context,
Packit 1fb8d4
                                      const POINTER_COLOR_UPDATE* pointer_color)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	rdpRdp* rdp = context->rdp;
Packit 1fb8d4
	BOOL ret = FALSE;
Packit 1fb8d4
	s = fastpath_update_pdu_init(rdp->fastpath);
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	if (!update_write_pointer_color(s, pointer_color))
Packit 1fb8d4
		goto out_fail;
Packit 1fb8d4
Packit Service 5a9772
	ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_COLOR, s, FALSE);
Packit 1fb8d4
out_fail:
Packit 1fb8d4
	Stream_Release(s);
Packit 1fb8d4
	return ret;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_write_pointer_large(wStream* s, const POINTER_LARGE_UPDATE* pointer)
Packit Service 5a9772
{
Packit Service 5a9772
	if (!Stream_EnsureRemainingCapacity(s, 32 + pointer->lengthAndMask + pointer->lengthXorMask))
Packit Service 5a9772
		return FALSE;
Packit Service 5a9772
Packit Service 5a9772
	Stream_Write_UINT16(s, pointer->xorBpp);
Packit Service 5a9772
	Stream_Write_UINT16(s, pointer->cacheIndex);
Packit Service 5a9772
	Stream_Write_UINT16(s, pointer->hotSpotX);
Packit Service 5a9772
	Stream_Write_UINT16(s, pointer->hotSpotY);
Packit Service 5a9772
	Stream_Write_UINT16(s, pointer->width);
Packit Service 5a9772
	Stream_Write_UINT16(s, pointer->height);
Packit Service 5a9772
	Stream_Write_UINT32(s, pointer->lengthAndMask);
Packit Service 5a9772
	Stream_Write_UINT32(s, pointer->lengthXorMask);
Packit Service 5a9772
	Stream_Write(s, pointer->xorMaskData, pointer->lengthXorMask);
Packit Service 5a9772
	Stream_Write(s, pointer->andMaskData, pointer->lengthAndMask);
Packit Service 5a9772
	Stream_Write_UINT8(s, 0); /* pad (1 byte) */
Packit Service 5a9772
	return TRUE;
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
static BOOL update_send_pointer_large(rdpContext* context, const POINTER_LARGE_UPDATE* pointer)
Packit Service 5a9772
{
Packit Service 5a9772
	wStream* s;
Packit Service 5a9772
	rdpRdp* rdp = context->rdp;
Packit Service 5a9772
	BOOL ret = FALSE;
Packit Service 5a9772
	s = fastpath_update_pdu_init(rdp->fastpath);
Packit Service 5a9772
Packit Service 5a9772
	if (!s)
Packit Service 5a9772
		return FALSE;
Packit Service 5a9772
Packit Service 5a9772
	if (!update_write_pointer_large(s, pointer))
Packit Service 5a9772
		goto out_fail;
Packit Service 5a9772
Packit Service 5a9772
	ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_LARGE_POINTER, s, FALSE);
Packit Service 5a9772
out_fail:
Packit Service 5a9772
	Stream_Release(s);
Packit Service 5a9772
	return ret;
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
static BOOL update_send_pointer_new(rdpContext* context, const POINTER_NEW_UPDATE* pointer_new)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	rdpRdp* rdp = context->rdp;
Packit 1fb8d4
	BOOL ret = FALSE;
Packit 1fb8d4
	s = fastpath_update_pdu_init(rdp->fastpath);
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	if (!Stream_EnsureRemainingCapacity(s, 16))
Packit 1fb8d4
		goto out_fail;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Write_UINT16(s, pointer_new->xorBpp); /* xorBpp (2 bytes) */
Packit 1fb8d4
	update_write_pointer_color(s, &pointer_new->colorPtrAttr);
Packit Service 5a9772
	ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_POINTER, s, FALSE);
Packit 1fb8d4
out_fail:
Packit 1fb8d4
	Stream_Release(s);
Packit 1fb8d4
	return ret;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static BOOL update_send_pointer_cached(rdpContext* context,
Packit 1fb8d4
                                       const POINTER_CACHED_UPDATE* pointer_cached)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	rdpRdp* rdp = context->rdp;
Packit 1fb8d4
	BOOL ret;
Packit 1fb8d4
	s = fastpath_update_pdu_init(rdp->fastpath);
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Write_UINT16(s, pointer_cached->cacheIndex); /* cacheIndex (2 bytes) */
Packit Service 5a9772
	ret = fastpath_send_update_pdu(rdp->fastpath, FASTPATH_UPDATETYPE_CACHED, s, FALSE);
Packit 1fb8d4
	Stream_Release(s);
Packit 1fb8d4
	return ret;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
BOOL update_read_refresh_rect(rdpUpdate* update, wStream* s)
Packit 1fb8d4
{
Packit 1fb8d4
	int index;
Packit 1fb8d4
	BYTE numberOfAreas;
Packit 1fb8d4
	RECTANGLE_16* areas;
Packit 1fb8d4
Packit 1fb8d4
	if (Stream_GetRemainingLength(s) < 4)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Read_UINT8(s, numberOfAreas);
Packit 1fb8d4
	Stream_Seek(s, 3); /* pad3Octects */
Packit 1fb8d4
Packit Service 5a9772
	if (Stream_GetRemainingLength(s) < ((size_t)numberOfAreas * 4 * 2))
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit Service 5a9772
	areas = (RECTANGLE_16*)calloc(numberOfAreas, sizeof(RECTANGLE_16));
Packit 1fb8d4
Packit 1fb8d4
	if (!areas)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	for (index = 0; index < numberOfAreas; index++)
Packit 1fb8d4
	{
Packit 1fb8d4
		Stream_Read_UINT16(s, areas[index].left);
Packit 1fb8d4
		Stream_Read_UINT16(s, areas[index].top);
Packit 1fb8d4
		Stream_Read_UINT16(s, areas[index].right);
Packit 1fb8d4
		Stream_Read_UINT16(s, areas[index].bottom);
Packit 1fb8d4
	}
Packit 1fb8d4
Packit 1fb8d4
	if (update->context->settings->RefreshRect)
Packit 1fb8d4
		IFCALL(update->RefreshRect, update->context, numberOfAreas, areas);
Packit 1fb8d4
	else
Packit 1fb8d4
		WLog_Print(update->log, WLOG_WARN, "ignoring refresh rect request from client");
Packit 1fb8d4
Packit 1fb8d4
	free(areas);
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
BOOL update_read_suppress_output(rdpUpdate* update, wStream* s)
Packit 1fb8d4
{
Packit Service 5a9772
	RECTANGLE_16* prect = NULL;
Packit Service 5a9772
	RECTANGLE_16 rect = { 0 };
Packit 1fb8d4
	BYTE allowDisplayUpdates;
Packit 1fb8d4
Packit 1fb8d4
	if (Stream_GetRemainingLength(s) < 4)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	Stream_Read_UINT8(s, allowDisplayUpdates);
Packit 1fb8d4
	Stream_Seek(s, 3); /* pad3Octects */
Packit 1fb8d4
Packit Service 5a9772
	if (allowDisplayUpdates > 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		if (Stream_GetRemainingLength(s) < sizeof(RECTANGLE_16))
Packit Service 5a9772
			return FALSE;
Packit Service 5a9772
		Stream_Read_UINT16(s, rect.left);
Packit Service 5a9772
		Stream_Read_UINT16(s, rect.top);
Packit Service 5a9772
		Stream_Read_UINT16(s, rect.right);
Packit Service 5a9772
		Stream_Read_UINT16(s, rect.bottom);
Packit Service 5a9772
Packit Service 5a9772
		prect = ▭
Packit Service 5a9772
	}
Packit 1fb8d4
Packit 1fb8d4
	if (update->context->settings->SuppressOutput)
Packit Service 5a9772
		IFCALL(update->SuppressOutput, update->context, allowDisplayUpdates, prect);
Packit 1fb8d4
	else
Packit Service 5a9772
		WLog_Print(update->log, WLOG_WARN, "ignoring suppress output request from client");
Packit 1fb8d4
Packit 1fb8d4
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_send_set_keyboard_indicators(rdpContext* context, UINT16 led_flags)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	rdpRdp* rdp = context->rdp;
Packit 1fb8d4
	s = rdp_data_pdu_init(rdp);
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit Service 5a9772
	Stream_Write_UINT16(s, 0);         /* unitId should be 0 according to MS-RDPBCGR 2.2.8.2.1.1 */
Packit 1fb8d4
	Stream_Write_UINT16(s, led_flags); /* ledFlags (2 bytes) */
Packit Service 5a9772
	return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SET_KEYBOARD_INDICATORS, rdp->mcs->userId);
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
static BOOL update_send_set_keyboard_ime_status(rdpContext* context, UINT16 imeId, UINT32 imeState,
Packit Service 5a9772
                                                UINT32 imeConvMode)
Packit 1fb8d4
{
Packit 1fb8d4
	wStream* s;
Packit 1fb8d4
	rdpRdp* rdp = context->rdp;
Packit 1fb8d4
	s = rdp_data_pdu_init(rdp);
Packit 1fb8d4
Packit 1fb8d4
	if (!s)
Packit 1fb8d4
		return FALSE;
Packit 1fb8d4
Packit 1fb8d4
	/* unitId should be 0 according to MS-RDPBCGR 2.2.8.2.2.1 */
Packit 1fb8d4
	Stream_Write_UINT16(s, imeId);
Packit 1fb8d4
	Stream_Write_UINT32(s, imeState);
Packit 1fb8d4
	Stream_Write_UINT32(s, imeConvMode);
Packit Service 5a9772
	return rdp_send_data_pdu(rdp, s, DATA_PDU_TYPE_SET_KEYBOARD_IME_STATUS, rdp->mcs->userId);
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
static UINT16 update_calculate_new_or_existing_window(const WINDOW_ORDER_INFO* orderInfo,
Packit Service 5a9772
                                                      const WINDOW_STATE_ORDER* stateOrder)
Packit Service 5a9772
{
Packit Service 5a9772
	UINT16 orderSize = 11;
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_OWNER) != 0)
Packit Service 5a9772
		orderSize += 4;
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_STYLE) != 0)
Packit Service 5a9772
		orderSize += 8;
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_SHOW) != 0)
Packit Service 5a9772
		orderSize += 1;
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_TITLE) != 0)
Packit Service 5a9772
		orderSize += 2 + stateOrder->titleInfo.length;
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_OFFSET) != 0)
Packit Service 5a9772
		orderSize += 8;
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_SIZE) != 0)
Packit Service 5a9772
		orderSize += 8;
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_RESIZE_MARGIN_X) != 0)
Packit Service 5a9772
		orderSize += 8;
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_RESIZE_MARGIN_Y) != 0)
Packit Service 5a9772
		orderSize += 8;
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_RP_CONTENT) != 0)
Packit Service 5a9772
		orderSize += 1;
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_ROOT_PARENT) != 0)
Packit Service 5a9772
		orderSize += 4;
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET) != 0)
Packit Service 5a9772
		orderSize += 8;
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_CLIENT_DELTA) != 0)
Packit Service 5a9772
		orderSize += 8;
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE) != 0)
Packit Service 5a9772
		orderSize += 8;
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_RECTS) != 0)
Packit Service 5a9772
		orderSize += 2 + stateOrder->numWindowRects * sizeof(RECTANGLE_16);
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_VIS_OFFSET) != 0)
Packit Service 5a9772
		orderSize += 8;
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_VISIBILITY) != 0)
Packit Service 5a9772
		orderSize += 2 + stateOrder->numVisibilityRects * sizeof(RECTANGLE_16);
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_OVERLAY_DESCRIPTION) != 0)
Packit Service 5a9772
		orderSize += 2 + stateOrder->OverlayDescription.length;
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_TASKBAR_BUTTON) != 0)
Packit Service 5a9772
		orderSize += 1;
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_ENFORCE_SERVER_ZORDER) != 0)
Packit Service 5a9772
		orderSize += 1;
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_APPBAR_STATE) != 0)
Packit Service 5a9772
		orderSize += 1;
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_APPBAR_EDGE) != 0)
Packit Service 5a9772
		orderSize += 1;
Packit Service 5a9772
Packit Service 5a9772
	return orderSize;
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
static BOOL update_send_new_or_existing_window(rdpContext* context,
Packit Service 5a9772
                                               const WINDOW_ORDER_INFO* orderInfo,
Packit Service 5a9772
                                               const WINDOW_STATE_ORDER* stateOrder)
Packit Service 5a9772
{
Packit Service 5a9772
	wStream* s;
Packit Service 5a9772
	rdpUpdate* update = context->update;
Packit Service 5a9772
	BYTE controlFlags = ORDER_SECONDARY | (ORDER_TYPE_WINDOW << 2);
Packit Service 5a9772
	UINT16 orderSize = update_calculate_new_or_existing_window(orderInfo, stateOrder);
Packit Service 5a9772
Packit Service 5a9772
	update_check_flush(context, orderSize);
Packit Service 5a9772
Packit Service 5a9772
	s = update->us;
Packit Service 5a9772
Packit Service 5a9772
	if (!s)
Packit Service 5a9772
		return FALSE;
Packit Service 5a9772
Packit Service 5a9772
	if (!Stream_EnsureRemainingCapacity(s, orderSize))
Packit Service 5a9772
		return FALSE;
Packit Service 5a9772
Packit Service 5a9772
	Stream_Write_UINT8(s, controlFlags);           /* Header (1 byte) */
Packit Service 5a9772
	Stream_Write_UINT16(s, orderSize);             /* OrderSize (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT32(s, orderInfo->fieldFlags); /* FieldsPresentFlags (4 bytes) */
Packit Service 5a9772
	Stream_Write_UINT32(s, orderInfo->windowId);   /* WindowID (4 bytes) */
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_OWNER) != 0)
Packit Service 5a9772
		Stream_Write_UINT32(s, stateOrder->ownerWindowId);
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_STYLE) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_UINT32(s, stateOrder->style);
Packit Service 5a9772
		Stream_Write_UINT32(s, stateOrder->extendedStyle);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_SHOW) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_UINT8(s, stateOrder->showState);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_TITLE) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_UINT16(s, stateOrder->titleInfo.length);
Packit Service 5a9772
		Stream_Write(s, stateOrder->titleInfo.string, stateOrder->titleInfo.length);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_OFFSET) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_INT32(s, stateOrder->clientOffsetX);
Packit Service 5a9772
		Stream_Write_INT32(s, stateOrder->clientOffsetY);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_SIZE) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_UINT32(s, stateOrder->clientAreaWidth);
Packit Service 5a9772
		Stream_Write_UINT32(s, stateOrder->clientAreaHeight);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_RESIZE_MARGIN_X) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_UINT32(s, stateOrder->resizeMarginLeft);
Packit Service 5a9772
		Stream_Write_UINT32(s, stateOrder->resizeMarginRight);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_RESIZE_MARGIN_Y) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_UINT32(s, stateOrder->resizeMarginTop);
Packit Service 5a9772
		Stream_Write_UINT32(s, stateOrder->resizeMarginBottom);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_RP_CONTENT) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_UINT8(s, stateOrder->RPContent);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_ROOT_PARENT) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_UINT32(s, stateOrder->rootParentHandle);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_INT32(s, stateOrder->windowOffsetX);
Packit Service 5a9772
		Stream_Write_INT32(s, stateOrder->windowOffsetY);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_CLIENT_DELTA) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_INT32(s, stateOrder->windowClientDeltaX);
Packit Service 5a9772
		Stream_Write_INT32(s, stateOrder->windowClientDeltaY);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_UINT32(s, stateOrder->windowWidth);
Packit Service 5a9772
		Stream_Write_UINT32(s, stateOrder->windowHeight);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_RECTS) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_UINT16(s, stateOrder->numWindowRects);
Packit Service 5a9772
		Stream_Write(s, stateOrder->windowRects, stateOrder->numWindowRects * sizeof(RECTANGLE_16));
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_VIS_OFFSET) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_UINT32(s, stateOrder->visibleOffsetX);
Packit Service 5a9772
		Stream_Write_UINT32(s, stateOrder->visibleOffsetY);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_VISIBILITY) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_UINT16(s, stateOrder->numVisibilityRects);
Packit Service 5a9772
		Stream_Write(s, stateOrder->visibilityRects,
Packit Service 5a9772
		             stateOrder->numVisibilityRects * sizeof(RECTANGLE_16));
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_OVERLAY_DESCRIPTION) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_UINT16(s, stateOrder->OverlayDescription.length);
Packit Service 5a9772
		Stream_Write(s, stateOrder->OverlayDescription.string,
Packit Service 5a9772
		             stateOrder->OverlayDescription.length);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_TASKBAR_BUTTON) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_UINT8(s, stateOrder->TaskbarButton);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_ENFORCE_SERVER_ZORDER) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_UINT8(s, stateOrder->EnforceServerZOrder);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_APPBAR_STATE) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_UINT8(s, stateOrder->AppBarState);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_APPBAR_EDGE) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_UINT8(s, stateOrder->AppBarEdge);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	update->numberOrders++;
Packit Service 5a9772
	return TRUE;
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
static BOOL update_send_window_create(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
Packit Service 5a9772
                                      const WINDOW_STATE_ORDER* stateOrder)
Packit Service 5a9772
{
Packit Service 5a9772
	return update_send_new_or_existing_window(context, orderInfo, stateOrder);
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
static BOOL update_send_window_update(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
Packit Service 5a9772
                                      const WINDOW_STATE_ORDER* stateOrder)
Packit Service 5a9772
{
Packit Service 5a9772
	return update_send_new_or_existing_window(context, orderInfo, stateOrder);
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
static UINT16 update_calculate_window_icon_order(const WINDOW_ORDER_INFO* orderInfo,
Packit Service 5a9772
                                                 const WINDOW_ICON_ORDER* iconOrder)
Packit Service 5a9772
{
Packit Service 5a9772
	UINT16 orderSize = 23;
Packit Service 5a9772
	ICON_INFO* iconInfo = iconOrder->iconInfo;
Packit Service 5a9772
Packit Service 5a9772
	orderSize += iconInfo->cbBitsColor + iconInfo->cbBitsMask;
Packit Service 5a9772
Packit Service 5a9772
	if (iconInfo->bpp <= 8)
Packit Service 5a9772
		orderSize += 2 + iconInfo->cbColorTable;
Packit Service 5a9772
Packit Service 5a9772
	return orderSize;
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
static BOOL update_send_window_icon(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
Packit Service 5a9772
                                    const WINDOW_ICON_ORDER* iconOrder)
Packit Service 5a9772
{
Packit Service 5a9772
	wStream* s;
Packit Service 5a9772
	rdpUpdate* update = context->update;
Packit Service 5a9772
	BYTE controlFlags = ORDER_SECONDARY | (ORDER_TYPE_WINDOW << 2);
Packit Service 5a9772
	ICON_INFO* iconInfo = iconOrder->iconInfo;
Packit Service 5a9772
	UINT16 orderSize = update_calculate_window_icon_order(orderInfo, iconOrder);
Packit Service 5a9772
Packit Service 5a9772
	update_check_flush(context, orderSize);
Packit Service 5a9772
Packit Service 5a9772
	s = update->us;
Packit Service 5a9772
Packit Service 5a9772
	if (!s || !iconInfo)
Packit Service 5a9772
		return FALSE;
Packit Service 5a9772
Packit Service 5a9772
	if (!Stream_EnsureRemainingCapacity(s, orderSize))
Packit Service 5a9772
		return FALSE;
Packit Service 5a9772
Packit Service 5a9772
	/* Write Hdr */
Packit Service 5a9772
	Stream_Write_UINT8(s, controlFlags);           /* Header (1 byte) */
Packit Service 5a9772
	Stream_Write_UINT16(s, orderSize);             /* OrderSize (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT32(s, orderInfo->fieldFlags); /* FieldsPresentFlags (4 bytes) */
Packit Service 5a9772
	Stream_Write_UINT32(s, orderInfo->windowId);   /* WindowID (4 bytes) */
Packit Service 5a9772
	/* Write body */
Packit Service 5a9772
	Stream_Write_UINT16(s, iconInfo->cacheEntry); /* CacheEntry (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT8(s, iconInfo->cacheId);     /* CacheId (1 byte) */
Packit Service 5a9772
	Stream_Write_UINT8(s, iconInfo->bpp);         /* Bpp (1 byte) */
Packit Service 5a9772
	Stream_Write_UINT16(s, iconInfo->width);      /* Width (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT16(s, iconInfo->height);     /* Height (2 bytes) */
Packit Service 5a9772
Packit Service 5a9772
	if (iconInfo->bpp <= 8)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_UINT16(s, iconInfo->cbColorTable); /* CbColorTable (2 bytes) */
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	Stream_Write_UINT16(s, iconInfo->cbBitsMask);              /* CbBitsMask (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT16(s, iconInfo->cbBitsColor);             /* CbBitsColor (2 bytes) */
Packit Service 5a9772
	Stream_Write(s, iconInfo->bitsMask, iconInfo->cbBitsMask); /* BitsMask (variable) */
Packit Service 5a9772
Packit Service 5a9772
	if (iconInfo->bpp <= 8)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write(s, iconInfo->colorTable, iconInfo->cbColorTable); /* ColorTable (variable) */
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	Stream_Write(s, iconInfo->bitsColor, iconInfo->cbBitsColor); /* BitsColor (variable) */
Packit Service 5a9772
Packit Service 5a9772
	update->numberOrders++;
Packit Service 5a9772
	return TRUE;
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
static BOOL update_send_window_cached_icon(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
Packit Service 5a9772
                                           const WINDOW_CACHED_ICON_ORDER* cachedIconOrder)
Packit Service 5a9772
{
Packit Service 5a9772
	wStream* s;
Packit Service 5a9772
	rdpUpdate* update = context->update;
Packit Service 5a9772
	BYTE controlFlags = ORDER_SECONDARY | (ORDER_TYPE_WINDOW << 2);
Packit Service 5a9772
	UINT16 orderSize = 14;
Packit Service 5a9772
	CACHED_ICON_INFO cachedIcon = cachedIconOrder->cachedIcon;
Packit Service 5a9772
Packit Service 5a9772
	update_check_flush(context, orderSize);
Packit Service 5a9772
Packit Service 5a9772
	s = update->us;
Packit Service 5a9772
	if (!s)
Packit Service 5a9772
		return FALSE;
Packit Service 5a9772
Packit Service 5a9772
	if (!Stream_EnsureRemainingCapacity(s, orderSize))
Packit Service 5a9772
		return FALSE;
Packit Service 5a9772
Packit Service 5a9772
	/* Write Hdr */
Packit Service 5a9772
	Stream_Write_UINT8(s, controlFlags);           /* Header (1 byte) */
Packit Service 5a9772
	Stream_Write_UINT16(s, orderSize);             /* OrderSize (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT32(s, orderInfo->fieldFlags); /* FieldsPresentFlags (4 bytes) */
Packit Service 5a9772
	Stream_Write_UINT32(s, orderInfo->windowId);   /* WindowID (4 bytes) */
Packit Service 5a9772
	/* Write body */
Packit Service 5a9772
	Stream_Write_UINT16(s, cachedIcon.cacheEntry); /* CacheEntry (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT8(s, cachedIcon.cacheId);     /* CacheId (1 byte) */
Packit Service 5a9772
	update->numberOrders++;
Packit Service 5a9772
	return TRUE;
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
static BOOL update_send_window_delete(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo)
Packit Service 5a9772
{
Packit Service 5a9772
	wStream* s;
Packit Service 5a9772
	rdpUpdate* update = context->update;
Packit Service 5a9772
	BYTE controlFlags = ORDER_SECONDARY | (ORDER_TYPE_WINDOW << 2);
Packit Service 5a9772
	UINT16 orderSize = 11;
Packit Service 5a9772
	update_check_flush(context, orderSize);
Packit Service 5a9772
Packit Service 5a9772
	s = update->us;
Packit Service 5a9772
Packit Service 5a9772
	if (!s)
Packit Service 5a9772
		return FALSE;
Packit Service 5a9772
Packit Service 5a9772
	if (!Stream_EnsureRemainingCapacity(s, orderSize))
Packit Service 5a9772
		return FALSE;
Packit Service 5a9772
Packit Service 5a9772
	/* Write Hdr */
Packit Service 5a9772
	Stream_Write_UINT8(s, controlFlags);           /* Header (1 byte) */
Packit Service 5a9772
	Stream_Write_UINT16(s, orderSize);             /* OrderSize (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT32(s, orderInfo->fieldFlags); /* FieldsPresentFlags (4 bytes) */
Packit Service 5a9772
	Stream_Write_UINT32(s, orderInfo->windowId);   /* WindowID (4 bytes) */
Packit Service 5a9772
	update->numberOrders++;
Packit Service 5a9772
	return TRUE;
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
static UINT16 update_calculate_new_or_existing_notification_icons_order(
Packit Service 5a9772
    const WINDOW_ORDER_INFO* orderInfo, const NOTIFY_ICON_STATE_ORDER* iconStateOrder)
Packit Service 5a9772
{
Packit Service 5a9772
	UINT16 orderSize = 15;
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_VERSION) != 0)
Packit Service 5a9772
		orderSize += 4;
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_TIP) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		orderSize += 2 + iconStateOrder->toolTip.length;
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_INFO_TIP) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		NOTIFY_ICON_INFOTIP infoTip = iconStateOrder->infoTip;
Packit Service 5a9772
		orderSize += 12 + infoTip.text.length + infoTip.title.length;
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_STATE) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		orderSize += 4;
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_ICON) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		ICON_INFO iconInfo = iconStateOrder->icon;
Packit Service 5a9772
		orderSize += 12;
Packit Service 5a9772
Packit Service 5a9772
		if (iconInfo.bpp <= 8)
Packit Service 5a9772
			orderSize += 2 + iconInfo.cbColorTable;
Packit Service 5a9772
Packit Service 5a9772
		orderSize += iconInfo.cbBitsMask + iconInfo.cbBitsColor;
Packit Service 5a9772
	}
Packit Service 5a9772
	else if ((orderInfo->fieldFlags & WINDOW_ORDER_CACHED_ICON) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		orderSize += 3;
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	return orderSize;
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
static BOOL
Packit Service 5a9772
update_send_new_or_existing_notification_icons(rdpContext* context,
Packit Service 5a9772
                                               const WINDOW_ORDER_INFO* orderInfo,
Packit Service 5a9772
                                               const NOTIFY_ICON_STATE_ORDER* iconStateOrder)
Packit Service 5a9772
{
Packit Service 5a9772
	wStream* s;
Packit Service 5a9772
	rdpUpdate* update = context->update;
Packit Service 5a9772
	BYTE controlFlags = ORDER_SECONDARY | (ORDER_TYPE_WINDOW << 2);
Packit Service 5a9772
	BOOL versionFieldPresent = FALSE;
Packit Service 5a9772
	UINT16 orderSize =
Packit Service 5a9772
	    update_calculate_new_or_existing_notification_icons_order(orderInfo, iconStateOrder);
Packit Service 5a9772
Packit Service 5a9772
	update_check_flush(context, orderSize);
Packit Service 5a9772
Packit Service 5a9772
	s = update->us;
Packit Service 5a9772
	if (!s)
Packit Service 5a9772
		return FALSE;
Packit Service 5a9772
Packit Service 5a9772
	if (!Stream_EnsureRemainingCapacity(s, orderSize))
Packit Service 5a9772
		return FALSE;
Packit Service 5a9772
Packit Service 5a9772
	/* Write Hdr */
Packit Service 5a9772
	Stream_Write_UINT8(s, controlFlags);             /* Header (1 byte) */
Packit Service 5a9772
	Stream_Write_INT16(s, orderSize);                /* OrderSize (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT32(s, orderInfo->fieldFlags);   /* FieldsPresentFlags (4 bytes) */
Packit Service 5a9772
	Stream_Write_UINT32(s, orderInfo->windowId);     /* WindowID (4 bytes) */
Packit Service 5a9772
	Stream_Write_UINT32(s, orderInfo->notifyIconId); /* NotifyIconId (4 bytes) */
Packit Service 5a9772
Packit Service 5a9772
	/* Write body */
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_VERSION) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		versionFieldPresent = TRUE;
Packit Service 5a9772
		Stream_Write_UINT32(s, iconStateOrder->version);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_TIP) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_UINT16(s, iconStateOrder->toolTip.length);
Packit Service 5a9772
		Stream_Write(s, iconStateOrder->toolTip.string, iconStateOrder->toolTip.length);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_INFO_TIP) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		NOTIFY_ICON_INFOTIP infoTip = iconStateOrder->infoTip;
Packit Service 5a9772
Packit Service 5a9772
		/* info tip should not be sent when version is 0 */
Packit Service 5a9772
		if (versionFieldPresent && iconStateOrder->version == 0)
Packit Service 5a9772
			return FALSE;
Packit Service 5a9772
Packit Service 5a9772
		Stream_Write_UINT32(s, infoTip.timeout);     /* Timeout (4 bytes) */
Packit Service 5a9772
		Stream_Write_UINT32(s, infoTip.flags);       /* InfoFlags (4 bytes) */
Packit Service 5a9772
		Stream_Write_UINT16(s, infoTip.text.length); /* InfoTipText (variable) */
Packit Service 5a9772
		Stream_Write(s, infoTip.text.string, infoTip.text.length);
Packit Service 5a9772
		Stream_Write_UINT16(s, infoTip.title.length); /* Title (variable) */
Packit Service 5a9772
		Stream_Write(s, infoTip.title.string, infoTip.title.length);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_FIELD_NOTIFY_STATE) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		/* notify state should not be sent when version is 0 */
Packit Service 5a9772
		if (versionFieldPresent && iconStateOrder->version == 0)
Packit Service 5a9772
			return FALSE;
Packit Service 5a9772
Packit Service 5a9772
		Stream_Write_UINT32(s, iconStateOrder->state);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if ((orderInfo->fieldFlags & WINDOW_ORDER_ICON) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		ICON_INFO iconInfo = iconStateOrder->icon;
Packit Service 5a9772
		Stream_Write_UINT16(s, iconInfo.cacheEntry); /* CacheEntry (2 bytes) */
Packit Service 5a9772
		Stream_Write_UINT8(s, iconInfo.cacheId);     /* CacheId (1 byte) */
Packit Service 5a9772
		Stream_Write_UINT8(s, iconInfo.bpp);         /* Bpp (1 byte) */
Packit Service 5a9772
		Stream_Write_UINT16(s, iconInfo.width);      /* Width (2 bytes) */
Packit Service 5a9772
		Stream_Write_UINT16(s, iconInfo.height);     /* Height (2 bytes) */
Packit Service 5a9772
Packit Service 5a9772
		if (iconInfo.bpp <= 8)
Packit Service 5a9772
		{
Packit Service 5a9772
			Stream_Write_UINT16(s, iconInfo.cbColorTable); /* CbColorTable (2 bytes) */
Packit Service 5a9772
		}
Packit Service 5a9772
Packit Service 5a9772
		Stream_Write_UINT16(s, iconInfo.cbBitsMask);             /* CbBitsMask (2 bytes) */
Packit Service 5a9772
		Stream_Write_UINT16(s, iconInfo.cbBitsColor);            /* CbBitsColor (2 bytes) */
Packit Service 5a9772
		Stream_Write(s, iconInfo.bitsMask, iconInfo.cbBitsMask); /* BitsMask (variable) */
Packit Service 5a9772
		orderSize += iconInfo.cbBitsMask;
Packit Service 5a9772
Packit Service 5a9772
		if (iconInfo.bpp <= 8)
Packit Service 5a9772
		{
Packit Service 5a9772
			Stream_Write(s, iconInfo.colorTable, iconInfo.cbColorTable); /* ColorTable (variable) */
Packit Service 5a9772
		}
Packit Service 5a9772
Packit Service 5a9772
		Stream_Write(s, iconInfo.bitsColor, iconInfo.cbBitsColor); /* BitsColor (variable) */
Packit Service 5a9772
	}
Packit Service 5a9772
	else if ((orderInfo->fieldFlags & WINDOW_ORDER_CACHED_ICON) != 0)
Packit Service 5a9772
	{
Packit Service 5a9772
		CACHED_ICON_INFO cachedIcon = iconStateOrder->cachedIcon;
Packit Service 5a9772
		Stream_Write_UINT16(s, cachedIcon.cacheEntry); /* CacheEntry (2 bytes) */
Packit Service 5a9772
		Stream_Write_UINT8(s, cachedIcon.cacheId);     /* CacheId (1 byte) */
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	update->numberOrders++;
Packit Service 5a9772
	return TRUE;
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
static BOOL update_send_notify_icon_create(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
Packit Service 5a9772
                                           const NOTIFY_ICON_STATE_ORDER* iconStateOrder)
Packit Service 5a9772
{
Packit Service 5a9772
	return update_send_new_or_existing_notification_icons(context, orderInfo, iconStateOrder);
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
static BOOL update_send_notify_icon_update(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
Packit Service 5a9772
                                           const NOTIFY_ICON_STATE_ORDER* iconStateOrder)
Packit Service 5a9772
{
Packit Service 5a9772
	return update_send_new_or_existing_notification_icons(context, orderInfo, iconStateOrder);
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
static BOOL update_send_notify_icon_delete(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo)
Packit Service 5a9772
{
Packit Service 5a9772
	wStream* s;
Packit Service 5a9772
	rdpUpdate* update = context->update;
Packit Service 5a9772
	BYTE controlFlags = ORDER_SECONDARY | (ORDER_TYPE_WINDOW << 2);
Packit Service 5a9772
	UINT16 orderSize = 15;
Packit Service 5a9772
	update_check_flush(context, orderSize);
Packit Service 5a9772
Packit Service 5a9772
	s = update->us;
Packit Service 5a9772
Packit Service 5a9772
	if (!s)
Packit Service 5a9772
		return FALSE;
Packit Service 5a9772
Packit Service 5a9772
	/* Write Hdr */
Packit Service 5a9772
	Stream_Write_UINT8(s, controlFlags);             /* Header (1 byte) */
Packit Service 5a9772
	Stream_Write_UINT16(s, orderSize);               /* OrderSize (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT32(s, orderInfo->fieldFlags);   /* FieldsPresentFlags (4 bytes) */
Packit Service 5a9772
	Stream_Write_UINT32(s, orderInfo->windowId);     /* WindowID (4 bytes) */
Packit Service 5a9772
	Stream_Write_UINT32(s, orderInfo->notifyIconId); /* NotifyIconId (4 bytes) */
Packit Service 5a9772
	update->numberOrders++;
Packit Service 5a9772
	return TRUE;
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
static UINT16 update_calculate_monitored_desktop(const WINDOW_ORDER_INFO* orderInfo,
Packit Service 5a9772
                                                 const MONITORED_DESKTOP_ORDER* monitoredDesktop)
Packit Service 5a9772
{
Packit Service 5a9772
	UINT16 orderSize = 7;
Packit Service 5a9772
Packit Service 5a9772
	if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_DESKTOP_ACTIVE_WND)
Packit Service 5a9772
	{
Packit Service 5a9772
		orderSize += 4;
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_DESKTOP_ZORDER)
Packit Service 5a9772
	{
Packit Service 5a9772
		orderSize += 1 + (4 * monitoredDesktop->numWindowIds);
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	return orderSize;
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
static BOOL update_send_monitored_desktop(rdpContext* context, const WINDOW_ORDER_INFO* orderInfo,
Packit Service 5a9772
                                          const MONITORED_DESKTOP_ORDER* monitoredDesktop)
Packit Service 5a9772
{
Packit Service 5a9772
	UINT32 i;
Packit Service 5a9772
	wStream* s;
Packit Service 5a9772
	rdpUpdate* update = context->update;
Packit Service 5a9772
	BYTE controlFlags = ORDER_SECONDARY | (ORDER_TYPE_WINDOW << 2);
Packit Service 5a9772
	UINT16 orderSize = update_calculate_monitored_desktop(orderInfo, monitoredDesktop);
Packit Service 5a9772
	update_check_flush(context, orderSize);
Packit Service 5a9772
Packit Service 5a9772
	s = update->us;
Packit Service 5a9772
Packit Service 5a9772
	if (!s)
Packit Service 5a9772
		return FALSE;
Packit Service 5a9772
Packit Service 5a9772
	Stream_Write_UINT8(s, controlFlags);           /* Header (1 byte) */
Packit Service 5a9772
	Stream_Write_UINT16(s, orderSize);             /* OrderSize (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT32(s, orderInfo->fieldFlags); /* FieldsPresentFlags (4 bytes) */
Packit Service 5a9772
Packit Service 5a9772
	if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_DESKTOP_ACTIVE_WND)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_UINT32(s, monitoredDesktop->activeWindowId); /* activeWindowId (4 bytes) */
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_DESKTOP_ZORDER)
Packit Service 5a9772
	{
Packit Service 5a9772
		Stream_Write_UINT8(s, monitoredDesktop->numWindowIds); /* numWindowIds (1 byte) */
Packit Service 5a9772
Packit Service 5a9772
		/* windowIds */
Packit Service 5a9772
		for (i = 0; i < monitoredDesktop->numWindowIds; i++)
Packit Service 5a9772
		{
Packit Service 5a9772
			Stream_Write_UINT32(s, monitoredDesktop->windowIds[i]);
Packit Service 5a9772
		}
Packit Service 5a9772
	}
Packit Service 5a9772
Packit Service 5a9772
	update->numberOrders++;
Packit Service 5a9772
	return TRUE;
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
static BOOL update_send_non_monitored_desktop(rdpContext* context,
Packit Service 5a9772
                                              const WINDOW_ORDER_INFO* orderInfo)
Packit Service 5a9772
{
Packit Service 5a9772
	wStream* s;
Packit Service 5a9772
	rdpUpdate* update = context->update;
Packit Service 5a9772
	BYTE controlFlags = ORDER_SECONDARY | (ORDER_TYPE_WINDOW << 2);
Packit Service 5a9772
	UINT16 orderSize = 7;
Packit Service 5a9772
	update_check_flush(context, orderSize);
Packit Service 5a9772
Packit Service 5a9772
	s = update->us;
Packit Service 5a9772
Packit Service 5a9772
	if (!s)
Packit Service 5a9772
		return FALSE;
Packit Service 5a9772
Packit Service 5a9772
	Stream_Write_UINT8(s, controlFlags);           /* Header (1 byte) */
Packit Service 5a9772
	Stream_Write_UINT16(s, orderSize);             /* OrderSize (2 bytes) */
Packit Service 5a9772
	Stream_Write_UINT32(s, orderInfo->fieldFlags); /* FieldsPresentFlags (4 bytes) */
Packit Service 5a9772
	update->numberOrders++;
Packit Service 5a9772
	return TRUE;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
void update_register_server_callbacks(rdpUpdate* update)
Packit 1fb8d4
{
Packit Service 5a9772
	update->BeginPaint = _update_begin_paint;
Packit Service 5a9772
	update->EndPaint = _update_end_paint;
Packit 1fb8d4
	update->SetBounds = update_set_bounds;
Packit 1fb8d4
	update->Synchronize = update_send_synchronize;
Packit 1fb8d4
	update->DesktopResize = update_send_desktop_resize;
Packit 1fb8d4
	update->BitmapUpdate = update_send_bitmap_update;
Packit 1fb8d4
	update->SurfaceBits = update_send_surface_bits;
Packit 1fb8d4
	update->SurfaceFrameMarker = update_send_surface_frame_marker;
Packit 1fb8d4
	update->SurfaceCommand = update_send_surface_command;
Packit 1fb8d4
	update->SurfaceFrameBits = update_send_surface_frame_bits;
Packit 1fb8d4
	update->PlaySound = update_send_play_sound;
Packit 1fb8d4
	update->SetKeyboardIndicators = update_send_set_keyboard_indicators;
Packit 1fb8d4
	update->SetKeyboardImeStatus = update_send_set_keyboard_ime_status;
Packit 1fb8d4
	update->SaveSessionInfo = rdp_send_save_session_info;
Packit Service 5a9772
	update->ServerStatusInfo = rdp_send_server_status_info;
Packit 1fb8d4
	update->primary->DstBlt = update_send_dstblt;
Packit 1fb8d4
	update->primary->PatBlt = update_send_patblt;
Packit 1fb8d4
	update->primary->ScrBlt = update_send_scrblt;
Packit 1fb8d4
	update->primary->OpaqueRect = update_send_opaque_rect;
Packit 1fb8d4
	update->primary->LineTo = update_send_line_to;
Packit 1fb8d4
	update->primary->MemBlt = update_send_memblt;
Packit 1fb8d4
	update->primary->GlyphIndex = update_send_glyph_index;
Packit 1fb8d4
	update->secondary->CacheBitmap = update_send_cache_bitmap;
Packit 1fb8d4
	update->secondary->CacheBitmapV2 = update_send_cache_bitmap_v2;
Packit 1fb8d4
	update->secondary->CacheBitmapV3 = update_send_cache_bitmap_v3;
Packit 1fb8d4
	update->secondary->CacheColorTable = update_send_cache_color_table;
Packit 1fb8d4
	update->secondary->CacheGlyph = update_send_cache_glyph;
Packit 1fb8d4
	update->secondary->CacheGlyphV2 = update_send_cache_glyph_v2;
Packit 1fb8d4
	update->secondary->CacheBrush = update_send_cache_brush;
Packit Service 5a9772
	update->altsec->CreateOffscreenBitmap = update_send_create_offscreen_bitmap_order;
Packit 1fb8d4
	update->altsec->SwitchSurface = update_send_switch_surface_order;
Packit 1fb8d4
	update->pointer->PointerSystem = update_send_pointer_system;
Packit 1fb8d4
	update->pointer->PointerPosition = update_send_pointer_position;
Packit 1fb8d4
	update->pointer->PointerColor = update_send_pointer_color;
Packit Service 5a9772
	update->pointer->PointerLarge = update_send_pointer_large;
Packit 1fb8d4
	update->pointer->PointerNew = update_send_pointer_new;
Packit 1fb8d4
	update->pointer->PointerCached = update_send_pointer_cached;
Packit Service 5a9772
	update->window->WindowCreate = update_send_window_create;
Packit Service 5a9772
	update->window->WindowUpdate = update_send_window_update;
Packit Service 5a9772
	update->window->WindowIcon = update_send_window_icon;
Packit Service 5a9772
	update->window->WindowCachedIcon = update_send_window_cached_icon;
Packit Service 5a9772
	update->window->WindowDelete = update_send_window_delete;
Packit Service 5a9772
	update->window->NotifyIconCreate = update_send_notify_icon_create;
Packit Service 5a9772
	update->window->NotifyIconUpdate = update_send_notify_icon_update;
Packit Service 5a9772
	update->window->NotifyIconDelete = update_send_notify_icon_delete;
Packit Service 5a9772
	update->window->MonitoredDesktop = update_send_monitored_desktop;
Packit Service 5a9772
	update->window->NonMonitoredDesktop = update_send_non_monitored_desktop;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
void update_register_client_callbacks(rdpUpdate* update)
Packit 1fb8d4
{
Packit 1fb8d4
	update->RefreshRect = update_send_refresh_rect;
Packit 1fb8d4
	update->SuppressOutput = update_send_suppress_output;
Packit 1fb8d4
	update->SurfaceFrameAcknowledge = update_send_frame_acknowledge;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
int update_process_messages(rdpUpdate* update)
Packit 1fb8d4
{
Packit 1fb8d4
	return update_message_queue_process_pending_messages(update);
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
static void update_free_queued_message(void* obj)
Packit 1fb8d4
{
Packit 1fb8d4
	wMessage* msg = (wMessage*)obj;
Packit 1fb8d4
	update_message_queue_free_message(msg);
Packit 1fb8d4
}
Packit 1fb8d4
Packit Service 5a9772
void update_free_window_state(WINDOW_STATE_ORDER* window_state)
Packit 1fb8d4
{
Packit 1fb8d4
	if (!window_state)
Packit 1fb8d4
		return;
Packit 1fb8d4
Packit Service 5a9772
	free(window_state->OverlayDescription.string);
Packit 1fb8d4
	free(window_state->titleInfo.string);
Packit 1fb8d4
	free(window_state->windowRects);
Packit 1fb8d4
	free(window_state->visibilityRects);
Packit Service 5a9772
	memset(window_state, 0, sizeof(WINDOW_STATE_ORDER));
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
rdpUpdate* update_new(rdpRdp* rdp)
Packit 1fb8d4
{
Packit Service 5a9772
	const wObject cb = { NULL, NULL, NULL, update_free_queued_message, NULL };
Packit 1fb8d4
	rdpUpdate* update;
Packit 1fb8d4
	OFFSCREEN_DELETE_LIST* deleteList;
Packit Service 5a9772
	WINPR_UNUSED(rdp);
Packit Service 5a9772
	update = (rdpUpdate*)calloc(1, sizeof(rdpUpdate));
Packit 1fb8d4
Packit 1fb8d4
	if (!update)
Packit 1fb8d4
		return NULL;
Packit 1fb8d4
Packit 1fb8d4
	update->log = WLog_Get("com.freerdp.core.update");
Packit Service 5a9772
	InitializeCriticalSection(&(update->mux));
Packit Service 5a9772
	update->pointer = (rdpPointerUpdate*)calloc(1, sizeof(rdpPointerUpdate));
Packit 1fb8d4
Packit 1fb8d4
	if (!update->pointer)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit Service 5a9772
	update->primary = (rdpPrimaryUpdate*)calloc(1, sizeof(rdpPrimaryUpdate));
Packit 1fb8d4
Packit 1fb8d4
	if (!update->primary)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit Service 5a9772
	update->secondary = (rdpSecondaryUpdate*)calloc(1, sizeof(rdpSecondaryUpdate));
Packit 1fb8d4
Packit 1fb8d4
	if (!update->secondary)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit Service 5a9772
	update->altsec = (rdpAltSecUpdate*)calloc(1, sizeof(rdpAltSecUpdate));
Packit 1fb8d4
Packit 1fb8d4
	if (!update->altsec)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit Service 5a9772
	update->window = (rdpWindowUpdate*)calloc(1, sizeof(rdpWindowUpdate));
Packit 1fb8d4
Packit 1fb8d4
	if (!update->window)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	deleteList = &(update->altsec->create_offscreen_bitmap.deleteList);
Packit 1fb8d4
	deleteList->sIndices = 64;
Packit 1fb8d4
	deleteList->indices = calloc(deleteList->sIndices, 2);
Packit 1fb8d4
Packit 1fb8d4
	if (!deleteList->indices)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	deleteList->cIndices = 0;
Packit 1fb8d4
	update->SuppressOutput = update_send_suppress_output;
Packit 1fb8d4
	update->initialState = TRUE;
Packit Service 5a9772
	update->autoCalculateBitmapData = TRUE;
Packit 1fb8d4
	update->queue = MessageQueue_New(&cb;;
Packit 1fb8d4
Packit 1fb8d4
	if (!update->queue)
Packit 1fb8d4
		goto fail;
Packit 1fb8d4
Packit 1fb8d4
	return update;
Packit 1fb8d4
fail:
Packit 1fb8d4
	update_free(update);
Packit 1fb8d4
	return NULL;
Packit 1fb8d4
}
Packit 1fb8d4
Packit 1fb8d4
void update_free(rdpUpdate* update)
Packit 1fb8d4
{
Packit 1fb8d4
	if (update != NULL)
Packit 1fb8d4
	{
Packit 1fb8d4
		OFFSCREEN_DELETE_LIST* deleteList = &(update->altsec->create_offscreen_bitmap.deleteList);
Packit 1fb8d4
Packit 1fb8d4
		if (deleteList)
Packit 1fb8d4
			free(deleteList->indices);
Packit 1fb8d4
Packit 1fb8d4
		free(update->pointer);
Packit 1fb8d4
Packit 1fb8d4
		if (update->primary)
Packit 1fb8d4
		{
Packit 1fb8d4
			free(update->primary->polyline.points);
Packit 1fb8d4
			free(update->primary->polygon_sc.points);
Packit 1fb8d4
			free(update->primary->fast_glyph.glyphData.aj);
Packit 1fb8d4
			free(update->primary);
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		free(update->secondary);
Packit 1fb8d4
		free(update->altsec);
Packit 1fb8d4
Packit 1fb8d4
		if (update->window)
Packit 1fb8d4
		{
Packit 1fb8d4
			free(update->window);
Packit 1fb8d4
		}
Packit 1fb8d4
Packit 1fb8d4
		MessageQueue_Free(update->queue);
Packit Service 5a9772
		DeleteCriticalSection(&update->mux);
Packit 1fb8d4
		free(update);
Packit 1fb8d4
	}
Packit 1fb8d4
}
Packit Service 5a9772
Packit Service 5a9772
BOOL update_begin_paint(rdpUpdate* update)
Packit Service 5a9772
{
Packit Service 5a9772
	if (!update)
Packit Service 5a9772
		return FALSE;
Packit Service 5a9772
Packit Service 5a9772
	EnterCriticalSection(&update->mux);
Packit Service 5a9772
Packit Service 5a9772
	if (!update->BeginPaint)
Packit Service 5a9772
		return TRUE;
Packit Service 5a9772
Packit Service 5a9772
	return update->BeginPaint(update->context);
Packit Service 5a9772
}
Packit Service 5a9772
Packit Service 5a9772
BOOL update_end_paint(rdpUpdate* update)
Packit Service 5a9772
{
Packit Service 5a9772
	BOOL rc = FALSE;
Packit Service 5a9772
Packit Service 5a9772
	if (!update)
Packit Service 5a9772
		return FALSE;
Packit Service 5a9772
Packit Service 5a9772
	if (update->EndPaint)
Packit Service 5a9772
		rc = update->EndPaint(update->context);
Packit Service 5a9772
Packit Service 5a9772
	LeaveCriticalSection(&update->mux);
Packit Service 5a9772
	return rc;
Packit Service 5a9772
}