mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-19 09:43:20 +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 capabilities = 0;
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
int argvi, argvsz;
|
||||
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)
|
||||
{
|
||||
integratedJavaScript = ILibString_Copy(argv[2], -1);
|
||||
integratedJavaScript = ILibString_Copy(argv[2], 0);
|
||||
integratedJavaScriptLen = (int)strnlen_s(integratedJavaScript, sizeof(ILibScratchPad));
|
||||
}
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
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));
|
||||
}
|
||||
if (argc > 1 && strcasecmp(argv[1], "-licenses") == 0)
|
||||
|
||||
@@ -1219,7 +1219,7 @@ void* kvm_server_mainloop(void* parm)
|
||||
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];
|
||||
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(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;
|
||||
UNREFERENCED_PARAMETER(sender);
|
||||
@@ -673,7 +673,7 @@ void kvm_relay_StdOutHandler(ILibProcessPipe_Process sender, char *buffer, int b
|
||||
}
|
||||
*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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
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])))
|
||||
{
|
||||
*bytesConsumed = 8 + (int)ntohl(((unsigned int*)(buffer))[1]);
|
||||
writeHandler(buffer, *bytesConsumed, reserved);
|
||||
writeHandler(buffer, (int)*bytesConsumed, reserved);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1178,7 +1178,7 @@ void kvm_relay_StdOutHandler(ILibProcessPipe_Process sender, char *buffer, int b
|
||||
}
|
||||
*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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -3143,7 +3143,10 @@ void MeshServer_OnResponse(ILibWebClient_StateObject WebStateObject, int Interru
|
||||
MeshCommand_BinaryPacket_ServerId *serveridcmd = (MeshCommand_BinaryPacket_ServerId*)ILibScratchPad2;
|
||||
serveridcmd->command = htons(MeshCommand_ServerId);
|
||||
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
|
||||
{
|
||||
@@ -3281,7 +3284,7 @@ void MeshServer_ConnectEx_NetworkError_Cleanup(void *j)
|
||||
}
|
||||
void MeshServer_ConnectEx(MeshAgentHostContainer *agent)
|
||||
{
|
||||
int len, serverUrlLen;
|
||||
size_t len, serverUrlLen;
|
||||
char *path;
|
||||
char *host;
|
||||
char *serverUrl;
|
||||
@@ -3327,7 +3330,7 @@ void MeshServer_ConnectEx(MeshAgentHostContainer *agent)
|
||||
{
|
||||
if (agent->multicastServerUrl != NULL) {
|
||||
serverUrl = agent->multicastServerUrl;
|
||||
serverUrlLen = (int)strnlen_s(serverUrl, sizeof(ILibScratchPad));
|
||||
serverUrlLen = strnlen_s(serverUrl, sizeof(ILibScratchPad));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3787,7 +3790,7 @@ int importSettings(MeshAgentHostContainer *agent, char* fileName)
|
||||
if (eq > 0)
|
||||
{
|
||||
char *key, *val;
|
||||
int keyLen, valLen;
|
||||
size_t keyLen, valLen;
|
||||
|
||||
key = f->data;
|
||||
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
|
||||
util_openssl_init();
|
||||
#endif
|
||||
|
||||
@@ -553,7 +553,7 @@ int wmain(int argc, char* wargv[])
|
||||
ILibDuktape_ScriptContainer_CheckEmbedded(&integratedJavaScript, &integragedJavaScriptLen);
|
||||
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));
|
||||
}
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1000,7 +1000,7 @@ char* getMshSettings(char* fileName, char* selfexe, char** meshname, char** mesh
|
||||
eq = ILibString_IndexOf(f->data, f->datalength, "=", 1);
|
||||
if (eq > 0) {
|
||||
char *key, *val;
|
||||
int keyLen, valLen;
|
||||
size_t keyLen, valLen;
|
||||
|
||||
key = f->data;
|
||||
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(): "); }
|
||||
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;
|
||||
if (!ILibMemory_CanaryOK(p)) { return; }
|
||||
@@ -145,7 +145,7 @@ void ILibDuktape_ChildProcess_SubProcess_StdOutHandler(ILibProcessPipe_Process s
|
||||
ILibDuktape_readableStream_WriteData(p->stdOut, buffer, 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;
|
||||
if (!ILibMemory_CanaryOK(p)) { return; }
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
// This file is auto-generated, any edits may be overwritten
|
||||
#define SOURCE_COMMIT_DATE "2020-Sep-17 12:49:12-0700"
|
||||
#define SOURCE_COMMIT_HASH "20d4345a87cb5a912f4d891da35bb2ba690b4588"
|
||||
#define SOURCE_COMMIT_DATE "2020-Oct-13 18:14:15-0700"
|
||||
#define SOURCE_COMMIT_HASH "78b65edc4e326bc239cf3fbac6b769bc207057ba"
|
||||
|
||||
@@ -187,7 +187,7 @@ duk_ret_t ILibDuktape_Polyfills_Buffer_from(duk_context *ctx)
|
||||
duk_size_t strlength;
|
||||
char *encoding;
|
||||
char *buffer;
|
||||
int bufferLen;
|
||||
size_t bufferLen;
|
||||
|
||||
if (nargs == 1)
|
||||
{
|
||||
|
||||
@@ -293,18 +293,18 @@ void __stdcall ILibDuktape_readableStream_WriteData_OnData_ChainThread_APC(ULONG
|
||||
}
|
||||
#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;
|
||||
int dispatchedNonNative = 0;
|
||||
int dispatched = 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)
|
||||
{
|
||||
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); }
|
||||
return(stream->paused);
|
||||
}
|
||||
@@ -331,7 +331,7 @@ int ILibDuktape_readableStream_WriteDataEx(ILibDuktape_readableStream *stream, i
|
||||
ILibDuktape_WritableStream *ws = (ILibDuktape_WritableStream*)w->nativeWritable;
|
||||
ws->Reserved = streamReserved;
|
||||
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:
|
||||
ws->OnWriteFlushEx = ILibDuktape_readableStream_WriteData_Flush;
|
||||
@@ -356,7 +356,7 @@ int ILibDuktape_readableStream_WriteDataEx(ILibDuktape_readableStream *stream, i
|
||||
tmp->ctx = stream->ctx;
|
||||
tmp->Next = (ILibDuktape_readableStream_bufferedData*)stream;
|
||||
tmp->Reserved = streamReserved;
|
||||
tmp->bufferLen = bufferLen;
|
||||
tmp->bufferLen = (int)bufferLen;
|
||||
memcpy_s(tmp->buffer, bufferLen, buffer, bufferLen);
|
||||
dispatchedNonNative = 1;
|
||||
needPause = 1;
|
||||
@@ -365,7 +365,7 @@ int ILibDuktape_readableStream_WriteDataEx(ILibDuktape_readableStream *stream, i
|
||||
else
|
||||
{
|
||||
// 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
|
||||
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);
|
||||
#endif
|
||||
tmp->ctx = stream->ctx;
|
||||
tmp->bufferLen = bufferLen;
|
||||
tmp->bufferLen = (int)bufferLen;
|
||||
tmp->Reserved = streamReserved;
|
||||
tmp->Next = (ILibDuktape_readableStream_bufferedData*)stream;
|
||||
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...
|
||||
// So we need to buffer the data, so when we are resumed later, we can retry
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
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);
|
||||
#define ILibDuktape_readableStream_WriteData(stream, buffer, bufferLen) ILibDuktape_readableStream_WriteDataEx(stream, 0, buffer, bufferLen)
|
||||
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);
|
||||
}
|
||||
#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; }
|
||||
|
||||
@@ -3243,7 +3243,7 @@ void ILibDuktape_ScriptContainer_StdOutSink_Chain(void *chain, void *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;
|
||||
|
||||
@@ -3358,7 +3358,7 @@ void ILibDuktape_ScriptContainer_StdErrSink_MicrostackThread(void *chain, void *
|
||||
}
|
||||
#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;
|
||||
|
||||
|
||||
@@ -571,7 +571,7 @@ duk_ret_t ILibDuktape_fs_write_writeset_sink(duk_context *ctx)
|
||||
return(0);
|
||||
}
|
||||
#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;
|
||||
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_eval_string(data->ctx, "require('fs');"); // [callback][this]
|
||||
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]
|
||||
data->write_callback = 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_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);
|
||||
|
||||
#else
|
||||
@@ -726,7 +726,7 @@ duk_ret_t ILibDuktape_fs_write(duk_context *ctx)
|
||||
}
|
||||
|
||||
#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;
|
||||
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_eval_string(data->ctx, "require('fs');"); // [callback][this]
|
||||
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]
|
||||
data->callback = NULL;
|
||||
data->userBuffer = NULL;
|
||||
@@ -892,7 +892,7 @@ duk_ret_t ILibDuktape_fs_read(duk_context *ctx)
|
||||
#ifdef WIN32
|
||||
data->buffer = buffer + offset;
|
||||
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);
|
||||
#else
|
||||
int bytesRead = read(fd, buffer + offset, length);
|
||||
|
||||
@@ -87,7 +87,7 @@ typedef struct ILibDuktape_net_WindowsIPC
|
||||
HANDLE mPipeHandle;
|
||||
int endCalled;
|
||||
int paused;
|
||||
int totalRead;
|
||||
DWORD totalRead;
|
||||
void *user1;
|
||||
void* ipcreserved;
|
||||
|
||||
@@ -101,10 +101,10 @@ typedef struct ILibDuktape_net_WindowsIPC
|
||||
ULONG_PTR _reserved[5];
|
||||
|
||||
char *buffer;
|
||||
int bufferLength;
|
||||
int bufferOffset;
|
||||
int bytesLeft;
|
||||
int unshiftedBytes;
|
||||
DWORD bufferLength;
|
||||
DWORD bufferOffset;
|
||||
DWORD bytesLeft;
|
||||
DWORD unshiftedBytes;
|
||||
}ILibDuktape_net_WindowsIPC;
|
||||
#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);
|
||||
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);
|
||||
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
|
||||
|
||||
|
||||
@@ -917,7 +917,7 @@ void ILibDuktape_net_server_OnSendOK(ILibAsyncServerSocket_ServerModule AsyncSer
|
||||
}
|
||||
|
||||
#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;
|
||||
int consumed = 0;
|
||||
@@ -979,7 +979,7 @@ BOOL ILibDuktape_server_ipc_ReadSink(void *chain, HANDLE h, ILibWaitHandle_Error
|
||||
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); }
|
||||
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; }
|
||||
duk_get_prop_index(winIPC->ctx, -1, 0); // [obj][array][buffer]
|
||||
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]
|
||||
}
|
||||
|
||||
|
||||
@@ -761,7 +761,6 @@ size_t ILibAsyncServerSocket_GetConnections(ILibAsyncServerSocket_ServerModule s
|
||||
{
|
||||
if (ILibAsyncSocket_IsConnected(mod->AsyncSockets[i]))
|
||||
{
|
||||
ILibAsyncServerSocket_Data *data = (ILibAsyncServerSocket_Data*)ILibAsyncSocket_GetUser(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;
|
||||
unsigned int vi;
|
||||
char *buffer;
|
||||
int bufferLen;
|
||||
size_t bufferLen;
|
||||
ILibAsyncSocket_MemoryOwnership UserFree;
|
||||
int lockOverride = ((count & ILibAsyncSocket_LOCK_OVERRIDE) == ILibAsyncSocket_LOCK_OVERRIDE) ? (count ^= ILibAsyncSocket_LOCK_OVERRIDE, 1) : 0;
|
||||
|
||||
// If the socket is empty, return now.
|
||||
if (socketModule == NULL) return ILibAsyncSocket_SEND_ON_CLOSED_SOCKET_ERROR;
|
||||
int notok = 0;
|
||||
|
||||
va_list vlist;
|
||||
va_start(vlist, count);
|
||||
@@ -562,11 +563,18 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_SendTo_MultiWrite(ILibAsyncSocket_Soc
|
||||
for (vi = 0; vi < count; ++vi)
|
||||
{
|
||||
buffer = va_arg(vlist, char*);
|
||||
bufferLen = va_arg(vlist, int);
|
||||
bufferLen = va_arg(vlist, size_t);
|
||||
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_write(module->ssl, buffer, bufferLen);
|
||||
SSL_write(module->ssl, buffer, (int)bufferLen); // No dataloss, becuase we capped at INT32_MAX
|
||||
SSL_TRACE2("SSL_write()");
|
||||
TLSLOG1("SSL_write[%d]: %d bytes...\n", module->internalSocket, bufferLen);
|
||||
|
||||
@@ -574,6 +582,8 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_SendTo_MultiWrite(ILibAsyncSocket_Soc
|
||||
}
|
||||
va_end(vlist);
|
||||
|
||||
if (notok == 0)
|
||||
{
|
||||
if (module->PendingSend_Tail == NULL)
|
||||
{
|
||||
// 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);
|
||||
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 (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)
|
||||
{
|
||||
buffer = va_arg(vlist, char*);
|
||||
bufferLen = va_arg(vlist, int);
|
||||
bufferLen = va_arg(vlist, size_t);
|
||||
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)
|
||||
{
|
||||
// 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->bufferSize = bufferLen;
|
||||
module->PendingBytesToSend += bufferLen;
|
||||
data->bufferSize = (int)bufferLen; // No dataloss, capped to INT32_MAX
|
||||
module->PendingBytesToSend += (int)bufferLen;
|
||||
if (UserFree == ILibAsyncSocket_MemoryOwnership_USER)
|
||||
{
|
||||
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)
|
||||
{
|
||||
// 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
|
||||
{
|
||||
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
|
||||
if ((bytesSent > 0 && bytesSent < bufferLen) || (bytesSent < 0 && WSAGetLastError() == WSAEWOULDBLOCK))
|
||||
if ((bytesSent > 0 && bytesSent < (int)bufferLen) || (bytesSent < 0 && WSAGetLastError() == WSAEWOULDBLOCK))
|
||||
#else
|
||||
if ((bytesSent > 0 && bytesSent < bufferLen) || (bytesSent < 0 && errno == EWOULDBLOCK))
|
||||
if ((bytesSent > 0 && bytesSent < (int)bufferLen) || (bytesSent < 0 && errno == EWOULDBLOCK))
|
||||
#endif
|
||||
{
|
||||
// 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);
|
||||
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);
|
||||
memcpy_s(data->buffer, data->bufferSize, buffer + bytesSent, data->bufferSize);
|
||||
data->UserFree = ILibAsyncSocket_MemoryOwnership_CHAIN;
|
||||
@@ -732,14 +754,14 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_SendTo_MultiWrite(ILibAsyncSocket_Soc
|
||||
else
|
||||
{
|
||||
data->buffer = buffer;
|
||||
data->bufferSize = bufferLen;
|
||||
data->bufferSize = (int)bufferLen; // No dataloss, capped to INT32_MAX
|
||||
data->bytesSent = bytesSent;
|
||||
data->UserFree = UserFree;
|
||||
}
|
||||
module->PendingSend_Head = module->PendingSend_Tail = data;
|
||||
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
|
||||
retVal = ILibAsyncSocket_ALL_DATA_SENT;
|
||||
@@ -760,6 +782,11 @@ ILibAsyncSocket_SendStatus ILibAsyncSocket_SendTo_MultiWrite(ILibAsyncSocket_Soc
|
||||
va_end(vlist);
|
||||
|
||||
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);
|
||||
return (retVal);
|
||||
|
||||
@@ -60,7 +60,8 @@ typedef enum ILibAsyncSocket_SendStatus
|
||||
{
|
||||
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_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;
|
||||
|
||||
/*! \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
|
||||
\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_SendTo(socketModule, buffer, length, remoteAddress, UserFree) ILibAsyncSocket_SendTo_MultiWrite(socketModule, remoteAddress, 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, (size_t)length, UserFree)
|
||||
|
||||
void ILibAsyncSocket_Disconnect(ILibAsyncSocket_SocketModule socketModule);
|
||||
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' };
|
||||
|
||||
|
||||
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_Init(&c);
|
||||
MD5_Update(&c, data, datalen);
|
||||
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;
|
||||
unsigned char *temp = (unsigned char*)out;
|
||||
@@ -94,7 +94,7 @@ void __fastcall util_md5hex(char* data, int datalen, char *out)
|
||||
|
||||
*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;
|
||||
SHA1_Init(&c);
|
||||
@@ -102,14 +102,14 @@ void __fastcall util_sha1(char* data, int datalen, char* result)
|
||||
SHA1_Final((unsigned char*)result, &c);
|
||||
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_Init(&c);
|
||||
SHA256_Update(&c, data, datalen);
|
||||
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;
|
||||
SHA384_Init(&c);
|
||||
@@ -152,9 +152,9 @@ void __fastcall util_free(char* ptr)
|
||||
free(ptr);
|
||||
//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;
|
||||
if (data == NULL || len == 0) { *p = 0; return NULL; }
|
||||
for (i = 0; i < len; i++)
|
||||
@@ -165,9 +165,9 @@ char* __fastcall util_tohex(char* data, int len, char* out)
|
||||
*p = 0;
|
||||
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;
|
||||
if (data == NULL || len == 0) { *p = 0; return NULL; }
|
||||
for (i = 0; i < len; i++)
|
||||
@@ -178,9 +178,9 @@ char* __fastcall util_tohex_lower(char* data, int len, char* out)
|
||||
*p = 0;
|
||||
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;
|
||||
if (data == NULL || len == 0) { *p = 0; return NULL; }
|
||||
for (i = 0; i < len; i++)
|
||||
@@ -196,9 +196,10 @@ char* __fastcall util_tohex2(char* data, int len, char* out)
|
||||
return out;
|
||||
}
|
||||
// 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
|
||||
while (*hexString == '0' && hexStringLength > 0) { hexString++; hexStringLength--; }
|
||||
@@ -214,9 +215,9 @@ int __fastcall util_hexToint(char *hexString, int hexStringLength)
|
||||
}
|
||||
|
||||
// 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); }
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -23,17 +23,17 @@ limitations under the License.
|
||||
#define __fastcall
|
||||
#endif
|
||||
|
||||
void __fastcall util_md5(char* data, int datalen, char* result);
|
||||
void __fastcall util_md5hex(char* data, int datalen, char *out);
|
||||
void __fastcall util_sha1(char* data, int datalen, char* result);
|
||||
char* __fastcall util_tohex(char* data, int len, char* out);
|
||||
char* __fastcall util_tohex2(char* data, int len, char* out);
|
||||
char* __fastcall util_tohex_lower(char* data, int len, char* out);
|
||||
int __fastcall util_hexToint(char *hexString, int hexStringLength);
|
||||
int __fastcall util_hexToBuf(char *hexString, int hexStringLength, char* output);
|
||||
void __fastcall util_md5(char* data, size_t datalen, char* result);
|
||||
void __fastcall util_md5hex(char* data, size_t datalen, char *out);
|
||||
void __fastcall util_sha1(char* data, size_t datalen, char* result);
|
||||
char* __fastcall util_tohex(char* data, size_t len, char* out);
|
||||
char* __fastcall util_tohex2(char* data, size_t len, char* out);
|
||||
char* __fastcall util_tohex_lower(char* data, size_t len, char* out);
|
||||
int __fastcall util_hexToint(char *hexString, size_t hexStringLength);
|
||||
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_sha384(char* data, int datalen, char* result);
|
||||
void __fastcall util_sha256(char* data, size_t datalen, char* result);
|
||||
void __fastcall util_sha384(char* data, size_t datalen, char* result);
|
||||
int __fastcall util_sha384file(char* filename, char* result);
|
||||
|
||||
// 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;
|
||||
*val = strtoull(instr, &eptr, 10);
|
||||
int e = errno;
|
||||
if (errno == ERANGE || eptr == instr || *val > MAX)
|
||||
{
|
||||
*val = 0;
|
||||
@@ -1175,17 +1174,17 @@ void* ILibMemory_AllocateA_Get(void *buffer, size_t sz)
|
||||
|
||||
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); }
|
||||
memset(retVal, 0, containerSize + extraMemorySize + (extraMemorySize > 0 ? 4 : 0));
|
||||
memset(retVal, 0, containerSize + extraMemorySize + (extraMemorySize > 0 ? sizeof(size_t) : 0));
|
||||
if (extraMemorySize > 0)
|
||||
{
|
||||
((int*)(retVal + containerSize))[0] = extraMemorySize;
|
||||
if (extraMemory != NULL) { *extraMemory = (retVal + containerSize + 4); }
|
||||
((size_t*)(retVal + containerSize))[0] = extraMemorySize;
|
||||
if (extraMemory != NULL) { *extraMemory = (retVal + containerSize + sizeof(size_t)); }
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1194,17 +1193,17 @@ void* ILibMemory_Allocate(int containerSize, int extraMemorySize, void** allocat
|
||||
if (allocatedContainer != NULL) { *allocatedContainer = 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; }
|
||||
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;
|
||||
void* extraMemory;
|
||||
@@ -1212,7 +1211,7 @@ ILibChain_Link* ILibChain_Link_Allocate(int structSize, int extraMemorySize)
|
||||
retVal->ExtraMemoryPtr = extraMemory;
|
||||
return retVal;
|
||||
}
|
||||
int ILibChain_Link_GetExtraMemorySize(ILibChain_Link* link)
|
||||
size_t ILibChain_Link_GetExtraMemorySize(ILibChain_Link* link)
|
||||
{
|
||||
return(ILibMemory_GetExtraMemorySize(link->ExtraMemoryPtr));
|
||||
}
|
||||
@@ -3211,7 +3210,7 @@ char *ILibChain_MetaData(char *file, int number)
|
||||
}
|
||||
#ifdef WIN32
|
||||
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));
|
||||
}
|
||||
@@ -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;
|
||||
if (bufferLen > UINT32_MAX) { return(ILibTransport_DoneState_ERROR); }
|
||||
|
||||
if (!WriteFile(h, buffer, (DWORD)bufferLen, NULL, p))
|
||||
{
|
||||
if ((e = GetLastError()) == ERROR_IO_PENDING)
|
||||
@@ -3322,7 +3323,7 @@ ILibTransport_DoneState ILibChain_WriteEx2(void *chain, HANDLE h, OVERLAPPED *p,
|
||||
// Completing Asynchronously
|
||||
ILibChain_WriteEx_data *state = (ILibChain_WriteEx_data*)ILibMemory_SmartAllocate(sizeof(ILibChain_WriteEx_data));
|
||||
state->buffer = buffer;
|
||||
state->bytesLeft = bufferLen;
|
||||
state->bytesLeft = (DWORD)bufferLen;
|
||||
state->totalWritten = 0;
|
||||
state->p = p;
|
||||
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);
|
||||
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;
|
||||
int e = 0;
|
||||
@@ -3432,7 +3433,7 @@ void* ILibChain_WaitHandle_RemoveAndSaveState(void *chain, HANDLE h)
|
||||
}
|
||||
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));
|
||||
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
|
||||
\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_field *field;
|
||||
struct parser_result *temp2;
|
||||
struct parser_result *temp3;
|
||||
char* TagName;
|
||||
int TagNameLength;
|
||||
size_t TagNameLength;
|
||||
int StartTag;
|
||||
int EmptyTag;
|
||||
int i;
|
||||
size_t i;
|
||||
int wsi;
|
||||
|
||||
struct ILibXMLNode *RetVal = NULL;
|
||||
@@ -4463,10 +4464,10 @@ struct ILibXMLNode *ILibParseXML(char *buffer, int offset, int length)
|
||||
struct ILibXMLNode *x = NULL;
|
||||
|
||||
char *NSTag;
|
||||
int NSTagLength;
|
||||
size_t NSTagLength;
|
||||
|
||||
char *CommentEnd = 0;
|
||||
int CommentIndex;
|
||||
size_t CommentIndex;
|
||||
|
||||
//
|
||||
// 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] 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;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
@@ -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)
|
||||
{
|
||||
@@ -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;
|
||||
char TempValue[4];
|
||||
@@ -5147,7 +5148,7 @@ int ILibGetHashValueEx(char *key, int keylength, int caseInSensitiveText)
|
||||
return(HashValue);
|
||||
}
|
||||
|
||||
/*! \fn ILibGetHashValue(char *key, int keylength)
|
||||
/*! \fn ILibGetHashValue(char *key, size_t keylength)
|
||||
\brief Calculates a numeric Hash from a given string
|
||||
\par
|
||||
Used by ILibHashTree methods
|
||||
@@ -5155,7 +5156,7 @@ Used by ILibHashTree methods
|
||||
\param keylength The length of the string to hash
|
||||
\return A hash value
|
||||
*/
|
||||
int ILibGetHashValue(char *key, int keylength)
|
||||
int ILibGetHashValue(const char *key, size_t keylength)
|
||||
{
|
||||
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
|
||||
//
|
||||
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 *current = root->Root;
|
||||
int HashValue = ILibGetHashValueEx(key, keylength, root->CaseInSensitive);
|
||||
int done = 0;
|
||||
|
||||
if (keylength == 0){return(NULL);}
|
||||
|
||||
//
|
||||
// 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);
|
||||
memcpy_s(current->Next->KeyValue, keylength + 1, key ,keylength);
|
||||
current->Next->KeyValue[keylength] = 0;
|
||||
current->Next->KeyLength = keylength;
|
||||
current->Next->KeyLength = (int)keylength; // No dataloss, capped to INT32_MAX
|
||||
return(current->Next);
|
||||
}
|
||||
else
|
||||
@@ -5237,7 +5238,7 @@ struct HashNode* ILibFindEntry(void *hashtree, void *key, int keylength, int cre
|
||||
\param keylength The length of the key
|
||||
\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
|
||||
@@ -5252,7 +5253,7 @@ int ILibHasEntry(void *hashtree, char* key, int keylength)
|
||||
\param keylength The length of the key
|
||||
\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
|
||||
@@ -5268,7 +5269,7 @@ void ILibAddEntry(void* hashtree, char* key, int keylength, void *value)
|
||||
\param value The data to add into the HashTree
|
||||
\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
|
||||
@@ -5289,7 +5290,7 @@ void ILibAddEntryEx(void* hashtree, char* key, int keylength, void *value, int v
|
||||
\param keylength The length of the key
|
||||
\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.
|
||||
@@ -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] 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.
|
||||
@@ -5436,12 +5437,12 @@ int ILibGetULong(const char *TestValue, const int TestValueLength, unsigned long
|
||||
//
|
||||
// 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
|
||||
//
|
||||
int i=0;
|
||||
size_t i=0;
|
||||
int RetVal = 1;
|
||||
if (DelimiterLength>buffersize)
|
||||
{
|
||||
@@ -5478,12 +5479,12 @@ quotation marks, whereas \a ILibParseString does not.
|
||||
\param DelimiterLength The length of the delimiter
|
||||
\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;
|
||||
int i=0;
|
||||
char* Token = NULL;
|
||||
int TokenLength = 0;
|
||||
size_t i=0;
|
||||
const char* Token = NULL;
|
||||
size_t TokenLength = 0;
|
||||
struct parser_result_field *p_resultfield;
|
||||
int Ignore = 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
|
||||
//
|
||||
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->NextResult = NULL;
|
||||
if (RetVal->FirstResult != NULL)
|
||||
@@ -5578,7 +5579,7 @@ struct parser_result* ILibParseStringAdv (char* buffer, int offset, int length,
|
||||
// last delimiter is the token
|
||||
//
|
||||
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->NextResult = 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
|
||||
\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)[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
|
||||
\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;
|
||||
char* Token = NULL;
|
||||
size_t i = 0;
|
||||
const char* Token = NULL;
|
||||
int TokenLength = 0;
|
||||
struct parser_result* RetVal;
|
||||
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
|
||||
//
|
||||
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->NextResult = 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
|
||||
//
|
||||
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->NextResult = NULL;
|
||||
if (RetVal->FirstResult != NULL)
|
||||
@@ -5915,7 +5916,7 @@ int ILibInPlaceHTTPUnEscapeEx(char* data, int length)
|
||||
\param length The length of the buffer to parse
|
||||
\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 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 = 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;
|
||||
}
|
||||
@@ -6128,9 +6132,9 @@ struct packetheader* ILibParsePacketHeader(char* buffer, int offset, int length)
|
||||
\param tokenLength The maximum size of each fragment or token
|
||||
\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( delimiter );
|
||||
@@ -6149,12 +6153,12 @@ int ILibFragmentTextLength(char *text, int textLength, char *delimiter, int deli
|
||||
\param RetVal The buffer to store the resultant 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;
|
||||
int i=0,i2=0;
|
||||
int BufferSize = 0;
|
||||
int allocSize = ILibFragmentTextLength(text, textLength, delimiter, delimiterLength, tokenLength);
|
||||
size_t i=0,i2=0;
|
||||
size_t BufferSize = 0;
|
||||
size_t allocSize = ILibFragmentTextLength(text, textLength, delimiter, delimiterLength, tokenLength);
|
||||
if ((*RetVal = (char*)malloc(allocSize)) == NULL) ILIBCRITICALEXIT(254);
|
||||
|
||||
Buffer = *RetVal;
|
||||
@@ -6184,18 +6188,18 @@ int ILibFragmentText(char *text, int textLength, char *delimiter, int delimiterL
|
||||
\param[out] RetVal The output char* 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;
|
||||
int BufferSize = 0;
|
||||
size_t i,i2;
|
||||
size_t BufferSize = 0;
|
||||
char* Buffer, *temp;
|
||||
|
||||
void *en;
|
||||
|
||||
char *Field;
|
||||
int FieldLength;
|
||||
size_t FieldLength;
|
||||
void *FieldData;
|
||||
int FieldDataLength;
|
||||
size_t FieldDataLength;
|
||||
|
||||
if (packet->StatusCode != -1)
|
||||
{
|
||||
@@ -6221,7 +6225,7 @@ int ILibGetRawPacket(struct packetheader* packet, char **RetVal)
|
||||
while (ILibHashTree_MoveNext(en)==0)
|
||||
{
|
||||
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
|
||||
// 4 characters for the ':' and CRLF
|
||||
@@ -6291,7 +6295,7 @@ int ILibGetRawPacket(struct packetheader* packet, char **RetVal)
|
||||
while (ILibHashTree_MoveNext(en)==0)
|
||||
{
|
||||
ILibHashTree_GetValueEx(en,&Field,&FieldLength,(void**)&FieldData,&FieldDataLength);
|
||||
if (FieldDataLength < 0) { continue; }
|
||||
if (FieldDataLength == (size_t)(-1)) { continue; }
|
||||
|
||||
//
|
||||
// Write each header
|
||||
@@ -6378,10 +6382,10 @@ ILibParseUriResult ILibParseUriEx (const char* URI, size_t URILen, char** Addr,
|
||||
{
|
||||
struct parser_result *result, *result2, *result3;
|
||||
char *TempString, *TempString2;
|
||||
int TempStringLength, TempStringLength2;
|
||||
size_t TempStringLength, TempStringLength2;
|
||||
unsigned short lport;
|
||||
char* laddr = NULL;
|
||||
int laddrLen = 0;
|
||||
size_t laddrLen = 0;
|
||||
|
||||
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 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);}
|
||||
packet->UserAllocVersion = 1;
|
||||
@@ -6627,7 +6631,7 @@ void ILibSetVersion(struct packetheader *packet, char* Version, int VersionLengt
|
||||
\param StatusData The status string, eg: OK
|
||||
\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); }
|
||||
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 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 (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 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;
|
||||
if (FieldNameLength < 0) { FieldNameLength = (int)strnlen_s(FieldName, 255); }
|
||||
if (FieldDataLength < 0) { FieldDataLength = (int)strnlen_s(FieldData, 255); }
|
||||
if (FieldNameLength == 0 || FieldNameLength == (size_t)(-1)) { FieldNameLength = strnlen_s(FieldName, 255); }
|
||||
if (FieldDataLength == 0 || FieldDataLength == (size_t)(-1)) { FieldDataLength = strnlen_s(FieldData, 255); }
|
||||
if (packet->ReservedMemory != NULL)
|
||||
{
|
||||
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->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
|
||||
@@ -7650,7 +7654,7 @@ void* ILibLinkedList_ShallowCopy(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)
|
||||
@@ -8581,13 +8585,16 @@ void ILibSparseArray_UnLock(ILibSparseArray sarray)
|
||||
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
|
||||
int i = 0;
|
||||
size_t i = 0;
|
||||
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);
|
||||
}
|
||||
@@ -8601,11 +8608,11 @@ int ILibString_IndexOfFirstWhiteSpace(const char *inString, int inStringLength)
|
||||
\param caseSensitive 0 if the matching is case-insensitive
|
||||
\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;
|
||||
if (inStringLength < 0) { inStringLength = (int)strnlen_s(inString, sizeof(ILibScratchPad)); }
|
||||
if (endWithStringLength < 0) { endWithStringLength = (int)strnlen_s(endWithString, sizeof(ILibScratchPad)); }
|
||||
if (inStringLength == 0 || inStringLength == (size_t)(-1)) { inStringLength = strnlen_s(inString, sizeof(ILibScratchPad)); }
|
||||
if (endWithStringLength == 0 || endWithStringLength == (size_t)(-1)) { endWithStringLength = strnlen_s(endWithString, sizeof(ILibScratchPad)); }
|
||||
|
||||
if (inStringLength>=endWithStringLength)
|
||||
{
|
||||
@@ -8622,7 +8629,7 @@ int ILibString_EndsWithEx(const char *inString, int inStringLength, const char *
|
||||
\param endWithStringLength The length of \a startsWithString
|
||||
\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));
|
||||
}
|
||||
@@ -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
|
||||
\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;
|
||||
if (inStringLength>=startsWithStringLength)
|
||||
@@ -8653,7 +8660,7 @@ int ILibString_StartsWithEx(const char *inString, int inStringLength, const char
|
||||
\param startsWithStringLength The length of \a startsWithString
|
||||
\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));
|
||||
}
|
||||
@@ -8666,26 +8673,26 @@ int ILibString_StartsWith(const char *inString, int inStringLength, const char *
|
||||
\param caseSensitive Non-zero if the match is case sensitive
|
||||
\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;
|
||||
int index = 0;
|
||||
size_t *RetVal = NULL;
|
||||
size_t index = 0;
|
||||
|
||||
while (inStringLength-index >= indexOfLength)
|
||||
{
|
||||
if (caseSensitive!=0 && memcmp(inString+index,indexOf,indexOfLength)==0)
|
||||
{
|
||||
RetVal = index;
|
||||
RetVal = &index;
|
||||
break;
|
||||
}
|
||||
else if (caseSensitive==0 && strncasecmp(inString+index,indexOf,indexOfLength)==0)
|
||||
{
|
||||
RetVal = index;
|
||||
RetVal = &index;
|
||||
break;
|
||||
}
|
||||
++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)
|
||||
\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
|
||||
\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));
|
||||
}
|
||||
@@ -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
|
||||
\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;
|
||||
int index = (inStringLength < 0 ? (int)strnlen_s(inString, sizeof(ILibScratchPad)) : inStringLength) - (lastIndexOfLength < 0 ? (int)strnlen_s(lastIndexOf, sizeof(ILibScratchPad)) : lastIndexOfLength);
|
||||
size_t *RetVal = NULL;
|
||||
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)
|
||||
{
|
||||
if (caseSensitive!=0 && memcmp(inString+index,lastIndexOf,lastIndexOfLength)==0)
|
||||
{
|
||||
RetVal = index;
|
||||
RetVal = &index;
|
||||
break;
|
||||
}
|
||||
else if (caseSensitive==0 && strncasecmp(inString+index,lastIndexOf,lastIndexOfLength)==0)
|
||||
{
|
||||
RetVal = index;
|
||||
RetVal = &index;
|
||||
break;
|
||||
}
|
||||
--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)
|
||||
\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
|
||||
\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));
|
||||
}
|
||||
@@ -8753,13 +8760,13 @@ int ILibString_LastIndexOf(const char *inString, int inStringLength, const char
|
||||
\param replaceWithThisLength The length of \a replaceWithThis
|
||||
\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;
|
||||
int RetValLength;
|
||||
size_t RetValLength;
|
||||
struct parser_result *pr;
|
||||
struct parser_result_field *prf;
|
||||
int mallocSize;
|
||||
size_t mallocSize;
|
||||
|
||||
pr = ILibParseString((char*)inString, 0, inStringLength,(char*)replaceThis,replaceThisLength);
|
||||
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)
|
||||
{
|
||||
size_t sourceLen = strnlen_s(source, destinationSize);
|
||||
int i;
|
||||
int x = -1;
|
||||
for (i = 0; i < (int)destinationSize - 1; ++i)
|
||||
size_t i;
|
||||
size_t *x = NULL;
|
||||
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); }
|
||||
memcpy_s(destination + x, destinationSize - x, source, sourceLen);
|
||||
destination[x + sourceLen] = 0;
|
||||
if (x == NULL || ((*x + sourceLen + 1 )> destinationSize)) { ILIBCRITICALEXIT(254); }
|
||||
memcpy_s(destination + *x, destinationSize - *x, source, sourceLen);
|
||||
destination[*x + sourceLen] = 0;
|
||||
return(destination);
|
||||
}
|
||||
#ifndef WIN32
|
||||
@@ -8841,7 +8848,7 @@ int ILibMemory_Move_s(void *destination, size_t destinationSize, void *source, s
|
||||
#endif
|
||||
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)
|
||||
{
|
||||
ILIBCRITICALEXIT(254);
|
||||
@@ -8860,21 +8867,21 @@ int ILibString_Copy_s(char *destination, size_t destinationSize, char *source)
|
||||
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;
|
||||
if (inString1Len < 0) { inString1Len = (int)strnlen_s(inString1, sizeof(ILibScratchPad)); }
|
||||
if (inString2Len < 0) { inString2Len = (int)strnlen_s(inString2, sizeof(ILibScratchPad)); }
|
||||
if (inString1Len == 0 || inString1Len == (size_t)(-1)) { inString1Len = strnlen_s(inString1, 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);
|
||||
memcpy_s(RetVal, inString1Len + inString2Len + 1, (char*)inString1, inString1Len);
|
||||
memcpy_s(RetVal + inString1Len, inString2Len + 1, (char*)inString2, inString2Len);
|
||||
RetVal[inString1Len + inString2Len]=0;
|
||||
return RetVal;
|
||||
}
|
||||
char* ILibString_Copy(const char *inString, int length)
|
||||
char* ILibString_Copy(const char *inString, size_t length)
|
||||
{
|
||||
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);
|
||||
memcpy_s(RetVal, length + 1, (char*)inString, length);
|
||||
RetVal[length] = 0;
|
||||
@@ -8882,7 +8889,7 @@ char* ILibString_Copy(const char *inString, int 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);
|
||||
memcpy_s(retVal, length + 1, inString, length);
|
||||
return(retVal);
|
||||
@@ -8895,7 +8902,7 @@ char* ILibString_CopyEx(const char *inString, size_t length)
|
||||
\param length The length of \a inString
|
||||
\return Converted string
|
||||
*/
|
||||
char *ILibString_ToUpper(const char *inString, int length)
|
||||
char *ILibString_ToUpper(const char *inString, size_t length)
|
||||
{
|
||||
char *RetVal;
|
||||
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
|
||||
\return Converted string
|
||||
*/
|
||||
char *ILibString_ToLower(const char *inString, int length)
|
||||
char *ILibString_ToLower(const char *inString, size_t length)
|
||||
{
|
||||
char *RetVal;
|
||||
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));
|
||||
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);
|
||||
(extraMemory + offset)[pathLen] = 0;
|
||||
|
||||
@@ -396,8 +396,8 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
char* MetaData;
|
||||
int RESERVED;
|
||||
}ILibChain_Link;
|
||||
ILibChain_Link* ILibChain_Link_Allocate(int structSize, int extraMemorySize);
|
||||
int ILibChain_Link_GetExtraMemorySize(ILibChain_Link* link);
|
||||
ILibChain_Link* ILibChain_Link_Allocate(size_t structSize, size_t extraMemorySize);
|
||||
size_t ILibChain_Link_GetExtraMemorySize(ILibChain_Link* link);
|
||||
|
||||
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_ReallocateRaw(ppMemory, memSize) if(((*ppMemory) = realloc(*ppMemory, memSize)) == NULL) {ILIBCRITICALEXIT(254);}
|
||||
|
||||
void* ILibMemory_Allocate(int containerSize, int extraMemorySize, void** allocatedContainer, void **extraMemory);
|
||||
int ILibMemory_GetExtraMemorySize(void* extraMemory);
|
||||
ILibExportMethod void* ILibMemory_GetExtraMemory(void *container, int containerSize);
|
||||
void* ILibMemory_Allocate(size_t containerSize, size_t extraMemorySize, void** allocatedContainer, void **extraMemory);
|
||||
size_t ILibMemory_GetExtraMemorySize(void* extraMemory);
|
||||
ILibExportMethod void* ILibMemory_GetExtraMemory(void *container, size_t containerSize);
|
||||
ILibChain_EventHookToken ILibChain_SetEventHook(void* chainLinkObject, int maxTimeout, ILibChain_EventHookHandler handler);
|
||||
void ILibChain_UpdateEventHook(ILibChain_EventHookToken token, int maxTimeout);
|
||||
|
||||
@@ -597,7 +597,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
/*! \var datalength
|
||||
\brief Length of \a data
|
||||
*/
|
||||
int datalength;
|
||||
size_t datalength;
|
||||
|
||||
/*! \var NextResult
|
||||
\brief Pointer to next token
|
||||
@@ -642,7 +642,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
/*! \var FieldLength
|
||||
\brief Length of \a Field
|
||||
*/
|
||||
int FieldLength;
|
||||
size_t FieldLength;
|
||||
/*! \var FieldData
|
||||
\brief Header Value
|
||||
*/
|
||||
@@ -650,7 +650,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
/*! \var FieldDataLength
|
||||
\brief Length of \a FieldData
|
||||
*/
|
||||
int FieldDataLength;
|
||||
size_t FieldDataLength;
|
||||
/*! \var UserAllocStrings
|
||||
\brief Boolean indicating if the above strings are non-static memory
|
||||
*/
|
||||
@@ -677,7 +677,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
/*! \var DirectiveLength
|
||||
\brief Length of \a Directive
|
||||
*/
|
||||
int DirectiveLength;
|
||||
size_t DirectiveLength;
|
||||
/*! \var DirectiveObj
|
||||
\brief HTTP Method Path
|
||||
\par
|
||||
@@ -691,7 +691,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
void *Reserved;
|
||||
char *ReservedMemory;
|
||||
|
||||
int DirectiveObjLength;
|
||||
size_t DirectiveObjLength;
|
||||
/*! \var StatusCode
|
||||
\brief HTTP Response Code
|
||||
\par
|
||||
@@ -707,7 +707,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
/*! \var StatusDataLength
|
||||
\brief Length of \a StatusData
|
||||
*/
|
||||
int StatusDataLength;
|
||||
size_t StatusDataLength;
|
||||
/*! \var Version
|
||||
\brief HTTP Version
|
||||
\par
|
||||
@@ -717,7 +717,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
/*! \var VersionLength
|
||||
\brief Length of \a Version
|
||||
*/
|
||||
int VersionLength;
|
||||
size_t VersionLength;
|
||||
/*! \var Body
|
||||
\brief Pointer to HTTP Body
|
||||
*/
|
||||
@@ -725,7 +725,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
/*! \var BodyLength
|
||||
\brief Length of \a Body
|
||||
*/
|
||||
int BodyLength;
|
||||
size_t BodyLength;
|
||||
/*! \var UserAllocStrings
|
||||
\brief Boolean indicating if Directive/Obj are non-static
|
||||
\par
|
||||
@@ -789,7 +789,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
/*! \var NameLength
|
||||
\brief Length of \a Name
|
||||
*/
|
||||
int NameLength;
|
||||
size_t NameLength;
|
||||
|
||||
/*! \var NSTag
|
||||
\brief Namespace Prefix of the current element
|
||||
@@ -800,7 +800,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
/*! \var NSLength
|
||||
\brief Length of \a NSTag
|
||||
*/
|
||||
int NSLength;
|
||||
size_t NSLength;
|
||||
|
||||
/*! \var StartTag
|
||||
\brief boolean indicating if the current element is a start element
|
||||
@@ -844,7 +844,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
/*! \var NameLength
|
||||
\brief Length of \a Name
|
||||
*/
|
||||
int NameLength;
|
||||
size_t NameLength;
|
||||
|
||||
/*! \var Prefix
|
||||
\brief Namespace Prefix of this attribute
|
||||
@@ -855,7 +855,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
/*! \var PrefixLength
|
||||
\brief Lenth of \a Prefix
|
||||
*/
|
||||
int PrefixLength;
|
||||
size_t PrefixLength;
|
||||
|
||||
/*! \var Parent
|
||||
\brief Pointer to the XML Node that contains this attribute
|
||||
@@ -869,7 +869,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
/*! \var ValueLength
|
||||
\brief Length of \a Value
|
||||
*/
|
||||
int ValueLength;
|
||||
size_t ValueLength;
|
||||
/*! \var Next
|
||||
\brief Pointer to the next attribute
|
||||
*/
|
||||
@@ -931,7 +931,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
//
|
||||
// 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.
|
||||
@@ -1014,9 +1014,9 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
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);
|
||||
#ifdef WIN32
|
||||
typedef void(*ILib_GenericReadHandler)(char *buffer, int bufferLen, int* 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_WriteEx_Handler)(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, int bytesWritten, void* user);
|
||||
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, DWORD bytesRead, void* user);
|
||||
typedef BOOL(*ILibChain_WriteEx_Handler)(void *chain, HANDLE h, ILibWaitHandle_ErrorStatus status, DWORD bytesWritten, void* user);
|
||||
typedef struct ILibChain_ReadEx_data
|
||||
{
|
||||
char *buffer;
|
||||
@@ -1029,8 +1029,8 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
{
|
||||
ILibChain_WriteEx_Handler handler;
|
||||
char *buffer;
|
||||
int bytesLeft;
|
||||
int totalWritten;
|
||||
DWORD bytesLeft;
|
||||
DWORD totalWritten;
|
||||
HANDLE fileHandle;
|
||||
OVERLAPPED *p;
|
||||
void *user;
|
||||
@@ -1040,16 +1040,16 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
void* ILibChain_WaitHandle_RemoveAndSaveState(void *chain, HANDLE h);
|
||||
void ILibChain_WaitHandle_RestoreState(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);
|
||||
|
||||
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);
|
||||
#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_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__))
|
||||
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__))
|
||||
|
||||
#endif
|
||||
@@ -1294,11 +1294,11 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
void* ILibInitHashTree_CaseInSensitiveEx(void *ReservedMemory);
|
||||
#define ILibInitHashTree_CaseInSensitive() ILibInitHashTree_CaseInSensitiveEx(NULL)
|
||||
void ILibDestroyHashTree(void *tree);
|
||||
int ILibHasEntry(void *hashtree, char* key, int keylength);
|
||||
void ILibAddEntry(void* hashtree, char* key, int keylength, void *value);
|
||||
void ILibAddEntryEx(void* hashtree, char* key, int keylength, void *value, int valueEx);
|
||||
void* ILibGetEntry(void *hashtree, char* key, int keylength);
|
||||
ILibExportMethod void ILibGetEntryEx(void *hashtree, char* key, int keylength, void **value, int *valueEx);
|
||||
int ILibHasEntry(void *hashtree, const char* key, size_t keylength);
|
||||
void ILibAddEntry(void* hashtree, const char* key, size_t keylength, void *value);
|
||||
void ILibAddEntryEx(void* hashtree, const char* key, size_t keylength, void *value, int valueEx);
|
||||
void* ILibGetEntry(void *hashtree, const char* key, size_t keylength);
|
||||
ILibExportMethod void ILibGetEntryEx(void *hashtree, const char* key, size_t keylength, void **value, int *valueEx);
|
||||
void ILibDeleteEntry(void *hashtree, char* key, int keylength);
|
||||
|
||||
void *ILibHashTree_GetEnumerator(void *tree);
|
||||
@@ -1306,7 +1306,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
int ILibHashTree_MoveNext(void *tree_enumerator);
|
||||
|
||||
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_UnLock(void *hashtree);
|
||||
|
||||
@@ -1359,27 +1359,27 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
int ILibFindEntryInTable(char *Entry, char **Table);
|
||||
|
||||
|
||||
int ILibTrimString(char **theString, int length);
|
||||
int ILibString_IndexOfFirstWhiteSpace(const char *inString, int inStringLength);
|
||||
char* ILibString_Cat(const char *inString1, int inString1Len, const char *inString2, int inString2Len);
|
||||
size_t ILibTrimString(char **theString, size_t length);
|
||||
int ILibString_IndexOfFirstWhiteSpace(const char *inString, size_t inStringLength);
|
||||
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_Copy(const char *inString, int length);
|
||||
char* ILibString_Copy(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_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_EndsWithEx(const char *inString, int inStringLength, const char *endWithString, int endWithStringLength, int caseSensitive);
|
||||
int ILibString_StartsWith(const char *inString, int inStringLength, const char *startsWithString, int startsWithStringLength);
|
||||
int ILibString_StartsWithEx(const char *inString, int inStringLength, const char *startsWithString, int startsWithStringLength, int caseSensitive);
|
||||
int ILibString_IndexOfEx(const char *inString, int inStringLength, const char *indexOf, int indexOfLength, int caseSensitive);
|
||||
int ILibString_IndexOf(const char *inString, int inStringLength, const char *indexOf, int indexOfLength);
|
||||
int ILibString_LastIndexOf(const char *inString, int inStringLength, const char *lastIndexOf, int lastIndexOfLength);
|
||||
int ILibString_LastIndexOfEx(const char *inString, int inStringLength, const char *lastIndexOf, int lastIndexOfLength, int caseSensitive);
|
||||
char *ILibString_Replace(const char *inString, int inStringLength, const char *replaceThis, int replaceThisLength, const char *replaceWithThis, int replaceWithThisLength);
|
||||
char *ILibString_ToUpper(const char *inString, int length);
|
||||
char *ILibString_ToLower(const char *inString, int length);
|
||||
void ILibToUpper(const char *in, int inLength, char *out);
|
||||
void ILibToLower(const char *in, int inLength, char *out);
|
||||
int ILibString_EndsWith(const char *inString, size_t inStringLength, const char *endWithString, size_t endWithStringLength);
|
||||
int ILibString_EndsWithEx(const char *inString, size_t inStringLength, const char *endWithString, size_t endWithStringLength, int caseSensitive);
|
||||
int ILibString_StartsWith(const char *inString, size_t inStringLength, const char *startsWithString, size_t startsWithStringLength);
|
||||
int ILibString_StartsWithEx(const char *inString, size_t inStringLength, const char *startsWithString, size_t startsWithStringLength, 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, size_t inStringLength, const char *indexOf, size_t indexOfLength);
|
||||
int ILibString_LastIndexOf(const char *inString, size_t inStringLength, const char *lastIndexOf, size_t lastIndexOfLength);
|
||||
int ILibString_LastIndexOfEx(const char *inString, size_t inStringLength, const char *lastIndexOf, size_t lastIndexOfLength, int caseSensitive);
|
||||
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, size_t length);
|
||||
char *ILibString_ToLower(const char *inString, size_t length);
|
||||
void ILibToUpper(const char *in, size_t inLength, char *out);
|
||||
void ILibToLower(const char *in, size_t inLength, char *out);
|
||||
#if !defined(WIN32)
|
||||
#ifndef strcat_s
|
||||
#define strcat_s(destination, destinationSize, source) ILibString_Cat_s(destination, destinationSize, source)
|
||||
@@ -1389,8 +1389,8 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct parser_result* ILibParseString (char* buffer, int offset, int length, const char* Delimiter, int DelimiterLength);
|
||||
struct parser_result* ILibParseStringAdv (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 (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);
|
||||
void ILibDestructParserResults(struct parser_result *result);
|
||||
|
||||
@@ -1406,8 +1406,8 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
|
||||
int ILibGetLong(char *TestValue, int TestValueLength, 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);
|
||||
int ILibFragmentTextLength(char *text, int textLength, char *delimiter, int delimiterLength, int tokenLength);
|
||||
size_t ILibFragmentText(char *text, size_t textLength, char *delimiter, size_t delimiterLength, size_t tokenLength, char **RetVal);
|
||||
size_t ILibFragmentTextLength(char *text, size_t textLength, char *delimiter, size_t delimiterLength, size_t tokenLength);
|
||||
|
||||
|
||||
/* Base64 handling methods */
|
||||
@@ -1432,7 +1432,7 @@ int ILibIsRunningOnChainThread(void* chain);
|
||||
|
||||
struct packetheader *ILibCreateEmptyPacketEx(void *ReservedMemory);
|
||||
#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 ILibHTTPPacket_Stash_Put(ILibHTTPPacket *packet, char* key, int keyLen, void *data);
|
||||
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* ILibGetHeaderLineSP(struct packetheader *packet, char* FieldName, int FieldNameLength);
|
||||
char* ILibGetHeaderLineSP_Next(char* PreviousValue, char* FieldName, int FieldNameLength);
|
||||
void ILibSetVersion(struct packetheader *packet, char* Version, int VersionLength);
|
||||
void ILibSetStatusCode(struct packetheader *packet, int StatusCode, char* StatusData, int StatusDataLength);
|
||||
void ILibSetDirective(struct packetheader *packet, char* Directive, int DirectiveLength, char* DirectiveObj, int DirectiveObjLength);
|
||||
void ILibSetVersion(struct packetheader *packet, char* Version, size_t VersionLength);
|
||||
void ILibSetStatusCode(struct packetheader *packet, int StatusCode, char* StatusData, size_t StatusDataLength);
|
||||
void ILibSetDirective(struct packetheader *packet, char* Directive, size_t DirectiveLength, char* DirectiveObj, size_t DirectiveObjLength);
|
||||
void ILibDestructPacket(struct packetheader *packet);
|
||||
struct packetheader* ILibParsePacketHeader(char* buffer, int offset, int length);
|
||||
int ILibGetRawPacket(struct packetheader *packet,char **buffer);
|
||||
struct packetheader* ILibParsePacketHeader(char* buffer, size_t offset, size_t length);
|
||||
size_t ILibGetRawPacket(struct packetheader *packet,char **buffer);
|
||||
struct packetheader* ILibClonePacket(struct packetheader *packet);
|
||||
|
||||
int ILibHTTPEscapeEx(char* outdata, const char* indata, size_t indataLen);
|
||||
|
||||
@@ -66,7 +66,7 @@ typedef struct ILibProcessPipe_Manager_Object
|
||||
}ILibProcessPipe_Manager_Object;
|
||||
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_GenericBrokenPipeHandler)(struct ILibProcessPipe_PipeObject* sender);
|
||||
struct ILibProcessPipe_Process_Object; // Forward Prototype
|
||||
@@ -74,11 +74,11 @@ struct ILibProcessPipe_Process_Object; // Forward Prototype
|
||||
typedef struct ILibProcessPipe_PipeObject
|
||||
{
|
||||
char* buffer;
|
||||
int bufferSize;
|
||||
size_t bufferSize;
|
||||
ILibTransport_MemoryOwnership bufferOwner;
|
||||
|
||||
int readOffset, readNewOffset;
|
||||
int totalRead;
|
||||
size_t readOffset, readNewOffset;
|
||||
size_t totalRead;
|
||||
int processingLoop;
|
||||
|
||||
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);
|
||||
}
|
||||
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
|
||||
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); }
|
||||
#endif
|
||||
ILibProcessPipe_PipeObject *pipeObject = (ILibProcessPipe_PipeObject*)user;
|
||||
int consumed;
|
||||
size_t consumed;
|
||||
int err=0;
|
||||
|
||||
#ifdef WIN32
|
||||
@@ -948,7 +934,7 @@ void ILibProcessPipe_Process_ReadHandler(void* user)
|
||||
if (pipeObject->PAUSED == 0)
|
||||
{
|
||||
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); }
|
||||
break;
|
||||
@@ -1094,7 +1080,7 @@ void ILibProcessPipe_Pipe_Pause(ILibProcessPipe_Pipe pipeObject)
|
||||
|
||||
void ILibProcessPipe_Pipe_ResumeEx_ContinueProcessing(ILibProcessPipe_PipeObject *p)
|
||||
{
|
||||
int consumed;
|
||||
size_t consumed;
|
||||
p->PAUSED = 0;
|
||||
p->processingLoop = 1;
|
||||
while (p->PAUSED == 0 && p->totalRead > 0)
|
||||
@@ -1156,7 +1142,7 @@ void ILibProcessPipe_Pipe_ResumeEx(ILibProcessPipe_PipeObject* p)
|
||||
}
|
||||
}
|
||||
#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
|
||||
void ILibProcessPipe_Pipe_Resume(ILibProcessPipe_Pipe pipeObject)
|
||||
{
|
||||
@@ -1188,7 +1174,7 @@ DWORD ILibProcessPipe_Pipe_BackgroundReader(void *arg)
|
||||
{
|
||||
ILibProcessPipe_PipeObject *pipeObject = (ILibProcessPipe_PipeObject*)arg;
|
||||
DWORD bytesRead = 0;
|
||||
int consumed = 0;
|
||||
size_t consumed = 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 (!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;
|
||||
pipeObject->totalRead += bytesRead;
|
||||
@@ -1240,11 +1226,11 @@ DWORD ILibProcessPipe_Pipe_BackgroundReader(void *arg)
|
||||
}
|
||||
#endif
|
||||
#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_GenericReadHandler handler = (ILibProcessPipe_GenericReadHandler)pipeObject->handler;
|
||||
int consumed = 0;
|
||||
size_t consumed = 0;
|
||||
if (status == ILibWaitHandle_ErrorStatus_NONE)
|
||||
{
|
||||
pipeObject->totalRead += bytesRead;
|
||||
@@ -1267,7 +1253,7 @@ BOOL ILibProcessPipe_Process_Pipe_ReadExHandler(void *chain, HANDLE h, ILibWaitH
|
||||
ILibMemory_ReallocateRaw(&(pipeObject->buffer), 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);
|
||||
}
|
||||
else
|
||||
@@ -1330,7 +1316,7 @@ void ILibProcessPipe_Process_StartPipeReaderEx(ILibProcessPipe_PipeObject *pipeO
|
||||
if (pipeObject->mOverlapped != NULL)
|
||||
{
|
||||
// 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
|
||||
{
|
||||
@@ -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
|
||||
#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;
|
||||
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;
|
||||
|
||||
|
||||
@@ -25,12 +25,12 @@ limitations under the License.
|
||||
|
||||
typedef void* ILibProcessPipe_Manager;
|
||||
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_ExitHandler)(ILibProcessPipe_Process sender, int exitCode, void* user);
|
||||
|
||||
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 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_Pause(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_GetStdOut(ILibProcessPipe_Process p);
|
||||
#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);
|
||||
|
||||
// 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)
|
||||
{
|
||||
// This is a compresed entry
|
||||
char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t));
|
||||
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;
|
||||
keyLen = (int)ILibMemory_Size(key);
|
||||
}
|
||||
@@ -153,8 +155,8 @@ void ILibSimpleDataStore_CachedEx(ILibSimpleDataStore dataStore, char* key, int
|
||||
}
|
||||
ILibSimpleDataStore_Root *root = (ILibSimpleDataStore_Root*)dataStore;
|
||||
if (root->cacheTable == NULL) { root->cacheTable = ILibHashtable_Create(); }
|
||||
ILibSimpleDataStore_CacheEntry *entry = (ILibSimpleDataStore_CacheEntry*)ILibMemory_Allocate(sizeof(ILibSimpleDataStore_CacheEntry) + valueLen, 0, NULL, NULL);
|
||||
entry->valueLength = valueLen;
|
||||
ILibSimpleDataStore_CacheEntry *entry = (ILibSimpleDataStore_CacheEntry*)ILibMemory_Allocate((int)(sizeof(ILibSimpleDataStore_CacheEntry) + valueLen), 0, NULL, NULL);
|
||||
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 (vhash != NULL)
|
||||
{
|
||||
@@ -165,7 +167,7 @@ void ILibSimpleDataStore_CachedEx(ILibSimpleDataStore dataStore, char* key, int
|
||||
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); }
|
||||
}
|
||||
|
||||
@@ -672,7 +674,7 @@ __EXPORT_TYPE ILibSimpleDataStore ILibSimpleDataStore_CreateEx2(char* filePath,
|
||||
|
||||
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);
|
||||
|
||||
if (retVal->dataFile == NULL)
|
||||
@@ -700,7 +702,7 @@ void ILibSimpleDataStore_ReOpenReadOnly(ILibSimpleDataStore dataStore, char* fil
|
||||
}
|
||||
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);
|
||||
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
|
||||
__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 allocated = 0;
|
||||
int ret;
|
||||
char hash[SHA384HASHSIZE];
|
||||
ILibSimpleDataStore_Root *root = (ILibSimpleDataStore_Root*)dataStore;
|
||||
ILibSimpleDataStore_TableEntry *entry;
|
||||
char *origkey = key;
|
||||
int origkeylen = keyLen;
|
||||
int origkeylen = (int)keyLen;
|
||||
|
||||
if (root == NULL) { return 0; }
|
||||
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
|
||||
// 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)
|
||||
{
|
||||
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
|
||||
char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(int));
|
||||
keyAllocated = 1;
|
||||
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;
|
||||
keyLen = (int)ILibMemory_Size(key);
|
||||
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
|
||||
|
||||
// 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);
|
||||
entry->valueLength = valueLen;
|
||||
entry->valueOffset = ILibSimpleDataStore_WriteRecord(root->dataFile, key, keyLen, value, valueLen, entry->valueHash); // Write the key and value
|
||||
entry->valueLength = (int)valueLen; // No dataloss, capped to INT32_MAX
|
||||
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;
|
||||
|
||||
if (entry->valueOffset == 0)
|
||||
@@ -812,18 +814,20 @@ __EXPORT_TYPE int ILibSimpleDataStore_PutEx2(ILibSimpleDataStore dataStore, char
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
root->warningSink(root, root->fileSize, root->warningSinkUser);
|
||||
}
|
||||
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;
|
||||
if (keyLen > INT32_MAX || valueLen > INT32_MAX) { return(ret); }
|
||||
|
||||
char hash[SHA384HASHSIZE];
|
||||
char *tmp = NULL;
|
||||
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
|
||||
__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;
|
||||
char hash[SHA384HASHSIZE];
|
||||
ILibSimpleDataStore_Root *root = (ILibSimpleDataStore_Root*)dataStore;
|
||||
@@ -862,14 +868,14 @@ __EXPORT_TYPE int ILibSimpleDataStore_GetEx(ILibSimpleDataStore dataStore, char*
|
||||
|
||||
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)
|
||||
{
|
||||
// Let's check if this is a compressed record entry
|
||||
size_t tmplen = 0;
|
||||
char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t));
|
||||
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));
|
||||
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)
|
||||
{
|
||||
// Before returning an error, check if this is a compressed record
|
||||
char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t));
|
||||
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));
|
||||
ILibMemory_Free(tmpkey);
|
||||
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.
|
||||
__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_TableEntry *entry = NULL;
|
||||
|
||||
if (root == NULL) return 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)
|
||||
{
|
||||
// Let's check if this is a compressed record entry
|
||||
char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t));
|
||||
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));
|
||||
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)
|
||||
{
|
||||
// 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));
|
||||
}
|
||||
// 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_TableEntry *entry;
|
||||
|
||||
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)
|
||||
{
|
||||
// Check to see if this is a compressed record, before we return an error
|
||||
char *tmpkey = (char*)ILibMemory_SmartAllocate(keyLen + sizeof(uint32_t));
|
||||
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));
|
||||
if (entry != NULL)
|
||||
{
|
||||
@@ -1033,7 +1041,7 @@ __EXPORT_TYPE int ILibSimpleDataStore_DeleteEx(ILibSimpleDataStore dataStore, ch
|
||||
}
|
||||
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); }
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ int ILibSimpleDataStore_Exists(char *filePath);
|
||||
|
||||
// Close the data store.
|
||||
__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)
|
||||
__EXPORT_TYPE int ILibSimpleDataStore_Cached_GetJSON(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);
|
||||
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);
|
||||
#define ILibSimpleDataStore_Put(dataStore, key, value) ILibSimpleDataStore_PutEx(dataStore, key, (int)strnlen_s(key, ILibSimpleDataStore_MaxKeyLength), value, (int)strnlen_s(value, ILibSimpleDataStore_MaxUnspecifiedValueLen))
|
||||
__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, 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)
|
||||
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.
|
||||
__EXPORT_TYPE int ILibSimpleDataStore_GetEx(ILibSimpleDataStore dataStore, char* key, int keyLen, char* buffer, int bufferLen);
|
||||
#define ILibSimpleDataStore_Get(dataStore, key, buffer, bufferLen) ILibSimpleDataStore_GetEx(dataStore, key, (int)strnlen_s(key, ILibSimpleDataStore_MaxKeyLength), buffer, 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, strnlen_s(key, ILibSimpleDataStore_MaxKeyLength), buffer, bufferLen)
|
||||
__EXPORT_TYPE int ILibSimpleDataStore_GetInt(ILibSimpleDataStore dataStore, char* key, int defaultValue);
|
||||
|
||||
// Get the SHA384 hash value from the datastore for a given a key.
|
||||
__EXPORT_TYPE char* ILibSimpleDataStore_GetHashEx(ILibSimpleDataStore dataStore, char* key, int keyLen);
|
||||
#define ILibSimpleDataStore_GetHash(dataStore, key) ILibSimpleDataStore_GetHashEx(dataStore, key, (int)strnlen_s(key, ILibSimpleDataStore_MaxKeyLength))
|
||||
__EXPORT_TYPE char* ILibSimpleDataStore_GetHashEx(ILibSimpleDataStore dataStore, char* key, size_t keyLen);
|
||||
#define ILibSimpleDataStore_GetHash(dataStore, key) ILibSimpleDataStore_GetHashEx(dataStore, key, strnlen_s(key, ILibSimpleDataStore_MaxKeyLength))
|
||||
int ILibSimpleDataStore_GetHashSize();
|
||||
|
||||
// Delete a key from the data store
|
||||
__EXPORT_TYPE int ILibSimpleDataStore_DeleteEx(ILibSimpleDataStore dataStore, char* key, int keyLen);
|
||||
#define ILibSimpleDataStore_Delete(dataStore, key) ILibSimpleDataStore_DeleteEx(dataStore, key, (int)strnlen_s(key, ILibSimpleDataStore_MaxKeyLength))
|
||||
__EXPORT_TYPE int ILibSimpleDataStore_DeleteEx(ILibSimpleDataStore dataStore, char* key, size_t keyLen);
|
||||
#define ILibSimpleDataStore_Delete(dataStore, key) ILibSimpleDataStore_DeleteEx(dataStore, key, strnlen_s(key, ILibSimpleDataStore_MaxKeyLength))
|
||||
|
||||
// Enumerate all keys from the data store
|
||||
__EXPORT_TYPE void ILibSimpleDataStore_EnumerateKeys(ILibSimpleDataStore dataStore, ILibSimpleDataStore_KeyEnumerationHandler handler, void *user);
|
||||
|
||||
@@ -277,7 +277,7 @@ typedef struct ILibWebRequest_buffer
|
||||
typedef struct ILibWebRequest
|
||||
{
|
||||
char **Buffer;
|
||||
int *BufferLength;
|
||||
size_t *BufferLength;
|
||||
int *UserFree;
|
||||
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 = 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 {
|
||||
// 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));
|
||||
@@ -2560,7 +2560,7 @@ ILibWebClient_RequestToken ILibWebClient_PipelineRequest(
|
||||
void *user1,
|
||||
void *user2)
|
||||
{
|
||||
int bufferLength;
|
||||
size_t bufferLength;
|
||||
char *buffer;
|
||||
ILibWebClient_RequestToken retVal;
|
||||
char *webSocketKey;
|
||||
@@ -2630,10 +2630,10 @@ ILibWebClient_RequestToken ILibWebClient_PipelineRequestEx2(
|
||||
ILibWebClient_RequestManager WebClient,
|
||||
struct sockaddr *RemoteEndpoint,
|
||||
char *headerBuffer,
|
||||
int headerBufferLength,
|
||||
size_t headerBufferLength,
|
||||
int headerBuffer_FREE,
|
||||
char *bodyBuffer,
|
||||
int bodyBufferLength,
|
||||
size_t bodyBufferLength,
|
||||
int bodyBuffer_FREE,
|
||||
ILibWebClient_OnResponse OnResponse,
|
||||
struct ILibWebClient_StreamedRequestState *state,
|
||||
@@ -2657,7 +2657,7 @@ ILibWebClient_RequestToken ILibWebClient_PipelineRequestEx2(
|
||||
|
||||
request->NumberOfBuffers = bodyBuffer != NULL?2:1;
|
||||
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);
|
||||
|
||||
request->Buffer[0] = headerBuffer;
|
||||
@@ -2867,10 +2867,10 @@ ILibWebClient_RequestToken ILibWebClient_PipelineRequestEx(
|
||||
ILibWebClient_RequestManager WebClient,
|
||||
struct sockaddr *RemoteEndpoint,
|
||||
char *headerBuffer,
|
||||
int headerBufferLength,
|
||||
size_t headerBufferLength,
|
||||
int headerBuffer_FREE,
|
||||
char *bodyBuffer,
|
||||
int bodyBufferLength,
|
||||
size_t bodyBufferLength,
|
||||
int bodyBuffer_FREE,
|
||||
ILibWebClient_OnResponse OnResponse,
|
||||
void *user1,
|
||||
@@ -2887,7 +2887,7 @@ ILibWebClient_RequestToken ILibWebClient_PipelineRequest2(
|
||||
void *user1,
|
||||
void *user2)
|
||||
{
|
||||
int bufferLength;
|
||||
size_t bufferLength;
|
||||
char *buffer;
|
||||
|
||||
bufferLength = ILibGetRawPacket(packet, &buffer);
|
||||
|
||||
@@ -194,10 +194,10 @@ ILibWebClient_RequestToken ILibWebClient_PipelineRequestEx(
|
||||
ILibWebClient_RequestManager WebClient,
|
||||
struct sockaddr *RemoteEndpoint,
|
||||
char *headerBuffer,
|
||||
int headerBufferLength,
|
||||
size_t headerBufferLength,
|
||||
int headerBuffer_FREE,
|
||||
char *bodyBuffer,
|
||||
int bodyBufferLength,
|
||||
size_t bodyBufferLength,
|
||||
int bodyBuffer_FREE,
|
||||
ILibWebClient_OnResponse OnResponse,
|
||||
void *user1,
|
||||
|
||||
@@ -242,7 +242,7 @@ struct packetheader *header,
|
||||
struct ILibWebServer_StateModule *wsm = (struct ILibWebServer_StateModule*)ws->Parent;
|
||||
|
||||
char *tmp;
|
||||
int tmpLength;
|
||||
size_t tmpLength;
|
||||
struct parser_result *pr;
|
||||
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 len;
|
||||
size_t len;
|
||||
int i = ILibString_IndexOf(value, valueLen, "=", 1);
|
||||
if (i < 0) { return 1; }
|
||||
|
||||
*token = value;
|
||||
|
||||
len = ILibTrimString(token, i);
|
||||
//(*token)[len] = 0;
|
||||
*tokenLen = len;
|
||||
if (len > INT32_MAX) { return(1); }
|
||||
*tokenLen = (int)len;
|
||||
|
||||
*tokenValue = value + i + 1;
|
||||
len = valueLen - (i + 1);
|
||||
@@ -1190,8 +1190,8 @@ int ILibWebServer_Digest_ParseAuthenticationHeader2(char* value, int valueLen, c
|
||||
{
|
||||
len -= 1;
|
||||
}
|
||||
//(*tokenValue)[len] = 0;
|
||||
*tokenValueLen = len;
|
||||
if (len > INT32_MAX) { return(1); }
|
||||
*tokenValueLen = (int)len;
|
||||
return 0;
|
||||
}
|
||||
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* tokenValue;
|
||||
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);
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
char *buffer;
|
||||
int bufferSize;
|
||||
size_t bufferSize;
|
||||
enum ILibWebServer_Status RetVal = ILibWebServer_ALL_DATA_SENT;
|
||||
|
||||
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
|
||||
\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;
|
||||
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))
|
||||
{
|
||||
@@ -1592,7 +1595,7 @@ enum ILibWebServer_Status ILibWebServer_StreamHeader_Raw(struct ILibWebServer_Se
|
||||
{
|
||||
int len;
|
||||
char *temp;
|
||||
int tempLength;
|
||||
size_t tempLength;
|
||||
char *buffer;
|
||||
int bufferLength;
|
||||
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)
|
||||
{
|
||||
struct packetheader *hdr;
|
||||
int bufferLength;
|
||||
size_t bufferLength;
|
||||
char *buffer;
|
||||
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 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
|
||||
\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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user