mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-19 17:53:28 +00:00
IOActive update for size_t vs int for buffer lengths
This commit is contained in:
@@ -87,7 +87,6 @@ int main(int argc, char **argv)
|
|||||||
int retCode = 0;
|
int retCode = 0;
|
||||||
int capabilities = 0;
|
int capabilities = 0;
|
||||||
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
int argvi, argvsz;
|
int argvi, argvsz;
|
||||||
char **argv = (char**)ILibMemory_SmartAllocate(argc * sizeof(void*));
|
char **argv = (char**)ILibMemory_SmartAllocate(argc * sizeof(void*));
|
||||||
@@ -125,7 +124,7 @@ char* crashMemory = ILib_POSIX_InstallCrashHandler(argv[0]);
|
|||||||
|
|
||||||
if (argc > 2 && strcmp(argv[1], "-exec") == 0 && integratedJavaScriptLen == 0)
|
if (argc > 2 && strcmp(argv[1], "-exec") == 0 && integratedJavaScriptLen == 0)
|
||||||
{
|
{
|
||||||
integratedJavaScript = ILibString_Copy(argv[2], -1);
|
integratedJavaScript = ILibString_Copy(argv[2], 0);
|
||||||
integratedJavaScriptLen = (int)strnlen_s(integratedJavaScript, sizeof(ILibScratchPad));
|
integratedJavaScriptLen = (int)strnlen_s(integratedJavaScript, sizeof(ILibScratchPad));
|
||||||
}
|
}
|
||||||
if (argc > 2 && strcmp(argv[1], "-b64exec") == 0)
|
if (argc > 2 && strcmp(argv[1], "-b64exec") == 0)
|
||||||
@@ -136,12 +135,12 @@ char* crashMemory = ILib_POSIX_InstallCrashHandler(argv[0]);
|
|||||||
if (argc > 1 && strcasecmp(argv[1], "-nodeid") == 0 && integratedJavaScriptLen == 0)
|
if (argc > 1 && strcasecmp(argv[1], "-nodeid") == 0 && integratedJavaScriptLen == 0)
|
||||||
{
|
{
|
||||||
char script[] = "console.log(require('_agentNodeId')());process.exit();";
|
char script[] = "console.log(require('_agentNodeId')());process.exit();";
|
||||||
integratedJavaScript = ILibString_Copy(script, (int)sizeof(script) - 1);
|
integratedJavaScript = ILibString_Copy(script, sizeof(script) - 1);
|
||||||
integratedJavaScriptLen = (int)sizeof(script) - 1;
|
integratedJavaScriptLen = (int)sizeof(script) - 1;
|
||||||
}
|
}
|
||||||
if (argc > 1 && strcmp(argv[1], "-daemon") == 0 && integratedJavaScriptLen == 0)
|
if (argc > 1 && strcmp(argv[1], "-daemon") == 0 && integratedJavaScriptLen == 0)
|
||||||
{
|
{
|
||||||
integratedJavaScript = ILibString_Copy("require('daemon').agent();", -1);
|
integratedJavaScript = ILibString_Copy("require('daemon').agent();", 0);
|
||||||
integratedJavaScriptLen = (int)strnlen_s(integratedJavaScript, sizeof(ILibScratchPad));
|
integratedJavaScriptLen = (int)strnlen_s(integratedJavaScript, sizeof(ILibScratchPad));
|
||||||
}
|
}
|
||||||
if (argc > 1 && strcasecmp(argv[1], "-licenses") == 0)
|
if (argc > 1 && strcasecmp(argv[1], "-licenses") == 0)
|
||||||
|
|||||||
@@ -1219,7 +1219,7 @@ void* kvm_server_mainloop(void* parm)
|
|||||||
return (void*)0;
|
return (void*)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void kvm_relay_readSink(ILibProcessPipe_Pipe sender, char *buffer, int bufferLen, int* bytesConsumed)
|
void kvm_relay_readSink(ILibProcessPipe_Pipe sender, char *buffer, size_t bufferLen, size_t* bytesConsumed)
|
||||||
{
|
{
|
||||||
ILibKVM_WriteHandler writeHandler = (ILibKVM_WriteHandler)((void**)ILibMemory_Extra(sender))[0];
|
ILibKVM_WriteHandler writeHandler = (ILibKVM_WriteHandler)((void**)ILibMemory_Extra(sender))[0];
|
||||||
void *reserved = ((void**)ILibMemory_Extra(sender))[1];
|
void *reserved = ((void**)ILibMemory_Extra(sender))[1];
|
||||||
|
|||||||
@@ -635,7 +635,7 @@ void kvm_relay_ExitHandler(ILibProcessPipe_Process sender, int exitCode, void* u
|
|||||||
UNREFERENCED_PARAMETER(exitCode);
|
UNREFERENCED_PARAMETER(exitCode);
|
||||||
UNREFERENCED_PARAMETER(user);
|
UNREFERENCED_PARAMETER(user);
|
||||||
}
|
}
|
||||||
void kvm_relay_StdOutHandler(ILibProcessPipe_Process sender, char *buffer, int bufferLen, int* bytesConsumed, void* user)
|
void kvm_relay_StdOutHandler(ILibProcessPipe_Process sender, char *buffer, size_t bufferLen, size_t* bytesConsumed, void* user)
|
||||||
{
|
{
|
||||||
unsigned short size = 0;
|
unsigned short size = 0;
|
||||||
UNREFERENCED_PARAMETER(sender);
|
UNREFERENCED_PARAMETER(sender);
|
||||||
@@ -673,7 +673,7 @@ void kvm_relay_StdOutHandler(ILibProcessPipe_Process sender, char *buffer, int b
|
|||||||
}
|
}
|
||||||
*bytesConsumed = 0;
|
*bytesConsumed = 0;
|
||||||
}
|
}
|
||||||
void kvm_relay_StdErrHandler(ILibProcessPipe_Process sender, char *buffer, int bufferLen, int* bytesConsumed, void* user)
|
void kvm_relay_StdErrHandler(ILibProcessPipe_Process sender, char *buffer, size_t bufferLen, size_t* bytesConsumed, void* user)
|
||||||
{
|
{
|
||||||
//KVMDebugLog *log = (KVMDebugLog*)buffer;
|
//KVMDebugLog *log = (KVMDebugLog*)buffer;
|
||||||
|
|
||||||
|
|||||||
@@ -1144,7 +1144,7 @@ void kvm_relay_ExitHandler(ILibProcessPipe_Process sender, int exitCode, void* u
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void kvm_relay_StdOutHandler(ILibProcessPipe_Process sender, char *buffer, int bufferLen, int* bytesConsumed, void* user)
|
void kvm_relay_StdOutHandler(ILibProcessPipe_Process sender, char *buffer, size_t bufferLen, size_t* bytesConsumed, void* user)
|
||||||
{
|
{
|
||||||
unsigned short size = 0;
|
unsigned short size = 0;
|
||||||
UNREFERENCED_PARAMETER(sender);
|
UNREFERENCED_PARAMETER(sender);
|
||||||
@@ -1160,7 +1160,7 @@ void kvm_relay_StdOutHandler(ILibProcessPipe_Process sender, char *buffer, int b
|
|||||||
if (bufferLen >= (8 + (int)ntohl(((unsigned int*)(buffer))[1])))
|
if (bufferLen >= (8 + (int)ntohl(((unsigned int*)(buffer))[1])))
|
||||||
{
|
{
|
||||||
*bytesConsumed = 8 + (int)ntohl(((unsigned int*)(buffer))[1]);
|
*bytesConsumed = 8 + (int)ntohl(((unsigned int*)(buffer))[1]);
|
||||||
writeHandler(buffer, *bytesConsumed, reserved);
|
writeHandler(buffer, (int)*bytesConsumed, reserved);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1178,7 +1178,7 @@ void kvm_relay_StdOutHandler(ILibProcessPipe_Process sender, char *buffer, int b
|
|||||||
}
|
}
|
||||||
*bytesConsumed = 0;
|
*bytesConsumed = 0;
|
||||||
}
|
}
|
||||||
void kvm_relay_StdErrHandler(ILibProcessPipe_Process sender, char *buffer, int bufferLen, int* bytesConsumed, void* user)
|
void kvm_relay_StdErrHandler(ILibProcessPipe_Process sender, char *buffer, size_t bufferLen, size_t* bytesConsumed, void* user)
|
||||||
{
|
{
|
||||||
KVMDebugLog *log = (KVMDebugLog*)buffer;
|
KVMDebugLog *log = (KVMDebugLog*)buffer;
|
||||||
|
|
||||||
@@ -1300,4 +1300,200 @@ void kvm_cleanup()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////
|
||||||
|
//// Desktop Duplication API KVM
|
||||||
|
////
|
||||||
|
//#include <d3d11.h>
|
||||||
|
//#include <dxgi1_2.h>
|
||||||
|
//
|
||||||
|
//typedef struct D3D11_Functions
|
||||||
|
//{
|
||||||
|
// HRESULT(*D3D11CreateDevice)(
|
||||||
|
// IDXGIAdapter *pAdapter,
|
||||||
|
// D3D_DRIVER_TYPE DriverType,
|
||||||
|
// HMODULE Software,
|
||||||
|
// UINT Flags,
|
||||||
|
// const D3D_FEATURE_LEVEL *pFeatureLevels,
|
||||||
|
// UINT FeatureLevels,
|
||||||
|
// UINT SDKVersion,
|
||||||
|
// ID3D11Device **ppDevice,
|
||||||
|
// D3D_FEATURE_LEVEL *pFeatureLevel,
|
||||||
|
// ID3D11DeviceContext **ppImmediateContext
|
||||||
|
// );
|
||||||
|
//}D3D11_Functions;
|
||||||
|
|
||||||
|
|
||||||
|
//void DD_Init()
|
||||||
|
//{
|
||||||
|
//int i;
|
||||||
|
//HRESULT hr;
|
||||||
|
//ID3D11Device* m_Device;
|
||||||
|
//ID3D11DeviceContext* m_DeviceContext;
|
||||||
|
//IDXGIFactory2* m_Factory;
|
||||||
|
//DWORD m_OcclusionCookie;
|
||||||
|
//DXGI_OUTDUPL_DESC lOutputDuplDesc;
|
||||||
|
//ID3D11Texture2D *lGDIImage;
|
||||||
|
//ID3D11Texture2D *desktopImage;
|
||||||
|
//ID3D11Texture2D *destinationImage;
|
||||||
|
|
||||||
|
//DXGI_OUTDUPL_FRAME_INFO lFrameInfo;
|
||||||
|
//IDXGIResource *lDesktopResource;
|
||||||
|
|
||||||
|
//D3D11_Functions funcs;
|
||||||
|
|
||||||
|
//HMODULE _D3D = NULL;
|
||||||
|
//if ((_D3D = LoadLibraryExA((LPCSTR)"D3D11.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32)) != NULL)
|
||||||
|
//{
|
||||||
|
// (FARPROC)funcs.D3D11CreateDevice = GetProcAddress(_D3D, "D3D11CreateDevice");
|
||||||
|
//}
|
||||||
|
|
||||||
|
//D3D_DRIVER_TYPE DriverTypes[] =
|
||||||
|
//{
|
||||||
|
// D3D_DRIVER_TYPE_HARDWARE,
|
||||||
|
// D3D_DRIVER_TYPE_WARP,
|
||||||
|
// D3D_DRIVER_TYPE_REFERENCE,
|
||||||
|
//};
|
||||||
|
//UINT NumDriverTypes = ARRAYSIZE(DriverTypes);
|
||||||
|
|
||||||
|
//// Feature levels supported
|
||||||
|
//D3D_FEATURE_LEVEL FeatureLevels[] =
|
||||||
|
//{
|
||||||
|
// D3D_FEATURE_LEVEL_11_0,
|
||||||
|
// D3D_FEATURE_LEVEL_10_1,
|
||||||
|
// D3D_FEATURE_LEVEL_10_0,
|
||||||
|
// D3D_FEATURE_LEVEL_9_1
|
||||||
|
//};
|
||||||
|
//UINT NumFeatureLevels = ARRAYSIZE(FeatureLevels);
|
||||||
|
//D3D_FEATURE_LEVEL FeatureLevel;
|
||||||
|
|
||||||
|
//// Create device
|
||||||
|
//for (UINT DriverTypeIndex = 0; DriverTypeIndex < NumDriverTypes; ++DriverTypeIndex)
|
||||||
|
//{
|
||||||
|
// hr = funcs.D3D11CreateDevice(NULL, DriverTypes[DriverTypeIndex], NULL, 0, FeatureLevels, NumFeatureLevels, D3D11_SDK_VERSION, &m_Device, &FeatureLevel, &m_DeviceContext);
|
||||||
|
// if (SUCCEEDED(hr))
|
||||||
|
// {
|
||||||
|
// // Device creation succeeded, no need to loop anymore
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
//if (FAILED(hr))
|
||||||
|
//{
|
||||||
|
// DebugBreak();
|
||||||
|
//}
|
||||||
|
|
||||||
|
//// Get DXGI factory
|
||||||
|
//IDXGIDevice* DxgiDevice = NULL;
|
||||||
|
//hr = m_Device->lpVtbl->QueryInterface(m_Device, &IID_IDXGIDevice, (void**)&DxgiDevice);
|
||||||
|
//if (FAILED(hr))
|
||||||
|
//{
|
||||||
|
// DebugBreak();
|
||||||
|
//}
|
||||||
|
|
||||||
|
//IDXGIAdapter* DxgiAdapter = NULL;
|
||||||
|
//hr = DxgiDevice->lpVtbl->GetParent(DxgiDevice, &IID_IDXGIAdapter, (void**)&DxgiAdapter);
|
||||||
|
//DxgiDevice->lpVtbl->Release(DxgiDevice);
|
||||||
|
//DxgiDevice = NULL;
|
||||||
|
//if (FAILED(hr))
|
||||||
|
//{
|
||||||
|
// DebugBreak();
|
||||||
|
//}
|
||||||
|
|
||||||
|
//hr = DxgiAdapter->lpVtbl->GetParent(DxgiAdapter, &IID_IDXGIFactory2, (void**)&m_Factory);
|
||||||
|
//DxgiAdapter->lpVtbl->Release(DxgiAdapter);
|
||||||
|
//DxgiAdapter = NULL;
|
||||||
|
//if (FAILED(hr))
|
||||||
|
//{
|
||||||
|
// DebugBreak();
|
||||||
|
// //return ProcessFailure(m_Device, L"Failed to get parent DXGI Factory", L"Error", hr, SystemTransitionsExpectedErrors);
|
||||||
|
//}
|
||||||
|
|
||||||
|
//IDXGIOutput1 *DxgiOutput1;
|
||||||
|
//hr = m_Device->lpVtbl->QueryInterface(m_Device, &IID_IDXGIOutput, (void**)&DxgiOutput1);
|
||||||
|
//if (FAILED(hr))
|
||||||
|
//{
|
||||||
|
// DebugBreak();
|
||||||
|
//}
|
||||||
|
|
||||||
|
//IDXGIOutputDuplication *dupl = NULL;
|
||||||
|
//DxgiOutput1->lpVtbl->DuplicateOutput(DxgiOutput1, m_Device, &dupl);
|
||||||
|
|
||||||
|
//// Create GUI drawing texture
|
||||||
|
//dupl->lpVtbl->GetDesc(dupl, &lOutputDuplDesc);
|
||||||
|
|
||||||
|
//D3D11_TEXTURE2D_DESC desc;
|
||||||
|
//desc.Width = lOutputDuplDesc.ModeDesc.Width;
|
||||||
|
//desc.Height = lOutputDuplDesc.ModeDesc.Height;
|
||||||
|
//desc.Format = lOutputDuplDesc.ModeDesc.Format;
|
||||||
|
//desc.ArraySize = 1;
|
||||||
|
//desc.BindFlags = D3D11_BIND_RENDER_TARGET;
|
||||||
|
//desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
|
||||||
|
//desc.SampleDesc.Count = 1;
|
||||||
|
//desc.SampleDesc.Quality = 0;
|
||||||
|
//desc.MipLevels = 1;
|
||||||
|
//desc.CPUAccessFlags = 0;
|
||||||
|
//desc.Usage = D3D11_USAGE_DEFAULT;
|
||||||
|
|
||||||
|
//hr = m_Device->lpVtbl->CreateTexture2D(m_Device, &desc, NULL, &lGDIImage);
|
||||||
|
//hr = m_Device->lpVtbl->CreateTexture2D(m_Device, &desc, NULL, &destinationImage);
|
||||||
|
|
||||||
|
//if (FAILED(hr))
|
||||||
|
//{
|
||||||
|
// DebugBreak();
|
||||||
|
//}
|
||||||
|
|
||||||
|
//// Get new frame
|
||||||
|
//for (i = 0; i < 5; ++i)
|
||||||
|
//{
|
||||||
|
// hr = dupl->lpVtbl->AcquireNextFrame(dupl, 250, &lFrameInfo, &lDesktopResource);
|
||||||
|
// if (hr != DXGI_ERROR_WAIT_TIMEOUT) { break; }
|
||||||
|
// Sleep(100);
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//hr = lDesktopResource->lpVtbl->QueryInterface(lDesktopResource, &IID_ID3D11Texture2D, &desktopImage);
|
||||||
|
|
||||||
|
//// Copy image into GDI drawing texture
|
||||||
|
//m_DeviceContext->lpVtbl->CopyResource(m_DeviceContext, lGDIImage, desktopImage);
|
||||||
|
|
||||||
|
//// Draw cursor image into GDI drawing texture
|
||||||
|
//IDXGISurface1 *surface;
|
||||||
|
//hr = lGDIImage->lpVtbl->QueryInterface(lGDIImage, &IID_IDXGISurface1, &surface);
|
||||||
|
|
||||||
|
|
||||||
|
//// Copy from CPU access texture to bitmap buffer
|
||||||
|
|
||||||
|
//D3D11_MAPPED_SUBRESOURCE resource;
|
||||||
|
//UINT subresource = D3D11CalcSubresource(0, 0, 0);
|
||||||
|
//m_DeviceContext->lpVtbl->Map(m_DeviceContext, destinationImage, subresource, D3D11_MAP_READ_WRITE, 0, &resource);
|
||||||
|
|
||||||
|
//BITMAPINFO lBmpInfo;
|
||||||
|
|
||||||
|
//// BMP 32 bpp
|
||||||
|
|
||||||
|
//ZeroMemory(&lBmpInfo, sizeof(BITMAPINFO));
|
||||||
|
//lBmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||||
|
//lBmpInfo.bmiHeader.biBitCount = 32;
|
||||||
|
//lBmpInfo.bmiHeader.biCompression = BI_RGB;
|
||||||
|
//lBmpInfo.bmiHeader.biWidth = lOutputDuplDesc.ModeDesc.Width;
|
||||||
|
//lBmpInfo.bmiHeader.biHeight = lOutputDuplDesc.ModeDesc.Height;
|
||||||
|
//lBmpInfo.bmiHeader.biPlanes = 1;
|
||||||
|
//lBmpInfo.bmiHeader.biSizeImage = lOutputDuplDesc.ModeDesc.Width * lOutputDuplDesc.ModeDesc.Height * 4;
|
||||||
|
|
||||||
|
|
||||||
|
//BYTE* pBuf = (BYTE*)ILibMemory_SmartAllocate(lBmpInfo.bmiHeader.biSizeImage);
|
||||||
|
//UINT lBmpRowPitch = lOutputDuplDesc.ModeDesc.Width * 4;
|
||||||
|
//BYTE* sptr = (BYTE*)resource.pData;
|
||||||
|
//BYTE* dptr = pBuf + lBmpInfo.bmiHeader.biSizeImage - lBmpRowPitch;
|
||||||
|
//UINT lRowPitch = min(lBmpRowPitch, resource.RowPitch);
|
||||||
|
//size_t h;
|
||||||
|
|
||||||
|
//for (h = 0; h < lOutputDuplDesc.ModeDesc.Height; ++h)
|
||||||
|
//{
|
||||||
|
// memcpy_s(dptr, lBmpRowPitch, sptr, lRowPitch);
|
||||||
|
// sptr += resource.RowPitch;
|
||||||
|
// dptr -= lBmpRowPitch;
|
||||||
|
//}
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3143,7 +3143,10 @@ void MeshServer_OnResponse(ILibWebClient_StateObject WebStateObject, int Interru
|
|||||||
MeshCommand_BinaryPacket_ServerId *serveridcmd = (MeshCommand_BinaryPacket_ServerId*)ILibScratchPad2;
|
MeshCommand_BinaryPacket_ServerId *serveridcmd = (MeshCommand_BinaryPacket_ServerId*)ILibScratchPad2;
|
||||||
serveridcmd->command = htons(MeshCommand_ServerId);
|
serveridcmd->command = htons(MeshCommand_ServerId);
|
||||||
memcpy_s(serveridcmd->serverId, sizeof(serveridcmd->serverId), agent->serverHash, sizeof(agent->serverHash)); // Place our mesh agent nonce
|
memcpy_s(serveridcmd->serverId, sizeof(serveridcmd->serverId), agent->serverHash, sizeof(agent->serverHash)); // Place our mesh agent nonce
|
||||||
ILibWebClient_WebSocket_Send(WebStateObject, ILibWebClient_WebSocket_DataType_BINARY, (char*)serveridcmd, sizeof(MeshCommand_BinaryPacket_ServerId), ILibAsyncSocket_MemoryOwnership_USER, ILibWebClient_WebSocket_FragmentFlag_Complete);
|
if ((int)ILibWebClient_WebSocket_Send(WebStateObject, ILibWebClient_WebSocket_DataType_BINARY, (char*)serveridcmd, sizeof(MeshCommand_BinaryPacket_ServerId), ILibAsyncSocket_MemoryOwnership_USER, ILibWebClient_WebSocket_FragmentFlag_Complete) < 0)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Check to see if we already have a validated TLS cert hash
|
// Check to see if we already have a validated TLS cert hash
|
||||||
{
|
{
|
||||||
@@ -3281,7 +3284,7 @@ void MeshServer_ConnectEx_NetworkError_Cleanup(void *j)
|
|||||||
}
|
}
|
||||||
void MeshServer_ConnectEx(MeshAgentHostContainer *agent)
|
void MeshServer_ConnectEx(MeshAgentHostContainer *agent)
|
||||||
{
|
{
|
||||||
int len, serverUrlLen;
|
size_t len, serverUrlLen;
|
||||||
char *path;
|
char *path;
|
||||||
char *host;
|
char *host;
|
||||||
char *serverUrl;
|
char *serverUrl;
|
||||||
@@ -3327,7 +3330,7 @@ void MeshServer_ConnectEx(MeshAgentHostContainer *agent)
|
|||||||
{
|
{
|
||||||
if (agent->multicastServerUrl != NULL) {
|
if (agent->multicastServerUrl != NULL) {
|
||||||
serverUrl = agent->multicastServerUrl;
|
serverUrl = agent->multicastServerUrl;
|
||||||
serverUrlLen = (int)strnlen_s(serverUrl, sizeof(ILibScratchPad));
|
serverUrlLen = strnlen_s(serverUrl, sizeof(ILibScratchPad));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -3787,7 +3790,7 @@ int importSettings(MeshAgentHostContainer *agent, char* fileName)
|
|||||||
if (eq > 0)
|
if (eq > 0)
|
||||||
{
|
{
|
||||||
char *key, *val;
|
char *key, *val;
|
||||||
int keyLen, valLen;
|
size_t keyLen, valLen;
|
||||||
|
|
||||||
key = f->data;
|
key = f->data;
|
||||||
keyLen = eq;
|
keyLen = eq;
|
||||||
@@ -5323,7 +5326,7 @@ int MeshAgent_Start(MeshAgentHostContainer *agentHost, int paramLen, char **para
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ILibCriticalLogFilename = ILibString_Copy(MeshAgent_MakeAbsolutePath(agentHost->exePath, ".log"), -1);
|
ILibCriticalLogFilename = ILibString_Copy(MeshAgent_MakeAbsolutePath(agentHost->exePath, ".log"), 0);
|
||||||
#ifndef MICROSTACK_NOTLS
|
#ifndef MICROSTACK_NOTLS
|
||||||
util_openssl_init();
|
util_openssl_init();
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -553,7 +553,7 @@ int wmain(int argc, char* wargv[])
|
|||||||
ILibDuktape_ScriptContainer_CheckEmbedded(&integratedJavaScript, &integragedJavaScriptLen);
|
ILibDuktape_ScriptContainer_CheckEmbedded(&integratedJavaScript, &integragedJavaScriptLen);
|
||||||
if (argc > 2 && strcmp(argv[1], "-exec") == 0 && integragedJavaScriptLen == 0)
|
if (argc > 2 && strcmp(argv[1], "-exec") == 0 && integragedJavaScriptLen == 0)
|
||||||
{
|
{
|
||||||
integratedJavaScript = ILibString_Copy(argv[2], -1);
|
integratedJavaScript = ILibString_Copy(argv[2], 0);
|
||||||
integragedJavaScriptLen = (int)strnlen_s(integratedJavaScript, sizeof(ILibScratchPad));
|
integragedJavaScriptLen = (int)strnlen_s(integratedJavaScript, sizeof(ILibScratchPad));
|
||||||
}
|
}
|
||||||
if (argc > 2 && strcmp(argv[1], "-b64exec") == 0 && integragedJavaScriptLen == 0)
|
if (argc > 2 && strcmp(argv[1], "-b64exec") == 0 && integragedJavaScriptLen == 0)
|
||||||
@@ -563,7 +563,7 @@ int wmain(int argc, char* wargv[])
|
|||||||
if (argc > 1 && strcasecmp(argv[1], "-nodeid") == 0)
|
if (argc > 1 && strcasecmp(argv[1], "-nodeid") == 0)
|
||||||
{
|
{
|
||||||
char script[] = "console.log(require('_agentNodeId')());process.exit();";
|
char script[] = "console.log(require('_agentNodeId')());process.exit();";
|
||||||
integratedJavaScript = ILibString_Copy(script, (int)sizeof(script) - 1);
|
integratedJavaScript = ILibString_Copy(script, sizeof(script) - 1);
|
||||||
integragedJavaScriptLen = (int)sizeof(script) - 1;
|
integragedJavaScriptLen = (int)sizeof(script) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1000,7 +1000,7 @@ char* getMshSettings(char* fileName, char* selfexe, char** meshname, char** mesh
|
|||||||
eq = ILibString_IndexOf(f->data, f->datalength, "=", 1);
|
eq = ILibString_IndexOf(f->data, f->datalength, "=", 1);
|
||||||
if (eq > 0) {
|
if (eq > 0) {
|
||||||
char *key, *val;
|
char *key, *val;
|
||||||
int keyLen, valLen;
|
size_t keyLen, valLen;
|
||||||
|
|
||||||
key = f->data;
|
key = f->data;
|
||||||
keyLen = eq;
|
keyLen = eq;
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ void ILibDuktape_ChildProcess_SubProcess_ExitHandler(ILibProcessPipe_Process sen
|
|||||||
if (duk_pcall_method(p->ctx, 3) != 0) { ILibDuktape_Process_UncaughtExceptionEx(p->ctx, "child_process.subProcess.exit(): "); }
|
if (duk_pcall_method(p->ctx, 3) != 0) { ILibDuktape_Process_UncaughtExceptionEx(p->ctx, "child_process.subProcess.exit(): "); }
|
||||||
duk_pop(p->ctx);
|
duk_pop(p->ctx);
|
||||||
}
|
}
|
||||||
void ILibDuktape_ChildProcess_SubProcess_StdOutHandler(ILibProcessPipe_Process sender, char *buffer, int bufferLen, int* bytesConsumed, void* user)
|
void ILibDuktape_ChildProcess_SubProcess_StdOutHandler(ILibProcessPipe_Process sender, char *buffer, size_t bufferLen, size_t* bytesConsumed, void* user)
|
||||||
{
|
{
|
||||||
ILibDuktape_ChildProcess_SubProcess *p = (ILibDuktape_ChildProcess_SubProcess*)user;
|
ILibDuktape_ChildProcess_SubProcess *p = (ILibDuktape_ChildProcess_SubProcess*)user;
|
||||||
if (!ILibMemory_CanaryOK(p)) { return; }
|
if (!ILibMemory_CanaryOK(p)) { return; }
|
||||||
@@ -145,7 +145,7 @@ void ILibDuktape_ChildProcess_SubProcess_StdOutHandler(ILibProcessPipe_Process s
|
|||||||
ILibDuktape_readableStream_WriteData(p->stdOut, buffer, bufferLen);
|
ILibDuktape_readableStream_WriteData(p->stdOut, buffer, bufferLen);
|
||||||
*bytesConsumed = bufferLen;
|
*bytesConsumed = bufferLen;
|
||||||
}
|
}
|
||||||
void ILibDuktape_ChildProcess_SubProcess_StdErrHandler(ILibProcessPipe_Process sender, char *buffer, int bufferLen, int* bytesConsumed, void* user)
|
void ILibDuktape_ChildProcess_SubProcess_StdErrHandler(ILibProcessPipe_Process sender, char *buffer, size_t bufferLen, size_t* bytesConsumed, void* user)
|
||||||
{
|
{
|
||||||
ILibDuktape_ChildProcess_SubProcess *p = (ILibDuktape_ChildProcess_SubProcess*)user;
|
ILibDuktape_ChildProcess_SubProcess *p = (ILibDuktape_ChildProcess_SubProcess*)user;
|
||||||
if (!ILibMemory_CanaryOK(p)) { return; }
|
if (!ILibMemory_CanaryOK(p)) { return; }
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
// This file is auto-generated, any edits may be overwritten
|
// This file is auto-generated, any edits may be overwritten
|
||||||
#define SOURCE_COMMIT_DATE "2020-Sep-17 12:49:12-0700"
|
#define SOURCE_COMMIT_DATE "2020-Oct-13 18:14:15-0700"
|
||||||
#define SOURCE_COMMIT_HASH "20d4345a87cb5a912f4d891da35bb2ba690b4588"
|
#define SOURCE_COMMIT_HASH "78b65edc4e326bc239cf3fbac6b769bc207057ba"
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ duk_ret_t ILibDuktape_Polyfills_Buffer_from(duk_context *ctx)
|
|||||||
duk_size_t strlength;
|
duk_size_t strlength;
|
||||||
char *encoding;
|
char *encoding;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
int bufferLen;
|
size_t bufferLen;
|
||||||
|
|
||||||
if (nargs == 1)
|
if (nargs == 1)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -293,18 +293,18 @@ void __stdcall ILibDuktape_readableStream_WriteData_OnData_ChainThread_APC(ULONG
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int ILibDuktape_readableStream_WriteDataEx(ILibDuktape_readableStream *stream, int streamReserved, char* buffer, int bufferLen)
|
int ILibDuktape_readableStream_WriteDataEx(ILibDuktape_readableStream *stream, int streamReserved, char* buffer, size_t bufferLen)
|
||||||
{
|
{
|
||||||
ILibDuktape_readableStream_nextWriteablePipe *w;
|
ILibDuktape_readableStream_nextWriteablePipe *w;
|
||||||
int dispatchedNonNative = 0;
|
int dispatchedNonNative = 0;
|
||||||
int dispatched = 0;
|
int dispatched = 0;
|
||||||
int needPause = 0;
|
int needPause = 0;
|
||||||
|
|
||||||
if (stream == NULL || !ILibMemory_CanaryOK(stream)) { return(1); }
|
if (stream == NULL || !ILibMemory_CanaryOK(stream) || bufferLen > INT32_MAX) { return(1); } // ToDo: Add support for larger data sets
|
||||||
|
|
||||||
if (stream->paused != 0)
|
if (stream->paused != 0)
|
||||||
{
|
{
|
||||||
ILibDuktape_readableStream_WriteData_buffer(stream, streamReserved, buffer, bufferLen);
|
ILibDuktape_readableStream_WriteData_buffer(stream, streamReserved, buffer, (int)bufferLen);
|
||||||
if (stream->paused == 0 && stream->PauseHandler != NULL) { stream->paused = 1; stream->PauseHandler(stream, stream->user); }
|
if (stream->paused == 0 && stream->PauseHandler != NULL) { stream->paused = 1; stream->PauseHandler(stream, stream->user); }
|
||||||
return(stream->paused);
|
return(stream->paused);
|
||||||
}
|
}
|
||||||
@@ -331,7 +331,7 @@ int ILibDuktape_readableStream_WriteDataEx(ILibDuktape_readableStream *stream, i
|
|||||||
ILibDuktape_WritableStream *ws = (ILibDuktape_WritableStream*)w->nativeWritable;
|
ILibDuktape_WritableStream *ws = (ILibDuktape_WritableStream*)w->nativeWritable;
|
||||||
ws->Reserved = streamReserved;
|
ws->Reserved = streamReserved;
|
||||||
ws->endBytes = -1;
|
ws->endBytes = -1;
|
||||||
switch (ws->WriteSink(ws, buffer, bufferLen, ws->WriteSink_User))
|
switch (ws->WriteSink(ws, buffer, (int)bufferLen, ws->WriteSink_User))
|
||||||
{
|
{
|
||||||
case ILibTransport_DoneState_INCOMPLETE:
|
case ILibTransport_DoneState_INCOMPLETE:
|
||||||
ws->OnWriteFlushEx = ILibDuktape_readableStream_WriteData_Flush;
|
ws->OnWriteFlushEx = ILibDuktape_readableStream_WriteData_Flush;
|
||||||
@@ -356,7 +356,7 @@ int ILibDuktape_readableStream_WriteDataEx(ILibDuktape_readableStream *stream, i
|
|||||||
tmp->ctx = stream->ctx;
|
tmp->ctx = stream->ctx;
|
||||||
tmp->Next = (ILibDuktape_readableStream_bufferedData*)stream;
|
tmp->Next = (ILibDuktape_readableStream_bufferedData*)stream;
|
||||||
tmp->Reserved = streamReserved;
|
tmp->Reserved = streamReserved;
|
||||||
tmp->bufferLen = bufferLen;
|
tmp->bufferLen = (int)bufferLen;
|
||||||
memcpy_s(tmp->buffer, bufferLen, buffer, bufferLen);
|
memcpy_s(tmp->buffer, bufferLen, buffer, bufferLen);
|
||||||
dispatchedNonNative = 1;
|
dispatchedNonNative = 1;
|
||||||
needPause = 1;
|
needPause = 1;
|
||||||
@@ -365,7 +365,7 @@ int ILibDuktape_readableStream_WriteDataEx(ILibDuktape_readableStream *stream, i
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// We're running on the Chain Thread, so we can directly dispatch into JS
|
// We're running on the Chain Thread, so we can directly dispatch into JS
|
||||||
switch (ILibDuktape_readableStream_WriteDataEx_Chain_Dispatch(stream, w->writableStream, buffer, bufferLen))
|
switch (ILibDuktape_readableStream_WriteDataEx_Chain_Dispatch(stream, w->writableStream, buffer, (int)bufferLen))
|
||||||
{
|
{
|
||||||
case 0: // Need to Pause
|
case 0: // Need to Pause
|
||||||
needPause = 1;
|
needPause = 1;
|
||||||
@@ -419,7 +419,7 @@ int ILibDuktape_readableStream_WriteDataEx(ILibDuktape_readableStream *stream, i
|
|||||||
ILibDuktape_readableStream_bufferedData *tmp = (ILibDuktape_readableStream_bufferedData*)ILibMemory_Allocate(sizeof(ILibDuktape_readableStream_bufferedData) + bufferLen, 0, NULL, NULL);
|
ILibDuktape_readableStream_bufferedData *tmp = (ILibDuktape_readableStream_bufferedData*)ILibMemory_Allocate(sizeof(ILibDuktape_readableStream_bufferedData) + bufferLen, 0, NULL, NULL);
|
||||||
#endif
|
#endif
|
||||||
tmp->ctx = stream->ctx;
|
tmp->ctx = stream->ctx;
|
||||||
tmp->bufferLen = bufferLen;
|
tmp->bufferLen = (int)bufferLen;
|
||||||
tmp->Reserved = streamReserved;
|
tmp->Reserved = streamReserved;
|
||||||
tmp->Next = (ILibDuktape_readableStream_bufferedData*)stream;
|
tmp->Next = (ILibDuktape_readableStream_bufferedData*)stream;
|
||||||
memcpy_s(tmp->buffer, bufferLen, buffer, bufferLen);
|
memcpy_s(tmp->buffer, bufferLen, buffer, bufferLen);
|
||||||
@@ -440,7 +440,7 @@ int ILibDuktape_readableStream_WriteDataEx(ILibDuktape_readableStream *stream, i
|
|||||||
// If we get here, it means we are writing data, but nobody is going to be receiving it...
|
// If we get here, it means we are writing data, but nobody is going to be receiving it...
|
||||||
// So we need to buffer the data, so when we are resumed later, we can retry
|
// So we need to buffer the data, so when we are resumed later, we can retry
|
||||||
needPause = 1;
|
needPause = 1;
|
||||||
ILibDuktape_readableStream_WriteData_buffer(stream, streamReserved, buffer, bufferLen);
|
ILibDuktape_readableStream_WriteData_buffer(stream, streamReserved, buffer, (int)bufferLen);
|
||||||
}
|
}
|
||||||
else if (ILibDuktape_EventEmitter_HasListeners(stream->emitter, "end") != 0)
|
else if (ILibDuktape_EventEmitter_HasListeners(stream->emitter, "end") != 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ ILibDuktape_readableStream* ILibDuktape_ReadableStream_InitEx(duk_context *ctx,
|
|||||||
#define ILibDuktape_readableStream_SetPauseResumeHandlers(stream, PauseFunc, ResumeFunc, userObj) ((ILibDuktape_readableStream*)stream)->PauseHandler = PauseFunc; ((ILibDuktape_readableStream*)stream)->ResumeHandler = ResumeFunc; ((ILibDuktape_readableStream*)stream)->user = userObj;
|
#define ILibDuktape_readableStream_SetPauseResumeHandlers(stream, PauseFunc, ResumeFunc, userObj) ((ILibDuktape_readableStream*)stream)->PauseHandler = PauseFunc; ((ILibDuktape_readableStream*)stream)->ResumeHandler = ResumeFunc; ((ILibDuktape_readableStream*)stream)->user = userObj;
|
||||||
|
|
||||||
void ILibDuktape_ReadableStream_DestroyPausedData(ILibDuktape_readableStream *stream);
|
void ILibDuktape_ReadableStream_DestroyPausedData(ILibDuktape_readableStream *stream);
|
||||||
int ILibDuktape_readableStream_WriteDataEx(ILibDuktape_readableStream *stream, int streamReserved, char* buffer, int bufferLen);
|
int ILibDuktape_readableStream_WriteDataEx(ILibDuktape_readableStream *stream, int streamReserved, char* buffer, size_t bufferLen);
|
||||||
int ILibDuktape_readableStream_WriteEnd(ILibDuktape_readableStream *stream);
|
int ILibDuktape_readableStream_WriteEnd(ILibDuktape_readableStream *stream);
|
||||||
#define ILibDuktape_readableStream_WriteData(stream, buffer, bufferLen) ILibDuktape_readableStream_WriteDataEx(stream, 0, buffer, bufferLen)
|
#define ILibDuktape_readableStream_WriteData(stream, buffer, bufferLen) ILibDuktape_readableStream_WriteDataEx(stream, 0, buffer, bufferLen)
|
||||||
void ILibDuktape_readableStream_Closed(ILibDuktape_readableStream *stream);
|
void ILibDuktape_readableStream_Closed(ILibDuktape_readableStream *stream);
|
||||||
|
|||||||
@@ -2969,7 +2969,7 @@ void ILibDuktape_ScriptContainer_Slave_OnReadStdInEx(void *chain, void *data)
|
|||||||
ILibProcessPipe_Pipe_Resume((ILibProcessPipe_Pipe)data);
|
ILibProcessPipe_Pipe_Resume((ILibProcessPipe_Pipe)data);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
void ILibDuktape_ScriptContainer_Slave_OnReadStdIn(ILibProcessPipe_Pipe sender, char *buffer, int bufferLen, int* bytesConsumed)
|
void ILibDuktape_ScriptContainer_Slave_OnReadStdIn(ILibProcessPipe_Pipe sender, char *buffer, size_t bufferLen, size_t* bytesConsumed)
|
||||||
{
|
{
|
||||||
if (!ILibMemory_CanaryOK(sender)) { return; }
|
if (!ILibMemory_CanaryOK(sender)) { return; }
|
||||||
|
|
||||||
@@ -3243,7 +3243,7 @@ void ILibDuktape_ScriptContainer_StdOutSink_Chain(void *chain, void *user)
|
|||||||
}
|
}
|
||||||
ILibMemory_Free(user);
|
ILibMemory_Free(user);
|
||||||
}
|
}
|
||||||
void ILibDuktape_ScriptContainer_StdOutSink(ILibProcessPipe_Process sender, char *buffer, int bufferLen, int* bytesConsumed, void* user)
|
void ILibDuktape_ScriptContainer_StdOutSink(ILibProcessPipe_Process sender, char *buffer, size_t bufferLen, size_t* bytesConsumed, void* user)
|
||||||
{
|
{
|
||||||
buffer[bufferLen] = 0;
|
buffer[bufferLen] = 0;
|
||||||
|
|
||||||
@@ -3358,7 +3358,7 @@ void ILibDuktape_ScriptContainer_StdErrSink_MicrostackThread(void *chain, void *
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
void ILibDuktape_ScriptContainer_StdErrSink(ILibProcessPipe_Process sender, char *buffer, int bufferLen, int* bytesConsumed, void* user)
|
void ILibDuktape_ScriptContainer_StdErrSink(ILibProcessPipe_Process sender, char *buffer, size_t bufferLen, size_t* bytesConsumed, void* user)
|
||||||
{
|
{
|
||||||
ILibDuktape_ScriptContainer_Master* master = (ILibDuktape_ScriptContainer_Master*)user;
|
ILibDuktape_ScriptContainer_Master* master = (ILibDuktape_ScriptContainer_Master*)user;
|
||||||
|
|
||||||
|
|||||||
@@ -571,7 +571,7 @@ duk_ret_t ILibDuktape_fs_write_writeset_sink(duk_context *ctx)
|
|||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
BOOL ILibDuktape_fs_write_WindowsSink(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, int bytesWritten, void* user)
|
BOOL ILibDuktape_fs_write_WindowsSink(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, DWORD bytesWritten, void* user)
|
||||||
{
|
{
|
||||||
ILibDuktape_WindowsHandle_Data *data = (ILibDuktape_WindowsHandle_Data*)user;
|
ILibDuktape_WindowsHandle_Data *data = (ILibDuktape_WindowsHandle_Data*)user;
|
||||||
if (ILibMemory_CanaryOK(data) && duk_ctx_is_alive(data->ctx))
|
if (ILibMemory_CanaryOK(data) && duk_ctx_is_alive(data->ctx))
|
||||||
@@ -588,7 +588,7 @@ BOOL ILibDuktape_fs_write_WindowsSink(void *chain, HANDLE h, ILibWaitHandle_Erro
|
|||||||
duk_push_heapptr(data->ctx, data->write_callback); // [callback]
|
duk_push_heapptr(data->ctx, data->write_callback); // [callback]
|
||||||
duk_eval_string(data->ctx, "require('fs');"); // [callback][this]
|
duk_eval_string(data->ctx, "require('fs');"); // [callback][this]
|
||||||
duk_push_int(data->ctx, status); // [callback][this][err]
|
duk_push_int(data->ctx, status); // [callback][this][err]
|
||||||
duk_push_int(data->ctx, bytesWritten); // [callback][this][err][bytesRead]
|
duk_push_uint(data->ctx, bytesWritten); // [callback][this][err][bytesRead]
|
||||||
duk_push_heapptr(data->ctx, data->write_userBuffer);// [callback][this][err][bytesRead][buffer]
|
duk_push_heapptr(data->ctx, data->write_userBuffer);// [callback][this][err][bytesRead][buffer]
|
||||||
data->write_callback = NULL;
|
data->write_callback = NULL;
|
||||||
data->write_userBuffer = NULL;
|
data->write_userBuffer = NULL;
|
||||||
@@ -644,7 +644,7 @@ duk_ret_t ILibDuktape_fs_write(duk_context *ctx)
|
|||||||
|
|
||||||
data->write_buffer = buffer + offset;
|
data->write_buffer = buffer + offset;
|
||||||
data->write_bufferSize = length;
|
data->write_bufferSize = length;
|
||||||
ILibChain_WriteEx2(duk_ctx_chain(ctx), data->H, &(data->write_p), data->write_buffer, (int)data->write_bufferSize, ILibDuktape_fs_write_WindowsSink, data, "fs.write()");
|
ILibChain_WriteEx2(duk_ctx_chain(ctx), data->H, &(data->write_p), data->write_buffer, (DWORD)data->write_bufferSize, ILibDuktape_fs_write_WindowsSink, data, "fs.write()");
|
||||||
return(0);
|
return(0);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@@ -726,7 +726,7 @@ duk_ret_t ILibDuktape_fs_write(duk_context *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
BOOL ILibDuktape_fs_read_WindowsSink(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, char *buffer, int bytesRead, void* user)
|
BOOL ILibDuktape_fs_read_WindowsSink(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, char *buffer, DWORD bytesRead, void* user)
|
||||||
{
|
{
|
||||||
ILibDuktape_WindowsHandle_Data *data = (ILibDuktape_WindowsHandle_Data*)user;
|
ILibDuktape_WindowsHandle_Data *data = (ILibDuktape_WindowsHandle_Data*)user;
|
||||||
if (ILibMemory_CanaryOK(data) && duk_ctx_is_alive(data->ctx))
|
if (ILibMemory_CanaryOK(data) && duk_ctx_is_alive(data->ctx))
|
||||||
@@ -743,7 +743,7 @@ BOOL ILibDuktape_fs_read_WindowsSink(void *chain, HANDLE h, ILibWaitHandle_Error
|
|||||||
duk_push_heapptr(data->ctx, data->callback); // [callback]
|
duk_push_heapptr(data->ctx, data->callback); // [callback]
|
||||||
duk_eval_string(data->ctx, "require('fs');"); // [callback][this]
|
duk_eval_string(data->ctx, "require('fs');"); // [callback][this]
|
||||||
duk_push_int(data->ctx, status); // [callback][this][err]
|
duk_push_int(data->ctx, status); // [callback][this][err]
|
||||||
duk_push_int(data->ctx, bytesRead); // [callback][this][err][bytesRead]
|
duk_push_uint(data->ctx, bytesRead); // [callback][this][err][bytesRead]
|
||||||
duk_push_heapptr(data->ctx, data->userBuffer); // [callback][this][err][bytesRead][buffer]
|
duk_push_heapptr(data->ctx, data->userBuffer); // [callback][this][err][bytesRead][buffer]
|
||||||
data->callback = NULL;
|
data->callback = NULL;
|
||||||
data->userBuffer = NULL;
|
data->userBuffer = NULL;
|
||||||
@@ -892,7 +892,7 @@ duk_ret_t ILibDuktape_fs_read(duk_context *ctx)
|
|||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
data->buffer = buffer + offset;
|
data->buffer = buffer + offset;
|
||||||
data->bufferSize = length;
|
data->bufferSize = length;
|
||||||
ILibChain_ReadEx2(duk_ctx_chain(ctx), data->H, &(data->p), data->buffer, (int)data->bufferSize, ILibDuktape_fs_read_WindowsSink, data, "fs.read()");
|
ILibChain_ReadEx2(duk_ctx_chain(ctx), data->H, &(data->p), data->buffer, (DWORD)data->bufferSize, ILibDuktape_fs_read_WindowsSink, data, "fs.read()");
|
||||||
return(0);
|
return(0);
|
||||||
#else
|
#else
|
||||||
int bytesRead = read(fd, buffer + offset, length);
|
int bytesRead = read(fd, buffer + offset, length);
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ typedef struct ILibDuktape_net_WindowsIPC
|
|||||||
HANDLE mPipeHandle;
|
HANDLE mPipeHandle;
|
||||||
int endCalled;
|
int endCalled;
|
||||||
int paused;
|
int paused;
|
||||||
int totalRead;
|
DWORD totalRead;
|
||||||
void *user1;
|
void *user1;
|
||||||
void* ipcreserved;
|
void* ipcreserved;
|
||||||
|
|
||||||
@@ -101,10 +101,10 @@ typedef struct ILibDuktape_net_WindowsIPC
|
|||||||
ULONG_PTR _reserved[5];
|
ULONG_PTR _reserved[5];
|
||||||
|
|
||||||
char *buffer;
|
char *buffer;
|
||||||
int bufferLength;
|
DWORD bufferLength;
|
||||||
int bufferOffset;
|
DWORD bufferOffset;
|
||||||
int bytesLeft;
|
DWORD bytesLeft;
|
||||||
int unshiftedBytes;
|
DWORD unshiftedBytes;
|
||||||
}ILibDuktape_net_WindowsIPC;
|
}ILibDuktape_net_WindowsIPC;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -144,7 +144,7 @@ void ILibDuktape_net_server_IPC_PauseSink(ILibDuktape_DuplexStream *sender, void
|
|||||||
void ILibDuktape_net_server_IPC_ResumeSink(ILibDuktape_DuplexStream *sender, void *user);
|
void ILibDuktape_net_server_IPC_ResumeSink(ILibDuktape_DuplexStream *sender, void *user);
|
||||||
int ILibDuktape_net_server_IPC_unshiftSink(ILibDuktape_DuplexStream *sender, int unshiftBytes, void *user);
|
int ILibDuktape_net_server_IPC_unshiftSink(ILibDuktape_DuplexStream *sender, int unshiftBytes, void *user);
|
||||||
duk_ret_t ILibDuktape_net_server_IPC_ConnectSink_Finalizer(duk_context *ctx);
|
duk_ret_t ILibDuktape_net_server_IPC_ConnectSink_Finalizer(duk_context *ctx);
|
||||||
BOOL ILibDuktape_server_ipc_ReadSink(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, char *buffer, int bytesRead, void* user);
|
BOOL ILibDuktape_server_ipc_ReadSink(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, char *buffer, DWORD bytesRead, void* user);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -917,7 +917,7 @@ void ILibDuktape_net_server_OnSendOK(ILibAsyncServerSocket_ServerModule AsyncSer
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
BOOL ILibDuktape_server_ipc_ReadSink(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, char *buffer, int bytesRead, void* user)
|
BOOL ILibDuktape_server_ipc_ReadSink(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, char *buffer, DWORD bytesRead, void* user)
|
||||||
{
|
{
|
||||||
ILibDuktape_net_WindowsIPC *winIPC = (ILibDuktape_net_WindowsIPC*)user;
|
ILibDuktape_net_WindowsIPC *winIPC = (ILibDuktape_net_WindowsIPC*)user;
|
||||||
int consumed = 0;
|
int consumed = 0;
|
||||||
@@ -979,7 +979,7 @@ BOOL ILibDuktape_server_ipc_ReadSink(void *chain, HANDLE h, ILibWaitHandle_Error
|
|||||||
return(FALSE);
|
return(FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BOOL ILibDuktape_server_ipc_WriteSink(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, int bytesWritten, void* user)
|
BOOL ILibDuktape_server_ipc_WriteSink(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, DWORD bytesWritten, void* user)
|
||||||
{
|
{
|
||||||
if (!ILibMemory_CanaryOK(user)) { return(FALSE); }
|
if (!ILibMemory_CanaryOK(user)) { return(FALSE); }
|
||||||
ILibDuktape_net_WindowsIPC *winIPC = (ILibDuktape_net_WindowsIPC*)user;
|
ILibDuktape_net_WindowsIPC *winIPC = (ILibDuktape_net_WindowsIPC*)user;
|
||||||
@@ -1002,7 +1002,7 @@ BOOL ILibDuktape_server_ipc_WriteSink(void *chain, HANDLE h, ILibWaitHandle_Erro
|
|||||||
if (duk_get_length(winIPC->ctx, -1) == 0) { break; }
|
if (duk_get_length(winIPC->ctx, -1) == 0) { break; }
|
||||||
duk_get_prop_index(winIPC->ctx, -1, 0); // [obj][array][buffer]
|
duk_get_prop_index(winIPC->ctx, -1, 0); // [obj][array][buffer]
|
||||||
buf = Duktape_GetBuffer(winIPC->ctx, -1, &bufLen);
|
buf = Duktape_GetBuffer(winIPC->ctx, -1, &bufLen);
|
||||||
d = ILibChain_WriteEx2(chain, h, &(winIPC->write_overlapped), buf, (int)bufLen, ILibDuktape_server_ipc_WriteSink, winIPC, "server_ipc_WriteSink()");
|
d = ILibChain_WriteEx2(chain, h, &(winIPC->write_overlapped), buf, (DWORD)bufLen, ILibDuktape_server_ipc_WriteSink, winIPC, "server_ipc_WriteSink()");
|
||||||
duk_pop(winIPC->ctx); // [obj][array]
|
duk_pop(winIPC->ctx); // [obj][array]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -761,7 +761,6 @@ size_t ILibAsyncServerSocket_GetConnections(ILibAsyncServerSocket_ServerModule s
|
|||||||
{
|
{
|
||||||
if (ILibAsyncSocket_IsConnected(mod->AsyncSockets[i]))
|
if (ILibAsyncSocket_IsConnected(mod->AsyncSockets[i]))
|
||||||
{
|
{
|
||||||
ILibAsyncServerSocket_Data *data = (ILibAsyncServerSocket_Data*)ILibAsyncSocket_GetUser(mod->AsyncSockets[i]);
|
|
||||||
connections[x++] = mod->AsyncSockets[i];
|
connections[x++] = mod->AsyncSockets[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -544,12 +544,13 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_SendTo_MultiWrite(ILibAsyncSocket_Soc
|
|||||||
enum ILibAsyncSocket_SendStatus retVal = ILibAsyncSocket_ALL_DATA_SENT;
|
enum ILibAsyncSocket_SendStatus retVal = ILibAsyncSocket_ALL_DATA_SENT;
|
||||||
unsigned int vi;
|
unsigned int vi;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
int bufferLen;
|
size_t bufferLen;
|
||||||
ILibAsyncSocket_MemoryOwnership UserFree;
|
ILibAsyncSocket_MemoryOwnership UserFree;
|
||||||
int lockOverride = ((count & ILibAsyncSocket_LOCK_OVERRIDE) == ILibAsyncSocket_LOCK_OVERRIDE) ? (count ^= ILibAsyncSocket_LOCK_OVERRIDE, 1) : 0;
|
int lockOverride = ((count & ILibAsyncSocket_LOCK_OVERRIDE) == ILibAsyncSocket_LOCK_OVERRIDE) ? (count ^= ILibAsyncSocket_LOCK_OVERRIDE, 1) : 0;
|
||||||
|
|
||||||
// If the socket is empty, return now.
|
// If the socket is empty, return now.
|
||||||
if (socketModule == NULL) return ILibAsyncSocket_SEND_ON_CLOSED_SOCKET_ERROR;
|
if (socketModule == NULL) return ILibAsyncSocket_SEND_ON_CLOSED_SOCKET_ERROR;
|
||||||
|
int notok = 0;
|
||||||
|
|
||||||
va_list vlist;
|
va_list vlist;
|
||||||
va_start(vlist, count);
|
va_start(vlist, count);
|
||||||
@@ -562,11 +563,18 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_SendTo_MultiWrite(ILibAsyncSocket_Soc
|
|||||||
for (vi = 0; vi < count; ++vi)
|
for (vi = 0; vi < count; ++vi)
|
||||||
{
|
{
|
||||||
buffer = va_arg(vlist, char*);
|
buffer = va_arg(vlist, char*);
|
||||||
bufferLen = va_arg(vlist, int);
|
bufferLen = va_arg(vlist, size_t);
|
||||||
UserFree = va_arg(vlist, ILibAsyncSocket_MemoryOwnership);
|
UserFree = va_arg(vlist, ILibAsyncSocket_MemoryOwnership);
|
||||||
|
|
||||||
|
if (bufferLen > INT32_MAX || notok != 0)
|
||||||
|
{
|
||||||
|
if (UserFree == ILibAsyncSocket_MemoryOwnership_CHAIN) { free(buffer); }
|
||||||
|
notok = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
SSL_TRACE1("SSL_write()");
|
SSL_TRACE1("SSL_write()");
|
||||||
SSL_write(module->ssl, buffer, bufferLen);
|
SSL_write(module->ssl, buffer, (int)bufferLen); // No dataloss, becuase we capped at INT32_MAX
|
||||||
SSL_TRACE2("SSL_write()");
|
SSL_TRACE2("SSL_write()");
|
||||||
TLSLOG1("SSL_write[%d]: %d bytes...\n", module->internalSocket, bufferLen);
|
TLSLOG1("SSL_write[%d]: %d bytes...\n", module->internalSocket, bufferLen);
|
||||||
|
|
||||||
@@ -574,6 +582,8 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_SendTo_MultiWrite(ILibAsyncSocket_Soc
|
|||||||
}
|
}
|
||||||
va_end(vlist);
|
va_end(vlist);
|
||||||
|
|
||||||
|
if (notok == 0)
|
||||||
|
{
|
||||||
if (module->PendingSend_Tail == NULL)
|
if (module->PendingSend_Tail == NULL)
|
||||||
{
|
{
|
||||||
// No pending data, so we can send now
|
// No pending data, so we can send now
|
||||||
@@ -640,6 +650,12 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_SendTo_MultiWrite(ILibAsyncSocket_Soc
|
|||||||
module->PendingBytesToSend = (unsigned int)(module->writeBioBuffer->length);
|
module->PendingBytesToSend = (unsigned int)(module->writeBioBuffer->length);
|
||||||
TLSLOG1(" --> [IN PROGRESS] Accumulated into BIOBUFFER[%d]...\n", module->internalSocket);
|
TLSLOG1(" --> [IN PROGRESS] Accumulated into BIOBUFFER[%d]...\n", module->internalSocket);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
retVal = ILibAsyncSocket_BUFFER_TOO_LARGE;
|
||||||
|
ILibAsyncSocket_SendError(module);
|
||||||
|
}
|
||||||
|
|
||||||
if (lockOverride == 0) { sem_post(&(module->SendLock)); }
|
if (lockOverride == 0) { sem_post(&(module->SendLock)); }
|
||||||
if (retVal != ILibAsyncSocket_ALL_DATA_SENT && !ILibIsRunningOnChainThread(module->Transport.ChainLink.ParentChain)) ILibForceUnBlockChain(module->Transport.ChainLink.ParentChain);
|
if (retVal != ILibAsyncSocket_ALL_DATA_SENT && !ILibIsRunningOnChainThread(module->Transport.ChainLink.ParentChain)) ILibForceUnBlockChain(module->Transport.ChainLink.ParentChain);
|
||||||
@@ -667,15 +683,21 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_SendTo_MultiWrite(ILibAsyncSocket_Soc
|
|||||||
for (vi = 0; vi < count; ++vi)
|
for (vi = 0; vi < count; ++vi)
|
||||||
{
|
{
|
||||||
buffer = va_arg(vlist, char*);
|
buffer = va_arg(vlist, char*);
|
||||||
bufferLen = va_arg(vlist, int);
|
bufferLen = va_arg(vlist, size_t);
|
||||||
UserFree = va_arg(vlist, ILibAsyncSocket_MemoryOwnership);
|
UserFree = va_arg(vlist, ILibAsyncSocket_MemoryOwnership);
|
||||||
|
|
||||||
|
if (bufferLen > INT32_MAX || notok != 0)
|
||||||
|
{
|
||||||
|
notok = 1;
|
||||||
|
if (UserFree == ILibAsyncSocket_MemoryOwnership_CHAIN) { free(buffer); }
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (module->PendingSend_Tail != NULL || module->FinConnect == 0)
|
if (module->PendingSend_Tail != NULL || module->FinConnect == 0)
|
||||||
{
|
{
|
||||||
// There are still bytes that are pending to be sent, or pending connection, so we need to queue this up
|
// There are still bytes that are pending to be sent, or pending connection, so we need to queue this up
|
||||||
data = (ILibAsyncSocket_SendData*)ILibMemory_Allocate(sizeof(ILibAsyncSocket_SendData), 0, NULL, NULL);
|
data = (ILibAsyncSocket_SendData*)ILibMemory_Allocate(sizeof(ILibAsyncSocket_SendData), 0, NULL, NULL);
|
||||||
data->bufferSize = bufferLen;
|
data->bufferSize = (int)bufferLen; // No dataloss, capped to INT32_MAX
|
||||||
module->PendingBytesToSend += bufferLen;
|
module->PendingBytesToSend += (int)bufferLen;
|
||||||
if (UserFree == ILibAsyncSocket_MemoryOwnership_USER)
|
if (UserFree == ILibAsyncSocket_MemoryOwnership_USER)
|
||||||
{
|
{
|
||||||
if ((data->buffer = (char*)malloc(data->bufferSize)) == NULL) ILIBCRITICALEXIT(254);
|
if ((data->buffer = (char*)malloc(data->bufferSize)) == NULL) ILIBCRITICALEXIT(254);
|
||||||
@@ -707,16 +729,16 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_SendTo_MultiWrite(ILibAsyncSocket_Soc
|
|||||||
if (remoteAddress == NULL || remoteAddress->sa_family == AF_UNIX)
|
if (remoteAddress == NULL || remoteAddress->sa_family == AF_UNIX)
|
||||||
{
|
{
|
||||||
// Set MSG_NOSIGNAL since we don't want to get Broken Pipe signals in Linux, ignored if Windows.
|
// Set MSG_NOSIGNAL since we don't want to get Broken Pipe signals in Linux, ignored if Windows.
|
||||||
bytesSent = send(module->internalSocket, buffer, bufferLen, MSG_NOSIGNAL);
|
bytesSent = send(module->internalSocket, buffer, (int)bufferLen, MSG_NOSIGNAL); // No dataloss, capped to INT32_MAX
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bytesSent = sendto(module->internalSocket, buffer, bufferLen, MSG_NOSIGNAL, (struct sockaddr*)remoteAddress, INET_SOCKADDR_LENGTH(remoteAddress->sa_family));
|
bytesSent = sendto(module->internalSocket, buffer, (int)bufferLen, MSG_NOSIGNAL, (struct sockaddr*)remoteAddress, INET_SOCKADDR_LENGTH(remoteAddress->sa_family)); // No dataloss, capped to INT32_MAX
|
||||||
}
|
}
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
if ((bytesSent > 0 && bytesSent < bufferLen) || (bytesSent < 0 && WSAGetLastError() == WSAEWOULDBLOCK))
|
if ((bytesSent > 0 && bytesSent < (int)bufferLen) || (bytesSent < 0 && WSAGetLastError() == WSAEWOULDBLOCK))
|
||||||
#else
|
#else
|
||||||
if ((bytesSent > 0 && bytesSent < bufferLen) || (bytesSent < 0 && errno == EWOULDBLOCK))
|
if ((bytesSent > 0 && bytesSent < (int)bufferLen) || (bytesSent < 0 && errno == EWOULDBLOCK))
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
// Not all data was sent
|
// Not all data was sent
|
||||||
@@ -724,7 +746,7 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_SendTo_MultiWrite(ILibAsyncSocket_Soc
|
|||||||
data = (ILibAsyncSocket_SendData*)ILibMemory_Allocate(sizeof(ILibAsyncSocket_SendData), 0, NULL, NULL);
|
data = (ILibAsyncSocket_SendData*)ILibMemory_Allocate(sizeof(ILibAsyncSocket_SendData), 0, NULL, NULL);
|
||||||
if (UserFree == ILibAsyncSocket_MemoryOwnership_USER)
|
if (UserFree == ILibAsyncSocket_MemoryOwnership_USER)
|
||||||
{
|
{
|
||||||
data->bufferSize = bufferLen - bytesSent;
|
data->bufferSize = (int)bufferLen - bytesSent; // No dataloss, capped to INT32_MAX
|
||||||
if ((data->buffer = (char*)malloc(data->bufferSize)) == NULL) ILIBCRITICALEXIT(254);
|
if ((data->buffer = (char*)malloc(data->bufferSize)) == NULL) ILIBCRITICALEXIT(254);
|
||||||
memcpy_s(data->buffer, data->bufferSize, buffer + bytesSent, data->bufferSize);
|
memcpy_s(data->buffer, data->bufferSize, buffer + bytesSent, data->bufferSize);
|
||||||
data->UserFree = ILibAsyncSocket_MemoryOwnership_CHAIN;
|
data->UserFree = ILibAsyncSocket_MemoryOwnership_CHAIN;
|
||||||
@@ -732,14 +754,14 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_SendTo_MultiWrite(ILibAsyncSocket_Soc
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
data->buffer = buffer;
|
data->buffer = buffer;
|
||||||
data->bufferSize = bufferLen;
|
data->bufferSize = (int)bufferLen; // No dataloss, capped to INT32_MAX
|
||||||
data->bytesSent = bytesSent;
|
data->bytesSent = bytesSent;
|
||||||
data->UserFree = UserFree;
|
data->UserFree = UserFree;
|
||||||
}
|
}
|
||||||
module->PendingSend_Head = module->PendingSend_Tail = data;
|
module->PendingSend_Head = module->PendingSend_Tail = data;
|
||||||
retVal = ILibAsyncSocket_NOT_ALL_DATA_SENT_YET;
|
retVal = ILibAsyncSocket_NOT_ALL_DATA_SENT_YET;
|
||||||
}
|
}
|
||||||
else if (bytesSent == bufferLen)
|
else if (bytesSent == (int)bufferLen) // No dataloss, capped to INT32_MAX
|
||||||
{
|
{
|
||||||
// All Data was sent
|
// All Data was sent
|
||||||
retVal = ILibAsyncSocket_ALL_DATA_SENT;
|
retVal = ILibAsyncSocket_ALL_DATA_SENT;
|
||||||
@@ -760,6 +782,11 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_SendTo_MultiWrite(ILibAsyncSocket_Soc
|
|||||||
va_end(vlist);
|
va_end(vlist);
|
||||||
|
|
||||||
if (lockOverride == 0) { sem_post(&(module->SendLock)); }
|
if (lockOverride == 0) { sem_post(&(module->SendLock)); }
|
||||||
|
if (notok != 0)
|
||||||
|
{
|
||||||
|
retVal = ILibAsyncSocket_BUFFER_TOO_LARGE;
|
||||||
|
ILibAsyncSocket_SendError(module);
|
||||||
|
}
|
||||||
|
|
||||||
if (retVal != ILibAsyncSocket_ALL_DATA_SENT && !ILibIsRunningOnChainThread(module->Transport.ChainLink.ParentChain)) ILibForceUnBlockChain(module->Transport.ChainLink.ParentChain);
|
if (retVal != ILibAsyncSocket_ALL_DATA_SENT && !ILibIsRunningOnChainThread(module->Transport.ChainLink.ParentChain)) ILibForceUnBlockChain(module->Transport.ChainLink.ParentChain);
|
||||||
return (retVal);
|
return (retVal);
|
||||||
|
|||||||
@@ -60,7 +60,8 @@ typedef enum ILibAsyncSocket_SendStatus
|
|||||||
{
|
{
|
||||||
ILibAsyncSocket_ALL_DATA_SENT = 1, /*!< All of the data has already been sent */
|
ILibAsyncSocket_ALL_DATA_SENT = 1, /*!< All of the data has already been sent */
|
||||||
ILibAsyncSocket_NOT_ALL_DATA_SENT_YET = 0, /*!< Not all of the data could be sent, but is queued to be sent as soon as possible */
|
ILibAsyncSocket_NOT_ALL_DATA_SENT_YET = 0, /*!< Not all of the data could be sent, but is queued to be sent as soon as possible */
|
||||||
ILibAsyncSocket_SEND_ON_CLOSED_SOCKET_ERROR = -4 /*!< A send operation was attmepted on a closed socket */
|
ILibAsyncSocket_SEND_ON_CLOSED_SOCKET_ERROR = -4, /*!< A send operation was attmepted on a closed socket */
|
||||||
|
ILibAsyncSocket_BUFFER_TOO_LARGE = -5
|
||||||
}ILibAsyncSocket_SendStatus;
|
}ILibAsyncSocket_SendStatus;
|
||||||
|
|
||||||
/*! \enum ILibAsyncSocket_MemoryOwnership
|
/*! \enum ILibAsyncSocket_MemoryOwnership
|
||||||
@@ -188,8 +189,8 @@ enum ILibAsyncSocket_SendStatus ILibAsyncSocket_SendTo_MultiWrite(ILibAsyncSocke
|
|||||||
\param UserFree The \a ILibAsyncSocket_MemoryOwnership enumeration, that identifies how the memory pointer to by \a buffer is to be handled
|
\param UserFree The \a ILibAsyncSocket_MemoryOwnership enumeration, that identifies how the memory pointer to by \a buffer is to be handled
|
||||||
\returns \a ILibAsyncSocket_SendStatus indicating the send status
|
\returns \a ILibAsyncSocket_SendStatus indicating the send status
|
||||||
*/
|
*/
|
||||||
#define ILibAsyncSocket_Send(socketModule, buffer, length, UserFree) ILibAsyncSocket_SendTo_MultiWrite(socketModule, NULL, 1, buffer, length, UserFree)
|
#define ILibAsyncSocket_Send(socketModule, buffer, length, UserFree) ILibAsyncSocket_SendTo_MultiWrite(socketModule, NULL, 1, buffer, (size_t)length, UserFree)
|
||||||
#define ILibAsyncSocket_SendTo(socketModule, buffer, length, remoteAddress, UserFree) ILibAsyncSocket_SendTo_MultiWrite(socketModule, remoteAddress, 1, buffer, length, UserFree)
|
#define ILibAsyncSocket_SendTo(socketModule, buffer, length, remoteAddress, UserFree) ILibAsyncSocket_SendTo_MultiWrite(socketModule, remoteAddress, 1, buffer, (size_t)length, UserFree)
|
||||||
|
|
||||||
void ILibAsyncSocket_Disconnect(ILibAsyncSocket_SocketModule socketModule);
|
void ILibAsyncSocket_Disconnect(ILibAsyncSocket_SocketModule socketModule);
|
||||||
void ILibAsyncSocket_GetBuffer(ILibAsyncSocket_SocketModule socketModule, char **buffer, int *BeginPointer, int *EndPointer);
|
void ILibAsyncSocket_GetBuffer(ILibAsyncSocket_SocketModule socketModule, char **buffer, int *BeginPointer, int *EndPointer);
|
||||||
|
|||||||
@@ -68,14 +68,14 @@ char utils_HexTable[16] = { '0','1','2','3','4','5','6','7','8','9','A','B','C',
|
|||||||
char utils_HexTable2[16] = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' };
|
char utils_HexTable2[16] = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' };
|
||||||
|
|
||||||
|
|
||||||
void __fastcall util_md5(char* data, int datalen, char* result)
|
void __fastcall util_md5(char* data, size_t datalen, char* result)
|
||||||
{
|
{
|
||||||
MD5_CTX c;
|
MD5_CTX c;
|
||||||
MD5_Init(&c);
|
MD5_Init(&c);
|
||||||
MD5_Update(&c, data, datalen);
|
MD5_Update(&c, data, datalen);
|
||||||
MD5_Final((unsigned char*)result, &c);
|
MD5_Final((unsigned char*)result, &c);
|
||||||
}
|
}
|
||||||
void __fastcall util_md5hex(char* data, int datalen, char *out)
|
void __fastcall util_md5hex(char* data, size_t datalen, char *out)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
unsigned char *temp = (unsigned char*)out;
|
unsigned char *temp = (unsigned char*)out;
|
||||||
@@ -94,7 +94,7 @@ void __fastcall util_md5hex(char* data, int datalen, char *out)
|
|||||||
|
|
||||||
*temp = '\0';
|
*temp = '\0';
|
||||||
}
|
}
|
||||||
void __fastcall util_sha1(char* data, int datalen, char* result)
|
void __fastcall util_sha1(char* data, size_t datalen, char* result)
|
||||||
{
|
{
|
||||||
SHA_CTX c;
|
SHA_CTX c;
|
||||||
SHA1_Init(&c);
|
SHA1_Init(&c);
|
||||||
@@ -102,14 +102,14 @@ void __fastcall util_sha1(char* data, int datalen, char* result)
|
|||||||
SHA1_Final((unsigned char*)result, &c);
|
SHA1_Final((unsigned char*)result, &c);
|
||||||
result[20] = 0;
|
result[20] = 0;
|
||||||
}
|
}
|
||||||
void __fastcall util_sha256(char* data, int datalen, char* result)
|
void __fastcall util_sha256(char* data, size_t datalen, char* result)
|
||||||
{
|
{
|
||||||
SHA256_CTX c;
|
SHA256_CTX c;
|
||||||
SHA256_Init(&c);
|
SHA256_Init(&c);
|
||||||
SHA256_Update(&c, data, datalen);
|
SHA256_Update(&c, data, datalen);
|
||||||
SHA256_Final((unsigned char*)result, &c);
|
SHA256_Final((unsigned char*)result, &c);
|
||||||
}
|
}
|
||||||
void __fastcall util_sha384(char* data, int datalen, char* result)
|
void __fastcall util_sha384(char* data, size_t datalen, char* result)
|
||||||
{
|
{
|
||||||
SHA512_CTX c;
|
SHA512_CTX c;
|
||||||
SHA384_Init(&c);
|
SHA384_Init(&c);
|
||||||
@@ -152,9 +152,9 @@ void __fastcall util_free(char* ptr)
|
|||||||
free(ptr);
|
free(ptr);
|
||||||
//ptr = NULL;
|
//ptr = NULL;
|
||||||
}
|
}
|
||||||
char* __fastcall util_tohex(char* data, int len, char* out)
|
char* __fastcall util_tohex(char* data, size_t len, char* out)
|
||||||
{
|
{
|
||||||
int i;
|
size_t i;
|
||||||
char *p = out;
|
char *p = out;
|
||||||
if (data == NULL || len == 0) { *p = 0; return NULL; }
|
if (data == NULL || len == 0) { *p = 0; return NULL; }
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
@@ -165,9 +165,9 @@ char* __fastcall util_tohex(char* data, int len, char* out)
|
|||||||
*p = 0;
|
*p = 0;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
char* __fastcall util_tohex_lower(char* data, int len, char* out)
|
char* __fastcall util_tohex_lower(char* data, size_t len, char* out)
|
||||||
{
|
{
|
||||||
int i;
|
size_t i;
|
||||||
char *p = out;
|
char *p = out;
|
||||||
if (data == NULL || len == 0) { *p = 0; return NULL; }
|
if (data == NULL || len == 0) { *p = 0; return NULL; }
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
@@ -178,9 +178,9 @@ char* __fastcall util_tohex_lower(char* data, int len, char* out)
|
|||||||
*p = 0;
|
*p = 0;
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
char* __fastcall util_tohex2(char* data, int len, char* out)
|
char* __fastcall util_tohex2(char* data, size_t len, char* out)
|
||||||
{
|
{
|
||||||
int i;
|
size_t i;
|
||||||
char *p = out;
|
char *p = out;
|
||||||
if (data == NULL || len == 0) { *p = 0; return NULL; }
|
if (data == NULL || len == 0) { *p = 0; return NULL; }
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
@@ -196,9 +196,10 @@ char* __fastcall util_tohex2(char* data, int len, char* out)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
// Convert hex string to int
|
// Convert hex string to int
|
||||||
int __fastcall util_hexToint(char *hexString, int hexStringLength)
|
int __fastcall util_hexToint(char *hexString, size_t hexStringLength)
|
||||||
{
|
{
|
||||||
int i, res = 0;
|
size_t i;
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
// Ignore the leading zeroes
|
// Ignore the leading zeroes
|
||||||
while (*hexString == '0' && hexStringLength > 0) { hexString++; hexStringLength--; }
|
while (*hexString == '0' && hexStringLength > 0) { hexString++; hexStringLength--; }
|
||||||
@@ -214,9 +215,9 @@ int __fastcall util_hexToint(char *hexString, int hexStringLength)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Convert hex string to int
|
// Convert hex string to int
|
||||||
int __fastcall util_hexToBuf(char *hexString, int hexStringLength, char* output)
|
size_t __fastcall util_hexToBuf(char *hexString, size_t hexStringLength, char* output)
|
||||||
{
|
{
|
||||||
int i, x = hexStringLength / 2;
|
size_t i, x = hexStringLength / 2;
|
||||||
for (i = 0; i < x; i++) { output[i] = (char)util_hexToint(hexString + (i * 2), 2); }
|
for (i = 0; i < x; i++) { output[i] = (char)util_hexToint(hexString + (i * 2), 2); }
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,17 +23,17 @@ limitations under the License.
|
|||||||
#define __fastcall
|
#define __fastcall
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void __fastcall util_md5(char* data, int datalen, char* result);
|
void __fastcall util_md5(char* data, size_t datalen, char* result);
|
||||||
void __fastcall util_md5hex(char* data, int datalen, char *out);
|
void __fastcall util_md5hex(char* data, size_t datalen, char *out);
|
||||||
void __fastcall util_sha1(char* data, int datalen, char* result);
|
void __fastcall util_sha1(char* data, size_t datalen, char* result);
|
||||||
char* __fastcall util_tohex(char* data, int len, char* out);
|
char* __fastcall util_tohex(char* data, size_t len, char* out);
|
||||||
char* __fastcall util_tohex2(char* data, int len, char* out);
|
char* __fastcall util_tohex2(char* data, size_t len, char* out);
|
||||||
char* __fastcall util_tohex_lower(char* data, int len, char* out);
|
char* __fastcall util_tohex_lower(char* data, size_t len, char* out);
|
||||||
int __fastcall util_hexToint(char *hexString, int hexStringLength);
|
int __fastcall util_hexToint(char *hexString, size_t hexStringLength);
|
||||||
int __fastcall util_hexToBuf(char *hexString, int hexStringLength, char* output);
|
size_t __fastcall util_hexToBuf(char *hexString, size_t hexStringLength, char* output);
|
||||||
|
|
||||||
void __fastcall util_sha256(char* data, int datalen, char* result);
|
void __fastcall util_sha256(char* data, size_t datalen, char* result);
|
||||||
void __fastcall util_sha384(char* data, int datalen, char* result);
|
void __fastcall util_sha384(char* data, size_t datalen, char* result);
|
||||||
int __fastcall util_sha384file(char* filename, char* result);
|
int __fastcall util_sha384file(char* filename, char* result);
|
||||||
|
|
||||||
// File and data methods
|
// File and data methods
|
||||||
|
|||||||
@@ -1081,7 +1081,6 @@ int ILib_atoi_uint64_ex(uint64_t *val, const char *instr, size_t instrLen, uint6
|
|||||||
{
|
{
|
||||||
char* eptr;
|
char* eptr;
|
||||||
*val = strtoull(instr, &eptr, 10);
|
*val = strtoull(instr, &eptr, 10);
|
||||||
int e = errno;
|
|
||||||
if (errno == ERANGE || eptr == instr || *val > MAX)
|
if (errno == ERANGE || eptr == instr || *val > MAX)
|
||||||
{
|
{
|
||||||
*val = 0;
|
*val = 0;
|
||||||
@@ -1175,17 +1174,17 @@ void* ILibMemory_AllocateA_Get(void *buffer, size_t sz)
|
|||||||
|
|
||||||
return(retVal);
|
return(retVal);
|
||||||
}
|
}
|
||||||
void* ILibMemory_Allocate(int containerSize, int extraMemorySize, void** allocatedContainer, void **extraMemory)
|
void* ILibMemory_Allocate(size_t containerSize, size_t extraMemorySize, void** allocatedContainer, void **extraMemory)
|
||||||
{
|
{
|
||||||
if (!((containerSize < (INT32_MAX - extraMemorySize)) && (containerSize + extraMemorySize) < (INT32_MAX - 4))) { ILIBCRITICALEXIT(254); }
|
if (!((containerSize < (SIZE_MAX - extraMemorySize)) && (containerSize + extraMemorySize) < (SIZE_MAX - sizeof(size_t)))) { ILIBCRITICALEXIT(254); }
|
||||||
|
|
||||||
char* retVal = (char*)malloc(containerSize + extraMemorySize + (extraMemorySize > 0 ? 4 : 0));
|
char* retVal = (char*)malloc(containerSize + extraMemorySize + (extraMemorySize > 0 ? sizeof(size_t) : 0));
|
||||||
if (retVal == NULL) { ILIBCRITICALEXIT(254); }
|
if (retVal == NULL) { ILIBCRITICALEXIT(254); }
|
||||||
memset(retVal, 0, containerSize + extraMemorySize + (extraMemorySize > 0 ? 4 : 0));
|
memset(retVal, 0, containerSize + extraMemorySize + (extraMemorySize > 0 ? sizeof(size_t) : 0));
|
||||||
if (extraMemorySize > 0)
|
if (extraMemorySize > 0)
|
||||||
{
|
{
|
||||||
((int*)(retVal + containerSize))[0] = extraMemorySize;
|
((size_t*)(retVal + containerSize))[0] = extraMemorySize;
|
||||||
if (extraMemory != NULL) { *extraMemory = (retVal + containerSize + 4); }
|
if (extraMemory != NULL) { *extraMemory = (retVal + containerSize + sizeof(size_t)); }
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1194,17 +1193,17 @@ void* ILibMemory_Allocate(int containerSize, int extraMemorySize, void** allocat
|
|||||||
if (allocatedContainer != NULL) { *allocatedContainer = retVal; }
|
if (allocatedContainer != NULL) { *allocatedContainer = retVal; }
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
ILibExportMethod void* ILibMemory_GetExtraMemory(void *container, int containerSize)
|
ILibExportMethod void* ILibMemory_GetExtraMemory(void *container, size_t containerSize)
|
||||||
{
|
{
|
||||||
return(container == NULL ? NULL : ((char*)container + 4 + containerSize));
|
return(container == NULL ? NULL : ((char*)container + sizeof(size_t) + containerSize));
|
||||||
}
|
}
|
||||||
int ILibMemory_GetExtraMemorySize(void* extraMemory)
|
size_t ILibMemory_GetExtraMemorySize(void* extraMemory)
|
||||||
{
|
{
|
||||||
if (extraMemory == NULL) { return 0; }
|
if (extraMemory == NULL) { return 0; }
|
||||||
return(((int*)((char*)extraMemory - 4))[0]);
|
return(((size_t*)((char*)extraMemory - sizeof(size_t)))[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
ILibChain_Link* ILibChain_Link_Allocate(int structSize, int extraMemorySize)
|
ILibChain_Link* ILibChain_Link_Allocate(size_t structSize, size_t extraMemorySize)
|
||||||
{
|
{
|
||||||
ILibChain_Link *retVal;
|
ILibChain_Link *retVal;
|
||||||
void* extraMemory;
|
void* extraMemory;
|
||||||
@@ -1212,7 +1211,7 @@ ILibChain_Link* ILibChain_Link_Allocate(int structSize, int extraMemorySize)
|
|||||||
retVal->ExtraMemoryPtr = extraMemory;
|
retVal->ExtraMemoryPtr = extraMemory;
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
int ILibChain_Link_GetExtraMemorySize(ILibChain_Link* link)
|
size_t ILibChain_Link_GetExtraMemorySize(ILibChain_Link* link)
|
||||||
{
|
{
|
||||||
return(ILibMemory_GetExtraMemorySize(link->ExtraMemoryPtr));
|
return(ILibMemory_GetExtraMemorySize(link->ExtraMemoryPtr));
|
||||||
}
|
}
|
||||||
@@ -3211,7 +3210,7 @@ char *ILibChain_MetaData(char *file, int number)
|
|||||||
}
|
}
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
BOOL ILibChain_WriteEx_Sink(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, void *user);
|
BOOL ILibChain_WriteEx_Sink(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, void *user);
|
||||||
BOOL ILibChain_WriteEx_Sink2(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, int bytesWritten, void *user)
|
BOOL ILibChain_WriteEx_Sink2(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, DWORD bytesWritten, void *user)
|
||||||
{
|
{
|
||||||
return(ILibChain_WriteEx_Sink(chain, h, status, user));
|
return(ILibChain_WriteEx_Sink(chain, h, status, user));
|
||||||
}
|
}
|
||||||
@@ -3312,9 +3311,11 @@ BOOL ILibChain_ReadEx_Sink(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus sta
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ILibTransport_DoneState ILibChain_WriteEx2(void *chain, HANDLE h, OVERLAPPED *p, char *buffer, int bufferLen, ILibChain_WriteEx_Handler handler, void *user, char *metadata)
|
ILibTransport_DoneState ILibChain_WriteEx2(void *chain, HANDLE h, OVERLAPPED *p, char *buffer, DWORD bufferLen, ILibChain_WriteEx_Handler handler, void *user, char *metadata)
|
||||||
{
|
{
|
||||||
int e = 0;
|
int e = 0;
|
||||||
|
if (bufferLen > UINT32_MAX) { return(ILibTransport_DoneState_ERROR); }
|
||||||
|
|
||||||
if (!WriteFile(h, buffer, (DWORD)bufferLen, NULL, p))
|
if (!WriteFile(h, buffer, (DWORD)bufferLen, NULL, p))
|
||||||
{
|
{
|
||||||
if ((e = GetLastError()) == ERROR_IO_PENDING)
|
if ((e = GetLastError()) == ERROR_IO_PENDING)
|
||||||
@@ -3322,7 +3323,7 @@ ILibTransport_DoneState ILibChain_WriteEx2(void *chain, HANDLE h, OVERLAPPED *p,
|
|||||||
// Completing Asynchronously
|
// Completing Asynchronously
|
||||||
ILibChain_WriteEx_data *state = (ILibChain_WriteEx_data*)ILibMemory_SmartAllocate(sizeof(ILibChain_WriteEx_data));
|
ILibChain_WriteEx_data *state = (ILibChain_WriteEx_data*)ILibMemory_SmartAllocate(sizeof(ILibChain_WriteEx_data));
|
||||||
state->buffer = buffer;
|
state->buffer = buffer;
|
||||||
state->bytesLeft = bufferLen;
|
state->bytesLeft = (DWORD)bufferLen;
|
||||||
state->totalWritten = 0;
|
state->totalWritten = 0;
|
||||||
state->p = p;
|
state->p = p;
|
||||||
state->handler = handler;
|
state->handler = handler;
|
||||||
@@ -3351,7 +3352,7 @@ void ILibChain_ReadEx2_UnwindHandler(void *chain, void *user)
|
|||||||
state->handler(chain, state->fileHandle, ILibWaitHandle_ErrorStatus_NONE, state->buffer, (int)(uintptr_t)state->p, state->user);
|
state->handler(chain, state->fileHandle, ILibWaitHandle_ErrorStatus_NONE, state->buffer, (int)(uintptr_t)state->p, state->user);
|
||||||
free(state);
|
free(state);
|
||||||
}
|
}
|
||||||
void ILibChain_ReadEx2(void *chain, HANDLE h, OVERLAPPED *p, char *buffer, int bufferLen, ILibChain_ReadEx_Handler handler, void *user, char *metadata)
|
void ILibChain_ReadEx2(void *chain, HANDLE h, OVERLAPPED *p, char *buffer, DWORD bufferLen, ILibChain_ReadEx_Handler handler, void *user, char *metadata)
|
||||||
{
|
{
|
||||||
DWORD bytesRead = 0;
|
DWORD bytesRead = 0;
|
||||||
int e = 0;
|
int e = 0;
|
||||||
@@ -3432,7 +3433,7 @@ void* ILibChain_WaitHandle_RemoveAndSaveState(void *chain, HANDLE h)
|
|||||||
}
|
}
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
void* ILibChain_ReadAndSaveStateEx(void *chain, HANDLE h, OVERLAPPED *p, char *buffer, int bufferLen, ILibChain_ReadEx_Handler handler, void *user, char *metadata)
|
void* ILibChain_ReadAndSaveStateEx(void *chain, HANDLE h, OVERLAPPED *p, char *buffer, DWORD bufferLen, ILibChain_ReadEx_Handler handler, void *user, char *metadata)
|
||||||
{
|
{
|
||||||
int metaDataLen = (int)(metadata == NULL ? 0 : strnlen_s(metadata, 1024));
|
int metaDataLen = (int)(metadata == NULL ? 0 : strnlen_s(metadata, 1024));
|
||||||
ILibChain_WaitHandleInfo *ret = (ILibChain_WaitHandleInfo*)ILibMemory_SmartAllocate(8 + metaDataLen + sizeof(ILibChain_WaitHandleInfo));
|
ILibChain_WaitHandleInfo *ret = (ILibChain_WaitHandleInfo*)ILibMemory_SmartAllocate(8 + metaDataLen + sizeof(ILibChain_WaitHandleInfo));
|
||||||
@@ -4445,17 +4446,17 @@ The strings are never copied. Everything is referenced via pointers into the ori
|
|||||||
\param length Length of \a buffer
|
\param length Length of \a buffer
|
||||||
\return A tree of ILibXMLNodes, representing the XML document
|
\return A tree of ILibXMLNodes, representing the XML document
|
||||||
*/
|
*/
|
||||||
struct ILibXMLNode *ILibParseXML(char *buffer, int offset, int length)
|
struct ILibXMLNode *ILibParseXML(char *buffer, size_t offset, size_t length)
|
||||||
{
|
{
|
||||||
struct parser_result *xml;
|
struct parser_result *xml;
|
||||||
struct parser_result_field *field;
|
struct parser_result_field *field;
|
||||||
struct parser_result *temp2;
|
struct parser_result *temp2;
|
||||||
struct parser_result *temp3;
|
struct parser_result *temp3;
|
||||||
char* TagName;
|
char* TagName;
|
||||||
int TagNameLength;
|
size_t TagNameLength;
|
||||||
int StartTag;
|
int StartTag;
|
||||||
int EmptyTag;
|
int EmptyTag;
|
||||||
int i;
|
size_t i;
|
||||||
int wsi;
|
int wsi;
|
||||||
|
|
||||||
struct ILibXMLNode *RetVal = NULL;
|
struct ILibXMLNode *RetVal = NULL;
|
||||||
@@ -4463,10 +4464,10 @@ struct ILibXMLNode *ILibParseXML(char *buffer, int offset, int length)
|
|||||||
struct ILibXMLNode *x = NULL;
|
struct ILibXMLNode *x = NULL;
|
||||||
|
|
||||||
char *NSTag;
|
char *NSTag;
|
||||||
int NSTagLength;
|
size_t NSTagLength;
|
||||||
|
|
||||||
char *CommentEnd = 0;
|
char *CommentEnd = 0;
|
||||||
int CommentIndex;
|
size_t CommentIndex;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Even though "technically" the first character of an XML document must be <
|
// Even though "technically" the first character of an XML document must be <
|
||||||
@@ -4980,7 +4981,7 @@ void ILibHashTree_GetValue(void *tree_enumerator, char **key, int *keyLength, vo
|
|||||||
\param[out] data The data of the current item
|
\param[out] data The data of the current item
|
||||||
\param[out] dataEx The extended data of the current item
|
\param[out] dataEx The extended data of the current item
|
||||||
*/
|
*/
|
||||||
void ILibHashTree_GetValueEx(void *tree_enumerator, char **key, int *keyLength, void **data, int *dataEx)
|
void ILibHashTree_GetValueEx(void *tree_enumerator, char **key, size_t *keyLength, void **data, size_t *dataEx)
|
||||||
{
|
{
|
||||||
struct HashNodeEnumerator *en = (struct HashNodeEnumerator*)tree_enumerator;
|
struct HashNodeEnumerator *en = (struct HashNodeEnumerator*)tree_enumerator;
|
||||||
|
|
||||||
@@ -5042,9 +5043,9 @@ void* ILibInitHashTree_CaseInSensitiveEx(void *ReservedMemory)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ILibToUpper(const char *in, int inLength, char *out)
|
void ILibToUpper(const char *in, size_t inLength, char *out)
|
||||||
{
|
{
|
||||||
int i;
|
size_t i;
|
||||||
|
|
||||||
for(i = 0; i < inLength; ++i)
|
for(i = 0; i < inLength; ++i)
|
||||||
{
|
{
|
||||||
@@ -5060,9 +5061,9 @@ void ILibToUpper(const char *in, int inLength, char *out)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ILibToLower(const char *in, int inLength, char *out)
|
void ILibToLower(const char *in, size_t inLength, char *out)
|
||||||
{
|
{
|
||||||
int i;
|
size_t i;
|
||||||
|
|
||||||
for(i = 0; i < inLength; ++i)
|
for(i = 0; i < inLength; ++i)
|
||||||
{
|
{
|
||||||
@@ -5079,7 +5080,7 @@ void ILibToLower(const char *in, int inLength, char *out)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ILibGetHashValueEx(char *key, int keylength, int caseInSensitiveText)
|
int ILibGetHashValueEx(const char *key, size_t keylength, int caseInSensitiveText)
|
||||||
{
|
{
|
||||||
int HashValue=0;
|
int HashValue=0;
|
||||||
char TempValue[4];
|
char TempValue[4];
|
||||||
@@ -5147,7 +5148,7 @@ int ILibGetHashValueEx(char *key, int keylength, int caseInSensitiveText)
|
|||||||
return(HashValue);
|
return(HashValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! \fn ILibGetHashValue(char *key, int keylength)
|
/*! \fn ILibGetHashValue(char *key, size_t keylength)
|
||||||
\brief Calculates a numeric Hash from a given string
|
\brief Calculates a numeric Hash from a given string
|
||||||
\par
|
\par
|
||||||
Used by ILibHashTree methods
|
Used by ILibHashTree methods
|
||||||
@@ -5155,7 +5156,7 @@ Used by ILibHashTree methods
|
|||||||
\param keylength The length of the string to hash
|
\param keylength The length of the string to hash
|
||||||
\return A hash value
|
\return A hash value
|
||||||
*/
|
*/
|
||||||
int ILibGetHashValue(char *key, int keylength)
|
int ILibGetHashValue(const char *key, size_t keylength)
|
||||||
{
|
{
|
||||||
return(ILibGetHashValueEx(key,keylength,0));
|
return(ILibGetHashValueEx(key,keylength,0));
|
||||||
}
|
}
|
||||||
@@ -5165,14 +5166,14 @@ int ILibGetHashValue(char *key, int keylength)
|
|||||||
//
|
//
|
||||||
// Determines if a key entry exists in a HashTree, and creates it if requested
|
// Determines if a key entry exists in a HashTree, and creates it if requested
|
||||||
//
|
//
|
||||||
struct HashNode* ILibFindEntry(void *hashtree, void *key, int keylength, int create)
|
struct HashNode* ILibFindEntry(void *hashtree, const void *key, size_t keylength, int create)
|
||||||
{
|
{
|
||||||
|
if (keylength == 0 || keylength > INT32_MAX) { return(NULL); }
|
||||||
struct HashNode_Root *root = (struct HashNode_Root*)hashtree;
|
struct HashNode_Root *root = (struct HashNode_Root*)hashtree;
|
||||||
struct HashNode *current = root->Root;
|
struct HashNode *current = root->Root;
|
||||||
int HashValue = ILibGetHashValueEx(key, keylength, root->CaseInSensitive);
|
int HashValue = ILibGetHashValueEx(key, keylength, root->CaseInSensitive);
|
||||||
int done = 0;
|
int done = 0;
|
||||||
|
|
||||||
if (keylength == 0){return(NULL);}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Iterate through our tree to see if we can find this key entry
|
// Iterate through our tree to see if we can find this key entry
|
||||||
@@ -5219,7 +5220,7 @@ struct HashNode* ILibFindEntry(void *hashtree, void *key, int keylength, int cre
|
|||||||
if ((current->Next->KeyValue = (root->Reserved == NULL ? (void*)malloc(keylength + 1) : ILibMemory_AllocateA_Get(root->Reserved, keylength + 1))) == NULL) ILIBCRITICALEXIT(254);
|
if ((current->Next->KeyValue = (root->Reserved == NULL ? (void*)malloc(keylength + 1) : ILibMemory_AllocateA_Get(root->Reserved, keylength + 1))) == NULL) ILIBCRITICALEXIT(254);
|
||||||
memcpy_s(current->Next->KeyValue, keylength + 1, key ,keylength);
|
memcpy_s(current->Next->KeyValue, keylength + 1, key ,keylength);
|
||||||
current->Next->KeyValue[keylength] = 0;
|
current->Next->KeyValue[keylength] = 0;
|
||||||
current->Next->KeyLength = keylength;
|
current->Next->KeyLength = (int)keylength; // No dataloss, capped to INT32_MAX
|
||||||
return(current->Next);
|
return(current->Next);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -5237,7 +5238,7 @@ struct HashNode* ILibFindEntry(void *hashtree, void *key, int keylength, int cre
|
|||||||
\param keylength The length of the key
|
\param keylength The length of the key
|
||||||
\return 0 if does not exist, nonzero otherwise
|
\return 0 if does not exist, nonzero otherwise
|
||||||
*/
|
*/
|
||||||
int ILibHasEntry(void *hashtree, char* key, int keylength)
|
int ILibHasEntry(void *hashtree, const char* key, size_t keylength)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// This can be duplicated by calling Find entry, but setting the create flag to false
|
// This can be duplicated by calling Find entry, but setting the create flag to false
|
||||||
@@ -5252,7 +5253,7 @@ int ILibHasEntry(void *hashtree, char* key, int keylength)
|
|||||||
\param keylength The length of the key
|
\param keylength The length of the key
|
||||||
\param value The data to add into the HashTree
|
\param value The data to add into the HashTree
|
||||||
*/
|
*/
|
||||||
void ILibAddEntry(void* hashtree, char* key, int keylength, void *value)
|
void ILibAddEntry(void* hashtree, const char* key, size_t keylength, void *value)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// This can be duplicated by calling FindEntry, and setting create to true
|
// This can be duplicated by calling FindEntry, and setting create to true
|
||||||
@@ -5268,7 +5269,7 @@ void ILibAddEntry(void* hashtree, char* key, int keylength, void *value)
|
|||||||
\param value The data to add into the HashTree
|
\param value The data to add into the HashTree
|
||||||
\param valueEx An optional int value
|
\param valueEx An optional int value
|
||||||
*/
|
*/
|
||||||
void ILibAddEntryEx(void* hashtree, char* key, int keylength, void *value, int valueEx)
|
void ILibAddEntryEx(void* hashtree, const char* key, size_t keylength, void *value, int valueEx)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// This can be duplicated by calling FindEntry, and setting create to true
|
// This can be duplicated by calling FindEntry, and setting create to true
|
||||||
@@ -5289,7 +5290,7 @@ void ILibAddEntryEx(void* hashtree, char* key, int keylength, void *value, int v
|
|||||||
\param keylength The length of the key
|
\param keylength The length of the key
|
||||||
\return The data in the HashTree. NULL if key does not exist
|
\return The data in the HashTree. NULL if key does not exist
|
||||||
*/
|
*/
|
||||||
void* ILibGetEntry(void *hashtree, char* key, int keylength)
|
void* ILibGetEntry(void *hashtree, const char* key, size_t keylength)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// This can be duplicated by calling FindEntry and setting create to false.
|
// This can be duplicated by calling FindEntry and setting create to false.
|
||||||
@@ -5313,7 +5314,7 @@ void* ILibGetEntry(void *hashtree, char* key, int keylength)
|
|||||||
\param[out] value The data in the HashTree. NULL if key does not exist
|
\param[out] value The data in the HashTree. NULL if key does not exist
|
||||||
\param[out] valueEx The extended data in the HashTree.
|
\param[out] valueEx The extended data in the HashTree.
|
||||||
*/
|
*/
|
||||||
ILibExportMethod void ILibGetEntryEx(void *hashtree, char *key, int keyLength, void **value, int* valueEx)
|
ILibExportMethod void ILibGetEntryEx(void *hashtree, const char *key, size_t keyLength, void **value, int* valueEx)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// This can be duplicated by calling FindEntry and setting create to false.
|
// This can be duplicated by calling FindEntry and setting create to false.
|
||||||
@@ -5436,12 +5437,12 @@ int ILibGetULong(const char *TestValue, const int TestValueLength, unsigned long
|
|||||||
//
|
//
|
||||||
// Determines if a buffer offset is a delimiter
|
// Determines if a buffer offset is a delimiter
|
||||||
//
|
//
|
||||||
int ILibIsDelimiter (const char* buffer, int offset, int buffersize, const char* Delimiter, int DelimiterLength)
|
int ILibIsDelimiter (const char* buffer, size_t offset, size_t buffersize, const char* Delimiter, size_t DelimiterLength)
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// For simplicity sake, we'll assume a match unless proven otherwise
|
// For simplicity sake, we'll assume a match unless proven otherwise
|
||||||
//
|
//
|
||||||
int i=0;
|
size_t i=0;
|
||||||
int RetVal = 1;
|
int RetVal = 1;
|
||||||
if (DelimiterLength>buffersize)
|
if (DelimiterLength>buffersize)
|
||||||
{
|
{
|
||||||
@@ -5478,12 +5479,12 @@ quotation marks, whereas \a ILibParseString does not.
|
|||||||
\param DelimiterLength The length of the delimiter
|
\param DelimiterLength The length of the delimiter
|
||||||
\return A list of tokens
|
\return A list of tokens
|
||||||
*/
|
*/
|
||||||
struct parser_result* ILibParseStringAdv (char* buffer, int offset, int length, const char* Delimiter, int DelimiterLength)
|
struct parser_result* ILibParseStringAdv (const char* buffer, size_t offset, size_t length, const char* Delimiter, size_t DelimiterLength)
|
||||||
{
|
{
|
||||||
struct parser_result* RetVal;
|
struct parser_result* RetVal;
|
||||||
int i=0;
|
size_t i=0;
|
||||||
char* Token = NULL;
|
const char* Token = NULL;
|
||||||
int TokenLength = 0;
|
size_t TokenLength = 0;
|
||||||
struct parser_result_field *p_resultfield;
|
struct parser_result_field *p_resultfield;
|
||||||
int Ignore = 0;
|
int Ignore = 0;
|
||||||
char StringDelimiter=0;
|
char StringDelimiter=0;
|
||||||
@@ -5540,7 +5541,7 @@ struct parser_result* ILibParseStringAdv (char* buffer, int offset, int length,
|
|||||||
// We found a delimiter in the string
|
// We found a delimiter in the string
|
||||||
//
|
//
|
||||||
if ((p_resultfield = (struct parser_result_field*)malloc(sizeof(struct parser_result_field))) == NULL) ILIBCRITICALEXIT(253);
|
if ((p_resultfield = (struct parser_result_field*)malloc(sizeof(struct parser_result_field))) == NULL) ILIBCRITICALEXIT(253);
|
||||||
p_resultfield->data = Token;
|
p_resultfield->data = (char*)Token;
|
||||||
p_resultfield->datalength = TokenLength;
|
p_resultfield->datalength = TokenLength;
|
||||||
p_resultfield->NextResult = NULL;
|
p_resultfield->NextResult = NULL;
|
||||||
if (RetVal->FirstResult != NULL)
|
if (RetVal->FirstResult != NULL)
|
||||||
@@ -5578,7 +5579,7 @@ struct parser_result* ILibParseStringAdv (char* buffer, int offset, int length,
|
|||||||
// last delimiter is the token
|
// last delimiter is the token
|
||||||
//
|
//
|
||||||
if ((p_resultfield = (struct parser_result_field*)malloc(sizeof(struct parser_result_field))) == NULL) ILIBCRITICALEXIT(254);
|
if ((p_resultfield = (struct parser_result_field*)malloc(sizeof(struct parser_result_field))) == NULL) ILIBCRITICALEXIT(254);
|
||||||
p_resultfield->data = Token;
|
p_resultfield->data = (char*)Token;
|
||||||
p_resultfield->datalength = TokenLength;
|
p_resultfield->datalength = TokenLength;
|
||||||
p_resultfield->NextResult = NULL;
|
p_resultfield->NextResult = NULL;
|
||||||
if (RetVal->FirstResult != NULL)
|
if (RetVal->FirstResult != NULL)
|
||||||
@@ -5602,7 +5603,7 @@ struct parser_result* ILibParseStringAdv (char* buffer, int offset, int length,
|
|||||||
\param length Length of \a theString
|
\param length Length of \a theString
|
||||||
\return Length of the trimmed string
|
\return Length of the trimmed string
|
||||||
*/
|
*/
|
||||||
int ILibTrimString(char **theString, int length)
|
size_t ILibTrimString(char **theString, size_t length)
|
||||||
{
|
{
|
||||||
while (length > 0 && ((*theString)[0] == 9 || (*theString)[0] == 32)) { length--; (*theString)++; } // Remove any blank chars at the start
|
while (length > 0 && ((*theString)[0] == 9 || (*theString)[0] == 32)) { length--; (*theString)++; } // Remove any blank chars at the start
|
||||||
while (length > 0 && ((*theString)[length - 1] == 9 || (*theString)[length - 1] == 32)) { length--; } // Remove any blank chars at the end
|
while (length > 0 && ((*theString)[length - 1] == 9 || (*theString)[length - 1] == 32)) { length--; } // Remove any blank chars at the end
|
||||||
@@ -5621,10 +5622,10 @@ quotation marks, whereas \a ILibParseStringAdv does.
|
|||||||
\param DelimiterLength The length of the delimiter
|
\param DelimiterLength The length of the delimiter
|
||||||
\return A list of tokens
|
\return A list of tokens
|
||||||
*/
|
*/
|
||||||
struct parser_result* ILibParseString(char* buffer, int offset, int length, const char* Delimiter, int DelimiterLength)
|
struct parser_result* ILibParseString(const char* buffer, size_t offset, size_t length, const char* Delimiter, size_t DelimiterLength)
|
||||||
{
|
{
|
||||||
int i = 0;
|
size_t i = 0;
|
||||||
char* Token = NULL;
|
const char* Token = NULL;
|
||||||
int TokenLength = 0;
|
int TokenLength = 0;
|
||||||
struct parser_result* RetVal;
|
struct parser_result* RetVal;
|
||||||
struct parser_result_field *p_resultfield;
|
struct parser_result_field *p_resultfield;
|
||||||
@@ -5650,7 +5651,7 @@ struct parser_result* ILibParseString(char* buffer, int offset, int length, cons
|
|||||||
// We found a delimiter in the string
|
// We found a delimiter in the string
|
||||||
//
|
//
|
||||||
if ((p_resultfield = (struct parser_result_field*)malloc(sizeof(struct parser_result_field))) == NULL) ILIBCRITICALEXIT(254);
|
if ((p_resultfield = (struct parser_result_field*)malloc(sizeof(struct parser_result_field))) == NULL) ILIBCRITICALEXIT(254);
|
||||||
p_resultfield->data = Token;
|
p_resultfield->data = (char*)Token;
|
||||||
p_resultfield->datalength = TokenLength;
|
p_resultfield->datalength = TokenLength;
|
||||||
p_resultfield->NextResult = NULL;
|
p_resultfield->NextResult = NULL;
|
||||||
if (RetVal->FirstResult != NULL)
|
if (RetVal->FirstResult != NULL)
|
||||||
@@ -5688,7 +5689,7 @@ struct parser_result* ILibParseString(char* buffer, int offset, int length, cons
|
|||||||
// last delimiter is the token
|
// last delimiter is the token
|
||||||
//
|
//
|
||||||
if ((p_resultfield = (struct parser_result_field*)malloc(sizeof(struct parser_result_field))) == NULL) ILIBCRITICALEXIT(254);
|
if ((p_resultfield = (struct parser_result_field*)malloc(sizeof(struct parser_result_field))) == NULL) ILIBCRITICALEXIT(254);
|
||||||
p_resultfield->data = Token;
|
p_resultfield->data = (char*)Token;
|
||||||
p_resultfield->datalength = TokenLength;
|
p_resultfield->datalength = TokenLength;
|
||||||
p_resultfield->NextResult = NULL;
|
p_resultfield->NextResult = NULL;
|
||||||
if (RetVal->FirstResult != NULL)
|
if (RetVal->FirstResult != NULL)
|
||||||
@@ -5915,7 +5916,7 @@ int ILibInPlaceHTTPUnEscapeEx(char* data, int length)
|
|||||||
\param length The length of the buffer to parse
|
\param length The length of the buffer to parse
|
||||||
\return packetheader structure
|
\return packetheader structure
|
||||||
*/
|
*/
|
||||||
struct packetheader* ILibParsePacketHeader(char* buffer, int offset, int length)
|
struct packetheader* ILibParsePacketHeader(char* buffer, size_t offset, size_t length)
|
||||||
{
|
{
|
||||||
struct packetheader *RetVal;
|
struct packetheader *RetVal;
|
||||||
struct parser_result *_packet;
|
struct parser_result *_packet;
|
||||||
@@ -6110,7 +6111,10 @@ struct packetheader* ILibParsePacketHeader(char* buffer, int offset, int length)
|
|||||||
RetVal->LastField->NextField = node; // Note: Klocwork says LastField could be NULL/dereferenced, but LastField is never going to be NULL.
|
RetVal->LastField->NextField = node; // Note: Klocwork says LastField could be NULL/dereferenced, but LastField is never going to be NULL.
|
||||||
}
|
}
|
||||||
RetVal->LastField = node;
|
RetVal->LastField = node;
|
||||||
ILibAddEntryEx(RetVal->HeaderTable,node->Field,node->FieldLength,node->FieldData,node->FieldDataLength);
|
if (node->FieldDataLength <= INT32_MAX)
|
||||||
|
{
|
||||||
|
ILibAddEntryEx(RetVal->HeaderTable, node->Field, node->FieldLength, node->FieldData, (int)node->FieldDataLength); // No data loss, capped at INT32_MAX
|
||||||
|
}
|
||||||
}
|
}
|
||||||
HeaderLine = HeaderLine->NextResult;
|
HeaderLine = HeaderLine->NextResult;
|
||||||
}
|
}
|
||||||
@@ -6128,9 +6132,9 @@ struct packetheader* ILibParsePacketHeader(char* buffer, int offset, int length)
|
|||||||
\param tokenLength The maximum size of each fragment or token
|
\param tokenLength The maximum size of each fragment or token
|
||||||
\return The length of the buffer required to call \a ILibFragmentText
|
\return The length of the buffer required to call \a ILibFragmentText
|
||||||
*/
|
*/
|
||||||
int ILibFragmentTextLength(char *text, int textLength, char *delimiter, int delimiterLength, int tokenLength)
|
size_t ILibFragmentTextLength(char *text, size_t textLength, char *delimiter, size_t delimiterLength, size_t tokenLength)
|
||||||
{
|
{
|
||||||
int RetVal;
|
size_t RetVal;
|
||||||
|
|
||||||
UNREFERENCED_PARAMETER( text );
|
UNREFERENCED_PARAMETER( text );
|
||||||
UNREFERENCED_PARAMETER( delimiter );
|
UNREFERENCED_PARAMETER( delimiter );
|
||||||
@@ -6149,12 +6153,12 @@ int ILibFragmentTextLength(char *text, int textLength, char *delimiter, int deli
|
|||||||
\param RetVal The buffer to store the resultant string
|
\param RetVal The buffer to store the resultant string
|
||||||
\return The length of the written string
|
\return The length of the written string
|
||||||
*/
|
*/
|
||||||
int ILibFragmentText(char *text, int textLength, char *delimiter, int delimiterLength, int tokenLength, char **RetVal)
|
size_t ILibFragmentText(char *text, size_t textLength, char *delimiter, size_t delimiterLength, size_t tokenLength, char **RetVal)
|
||||||
{
|
{
|
||||||
char *Buffer;
|
char *Buffer;
|
||||||
int i=0,i2=0;
|
size_t i=0,i2=0;
|
||||||
int BufferSize = 0;
|
size_t BufferSize = 0;
|
||||||
int allocSize = ILibFragmentTextLength(text, textLength, delimiter, delimiterLength, tokenLength);
|
size_t allocSize = ILibFragmentTextLength(text, textLength, delimiter, delimiterLength, tokenLength);
|
||||||
if ((*RetVal = (char*)malloc(allocSize)) == NULL) ILIBCRITICALEXIT(254);
|
if ((*RetVal = (char*)malloc(allocSize)) == NULL) ILIBCRITICALEXIT(254);
|
||||||
|
|
||||||
Buffer = *RetVal;
|
Buffer = *RetVal;
|
||||||
@@ -6184,18 +6188,18 @@ int ILibFragmentText(char *text, int textLength, char *delimiter, int delimiterL
|
|||||||
\param[out] RetVal The output char* buffer
|
\param[out] RetVal The output char* buffer
|
||||||
\return The length of the output buffer
|
\return The length of the output buffer
|
||||||
*/
|
*/
|
||||||
int ILibGetRawPacket(struct packetheader* packet, char **RetVal)
|
size_t ILibGetRawPacket(struct packetheader* packet, char **RetVal)
|
||||||
{
|
{
|
||||||
int i,i2;
|
size_t i,i2;
|
||||||
int BufferSize = 0;
|
size_t BufferSize = 0;
|
||||||
char* Buffer, *temp;
|
char* Buffer, *temp;
|
||||||
|
|
||||||
void *en;
|
void *en;
|
||||||
|
|
||||||
char *Field;
|
char *Field;
|
||||||
int FieldLength;
|
size_t FieldLength;
|
||||||
void *FieldData;
|
void *FieldData;
|
||||||
int FieldDataLength;
|
size_t FieldDataLength;
|
||||||
|
|
||||||
if (packet->StatusCode != -1)
|
if (packet->StatusCode != -1)
|
||||||
{
|
{
|
||||||
@@ -6221,7 +6225,7 @@ int ILibGetRawPacket(struct packetheader* packet, char **RetVal)
|
|||||||
while (ILibHashTree_MoveNext(en)==0)
|
while (ILibHashTree_MoveNext(en)==0)
|
||||||
{
|
{
|
||||||
ILibHashTree_GetValueEx(en,&Field,&FieldLength,(void**)&FieldData,&FieldDataLength);
|
ILibHashTree_GetValueEx(en,&Field,&FieldLength,(void**)&FieldData,&FieldDataLength);
|
||||||
if (FieldDataLength < 0) { continue; }
|
if (FieldDataLength == (size_t)(-1)) { continue; }
|
||||||
//
|
//
|
||||||
// A conservative estimate adding the lengths of the header name and value, plus
|
// A conservative estimate adding the lengths of the header name and value, plus
|
||||||
// 4 characters for the ':' and CRLF
|
// 4 characters for the ':' and CRLF
|
||||||
@@ -6291,7 +6295,7 @@ int ILibGetRawPacket(struct packetheader* packet, char **RetVal)
|
|||||||
while (ILibHashTree_MoveNext(en)==0)
|
while (ILibHashTree_MoveNext(en)==0)
|
||||||
{
|
{
|
||||||
ILibHashTree_GetValueEx(en,&Field,&FieldLength,(void**)&FieldData,&FieldDataLength);
|
ILibHashTree_GetValueEx(en,&Field,&FieldLength,(void**)&FieldData,&FieldDataLength);
|
||||||
if (FieldDataLength < 0) { continue; }
|
if (FieldDataLength == (size_t)(-1)) { continue; }
|
||||||
|
|
||||||
//
|
//
|
||||||
// Write each header
|
// Write each header
|
||||||
@@ -6378,10 +6382,10 @@ ILibParseUriResult ILibParseUriEx (const char* URI, size_t URILen, char** Addr,
|
|||||||
{
|
{
|
||||||
struct parser_result *result, *result2, *result3;
|
struct parser_result *result, *result2, *result3;
|
||||||
char *TempString, *TempString2;
|
char *TempString, *TempString2;
|
||||||
int TempStringLength, TempStringLength2;
|
size_t TempStringLength, TempStringLength2;
|
||||||
unsigned short lport;
|
unsigned short lport;
|
||||||
char* laddr = NULL;
|
char* laddr = NULL;
|
||||||
int laddrLen = 0;
|
size_t laddrLen = 0;
|
||||||
|
|
||||||
ILibParseUriResult retVal = ILibParseUriResult_UNKNOWN_SCHEME;
|
ILibParseUriResult retVal = ILibParseUriResult_UNKNOWN_SCHEME;
|
||||||
|
|
||||||
@@ -6611,7 +6615,7 @@ struct packetheader* ILibClonePacket(struct packetheader *packet)
|
|||||||
\param Version The version string to write. eg: 1.1
|
\param Version The version string to write. eg: 1.1
|
||||||
\param VersionLength The length of the \a Version
|
\param VersionLength The length of the \a Version
|
||||||
*/
|
*/
|
||||||
void ILibSetVersion(struct packetheader *packet, char* Version, int VersionLength)
|
void ILibSetVersion(struct packetheader *packet, char* Version, size_t VersionLength)
|
||||||
{
|
{
|
||||||
if (packet->UserAllocVersion!=0) {free(packet->Version);}
|
if (packet->UserAllocVersion!=0) {free(packet->Version);}
|
||||||
packet->UserAllocVersion = 1;
|
packet->UserAllocVersion = 1;
|
||||||
@@ -6627,7 +6631,7 @@ void ILibSetVersion(struct packetheader *packet, char* Version, int VersionLengt
|
|||||||
\param StatusData The status string, eg: OK
|
\param StatusData The status string, eg: OK
|
||||||
\param StatusDataLength The length of \a StatusData
|
\param StatusDataLength The length of \a StatusData
|
||||||
*/
|
*/
|
||||||
void ILibSetStatusCode(struct packetheader *packet, int StatusCode, char *StatusData, int StatusDataLength)
|
void ILibSetStatusCode(struct packetheader *packet, int StatusCode, char *StatusData, size_t StatusDataLength)
|
||||||
{
|
{
|
||||||
if (StatusDataLength < 0) { StatusDataLength = (int)strnlen_s(StatusData, 255); }
|
if (StatusDataLength < 0) { StatusDataLength = (int)strnlen_s(StatusData, 255); }
|
||||||
packet->StatusCode = StatusCode;
|
packet->StatusCode = StatusCode;
|
||||||
@@ -6646,7 +6650,7 @@ void ILibSetStatusCode(struct packetheader *packet, int StatusCode, char *Status
|
|||||||
\param DirectiveObj The path component of the method, eg: \b /index.html
|
\param DirectiveObj The path component of the method, eg: \b /index.html
|
||||||
\param DirectiveObjLength The length of \a DirectiveObj
|
\param DirectiveObjLength The length of \a DirectiveObj
|
||||||
*/
|
*/
|
||||||
void ILibSetDirective(struct packetheader *packet, char* Directive, int DirectiveLength, char* DirectiveObj, int DirectiveObjLength)
|
void ILibSetDirective(struct packetheader *packet, char* Directive, size_t DirectiveLength, char* DirectiveObj, size_t DirectiveObjLength)
|
||||||
{
|
{
|
||||||
if (DirectiveLength < 0)DirectiveLength = (int)strnlen_s(Directive, 255);
|
if (DirectiveLength < 0)DirectiveLength = (int)strnlen_s(Directive, 255);
|
||||||
if (DirectiveObjLength < 0)DirectiveObjLength = (int)strnlen_s(DirectiveObj, 255);
|
if (DirectiveObjLength < 0)DirectiveObjLength = (int)strnlen_s(DirectiveObj, 255);
|
||||||
@@ -6712,11 +6716,11 @@ void ILibDeleteHeaderLine(struct packetheader *packet, char* FieldName, int Fiel
|
|||||||
\param FieldData The header value, eg: \b text/xml
|
\param FieldData The header value, eg: \b text/xml
|
||||||
\param FieldDataLength The length of the \a FieldData
|
\param FieldDataLength The length of the \a FieldData
|
||||||
*/
|
*/
|
||||||
void ILibAddHeaderLine(struct packetheader *packet, const char* FieldName, int FieldNameLength, const char* FieldData, int FieldDataLength)
|
void ILibAddHeaderLine(struct packetheader *packet, const char* FieldName, size_t FieldNameLength, const char* FieldData, size_t FieldDataLength)
|
||||||
{
|
{
|
||||||
struct packetheader_field_node *node;
|
struct packetheader_field_node *node;
|
||||||
if (FieldNameLength < 0) { FieldNameLength = (int)strnlen_s(FieldName, 255); }
|
if (FieldNameLength == 0 || FieldNameLength == (size_t)(-1)) { FieldNameLength = strnlen_s(FieldName, 255); }
|
||||||
if (FieldDataLength < 0) { FieldDataLength = (int)strnlen_s(FieldData, 255); }
|
if (FieldDataLength == 0 || FieldDataLength == (size_t)(-1)) { FieldDataLength = strnlen_s(FieldData, 255); }
|
||||||
if (packet->ReservedMemory != NULL)
|
if (packet->ReservedMemory != NULL)
|
||||||
{
|
{
|
||||||
if (ILibMemory_AllocateA_Size(packet->ReservedMemory) > (sizeof(struct packetheader_field_node) + FieldNameLength + FieldDataLength + 2))
|
if (ILibMemory_AllocateA_Size(packet->ReservedMemory) > (sizeof(struct packetheader_field_node) + FieldNameLength + FieldDataLength + 2))
|
||||||
@@ -6750,7 +6754,7 @@ void ILibAddHeaderLine(struct packetheader *packet, const char* FieldName, int F
|
|||||||
node->FieldDataLength = FieldDataLength;
|
node->FieldDataLength = FieldDataLength;
|
||||||
node->NextField = NULL;
|
node->NextField = NULL;
|
||||||
|
|
||||||
if (packet->HeaderTable != NULL) { ILibAddEntryEx(packet->HeaderTable, node->Field, node->FieldLength, node->FieldData, node->FieldDataLength); }
|
if (packet->HeaderTable != NULL) { ILibAddEntryEx(packet->HeaderTable, node->Field, node->FieldLength, node->FieldData,(int) node->FieldDataLength); } // No dataloss, capped to 255
|
||||||
|
|
||||||
//
|
//
|
||||||
// And attach it to the linked list
|
// And attach it to the linked list
|
||||||
@@ -7650,7 +7654,7 @@ void* ILibLinkedList_ShallowCopy(void *LinkedList)
|
|||||||
*/
|
*/
|
||||||
void* ILibLinkedList_GetNode_Head(void *LinkedList)
|
void* ILibLinkedList_GetNode_Head(void *LinkedList)
|
||||||
{
|
{
|
||||||
return(((struct ILibLinkedListNode_Root*)LinkedList)->Head);
|
return(LinkedList != NULL ? ((struct ILibLinkedListNode_Root*)LinkedList)->Head : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! \fn ILibLinkedList_GetNode_Tail(void *LinkedList)
|
/*! \fn ILibLinkedList_GetNode_Tail(void *LinkedList)
|
||||||
@@ -8581,13 +8585,16 @@ void ILibSparseArray_UnLock(ILibSparseArray sarray)
|
|||||||
sem_post(&(((ILibSparseArray_Root*)sarray)->LOCK));
|
sem_post(&(((ILibSparseArray_Root*)sarray)->LOCK));
|
||||||
}
|
}
|
||||||
|
|
||||||
int ILibString_IndexOfFirstWhiteSpace(const char *inString, int inStringLength)
|
int ILibString_IndexOfFirstWhiteSpace(const char *inString, size_t inStringLength)
|
||||||
{
|
{
|
||||||
//CR, LF, space, tab
|
//CR, LF, space, tab
|
||||||
int i = 0;
|
size_t i = 0;
|
||||||
for(i = 0;i < inStringLength; ++i)
|
for(i = 0;i < inStringLength; ++i)
|
||||||
{
|
{
|
||||||
if (inString[i] == 13 || inString[i] == 10 || inString[i] == 9 || inString[i] == 32) return(i);
|
if (inString[i] == 13 || inString[i] == 10 || inString[i] == 9 || inString[i] == 32)
|
||||||
|
{
|
||||||
|
return(i > INT32_MAX ? -1 : (int)i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
@@ -8601,11 +8608,11 @@ int ILibString_IndexOfFirstWhiteSpace(const char *inString, int inStringLength)
|
|||||||
\param caseSensitive 0 if the matching is case-insensitive
|
\param caseSensitive 0 if the matching is case-insensitive
|
||||||
\return Non-zero if the string starts with the substring
|
\return Non-zero if the string starts with the substring
|
||||||
*/
|
*/
|
||||||
int ILibString_EndsWithEx(const char *inString, int inStringLength, const char *endWithString, int endWithStringLength, int caseSensitive)
|
int ILibString_EndsWithEx(const char *inString, size_t inStringLength, const char *endWithString, size_t endWithStringLength, int caseSensitive)
|
||||||
{
|
{
|
||||||
int RetVal = 0;
|
int RetVal = 0;
|
||||||
if (inStringLength < 0) { inStringLength = (int)strnlen_s(inString, sizeof(ILibScratchPad)); }
|
if (inStringLength == 0 || inStringLength == (size_t)(-1)) { inStringLength = strnlen_s(inString, sizeof(ILibScratchPad)); }
|
||||||
if (endWithStringLength < 0) { endWithStringLength = (int)strnlen_s(endWithString, sizeof(ILibScratchPad)); }
|
if (endWithStringLength == 0 || endWithStringLength == (size_t)(-1)) { endWithStringLength = strnlen_s(endWithString, sizeof(ILibScratchPad)); }
|
||||||
|
|
||||||
if (inStringLength>=endWithStringLength)
|
if (inStringLength>=endWithStringLength)
|
||||||
{
|
{
|
||||||
@@ -8622,7 +8629,7 @@ int ILibString_EndsWithEx(const char *inString, int inStringLength, const char *
|
|||||||
\param endWithStringLength The length of \a startsWithString
|
\param endWithStringLength The length of \a startsWithString
|
||||||
\return Non-zero if the string starts with the substring
|
\return Non-zero if the string starts with the substring
|
||||||
*/
|
*/
|
||||||
int ILibString_EndsWith(const char *inString, int inStringLength, const char *endWithString, int endWithStringLength)
|
int ILibString_EndsWith(const char *inString, size_t inStringLength, const char *endWithString, size_t endWithStringLength)
|
||||||
{
|
{
|
||||||
return(ILibString_EndsWithEx(inString,inStringLength,endWithString,endWithStringLength,1));
|
return(ILibString_EndsWithEx(inString,inStringLength,endWithString,endWithStringLength,1));
|
||||||
}
|
}
|
||||||
@@ -8635,7 +8642,7 @@ int ILibString_EndsWith(const char *inString, int inStringLength, const char *en
|
|||||||
\param caseSensitive Non-zero if match is to be case sensitive
|
\param caseSensitive Non-zero if match is to be case sensitive
|
||||||
\return Non-zero if the string starts with the substring
|
\return Non-zero if the string starts with the substring
|
||||||
*/
|
*/
|
||||||
int ILibString_StartsWithEx(const char *inString, int inStringLength, const char *startsWithString, int startsWithStringLength, int caseSensitive)
|
int ILibString_StartsWithEx(const char *inString, size_t inStringLength, const char *startsWithString, size_t startsWithStringLength, int caseSensitive)
|
||||||
{
|
{
|
||||||
int RetVal = 0;
|
int RetVal = 0;
|
||||||
if (inStringLength>=startsWithStringLength)
|
if (inStringLength>=startsWithStringLength)
|
||||||
@@ -8653,7 +8660,7 @@ int ILibString_StartsWithEx(const char *inString, int inStringLength, const char
|
|||||||
\param startsWithStringLength The length of \a startsWithString
|
\param startsWithStringLength The length of \a startsWithString
|
||||||
\return Non-zero if the string starts with the substring
|
\return Non-zero if the string starts with the substring
|
||||||
*/
|
*/
|
||||||
int ILibString_StartsWith(const char *inString, int inStringLength, const char *startsWithString, int startsWithStringLength)
|
int ILibString_StartsWith(const char *inString, size_t inStringLength, const char *startsWithString, size_t startsWithStringLength)
|
||||||
{
|
{
|
||||||
return(ILibString_StartsWithEx(inString,inStringLength,startsWithString,startsWithStringLength,1));
|
return(ILibString_StartsWithEx(inString,inStringLength,startsWithString,startsWithStringLength,1));
|
||||||
}
|
}
|
||||||
@@ -8666,26 +8673,26 @@ int ILibString_StartsWith(const char *inString, int inStringLength, const char *
|
|||||||
\param caseSensitive Non-zero if the match is case sensitive
|
\param caseSensitive Non-zero if the match is case sensitive
|
||||||
\return Position index of first occurance. -1 if the substring is not found
|
\return Position index of first occurance. -1 if the substring is not found
|
||||||
*/
|
*/
|
||||||
int ILibString_IndexOfEx(const char *inString, int inStringLength, const char *indexOf, int indexOfLength, int caseSensitive)
|
int ILibString_IndexOfEx(const char *inString, size_t inStringLength, const char *indexOf, size_t indexOfLength, int caseSensitive)
|
||||||
{
|
{
|
||||||
int RetVal = -1;
|
size_t *RetVal = NULL;
|
||||||
int index = 0;
|
size_t index = 0;
|
||||||
|
|
||||||
while (inStringLength-index >= indexOfLength)
|
while (inStringLength-index >= indexOfLength)
|
||||||
{
|
{
|
||||||
if (caseSensitive!=0 && memcmp(inString+index,indexOf,indexOfLength)==0)
|
if (caseSensitive!=0 && memcmp(inString+index,indexOf,indexOfLength)==0)
|
||||||
{
|
{
|
||||||
RetVal = index;
|
RetVal = &index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (caseSensitive==0 && strncasecmp(inString+index,indexOf,indexOfLength)==0)
|
else if (caseSensitive==0 && strncasecmp(inString+index,indexOf,indexOfLength)==0)
|
||||||
{
|
{
|
||||||
RetVal = index;
|
RetVal = &index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
return RetVal;
|
return((RetVal == NULL || *RetVal > INT32_MAX) ? -1 : (int)*RetVal);
|
||||||
}
|
}
|
||||||
/*! \fn ILibString_IndexOf(const char *inString, int inStringLength, const char *indexOf, int indexOfLength)
|
/*! \fn ILibString_IndexOf(const char *inString, int inStringLength, const char *indexOf, int indexOfLength)
|
||||||
\brief Returns the position index of the first occurance of a given substring
|
\brief Returns the position index of the first occurance of a given substring
|
||||||
@@ -8695,7 +8702,7 @@ int ILibString_IndexOfEx(const char *inString, int inStringLength, const char *i
|
|||||||
\param indexOfLength The length of \a lastIndexOf
|
\param indexOfLength The length of \a lastIndexOf
|
||||||
\return Position index of first occurance. -1 if the substring is not found
|
\return Position index of first occurance. -1 if the substring is not found
|
||||||
*/
|
*/
|
||||||
int ILibString_IndexOf(const char *inString, int inStringLength, const char *indexOf, int indexOfLength)
|
int ILibString_IndexOf(const char *inString, size_t inStringLength, const char *indexOf, size_t indexOfLength)
|
||||||
{
|
{
|
||||||
return(ILibString_IndexOfEx(inString,inStringLength,indexOf,indexOfLength,1));
|
return(ILibString_IndexOfEx(inString,inStringLength,indexOf,indexOfLength,1));
|
||||||
}
|
}
|
||||||
@@ -8708,26 +8715,26 @@ int ILibString_IndexOf(const char *inString, int inStringLength, const char *ind
|
|||||||
\param caseSensitive 0 for case insensitive matching, non-zero for case-sensitive matching
|
\param caseSensitive 0 for case insensitive matching, non-zero for case-sensitive matching
|
||||||
\return Position index of last occurance. -1 if the substring is not found
|
\return Position index of last occurance. -1 if the substring is not found
|
||||||
*/
|
*/
|
||||||
int ILibString_LastIndexOfEx(const char *inString, int inStringLength, const char *lastIndexOf, int lastIndexOfLength, int caseSensitive)
|
int ILibString_LastIndexOfEx(const char *inString, size_t inStringLength, const char *lastIndexOf, size_t lastIndexOfLength, int caseSensitive)
|
||||||
{
|
{
|
||||||
int RetVal = -1;
|
size_t *RetVal = NULL;
|
||||||
int index = (inStringLength < 0 ? (int)strnlen_s(inString, sizeof(ILibScratchPad)) : inStringLength) - (lastIndexOfLength < 0 ? (int)strnlen_s(lastIndexOf, sizeof(ILibScratchPad)) : lastIndexOfLength);
|
size_t index = ((inStringLength == 0 || inStringLength == (size_t)(-1))? strnlen_s(inString, sizeof(ILibScratchPad)) : inStringLength) - (lastIndexOfLength < 0 ? strnlen_s(lastIndexOf, sizeof(ILibScratchPad)) : lastIndexOfLength);
|
||||||
|
|
||||||
while (index >= 0)
|
while (index >= 0)
|
||||||
{
|
{
|
||||||
if (caseSensitive!=0 && memcmp(inString+index,lastIndexOf,lastIndexOfLength)==0)
|
if (caseSensitive!=0 && memcmp(inString+index,lastIndexOf,lastIndexOfLength)==0)
|
||||||
{
|
{
|
||||||
RetVal = index;
|
RetVal = &index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (caseSensitive==0 && strncasecmp(inString+index,lastIndexOf,lastIndexOfLength)==0)
|
else if (caseSensitive==0 && strncasecmp(inString+index,lastIndexOf,lastIndexOfLength)==0)
|
||||||
{
|
{
|
||||||
RetVal = index;
|
RetVal = &index;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
--index;
|
--index;
|
||||||
}
|
}
|
||||||
return RetVal;
|
return((RetVal == NULL || *RetVal > INT32_MAX) ? -1 : (int)(*RetVal));
|
||||||
}
|
}
|
||||||
/*! \fn ILibString_LastIndexOf(const char *inString, int inStringLength, const char *lastIndexOf, int lastIndexOfLength)
|
/*! \fn ILibString_LastIndexOf(const char *inString, int inStringLength, const char *lastIndexOf, int lastIndexOfLength)
|
||||||
\brief Returns the position index of the last occurance of a given substring
|
\brief Returns the position index of the last occurance of a given substring
|
||||||
@@ -8737,7 +8744,7 @@ int ILibString_LastIndexOfEx(const char *inString, int inStringLength, const cha
|
|||||||
\param lastIndexOfLength The length of \a lastIndexOf
|
\param lastIndexOfLength The length of \a lastIndexOf
|
||||||
\return Position index of last occurance. -1 if the substring is not found
|
\return Position index of last occurance. -1 if the substring is not found
|
||||||
*/
|
*/
|
||||||
int ILibString_LastIndexOf(const char *inString, int inStringLength, const char *lastIndexOf, int lastIndexOfLength)
|
int ILibString_LastIndexOf(const char *inString, size_t inStringLength, const char *lastIndexOf, size_t lastIndexOfLength)
|
||||||
{
|
{
|
||||||
return(ILibString_LastIndexOfEx(inString,inStringLength,lastIndexOf,lastIndexOfLength,1));
|
return(ILibString_LastIndexOfEx(inString,inStringLength,lastIndexOf,lastIndexOfLength,1));
|
||||||
}
|
}
|
||||||
@@ -8753,13 +8760,13 @@ int ILibString_LastIndexOf(const char *inString, int inStringLength, const char
|
|||||||
\param replaceWithThisLength The length of \a replaceWithThis
|
\param replaceWithThisLength The length of \a replaceWithThis
|
||||||
\return New string with replaced values
|
\return New string with replaced values
|
||||||
*/
|
*/
|
||||||
char *ILibString_Replace(const char *inString, int inStringLength, const char *replaceThis, int replaceThisLength, const char *replaceWithThis, int replaceWithThisLength)
|
char *ILibString_Replace(const char *inString, size_t inStringLength, const char *replaceThis, size_t replaceThisLength, const char *replaceWithThis, size_t replaceWithThisLength)
|
||||||
{
|
{
|
||||||
char *RetVal;
|
char *RetVal;
|
||||||
int RetValLength;
|
size_t RetValLength;
|
||||||
struct parser_result *pr;
|
struct parser_result *pr;
|
||||||
struct parser_result_field *prf;
|
struct parser_result_field *prf;
|
||||||
int mallocSize;
|
size_t mallocSize;
|
||||||
|
|
||||||
pr = ILibParseString((char*)inString, 0, inStringLength,(char*)replaceThis,replaceThisLength);
|
pr = ILibParseString((char*)inString, 0, inStringLength,(char*)replaceThis,replaceThisLength);
|
||||||
RetValLength = (pr->NumResults-1) * replaceWithThisLength; // string that will be inserted
|
RetValLength = (pr->NumResults-1) * replaceWithThisLength; // string that will be inserted
|
||||||
@@ -8789,15 +8796,15 @@ char *ILibString_Replace(const char *inString, int inStringLength, const char *r
|
|||||||
char* ILibString_Cat_s(char *destination, size_t destinationSize, char *source)
|
char* ILibString_Cat_s(char *destination, size_t destinationSize, char *source)
|
||||||
{
|
{
|
||||||
size_t sourceLen = strnlen_s(source, destinationSize);
|
size_t sourceLen = strnlen_s(source, destinationSize);
|
||||||
int i;
|
size_t i;
|
||||||
int x = -1;
|
size_t *x = NULL;
|
||||||
for (i = 0; i < (int)destinationSize - 1; ++i)
|
for (i = 0; i < destinationSize - 1; ++i)
|
||||||
{
|
{
|
||||||
if (destination[i] == 0) { x = i; break; }
|
if (destination[i] == 0) { *x = i; break; }
|
||||||
}
|
}
|
||||||
if (x < 0 || ((x + sourceLen + 1 )> destinationSize)) { ILIBCRITICALEXIT(254); }
|
if (x == NULL || ((*x + sourceLen + 1 )> destinationSize)) { ILIBCRITICALEXIT(254); }
|
||||||
memcpy_s(destination + x, destinationSize - x, source, sourceLen);
|
memcpy_s(destination + *x, destinationSize - *x, source, sourceLen);
|
||||||
destination[x + sourceLen] = 0;
|
destination[*x + sourceLen] = 0;
|
||||||
return(destination);
|
return(destination);
|
||||||
}
|
}
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
@@ -8841,7 +8848,7 @@ int ILibMemory_Move_s(void *destination, size_t destinationSize, void *source, s
|
|||||||
#endif
|
#endif
|
||||||
int ILibString_n_Copy_s(char *destination, size_t destinationSize, char *source, size_t maxCount)
|
int ILibString_n_Copy_s(char *destination, size_t destinationSize, char *source, size_t maxCount)
|
||||||
{
|
{
|
||||||
size_t count = strnlen_s(source, maxCount == (size_t)-1 ? (destinationSize-1) : maxCount);
|
size_t count = strnlen_s(source, (maxCount == (size_t)(-1)) ? (destinationSize-1) : maxCount);
|
||||||
if ((count + 1) > destinationSize)
|
if ((count + 1) > destinationSize)
|
||||||
{
|
{
|
||||||
ILIBCRITICALEXIT(254);
|
ILIBCRITICALEXIT(254);
|
||||||
@@ -8860,21 +8867,21 @@ int ILibString_Copy_s(char *destination, size_t destinationSize, char *source)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* ILibString_Cat(const char *inString1, int inString1Len, const char *inString2, int inString2Len)
|
char* ILibString_Cat(const char *inString1, size_t inString1Len, const char *inString2, size_t inString2Len)
|
||||||
{
|
{
|
||||||
char *RetVal;
|
char *RetVal;
|
||||||
if (inString1Len < 0) { inString1Len = (int)strnlen_s(inString1, sizeof(ILibScratchPad)); }
|
if (inString1Len == 0 || inString1Len == (size_t)(-1)) { inString1Len = strnlen_s(inString1, sizeof(ILibScratchPad)); }
|
||||||
if (inString2Len < 0) { inString2Len = (int)strnlen_s(inString2, sizeof(ILibScratchPad)); }
|
if (inString2Len == 0 || inString2Len == (size_t)(-1)) { inString2Len = strnlen_s(inString2, sizeof(ILibScratchPad)); }
|
||||||
if ((RetVal = (char*)malloc(inString1Len + inString2Len+1)) == NULL) ILIBCRITICALEXIT(254);
|
if ((RetVal = (char*)malloc(inString1Len + inString2Len+1)) == NULL) ILIBCRITICALEXIT(254);
|
||||||
memcpy_s(RetVal, inString1Len + inString2Len + 1, (char*)inString1, inString1Len);
|
memcpy_s(RetVal, inString1Len + inString2Len + 1, (char*)inString1, inString1Len);
|
||||||
memcpy_s(RetVal + inString1Len, inString2Len + 1, (char*)inString2, inString2Len);
|
memcpy_s(RetVal + inString1Len, inString2Len + 1, (char*)inString2, inString2Len);
|
||||||
RetVal[inString1Len + inString2Len]=0;
|
RetVal[inString1Len + inString2Len]=0;
|
||||||
return RetVal;
|
return RetVal;
|
||||||
}
|
}
|
||||||
char* ILibString_Copy(const char *inString, int length)
|
char* ILibString_Copy(const char *inString, size_t length)
|
||||||
{
|
{
|
||||||
char *RetVal;
|
char *RetVal;
|
||||||
if (length<0) length = (int)strnlen_s(inString, sizeof(ILibScratchPad));
|
if (length==0 || length == (size_t)(-1)) length = strnlen_s(inString, sizeof(ILibScratchPad));
|
||||||
if ((RetVal = (char*)malloc(length + 1)) == NULL) ILIBCRITICALEXIT(254);
|
if ((RetVal = (char*)malloc(length + 1)) == NULL) ILIBCRITICALEXIT(254);
|
||||||
memcpy_s(RetVal, length + 1, (char*)inString, length);
|
memcpy_s(RetVal, length + 1, (char*)inString, length);
|
||||||
RetVal[length] = 0;
|
RetVal[length] = 0;
|
||||||
@@ -8882,7 +8889,7 @@ char* ILibString_Copy(const char *inString, int length)
|
|||||||
}
|
}
|
||||||
char* ILibString_CopyEx(const char *inString, size_t length)
|
char* ILibString_CopyEx(const char *inString, size_t length)
|
||||||
{
|
{
|
||||||
if (length == 0) { length = strnlen_s(inString, sizeof(ILibScratchPad)); }
|
if (length == 0 || length == (size_t)(-1)) { length = strnlen_s(inString, sizeof(ILibScratchPad)); }
|
||||||
char *retVal = ILibMemory_SmartAllocate(length + 1);
|
char *retVal = ILibMemory_SmartAllocate(length + 1);
|
||||||
memcpy_s(retVal, length + 1, inString, length);
|
memcpy_s(retVal, length + 1, inString, length);
|
||||||
return(retVal);
|
return(retVal);
|
||||||
@@ -8895,7 +8902,7 @@ char* ILibString_CopyEx(const char *inString, size_t length)
|
|||||||
\param length The length of \a inString
|
\param length The length of \a inString
|
||||||
\return Converted string
|
\return Converted string
|
||||||
*/
|
*/
|
||||||
char *ILibString_ToUpper(const char *inString, int length)
|
char *ILibString_ToUpper(const char *inString, size_t length)
|
||||||
{
|
{
|
||||||
char *RetVal;
|
char *RetVal;
|
||||||
if ((RetVal = (char*)malloc(length + 1)) == NULL) ILIBCRITICALEXIT(254);
|
if ((RetVal = (char*)malloc(length + 1)) == NULL) ILIBCRITICALEXIT(254);
|
||||||
@@ -8911,7 +8918,7 @@ char *ILibString_ToUpper(const char *inString, int length)
|
|||||||
\param length The length of \a inString
|
\param length The length of \a inString
|
||||||
\return Converted string
|
\return Converted string
|
||||||
*/
|
*/
|
||||||
char *ILibString_ToLower(const char *inString, int length)
|
char *ILibString_ToLower(const char *inString, size_t length)
|
||||||
{
|
{
|
||||||
char *RetVal;
|
char *RetVal;
|
||||||
if ((RetVal = (char*)malloc(length + 1)) == NULL) ILIBCRITICALEXIT(254);
|
if ((RetVal = (char*)malloc(length + 1)) == NULL) ILIBCRITICALEXIT(254);
|
||||||
@@ -10625,7 +10632,7 @@ void ILibLinkedList_FileBacked_CopyPath(ILibLinkedList_FileBacked_Root *root, ch
|
|||||||
{
|
{
|
||||||
char *extraMemory = (char*)ILibMemory_GetExtraMemory(root, sizeof(ILibLinkedList_FileBacked_Root));
|
char *extraMemory = (char*)ILibMemory_GetExtraMemory(root, sizeof(ILibLinkedList_FileBacked_Root));
|
||||||
int pathLen = (int)strnlen_s(path, _MAX_PATH);
|
int pathLen = (int)strnlen_s(path, _MAX_PATH);
|
||||||
int offset = ILibMemory_GetExtraMemorySize(extraMemory) - pathLen - 1;
|
size_t offset = ILibMemory_GetExtraMemorySize(extraMemory) - pathLen - 1;
|
||||||
|
|
||||||
memcpy_s(extraMemory + offset, pathLen, path, pathLen);
|
memcpy_s(extraMemory + offset, pathLen, path, pathLen);
|
||||||
(extraMemory + offset)[pathLen] = 0;
|
(extraMemory + offset)[pathLen] = 0;
|
||||||
|
|||||||
@@ -396,8 +396,8 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
char* MetaData;
|
char* MetaData;
|
||||||
int RESERVED;
|
int RESERVED;
|
||||||
}ILibChain_Link;
|
}ILibChain_Link;
|
||||||
ILibChain_Link* ILibChain_Link_Allocate(int structSize, int extraMemorySize);
|
ILibChain_Link* ILibChain_Link_Allocate(size_t structSize, size_t extraMemorySize);
|
||||||
int ILibChain_Link_GetExtraMemorySize(ILibChain_Link* link);
|
size_t ILibChain_Link_GetExtraMemorySize(ILibChain_Link* link);
|
||||||
|
|
||||||
typedef enum ILibMemory_Types
|
typedef enum ILibMemory_Types
|
||||||
{
|
{
|
||||||
@@ -460,9 +460,9 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
#define ILibMemory_AllocateRaw(memPtr, memSize) if((memPtr = malloc(memSize)) == NULL) {ILIBCRITICALEXIT(254);}
|
#define ILibMemory_AllocateRaw(memPtr, memSize) if((memPtr = malloc(memSize)) == NULL) {ILIBCRITICALEXIT(254);}
|
||||||
#define ILibMemory_ReallocateRaw(ppMemory, memSize) if(((*ppMemory) = realloc(*ppMemory, memSize)) == NULL) {ILIBCRITICALEXIT(254);}
|
#define ILibMemory_ReallocateRaw(ppMemory, memSize) if(((*ppMemory) = realloc(*ppMemory, memSize)) == NULL) {ILIBCRITICALEXIT(254);}
|
||||||
|
|
||||||
void* ILibMemory_Allocate(int containerSize, int extraMemorySize, void** allocatedContainer, void **extraMemory);
|
void* ILibMemory_Allocate(size_t containerSize, size_t extraMemorySize, void** allocatedContainer, void **extraMemory);
|
||||||
int ILibMemory_GetExtraMemorySize(void* extraMemory);
|
size_t ILibMemory_GetExtraMemorySize(void* extraMemory);
|
||||||
ILibExportMethod void* ILibMemory_GetExtraMemory(void *container, int containerSize);
|
ILibExportMethod void* ILibMemory_GetExtraMemory(void *container, size_t containerSize);
|
||||||
ILibChain_EventHookToken ILibChain_SetEventHook(void* chainLinkObject, int maxTimeout, ILibChain_EventHookHandler handler);
|
ILibChain_EventHookToken ILibChain_SetEventHook(void* chainLinkObject, int maxTimeout, ILibChain_EventHookHandler handler);
|
||||||
void ILibChain_UpdateEventHook(ILibChain_EventHookToken token, int maxTimeout);
|
void ILibChain_UpdateEventHook(ILibChain_EventHookToken token, int maxTimeout);
|
||||||
|
|
||||||
@@ -597,7 +597,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
/*! \var datalength
|
/*! \var datalength
|
||||||
\brief Length of \a data
|
\brief Length of \a data
|
||||||
*/
|
*/
|
||||||
int datalength;
|
size_t datalength;
|
||||||
|
|
||||||
/*! \var NextResult
|
/*! \var NextResult
|
||||||
\brief Pointer to next token
|
\brief Pointer to next token
|
||||||
@@ -642,7 +642,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
/*! \var FieldLength
|
/*! \var FieldLength
|
||||||
\brief Length of \a Field
|
\brief Length of \a Field
|
||||||
*/
|
*/
|
||||||
int FieldLength;
|
size_t FieldLength;
|
||||||
/*! \var FieldData
|
/*! \var FieldData
|
||||||
\brief Header Value
|
\brief Header Value
|
||||||
*/
|
*/
|
||||||
@@ -650,7 +650,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
/*! \var FieldDataLength
|
/*! \var FieldDataLength
|
||||||
\brief Length of \a FieldData
|
\brief Length of \a FieldData
|
||||||
*/
|
*/
|
||||||
int FieldDataLength;
|
size_t FieldDataLength;
|
||||||
/*! \var UserAllocStrings
|
/*! \var UserAllocStrings
|
||||||
\brief Boolean indicating if the above strings are non-static memory
|
\brief Boolean indicating if the above strings are non-static memory
|
||||||
*/
|
*/
|
||||||
@@ -677,7 +677,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
/*! \var DirectiveLength
|
/*! \var DirectiveLength
|
||||||
\brief Length of \a Directive
|
\brief Length of \a Directive
|
||||||
*/
|
*/
|
||||||
int DirectiveLength;
|
size_t DirectiveLength;
|
||||||
/*! \var DirectiveObj
|
/*! \var DirectiveObj
|
||||||
\brief HTTP Method Path
|
\brief HTTP Method Path
|
||||||
\par
|
\par
|
||||||
@@ -691,7 +691,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
void *Reserved;
|
void *Reserved;
|
||||||
char *ReservedMemory;
|
char *ReservedMemory;
|
||||||
|
|
||||||
int DirectiveObjLength;
|
size_t DirectiveObjLength;
|
||||||
/*! \var StatusCode
|
/*! \var StatusCode
|
||||||
\brief HTTP Response Code
|
\brief HTTP Response Code
|
||||||
\par
|
\par
|
||||||
@@ -707,7 +707,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
/*! \var StatusDataLength
|
/*! \var StatusDataLength
|
||||||
\brief Length of \a StatusData
|
\brief Length of \a StatusData
|
||||||
*/
|
*/
|
||||||
int StatusDataLength;
|
size_t StatusDataLength;
|
||||||
/*! \var Version
|
/*! \var Version
|
||||||
\brief HTTP Version
|
\brief HTTP Version
|
||||||
\par
|
\par
|
||||||
@@ -717,7 +717,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
/*! \var VersionLength
|
/*! \var VersionLength
|
||||||
\brief Length of \a Version
|
\brief Length of \a Version
|
||||||
*/
|
*/
|
||||||
int VersionLength;
|
size_t VersionLength;
|
||||||
/*! \var Body
|
/*! \var Body
|
||||||
\brief Pointer to HTTP Body
|
\brief Pointer to HTTP Body
|
||||||
*/
|
*/
|
||||||
@@ -725,7 +725,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
/*! \var BodyLength
|
/*! \var BodyLength
|
||||||
\brief Length of \a Body
|
\brief Length of \a Body
|
||||||
*/
|
*/
|
||||||
int BodyLength;
|
size_t BodyLength;
|
||||||
/*! \var UserAllocStrings
|
/*! \var UserAllocStrings
|
||||||
\brief Boolean indicating if Directive/Obj are non-static
|
\brief Boolean indicating if Directive/Obj are non-static
|
||||||
\par
|
\par
|
||||||
@@ -789,7 +789,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
/*! \var NameLength
|
/*! \var NameLength
|
||||||
\brief Length of \a Name
|
\brief Length of \a Name
|
||||||
*/
|
*/
|
||||||
int NameLength;
|
size_t NameLength;
|
||||||
|
|
||||||
/*! \var NSTag
|
/*! \var NSTag
|
||||||
\brief Namespace Prefix of the current element
|
\brief Namespace Prefix of the current element
|
||||||
@@ -800,7 +800,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
/*! \var NSLength
|
/*! \var NSLength
|
||||||
\brief Length of \a NSTag
|
\brief Length of \a NSTag
|
||||||
*/
|
*/
|
||||||
int NSLength;
|
size_t NSLength;
|
||||||
|
|
||||||
/*! \var StartTag
|
/*! \var StartTag
|
||||||
\brief boolean indicating if the current element is a start element
|
\brief boolean indicating if the current element is a start element
|
||||||
@@ -844,7 +844,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
/*! \var NameLength
|
/*! \var NameLength
|
||||||
\brief Length of \a Name
|
\brief Length of \a Name
|
||||||
*/
|
*/
|
||||||
int NameLength;
|
size_t NameLength;
|
||||||
|
|
||||||
/*! \var Prefix
|
/*! \var Prefix
|
||||||
\brief Namespace Prefix of this attribute
|
\brief Namespace Prefix of this attribute
|
||||||
@@ -855,7 +855,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
/*! \var PrefixLength
|
/*! \var PrefixLength
|
||||||
\brief Lenth of \a Prefix
|
\brief Lenth of \a Prefix
|
||||||
*/
|
*/
|
||||||
int PrefixLength;
|
size_t PrefixLength;
|
||||||
|
|
||||||
/*! \var Parent
|
/*! \var Parent
|
||||||
\brief Pointer to the XML Node that contains this attribute
|
\brief Pointer to the XML Node that contains this attribute
|
||||||
@@ -869,7 +869,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
/*! \var ValueLength
|
/*! \var ValueLength
|
||||||
\brief Length of \a Value
|
\brief Length of \a Value
|
||||||
*/
|
*/
|
||||||
int ValueLength;
|
size_t ValueLength;
|
||||||
/*! \var Next
|
/*! \var Next
|
||||||
\brief Pointer to the next attribute
|
\brief Pointer to the next attribute
|
||||||
*/
|
*/
|
||||||
@@ -931,7 +931,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
//
|
//
|
||||||
// Parses an XML string. Returns a tree of ILibXMLNode elements.
|
// Parses an XML string. Returns a tree of ILibXMLNode elements.
|
||||||
//
|
//
|
||||||
struct ILibXMLNode *ILibParseXML(char *buffer, int offset, int length);
|
struct ILibXMLNode *ILibParseXML(char *buffer, size_t offset, size_t length);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Preprocesses the tree of ILibXMLNode elements returned by ILibParseXML.
|
// Preprocesses the tree of ILibXMLNode elements returned by ILibParseXML.
|
||||||
@@ -1014,9 +1014,9 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
char *ILibChain_GetMetaDataFromDescriptorSet(void *chain, fd_set *inr, fd_set *inw, fd_set *ine);
|
char *ILibChain_GetMetaDataFromDescriptorSet(void *chain, fd_set *inr, fd_set *inw, fd_set *ine);
|
||||||
char *ILibChain_GetMetaDataFromDescriptorSetEx(void *chain, fd_set *inr, fd_set *inw, fd_set *ine);
|
char *ILibChain_GetMetaDataFromDescriptorSetEx(void *chain, fd_set *inr, fd_set *inw, fd_set *ine);
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
typedef void(*ILib_GenericReadHandler)(char *buffer, int bufferLen, int* bytesConsumed, void* user1, void *user2);
|
typedef void(*ILib_GenericReadHandler)(char *buffer, int bufferLen, DWORD* bytesConsumed, void* user1, void *user2);
|
||||||
typedef BOOL(*ILibChain_ReadEx_Handler)(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, char *buffer, int bytesRead, void* user);
|
typedef BOOL(*ILibChain_ReadEx_Handler)(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, char *buffer, DWORD bytesRead, void* user);
|
||||||
typedef BOOL(*ILibChain_WriteEx_Handler)(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, int bytesWritten, void* user);
|
typedef BOOL(*ILibChain_WriteEx_Handler)(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, DWORD bytesWritten, void* user);
|
||||||
typedef struct ILibChain_ReadEx_data
|
typedef struct ILibChain_ReadEx_data
|
||||||
{
|
{
|
||||||
char *buffer;
|
char *buffer;
|
||||||
@@ -1029,8 +1029,8 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
{
|
{
|
||||||
ILibChain_WriteEx_Handler handler;
|
ILibChain_WriteEx_Handler handler;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
int bytesLeft;
|
DWORD bytesLeft;
|
||||||
int totalWritten;
|
DWORD totalWritten;
|
||||||
HANDLE fileHandle;
|
HANDLE fileHandle;
|
||||||
OVERLAPPED *p;
|
OVERLAPPED *p;
|
||||||
void *user;
|
void *user;
|
||||||
@@ -1040,16 +1040,16 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
void* ILibChain_WaitHandle_RemoveAndSaveState(void *chain, HANDLE h);
|
void* ILibChain_WaitHandle_RemoveAndSaveState(void *chain, HANDLE h);
|
||||||
void ILibChain_WaitHandle_RestoreState(void *chain, void *state);
|
void ILibChain_WaitHandle_RestoreState(void *chain, void *state);
|
||||||
void ILibChain_WaitHandle_DestroySavedState(void *chain, void *state);
|
void ILibChain_WaitHandle_DestroySavedState(void *chain, void *state);
|
||||||
void* ILibChain_ReadAndSaveStateEx(void *chain, HANDLE h, OVERLAPPED *p, char *buffer, int bufferLen, ILibChain_ReadEx_Handler handler, void *user, char *metadata);
|
void* ILibChain_ReadAndSaveStateEx(void *chain, HANDLE h, OVERLAPPED *p, char *buffer, DWORD bufferLen, ILibChain_ReadEx_Handler handler, void *user, char *metadata);
|
||||||
BOOL ILibChain_WaitHandleAdded(void *chain, HANDLE h);
|
BOOL ILibChain_WaitHandleAdded(void *chain, HANDLE h);
|
||||||
|
|
||||||
void ILibChain_WaitHandle_UpdateMetadata(void *chain, HANDLE h, char *metadata);
|
void ILibChain_WaitHandle_UpdateMetadata(void *chain, HANDLE h, char *metadata);
|
||||||
void ILibChain_AddWaitHandleEx(void *chain, HANDLE h, int msTIMEOUT, ILibChain_WaitHandleHandler handler, void *user, char *metadata);
|
void ILibChain_AddWaitHandleEx(void *chain, HANDLE h, int msTIMEOUT, ILibChain_WaitHandleHandler handler, void *user, char *metadata);
|
||||||
#define ILibChain_AddWaitHandle(chain, h, msTIMEOUT, handler, user) ILibChain_AddWaitHandleEx(chain, h, msTIMEOUT, handler, user, ILibChain_MetaData(__FILE__, __LINE__))
|
#define ILibChain_AddWaitHandle(chain, h, msTIMEOUT, handler, user) ILibChain_AddWaitHandleEx(chain, h, msTIMEOUT, handler, user, ILibChain_MetaData(__FILE__, __LINE__))
|
||||||
void ILibChain_RemoveWaitHandle(void *chain, HANDLE h);
|
void ILibChain_RemoveWaitHandle(void *chain, HANDLE h);
|
||||||
void ILibChain_ReadEx2(void *chain, HANDLE h, OVERLAPPED *p, char *buffer, int bufferLen, ILibChain_ReadEx_Handler handler, void *user, char *metadata);
|
void ILibChain_ReadEx2(void *chain, HANDLE h, OVERLAPPED *p, char *buffer, DWORD bufferLen, ILibChain_ReadEx_Handler handler, void *user, char *metadata);
|
||||||
#define ILibChain_ReadEx(chain, h, overlapped, buffer, bufferLen, handler, user) ILibChain_ReadEx2(chain, h, overlapped, buffer, bufferLen, handler, user, ILibChain_MetaData(__FILE__, __LINE__))
|
#define ILibChain_ReadEx(chain, h, overlapped, buffer, bufferLen, handler, user) ILibChain_ReadEx2(chain, h, overlapped, buffer, bufferLen, handler, user, ILibChain_MetaData(__FILE__, __LINE__))
|
||||||
ILibTransport_DoneState ILibChain_WriteEx2(void *chain, HANDLE h, OVERLAPPED *p, char *buffer, int bufferLen, ILibChain_WriteEx_Handler handler, void *user, char *metadata);
|
ILibTransport_DoneState ILibChain_WriteEx2(void *chain, HANDLE h, OVERLAPPED *p, char *buffer, DWORD bufferLen, ILibChain_WriteEx_Handler handler, void *user, char *metadata);
|
||||||
#define ILibChain_WriteEx(chain, h, overlapped, buffer, bufferLen, handler, user) ILibChain_WriteEx2(chain, h, overlapped, buffer, bufferLen, handler, user, ILibChain_MetaData(__FILE__, __LINE__))
|
#define ILibChain_WriteEx(chain, h, overlapped, buffer, bufferLen, handler, user) ILibChain_WriteEx2(chain, h, overlapped, buffer, bufferLen, handler, user, ILibChain_MetaData(__FILE__, __LINE__))
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1294,11 +1294,11 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
void* ILibInitHashTree_CaseInSensitiveEx(void *ReservedMemory);
|
void* ILibInitHashTree_CaseInSensitiveEx(void *ReservedMemory);
|
||||||
#define ILibInitHashTree_CaseInSensitive() ILibInitHashTree_CaseInSensitiveEx(NULL)
|
#define ILibInitHashTree_CaseInSensitive() ILibInitHashTree_CaseInSensitiveEx(NULL)
|
||||||
void ILibDestroyHashTree(void *tree);
|
void ILibDestroyHashTree(void *tree);
|
||||||
int ILibHasEntry(void *hashtree, char* key, int keylength);
|
int ILibHasEntry(void *hashtree, const char* key, size_t keylength);
|
||||||
void ILibAddEntry(void* hashtree, char* key, int keylength, void *value);
|
void ILibAddEntry(void* hashtree, const char* key, size_t keylength, void *value);
|
||||||
void ILibAddEntryEx(void* hashtree, char* key, int keylength, void *value, int valueEx);
|
void ILibAddEntryEx(void* hashtree, const char* key, size_t keylength, void *value, int valueEx);
|
||||||
void* ILibGetEntry(void *hashtree, char* key, int keylength);
|
void* ILibGetEntry(void *hashtree, const char* key, size_t keylength);
|
||||||
ILibExportMethod void ILibGetEntryEx(void *hashtree, char* key, int keylength, void **value, int *valueEx);
|
ILibExportMethod void ILibGetEntryEx(void *hashtree, const char* key, size_t keylength, void **value, int *valueEx);
|
||||||
void ILibDeleteEntry(void *hashtree, char* key, int keylength);
|
void ILibDeleteEntry(void *hashtree, char* key, int keylength);
|
||||||
|
|
||||||
void *ILibHashTree_GetEnumerator(void *tree);
|
void *ILibHashTree_GetEnumerator(void *tree);
|
||||||
@@ -1306,7 +1306,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
int ILibHashTree_MoveNext(void *tree_enumerator);
|
int ILibHashTree_MoveNext(void *tree_enumerator);
|
||||||
|
|
||||||
void ILibHashTree_GetValue(void *tree_enumerator, char **key, int *keyLength, void **data);
|
void ILibHashTree_GetValue(void *tree_enumerator, char **key, int *keyLength, void **data);
|
||||||
void ILibHashTree_GetValueEx(void *tree_enumerator, char **key, int *keyLength, void **data, int *dataEx);
|
void ILibHashTree_GetValueEx(void *tree_enumerator, char **key, size_t *keyLength, void **data, size_t *dataEx);
|
||||||
void ILibHashTree_Lock(void *hashtree);
|
void ILibHashTree_Lock(void *hashtree);
|
||||||
void ILibHashTree_UnLock(void *hashtree);
|
void ILibHashTree_UnLock(void *hashtree);
|
||||||
|
|
||||||
@@ -1359,27 +1359,27 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
int ILibFindEntryInTable(char *Entry, char **Table);
|
int ILibFindEntryInTable(char *Entry, char **Table);
|
||||||
|
|
||||||
|
|
||||||
int ILibTrimString(char **theString, int length);
|
size_t ILibTrimString(char **theString, size_t length);
|
||||||
int ILibString_IndexOfFirstWhiteSpace(const char *inString, int inStringLength);
|
int ILibString_IndexOfFirstWhiteSpace(const char *inString, size_t inStringLength);
|
||||||
char* ILibString_Cat(const char *inString1, int inString1Len, const char *inString2, int inString2Len);
|
char* ILibString_Cat(const char *inString1, size_t inString1Len, const char *inString2, size_t inString2Len);
|
||||||
char* ILibString_Cat_s(char *destination, size_t destinationSize, char *source);
|
char* ILibString_Cat_s(char *destination, size_t destinationSize, char *source);
|
||||||
char *ILibString_Copy(const char *inString, int length);
|
char* ILibString_Copy(const char *inString, size_t length);
|
||||||
char* ILibString_CopyEx(const char *inString, size_t length);
|
char* ILibString_CopyEx(const char *inString, size_t length);
|
||||||
int ILibString_Copy_s(char *destination, size_t destinationSize, char *source);
|
int ILibString_Copy_s(char *destination, size_t destinationSize, char *source);
|
||||||
int ILibString_n_Copy_s(char *destination, size_t destinationSize, char *source, size_t count);
|
int ILibString_n_Copy_s(char *destination, size_t destinationSize, char *source, size_t count);
|
||||||
int ILibString_EndsWith(const char *inString, int inStringLength, const char *endWithString, int endWithStringLength);
|
int ILibString_EndsWith(const char *inString, size_t inStringLength, const char *endWithString, size_t endWithStringLength);
|
||||||
int ILibString_EndsWithEx(const char *inString, int inStringLength, const char *endWithString, int endWithStringLength, int caseSensitive);
|
int ILibString_EndsWithEx(const char *inString, size_t inStringLength, const char *endWithString, size_t endWithStringLength, int caseSensitive);
|
||||||
int ILibString_StartsWith(const char *inString, int inStringLength, const char *startsWithString, int startsWithStringLength);
|
int ILibString_StartsWith(const char *inString, size_t inStringLength, const char *startsWithString, size_t startsWithStringLength);
|
||||||
int ILibString_StartsWithEx(const char *inString, int inStringLength, const char *startsWithString, int startsWithStringLength, int caseSensitive);
|
int ILibString_StartsWithEx(const char *inString, size_t inStringLength, const char *startsWithString, size_t startsWithStringLength, int caseSensitive);
|
||||||
int ILibString_IndexOfEx(const char *inString, int inStringLength, const char *indexOf, int indexOfLength, int caseSensitive);
|
int ILibString_IndexOfEx(const char *inString, size_t inStringLength, const char *indexOf, size_t indexOfLength, int caseSensitive);
|
||||||
int ILibString_IndexOf(const char *inString, int inStringLength, const char *indexOf, int indexOfLength);
|
int ILibString_IndexOf(const char *inString, size_t inStringLength, const char *indexOf, size_t indexOfLength);
|
||||||
int ILibString_LastIndexOf(const char *inString, int inStringLength, const char *lastIndexOf, int lastIndexOfLength);
|
int ILibString_LastIndexOf(const char *inString, size_t inStringLength, const char *lastIndexOf, size_t lastIndexOfLength);
|
||||||
int ILibString_LastIndexOfEx(const char *inString, int inStringLength, const char *lastIndexOf, int lastIndexOfLength, int caseSensitive);
|
int ILibString_LastIndexOfEx(const char *inString, size_t inStringLength, const char *lastIndexOf, size_t lastIndexOfLength, int caseSensitive);
|
||||||
char *ILibString_Replace(const char *inString, int inStringLength, const char *replaceThis, int replaceThisLength, const char *replaceWithThis, int replaceWithThisLength);
|
char *ILibString_Replace(const char *inString, size_t inStringLength, const char *replaceThis, size_t replaceThisLength, const char *replaceWithThis, size_t replaceWithThisLength);
|
||||||
char *ILibString_ToUpper(const char *inString, int length);
|
char *ILibString_ToUpper(const char *inString, size_t length);
|
||||||
char *ILibString_ToLower(const char *inString, int length);
|
char *ILibString_ToLower(const char *inString, size_t length);
|
||||||
void ILibToUpper(const char *in, int inLength, char *out);
|
void ILibToUpper(const char *in, size_t inLength, char *out);
|
||||||
void ILibToLower(const char *in, int inLength, char *out);
|
void ILibToLower(const char *in, size_t inLength, char *out);
|
||||||
#if !defined(WIN32)
|
#if !defined(WIN32)
|
||||||
#ifndef strcat_s
|
#ifndef strcat_s
|
||||||
#define strcat_s(destination, destinationSize, source) ILibString_Cat_s(destination, destinationSize, source)
|
#define strcat_s(destination, destinationSize, source) ILibString_Cat_s(destination, destinationSize, source)
|
||||||
@@ -1389,8 +1389,8 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct parser_result* ILibParseString (char* buffer, int offset, int length, const char* Delimiter, int DelimiterLength);
|
struct parser_result* ILibParseString (const char* buffer, size_t offset, size_t length, const char* Delimiter, size_t DelimiterLength);
|
||||||
struct parser_result* ILibParseStringAdv (char* buffer, int offset, int length, const char* Delimiter, int DelimiterLength);
|
struct parser_result* ILibParseStringAdv (const char* buffer, size_t offset, size_t length, const char* Delimiter, size_t DelimiterLength);
|
||||||
parser_result_field* ILibParseString_GetResultIndex(parser_result* r, int index);
|
parser_result_field* ILibParseString_GetResultIndex(parser_result* r, int index);
|
||||||
void ILibDestructParserResults(struct parser_result *result);
|
void ILibDestructParserResults(struct parser_result *result);
|
||||||
|
|
||||||
@@ -1406,8 +1406,8 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
|
|
||||||
int ILibGetLong(char *TestValue, int TestValueLength, long* NumericValue);
|
int ILibGetLong(char *TestValue, int TestValueLength, long* NumericValue);
|
||||||
int ILibGetULong(const char *TestValue, const int TestValueLength, unsigned long* NumericValue);
|
int ILibGetULong(const char *TestValue, const int TestValueLength, unsigned long* NumericValue);
|
||||||
int ILibFragmentText(char *text, int textLength, char *delimiter, int delimiterLength, int tokenLength, char **RetVal);
|
size_t ILibFragmentText(char *text, size_t textLength, char *delimiter, size_t delimiterLength, size_t tokenLength, char **RetVal);
|
||||||
int ILibFragmentTextLength(char *text, int textLength, char *delimiter, int delimiterLength, int tokenLength);
|
size_t ILibFragmentTextLength(char *text, size_t textLength, char *delimiter, size_t delimiterLength, size_t tokenLength);
|
||||||
|
|
||||||
|
|
||||||
/* Base64 handling methods */
|
/* Base64 handling methods */
|
||||||
@@ -1432,7 +1432,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
|
|
||||||
struct packetheader *ILibCreateEmptyPacketEx(void *ReservedMemory);
|
struct packetheader *ILibCreateEmptyPacketEx(void *ReservedMemory);
|
||||||
#define ILibCreateEmptyPacket() ILibCreateEmptyPacketEx(NULL)
|
#define ILibCreateEmptyPacket() ILibCreateEmptyPacketEx(NULL)
|
||||||
void ILibAddHeaderLine(struct packetheader *packet, const char* FieldName, int FieldNameLength, const char* FieldData, int FieldDataLength);
|
void ILibAddHeaderLine(struct packetheader *packet, const char* FieldName, size_t FieldNameLength, const char* FieldData, size_t FieldDataLength);
|
||||||
void ILibDeleteHeaderLine(struct packetheader *packet, char* FieldName, int FieldNameLength);
|
void ILibDeleteHeaderLine(struct packetheader *packet, char* FieldName, int FieldNameLength);
|
||||||
void ILibHTTPPacket_Stash_Put(ILibHTTPPacket *packet, char* key, int keyLen, void *data);
|
void ILibHTTPPacket_Stash_Put(ILibHTTPPacket *packet, char* key, int keyLen, void *data);
|
||||||
int ILibHTTPPacket_Stash_HasKey(ILibHTTPPacket *packet, char* key, int keyLen);
|
int ILibHTTPPacket_Stash_HasKey(ILibHTTPPacket *packet, char* key, int keyLen);
|
||||||
@@ -1443,12 +1443,12 @@ int ILibIsRunningOnChainThread(void* chain);
|
|||||||
char* ILibGetHeaderLineEx(struct packetheader *packet, char* FieldName, int FieldNameLength, int *len);
|
char* ILibGetHeaderLineEx(struct packetheader *packet, char* FieldName, int FieldNameLength, int *len);
|
||||||
char* ILibGetHeaderLineSP(struct packetheader *packet, char* FieldName, int FieldNameLength);
|
char* ILibGetHeaderLineSP(struct packetheader *packet, char* FieldName, int FieldNameLength);
|
||||||
char* ILibGetHeaderLineSP_Next(char* PreviousValue, char* FieldName, int FieldNameLength);
|
char* ILibGetHeaderLineSP_Next(char* PreviousValue, char* FieldName, int FieldNameLength);
|
||||||
void ILibSetVersion(struct packetheader *packet, char* Version, int VersionLength);
|
void ILibSetVersion(struct packetheader *packet, char* Version, size_t VersionLength);
|
||||||
void ILibSetStatusCode(struct packetheader *packet, int StatusCode, char* StatusData, int StatusDataLength);
|
void ILibSetStatusCode(struct packetheader *packet, int StatusCode, char* StatusData, size_t StatusDataLength);
|
||||||
void ILibSetDirective(struct packetheader *packet, char* Directive, int DirectiveLength, char* DirectiveObj, int DirectiveObjLength);
|
void ILibSetDirective(struct packetheader *packet, char* Directive, size_t DirectiveLength, char* DirectiveObj, size_t DirectiveObjLength);
|
||||||
void ILibDestructPacket(struct packetheader *packet);
|
void ILibDestructPacket(struct packetheader *packet);
|
||||||
struct packetheader* ILibParsePacketHeader(char* buffer, int offset, int length);
|
struct packetheader* ILibParsePacketHeader(char* buffer, size_t offset, size_t length);
|
||||||
int ILibGetRawPacket(struct packetheader *packet,char **buffer);
|
size_t ILibGetRawPacket(struct packetheader *packet,char **buffer);
|
||||||
struct packetheader* ILibClonePacket(struct packetheader *packet);
|
struct packetheader* ILibClonePacket(struct packetheader *packet);
|
||||||
|
|
||||||
int ILibHTTPEscapeEx(char* outdata, const char* indata, size_t indataLen);
|
int ILibHTTPEscapeEx(char* outdata, const char* indata, size_t indataLen);
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ typedef struct ILibProcessPipe_Manager_Object
|
|||||||
}ILibProcessPipe_Manager_Object;
|
}ILibProcessPipe_Manager_Object;
|
||||||
struct ILibProcessPipe_PipeObject;
|
struct ILibProcessPipe_PipeObject;
|
||||||
|
|
||||||
typedef void(*ILibProcessPipe_GenericReadHandler)(char *buffer, int bufferLen, int* bytesConsumed, void* user1, void* user2);
|
typedef void(*ILibProcessPipe_GenericReadHandler)(char *buffer, size_t bufferLen, size_t* bytesConsumed, void* user1, void* user2);
|
||||||
typedef void(*ILibProcessPipe_GenericSendOKHandler)(void* user1, void* user2);
|
typedef void(*ILibProcessPipe_GenericSendOKHandler)(void* user1, void* user2);
|
||||||
typedef void(*ILibProcessPipe_GenericBrokenPipeHandler)(struct ILibProcessPipe_PipeObject* sender);
|
typedef void(*ILibProcessPipe_GenericBrokenPipeHandler)(struct ILibProcessPipe_PipeObject* sender);
|
||||||
struct ILibProcessPipe_Process_Object; // Forward Prototype
|
struct ILibProcessPipe_Process_Object; // Forward Prototype
|
||||||
@@ -74,11 +74,11 @@ struct ILibProcessPipe_Process_Object; // Forward Prototype
|
|||||||
typedef struct ILibProcessPipe_PipeObject
|
typedef struct ILibProcessPipe_PipeObject
|
||||||
{
|
{
|
||||||
char* buffer;
|
char* buffer;
|
||||||
int bufferSize;
|
size_t bufferSize;
|
||||||
ILibTransport_MemoryOwnership bufferOwner;
|
ILibTransport_MemoryOwnership bufferOwner;
|
||||||
|
|
||||||
int readOffset, readNewOffset;
|
size_t readOffset, readNewOffset;
|
||||||
int totalRead;
|
size_t totalRead;
|
||||||
int processingLoop;
|
int processingLoop;
|
||||||
|
|
||||||
ILibProcessPipe_Manager_Object *manager;
|
ILibProcessPipe_Manager_Object *manager;
|
||||||
@@ -821,20 +821,6 @@ int ILibProcessPipe_Process_IsDetached(ILibProcessPipe_Process p)
|
|||||||
{
|
{
|
||||||
return(((ILibProcessPipe_Process_Object*)p)->stdErr == NULL && ((ILibProcessPipe_Process_Object*)p)->stdIn == NULL && ((ILibProcessPipe_Process_Object*)p)->stdOut == NULL);
|
return(((ILibProcessPipe_Process_Object*)p)->stdErr == NULL && ((ILibProcessPipe_Process_Object*)p)->stdIn == NULL && ((ILibProcessPipe_Process_Object*)p)->stdOut == NULL);
|
||||||
}
|
}
|
||||||
void ILibProcessPipe_Pipe_SwapBuffers(ILibProcessPipe_Pipe obj, char* newBuffer, int newBufferLen, int newBufferReadOffset, int newBufferTotalBytesRead, char **oldBuffer, int *oldBufferLen, int *oldBufferReadOffset, int *oldBufferTotalBytesRead)
|
|
||||||
{
|
|
||||||
ILibProcessPipe_PipeObject *pipeObject = (ILibProcessPipe_PipeObject*)obj;
|
|
||||||
|
|
||||||
*oldBuffer = pipeObject->buffer;
|
|
||||||
if (oldBufferLen != NULL) { *oldBufferLen = pipeObject->bufferSize; }
|
|
||||||
if (oldBufferReadOffset != NULL) { *oldBufferReadOffset = pipeObject->readOffset; }
|
|
||||||
if (oldBufferTotalBytesRead != NULL) { *oldBufferTotalBytesRead = pipeObject->totalRead; }
|
|
||||||
|
|
||||||
pipeObject->buffer = newBuffer;
|
|
||||||
pipeObject->bufferSize = newBufferLen;
|
|
||||||
pipeObject->readOffset = newBufferReadOffset;
|
|
||||||
pipeObject->totalRead = newBufferTotalBytesRead;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
BOOL ILibProcessPipe_Process_ReadHandler(void *chain, HANDLE event, ILibWaitHandle_ErrorStatus errors, void* user)
|
BOOL ILibProcessPipe_Process_ReadHandler(void *chain, HANDLE event, ILibWaitHandle_ErrorStatus errors, void* user)
|
||||||
@@ -846,7 +832,7 @@ void ILibProcessPipe_Process_ReadHandler(void* user)
|
|||||||
if (errors != ILibWaitHandle_ErrorStatus_NONE) { return(FALSE); }
|
if (errors != ILibWaitHandle_ErrorStatus_NONE) { return(FALSE); }
|
||||||
#endif
|
#endif
|
||||||
ILibProcessPipe_PipeObject *pipeObject = (ILibProcessPipe_PipeObject*)user;
|
ILibProcessPipe_PipeObject *pipeObject = (ILibProcessPipe_PipeObject*)user;
|
||||||
int consumed;
|
size_t consumed;
|
||||||
int err=0;
|
int err=0;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@@ -948,7 +934,7 @@ void ILibProcessPipe_Process_ReadHandler(void* user)
|
|||||||
if (pipeObject->PAUSED == 0)
|
if (pipeObject->PAUSED == 0)
|
||||||
{
|
{
|
||||||
pipeObject->inProgress = 1;
|
pipeObject->inProgress = 1;
|
||||||
if (ReadFile(pipeObject->mPipe_ReadEnd, pipeObject->buffer + pipeObject->readOffset + pipeObject->totalRead, pipeObject->bufferSize - pipeObject->totalRead, &bytesRead, pipeObject->mOverlapped) != TRUE)
|
if (ReadFile(pipeObject->mPipe_ReadEnd, pipeObject->buffer + pipeObject->readOffset + pipeObject->totalRead, (DWORD)(pipeObject->bufferSize - pipeObject->totalRead), &bytesRead, pipeObject->mOverlapped) != TRUE)
|
||||||
{
|
{
|
||||||
if (GetLastError() == ERROR_IO_PENDING) { return(TRUE); }
|
if (GetLastError() == ERROR_IO_PENDING) { return(TRUE); }
|
||||||
break;
|
break;
|
||||||
@@ -1094,7 +1080,7 @@ void ILibProcessPipe_Pipe_Pause(ILibProcessPipe_Pipe pipeObject)
|
|||||||
|
|
||||||
void ILibProcessPipe_Pipe_ResumeEx_ContinueProcessing(ILibProcessPipe_PipeObject *p)
|
void ILibProcessPipe_Pipe_ResumeEx_ContinueProcessing(ILibProcessPipe_PipeObject *p)
|
||||||
{
|
{
|
||||||
int consumed;
|
size_t consumed;
|
||||||
p->PAUSED = 0;
|
p->PAUSED = 0;
|
||||||
p->processingLoop = 1;
|
p->processingLoop = 1;
|
||||||
while (p->PAUSED == 0 && p->totalRead > 0)
|
while (p->PAUSED == 0 && p->totalRead > 0)
|
||||||
@@ -1156,7 +1142,7 @@ void ILibProcessPipe_Pipe_ResumeEx(ILibProcessPipe_PipeObject* p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
BOOL ILibProcessPipe_Process_Pipe_ReadExHandler(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, char *buffer, int bytesRead, void* user);
|
BOOL ILibProcessPipe_Process_Pipe_ReadExHandler(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, char *buffer, DWORD bytesRead, void* user);
|
||||||
#endif
|
#endif
|
||||||
void ILibProcessPipe_Pipe_Resume(ILibProcessPipe_Pipe pipeObject)
|
void ILibProcessPipe_Pipe_Resume(ILibProcessPipe_Pipe pipeObject)
|
||||||
{
|
{
|
||||||
@@ -1188,7 +1174,7 @@ DWORD ILibProcessPipe_Pipe_BackgroundReader(void *arg)
|
|||||||
{
|
{
|
||||||
ILibProcessPipe_PipeObject *pipeObject = (ILibProcessPipe_PipeObject*)arg;
|
ILibProcessPipe_PipeObject *pipeObject = (ILibProcessPipe_PipeObject*)arg;
|
||||||
DWORD bytesRead = 0;
|
DWORD bytesRead = 0;
|
||||||
int consumed = 0;
|
size_t consumed = 0;
|
||||||
|
|
||||||
while (pipeObject->PAUSED == 0 || WaitForSingleObject(pipeObject->mPipe_Reader_ResumeEvent, INFINITE) == WAIT_OBJECT_0)
|
while (pipeObject->PAUSED == 0 || WaitForSingleObject(pipeObject->mPipe_Reader_ResumeEvent, INFINITE) == WAIT_OBJECT_0)
|
||||||
{
|
{
|
||||||
@@ -1221,7 +1207,7 @@ DWORD ILibProcessPipe_Pipe_BackgroundReader(void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pipeObject->PAUSED == 1) { continue; }
|
if (pipeObject->PAUSED == 1) { continue; }
|
||||||
if (!ReadFile(pipeObject->mPipe_ReadEnd, pipeObject->buffer + pipeObject->readOffset + pipeObject->readNewOffset, pipeObject->bufferSize - pipeObject->readOffset - pipeObject->readNewOffset, &bytesRead, NULL)) { break; }
|
if (!ReadFile(pipeObject->mPipe_ReadEnd, pipeObject->buffer + pipeObject->readOffset + pipeObject->readNewOffset, (DWORD)(pipeObject->bufferSize - pipeObject->readOffset - pipeObject->readNewOffset), &bytesRead, NULL)) { break; }
|
||||||
|
|
||||||
consumed = 0;
|
consumed = 0;
|
||||||
pipeObject->totalRead += bytesRead;
|
pipeObject->totalRead += bytesRead;
|
||||||
@@ -1240,11 +1226,11 @@ DWORD ILibProcessPipe_Pipe_BackgroundReader(void *arg)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
BOOL ILibProcessPipe_Process_Pipe_ReadExHandler(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, char *buffer, int bytesRead, void* user)
|
BOOL ILibProcessPipe_Process_Pipe_ReadExHandler(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, char *buffer, DWORD bytesRead, void* user)
|
||||||
{
|
{
|
||||||
ILibProcessPipe_PipeObject *pipeObject = (ILibProcessPipe_PipeObject*)user;
|
ILibProcessPipe_PipeObject *pipeObject = (ILibProcessPipe_PipeObject*)user;
|
||||||
ILibProcessPipe_GenericReadHandler handler = (ILibProcessPipe_GenericReadHandler)pipeObject->handler;
|
ILibProcessPipe_GenericReadHandler handler = (ILibProcessPipe_GenericReadHandler)pipeObject->handler;
|
||||||
int consumed = 0;
|
size_t consumed = 0;
|
||||||
if (status == ILibWaitHandle_ErrorStatus_NONE)
|
if (status == ILibWaitHandle_ErrorStatus_NONE)
|
||||||
{
|
{
|
||||||
pipeObject->totalRead += bytesRead;
|
pipeObject->totalRead += bytesRead;
|
||||||
@@ -1267,7 +1253,7 @@ BOOL ILibProcessPipe_Process_Pipe_ReadExHandler(void *chain, HANDLE h, ILibWaitH
|
|||||||
ILibMemory_ReallocateRaw(&(pipeObject->buffer), pipeObject->bufferSize * 2);
|
ILibMemory_ReallocateRaw(&(pipeObject->buffer), pipeObject->bufferSize * 2);
|
||||||
pipeObject->bufferSize = pipeObject->bufferSize * 2;
|
pipeObject->bufferSize = pipeObject->bufferSize * 2;
|
||||||
}
|
}
|
||||||
ILibChain_ReadEx2(chain, h, pipeObject->mOverlapped, pipeObject->buffer + pipeObject->readOffset + pipeObject->totalRead, pipeObject->bufferSize - pipeObject->totalRead, ILibProcessPipe_Process_Pipe_ReadExHandler, pipeObject, pipeObject->metadata);
|
ILibChain_ReadEx2(chain, h, pipeObject->mOverlapped, pipeObject->buffer + pipeObject->readOffset + pipeObject->totalRead, (DWORD)(pipeObject->bufferSize - pipeObject->totalRead), ILibProcessPipe_Process_Pipe_ReadExHandler, pipeObject, pipeObject->metadata);
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1330,7 +1316,7 @@ void ILibProcessPipe_Process_StartPipeReaderEx(ILibProcessPipe_PipeObject *pipeO
|
|||||||
if (pipeObject->mOverlapped != NULL)
|
if (pipeObject->mOverlapped != NULL)
|
||||||
{
|
{
|
||||||
// This PIPE supports Overlapped I/O
|
// This PIPE supports Overlapped I/O
|
||||||
ILibChain_ReadEx2(pipeObject->manager->ChainLink.ParentChain, pipeObject->mPipe_ReadEnd, pipeObject->mOverlapped, pipeObject->buffer, pipeObject->bufferSize, ILibProcessPipe_Process_Pipe_ReadExHandler, pipeObject, pipeObject->metadata);
|
ILibChain_ReadEx2(pipeObject->manager->ChainLink.ParentChain, pipeObject->mPipe_ReadEnd, pipeObject->mOverlapped, pipeObject->buffer, (DWORD)pipeObject->bufferSize, ILibProcessPipe_Process_Pipe_ReadExHandler, pipeObject, pipeObject->metadata);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1342,7 +1328,7 @@ void ILibProcessPipe_Process_StartPipeReaderEx(ILibProcessPipe_PipeObject *pipeO
|
|||||||
ILibLifeTime_Add(ILibGetBaseTimer(pipeObject->manager->ChainLink.ParentChain), pipeObject, 0, &ILibProcessPipe_Process_StartPipeReaderWriterEx, NULL); // Need to context switch to Chain Thread
|
ILibLifeTime_Add(ILibGetBaseTimer(pipeObject->manager->ChainLink.ParentChain), pipeObject, 0, &ILibProcessPipe_Process_StartPipeReaderWriterEx, NULL); // Need to context switch to Chain Thread
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
void ILibProcessPipe_Process_PipeHandler_StdOut(char *buffer, int bufferLen, int* bytesConsumed, void* user1, void *user2)
|
void ILibProcessPipe_Process_PipeHandler_StdOut(char *buffer, size_t bufferLen, size_t* bytesConsumed, void* user1, void *user2)
|
||||||
{
|
{
|
||||||
ILibProcessPipe_Process_Object *j = (ILibProcessPipe_Process_Object*)user1;
|
ILibProcessPipe_Process_Object *j = (ILibProcessPipe_Process_Object*)user1;
|
||||||
if (user2 != NULL)
|
if (user2 != NULL)
|
||||||
@@ -1562,7 +1548,7 @@ ILibTransport_DoneState ILibProcessPipe_Process_WriteStdIn(ILibProcessPipe_Proce
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ILibProcessPipe_Pipe_ReadSink(char *buffer, int bufferLen, int* bytesConsumed, void* user1, void* user2)
|
void ILibProcessPipe_Pipe_ReadSink(char *buffer, size_t bufferLen, size_t* bytesConsumed, void* user1, void* user2)
|
||||||
{
|
{
|
||||||
ILibProcessPipe_Pipe target = (ILibProcessPipe_Pipe)user1;
|
ILibProcessPipe_Pipe target = (ILibProcessPipe_Pipe)user1;
|
||||||
|
|
||||||
|
|||||||
@@ -25,12 +25,12 @@ limitations under the License.
|
|||||||
|
|
||||||
typedef void* ILibProcessPipe_Manager;
|
typedef void* ILibProcessPipe_Manager;
|
||||||
typedef void* ILibProcessPipe_Process;
|
typedef void* ILibProcessPipe_Process;
|
||||||
typedef void(*ILibProcessPipe_Process_OutputHandler)(ILibProcessPipe_Process sender, char *buffer, int bufferLen, int* bytesConsumed, void* user);
|
typedef void(*ILibProcessPipe_Process_OutputHandler)(ILibProcessPipe_Process sender, char *buffer, size_t bufferLen, size_t* bytesConsumed, void* user);
|
||||||
typedef void(*ILibProcessPipe_Process_SendOKHandler)(ILibProcessPipe_Process sender, void* user);
|
typedef void(*ILibProcessPipe_Process_SendOKHandler)(ILibProcessPipe_Process sender, void* user);
|
||||||
typedef void(*ILibProcessPipe_Process_ExitHandler)(ILibProcessPipe_Process sender, int exitCode, void* user);
|
typedef void(*ILibProcessPipe_Process_ExitHandler)(ILibProcessPipe_Process sender, int exitCode, void* user);
|
||||||
|
|
||||||
typedef void* ILibProcessPipe_Pipe;
|
typedef void* ILibProcessPipe_Pipe;
|
||||||
typedef void(*ILibProcessPipe_Pipe_ReadHandler)(ILibProcessPipe_Pipe sender, char *buffer, int bufferLen, int* bytesConsumed);
|
typedef void(*ILibProcessPipe_Pipe_ReadHandler)(ILibProcessPipe_Pipe sender, char *buffer, size_t bufferLen, size_t* bytesConsumed);
|
||||||
typedef void(*ILibProcessPipe_Pipe_BrokenPipeHandler)(ILibProcessPipe_Pipe sender);
|
typedef void(*ILibProcessPipe_Pipe_BrokenPipeHandler)(ILibProcessPipe_Pipe sender);
|
||||||
|
|
||||||
typedef enum ILibProcessPipe_SpawnTypes
|
typedef enum ILibProcessPipe_SpawnTypes
|
||||||
@@ -98,7 +98,6 @@ void ILibProcessPipe_Pipe_ResetMetadata(ILibProcessPipe_Pipe p, char *metadata);
|
|||||||
void ILibProcessPipe_Pipe_Close(ILibProcessPipe_Pipe po);
|
void ILibProcessPipe_Pipe_Close(ILibProcessPipe_Pipe po);
|
||||||
void ILibProcessPipe_Pipe_Pause(ILibProcessPipe_Pipe pipeObject);
|
void ILibProcessPipe_Pipe_Pause(ILibProcessPipe_Pipe pipeObject);
|
||||||
void ILibProcessPipe_Pipe_Resume(ILibProcessPipe_Pipe pipeObject);
|
void ILibProcessPipe_Pipe_Resume(ILibProcessPipe_Pipe pipeObject);
|
||||||
void ILibProcessPipe_Pipe_SwapBuffers(ILibProcessPipe_Pipe pipeObject, char* newBuffer, int newBufferLen, int newBufferReadOffset, int newBufferTotalBytesRead, char **oldBuffer, int *oldBufferLen, int *oldBufferReadOffset, int *oldBufferTotalBytesRead);
|
|
||||||
ILibProcessPipe_Pipe ILibProcessPipe_Process_GetStdErr(ILibProcessPipe_Process p);
|
ILibProcessPipe_Pipe ILibProcessPipe_Process_GetStdErr(ILibProcessPipe_Process p);
|
||||||
ILibProcessPipe_Pipe ILibProcessPipe_Process_GetStdOut(ILibProcessPipe_Process p);
|
ILibProcessPipe_Pipe ILibProcessPipe_Process_GetStdOut(ILibProcessPipe_Process p);
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|||||||
@@ -120,16 +120,18 @@ extern int ILibDeflate(char *buffer, size_t bufferLen, char *compressed, size_t
|
|||||||
extern uint32_t crc32c(uint32_t crci, const unsigned char *buf, uint32_t len);
|
extern uint32_t crc32c(uint32_t crci, const unsigned char *buf, uint32_t len);
|
||||||
|
|
||||||
// Perform a SHA384 hash of some data
|
// Perform a SHA384 hash of some data
|
||||||
void ILibSimpleDataStore_SHA384(char *data, int datalen, char* result) { util_sha384(data, datalen, result); }
|
void ILibSimpleDataStore_SHA384(char *data, size_t datalen, char* result) { util_sha384(data, datalen, result); }
|
||||||
|
|
||||||
void ILibSimpleDataStore_CachedEx(ILibSimpleDataStore dataStore, char* key, int keyLen, char* value, int valueLen, char *vhash)
|
void ILibSimpleDataStore_CachedEx(ILibSimpleDataStore dataStore, char* key, size_t keyLen, char* value, size_t valueLen, char *vhash)
|
||||||
{
|
{
|
||||||
|
if (keyLen > INT32_MAX || valueLen > INT32_MAX) { return; }
|
||||||
|
|
||||||
if (vhash != NULL)
|
if (vhash != NULL)
|
||||||
{
|
{
|
||||||
// This is a compresed entry
|
// This is a compresed entry
|
||||||
char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t));
|
char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t));
|
||||||
memcpy_s(tmpkey, ILibMemory_Size(tmpkey), key, keyLen);
|
memcpy_s(tmpkey, ILibMemory_Size(tmpkey), key, keyLen);
|
||||||
((uint32_t*)(tmpkey + keyLen))[0] = crc32c(0, (unsigned char*)key, keyLen);
|
((uint32_t*)(tmpkey + keyLen))[0] = crc32c(0, (unsigned char*)key, (uint32_t)keyLen);
|
||||||
key = tmpkey;
|
key = tmpkey;
|
||||||
keyLen = (int)ILibMemory_Size(key);
|
keyLen = (int)ILibMemory_Size(key);
|
||||||
}
|
}
|
||||||
@@ -153,8 +155,8 @@ void ILibSimpleDataStore_CachedEx(ILibSimpleDataStore dataStore, char* key, int
|
|||||||
}
|
}
|
||||||
ILibSimpleDataStore_Root *root = (ILibSimpleDataStore_Root*)dataStore;
|
ILibSimpleDataStore_Root *root = (ILibSimpleDataStore_Root*)dataStore;
|
||||||
if (root->cacheTable == NULL) { root->cacheTable = ILibHashtable_Create(); }
|
if (root->cacheTable == NULL) { root->cacheTable = ILibHashtable_Create(); }
|
||||||
ILibSimpleDataStore_CacheEntry *entry = (ILibSimpleDataStore_CacheEntry*)ILibMemory_Allocate(sizeof(ILibSimpleDataStore_CacheEntry) + valueLen, 0, NULL, NULL);
|
ILibSimpleDataStore_CacheEntry *entry = (ILibSimpleDataStore_CacheEntry*)ILibMemory_Allocate((int)(sizeof(ILibSimpleDataStore_CacheEntry) + valueLen), 0, NULL, NULL);
|
||||||
entry->valueLength = valueLen;
|
entry->valueLength = (int)valueLen; // No loss of data, becuase it's capped to INT32_MAX
|
||||||
if (valueLen > 0) { memcpy_s(entry->value, valueLen, value, valueLen); }
|
if (valueLen > 0) { memcpy_s(entry->value, valueLen, value, valueLen); }
|
||||||
if (vhash != NULL)
|
if (vhash != NULL)
|
||||||
{
|
{
|
||||||
@@ -165,7 +167,7 @@ void ILibSimpleDataStore_CachedEx(ILibSimpleDataStore dataStore, char* key, int
|
|||||||
ILibSimpleDataStore_SHA384(value, valueLen, entry->valueHash);
|
ILibSimpleDataStore_SHA384(value, valueLen, entry->valueHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
ILibHashtable_Put(root->cacheTable, NULL, key, keyLen, entry);
|
ILibHashtable_Put(root->cacheTable, NULL, key, (int)keyLen, entry); // No loss of data, becuase capped at INT32_MAX
|
||||||
if (vhash != NULL) { ILibMemory_Free(key); }
|
if (vhash != NULL) { ILibMemory_Free(key); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -672,7 +674,7 @@ __EXPORT_TYPE ILibSimpleDataStore ILibSimpleDataStore_CreateEx2(char* filePath,
|
|||||||
|
|
||||||
if (filePath != NULL)
|
if (filePath != NULL)
|
||||||
{
|
{
|
||||||
retVal->filePath = ILibString_Copy(filePath, (int)strnlen_s(filePath, ILibSimpleDataStore_MaxFilePath));
|
retVal->filePath = ILibString_Copy(filePath, strnlen_s(filePath, ILibSimpleDataStore_MaxFilePath));
|
||||||
retVal->dataFile = ILibSimpleDataStore_OpenFileEx2(retVal->filePath, 0, readonly);
|
retVal->dataFile = ILibSimpleDataStore_OpenFileEx2(retVal->filePath, 0, readonly);
|
||||||
|
|
||||||
if (retVal->dataFile == NULL)
|
if (retVal->dataFile == NULL)
|
||||||
@@ -700,7 +702,7 @@ void ILibSimpleDataStore_ReOpenReadOnly(ILibSimpleDataStore dataStore, char* fil
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
root->filePath = ILibString_Copy(filePath, (int)strnlen_s(filePath, ILibSimpleDataStore_MaxFilePath));
|
root->filePath = ILibString_Copy(filePath, strnlen_s(filePath, ILibSimpleDataStore_MaxFilePath));
|
||||||
}
|
}
|
||||||
root->dataFile = ILibSimpleDataStore_OpenFileEx2(root->filePath, 0, 1);
|
root->dataFile = ILibSimpleDataStore_OpenFileEx2(root->filePath, 0, 1);
|
||||||
if (root->dataFile != NULL) { ILibSimpleDataStore_RebuildKeyTable(root); }
|
if (root->dataFile != NULL) { ILibSimpleDataStore_RebuildKeyTable(root); }
|
||||||
@@ -738,16 +740,16 @@ __EXPORT_TYPE void ILibSimpleDataStore_Close(ILibSimpleDataStore dataStore)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Store a key/value pair in the data store
|
// Store a key/value pair in the data store
|
||||||
__EXPORT_TYPE int ILibSimpleDataStore_PutEx2(ILibSimpleDataStore dataStore, char* key, int keyLen, char* value, int valueLen, char *vhash)
|
__EXPORT_TYPE int ILibSimpleDataStore_PutEx2(ILibSimpleDataStore dataStore, char* key, size_t keyLen, char* value, size_t valueLen, char *vhash)
|
||||||
{
|
{
|
||||||
|
if (valueLen > INT32_MAX || valueLen > INT32_MAX || keyLen > INT32_MAX) { return(1); }
|
||||||
int keyAllocated = 0;
|
int keyAllocated = 0;
|
||||||
int allocated = 0;
|
int allocated = 0;
|
||||||
int ret;
|
|
||||||
char hash[SHA384HASHSIZE];
|
char hash[SHA384HASHSIZE];
|
||||||
ILibSimpleDataStore_Root *root = (ILibSimpleDataStore_Root*)dataStore;
|
ILibSimpleDataStore_Root *root = (ILibSimpleDataStore_Root*)dataStore;
|
||||||
ILibSimpleDataStore_TableEntry *entry;
|
ILibSimpleDataStore_TableEntry *entry;
|
||||||
char *origkey = key;
|
char *origkey = key;
|
||||||
int origkeylen = keyLen;
|
int origkeylen = (int)keyLen;
|
||||||
|
|
||||||
if (root == NULL) { return 0; }
|
if (root == NULL) { return 0; }
|
||||||
if (root->dataFile == NULL)
|
if (root->dataFile == NULL)
|
||||||
@@ -761,23 +763,23 @@ __EXPORT_TYPE int ILibSimpleDataStore_PutEx2(ILibSimpleDataStore dataStore, char
|
|||||||
{
|
{
|
||||||
// If we're going to save a compressed record, then we should delete the corrosponding
|
// If we're going to save a compressed record, then we should delete the corrosponding
|
||||||
// non compressed entry, to avoid confusion/conflicts
|
// non compressed entry, to avoid confusion/conflicts
|
||||||
entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Remove(root->keyTable, NULL, key, keyLen);
|
entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Remove(root->keyTable, NULL, key, (int)keyLen); // No loss of data, capped to INT32_MAX
|
||||||
if (entry != NULL)
|
if (entry != NULL)
|
||||||
{
|
{
|
||||||
ILibSimpleDataStore_WriteRecord(root->dataFile, key, keyLen, NULL, 0, NULL);
|
ILibSimpleDataStore_WriteRecord(root->dataFile, key, (int)keyLen, NULL, 0, NULL); // No dataloss, capped to INT32_MAX
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the key to use for the compressed record entry
|
// Calculate the key to use for the compressed record entry
|
||||||
char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(int));
|
char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(int));
|
||||||
keyAllocated = 1;
|
keyAllocated = 1;
|
||||||
memcpy_s(tmpkey, ILibMemory_Size(tmpkey), key, keyLen);
|
memcpy_s(tmpkey, ILibMemory_Size(tmpkey), key, keyLen);
|
||||||
((uint32_t*)(tmpkey + keyLen))[0] = crc32c(0, (unsigned char*)tmpkey, keyLen);
|
((uint32_t*)(tmpkey + keyLen))[0] = crc32c(0, (unsigned char*)tmpkey, (uint32_t)keyLen); // No dataloss, capped to INT32_MAX
|
||||||
key = tmpkey;
|
key = tmpkey;
|
||||||
keyLen = (int)ILibMemory_Size(key);
|
keyLen = (int)ILibMemory_Size(key);
|
||||||
memcpy_s(hash, sizeof(hash), vhash, SHA384HASHSIZE);
|
memcpy_s(hash, sizeof(hash), vhash, SHA384HASHSIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Get(root->keyTable, NULL, key, keyLen);
|
entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Get(root->keyTable, NULL, key, (int)keyLen); // No dataloss, capped to INT32_MAX
|
||||||
if (vhash == NULL) { ILibSimpleDataStore_SHA384(value, valueLen, hash); } // Hash the value
|
if (vhash == NULL) { ILibSimpleDataStore_SHA384(value, valueLen, hash); } // Hash the value
|
||||||
|
|
||||||
// Create a new record for the key and value
|
// Create a new record for the key and value
|
||||||
@@ -793,8 +795,8 @@ __EXPORT_TYPE int ILibSimpleDataStore_PutEx2(ILibSimpleDataStore dataStore, char
|
|||||||
}
|
}
|
||||||
|
|
||||||
memcpy_s(entry->valueHash, sizeof(entry->valueHash), hash, SHA384HASHSIZE);
|
memcpy_s(entry->valueHash, sizeof(entry->valueHash), hash, SHA384HASHSIZE);
|
||||||
entry->valueLength = valueLen;
|
entry->valueLength = (int)valueLen; // No dataloss, capped to INT32_MAX
|
||||||
entry->valueOffset = ILibSimpleDataStore_WriteRecord(root->dataFile, key, keyLen, value, valueLen, entry->valueHash); // Write the key and value
|
entry->valueOffset = ILibSimpleDataStore_WriteRecord(root->dataFile, key, (int)keyLen, value, (int)valueLen, entry->valueHash); // Write the key and value, no dataloss, capped to INT32_MAX
|
||||||
root->fileSize = ILibSimpleDataStore_GetPosition(root->dataFile); // Update the size of the data store;
|
root->fileSize = ILibSimpleDataStore_GetPosition(root->dataFile); // Update the size of the data store;
|
||||||
|
|
||||||
if (entry->valueOffset == 0)
|
if (entry->valueOffset == 0)
|
||||||
@@ -812,18 +814,20 @@ __EXPORT_TYPE int ILibSimpleDataStore_PutEx2(ILibSimpleDataStore dataStore, char
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the record to the data store
|
// Add the record to the data store
|
||||||
ret = ILibHashtable_Put(root->keyTable, NULL, key, keyLen, entry) == NULL ? 0 : 1;
|
ILibHashtable_Put(root->keyTable, NULL, key, (int)keyLen, entry); // No dataloss, capped to INT32_MAX
|
||||||
if (root->warningSize > 0 && root->fileSize > root->warningSize && root->warningSink != NULL)
|
if (root->warningSize > 0 && root->fileSize > root->warningSize && root->warningSink != NULL)
|
||||||
{
|
{
|
||||||
root->warningSink(root, root->fileSize, root->warningSinkUser);
|
root->warningSink(root, root->fileSize, root->warningSinkUser);
|
||||||
}
|
}
|
||||||
if (keyAllocated) { ILibMemory_Free(key); }
|
if (keyAllocated) { ILibMemory_Free(key); }
|
||||||
return(ret);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ILibSimpleDataStore_PutCompressed(ILibSimpleDataStore dataStore, char* key, int keyLen, char* value, int valueLen)
|
int ILibSimpleDataStore_PutCompressed(ILibSimpleDataStore dataStore, char* key, size_t keyLen, char* value, size_t valueLen)
|
||||||
{
|
{
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
|
if (keyLen > INT32_MAX || valueLen > INT32_MAX) { return(ret); }
|
||||||
|
|
||||||
char hash[SHA384HASHSIZE];
|
char hash[SHA384HASHSIZE];
|
||||||
char *tmp = NULL;
|
char *tmp = NULL;
|
||||||
size_t tmpLen = 0;
|
size_t tmpLen = 0;
|
||||||
@@ -850,8 +854,10 @@ __EXPORT_TYPE int ILibSimpleDataStore_GetInt(ILibSimpleDataStore dataStore, char
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get a value from the data store given a key
|
// Get a value from the data store given a key
|
||||||
__EXPORT_TYPE int ILibSimpleDataStore_GetEx(ILibSimpleDataStore dataStore, char* key, int keyLen, char *buffer, int bufferLen)
|
__EXPORT_TYPE int ILibSimpleDataStore_GetEx(ILibSimpleDataStore dataStore, char* key, size_t keyLen, char *buffer, size_t bufferLen)
|
||||||
{
|
{
|
||||||
|
if (keyLen > INT32_MAX || bufferLen > INT32_MAX) { return(0); }
|
||||||
|
|
||||||
int isCompressed = 0;
|
int isCompressed = 0;
|
||||||
char hash[SHA384HASHSIZE];
|
char hash[SHA384HASHSIZE];
|
||||||
ILibSimpleDataStore_Root *root = (ILibSimpleDataStore_Root*)dataStore;
|
ILibSimpleDataStore_Root *root = (ILibSimpleDataStore_Root*)dataStore;
|
||||||
@@ -862,14 +868,14 @@ __EXPORT_TYPE int ILibSimpleDataStore_GetEx(ILibSimpleDataStore dataStore, char*
|
|||||||
|
|
||||||
if (root->cacheTable != NULL)
|
if (root->cacheTable != NULL)
|
||||||
{
|
{
|
||||||
ILibSimpleDataStore_CacheEntry *centry = (ILibSimpleDataStore_CacheEntry*)ILibHashtable_Get(root->cacheTable, NULL, key, keyLen);
|
ILibSimpleDataStore_CacheEntry *centry = (ILibSimpleDataStore_CacheEntry*)ILibHashtable_Get(root->cacheTable, NULL, key, (int)keyLen); // No dataloss, capped to INT32_MAX
|
||||||
if (centry == NULL)
|
if (centry == NULL)
|
||||||
{
|
{
|
||||||
// Let's check if this is a compressed record entry
|
// Let's check if this is a compressed record entry
|
||||||
size_t tmplen = 0;
|
size_t tmplen = 0;
|
||||||
char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t));
|
char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t));
|
||||||
memcpy_s(tmpkey, ILibMemory_Size(tmpkey), key, keyLen);
|
memcpy_s(tmpkey, ILibMemory_Size(tmpkey), key, keyLen);
|
||||||
((uint32_t*)(tmpkey + keyLen))[0] = crc32c(0, (unsigned char*)key, keyLen);
|
((uint32_t*)(tmpkey + keyLen))[0] = crc32c(0, (unsigned char*)key, (uint32_t)keyLen); // No dataloss, capped to INT32_MAX
|
||||||
centry = (ILibSimpleDataStore_CacheEntry*)ILibHashtable_Get(root->cacheTable, NULL, tmpkey, (int)ILibMemory_Size(tmpkey));
|
centry = (ILibSimpleDataStore_CacheEntry*)ILibHashtable_Get(root->cacheTable, NULL, tmpkey, (int)ILibMemory_Size(tmpkey));
|
||||||
if (centry != NULL)
|
if (centry != NULL)
|
||||||
{
|
{
|
||||||
@@ -902,13 +908,13 @@ __EXPORT_TYPE int ILibSimpleDataStore_GetEx(ILibSimpleDataStore dataStore, char*
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Get(root->keyTable, NULL, key, keyLen);
|
entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Get(root->keyTable, NULL, key, (int)keyLen); // No dataloss, capped to INT32_MAX
|
||||||
if (entry == NULL)
|
if (entry == NULL)
|
||||||
{
|
{
|
||||||
// Before returning an error, check if this is a compressed record
|
// Before returning an error, check if this is a compressed record
|
||||||
char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t));
|
char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t));
|
||||||
memcpy_s(tmpkey, ILibMemory_Size(tmpkey), key, keyLen);
|
memcpy_s(tmpkey, ILibMemory_Size(tmpkey), key, keyLen);
|
||||||
((uint32_t*)(tmpkey + keyLen))[0] = crc32c(0, (unsigned char*)tmpkey, keyLen);
|
((uint32_t*)(tmpkey + keyLen))[0] = crc32c(0, (unsigned char*)tmpkey, (uint32_t)keyLen); // no dataloss, capped to INT32_MAX
|
||||||
entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Get(root->keyTable, NULL, tmpkey, (int)ILibMemory_Size(tmpkey));
|
entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Get(root->keyTable, NULL, tmpkey, (int)ILibMemory_Size(tmpkey));
|
||||||
ILibMemory_Free(tmpkey);
|
ILibMemory_Free(tmpkey);
|
||||||
if (entry != NULL) { isCompressed = 1; }
|
if (entry != NULL) { isCompressed = 1; }
|
||||||
@@ -957,21 +963,22 @@ __EXPORT_TYPE int ILibSimpleDataStore_GetEx(ILibSimpleDataStore dataStore, char*
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the reference to the SHA384 hash value from the datastore for a given a key.
|
// Get the reference to the SHA384 hash value from the datastore for a given a key.
|
||||||
__EXPORT_TYPE char* ILibSimpleDataStore_GetHashEx(ILibSimpleDataStore dataStore, char* key, int keyLen)
|
__EXPORT_TYPE char* ILibSimpleDataStore_GetHashEx(ILibSimpleDataStore dataStore, char* key, size_t keyLen)
|
||||||
{
|
{
|
||||||
|
if (keyLen > INT32_MAX) { return(NULL); }
|
||||||
ILibSimpleDataStore_Root *root = (ILibSimpleDataStore_Root*)dataStore;
|
ILibSimpleDataStore_Root *root = (ILibSimpleDataStore_Root*)dataStore;
|
||||||
ILibSimpleDataStore_TableEntry *entry = NULL;
|
ILibSimpleDataStore_TableEntry *entry = NULL;
|
||||||
|
|
||||||
if (root == NULL) return NULL;
|
if (root == NULL) return NULL;
|
||||||
if (root->cacheTable != NULL)
|
if (root->cacheTable != NULL)
|
||||||
{
|
{
|
||||||
ILibSimpleDataStore_CacheEntry *centry = (ILibSimpleDataStore_CacheEntry*)ILibHashtable_Get(root->cacheTable, NULL, key, keyLen);
|
ILibSimpleDataStore_CacheEntry *centry = (ILibSimpleDataStore_CacheEntry*)ILibHashtable_Get(root->cacheTable, NULL, key, (int)keyLen); // no dataloss, capped to INT32_MAX
|
||||||
if (centry == NULL)
|
if (centry == NULL)
|
||||||
{
|
{
|
||||||
// Let's check if this is a compressed record entry
|
// Let's check if this is a compressed record entry
|
||||||
char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t));
|
char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t));
|
||||||
memcpy_s(tmpkey, ILibMemory_Size(tmpkey), key, keyLen);
|
memcpy_s(tmpkey, ILibMemory_Size(tmpkey), key, keyLen);
|
||||||
((uint32_t*)(tmpkey + keyLen))[0] = crc32c(0, (unsigned char*)key, keyLen);
|
((uint32_t*)(tmpkey + keyLen))[0] = crc32c(0, (unsigned char*)key, (uint32_t)keyLen); // no dataloss, capped to INT32_MAX
|
||||||
centry = (ILibSimpleDataStore_CacheEntry*)ILibHashtable_Get(root->cacheTable, NULL, tmpkey, (int)ILibMemory_Size(tmpkey));
|
centry = (ILibSimpleDataStore_CacheEntry*)ILibHashtable_Get(root->cacheTable, NULL, tmpkey, (int)ILibMemory_Size(tmpkey));
|
||||||
if (centry != NULL)
|
if (centry != NULL)
|
||||||
{
|
{
|
||||||
@@ -985,7 +992,7 @@ __EXPORT_TYPE char* ILibSimpleDataStore_GetHashEx(ILibSimpleDataStore dataStore,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Get(root->keyTable, NULL, key, keyLen);
|
entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Get(root->keyTable, NULL, key, (int)keyLen); // no dataloss, capped to INT32_MAX
|
||||||
if (entry == NULL)
|
if (entry == NULL)
|
||||||
{
|
{
|
||||||
// Before we return an error, let's check if this is a compressed record
|
// Before we return an error, let's check if this is a compressed record
|
||||||
@@ -1005,19 +1012,20 @@ int ILibSimpleDataStore_GetHashSize()
|
|||||||
return((int)sizeof(e.valueHash));
|
return((int)sizeof(e.valueHash));
|
||||||
}
|
}
|
||||||
// Delete a key and value from the data store
|
// Delete a key and value from the data store
|
||||||
__EXPORT_TYPE int ILibSimpleDataStore_DeleteEx(ILibSimpleDataStore dataStore, char* key, int keyLen)
|
__EXPORT_TYPE int ILibSimpleDataStore_DeleteEx(ILibSimpleDataStore dataStore, char* key, size_t keyLen)
|
||||||
{
|
{
|
||||||
|
if (keyLen > INT32_MAX) { return(0); }
|
||||||
ILibSimpleDataStore_Root *root = (ILibSimpleDataStore_Root*)dataStore;
|
ILibSimpleDataStore_Root *root = (ILibSimpleDataStore_Root*)dataStore;
|
||||||
ILibSimpleDataStore_TableEntry *entry;
|
ILibSimpleDataStore_TableEntry *entry;
|
||||||
|
|
||||||
if (root == NULL) return 0;
|
if (root == NULL) return 0;
|
||||||
entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Remove(root->keyTable, NULL, key, keyLen);
|
entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Remove(root->keyTable, NULL, key, (int)keyLen); // no dataloss, capped to INT32_MAX
|
||||||
if (entry == NULL)
|
if (entry == NULL)
|
||||||
{
|
{
|
||||||
// Check to see if this is a compressed record, before we return an error
|
// Check to see if this is a compressed record, before we return an error
|
||||||
char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t));
|
char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t));
|
||||||
memcpy_s(tmpkey, ILibMemory_Size(tmpkey), key, keyLen);
|
memcpy_s(tmpkey, ILibMemory_Size(tmpkey), key, keyLen);
|
||||||
((uint32_t*)(tmpkey + keyLen))[0] = crc32c(0, (unsigned char*)key, keyLen);
|
((uint32_t*)(tmpkey + keyLen))[0] = crc32c(0, (unsigned char*)key, (uint32_t)keyLen); // no dataloss, capped to INT32_MAX
|
||||||
entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Remove(root->keyTable, NULL, tmpkey, (int)ILibMemory_Size(tmpkey));
|
entry = (ILibSimpleDataStore_TableEntry*)ILibHashtable_Remove(root->keyTable, NULL, tmpkey, (int)ILibMemory_Size(tmpkey));
|
||||||
if (entry != NULL)
|
if (entry != NULL)
|
||||||
{
|
{
|
||||||
@@ -1033,7 +1041,7 @@ __EXPORT_TYPE int ILibSimpleDataStore_DeleteEx(ILibSimpleDataStore dataStore, ch
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (ILibSimpleDataStore_WriteRecord(root->dataFile, key, keyLen, NULL, 0, NULL) == 0)
|
if (ILibSimpleDataStore_WriteRecord(root->dataFile, key, (int)keyLen, NULL, 0, NULL) == 0) // no dataloss, capped to INT32_MAX
|
||||||
{
|
{
|
||||||
if (root->ErrorHandler != NULL) { root->ErrorHandler(root, root->ErrorHandlerUser); }
|
if (root->ErrorHandler != NULL) { root->ErrorHandler(root, root->ErrorHandlerUser); }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ int ILibSimpleDataStore_Exists(char *filePath);
|
|||||||
|
|
||||||
// Close the data store.
|
// Close the data store.
|
||||||
__EXPORT_TYPE void ILibSimpleDataStore_Close(ILibSimpleDataStore dataStore);
|
__EXPORT_TYPE void ILibSimpleDataStore_Close(ILibSimpleDataStore dataStore);
|
||||||
__EXPORT_TYPE void ILibSimpleDataStore_CachedEx(ILibSimpleDataStore dataStore, char* key, int keyLen, char* value, int valueLen, char *vhash);
|
__EXPORT_TYPE void ILibSimpleDataStore_CachedEx(ILibSimpleDataStore dataStore, char* key, size_t keyLen, char* value, size_t valueLen, char *vhash);
|
||||||
#define ILibSimpleDataStore_Cached(dataStore, key, keyLen, value, valueLen) ILibSimpleDataStore_CachedEx(dataStore, key, keyLen, value, valueLen, NULL)
|
#define ILibSimpleDataStore_Cached(dataStore, key, keyLen, value, valueLen) ILibSimpleDataStore_CachedEx(dataStore, key, keyLen, value, valueLen, NULL)
|
||||||
__EXPORT_TYPE int ILibSimpleDataStore_Cached_GetJSON(ILibSimpleDataStore dataStore, char *buffer, int bufferLen);
|
__EXPORT_TYPE int ILibSimpleDataStore_Cached_GetJSON(ILibSimpleDataStore dataStore, char *buffer, int bufferLen);
|
||||||
__EXPORT_TYPE int ILibSimpleDataStore_Cached_GetJSONEx(ILibSimpleDataStore dataStore, char *buffer, int bufferLen);
|
__EXPORT_TYPE int ILibSimpleDataStore_Cached_GetJSONEx(ILibSimpleDataStore dataStore, char *buffer, int bufferLen);
|
||||||
@@ -63,24 +63,24 @@ __EXPORT_TYPE void ILibSimpleDataStore_ConfigCompact(ILibSimpleDataStore dataSto
|
|||||||
__EXPORT_TYPE void ILibSimpleDataStore_ConfigSizeLimit(ILibSimpleDataStore dataStore, uint64_t sizeLimit, ILibSimpleDataStore_SizeWarningHandler handler, void *user);
|
__EXPORT_TYPE void ILibSimpleDataStore_ConfigSizeLimit(ILibSimpleDataStore dataStore, uint64_t sizeLimit, ILibSimpleDataStore_SizeWarningHandler handler, void *user);
|
||||||
void ILibSimpleDataStore_ConfigWriteErrorHandler(ILibSimpleDataStore dataStore, ILibSimpleDataStore_WriteErrorHandler handler, void *user);
|
void ILibSimpleDataStore_ConfigWriteErrorHandler(ILibSimpleDataStore dataStore, ILibSimpleDataStore_WriteErrorHandler handler, void *user);
|
||||||
|
|
||||||
__EXPORT_TYPE int ILibSimpleDataStore_PutEx2(ILibSimpleDataStore dataStore, char* key, int keyLen, char* value, int valueLen, char *hash);
|
__EXPORT_TYPE int ILibSimpleDataStore_PutEx2(ILibSimpleDataStore dataStore, char* key, size_t keyLen, char* value, size_t valueLen, char *hash);
|
||||||
#define ILibSimpleDataStore_Put(dataStore, key, value) ILibSimpleDataStore_PutEx(dataStore, key, (int)strnlen_s(key, ILibSimpleDataStore_MaxKeyLength), value, (int)strnlen_s(value, ILibSimpleDataStore_MaxUnspecifiedValueLen))
|
#define ILibSimpleDataStore_Put(dataStore, key, value) ILibSimpleDataStore_PutEx(dataStore, key, strnlen_s(key, ILibSimpleDataStore_MaxKeyLength), value, strnlen_s(value, ILibSimpleDataStore_MaxUnspecifiedValueLen))
|
||||||
#define ILibSimpleDataStore_PutEx(dataStore, key, keyLen, value, valueLen) ILibSimpleDataStore_PutEx2(dataStore, key, keyLen, value, valueLen, NULL)
|
#define ILibSimpleDataStore_PutEx(dataStore, key, keyLen, value, valueLen) ILibSimpleDataStore_PutEx2(dataStore, key, keyLen, value, valueLen, NULL)
|
||||||
int ILibSimpleDataStore_PutCompressed(ILibSimpleDataStore dataStore, char* key, int keyLen, char* value, int valueLen);
|
int ILibSimpleDataStore_PutCompressed(ILibSimpleDataStore dataStore, char* key, size_t keyLen, char* value, size_t valueLen);
|
||||||
|
|
||||||
// Get a value from the datastore of given a key.
|
// Get a value from the datastore of given a key.
|
||||||
__EXPORT_TYPE int ILibSimpleDataStore_GetEx(ILibSimpleDataStore dataStore, char* key, int keyLen, char* buffer, int bufferLen);
|
__EXPORT_TYPE int ILibSimpleDataStore_GetEx(ILibSimpleDataStore dataStore, char* key, size_t keyLen, char* buffer, size_t bufferLen);
|
||||||
#define ILibSimpleDataStore_Get(dataStore, key, buffer, bufferLen) ILibSimpleDataStore_GetEx(dataStore, key, (int)strnlen_s(key, ILibSimpleDataStore_MaxKeyLength), buffer, bufferLen)
|
#define ILibSimpleDataStore_Get(dataStore, key, buffer, bufferLen) ILibSimpleDataStore_GetEx(dataStore, key, strnlen_s(key, ILibSimpleDataStore_MaxKeyLength), buffer, bufferLen)
|
||||||
__EXPORT_TYPE int ILibSimpleDataStore_GetInt(ILibSimpleDataStore dataStore, char* key, int defaultValue);
|
__EXPORT_TYPE int ILibSimpleDataStore_GetInt(ILibSimpleDataStore dataStore, char* key, int defaultValue);
|
||||||
|
|
||||||
// Get the SHA384 hash value from the datastore for a given a key.
|
// Get the SHA384 hash value from the datastore for a given a key.
|
||||||
__EXPORT_TYPE char* ILibSimpleDataStore_GetHashEx(ILibSimpleDataStore dataStore, char* key, int keyLen);
|
__EXPORT_TYPE char* ILibSimpleDataStore_GetHashEx(ILibSimpleDataStore dataStore, char* key, size_t keyLen);
|
||||||
#define ILibSimpleDataStore_GetHash(dataStore, key) ILibSimpleDataStore_GetHashEx(dataStore, key, (int)strnlen_s(key, ILibSimpleDataStore_MaxKeyLength))
|
#define ILibSimpleDataStore_GetHash(dataStore, key) ILibSimpleDataStore_GetHashEx(dataStore, key, strnlen_s(key, ILibSimpleDataStore_MaxKeyLength))
|
||||||
int ILibSimpleDataStore_GetHashSize();
|
int ILibSimpleDataStore_GetHashSize();
|
||||||
|
|
||||||
// Delete a key from the data store
|
// Delete a key from the data store
|
||||||
__EXPORT_TYPE int ILibSimpleDataStore_DeleteEx(ILibSimpleDataStore dataStore, char* key, int keyLen);
|
__EXPORT_TYPE int ILibSimpleDataStore_DeleteEx(ILibSimpleDataStore dataStore, char* key, size_t keyLen);
|
||||||
#define ILibSimpleDataStore_Delete(dataStore, key) ILibSimpleDataStore_DeleteEx(dataStore, key, (int)strnlen_s(key, ILibSimpleDataStore_MaxKeyLength))
|
#define ILibSimpleDataStore_Delete(dataStore, key) ILibSimpleDataStore_DeleteEx(dataStore, key, strnlen_s(key, ILibSimpleDataStore_MaxKeyLength))
|
||||||
|
|
||||||
// Enumerate all keys from the data store
|
// Enumerate all keys from the data store
|
||||||
__EXPORT_TYPE void ILibSimpleDataStore_EnumerateKeys(ILibSimpleDataStore dataStore, ILibSimpleDataStore_KeyEnumerationHandler handler, void *user);
|
__EXPORT_TYPE void ILibSimpleDataStore_EnumerateKeys(ILibSimpleDataStore dataStore, ILibSimpleDataStore_KeyEnumerationHandler handler, void *user);
|
||||||
|
|||||||
@@ -277,7 +277,7 @@ typedef struct ILibWebRequest_buffer
|
|||||||
typedef struct ILibWebRequest
|
typedef struct ILibWebRequest
|
||||||
{
|
{
|
||||||
char **Buffer;
|
char **Buffer;
|
||||||
int *BufferLength;
|
size_t *BufferLength;
|
||||||
int *UserFree;
|
int *UserFree;
|
||||||
int NumberOfBuffers;
|
int NumberOfBuffers;
|
||||||
|
|
||||||
@@ -1298,10 +1298,10 @@ ILibAsyncSocket_SendStatus ILibWebClient_WebSocket_Send(ILibWebClient_StateObjec
|
|||||||
for (x = (x << 2); x < bufferLen; ++x) { dataFrame[x] = buffer[x] ^ maskKey[x % 4]; } // Mask the reminder
|
for (x = (x << 2); x < bufferLen; ++x) { dataFrame[x] = buffer[x] ^ maskKey[x % 4]; } // Mask the reminder
|
||||||
//for (x = 0; x < bufferLen; ++x) { dataFrame[x] = buffer[x] ^ maskKey[x % 4]; } // This is the slower version
|
//for (x = 0; x < bufferLen; ++x) { dataFrame[x] = buffer[x] ^ maskKey[x % 4]; } // This is the slower version
|
||||||
}
|
}
|
||||||
RetVal = ILibAsyncSocket_SendTo_MultiWrite(wcdo->SOCK, NULL, 3 | ILibAsyncSocket_LOCK_OVERRIDE, header, headerLen, ILibAsyncSocket_MemoryOwnership_USER, maskKey, 4, ILibAsyncSocket_MemoryOwnership_USER, dataFrame, bufferLen, ILibAsyncSocket_MemoryOwnership_USER);
|
RetVal = ILibAsyncSocket_SendTo_MultiWrite(wcdo->SOCK, NULL, 3 | ILibAsyncSocket_LOCK_OVERRIDE, header, (size_t)headerLen, ILibAsyncSocket_MemoryOwnership_USER, maskKey, 4, ILibAsyncSocket_MemoryOwnership_USER, dataFrame, bufferLen, ILibAsyncSocket_MemoryOwnership_USER);
|
||||||
} else {
|
} else {
|
||||||
// Send payload without masking
|
// Send payload without masking
|
||||||
RetVal = ILibAsyncSocket_SendTo_MultiWrite(wcdo->SOCK, NULL, 2 | ILibAsyncSocket_LOCK_OVERRIDE, header, headerLen, ILibAsyncSocket_MemoryOwnership_USER, buffer, bufferLen, ILibAsyncSocket_MemoryOwnership_USER);
|
RetVal = ILibAsyncSocket_SendTo_MultiWrite(wcdo->SOCK, NULL, 2 | ILibAsyncSocket_LOCK_OVERRIDE, header, (size_t)headerLen, ILibAsyncSocket_MemoryOwnership_USER, buffer, (size_t)bufferLen, ILibAsyncSocket_MemoryOwnership_USER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sem_post(ILibAsyncSocket_GetSendLock(wcdo->SOCK));
|
sem_post(ILibAsyncSocket_GetSendLock(wcdo->SOCK));
|
||||||
@@ -2560,7 +2560,7 @@ ILibWebClient_RequestToken ILibWebClient_PipelineRequest(
|
|||||||
void *user1,
|
void *user1,
|
||||||
void *user2)
|
void *user2)
|
||||||
{
|
{
|
||||||
int bufferLength;
|
size_t bufferLength;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
ILibWebClient_RequestToken retVal;
|
ILibWebClient_RequestToken retVal;
|
||||||
char *webSocketKey;
|
char *webSocketKey;
|
||||||
@@ -2630,10 +2630,10 @@ ILibWebClient_RequestToken ILibWebClient_PipelineRequestEx2(
|
|||||||
ILibWebClient_RequestManager WebClient,
|
ILibWebClient_RequestManager WebClient,
|
||||||
struct sockaddr *RemoteEndpoint,
|
struct sockaddr *RemoteEndpoint,
|
||||||
char *headerBuffer,
|
char *headerBuffer,
|
||||||
int headerBufferLength,
|
size_t headerBufferLength,
|
||||||
int headerBuffer_FREE,
|
int headerBuffer_FREE,
|
||||||
char *bodyBuffer,
|
char *bodyBuffer,
|
||||||
int bodyBufferLength,
|
size_t bodyBufferLength,
|
||||||
int bodyBuffer_FREE,
|
int bodyBuffer_FREE,
|
||||||
ILibWebClient_OnResponse OnResponse,
|
ILibWebClient_OnResponse OnResponse,
|
||||||
struct ILibWebClient_StreamedRequestState *state,
|
struct ILibWebClient_StreamedRequestState *state,
|
||||||
@@ -2657,7 +2657,7 @@ ILibWebClient_RequestToken ILibWebClient_PipelineRequestEx2(
|
|||||||
|
|
||||||
request->NumberOfBuffers = bodyBuffer != NULL?2:1;
|
request->NumberOfBuffers = bodyBuffer != NULL?2:1;
|
||||||
if ((request->Buffer = (char**)malloc(request->NumberOfBuffers * sizeof(char*))) == NULL) ILIBCRITICALEXIT(254);
|
if ((request->Buffer = (char**)malloc(request->NumberOfBuffers * sizeof(char*))) == NULL) ILIBCRITICALEXIT(254);
|
||||||
if ((request->BufferLength = (int*)malloc(request->NumberOfBuffers * sizeof(int))) == NULL) ILIBCRITICALEXIT(254);
|
if ((request->BufferLength = (size_t*)malloc(request->NumberOfBuffers * sizeof(size_t))) == NULL) ILIBCRITICALEXIT(254);
|
||||||
if ((request->UserFree = (int*)malloc(request->NumberOfBuffers * sizeof(int))) == NULL) ILIBCRITICALEXIT(254);
|
if ((request->UserFree = (int*)malloc(request->NumberOfBuffers * sizeof(int))) == NULL) ILIBCRITICALEXIT(254);
|
||||||
|
|
||||||
request->Buffer[0] = headerBuffer;
|
request->Buffer[0] = headerBuffer;
|
||||||
@@ -2867,10 +2867,10 @@ ILibWebClient_RequestToken ILibWebClient_PipelineRequestEx(
|
|||||||
ILibWebClient_RequestManager WebClient,
|
ILibWebClient_RequestManager WebClient,
|
||||||
struct sockaddr *RemoteEndpoint,
|
struct sockaddr *RemoteEndpoint,
|
||||||
char *headerBuffer,
|
char *headerBuffer,
|
||||||
int headerBufferLength,
|
size_t headerBufferLength,
|
||||||
int headerBuffer_FREE,
|
int headerBuffer_FREE,
|
||||||
char *bodyBuffer,
|
char *bodyBuffer,
|
||||||
int bodyBufferLength,
|
size_t bodyBufferLength,
|
||||||
int bodyBuffer_FREE,
|
int bodyBuffer_FREE,
|
||||||
ILibWebClient_OnResponse OnResponse,
|
ILibWebClient_OnResponse OnResponse,
|
||||||
void *user1,
|
void *user1,
|
||||||
@@ -2887,7 +2887,7 @@ ILibWebClient_RequestToken ILibWebClient_PipelineRequest2(
|
|||||||
void *user1,
|
void *user1,
|
||||||
void *user2)
|
void *user2)
|
||||||
{
|
{
|
||||||
int bufferLength;
|
size_t bufferLength;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
|
|
||||||
bufferLength = ILibGetRawPacket(packet, &buffer);
|
bufferLength = ILibGetRawPacket(packet, &buffer);
|
||||||
|
|||||||
@@ -194,10 +194,10 @@ ILibWebClient_RequestToken ILibWebClient_PipelineRequestEx(
|
|||||||
ILibWebClient_RequestManager WebClient,
|
ILibWebClient_RequestManager WebClient,
|
||||||
struct sockaddr *RemoteEndpoint,
|
struct sockaddr *RemoteEndpoint,
|
||||||
char *headerBuffer,
|
char *headerBuffer,
|
||||||
int headerBufferLength,
|
size_t headerBufferLength,
|
||||||
int headerBuffer_FREE,
|
int headerBuffer_FREE,
|
||||||
char *bodyBuffer,
|
char *bodyBuffer,
|
||||||
int bodyBufferLength,
|
size_t bodyBufferLength,
|
||||||
int bodyBuffer_FREE,
|
int bodyBuffer_FREE,
|
||||||
ILibWebClient_OnResponse OnResponse,
|
ILibWebClient_OnResponse OnResponse,
|
||||||
void *user1,
|
void *user1,
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ struct packetheader *header,
|
|||||||
struct ILibWebServer_StateModule *wsm = (struct ILibWebServer_StateModule*)ws->Parent;
|
struct ILibWebServer_StateModule *wsm = (struct ILibWebServer_StateModule*)ws->Parent;
|
||||||
|
|
||||||
char *tmp;
|
char *tmp;
|
||||||
int tmpLength;
|
size_t tmpLength;
|
||||||
struct parser_result *pr;
|
struct parser_result *pr;
|
||||||
int PreSlash = 0;
|
int PreSlash = 0;
|
||||||
|
|
||||||
@@ -1167,15 +1167,15 @@ ILibExportMethod void ILibWebServer_Digest_SendUnauthorized(struct ILibWebServer
|
|||||||
|
|
||||||
int ILibWebServer_Digest_ParseAuthenticationHeader2(char* value, int valueLen, char **token, int *tokenLen, char **tokenValue, int *tokenValueLen)
|
int ILibWebServer_Digest_ParseAuthenticationHeader2(char* value, int valueLen, char **token, int *tokenLen, char **tokenValue, int *tokenValueLen)
|
||||||
{
|
{
|
||||||
int len;
|
size_t len;
|
||||||
int i = ILibString_IndexOf(value, valueLen, "=", 1);
|
int i = ILibString_IndexOf(value, valueLen, "=", 1);
|
||||||
if (i < 0) { return 1; }
|
if (i < 0) { return 1; }
|
||||||
|
|
||||||
*token = value;
|
*token = value;
|
||||||
|
|
||||||
len = ILibTrimString(token, i);
|
len = ILibTrimString(token, i);
|
||||||
//(*token)[len] = 0;
|
if (len > INT32_MAX) { return(1); }
|
||||||
*tokenLen = len;
|
*tokenLen = (int)len;
|
||||||
|
|
||||||
*tokenValue = value + i + 1;
|
*tokenValue = value + i + 1;
|
||||||
len = valueLen - (i + 1);
|
len = valueLen - (i + 1);
|
||||||
@@ -1190,8 +1190,8 @@ int ILibWebServer_Digest_ParseAuthenticationHeader2(char* value, int valueLen, c
|
|||||||
{
|
{
|
||||||
len -= 1;
|
len -= 1;
|
||||||
}
|
}
|
||||||
//(*tokenValue)[len] = 0;
|
if (len > INT32_MAX) { return(1); }
|
||||||
*tokenValueLen = len;
|
*tokenValueLen = (int)len;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void ILibWebServer_Digest_ParseAuthenticationHeader(void* table, char* value, int valueLen)
|
void ILibWebServer_Digest_ParseAuthenticationHeader(void* table, char* value, int valueLen)
|
||||||
@@ -1204,10 +1204,13 @@ void ILibWebServer_Digest_ParseAuthenticationHeader(void* table, char* value, in
|
|||||||
char *token;
|
char *token;
|
||||||
char* tokenValue;
|
char* tokenValue;
|
||||||
int tokenLen, tokenValueLen;
|
int tokenLen, tokenValueLen;
|
||||||
if (ILibWebServer_Digest_ParseAuthenticationHeader2(f->data, f->datalength, &token, &tokenLen, &tokenValue, &tokenValueLen) == 0)
|
if (f->datalength < INT32_MAX)
|
||||||
|
{
|
||||||
|
if (ILibWebServer_Digest_ParseAuthenticationHeader2(f->data, (int)f->datalength, &token, &tokenLen, &tokenValue, &tokenValueLen) == 0)
|
||||||
{
|
{
|
||||||
ILibAddEntryEx(table, token, tokenLen, tokenValue, tokenValueLen);
|
ILibAddEntryEx(table, token, tokenLen, tokenValue, tokenValueLen);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
f = f->NextResult;
|
f = f->NextResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1434,7 +1437,7 @@ ILibExportMethod int ILibWebServer_UpgradeWebSocket(struct ILibWebServer_Session
|
|||||||
ILibExportMethod enum ILibWebServer_Status ILibWebServer_Send(struct ILibWebServer_Session *session, struct packetheader *packet)
|
ILibExportMethod enum ILibWebServer_Status ILibWebServer_Send(struct ILibWebServer_Session *session, struct packetheader *packet)
|
||||||
{
|
{
|
||||||
char *buffer;
|
char *buffer;
|
||||||
int bufferSize;
|
size_t bufferSize;
|
||||||
enum ILibWebServer_Status RetVal = ILibWebServer_ALL_DATA_SENT;
|
enum ILibWebServer_Status RetVal = ILibWebServer_ALL_DATA_SENT;
|
||||||
|
|
||||||
if (session == NULL || session->SessionInterrupted != 0 || ILibWebServer_Session_GetSystemData(session)->WebSocket_Request != NULL)
|
if (session == NULL || session->SessionInterrupted != 0 || ILibWebServer_Session_GetSystemData(session)->WebSocket_Request != NULL)
|
||||||
@@ -1555,10 +1558,10 @@ ILibExportMethod enum ILibWebServer_Status ILibWebServer_WebSocket_Send(struct I
|
|||||||
\param done Flag indicating if this is everything
|
\param done Flag indicating if this is everything
|
||||||
\returns Send Status
|
\returns Send Status
|
||||||
*/
|
*/
|
||||||
ILibExportMethod enum ILibWebServer_Status ILibWebServer_Send_Raw(struct ILibWebServer_Session *session, char *buffer, int bufferSize, enum ILibAsyncSocket_MemoryOwnership userFree, ILibWebServer_DoneFlag done)
|
ILibExportMethod enum ILibWebServer_Status ILibWebServer_Send_Raw(struct ILibWebServer_Session *session, char *buffer, size_t bufferSize, enum ILibAsyncSocket_MemoryOwnership userFree, ILibWebServer_DoneFlag done)
|
||||||
{
|
{
|
||||||
enum ILibWebServer_Status RetVal = ILibWebServer_ALL_DATA_SENT;
|
enum ILibWebServer_Status RetVal = ILibWebServer_ALL_DATA_SENT;
|
||||||
if (bufferSize < 0) { bufferSize = (int)strnlen_s(buffer, ILibWebServer_StreamHeader_Raw_MaxHeaderLength); }
|
if (bufferSize == 0 || bufferSize == (size_t)(-1)) { bufferSize = strnlen_s(buffer, ILibWebServer_StreamHeader_Raw_MaxHeaderLength); }
|
||||||
|
|
||||||
if (session == NULL || (session != NULL && session->SessionInterrupted != 0))
|
if (session == NULL || (session != NULL && session->SessionInterrupted != 0))
|
||||||
{
|
{
|
||||||
@@ -1592,7 +1595,7 @@ enum ILibWebServer_Status ILibWebServer_StreamHeader_Raw(struct ILibWebServer_Se
|
|||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
char *temp;
|
char *temp;
|
||||||
int tempLength;
|
size_t tempLength;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
int bufferLength;
|
int bufferLength;
|
||||||
struct packetheader *hdr;
|
struct packetheader *hdr;
|
||||||
@@ -1735,7 +1738,7 @@ enum ILibWebServer_Status ILibWebServer_StreamHeader_Raw(struct ILibWebServer_Se
|
|||||||
enum ILibWebServer_Status ILibWebServer_StreamHeader(struct ILibWebServer_Session *session, struct packetheader *header)
|
enum ILibWebServer_Status ILibWebServer_StreamHeader(struct ILibWebServer_Session *session, struct packetheader *header)
|
||||||
{
|
{
|
||||||
struct packetheader *hdr;
|
struct packetheader *hdr;
|
||||||
int bufferLength;
|
size_t bufferLength;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
enum ILibWebServer_Status RetVal = ILibWebServer_INVALID_SESSION;
|
enum ILibWebServer_Status RetVal = ILibWebServer_INVALID_SESSION;
|
||||||
|
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ ILibExportMethod void ILibWebServer_WebSocket_Close(struct ILibWebServer_Session
|
|||||||
ILibExportMethod ILibWebServer_WebSocket_DataTypes ILibWebServer_WebSocket_GetDataType(ILibWebServer_Session *session);
|
ILibExportMethod ILibWebServer_WebSocket_DataTypes ILibWebServer_WebSocket_GetDataType(ILibWebServer_Session *session);
|
||||||
|
|
||||||
ILibExportMethod enum ILibWebServer_Status ILibWebServer_Send(struct ILibWebServer_Session *session, struct packetheader *packet);
|
ILibExportMethod enum ILibWebServer_Status ILibWebServer_Send(struct ILibWebServer_Session *session, struct packetheader *packet);
|
||||||
ILibExportMethod enum ILibWebServer_Status ILibWebServer_Send_Raw(struct ILibWebServer_Session *session, char *buffer, int bufferSize, enum ILibAsyncSocket_MemoryOwnership userFree, ILibWebServer_DoneFlag done);
|
ILibExportMethod enum ILibWebServer_Status ILibWebServer_Send_Raw(struct ILibWebServer_Session *session, char *buffer, size_t bufferSize, enum ILibAsyncSocket_MemoryOwnership userFree, ILibWebServer_DoneFlag done);
|
||||||
|
|
||||||
/*! \def ILibWebServer_Session_GetPendingBytesToSend
|
/*! \def ILibWebServer_Session_GetPendingBytesToSend
|
||||||
\brief Returns the number of outstanding bytes to be sent
|
\brief Returns the number of outstanding bytes to be sent
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ char* ILibWrapper_SdpToBlock(char* sdp, int sdpLen, int *isActive, char **userna
|
|||||||
if(f->datalength > 22 && strncmp(f->data, "a=fingerprint:sha-256 ", 22)==0)
|
if(f->datalength > 22 && strncmp(f->data, "a=fingerprint:sha-256 ", 22)==0)
|
||||||
{
|
{
|
||||||
char* tmp = ILibString_Replace(f->data + 22, f->datalength - 22, ":", 1, "", 0);
|
char* tmp = ILibString_Replace(f->data + 22, f->datalength - 22, ":", 1, "", 0);
|
||||||
dtlsHashLen = util_hexToBuf(tmp, (int)strnlen_s(tmp, f->datalength - 22), tmp);
|
dtlsHashLen = (int)util_hexToBuf(tmp, strnlen_s(tmp, f->datalength - 22), tmp); // No Loss of data, becuase DTLS hash length < INT32_MAX
|
||||||
dtlshash = tmp;
|
dtlshash = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user