|
|
@ -169,7 +169,7 @@ namespace pnNetCli { |
|
|
|
//============================================================================
|
|
|
|
//============================================================================
|
|
|
|
static void PutBufferOnWire (NetCli * cli, void * data, unsigned bytes) { |
|
|
|
static void PutBufferOnWire (NetCli * cli, void * data, unsigned bytes) { |
|
|
|
|
|
|
|
|
|
|
|
uint8_t * temp, * heap = NULL; |
|
|
|
uint8_t * temp = NULL; |
|
|
|
|
|
|
|
|
|
|
|
#ifndef PLASMA_EXTERNAL_RELEASE |
|
|
|
#ifndef PLASMA_EXTERNAL_RELEASE |
|
|
|
// Write to the netlog
|
|
|
|
// Write to the netlog
|
|
|
@ -189,13 +189,7 @@ static void PutBufferOnWire (NetCli * cli, void * data, unsigned bytes) { |
|
|
|
#endif // PLASMA_EXTERNAL_RELEASE
|
|
|
|
#endif // PLASMA_EXTERNAL_RELEASE
|
|
|
|
|
|
|
|
|
|
|
|
if (cli->mode == kNetCliModeEncrypted && cli->cryptOut) { |
|
|
|
if (cli->mode == kNetCliModeEncrypted && cli->cryptOut) { |
|
|
|
// Encrypt data...
|
|
|
|
temp = (uint8_t *)malloc(bytes); |
|
|
|
if (bytes <= 2048) |
|
|
|
|
|
|
|
// uint8_t count is small, use stack-based buffer
|
|
|
|
|
|
|
|
temp = ALLOCA(uint8_t, bytes); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
// uint8_t count is large, use heap-based buffer
|
|
|
|
|
|
|
|
temp = heap = (uint8_t *)malloc(bytes); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MemCopy(temp, data, bytes); |
|
|
|
MemCopy(temp, data, bytes); |
|
|
|
CryptEncrypt(cli->cryptOut, bytes, temp); |
|
|
|
CryptEncrypt(cli->cryptOut, bytes, temp); |
|
|
@ -205,7 +199,7 @@ static void PutBufferOnWire (NetCli * cli, void * data, unsigned bytes) { |
|
|
|
AsyncSocketSend(cli->sock, data, bytes); |
|
|
|
AsyncSocketSend(cli->sock, data, bytes); |
|
|
|
|
|
|
|
|
|
|
|
// free heap buffer (if any)
|
|
|
|
// free heap buffer (if any)
|
|
|
|
free(heap); |
|
|
|
free(temp); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//============================================================================
|
|
|
@ -295,7 +289,7 @@ static void BufferedSendData ( |
|
|
|
case kNetMsgFieldInteger: { |
|
|
|
case kNetMsgFieldInteger: { |
|
|
|
const unsigned count = cmd->count ? cmd->count : 1; |
|
|
|
const unsigned count = cmd->count ? cmd->count : 1; |
|
|
|
const unsigned bytes = cmd->size * count; |
|
|
|
const unsigned bytes = cmd->size * count; |
|
|
|
void * temp = ALLOCA(uint8_t, bytes); |
|
|
|
void * temp = malloc(bytes); |
|
|
|
|
|
|
|
|
|
|
|
if (count == 1) |
|
|
|
if (count == 1) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -328,6 +322,8 @@ static void BufferedSendData ( |
|
|
|
|
|
|
|
|
|
|
|
// Write values to send buffer
|
|
|
|
// Write values to send buffer
|
|
|
|
AddToSendBuffer(cli, bytes, temp); |
|
|
|
AddToSendBuffer(cli, bytes, temp); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
free(temp); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
@ -1112,15 +1108,10 @@ bool NetCliDispatch ( |
|
|
|
do { |
|
|
|
do { |
|
|
|
if (cli->mode == kNetCliModeEncrypted) { |
|
|
|
if (cli->mode == kNetCliModeEncrypted) { |
|
|
|
// Decrypt data...
|
|
|
|
// Decrypt data...
|
|
|
|
uint8_t * temp, * heap = NULL; |
|
|
|
uint8_t * temp = NULL; |
|
|
|
|
|
|
|
|
|
|
|
if (cli->cryptIn) { |
|
|
|
if (cli->cryptIn) { |
|
|
|
if (bytes <= 2048) |
|
|
|
temp = (uint8_t *)malloc(bytes); |
|
|
|
// uint8_t count is small, use stack-based buffer
|
|
|
|
|
|
|
|
temp = ALLOCA(uint8_t, bytes); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
// uint8_t count is large, use heap-based buffer
|
|
|
|
|
|
|
|
temp = heap = (uint8_t *)malloc(bytes); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MemCopy(temp, data, bytes); |
|
|
|
MemCopy(temp, data, bytes); |
|
|
|
CryptDecrypt(cli->cryptIn, bytes, temp); |
|
|
|
CryptDecrypt(cli->cryptIn, bytes, temp); |
|
|
@ -1153,7 +1144,7 @@ bool NetCliDispatch ( |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
// free heap buffer (if any)
|
|
|
|
// free heap buffer (if any)
|
|
|
|
free(heap); |
|
|
|
free(temp); |
|
|
|
|
|
|
|
|
|
|
|
cli->input.Compact(); |
|
|
|
cli->input.Compact(); |
|
|
|
return cli->recvDispatch; |
|
|
|
return cli->recvDispatch; |
|
|
|