Merge pull request #5285 from akallabeth/urbdrc_preparations
Channel, log debug and semaphore related fixes
This commit is contained in:
commit
37358e81d0
@ -768,14 +768,17 @@ static UINT drdynvc_write_data(drdynvcPlugin* drdynvc, UINT32 ChannelId,
|
||||
if (dataSize == 0)
|
||||
{
|
||||
Stream_SetPosition(data_out, 0);
|
||||
Stream_Write_UINT8(data_out, 0x40 | cbChId);
|
||||
Stream_Write_UINT8(data_out, (CLOSE_REQUEST_PDU << 4) | cbChId);
|
||||
Stream_SetPosition(data_out, pos);
|
||||
status = drdynvc_send(drdynvc, data_out);
|
||||
/* Remove the channel from the active client channel list.
|
||||
* The server MAY send a response, but that is not guaranteed. */
|
||||
dvcman_close_channel(drdynvc->channel_mgr, ChannelId);
|
||||
}
|
||||
else if (dataSize <= CHANNEL_CHUNK_LENGTH - pos)
|
||||
{
|
||||
Stream_SetPosition(data_out, 0);
|
||||
Stream_Write_UINT8(data_out, 0x30 | cbChId);
|
||||
Stream_Write_UINT8(data_out, (DATA_PDU << 4) | cbChId);
|
||||
Stream_SetPosition(data_out, pos);
|
||||
Stream_Write(data_out, data, dataSize);
|
||||
status = drdynvc_send(drdynvc, data_out);
|
||||
@ -786,7 +789,7 @@ static UINT drdynvc_write_data(drdynvcPlugin* drdynvc, UINT32 ChannelId,
|
||||
cbLen = drdynvc_write_variable_uint(data_out, dataSize);
|
||||
pos = Stream_GetPosition(data_out);
|
||||
Stream_SetPosition(data_out, 0);
|
||||
Stream_Write_UINT8(data_out, (UINT8)(0x20 | cbChId | (cbLen << 2)));
|
||||
Stream_Write_UINT8(data_out, (DATA_FIRST_PDU << 4) | cbChId | (cbLen << 2));
|
||||
Stream_SetPosition(data_out, pos);
|
||||
chunkLength = CHANNEL_CHUNK_LENGTH - pos;
|
||||
Stream_Write(data_out, data, chunkLength);
|
||||
@ -808,7 +811,7 @@ static UINT drdynvc_write_data(drdynvcPlugin* drdynvc, UINT32 ChannelId,
|
||||
cbChId = drdynvc_write_variable_uint(data_out, ChannelId);
|
||||
pos = Stream_GetPosition(data_out);
|
||||
Stream_SetPosition(data_out, 0);
|
||||
Stream_Write_UINT8(data_out, 0x30 | cbChId);
|
||||
Stream_Write_UINT8(data_out, (DATA_PDU << 4) | cbChId);
|
||||
Stream_SetPosition(data_out, pos);
|
||||
chunkLength = dataSize;
|
||||
|
||||
@ -1004,7 +1007,7 @@ static UINT drdynvc_process_create_request(drdynvcPlugin* drdynvc, int Sp,
|
||||
return CHANNEL_RC_NO_MEMORY;
|
||||
}
|
||||
|
||||
Stream_Write_UINT8(data_out, (UINT8)(0x10 | cbChId));
|
||||
Stream_Write_UINT8(data_out, (CREATE_REQUEST_PDU << 4) | cbChId);
|
||||
Stream_SetPosition(s, 1);
|
||||
Stream_Copy(s, data_out, pos - 1);
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include <winpr/winpr.h>
|
||||
#include <winpr/wtypes.h>
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#define WINPR_HEXDUMP_LINE_LENGTH 16
|
||||
|
||||
@ -33,8 +34,10 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
WINPR_API void winpr_HexDump(const char* tag, UINT32 lvl, const BYTE* data, int length);
|
||||
WINPR_API void winpr_CArrayDump(const char* tag, UINT32 lvl, const BYTE* data, int length, int width);
|
||||
WINPR_API void winpr_HexDump(const char* tag, UINT32 lvl, const BYTE* data, size_t length);
|
||||
WINPR_API void winpr_HexLogDump(wLog* log, UINT32 lvl, const BYTE* data, size_t length);
|
||||
WINPR_API void winpr_CArrayDump(const char* tag, UINT32 lvl, const BYTE* data, int length,
|
||||
int width);
|
||||
|
||||
WINPR_API char* winpr_BinToHexString(const BYTE* data, int length, BOOL space);
|
||||
|
||||
|
@ -246,11 +246,16 @@ BOOL ReleaseSemaphore(HANDLE hSemaphore, LONG lReleaseCount, LPLONG lpPreviousCo
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
while (lReleaseCount > 0)
|
||||
{
|
||||
#if defined __APPLE__
|
||||
semaphore_signal(*((winpr_sem_t*) semaphore->sem));
|
||||
semaphore_signal(*((winpr_sem_t*) semaphore->sem));
|
||||
#else
|
||||
sem_post((winpr_sem_t*) semaphore->sem);
|
||||
sem_post((winpr_sem_t*) semaphore->sem);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -458,6 +458,7 @@ int HashTable_GetKeys(wHashTable* table, ULONG_PTR** ppKeys)
|
||||
|
||||
iKey = 0;
|
||||
count = table->numOfElements;
|
||||
*ppKeys = NULL;
|
||||
|
||||
if (count < 1)
|
||||
{
|
||||
|
@ -33,44 +33,94 @@
|
||||
|
||||
#include "../log.h"
|
||||
|
||||
void winpr_HexDump(const char* tag, UINT32 level, const BYTE* data, int length)
|
||||
void winpr_HexDump(const char* tag, UINT32 level, const BYTE* data, size_t length)
|
||||
{
|
||||
wLog* log = WLog_Get(tag);
|
||||
winpr_HexLogDump(log, level, data, length);
|
||||
}
|
||||
|
||||
void winpr_HexLogDump(wLog* log, UINT32 lvl, const BYTE* data, size_t length)
|
||||
{
|
||||
const BYTE* p = data;
|
||||
int i, line, offset = 0;
|
||||
size_t blen = 7 + WINPR_HEXDUMP_LINE_LENGTH * 5;
|
||||
size_t i, line, offset = 0;
|
||||
const int maxlen = 20; /* 64bit SIZE_MAX as decimal */
|
||||
/* String line length:
|
||||
* prefix '[1234] '
|
||||
* hexdump '01 02 03 04'
|
||||
* separator ' '
|
||||
* ASIC line 'ab..cd'
|
||||
* zero terminator '\0'
|
||||
*/
|
||||
const size_t blen = ((size_t)maxlen + 3) + (WINPR_HEXDUMP_LINE_LENGTH * 3) + 3 + WINPR_HEXDUMP_LINE_LENGTH + 1;
|
||||
size_t pos = 0;
|
||||
char* buffer = malloc(blen);
|
||||
|
||||
|
||||
char* buffer;
|
||||
|
||||
if (!log || (maxlen < 0))
|
||||
return;
|
||||
|
||||
buffer = malloc(blen);
|
||||
|
||||
if (!buffer)
|
||||
{
|
||||
WLog_ERR(tag, "malloc(%"PRIuz") failed with [%d] %s", blen, errno, strerror(errno));
|
||||
WLog_Print(log, WLOG_ERROR, "malloc(%"PRIuz") failed with [%"PRIuz"] %s", blen, errno,
|
||||
strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
while (offset < length)
|
||||
{
|
||||
pos += trio_snprintf(&buffer[pos], blen - pos, "%04x ", offset);
|
||||
int rc = trio_snprintf(&buffer[pos], blen - pos, "%04"PRIuz" ", offset);
|
||||
|
||||
if (rc < 0)
|
||||
goto fail;
|
||||
|
||||
pos += (size_t)rc;
|
||||
line = length - offset;
|
||||
|
||||
if (line > WINPR_HEXDUMP_LINE_LENGTH)
|
||||
line = WINPR_HEXDUMP_LINE_LENGTH;
|
||||
|
||||
for (i = 0; i < line; i++)
|
||||
pos += trio_snprintf(&buffer[pos], blen - pos, "%02"PRIx8" ", p[i]);
|
||||
{
|
||||
rc = trio_snprintf(&buffer[pos], blen - pos, "%02"PRIx8" ", p[i]);
|
||||
|
||||
if (rc < 0)
|
||||
goto fail;
|
||||
|
||||
pos += (size_t)rc;
|
||||
}
|
||||
|
||||
for (; i < WINPR_HEXDUMP_LINE_LENGTH; i++)
|
||||
pos += trio_snprintf(&buffer[pos], blen - pos, " ");
|
||||
{
|
||||
rc = trio_snprintf(&buffer[pos], blen - pos, " ");
|
||||
|
||||
if (rc < 0)
|
||||
goto fail;
|
||||
|
||||
pos += (size_t)rc;
|
||||
}
|
||||
|
||||
for (i = 0; i < line; i++)
|
||||
pos += trio_snprintf(&buffer[pos], blen - pos, "%c",
|
||||
(p[i] >= 0x20 && p[i] < 0x7F) ? (char) p[i] : '.');
|
||||
{
|
||||
rc = trio_snprintf(&buffer[pos], blen - pos, "%c",
|
||||
(p[i] >= 0x20 && p[i] < 0x7F) ? (char) p[i] : '.');
|
||||
|
||||
WLog_LVL(tag, level, "%s", buffer);
|
||||
if (rc < 0)
|
||||
goto fail;
|
||||
|
||||
pos += (size_t)rc;
|
||||
}
|
||||
|
||||
WLog_Print(log, lvl, "%s", buffer);
|
||||
offset += line;
|
||||
p += line;
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
WLog_Print(log, lvl, "[length=%"PRIuz"] ", length);
|
||||
fail:
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
@ -117,6 +167,7 @@ char* winpr_BinToHexString(const BYTE* data, int length, BOOL space)
|
||||
char bin2hex[] = "0123456789ABCDEF";
|
||||
n = space ? 3 : 2;
|
||||
p = (char*) malloc((length + 1) * n);
|
||||
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user