return TRUE;
}
-static int fastpath_recv_update(rdpFastPath* fastpath, BYTE updateCode, UINT32 size, wStream* s)
+static int fastpath_recv_update(rdpFastPath* fastpath, BYTE updateCode, wStream* s)
{
int status = 0;
rdpUpdate* update;
context = update->context;
pointer = update->pointer;
#ifdef WITH_DEBUG_RDP
- DEBUG_RDP("recv Fast-Path %s Update (0x%02"PRIX8"), length:%"PRIu32"",
+ DEBUG_RDP("recv Fast-Path %s Update (0x%02"PRIX8"), length:%"PRIuz"",
updateCode < ARRAYSIZE(FASTPATH_UPDATETYPE_STRINGS) ? FASTPATH_UPDATETYPE_STRINGS[updateCode] :
- "???", updateCode, size);
+ "???", updateCode, Stream_GetLength(s));
#endif
switch (updateCode)
int status;
UINT16 size;
rdpRdp* rdp;
- size_t next_pos;
- wStream* cs;
int bulkStatus;
- UINT32 totalSize;
BYTE updateCode;
BYTE fragmentation;
BYTE compression;
return -1;
}
- cs = s;
- next_pos = Stream_GetPosition(s) + size;
bulkStatus = bulk_decompress(rdp->bulk, Stream_Pointer(s), size, &pDstData, &DstSize,
compressionFlags);
+ Stream_Seek(s, size);
if (bulkStatus < 0)
{
return -1;
}
- if (bulkStatus > 0)
- {
- /* data was compressed, copy from decompression buffer */
- size = DstSize;
-
- if (!(cs = StreamPool_Take(transport->ReceivePool, DstSize)))
- return -1;
+ if (!Stream_EnsureRemainingCapacity(fastpath->updateData, DstSize))
+ return -1;
- Stream_SetPosition(cs, 0);
- Stream_Write(cs, pDstData, DstSize);
- Stream_SealLength(cs);
- Stream_SetPosition(cs, 0);
- }
+ Stream_Write(fastpath->updateData, pDstData, DstSize);
if (fragmentation == FASTPATH_FRAGMENT_SINGLE)
{
goto out_fail;
}
- totalSize = size;
- status = fastpath_recv_update(fastpath, updateCode, totalSize, cs);
+ Stream_SealLength(fastpath->updateData);
+ Stream_SetPosition(fastpath->updateData, 0);
+ status = fastpath_recv_update(fastpath, updateCode, fastpath->updateData);
+ Stream_SetPosition(fastpath->updateData, 0);
if (status < 0)
{
}
else
{
+ const size_t totalSize = Stream_GetPosition(fastpath->updateData);
+ if (totalSize > transport->settings->MultifragMaxRequestSize)
+ {
+ WLog_ERR(TAG, "Total size (%"PRIuz") exceeds MultifragMaxRequestSize (%"PRIu32")",
+ totalSize, transport->settings->MultifragMaxRequestSize);
+ goto out_fail;
+ }
+
if (fragmentation == FASTPATH_FRAGMENT_FIRST)
{
if (fastpath->fragmentation != -1)
}
fastpath->fragmentation = FASTPATH_FRAGMENT_FIRST;
- totalSize = size;
-
- if (totalSize > transport->settings->MultifragMaxRequestSize)
- {
- WLog_ERR(TAG, "Total size (%"PRIu32") exceeds MultifragMaxRequestSize (%"PRIu32")",
- totalSize, transport->settings->MultifragMaxRequestSize);
- goto out_fail;
- }
-
- if (!(fastpath->updateData = StreamPool_Take(transport->ReceivePool, size)))
- goto out_fail;
- Stream_SetPosition(fastpath->updateData, 0);
- Stream_Copy(cs, fastpath->updateData, size);
+
}
else if (fragmentation == FASTPATH_FRAGMENT_NEXT)
{
}
fastpath->fragmentation = FASTPATH_FRAGMENT_NEXT;
- totalSize = Stream_GetPosition(fastpath->updateData) + size;
-
- if (totalSize > transport->settings->MultifragMaxRequestSize)
- {
- WLog_ERR(TAG, "Total size (%"PRIu32") exceeds MultifragMaxRequestSize (%"PRIu32")",
- totalSize, transport->settings->MultifragMaxRequestSize);
- goto out_fail;
- }
-
- if (!Stream_EnsureCapacity(fastpath->updateData, totalSize))
- {
- WLog_ERR(TAG, "Couldn't re-allocate memory for stream");
- goto out_fail;
- }
-
- Stream_Copy(cs, fastpath->updateData, size);
}
else if (fragmentation == FASTPATH_FRAGMENT_LAST)
{
}
fastpath->fragmentation = -1;
- totalSize = Stream_GetPosition(fastpath->updateData) + size;
- if (totalSize > transport->settings->MultifragMaxRequestSize)
- {
- WLog_ERR(TAG, "Total size (%"PRIu32") exceeds MultifragMaxRequestSize (%"PRIu32")",
- totalSize, transport->settings->MultifragMaxRequestSize);
- goto out_fail;
- }
-
- if (!Stream_EnsureCapacity(fastpath->updateData, totalSize))
- {
- WLog_ERR(TAG, "Couldn't re-allocate memory for stream");
- goto out_fail;
- }
-
- Stream_Copy(cs, fastpath->updateData, size);
Stream_SealLength(fastpath->updateData);
Stream_SetPosition(fastpath->updateData, 0);
- status = fastpath_recv_update(fastpath, updateCode, totalSize, fastpath->updateData);
- Stream_Release(fastpath->updateData);
+ status = fastpath_recv_update(fastpath, updateCode, fastpath->updateData);
+ Stream_SetPosition(fastpath->updateData, 0);
if (status < 0)
{
}
}
- Stream_SetPosition(s, next_pos);
-
- if (cs != s)
- Stream_Release(cs);
-
return status;
out_fail:
- if (cs != s)
- {
- Stream_Release(cs);
- }
-
return -1;
}
fastpath->rdp = rdp;
fastpath->fragmentation = -1;
fastpath->fs = Stream_New(NULL, FASTPATH_MAX_PACKET_SIZE);
+ fastpath->updateData = Stream_New(NULL, FASTPATH_MAX_PACKET_SIZE);
- if (!fastpath->fs)
+ if (!fastpath->fs || !fastpath->updateData)
goto out_free;
return fastpath;
out_free:
- free(fastpath);
+ fastpath_free(fastpath);
return NULL;
}
{
if (fastpath)
{
+ Stream_Free(fastpath->updateData, TRUE);
Stream_Free(fastpath->fs, TRUE);
free(fastpath);
}