mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-15 00:44:19 +09:00
[winpr,stream] Add Stream_ResetPosition
A helper function that does not require return checks, in contrast to Stream_SetPosition, which might fail.
This commit is contained in:
@@ -109,7 +109,7 @@ static void mf_peer_rfx_update(freerdp_peer* client)
|
||||
WINPR_ASSERT(s);
|
||||
|
||||
Stream_Clear(s);
|
||||
Stream_SetPosition(s, 0);
|
||||
Stream_ResetPosition(s);
|
||||
UINT32 x = mfi->invalid.x / mfi->scale;
|
||||
UINT32 y = mfi->invalid.y / mfi->scale;
|
||||
rect.x = 0;
|
||||
|
||||
@@ -172,7 +172,7 @@ static wStream* test_peer_stream_init(testPeerContext* context)
|
||||
WINPR_ASSERT(context->s);
|
||||
|
||||
Stream_Clear(context->s);
|
||||
Stream_SetPosition(context->s, 0);
|
||||
Stream_ResetPosition(context->s);
|
||||
return context->s;
|
||||
}
|
||||
|
||||
@@ -652,7 +652,7 @@ static DWORD WINAPI tf_debug_channel_thread_func(LPVOID arg)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
Stream_SetPosition(s, 0);
|
||||
Stream_ResetPosition(s);
|
||||
|
||||
if (WTSVirtualChannelRead(context->debug_channel, 0, Stream_BufferAs(s, char),
|
||||
(ULONG)Stream_Capacity(s), &BytesReturned) == FALSE)
|
||||
@@ -1108,7 +1108,7 @@ static int hook_peer_write_pdu(rdpTransport* transport, wStream* s)
|
||||
if (rc < 0)
|
||||
goto fail;
|
||||
}
|
||||
Stream_SetPosition(ls, 0);
|
||||
Stream_ResetPosition(ls);
|
||||
}
|
||||
|
||||
fail:
|
||||
|
||||
@@ -113,7 +113,7 @@ void wf_update_encode(wfInfo* wfi)
|
||||
SURFACE_BITS_COMMAND* cmd;
|
||||
wf_info_find_invalid_region(wfi);
|
||||
cmd = &wfi->cmd;
|
||||
Stream_SetPosition(wfi->s, 0);
|
||||
Stream_ResetPosition(wfi->s);
|
||||
wf_info_getScreenData(wfi, &width, &height, &pDataBits, &stride);
|
||||
rect.x = 0;
|
||||
rect.y = 0;
|
||||
|
||||
@@ -334,7 +334,7 @@ static PfChannelResult DynvcTrackerPeekHandleByMode(ChannelStateTracker* tracker
|
||||
trackerState->CurrentDataReceived = 0;
|
||||
|
||||
if (dynChannel->packetReassembly && trackerState->currentPacket)
|
||||
Stream_SetPosition(trackerState->currentPacket, 0);
|
||||
Stream_ResetPosition(trackerState->currentPacket);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -551,7 +551,7 @@ static PfChannelResult DynvcTrackerHandleCmdDATA(ChannelStateTracker* tracker,
|
||||
if (dynChannel->packetReassembly)
|
||||
{
|
||||
if (trackerState->currentPacket)
|
||||
Stream_SetPosition(trackerState->currentPacket, 0);
|
||||
Stream_ResetPosition(trackerState->currentPacket);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -199,8 +199,8 @@ static wStream* rdpdr_get_send_buffer(pf_channel_common_context* rdpdr, UINT16 c
|
||||
{
|
||||
WINPR_ASSERT(rdpdr);
|
||||
WINPR_ASSERT(rdpdr->s);
|
||||
if (!Stream_SetPosition(rdpdr->s, 0))
|
||||
return nullptr;
|
||||
Stream_ResetPosition(rdpdr->s);
|
||||
|
||||
if (!Stream_EnsureCapacity(rdpdr->s, capacity + 4))
|
||||
return nullptr;
|
||||
Stream_Write_UINT16(rdpdr->s, component);
|
||||
@@ -1068,7 +1068,7 @@ static BOOL pf_channel_rdpdr_rewrite_device_list_to(wStream* s, UINT32 fromVersi
|
||||
Stream_Copy(s, clone, cap);
|
||||
Stream_SealLength(clone);
|
||||
|
||||
Stream_SetPosition(clone, 0);
|
||||
Stream_ResetPosition(clone);
|
||||
Stream_SetPosition(s, pos);
|
||||
}
|
||||
|
||||
@@ -1148,7 +1148,7 @@ static BOOL pf_channel_rdpdr_rewrite_device_list(pf_channel_client_context* rdpd
|
||||
const size_t pos = Stream_GetPosition(s);
|
||||
UINT16 component = 0;
|
||||
UINT16 packetid = 0;
|
||||
Stream_SetPosition(s, 0);
|
||||
Stream_ResetPosition(s);
|
||||
|
||||
if (!Stream_CheckAndLogRequiredLengthWLog(rdpdr->log, s, 4))
|
||||
return FALSE;
|
||||
@@ -1381,7 +1381,7 @@ BOOL pf_channel_rdpdr_client_handle(pClientContext* pc, UINT16 channelId, const
|
||||
}
|
||||
s = rdpdr->common.buffer;
|
||||
if (flags & CHANNEL_FLAG_FIRST)
|
||||
Stream_SetPosition(s, 0);
|
||||
Stream_ResetPosition(s);
|
||||
if (!Stream_EnsureRemainingCapacity(s, xsize))
|
||||
{
|
||||
CLIENT_RX_LOG(rdpdr->log, WLOG_ERROR,
|
||||
@@ -1394,7 +1394,7 @@ BOOL pf_channel_rdpdr_client_handle(pClientContext* pc, UINT16 channelId, const
|
||||
return TRUE;
|
||||
|
||||
Stream_SealLength(s);
|
||||
Stream_SetPosition(s, 0);
|
||||
Stream_ResetPosition(s);
|
||||
if (Stream_Length(s) != totalSize)
|
||||
{
|
||||
CLIENT_RX_LOG(rdpdr->log, WLOG_WARN,
|
||||
@@ -1919,7 +1919,7 @@ BOOL pf_channel_rdpdr_server_handle(pServerContext* ps, UINT16 channelId, const
|
||||
s = rdpdr->common.buffer;
|
||||
|
||||
if (flags & CHANNEL_FLAG_FIRST)
|
||||
Stream_SetPosition(s, 0);
|
||||
Stream_ResetPosition(s);
|
||||
|
||||
if (!Stream_EnsureRemainingCapacity(s, xsize))
|
||||
return FALSE;
|
||||
@@ -1929,7 +1929,7 @@ BOOL pf_channel_rdpdr_server_handle(pServerContext* ps, UINT16 channelId, const
|
||||
return TRUE;
|
||||
|
||||
Stream_SealLength(s);
|
||||
Stream_SetPosition(s, 0);
|
||||
Stream_ResetPosition(s);
|
||||
|
||||
if (Stream_Length(s) != totalSize)
|
||||
{
|
||||
|
||||
@@ -84,7 +84,7 @@ static BOOL pf_channel_client_write_iostatus(wStream* out, const SMARTCARD_OPERA
|
||||
WINPR_ASSERT(out);
|
||||
|
||||
pos = Stream_GetPosition(out);
|
||||
Stream_SetPosition(out, 0);
|
||||
Stream_ResetPosition(out);
|
||||
if (!Stream_CheckAndLogRequiredLength(TAG, out, 16))
|
||||
return FALSE;
|
||||
|
||||
|
||||
@@ -209,7 +209,7 @@ class DynChannelState
|
||||
[[nodiscard]] static BOOL drdynvc_try_read_header(wStream* s, uint32_t& channelId, size_t& length)
|
||||
{
|
||||
UINT8 value = 0;
|
||||
Stream_SetPosition(s, 0);
|
||||
Stream_ResetPosition(s);
|
||||
if (Stream_GetRemainingLength(s) < 1)
|
||||
return FALSE;
|
||||
Stream_Read_UINT8(s, value);
|
||||
|
||||
@@ -60,7 +60,7 @@ static BOOL channelTracker_resetCurrentPacket(ChannelStateTracker* tracker)
|
||||
tracker->currentPacket = Stream_New(nullptr, 10ULL * 1024ULL);
|
||||
if (!tracker->currentPacket)
|
||||
return FALSE;
|
||||
Stream_SetPosition(tracker->currentPacket, 0);
|
||||
Stream_ResetPosition(tracker->currentPacket);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -923,7 +923,7 @@ static int pf_client_verify_X509_certificate(freerdp* instance, const BYTE* data
|
||||
|
||||
if (!Stream_EnsureCapacity(pc->remote_pem, length))
|
||||
return 0;
|
||||
Stream_SetPosition(pc->remote_pem, 0);
|
||||
Stream_ResetPosition(pc->remote_pem);
|
||||
|
||||
free(pc->remote_hostname);
|
||||
pc->remote_hostname = nullptr;
|
||||
|
||||
@@ -1601,7 +1601,7 @@ static BOOL shadow_client_send_surface_bits(rdpShadowClient* client, BYTE* pSrcD
|
||||
|
||||
for (size_t i = 0; i < numMessages; i++)
|
||||
{
|
||||
Stream_SetPosition(s, 0);
|
||||
Stream_ResetPosition(s);
|
||||
|
||||
const RFX_MESSAGE* msg = rfx_message_list_get(messages, i);
|
||||
if (!rfx_write_message(encoder->rfx, s, msg))
|
||||
@@ -1642,7 +1642,7 @@ static BOOL shadow_client_send_surface_bits(rdpShadowClient* client, BYTE* pSrcD
|
||||
}
|
||||
|
||||
s = encoder->bs;
|
||||
Stream_SetPosition(s, 0);
|
||||
Stream_ResetPosition(s);
|
||||
pSrcData = &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 4)];
|
||||
if (!nsc_compose_message(encoder->nsc, s, pSrcData, nWidth, nHeight, nSrcStep))
|
||||
return FALSE;
|
||||
|
||||
Reference in New Issue
Block a user