You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-15 01:04:37 +02:00
Allow additional memory to be allocated with a mem context.
The primary benefit is that objects can allocate memory for their struct with the context, which saves an additional allocation and makes it easier to read context/allocation dumps. Also, the memory context does not need to be stored with the object since it can be determined using the object pointer. Object pointers cannot be moved, so this means whatever additional memory is allocated cannot be resized. That makes the additional memory ideal for object structs, but not so much for allocating a list that might change size. Mem contexts can no longer be reused since they will probably be the wrong size so their memory is freed on memContextFree(). This still means fewer allocations and frees overall. Interfaces still need to be freed by mem context so the old objMove() and objFree() have been preserved as objMoveContext() and objFreeContext(). This will be addressed in a future commit.
This commit is contained in:
@ -59,7 +59,7 @@ The following sections provide information on some important concepts needed for
|
|||||||
|
|
||||||
### Memory Contexts
|
### Memory Contexts
|
||||||
|
|
||||||
Memory is allocated inside contexts and can be long lasting (for objects) or temporary (for functions). In general, use `MEM_CONTEXT_NEW_BEGIN("SomeName")` for objects and `MEM_CONTEXT_TEMP_BEGIN()` for functions. See [memContext.h](https://github.com/pgbackrest/pgbackrest/blob/master/src/common/memContext.h) for more details and the [Coding Example](#coding-example) below.
|
Memory is allocated inside contexts and can be long lasting (for objects) or temporary (for functions). In general, use `OBJ_NEW_BEGIN(MyObj)` for objects and `MEM_CONTEXT_TEMP_BEGIN()` for functions. See [memContext.h](https://github.com/pgbackrest/pgbackrest/blob/master/src/common/memContext.h) for more details and the [Coding Example](#coding-example) below.
|
||||||
|
|
||||||
### Logging
|
### Logging
|
||||||
|
|
||||||
@ -86,7 +86,6 @@ MyObj *myObjNew(unsigned int myData, const String *secretName);
|
|||||||
// Declare the publicly accessible variables in a structure with Pub appended to the name
|
// Declare the publicly accessible variables in a structure with Pub appended to the name
|
||||||
typedef struct MyObjPub // First letter upper case
|
typedef struct MyObjPub // First letter upper case
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Pointer to memContext in which this object resides
|
|
||||||
unsigned int myData; // Contents of the myData variable
|
unsigned int myData; // Contents of the myData variable
|
||||||
} MyObjPub;
|
} MyObjPub;
|
||||||
|
|
||||||
@ -135,21 +134,20 @@ myObjNew(unsigned int myData, const String *secretName)
|
|||||||
|
|
||||||
MyObj *this = NULL; // Declare the object in the parent memory context: it will live only as long as the parent
|
MyObj *this = NULL; // Declare the object in the parent memory context: it will live only as long as the parent
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("MyObj") // Create a long lasting memory context with the name of the object
|
OBJ_NEW_BEGIN(MyObj) // Create a long lasting memory context with the name of the object
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(MyObj)); // Allocate the memory required by the object
|
this = OBJ_NEW_ALLOC(); // Allocate the memory required by the object
|
||||||
|
|
||||||
*this = (MyObj) // Initialize the object
|
*this = (MyObj) // Initialize the object
|
||||||
{
|
{
|
||||||
.pub =
|
.pub =
|
||||||
{
|
{
|
||||||
.memContext = memContextCurrent(), // Set the memory context to the current MyObj memory context
|
|
||||||
.myData = myData, // Copy the simple data type to this object
|
.myData = myData, // Copy the simple data type to this object
|
||||||
},
|
},
|
||||||
.name = strDup(secretName), // Duplicate the String data type to the this object's memory context
|
.name = strDup(secretName), // Duplicate the String data type to the this object's memory context
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(MyObj, this);
|
FUNCTION_LOG_RETURN(MyObj, this);
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@
|
|||||||
<section id="memory-context">
|
<section id="memory-context">
|
||||||
<title>Memory Contexts</title>
|
<title>Memory Contexts</title>
|
||||||
|
|
||||||
<p>Memory is allocated inside contexts and can be long lasting (for objects) or temporary (for functions). In general, use <code>MEM_CONTEXT_NEW_BEGIN("SomeName")</code> for objects and <code>MEM_CONTEXT_TEMP_BEGIN()</code> for functions. See <link url="{[github-url-src-common]}/memContext.h">memContext.h</link> for more details and the <link section="/coding/coding-example">Coding Example</link> below.</p>
|
<p>Memory is allocated inside contexts and can be long lasting (for objects) or temporary (for functions). In general, use <code>OBJ_NEW_BEGIN(MyObj)</code> for objects and <code>MEM_CONTEXT_TEMP_BEGIN()</code> for functions. See <link url="{[github-url-src-common]}/memContext.h">memContext.h</link> for more details and the <link section="/coding/coding-example">Coding Example</link> below.</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section id="message-logging">
|
<section id="message-logging">
|
||||||
@ -186,7 +186,6 @@ MyObj *myObjNew(unsigned int myData, const String *secretName);
|
|||||||
// Declare the publicly accessible variables in a structure with Pub appended to the name
|
// Declare the publicly accessible variables in a structure with Pub appended to the name
|
||||||
typedef struct MyObjPub // First letter upper case
|
typedef struct MyObjPub // First letter upper case
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Pointer to memContext in which this object resides
|
|
||||||
unsigned int myData; // Contents of the myData variable
|
unsigned int myData; // Contents of the myData variable
|
||||||
} MyObjPub;
|
} MyObjPub;
|
||||||
|
|
||||||
@ -235,21 +234,20 @@ myObjNew(unsigned int myData, const String *secretName)
|
|||||||
|
|
||||||
MyObj *this = NULL; // Declare the object in the parent memory context: it will live only as long as the parent
|
MyObj *this = NULL; // Declare the object in the parent memory context: it will live only as long as the parent
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("MyObj") // Create a long lasting memory context with the name of the object
|
OBJ_NEW_BEGIN(MyObj) // Create a long lasting memory context with the name of the object
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(MyObj)); // Allocate the memory required by the object
|
this = OBJ_NEW_ALLOC(); // Allocate the memory required by the object
|
||||||
|
|
||||||
*this = (MyObj) // Initialize the object
|
*this = (MyObj) // Initialize the object
|
||||||
{
|
{
|
||||||
.pub =
|
.pub =
|
||||||
{
|
{
|
||||||
.memContext = memContextCurrent(), // Set the memory context to the current MyObj memory context
|
|
||||||
.myData = myData, // Copy the simple data type to this object
|
.myData = myData, // Copy the simple data type to this object
|
||||||
},
|
},
|
||||||
.name = strDup(secretName), // Duplicate the String data type to the this object's memory context
|
.name = strDup(secretName), // Duplicate the String data type to the this object's memory context
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(MyObj, this);
|
FUNCTION_LOG_RETURN(MyObj, this);
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ Yaml Handler
|
|||||||
|
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
|
|
||||||
#include "build/common/yaml.h"
|
#include "build/common/yaml.h"
|
||||||
|
|
||||||
@ -16,7 +15,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
struct Yaml
|
struct Yaml
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
yaml_parser_t parser; // Parse context
|
yaml_parser_t parser; // Parse context
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -49,19 +47,15 @@ yamlNew(const Buffer *const buffer)
|
|||||||
|
|
||||||
Yaml *this = NULL;
|
Yaml *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("Yaml")
|
OBJ_NEW_BEGIN(Yaml)
|
||||||
{
|
{
|
||||||
// Create object
|
// Create object
|
||||||
this = memNew(sizeof(Yaml));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
*this = (Yaml){0};
|
||||||
*this = (Yaml)
|
|
||||||
{
|
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Initialize parser context
|
// Initialize parser context
|
||||||
CHECK(yaml_parser_initialize(&this->parser));
|
CHECK(yaml_parser_initialize(&this->parser));
|
||||||
memContextCallbackSet(this->memContext, yamlFreeResource, this);
|
memContextCallbackSet(objMemContext(this), yamlFreeResource, this);
|
||||||
|
|
||||||
// Set yaml string
|
// Set yaml string
|
||||||
yaml_parser_set_input_string(&this->parser, bufPtrConst(buffer), bufUsed(buffer));
|
yaml_parser_set_input_string(&this->parser, bufPtrConst(buffer), bufUsed(buffer));
|
||||||
@ -70,7 +64,7 @@ yamlNew(const Buffer *const buffer)
|
|||||||
CHECK(yamlEventNext(this).type == yamlEventTypeStreamBegin);
|
CHECK(yamlEventNext(this).type == yamlEventTypeStreamBegin);
|
||||||
CHECK(yamlEventNext(this).type == yamlEventTypeDocBegin);
|
CHECK(yamlEventNext(this).type == yamlEventTypeDocBegin);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(this);
|
FUNCTION_TEST_RETURN(this);
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ Page Checksum Filter
|
|||||||
#include "command/backup/pageChecksum.h"
|
#include "command/backup/pageChecksum.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/macro.h"
|
#include "common/macro.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
#include "postgres/interface.h"
|
#include "postgres/interface.h"
|
||||||
#include "postgres/interface/static.vendor.h"
|
#include "postgres/interface/static.vendor.h"
|
||||||
@ -229,9 +228,9 @@ pageChecksumNew(unsigned int segmentNo, unsigned int segmentPageTotal, uint64_t
|
|||||||
|
|
||||||
IoFilter *this = NULL;
|
IoFilter *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("PageChecksum")
|
OBJ_NEW_BEGIN(PageChecksum)
|
||||||
{
|
{
|
||||||
PageChecksum *driver = memNew(sizeof(PageChecksum));
|
PageChecksum *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (PageChecksum)
|
*driver = (PageChecksum)
|
||||||
{
|
{
|
||||||
@ -251,7 +250,7 @@ pageChecksumNew(unsigned int segmentNo, unsigned int segmentPageTotal, uint64_t
|
|||||||
this = ioFilterNewP(
|
this = ioFilterNewP(
|
||||||
PAGE_CHECKSUM_FILTER_TYPE_STR, driver, paramList, .in = pageChecksumProcess, .result = pageChecksumResult);
|
PAGE_CHECKSUM_FILTER_TYPE_STR, driver, paramList, .in = pageChecksumProcess, .result = pageChecksumResult);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ BZ2 Compress
|
|||||||
#include "common/io/filter/filter.h"
|
#include "common/io/filter/filter.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/macro.h"
|
#include "common/macro.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -25,7 +24,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct Bz2Compress
|
typedef struct Bz2Compress
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Context to store data
|
|
||||||
bz_stream stream; // Compression stream
|
bz_stream stream; // Compression stream
|
||||||
|
|
||||||
bool inputSame; // Is the same input required on the next process call?
|
bool inputSame; // Is the same input required on the next process call?
|
||||||
@ -173,13 +171,12 @@ bz2CompressNew(int level)
|
|||||||
|
|
||||||
IoFilter *this = NULL;
|
IoFilter *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("Bz2Compress")
|
OBJ_NEW_BEGIN(Bz2Compress)
|
||||||
{
|
{
|
||||||
Bz2Compress *driver = memNew(sizeof(Bz2Compress));
|
Bz2Compress *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (Bz2Compress)
|
*driver = (Bz2Compress)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.stream = {.bzalloc = NULL},
|
.stream = {.bzalloc = NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -187,7 +184,7 @@ bz2CompressNew(int level)
|
|||||||
bz2Error(BZ2_bzCompressInit(&driver->stream, level, 0, 0));
|
bz2Error(BZ2_bzCompressInit(&driver->stream, level, 0, 0));
|
||||||
|
|
||||||
// Set callback to ensure bz2 stream is freed
|
// Set callback to ensure bz2 stream is freed
|
||||||
memContextCallbackSet(driver->memContext, bz2CompressFreeResource, driver);
|
memContextCallbackSet(objMemContext(driver), bz2CompressFreeResource, driver);
|
||||||
|
|
||||||
// Create param list
|
// Create param list
|
||||||
VariantList *paramList = varLstNew();
|
VariantList *paramList = varLstNew();
|
||||||
@ -198,7 +195,7 @@ bz2CompressNew(int level)
|
|||||||
BZ2_COMPRESS_FILTER_TYPE_STR, driver, paramList, .done = bz2CompressDone, .inOut = bz2CompressProcess,
|
BZ2_COMPRESS_FILTER_TYPE_STR, driver, paramList, .done = bz2CompressDone, .inOut = bz2CompressProcess,
|
||||||
.inputSame = bz2CompressInputSame);
|
.inputSame = bz2CompressInputSame);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ BZ2 Decompress
|
|||||||
#include "common/io/filter/filter.h"
|
#include "common/io/filter/filter.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/macro.h"
|
#include "common/macro.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -25,7 +24,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct Bz2Decompress
|
typedef struct Bz2Decompress
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Context to store data
|
|
||||||
bz_stream stream; // Decompression stream state
|
bz_stream stream; // Decompression stream state
|
||||||
|
|
||||||
int result; // Result of last operation
|
int result; // Result of last operation
|
||||||
@ -157,14 +155,13 @@ bz2DecompressNew(void)
|
|||||||
|
|
||||||
IoFilter *this = NULL;
|
IoFilter *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("Bz2Decompress")
|
OBJ_NEW_BEGIN(Bz2Decompress)
|
||||||
{
|
{
|
||||||
// Allocate state and set context
|
// Allocate state and set context
|
||||||
Bz2Decompress *driver = memNew(sizeof(Bz2Decompress));
|
Bz2Decompress *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (Bz2Decompress)
|
*driver = (Bz2Decompress)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.stream = {.bzalloc = NULL},
|
.stream = {.bzalloc = NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -172,14 +169,14 @@ bz2DecompressNew(void)
|
|||||||
bz2Error(driver->result = BZ2_bzDecompressInit(&driver->stream, 0, 0));
|
bz2Error(driver->result = BZ2_bzDecompressInit(&driver->stream, 0, 0));
|
||||||
|
|
||||||
// Set free callback to ensure bz2 context is freed
|
// Set free callback to ensure bz2 context is freed
|
||||||
memContextCallbackSet(driver->memContext, bz2DecompressFreeResource, driver);
|
memContextCallbackSet(objMemContext(driver), bz2DecompressFreeResource, driver);
|
||||||
|
|
||||||
// Create filter interface
|
// Create filter interface
|
||||||
this = ioFilterNewP(
|
this = ioFilterNewP(
|
||||||
BZ2_DECOMPRESS_FILTER_TYPE_STR, driver, NULL, .done = bz2DecompressDone, .inOut = bz2DecompressProcess,
|
BZ2_DECOMPRESS_FILTER_TYPE_STR, driver, NULL, .done = bz2DecompressDone, .inOut = bz2DecompressProcess,
|
||||||
.inputSame = bz2DecompressInputSame);
|
.inputSame = bz2DecompressInputSame);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ Gz Compress
|
|||||||
#include "common/io/filter/filter.h"
|
#include "common/io/filter/filter.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/macro.h"
|
#include "common/macro.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -25,7 +24,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct GzCompress
|
typedef struct GzCompress
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Context to store data
|
|
||||||
z_stream stream; // Compression stream state
|
z_stream stream; // Compression stream state
|
||||||
|
|
||||||
bool inputSame; // Is the same input required on the next process call?
|
bool inputSame; // Is the same input required on the next process call?
|
||||||
@ -178,13 +176,12 @@ gzCompressNew(int level)
|
|||||||
|
|
||||||
IoFilter *this = NULL;
|
IoFilter *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("GzCompress")
|
OBJ_NEW_BEGIN(GzCompress)
|
||||||
{
|
{
|
||||||
GzCompress *driver = memNew(sizeof(GzCompress));
|
GzCompress *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (GzCompress)
|
*driver = (GzCompress)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.stream = {.zalloc = NULL},
|
.stream = {.zalloc = NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -192,7 +189,7 @@ gzCompressNew(int level)
|
|||||||
gzError(deflateInit2(&driver->stream, level, Z_DEFLATED, WANT_GZ | WINDOW_BITS, MEM_LEVEL, Z_DEFAULT_STRATEGY));
|
gzError(deflateInit2(&driver->stream, level, Z_DEFLATED, WANT_GZ | WINDOW_BITS, MEM_LEVEL, Z_DEFAULT_STRATEGY));
|
||||||
|
|
||||||
// Set free callback to ensure gz context is freed
|
// Set free callback to ensure gz context is freed
|
||||||
memContextCallbackSet(driver->memContext, gzCompressFreeResource, driver);
|
memContextCallbackSet(objMemContext(driver), gzCompressFreeResource, driver);
|
||||||
|
|
||||||
// Create param list
|
// Create param list
|
||||||
VariantList *paramList = varLstNew();
|
VariantList *paramList = varLstNew();
|
||||||
@ -203,7 +200,7 @@ gzCompressNew(int level)
|
|||||||
GZ_COMPRESS_FILTER_TYPE_STR, driver, paramList, .done = gzCompressDone, .inOut = gzCompressProcess,
|
GZ_COMPRESS_FILTER_TYPE_STR, driver, paramList, .done = gzCompressDone, .inOut = gzCompressProcess,
|
||||||
.inputSame = gzCompressInputSame);
|
.inputSame = gzCompressInputSame);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ Gz Decompress
|
|||||||
#include "common/io/filter/filter.h"
|
#include "common/io/filter/filter.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/macro.h"
|
#include "common/macro.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -25,7 +24,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct GzDecompress
|
typedef struct GzDecompress
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Context to store data
|
|
||||||
z_stream stream; // Decompression stream state
|
z_stream stream; // Decompression stream state
|
||||||
|
|
||||||
int result; // Result of last operation
|
int result; // Result of last operation
|
||||||
@ -157,14 +155,13 @@ gzDecompressNew(void)
|
|||||||
|
|
||||||
IoFilter *this = NULL;
|
IoFilter *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("GzDecompress")
|
OBJ_NEW_BEGIN(GzDecompress)
|
||||||
{
|
{
|
||||||
// Allocate state and set context
|
// Allocate state and set context
|
||||||
GzDecompress *driver = memNew(sizeof(GzDecompress));
|
GzDecompress *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (GzDecompress)
|
*driver = (GzDecompress)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.stream = {.zalloc = NULL},
|
.stream = {.zalloc = NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -172,14 +169,14 @@ gzDecompressNew(void)
|
|||||||
gzError(driver->result = inflateInit2(&driver->stream, WANT_GZ | WINDOW_BITS));
|
gzError(driver->result = inflateInit2(&driver->stream, WANT_GZ | WINDOW_BITS));
|
||||||
|
|
||||||
// Set free callback to ensure gz context is freed
|
// Set free callback to ensure gz context is freed
|
||||||
memContextCallbackSet(driver->memContext, gzDecompressFreeResource, driver);
|
memContextCallbackSet(objMemContext(driver), gzDecompressFreeResource, driver);
|
||||||
|
|
||||||
// Create filter interface
|
// Create filter interface
|
||||||
this = ioFilterNewP(
|
this = ioFilterNewP(
|
||||||
GZ_DECOMPRESS_FILTER_TYPE_STR, driver, NULL, .done = gzDecompressDone, .inOut = gzDecompressProcess,
|
GZ_DECOMPRESS_FILTER_TYPE_STR, driver, NULL, .done = gzDecompressDone, .inOut = gzDecompressProcess,
|
||||||
.inputSame = gzDecompressInputSame);
|
.inputSame = gzDecompressInputSame);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@ Developed against version r131 using the documentation in https://github.com/lz4
|
|||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/io/filter/filter.h"
|
#include "common/io/filter/filter.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -36,7 +35,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct Lz4Compress
|
typedef struct Lz4Compress
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Context to store data
|
|
||||||
LZ4F_compressionContext_t context; // LZ4 compression context
|
LZ4F_compressionContext_t context; // LZ4 compression context
|
||||||
LZ4F_preferences_t prefs; // Preferences -- just compress level set
|
LZ4F_preferences_t prefs; // Preferences -- just compress level set
|
||||||
IoFilter *filter; // Filter interface
|
IoFilter *filter; // Filter interface
|
||||||
@ -259,13 +257,12 @@ lz4CompressNew(int level)
|
|||||||
|
|
||||||
IoFilter *this = NULL;
|
IoFilter *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("Lz4Compress")
|
OBJ_NEW_BEGIN(Lz4Compress)
|
||||||
{
|
{
|
||||||
Lz4Compress *driver = memNew(sizeof(Lz4Compress));
|
Lz4Compress *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (Lz4Compress)
|
*driver = (Lz4Compress)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.prefs = {.compressionLevel = level, .frameInfo = {.contentChecksumFlag = LZ4F_contentChecksumEnabled}},
|
.prefs = {.compressionLevel = level, .frameInfo = {.contentChecksumFlag = LZ4F_contentChecksumEnabled}},
|
||||||
.first = true,
|
.first = true,
|
||||||
.buffer = bufNew(0),
|
.buffer = bufNew(0),
|
||||||
@ -275,7 +272,7 @@ lz4CompressNew(int level)
|
|||||||
lz4Error(LZ4F_createCompressionContext(&driver->context, LZ4F_VERSION));
|
lz4Error(LZ4F_createCompressionContext(&driver->context, LZ4F_VERSION));
|
||||||
|
|
||||||
// Set callback to ensure lz4 context is freed
|
// Set callback to ensure lz4 context is freed
|
||||||
memContextCallbackSet(driver->memContext, lz4CompressFreeResource, driver);
|
memContextCallbackSet(objMemContext(driver), lz4CompressFreeResource, driver);
|
||||||
|
|
||||||
// Create param list
|
// Create param list
|
||||||
VariantList *paramList = varLstNew();
|
VariantList *paramList = varLstNew();
|
||||||
@ -286,7 +283,7 @@ lz4CompressNew(int level)
|
|||||||
LZ4_COMPRESS_FILTER_TYPE_STR, driver, paramList, .done = lz4CompressDone, .inOut = lz4CompressProcess,
|
LZ4_COMPRESS_FILTER_TYPE_STR, driver, paramList, .done = lz4CompressDone, .inOut = lz4CompressProcess,
|
||||||
.inputSame = lz4CompressInputSame);
|
.inputSame = lz4CompressInputSame);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ LZ4 Decompress
|
|||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/io/filter/filter.h"
|
#include "common/io/filter/filter.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -26,7 +25,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct Lz4Decompress
|
typedef struct Lz4Decompress
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Context to store data
|
|
||||||
LZ4F_decompressionContext_t context; // LZ4 decompression context
|
LZ4F_decompressionContext_t context; // LZ4 decompression context
|
||||||
IoFilter *filter; // Filter interface
|
IoFilter *filter; // Filter interface
|
||||||
|
|
||||||
@ -170,27 +168,23 @@ lz4DecompressNew(void)
|
|||||||
|
|
||||||
IoFilter *this = NULL;
|
IoFilter *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("Lz4Decompress")
|
OBJ_NEW_BEGIN(Lz4Decompress)
|
||||||
{
|
{
|
||||||
Lz4Decompress *driver = memNew(sizeof(Lz4Decompress));
|
Lz4Decompress *driver = OBJ_NEW_ALLOC();
|
||||||
|
*driver = (Lz4Decompress){0};
|
||||||
*driver = (Lz4Decompress)
|
|
||||||
{
|
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Create lz4 context
|
// Create lz4 context
|
||||||
lz4Error(LZ4F_createDecompressionContext(&driver->context, LZ4F_VERSION));
|
lz4Error(LZ4F_createDecompressionContext(&driver->context, LZ4F_VERSION));
|
||||||
|
|
||||||
// Set callback to ensure lz4 context is freed
|
// Set callback to ensure lz4 context is freed
|
||||||
memContextCallbackSet(driver->memContext, lz4DecompressFreeResource, driver);
|
memContextCallbackSet(objMemContext(driver), lz4DecompressFreeResource, driver);
|
||||||
|
|
||||||
// Create filter interface
|
// Create filter interface
|
||||||
this = ioFilterNewP(
|
this = ioFilterNewP(
|
||||||
LZ4_DECOMPRESS_FILTER_TYPE_STR, driver, NULL, .done = lz4DecompressDone, .inOut = lz4DecompressProcess,
|
LZ4_DECOMPRESS_FILTER_TYPE_STR, driver, NULL, .done = lz4DecompressDone, .inOut = lz4DecompressProcess,
|
||||||
.inputSame = lz4DecompressInputSame);
|
.inputSame = lz4DecompressInputSame);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ ZST Compress
|
|||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/io/filter/filter.h"
|
#include "common/io/filter/filter.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -25,7 +24,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct ZstCompress
|
typedef struct ZstCompress
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Context to store data
|
|
||||||
ZSTD_CStream *context; // Compression context
|
ZSTD_CStream *context; // Compression context
|
||||||
int level; // Compression level
|
int level; // Compression level
|
||||||
IoFilter *filter; // Filter interface
|
IoFilter *filter; // Filter interface
|
||||||
@ -180,19 +178,18 @@ zstCompressNew(int level)
|
|||||||
|
|
||||||
IoFilter *this = NULL;
|
IoFilter *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("ZstCompress")
|
OBJ_NEW_BEGIN(ZstCompress)
|
||||||
{
|
{
|
||||||
ZstCompress *driver = memNew(sizeof(ZstCompress));
|
ZstCompress *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (ZstCompress)
|
*driver = (ZstCompress)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.context = ZSTD_createCStream(),
|
.context = ZSTD_createCStream(),
|
||||||
.level = level,
|
.level = level,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Set callback to ensure zst context is freed
|
// Set callback to ensure zst context is freed
|
||||||
memContextCallbackSet(driver->memContext, zstCompressFreeResource, driver);
|
memContextCallbackSet(objMemContext(driver), zstCompressFreeResource, driver);
|
||||||
|
|
||||||
// Initialize context
|
// Initialize context
|
||||||
zstError(ZSTD_initCStream(driver->context, driver->level));
|
zstError(ZSTD_initCStream(driver->context, driver->level));
|
||||||
@ -206,7 +203,7 @@ zstCompressNew(int level)
|
|||||||
ZST_COMPRESS_FILTER_TYPE_STR, driver, paramList, .done = zstCompressDone, .inOut = zstCompressProcess,
|
ZST_COMPRESS_FILTER_TYPE_STR, driver, paramList, .done = zstCompressDone, .inOut = zstCompressProcess,
|
||||||
.inputSame = zstCompressInputSame);
|
.inputSame = zstCompressInputSame);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ ZST Decompress
|
|||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/io/filter/filter.h"
|
#include "common/io/filter/filter.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -25,7 +24,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct ZstDecompress
|
typedef struct ZstDecompress
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Context to store data
|
|
||||||
ZSTD_DStream *context; // Decompression context
|
ZSTD_DStream *context; // Decompression context
|
||||||
IoFilter *filter; // Filter interface
|
IoFilter *filter; // Filter interface
|
||||||
|
|
||||||
@ -169,18 +167,17 @@ zstDecompressNew(void)
|
|||||||
|
|
||||||
IoFilter *this = NULL;
|
IoFilter *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("ZstDecompress")
|
OBJ_NEW_BEGIN(ZstDecompress)
|
||||||
{
|
{
|
||||||
ZstDecompress *driver = memNew(sizeof(ZstDecompress));
|
ZstDecompress *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (ZstDecompress)
|
*driver = (ZstDecompress)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.context = ZSTD_createDStream(),
|
.context = ZSTD_createDStream(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Set callback to ensure zst context is freed
|
// Set callback to ensure zst context is freed
|
||||||
memContextCallbackSet(driver->memContext, zstDecompressFreeResource, driver);
|
memContextCallbackSet(objMemContext(driver), zstDecompressFreeResource, driver);
|
||||||
|
|
||||||
// Initialize context
|
// Initialize context
|
||||||
zstError(ZSTD_initDStream(driver->context));
|
zstError(ZSTD_initDStream(driver->context));
|
||||||
@ -190,7 +187,7 @@ zstDecompressNew(void)
|
|||||||
ZST_DECOMPRESS_FILTER_TYPE_STR, driver, NULL, .done = zstDecompressDone, .inOut = zstDecompressProcess,
|
ZST_DECOMPRESS_FILTER_TYPE_STR, driver, NULL, .done = zstDecompressDone, .inOut = zstDecompressProcess,
|
||||||
.inputSame = zstDecompressInputSame);
|
.inputSame = zstDecompressInputSame);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ Block Cipher
|
|||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/io/filter/filter.h"
|
#include "common/io/filter/filter.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -37,7 +36,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct CipherBlock
|
typedef struct CipherBlock
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Context to store data
|
|
||||||
CipherMode mode; // Mode encrypt/decrypt
|
CipherMode mode; // Mode encrypt/decrypt
|
||||||
bool saltDone; // Has the salt been read/generated?
|
bool saltDone; // Has the salt been read/generated?
|
||||||
bool processDone; // Has any data been processed?
|
bool processDone; // Has any data been processed?
|
||||||
@ -194,7 +192,7 @@ cipherBlockProcessBlock(CipherBlock *this, const unsigned char *source, size_t s
|
|||||||
cryptoError(!(this->cipherContext = EVP_CIPHER_CTX_new()), "unable to create context");
|
cryptoError(!(this->cipherContext = EVP_CIPHER_CTX_new()), "unable to create context");
|
||||||
|
|
||||||
// Set free callback to ensure cipher context is freed
|
// Set free callback to ensure cipher context is freed
|
||||||
memContextCallbackSet(this->memContext, cipherBlockFreeResource, this);
|
memContextCallbackSet(objMemContext(this), cipherBlockFreeResource, this);
|
||||||
|
|
||||||
// Initialize cipher
|
// Initialize cipher
|
||||||
cryptoError(
|
cryptoError(
|
||||||
@ -306,7 +304,7 @@ cipherBlockProcess(THIS_VOID, const Buffer *source, Buffer *destination)
|
|||||||
if (destinationSize > bufRemains(destination))
|
if (destinationSize > bufRemains(destination))
|
||||||
{
|
{
|
||||||
// Allocate the buffer if needed
|
// Allocate the buffer if needed
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(objMemContext(this))
|
||||||
{
|
{
|
||||||
if (this->buffer == NULL)
|
if (this->buffer == NULL)
|
||||||
{
|
{
|
||||||
@ -425,13 +423,12 @@ cipherBlockNew(CipherMode mode, CipherType cipherType, const Buffer *pass, const
|
|||||||
// Allocate memory to hold process state
|
// Allocate memory to hold process state
|
||||||
IoFilter *this = NULL;
|
IoFilter *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("CipherBlock")
|
OBJ_NEW_BEGIN(CipherBlock)
|
||||||
{
|
{
|
||||||
CipherBlock *driver = memNew(sizeof(CipherBlock));
|
CipherBlock *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (CipherBlock)
|
*driver = (CipherBlock)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.mode = mode,
|
.mode = mode,
|
||||||
.cipher = cipher,
|
.cipher = cipher,
|
||||||
.digest = digest,
|
.digest = digest,
|
||||||
@ -456,7 +453,7 @@ cipherBlockNew(CipherMode mode, CipherType cipherType, const Buffer *pass, const
|
|||||||
CIPHER_BLOCK_FILTER_TYPE_STR, driver, paramList, .done = cipherBlockDone, .inOut = cipherBlockProcess,
|
CIPHER_BLOCK_FILTER_TYPE_STR, driver, paramList, .done = cipherBlockDone, .inOut = cipherBlockProcess,
|
||||||
.inputSame = cipherBlockInputSame);
|
.inputSame = cipherBlockInputSame);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ Cryptographic Hash
|
|||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/io/filter/filter.h"
|
#include "common/io/filter/filter.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
#include "common/crypto/common.h"
|
#include "common/crypto/common.h"
|
||||||
|
|
||||||
@ -45,7 +44,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct CryptoHash
|
typedef struct CryptoHash
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Context to store data
|
|
||||||
const EVP_MD *hashType; // Hash type (sha1, md5, etc.)
|
const EVP_MD *hashType; // Hash type (sha1, md5, etc.)
|
||||||
EVP_MD_CTX *hashContext; // Message hash context
|
EVP_MD_CTX *hashContext; // Message hash context
|
||||||
MD5_CTX *md5Context; // MD5 context (used to bypass FIPS restrictions)
|
MD5_CTX *md5Context; // MD5 context (used to bypass FIPS restrictions)
|
||||||
@ -122,7 +120,7 @@ cryptoHash(CryptoHash *this)
|
|||||||
|
|
||||||
if (this->hash == NULL)
|
if (this->hash == NULL)
|
||||||
{
|
{
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(objMemContext(this))
|
||||||
{
|
{
|
||||||
// Standard OpenSSL implementation
|
// Standard OpenSSL implementation
|
||||||
if (this->hashContext != NULL)
|
if (this->hashContext != NULL)
|
||||||
@ -178,14 +176,10 @@ cryptoHashNew(const String *type)
|
|||||||
// Allocate memory to hold process state
|
// Allocate memory to hold process state
|
||||||
IoFilter *this = NULL;
|
IoFilter *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("CryptoHash")
|
OBJ_NEW_BEGIN(CryptoHash)
|
||||||
{
|
{
|
||||||
CryptoHash *driver = memNew(sizeof(CryptoHash));
|
CryptoHash *driver = OBJ_NEW_ALLOC();
|
||||||
|
*driver = (CryptoHash){0};
|
||||||
*driver = (CryptoHash)
|
|
||||||
{
|
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Use local MD5 implementation since FIPS-enabled systems do not allow MD5. This is a bit misguided since there are valid
|
// Use local MD5 implementation since FIPS-enabled systems do not allow MD5. This is a bit misguided since there are valid
|
||||||
// cases for using MD5 which do not involve, for example, password hashes. Since popular object stores, e.g. S3, require
|
// cases for using MD5 which do not involve, for example, password hashes. Since popular object stores, e.g. S3, require
|
||||||
@ -207,7 +201,7 @@ cryptoHashNew(const String *type)
|
|||||||
cryptoError((driver->hashContext = EVP_MD_CTX_create()) == NULL, "unable to create hash context");
|
cryptoError((driver->hashContext = EVP_MD_CTX_create()) == NULL, "unable to create hash context");
|
||||||
|
|
||||||
// Set free callback to ensure hash context is freed
|
// Set free callback to ensure hash context is freed
|
||||||
memContextCallbackSet(driver->memContext, cryptoHashFreeResource, driver);
|
memContextCallbackSet(objMemContext(driver), cryptoHashFreeResource, driver);
|
||||||
|
|
||||||
// Initialize context
|
// Initialize context
|
||||||
cryptoError(!EVP_DigestInit_ex(driver->hashContext, driver->hashType, NULL), "unable to initialize hash context");
|
cryptoError(!EVP_DigestInit_ex(driver->hashContext, driver->hashType, NULL), "unable to initialize hash context");
|
||||||
@ -220,7 +214,7 @@ cryptoHashNew(const String *type)
|
|||||||
// Create filter interface
|
// Create filter interface
|
||||||
this = ioFilterNewP(CRYPTO_HASH_FILTER_TYPE_STR, driver, paramList, .in = cryptoHashProcess, .result = cryptoHashResult);
|
this = ioFilterNewP(CRYPTO_HASH_FILTER_TYPE_STR, driver, paramList, .in = cryptoHashProcess, .result = cryptoHashResult);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
||||||
}
|
}
|
||||||
|
@ -127,16 +127,12 @@ execNew(const String *command, const StringList *param, const String *name, Time
|
|||||||
|
|
||||||
Exec *this = NULL;
|
Exec *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("Exec")
|
OBJ_NEW_BEGIN(Exec)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(Exec));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (Exec)
|
*this = (Exec)
|
||||||
{
|
{
|
||||||
.pub =
|
|
||||||
{
|
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
},
|
|
||||||
.command = strDup(command),
|
.command = strDup(command),
|
||||||
.name = strDup(name),
|
.name = strDup(name),
|
||||||
.timeout = timeout,
|
.timeout = timeout,
|
||||||
@ -148,7 +144,7 @@ execNew(const String *command, const StringList *param, const String *name, Time
|
|||||||
// The first parameter must be the command
|
// The first parameter must be the command
|
||||||
strLstInsert(this->param, 0, this->command);
|
strLstInsert(this->param, 0, this->command);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(EXEC, this);
|
FUNCTION_LOG_RETURN(EXEC, this);
|
||||||
}
|
}
|
||||||
@ -369,7 +365,7 @@ execOpen(Exec *this)
|
|||||||
ioWriteOpen(execIoWrite(this));
|
ioWriteOpen(execIoWrite(this));
|
||||||
|
|
||||||
// Set a callback so the file descriptors will get freed
|
// Set a callback so the file descriptors will get freed
|
||||||
memContextCallbackSet(execMemContext(this), execFreeResource, this);
|
memContextCallbackSet(objMemContext(this), execFreeResource, this);
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN_VOID();
|
FUNCTION_LOG_RETURN_VOID();
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@ Getters/Setters
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct ExecPub
|
typedef struct ExecPub
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
IoRead *ioReadExec; // Wrapper for file descriptor read interface
|
IoRead *ioReadExec; // Wrapper for file descriptor read interface
|
||||||
IoWrite *ioWriteExec; // Wrapper for file descriptor write interface
|
IoWrite *ioWriteExec; // Wrapper for file descriptor write interface
|
||||||
} ExecPub;
|
} ExecPub;
|
||||||
@ -52,7 +51,7 @@ execIoWrite(Exec *const this)
|
|||||||
__attribute__((always_inline)) static inline MemContext *
|
__attribute__((always_inline)) static inline MemContext *
|
||||||
execMemContext(Exec *const this)
|
execMemContext(Exec *const this)
|
||||||
{
|
{
|
||||||
return THIS_PUB(Exec)->memContext;
|
return objMemContext(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
|
@ -8,7 +8,6 @@ Ini Handler
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/ini.h"
|
#include "common/ini.h"
|
||||||
#include "common/type/json.h"
|
#include "common/type/json.h"
|
||||||
@ -19,7 +18,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
struct Ini
|
struct Ini
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Context that contains the ini
|
|
||||||
KeyValue *store; // Key value store that contains the ini data
|
KeyValue *store; // Key value store that contains the ini data
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -31,17 +29,16 @@ iniNew(void)
|
|||||||
|
|
||||||
Ini *this = NULL;
|
Ini *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("Ini")
|
OBJ_NEW_BEGIN(Ini)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(Ini));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (Ini)
|
*this = (Ini)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.store = kvNew(),
|
.store = kvNew(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(this);
|
FUNCTION_TEST_RETURN(this);
|
||||||
}
|
}
|
||||||
@ -228,7 +225,7 @@ iniParse(Ini *this, const String *content)
|
|||||||
|
|
||||||
ASSERT(this != NULL);
|
ASSERT(this != NULL);
|
||||||
|
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(objMemContext(this))
|
||||||
{
|
{
|
||||||
kvFree(this->store);
|
kvFree(this->store);
|
||||||
this->store = kvNew();
|
this->store = kvNew();
|
||||||
|
@ -7,7 +7,6 @@ Buffer IO Read
|
|||||||
#include "common/io/bufferRead.h"
|
#include "common/io/bufferRead.h"
|
||||||
#include "common/io/read.h"
|
#include "common/io/read.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -15,7 +14,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct IoBufferRead
|
typedef struct IoBufferRead
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Object memory context
|
|
||||||
const Buffer *read; // Buffer to read data from
|
const Buffer *read; // Buffer to read data from
|
||||||
|
|
||||||
size_t readPos; // Current position in the read buffer
|
size_t readPos; // Current position in the read buffer
|
||||||
@ -96,19 +94,18 @@ ioBufferReadNew(const Buffer *buffer)
|
|||||||
|
|
||||||
IoRead *this = NULL;
|
IoRead *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("IoBufferRead")
|
OBJ_NEW_BEGIN(IoBufferRead)
|
||||||
{
|
{
|
||||||
IoBufferRead *driver = memNew(sizeof(IoBufferRead));
|
IoBufferRead *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (IoBufferRead)
|
*driver = (IoBufferRead)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.read = buffer,
|
.read = buffer,
|
||||||
};
|
};
|
||||||
|
|
||||||
this = ioReadNewP(driver, .eof = ioBufferReadEof, .read = ioBufferRead);
|
this = ioReadNewP(driver, .eof = ioBufferReadEof, .read = ioBufferRead);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_READ, this);
|
FUNCTION_LOG_RETURN(IO_READ, this);
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ Buffer IO Write
|
|||||||
#include "common/io/bufferWrite.h"
|
#include "common/io/bufferWrite.h"
|
||||||
#include "common/io/write.h"
|
#include "common/io/write.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -15,7 +14,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct IoBufferWrite
|
typedef struct IoBufferWrite
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Object memory context
|
|
||||||
Buffer *write; // Buffer to write into
|
Buffer *write; // Buffer to write into
|
||||||
} IoBufferWrite;
|
} IoBufferWrite;
|
||||||
|
|
||||||
@ -60,19 +58,18 @@ ioBufferWriteNew(Buffer *buffer)
|
|||||||
|
|
||||||
IoWrite *this = NULL;
|
IoWrite *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("IoBufferWrite")
|
OBJ_NEW_BEGIN(IoBufferWrite)
|
||||||
{
|
{
|
||||||
IoBufferWrite *driver = memNew(sizeof(IoBufferWrite));
|
IoBufferWrite *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (IoBufferWrite)
|
*driver = (IoBufferWrite)
|
||||||
{
|
{
|
||||||
.memContext = memContextCurrent(),
|
|
||||||
.write = buffer,
|
.write = buffer,
|
||||||
};
|
};
|
||||||
|
|
||||||
this = ioWriteNewP(driver, .write = ioBufferWrite);
|
this = ioWriteNewP(driver, .write = ioBufferWrite);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_WRITE, this);
|
FUNCTION_LOG_RETURN(IO_WRITE, this);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ Io Client Interface
|
|||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/io/client.h"
|
#include "common/io/client.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Object type
|
Object type
|
||||||
|
@ -40,7 +40,7 @@ Functions
|
|||||||
__attribute__((always_inline)) static inline IoClient *
|
__attribute__((always_inline)) static inline IoClient *
|
||||||
ioClientMove(IoClient *const this, MemContext *const parentNew)
|
ioClientMove(IoClient *const this, MemContext *const parentNew)
|
||||||
{
|
{
|
||||||
return objMove(this, parentNew);
|
return objMoveContext(this, parentNew);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open session
|
// Open session
|
||||||
@ -56,7 +56,7 @@ Destructor
|
|||||||
__attribute__((always_inline)) static inline void
|
__attribute__((always_inline)) static inline void
|
||||||
ioClientFree(IoClient *const this)
|
ioClientFree(IoClient *const this)
|
||||||
{
|
{
|
||||||
objFree(this);
|
objFreeContext(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
|
@ -10,7 +10,6 @@ File Descriptor Io Read
|
|||||||
#include "common/io/fdRead.h"
|
#include "common/io/fdRead.h"
|
||||||
#include "common/io/read.h"
|
#include "common/io/read.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -18,7 +17,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct IoFdRead
|
typedef struct IoFdRead
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Object memory context
|
|
||||||
const String *name; // File descriptor name for error messages
|
const String *name; // File descriptor name for error messages
|
||||||
int fd; // File descriptor to read data from
|
int fd; // File descriptor to read data from
|
||||||
TimeMSec timeout; // Timeout for read operation
|
TimeMSec timeout; // Timeout for read operation
|
||||||
@ -158,13 +156,12 @@ ioFdReadNew(const String *name, int fd, TimeMSec timeout)
|
|||||||
|
|
||||||
IoRead *this = NULL;
|
IoRead *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("IoFdRead")
|
OBJ_NEW_BEGIN(IoFdRead)
|
||||||
{
|
{
|
||||||
IoFdRead *driver = memNew(sizeof(IoFdRead));
|
IoFdRead *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (IoFdRead)
|
*driver = (IoFdRead)
|
||||||
{
|
{
|
||||||
.memContext = memContextCurrent(),
|
|
||||||
.name = strDup(name),
|
.name = strDup(name),
|
||||||
.fd = fd,
|
.fd = fd,
|
||||||
.timeout = timeout,
|
.timeout = timeout,
|
||||||
@ -172,7 +169,7 @@ ioFdReadNew(const String *name, int fd, TimeMSec timeout)
|
|||||||
|
|
||||||
this = ioReadNewP(driver, .block = true, .eof = ioFdReadEof, .fd = ioFdReadFd, .read = ioFdRead, .ready = ioFdReadReady);
|
this = ioReadNewP(driver, .block = true, .eof = ioFdReadEof, .fd = ioFdReadFd, .read = ioFdRead, .ready = ioFdReadReady);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_READ, this);
|
FUNCTION_LOG_RETURN(IO_READ, this);
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ File Descriptor Io Write
|
|||||||
#include "common/io/fdWrite.h"
|
#include "common/io/fdWrite.h"
|
||||||
#include "common/io/write.h"
|
#include "common/io/write.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -18,7 +17,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct IoFdWrite
|
typedef struct IoFdWrite
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Object memory context
|
|
||||||
const String *name; // File descriptor name for error messages
|
const String *name; // File descriptor name for error messages
|
||||||
int fd; // File descriptor to write to
|
int fd; // File descriptor to write to
|
||||||
TimeMSec timeout; // Timeout for write operation
|
TimeMSec timeout; // Timeout for write operation
|
||||||
@ -114,13 +112,12 @@ ioFdWriteNew(const String *name, int fd, TimeMSec timeout)
|
|||||||
|
|
||||||
IoWrite *this = NULL;
|
IoWrite *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("IoFdWrite")
|
OBJ_NEW_BEGIN(IoFdWrite)
|
||||||
{
|
{
|
||||||
IoFdWrite *driver = memNew(sizeof(IoFdWrite));
|
IoFdWrite *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (IoFdWrite)
|
*driver = (IoFdWrite)
|
||||||
{
|
{
|
||||||
.memContext = memContextCurrent(),
|
|
||||||
.name = strDup(name),
|
.name = strDup(name),
|
||||||
.fd = fd,
|
.fd = fd,
|
||||||
.timeout = timeout,
|
.timeout = timeout,
|
||||||
@ -128,7 +125,7 @@ ioFdWriteNew(const String *name, int fd, TimeMSec timeout)
|
|||||||
|
|
||||||
this = ioWriteNewP(driver, .fd = ioFdWriteFd, .ready = ioFdWriteReady, .write = ioFdWrite);
|
this = ioWriteNewP(driver, .fd = ioFdWriteFd, .ready = ioFdWriteReady, .write = ioFdWrite);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_WRITE, this);
|
FUNCTION_LOG_RETURN(IO_WRITE, this);
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ IO Buffer Filter
|
|||||||
#include "common/io/filter/buffer.h"
|
#include "common/io/filter/buffer.h"
|
||||||
#include "common/io/filter/filter.h"
|
#include "common/io/filter/filter.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -23,8 +22,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct IoBuffer
|
typedef struct IoBuffer
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context of filter
|
|
||||||
|
|
||||||
size_t inputPos; // Position in input buffer
|
size_t inputPos; // Position in input buffer
|
||||||
bool inputSame; // Is the same input required again?
|
bool inputSame; // Is the same input required again?
|
||||||
} IoBuffer;
|
} IoBuffer;
|
||||||
@ -114,18 +111,14 @@ ioBufferNew(void)
|
|||||||
|
|
||||||
IoFilter *this = NULL;
|
IoFilter *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("IoBuffer")
|
OBJ_NEW_BEGIN(IoBuffer)
|
||||||
{
|
{
|
||||||
IoBuffer *driver = memNew(sizeof(IoBuffer));
|
IoBuffer *driver = OBJ_NEW_ALLOC();
|
||||||
|
*driver = (IoBuffer){0};
|
||||||
*driver = (IoBuffer)
|
|
||||||
{
|
|
||||||
.memContext = memContextCurrent(),
|
|
||||||
};
|
|
||||||
|
|
||||||
this = ioFilterNewP(BUFFER_FILTER_TYPE_STR, driver, NULL, .inOut = ioBufferProcess, .inputSame = ioBufferInputSame);
|
this = ioFilterNewP(BUFFER_FILTER_TYPE_STR, driver, NULL, .inOut = ioBufferProcess, .inputSame = ioBufferInputSame);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ Destructor
|
|||||||
__attribute__((always_inline)) static inline void
|
__attribute__((always_inline)) static inline void
|
||||||
ioFilterFree(IoFilter *const this)
|
ioFilterFree(IoFilter *const this)
|
||||||
{
|
{
|
||||||
objFree(this);
|
objFreeContext(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
|
@ -113,7 +113,7 @@ void ioFilterProcessInOut(IoFilter *this, const Buffer *input, Buffer *output);
|
|||||||
__attribute__((always_inline)) static inline IoFilter *
|
__attribute__((always_inline)) static inline IoFilter *
|
||||||
ioFilterMove(IoFilter *this, MemContext *parentNew)
|
ioFilterMove(IoFilter *this, MemContext *parentNew)
|
||||||
{
|
{
|
||||||
return objMove(this, parentNew);
|
return objMoveContext(this, parentNew);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
|
@ -11,7 +11,6 @@ IO Filter Group
|
|||||||
#include "common/io/filter/group.h"
|
#include "common/io/filter/group.h"
|
||||||
#include "common/io/io.h"
|
#include "common/io/io.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/list.h"
|
#include "common/type/list.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -55,21 +54,20 @@ ioFilterGroupNew(void)
|
|||||||
|
|
||||||
IoFilterGroup *this = NULL;
|
IoFilterGroup *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("IoFilterGroup")
|
OBJ_NEW_BEGIN(IoFilterGroup)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(IoFilterGroup));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (IoFilterGroup)
|
*this = (IoFilterGroup)
|
||||||
{
|
{
|
||||||
.pub =
|
.pub =
|
||||||
{
|
{
|
||||||
.memContext = memContextCurrent(),
|
|
||||||
.done = false,
|
.done = false,
|
||||||
.filterList = lstNewP(sizeof(IoFilterData)),
|
.filterList = lstNewP(sizeof(IoFilterData)),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_FILTER_GROUP, this);
|
FUNCTION_LOG_RETURN(IO_FILTER_GROUP, this);
|
||||||
}
|
}
|
||||||
@ -88,7 +86,7 @@ ioFilterGroupAdd(IoFilterGroup *this, IoFilter *filter)
|
|||||||
ASSERT(filter != NULL);
|
ASSERT(filter != NULL);
|
||||||
|
|
||||||
// Move the filter to this object's mem context
|
// Move the filter to this object's mem context
|
||||||
ioFilterMove(filter, this->pub.memContext);
|
ioFilterMove(filter, objMemContext(this));
|
||||||
|
|
||||||
// Add the filter
|
// Add the filter
|
||||||
IoFilterData filterData = {.filter = filter};
|
IoFilterData filterData = {.filter = filter};
|
||||||
@ -111,7 +109,7 @@ ioFilterGroupInsert(IoFilterGroup *this, unsigned int listIdx, IoFilter *filter)
|
|||||||
ASSERT(filter != NULL);
|
ASSERT(filter != NULL);
|
||||||
|
|
||||||
// Move the filter to this object's mem context
|
// Move the filter to this object's mem context
|
||||||
ioFilterMove(filter, this->pub.memContext);
|
ioFilterMove(filter, objMemContext(this));
|
||||||
|
|
||||||
// Add the filter
|
// Add the filter
|
||||||
IoFilterData filterData = {.filter = filter};
|
IoFilterData filterData = {.filter = filter};
|
||||||
@ -167,7 +165,7 @@ ioFilterGroupOpen(IoFilterGroup *this)
|
|||||||
|
|
||||||
ASSERT(this != NULL);
|
ASSERT(this != NULL);
|
||||||
|
|
||||||
MEM_CONTEXT_BEGIN(this->pub.memContext)
|
MEM_CONTEXT_BEGIN(objMemContext(this))
|
||||||
{
|
{
|
||||||
// If the last filter is not an output filter then add a filter to buffer/copy data. Input filters won't copy to an output
|
// If the last filter is not an output filter then add a filter to buffer/copy data. Input filters won't copy to an output
|
||||||
// buffer so we need some way to get the data to the output buffer.
|
// buffer so we need some way to get the data to the output buffer.
|
||||||
@ -362,7 +360,7 @@ ioFilterGroupClose(IoFilterGroup *this)
|
|||||||
|
|
||||||
if (this->filterResult == NULL)
|
if (this->filterResult == NULL)
|
||||||
{
|
{
|
||||||
MEM_CONTEXT_BEGIN(this->pub.memContext)
|
MEM_CONTEXT_BEGIN(objMemContext(this))
|
||||||
{
|
{
|
||||||
this->filterResult = kvNew();
|
this->filterResult = kvNew();
|
||||||
}
|
}
|
||||||
@ -461,7 +459,7 @@ ioFilterGroupResultAllSet(IoFilterGroup *this, const Variant *filterResult)
|
|||||||
|
|
||||||
if (filterResult != NULL)
|
if (filterResult != NULL)
|
||||||
{
|
{
|
||||||
MEM_CONTEXT_BEGIN(this->pub.memContext)
|
MEM_CONTEXT_BEGIN(objMemContext(this))
|
||||||
{
|
{
|
||||||
this->filterResult = kvDup(varKv(filterResult));
|
this->filterResult = kvDup(varKv(filterResult));
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@ Getters/Setters
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct IoFilterGroupPub
|
typedef struct IoFilterGroupPub
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
List *filterList; // List of filters to apply
|
List *filterList; // List of filters to apply
|
||||||
bool inputSame; // Same input required again?
|
bool inputSame; // Same input required again?
|
||||||
bool done; // Is processing done?
|
bool done; // Is processing done?
|
||||||
|
@ -7,7 +7,6 @@ IO Sink Filter
|
|||||||
#include "common/io/filter/filter.h"
|
#include "common/io/filter/filter.h"
|
||||||
#include "common/io/filter/sink.h"
|
#include "common/io/filter/sink.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -20,7 +19,7 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct IoSink
|
typedef struct IoSink
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context of filter
|
bool dummy; // Struct requires one member
|
||||||
} IoSink;
|
} IoSink;
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -60,18 +59,12 @@ ioSinkNew(void)
|
|||||||
|
|
||||||
IoFilter *this = NULL;
|
IoFilter *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("IoSink")
|
OBJ_NEW_BEGIN(IoSink)
|
||||||
{
|
{
|
||||||
IoSink *driver = memNew(sizeof(IoSink));
|
IoSink *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (IoSink)
|
|
||||||
{
|
|
||||||
.memContext = memContextCurrent(),
|
|
||||||
};
|
|
||||||
|
|
||||||
this = ioFilterNewP(SINK_FILTER_TYPE_STR, driver, NULL, .inOut = ioSinkProcess);
|
this = ioFilterNewP(SINK_FILTER_TYPE_STR, driver, NULL, .inOut = ioSinkProcess);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ IO Size Filter
|
|||||||
#include "common/io/filter/filter.h"
|
#include "common/io/filter/filter.h"
|
||||||
#include "common/io/filter/size.h"
|
#include "common/io/filter/size.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -22,8 +21,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct IoSize
|
typedef struct IoSize
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context of filter
|
|
||||||
|
|
||||||
uint64_t size; // Total size of al input
|
uint64_t size; // Total size of al input
|
||||||
} IoSize;
|
} IoSize;
|
||||||
|
|
||||||
@ -87,18 +84,14 @@ ioSizeNew(void)
|
|||||||
|
|
||||||
IoFilter *this = NULL;
|
IoFilter *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("IoSize")
|
OBJ_NEW_BEGIN(IoSize)
|
||||||
{
|
{
|
||||||
IoSize *driver = memNew(sizeof(IoSize));
|
IoSize *driver = OBJ_NEW_ALLOC();
|
||||||
|
*driver = (IoSize){0};
|
||||||
*driver = (IoSize)
|
|
||||||
{
|
|
||||||
.memContext = memContextCurrent(),
|
|
||||||
};
|
|
||||||
|
|
||||||
this = ioFilterNewP(SIZE_FILTER_TYPE_STR, driver, NULL, .in = ioSizeProcess, .result = ioSizeResult);
|
this = ioFilterNewP(SIZE_FILTER_TYPE_STR, driver, NULL, .in = ioSizeProcess, .result = ioSizeResult);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
FUNCTION_LOG_RETURN(IO_FILTER, this);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ Object type
|
|||||||
struct HttpClient
|
struct HttpClient
|
||||||
{
|
{
|
||||||
HttpClientPub pub; // Publicly accessible variables
|
HttpClientPub pub; // Publicly accessible variables
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
IoClient *ioClient; // Io client (e.g. TLS or socket client)
|
IoClient *ioClient; // Io client (e.g. TLS or socket client)
|
||||||
|
|
||||||
List *sessionReuseList; // List of HTTP sessions that can be reused
|
List *sessionReuseList; // List of HTTP sessions that can be reused
|
||||||
@ -44,9 +43,9 @@ httpClientNew(IoClient *ioClient, TimeMSec timeout)
|
|||||||
|
|
||||||
HttpClient *this = NULL;
|
HttpClient *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("HttpClient")
|
OBJ_NEW_BEGIN(HttpClient)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(HttpClient));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (HttpClient)
|
*this = (HttpClient)
|
||||||
{
|
{
|
||||||
@ -54,14 +53,13 @@ httpClientNew(IoClient *ioClient, TimeMSec timeout)
|
|||||||
{
|
{
|
||||||
.timeout = timeout,
|
.timeout = timeout,
|
||||||
},
|
},
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.ioClient = ioClient,
|
.ioClient = ioClient,
|
||||||
.sessionReuseList = lstNewP(sizeof(HttpSession *)),
|
.sessionReuseList = lstNewP(sizeof(HttpSession *)),
|
||||||
};
|
};
|
||||||
|
|
||||||
statInc(HTTP_STAT_CLIENT_STR);
|
statInc(HTTP_STAT_CLIENT_STR);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(HTTP_CLIENT, this);
|
FUNCTION_LOG_RETURN(HTTP_CLIENT, this);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ HTTP Header
|
|||||||
|
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/io/http/header.h"
|
#include "common/io/http/header.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/keyValue.h"
|
#include "common/type/keyValue.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -13,7 +12,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
struct HttpHeader
|
struct HttpHeader
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
const StringList *redactList; // List of headers to redact during logging
|
const StringList *redactList; // List of headers to redact during logging
|
||||||
KeyValue *kv; // KeyValue store
|
KeyValue *kv; // KeyValue store
|
||||||
};
|
};
|
||||||
@ -26,19 +24,18 @@ httpHeaderNew(const StringList *redactList)
|
|||||||
|
|
||||||
HttpHeader *this = NULL;
|
HttpHeader *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("HttpHeader")
|
OBJ_NEW_BEGIN(HttpHeader)
|
||||||
{
|
{
|
||||||
// Allocate state and set context
|
// Allocate state and set context
|
||||||
this = memNew(sizeof(HttpHeader));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (HttpHeader)
|
*this = (HttpHeader)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.redactList = strLstDup(redactList),
|
.redactList = strLstDup(redactList),
|
||||||
.kv = kvNew(),
|
.kv = kvNew(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(this);
|
FUNCTION_TEST_RETURN(this);
|
||||||
}
|
}
|
||||||
@ -56,19 +53,18 @@ httpHeaderDup(const HttpHeader *header, const StringList *redactList)
|
|||||||
|
|
||||||
if (header != NULL)
|
if (header != NULL)
|
||||||
{
|
{
|
||||||
MEM_CONTEXT_NEW_BEGIN("HttpHeader")
|
OBJ_NEW_BEGIN(HttpHeader)
|
||||||
{
|
{
|
||||||
// Allocate state and set context
|
// Allocate state and set context
|
||||||
this = memNew(sizeof(HttpHeader));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (HttpHeader)
|
*this = (HttpHeader)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.redactList = redactList == NULL ? strLstDup(header->redactList) : strLstDup(redactList),
|
.redactList = redactList == NULL ? strLstDup(header->redactList) : strLstDup(redactList),
|
||||||
.kv = kvDup(header->kv),
|
.kv = kvDup(header->kv),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
}
|
}
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(this);
|
FUNCTION_TEST_RETURN(this);
|
||||||
|
@ -6,7 +6,6 @@ HTTP Query
|
|||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/io/http/common.h"
|
#include "common/io/http/common.h"
|
||||||
#include "common/io/http/query.h"
|
#include "common/io/http/query.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/keyValue.h"
|
#include "common/type/keyValue.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -14,7 +13,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
struct HttpQuery
|
struct HttpQuery
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
KeyValue *kv; // KeyValue store
|
KeyValue *kv; // KeyValue store
|
||||||
const StringList *redactList; // List of keys to redact values for
|
const StringList *redactList; // List of keys to redact values for
|
||||||
};
|
};
|
||||||
@ -29,19 +27,18 @@ httpQueryNew(HttpQueryNewParam param)
|
|||||||
|
|
||||||
HttpQuery *this = NULL;
|
HttpQuery *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("HttpQuery")
|
OBJ_NEW_BEGIN(HttpQuery)
|
||||||
{
|
{
|
||||||
// Allocate state and set context
|
// Allocate state and set context
|
||||||
this = memNew(sizeof(HttpQuery));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (HttpQuery)
|
*this = (HttpQuery)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.kv = kvNew(),
|
.kv = kvNew(),
|
||||||
.redactList = strLstDup(param.redactList),
|
.redactList = strLstDup(param.redactList),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(this);
|
FUNCTION_TEST_RETURN(this);
|
||||||
}
|
}
|
||||||
@ -58,13 +55,12 @@ httpQueryNewStr(const String *query)
|
|||||||
|
|
||||||
HttpQuery *this = NULL;
|
HttpQuery *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("HttpQuery")
|
OBJ_NEW_BEGIN(HttpQuery)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(HttpQuery));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (HttpQuery)
|
*this = (HttpQuery)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.kv = kvNew(),
|
.kv = kvNew(),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -94,7 +90,7 @@ httpQueryNewStr(const String *query)
|
|||||||
}
|
}
|
||||||
MEM_CONTEXT_TEMP_END();
|
MEM_CONTEXT_TEMP_END();
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(this);
|
FUNCTION_TEST_RETURN(this);
|
||||||
}
|
}
|
||||||
@ -112,19 +108,18 @@ httpQueryDup(const HttpQuery *query, HttpQueryDupParam param)
|
|||||||
|
|
||||||
if (query != NULL)
|
if (query != NULL)
|
||||||
{
|
{
|
||||||
MEM_CONTEXT_NEW_BEGIN("HttpQuery")
|
OBJ_NEW_BEGIN(HttpQuery)
|
||||||
{
|
{
|
||||||
// Allocate state and set context
|
// Allocate state and set context
|
||||||
this = memNew(sizeof(HttpQuery));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (HttpQuery)
|
*this = (HttpQuery)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.kv = kvDup(query->kv),
|
.kv = kvDup(query->kv),
|
||||||
.redactList = param.redactList != NULL ? strLstDup(param.redactList) : strLstDup(query->redactList),
|
.redactList = param.redactList != NULL ? strLstDup(param.redactList) : strLstDup(query->redactList),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
}
|
}
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(this);
|
FUNCTION_TEST_RETURN(this);
|
||||||
|
@ -126,7 +126,7 @@ httpRequestProcess(HttpRequest *this, bool waitForResponse, bool contentCache)
|
|||||||
|
|
||||||
// If not waiting for the response then move the session to the object context
|
// If not waiting for the response then move the session to the object context
|
||||||
if (!waitForResponse)
|
if (!waitForResponse)
|
||||||
this->session = httpSessionMove(session, this->pub.memContext);
|
this->session = httpSessionMove(session, objMemContext(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for response
|
// Wait for response
|
||||||
@ -189,15 +189,14 @@ httpRequestNew(HttpClient *client, const String *verb, const String *path, HttpR
|
|||||||
|
|
||||||
HttpRequest *this = NULL;
|
HttpRequest *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("HttpRequest")
|
OBJ_NEW_BEGIN(HttpRequest)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(HttpRequest));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (HttpRequest)
|
*this = (HttpRequest)
|
||||||
{
|
{
|
||||||
.pub =
|
.pub =
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.verb = strDup(verb),
|
.verb = strDup(verb),
|
||||||
.path = strDup(path),
|
.path = strDup(path),
|
||||||
.query = httpQueryDupP(param.query),
|
.query = httpQueryDupP(param.query),
|
||||||
@ -211,7 +210,7 @@ httpRequestNew(HttpClient *client, const String *verb, const String *path, HttpR
|
|||||||
httpRequestProcess(this, false, false);
|
httpRequestProcess(this, false, false);
|
||||||
statInc(HTTP_STAT_REQUEST_STR);
|
statInc(HTTP_STAT_REQUEST_STR);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(HTTP_REQUEST, this);
|
FUNCTION_LOG_RETURN(HTTP_REQUEST, this);
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,6 @@ Getters/Setters
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct HttpRequestPub
|
typedef struct HttpRequestPub
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
const String *verb; // HTTP verb (GET, POST, etc.)
|
const String *verb; // HTTP verb (GET, POST, etc.)
|
||||||
const String *path; // HTTP path
|
const String *path; // HTTP path
|
||||||
const HttpQuery *query; // HTTP query
|
const HttpQuery *query; // HTTP query
|
||||||
|
@ -202,15 +202,14 @@ httpResponseNew(HttpSession *session, const String *verb, bool contentCache)
|
|||||||
|
|
||||||
HttpResponse *this = NULL;
|
HttpResponse *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("HttpResponse")
|
OBJ_NEW_BEGIN(HttpResponse)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(HttpResponse));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (HttpResponse)
|
*this = (HttpResponse)
|
||||||
{
|
{
|
||||||
.pub =
|
.pub =
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.header = httpHeaderNew(NULL),
|
.header = httpHeaderNew(NULL),
|
||||||
},
|
},
|
||||||
.session = httpSessionMove(session, memContextCurrent()),
|
.session = httpSessionMove(session, memContextCurrent()),
|
||||||
@ -251,7 +250,7 @@ httpResponseNew(HttpSession *session, const String *verb, bool contentCache)
|
|||||||
this->pub.code = cvtZToUInt(strZ(strSubN(status, 0, (size_t)spacePos)));
|
this->pub.code = cvtZToUInt(strZ(strSubN(status, 0, (size_t)spacePos)));
|
||||||
|
|
||||||
// Read reason phrase. A missing reason phrase will be represented as an empty string.
|
// Read reason phrase. A missing reason phrase will be represented as an empty string.
|
||||||
MEM_CONTEXT_BEGIN(this->pub.memContext)
|
MEM_CONTEXT_BEGIN(objMemContext(this))
|
||||||
{
|
{
|
||||||
this->pub.reason = strSub(status, (size_t)spacePos + 1);
|
this->pub.reason = strSub(status, (size_t)spacePos + 1);
|
||||||
}
|
}
|
||||||
@ -321,7 +320,7 @@ httpResponseNew(HttpSession *session, const String *verb, bool contentCache)
|
|||||||
|
|
||||||
// Create an io object, even if there is no content. This makes the logic for readers easier -- they can just check eof
|
// Create an io object, even if there is no content. This makes the logic for readers easier -- they can just check eof
|
||||||
// rather than also checking if the io object exists.
|
// rather than also checking if the io object exists.
|
||||||
MEM_CONTEXT_BEGIN(this->pub.memContext)
|
MEM_CONTEXT_BEGIN(objMemContext(this))
|
||||||
{
|
{
|
||||||
this->pub.contentRead = ioReadNewP(this, .eof = httpResponseEof, .read = httpResponseRead);
|
this->pub.contentRead = ioReadNewP(this, .eof = httpResponseEof, .read = httpResponseRead);
|
||||||
ioReadOpen(httpResponseIoRead(this));
|
ioReadOpen(httpResponseIoRead(this));
|
||||||
@ -336,7 +335,7 @@ httpResponseNew(HttpSession *session, const String *verb, bool contentCache)
|
|||||||
// Else cache content when requested or on error
|
// Else cache content when requested or on error
|
||||||
else if (contentCache || !httpResponseCodeOk(this))
|
else if (contentCache || !httpResponseCodeOk(this))
|
||||||
{
|
{
|
||||||
MEM_CONTEXT_BEGIN(this->pub.memContext)
|
MEM_CONTEXT_BEGIN(objMemContext(this))
|
||||||
{
|
{
|
||||||
httpResponseContent(this);
|
httpResponseContent(this);
|
||||||
}
|
}
|
||||||
@ -345,7 +344,7 @@ httpResponseNew(HttpSession *session, const String *verb, bool contentCache)
|
|||||||
}
|
}
|
||||||
MEM_CONTEXT_TEMP_END();
|
MEM_CONTEXT_TEMP_END();
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(HTTP_RESPONSE, this);
|
FUNCTION_LOG_RETURN(HTTP_RESPONSE, this);
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,6 @@ Getters/Setters
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct HttpResponsePub
|
typedef struct HttpResponsePub
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
IoRead *contentRead; // Read interface for response content
|
IoRead *contentRead; // Read interface for response content
|
||||||
unsigned int code; // Response code (e.g. 200, 404)
|
unsigned int code; // Response code (e.g. 200, 404)
|
||||||
HttpHeader *header; // Response headers
|
HttpHeader *header; // Response headers
|
||||||
|
@ -7,14 +7,12 @@ HTTP Session
|
|||||||
#include "common/io/http/session.h"
|
#include "common/io/http/session.h"
|
||||||
#include "common/io/io.h"
|
#include "common/io/io.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Object type
|
Object type
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
struct HttpSession
|
struct HttpSession
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
HttpClient *httpClient; // HTTP client
|
HttpClient *httpClient; // HTTP client
|
||||||
IoSession *ioSession; // IO session
|
IoSession *ioSession; // IO session
|
||||||
};
|
};
|
||||||
@ -33,18 +31,17 @@ httpSessionNew(HttpClient *httpClient, IoSession *ioSession)
|
|||||||
|
|
||||||
HttpSession *this = NULL;
|
HttpSession *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("HttpSession")
|
OBJ_NEW_BEGIN(HttpSession)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(HttpSession));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (HttpSession)
|
*this = (HttpSession)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.httpClient = httpClient,
|
.httpClient = httpClient,
|
||||||
.ioSession = ioSessionMove(ioSession, memContextCurrent()),
|
.ioSession = ioSessionMove(ioSession, memContextCurrent()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(HTTP_SESSION, this);
|
FUNCTION_LOG_RETURN(HTTP_SESSION, this);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ HTTP URL
|
|||||||
|
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/io/http/url.h"
|
#include "common/io/http/url.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/stringList.h"
|
#include "common/type/stringList.h"
|
||||||
#include "common/regExp.h"
|
#include "common/regExp.h"
|
||||||
|
|
||||||
@ -63,16 +62,15 @@ httpUrlNewParse(const String *const url, HttpUrlNewParseParam param)
|
|||||||
|
|
||||||
HttpUrl *this = NULL;
|
HttpUrl *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("HttpUrl")
|
OBJ_NEW_BEGIN(HttpUrl)
|
||||||
{
|
{
|
||||||
// Allocate state and set context
|
// Allocate state and set context
|
||||||
this = memNew(sizeof(HttpUrl));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (HttpUrl)
|
*this = (HttpUrl)
|
||||||
{
|
{
|
||||||
.pub =
|
.pub =
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.url = strDup(url),
|
.url = strDup(url),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -191,7 +189,7 @@ httpUrlNewParse(const String *const url, HttpUrlNewParseParam param)
|
|||||||
}
|
}
|
||||||
MEM_CONTEXT_TEMP_END();
|
MEM_CONTEXT_TEMP_END();
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(this);
|
FUNCTION_TEST_RETURN(this);
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,6 @@ Getters/setters
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct HttpUrlPub
|
typedef struct HttpUrlPub
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
const String *url; // Original URL
|
const String *url; // Original URL
|
||||||
HttpProtocolType type; // Protocol type, e.g. http
|
HttpProtocolType type; // Protocol type, e.g. http
|
||||||
const String *host; // Host
|
const String *host; // Host
|
||||||
|
@ -9,7 +9,6 @@ IO Read Interface
|
|||||||
#include "common/io/io.h"
|
#include "common/io/io.h"
|
||||||
#include "common/io/read.h"
|
#include "common/io/read.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Object type
|
Object type
|
||||||
@ -36,9 +35,9 @@ ioReadNew(void *driver, IoReadInterface interface)
|
|||||||
|
|
||||||
IoRead *this = NULL;
|
IoRead *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("IoRead")
|
OBJ_NEW_BEGIN(IoRead)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(IoRead));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (IoRead)
|
*this = (IoRead)
|
||||||
{
|
{
|
||||||
@ -52,7 +51,7 @@ ioReadNew(void *driver, IoReadInterface interface)
|
|||||||
.input = bufNew(ioBufferSize()),
|
.input = bufNew(ioBufferSize()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_READ, this);
|
FUNCTION_LOG_RETURN(IO_READ, this);
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ Destructor
|
|||||||
__attribute__((always_inline)) static inline void
|
__attribute__((always_inline)) static inline void
|
||||||
ioReadFree(IoRead *const this)
|
ioReadFree(IoRead *const this)
|
||||||
{
|
{
|
||||||
objFree(this);
|
objFreeContext(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
|
@ -6,7 +6,6 @@ Io Session Interface
|
|||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/io/session.h"
|
#include "common/io/session.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Object type
|
Object type
|
||||||
|
@ -76,7 +76,7 @@ ioSessionClose(IoSession *const this)
|
|||||||
__attribute__((always_inline)) static inline IoSession *
|
__attribute__((always_inline)) static inline IoSession *
|
||||||
ioSessionMove(IoSession *const this, MemContext *const parentNew)
|
ioSessionMove(IoSession *const this, MemContext *const parentNew)
|
||||||
{
|
{
|
||||||
return objMove(this, parentNew);
|
return objMoveContext(this, parentNew);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -85,7 +85,7 @@ Destructor
|
|||||||
__attribute__((always_inline)) static inline void
|
__attribute__((always_inline)) static inline void
|
||||||
ioSessionFree(IoSession *const this)
|
ioSessionFree(IoSession *const this)
|
||||||
{
|
{
|
||||||
objFree(this);
|
objFreeContext(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
|
@ -14,7 +14,6 @@ Socket Client
|
|||||||
#include "common/io/socket/client.h"
|
#include "common/io/socket/client.h"
|
||||||
#include "common/io/socket/common.h"
|
#include "common/io/socket/common.h"
|
||||||
#include "common/io/socket/session.h"
|
#include "common/io/socket/session.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/stat.h"
|
#include "common/stat.h"
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
#include "common/wait.h"
|
#include "common/wait.h"
|
||||||
@ -31,7 +30,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct SocketClient
|
typedef struct SocketClient
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
String *host; // Hostname or IP address
|
String *host; // Hostname or IP address
|
||||||
unsigned int port; // Port to connect to host on
|
unsigned int port; // Port to connect to host on
|
||||||
String *name; // Socket name (host:port)
|
String *name; // Socket name (host:port)
|
||||||
@ -190,13 +188,12 @@ sckClientNew(const String *host, unsigned int port, TimeMSec timeout)
|
|||||||
|
|
||||||
IoClient *this = NULL;
|
IoClient *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("SocketClient")
|
OBJ_NEW_BEGIN(SocketClient)
|
||||||
{
|
{
|
||||||
SocketClient *driver = memNew(sizeof(SocketClient));
|
SocketClient *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (SocketClient)
|
*driver = (SocketClient)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.host = strDup(host),
|
.host = strDup(host),
|
||||||
.port = port,
|
.port = port,
|
||||||
.name = strNewFmt("%s:%u", strZ(host), port),
|
.name = strNewFmt("%s:%u", strZ(host), port),
|
||||||
@ -207,7 +204,7 @@ sckClientNew(const String *host, unsigned int port, TimeMSec timeout)
|
|||||||
|
|
||||||
this = ioClientNew(driver, &sckClientInterface);
|
this = ioClientNew(driver, &sckClientInterface);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_CLIENT, this);
|
FUNCTION_LOG_RETURN(IO_CLIENT, this);
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ Socket Session
|
|||||||
#include "common/io/fdWrite.h"
|
#include "common/io/fdWrite.h"
|
||||||
#include "common/io/socket/client.h"
|
#include "common/io/socket/client.h"
|
||||||
#include "common/io/session.h"
|
#include "common/io/session.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -19,7 +18,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct SocketSession
|
typedef struct SocketSession
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
IoSessionRole role; // Role (server or client)
|
IoSessionRole role; // Role (server or client)
|
||||||
int fd; // File descriptor
|
int fd; // File descriptor
|
||||||
String *host; // Hostname or IP address
|
String *host; // Hostname or IP address
|
||||||
@ -81,7 +79,7 @@ sckSessionClose(THIS_VOID)
|
|||||||
if (this->fd != -1)
|
if (this->fd != -1)
|
||||||
{
|
{
|
||||||
// Clear the callback to close the socket
|
// Clear the callback to close the socket
|
||||||
memContextCallbackClear(this->memContext);
|
memContextCallbackClear(objMemContext(this));
|
||||||
|
|
||||||
// Close the socket
|
// Close the socket
|
||||||
close(this->fd);
|
close(this->fd);
|
||||||
@ -179,15 +177,14 @@ sckSessionNew(IoSessionRole role, int fd, const String *host, unsigned int port,
|
|||||||
|
|
||||||
IoSession *this = NULL;
|
IoSession *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("SocketSession")
|
OBJ_NEW_BEGIN(SocketSession)
|
||||||
{
|
{
|
||||||
SocketSession *driver = memNew(sizeof(SocketSession));
|
SocketSession *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
String *name = strNewFmt("%s:%u", strZ(host), port);
|
String *name = strNewFmt("%s:%u", strZ(host), port);
|
||||||
|
|
||||||
*driver = (SocketSession)
|
*driver = (SocketSession)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.role = role,
|
.role = role,
|
||||||
.fd = fd,
|
.fd = fd,
|
||||||
.host = strDup(host),
|
.host = strDup(host),
|
||||||
@ -200,11 +197,11 @@ sckSessionNew(IoSessionRole role, int fd, const String *host, unsigned int port,
|
|||||||
strFree(name);
|
strFree(name);
|
||||||
|
|
||||||
// Ensure file descriptor is closed
|
// Ensure file descriptor is closed
|
||||||
memContextCallbackSet(driver->memContext, sckSessionFreeResource, driver);
|
memContextCallbackSet(objMemContext(driver), sckSessionFreeResource, driver);
|
||||||
|
|
||||||
this = ioSessionNew(driver, &sckSessionInterface);
|
this = ioSessionNew(driver, &sckSessionInterface);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_SESSION, this);
|
FUNCTION_LOG_RETURN(IO_SESSION, this);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ TLS Client
|
|||||||
#include "common/io/io.h"
|
#include "common/io/io.h"
|
||||||
#include "common/io/tls/client.h"
|
#include "common/io/tls/client.h"
|
||||||
#include "common/io/tls/session.h"
|
#include "common/io/tls/session.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/stat.h"
|
#include "common/stat.h"
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
#include "common/wait.h"
|
#include "common/wait.h"
|
||||||
@ -32,7 +31,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct TlsClient
|
typedef struct TlsClient
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
const String *host; // Host to use for peer verification
|
const String *host; // Host to use for peer verification
|
||||||
TimeMSec timeout; // Timeout for any i/o operation (connect, read, etc.)
|
TimeMSec timeout; // Timeout for any i/o operation (connect, read, etc.)
|
||||||
bool verifyPeer; // Should the peer (server) certificate be verified?
|
bool verifyPeer; // Should the peer (server) certificate be verified?
|
||||||
@ -51,7 +49,7 @@ tlsClientToLog(const THIS_VOID)
|
|||||||
|
|
||||||
return strNewFmt(
|
return strNewFmt(
|
||||||
"{ioClient: %s, timeout: %" PRIu64", verifyPeer: %s}",
|
"{ioClient: %s, timeout: %" PRIu64", verifyPeer: %s}",
|
||||||
memContextFreeing(this->memContext) ? NULL_Z : strZ(ioClientToLog(this->ioClient)), this->timeout,
|
objMemContextFreeing(this) ? NULL_Z : strZ(ioClientToLog(this->ioClient)), this->timeout,
|
||||||
cvtBoolToConstZ(this->verifyPeer));
|
cvtBoolToConstZ(this->verifyPeer));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,13 +351,12 @@ tlsClientNew(IoClient *ioClient, const String *host, TimeMSec timeout, bool veri
|
|||||||
|
|
||||||
IoClient *this = NULL;
|
IoClient *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("TlsClient")
|
OBJ_NEW_BEGIN(TlsClient)
|
||||||
{
|
{
|
||||||
TlsClient *driver = memNew(sizeof(TlsClient));
|
TlsClient *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (TlsClient)
|
*driver = (TlsClient)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.ioClient = ioClientMove(ioClient, MEM_CONTEXT_NEW()),
|
.ioClient = ioClientMove(ioClient, MEM_CONTEXT_NEW()),
|
||||||
.host = strDup(host),
|
.host = strDup(host),
|
||||||
.timeout = timeout,
|
.timeout = timeout,
|
||||||
@ -379,7 +376,7 @@ tlsClientNew(IoClient *ioClient, const String *host, TimeMSec timeout, bool veri
|
|||||||
driver->context = SSL_CTX_new(method);
|
driver->context = SSL_CTX_new(method);
|
||||||
cryptoError(driver->context == NULL, "unable to create TLS context");
|
cryptoError(driver->context == NULL, "unable to create TLS context");
|
||||||
|
|
||||||
memContextCallbackSet(driver->memContext, tlsClientFreeResource, driver);
|
memContextCallbackSet(objMemContext(driver), tlsClientFreeResource, driver);
|
||||||
|
|
||||||
// Exclude SSL versions to only allow TLS and also disable compression
|
// Exclude SSL versions to only allow TLS and also disable compression
|
||||||
SSL_CTX_set_options(driver->context, (long)(SSL_OP_ALL | SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_COMPRESSION));
|
SSL_CTX_set_options(driver->context, (long)(SSL_OP_ALL | SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_COMPRESSION));
|
||||||
@ -411,7 +408,7 @@ tlsClientNew(IoClient *ioClient, const String *host, TimeMSec timeout, bool veri
|
|||||||
// Create client interface
|
// Create client interface
|
||||||
this = ioClientNew(driver, &tlsClientInterface);
|
this = ioClientNew(driver, &tlsClientInterface);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_CLIENT, this);
|
FUNCTION_LOG_RETURN(IO_CLIENT, this);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ TLS Session
|
|||||||
#include "common/io/tls/session.h"
|
#include "common/io/tls/session.h"
|
||||||
#include "common/io/write.h"
|
#include "common/io/write.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -22,7 +21,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct TlsSession
|
typedef struct TlsSession
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
IoSession *ioSession; // Io session
|
IoSession *ioSession; // Io session
|
||||||
SSL *session; // TLS session on the file descriptor
|
SSL *session; // TLS session on the file descriptor
|
||||||
TimeMSec timeout; // Timeout for any i/o operation (connect, read, etc.)
|
TimeMSec timeout; // Timeout for any i/o operation (connect, read, etc.)
|
||||||
@ -42,7 +40,7 @@ tlsSessionToLog(const THIS_VOID)
|
|||||||
|
|
||||||
return strNewFmt(
|
return strNewFmt(
|
||||||
"{ioSession: %s, timeout: %" PRIu64", shutdownOnClose: %s}",
|
"{ioSession: %s, timeout: %" PRIu64", shutdownOnClose: %s}",
|
||||||
memContextFreeing(this->memContext) ? NULL_Z : strZ(ioSessionToLog(this->ioSession)), this->timeout,
|
objMemContextFreeing(this) ? NULL_Z : strZ(ioSessionToLog(this->ioSession)), this->timeout,
|
||||||
cvtBoolToConstZ(this->shutdownOnClose));
|
cvtBoolToConstZ(this->shutdownOnClose));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +91,7 @@ tlsSessionClose(THIS_VOID)
|
|||||||
ioSessionClose(this->ioSession);
|
ioSessionClose(this->ioSession);
|
||||||
|
|
||||||
// Free the TLS session
|
// Free the TLS session
|
||||||
memContextCallbackClear(this->memContext);
|
memContextCallbackClear(objMemContext(this));
|
||||||
tlsSessionFreeResource(this);
|
tlsSessionFreeResource(this);
|
||||||
this->session = NULL;
|
this->session = NULL;
|
||||||
}
|
}
|
||||||
@ -363,13 +361,12 @@ tlsSessionNew(SSL *session, IoSession *ioSession, TimeMSec timeout)
|
|||||||
|
|
||||||
IoSession *this = NULL;
|
IoSession *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("TlsSession")
|
OBJ_NEW_BEGIN(TlsSession)
|
||||||
{
|
{
|
||||||
TlsSession *driver = memNew(sizeof(TlsSession));
|
TlsSession *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (TlsSession)
|
*driver = (TlsSession)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.session = session,
|
.session = session,
|
||||||
.ioSession = ioSessionMove(ioSession, MEM_CONTEXT_NEW()),
|
.ioSession = ioSessionMove(ioSession, MEM_CONTEXT_NEW()),
|
||||||
.timeout = timeout,
|
.timeout = timeout,
|
||||||
@ -377,7 +374,7 @@ tlsSessionNew(SSL *session, IoSession *ioSession, TimeMSec timeout)
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Ensure session is freed
|
// Ensure session is freed
|
||||||
memContextCallbackSet(driver->memContext, tlsSessionFreeResource, driver);
|
memContextCallbackSet(objMemContext(driver), tlsSessionFreeResource, driver);
|
||||||
|
|
||||||
// Assign file descriptor to TLS session
|
// Assign file descriptor to TLS session
|
||||||
cryptoError(SSL_set_fd(driver->session, ioSessionFd(driver->ioSession)) != 1, "unable to add fd to TLS session");
|
cryptoError(SSL_set_fd(driver->session, ioSessionFd(driver->ioSession)) != 1, "unable to add fd to TLS session");
|
||||||
@ -404,7 +401,7 @@ tlsSessionNew(SSL *session, IoSession *ioSession, TimeMSec timeout)
|
|||||||
// Create session interface
|
// Create session interface
|
||||||
this = ioSessionNew(driver, &tlsSessionInterface);
|
this = ioSessionNew(driver, &tlsSessionInterface);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_SESSION, this);
|
FUNCTION_LOG_RETURN(IO_SESSION, this);
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ IO Write Interface
|
|||||||
#include "common/io/io.h"
|
#include "common/io/io.h"
|
||||||
#include "common/io/write.h"
|
#include "common/io/write.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Object type
|
Object type
|
||||||
@ -42,9 +41,9 @@ ioWriteNew(void *driver, IoWriteInterface interface)
|
|||||||
|
|
||||||
IoWrite *this = NULL;
|
IoWrite *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("IoWrite")
|
OBJ_NEW_BEGIN(IoWrite)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(IoWrite));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (IoWrite)
|
*this = (IoWrite)
|
||||||
{
|
{
|
||||||
@ -58,7 +57,7 @@ ioWriteNew(void *driver, IoWriteInterface interface)
|
|||||||
.output = bufNew(ioBufferSize()),
|
.output = bufNew(ioBufferSize()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(IO_WRITE, this);
|
FUNCTION_LOG_RETURN(IO_WRITE, this);
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ Destructor
|
|||||||
__attribute__((always_inline)) static inline void
|
__attribute__((always_inline)) static inline void
|
||||||
ioWriteFree(IoWrite *const this)
|
ioWriteFree(IoWrite *const this)
|
||||||
{
|
{
|
||||||
objFree(this);
|
objFreeContext(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
|
@ -15,8 +15,7 @@ Memory context states
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
memContextStateFree = 0,
|
memContextStateFreeing = 0,
|
||||||
memContextStateFreeing,
|
|
||||||
memContextStateActive
|
memContextStateActive
|
||||||
} MemContextState;
|
} MemContextState;
|
||||||
|
|
||||||
@ -51,7 +50,8 @@ Contains information about the memory context
|
|||||||
struct MemContext
|
struct MemContext
|
||||||
{
|
{
|
||||||
const char *name; // Indicates what the context is being used for
|
const char *name; // Indicates what the context is being used for
|
||||||
MemContextState state; // Current state of the context
|
MemContextState state:1; // Current state of the context
|
||||||
|
size_t allocExtra:16; // Size of extra allocation (1kB max)
|
||||||
|
|
||||||
unsigned int contextParentIdx; // Index in the parent context list
|
unsigned int contextParentIdx; // Index in the parent context list
|
||||||
MemContext *contextParent; // All contexts have a parent except top
|
MemContext *contextParent; // All contexts have a parent except top
|
||||||
@ -210,11 +210,10 @@ memFreeInternal(void *buffer)
|
|||||||
Find space for a new mem context
|
Find space for a new mem context
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
static unsigned int
|
static unsigned int
|
||||||
memContextNewIndex(MemContext *memContext, bool allowFree)
|
memContextNewIndex(MemContext *memContext)
|
||||||
{
|
{
|
||||||
FUNCTION_TEST_BEGIN();
|
FUNCTION_TEST_BEGIN();
|
||||||
FUNCTION_TEST_PARAM(MEM_CONTEXT, memContext);
|
FUNCTION_TEST_PARAM(MEM_CONTEXT, memContext);
|
||||||
FUNCTION_TEST_PARAM(BOOL, allowFree);
|
|
||||||
FUNCTION_TEST_END();
|
FUNCTION_TEST_END();
|
||||||
|
|
||||||
ASSERT(memContext != NULL);
|
ASSERT(memContext != NULL);
|
||||||
@ -222,12 +221,9 @@ memContextNewIndex(MemContext *memContext, bool allowFree)
|
|||||||
// Try to find space for the new context
|
// Try to find space for the new context
|
||||||
for (; memContext->contextChildFreeIdx < memContext->contextChildListSize; memContext->contextChildFreeIdx++)
|
for (; memContext->contextChildFreeIdx < memContext->contextChildListSize; memContext->contextChildFreeIdx++)
|
||||||
{
|
{
|
||||||
if (memContext->contextChildList[memContext->contextChildFreeIdx] == NULL ||
|
if (memContext->contextChildList[memContext->contextChildFreeIdx] == NULL)
|
||||||
(allowFree && memContext->contextChildList[memContext->contextChildFreeIdx]->state == memContextStateFree))
|
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// If no space was found then allocate more
|
// If no space was found then allocate more
|
||||||
if (memContext->contextChildFreeIdx == memContext->contextChildListSize)
|
if (memContext->contextChildFreeIdx == memContext->contextChildListSize)
|
||||||
@ -261,37 +257,35 @@ memContextNewIndex(MemContext *memContext, bool allowFree)
|
|||||||
|
|
||||||
/**********************************************************************************************************************************/
|
/**********************************************************************************************************************************/
|
||||||
MemContext *
|
MemContext *
|
||||||
memContextNew(const char *name)
|
memContextNew(const char *const name, const MemContextNewParam param)
|
||||||
{
|
{
|
||||||
FUNCTION_TEST_BEGIN();
|
FUNCTION_TEST_BEGIN();
|
||||||
FUNCTION_TEST_PARAM(STRINGZ, name);
|
FUNCTION_TEST_PARAM(STRINGZ, name);
|
||||||
|
FUNCTION_TEST_PARAM(SIZE, param.allocExtra);
|
||||||
FUNCTION_TEST_END();
|
FUNCTION_TEST_END();
|
||||||
|
|
||||||
ASSERT(name != NULL);
|
ASSERT(name != NULL);
|
||||||
|
|
||||||
// Check context name length
|
// Check context name length
|
||||||
ASSERT(name[0] != '\0');
|
ASSERT(name[0] != '\0');
|
||||||
|
|
||||||
// Find space for the new context
|
// Find space for the new context
|
||||||
MemContext *contextCurrent = memContextStack[memContextCurrentStackIdx].memContext;
|
MemContext *contextCurrent = memContextStack[memContextCurrentStackIdx].memContext;
|
||||||
unsigned int contextIdx = memContextNewIndex(contextCurrent, true);
|
unsigned int contextIdx = memContextNewIndex(contextCurrent);
|
||||||
|
|
||||||
// If the context has not been allocated yet
|
// Allocate memory for the context
|
||||||
if (contextCurrent->contextChildList[contextIdx] == NULL)
|
contextCurrent->contextChildList[contextIdx] = memAllocInternal(sizeof(MemContext) + param.allocExtra);
|
||||||
contextCurrent->contextChildList[contextIdx] = memAllocInternal(sizeof(MemContext));
|
|
||||||
|
|
||||||
// Get the context
|
// Get the context
|
||||||
MemContext *this = contextCurrent->contextChildList[contextIdx];
|
MemContext *this = contextCurrent->contextChildList[contextIdx];
|
||||||
|
|
||||||
*this = (MemContext)
|
*this = (MemContext)
|
||||||
{
|
{
|
||||||
// Create initial space for allocations
|
|
||||||
.allocList = memAllocPtrArrayInternal(MEM_CONTEXT_ALLOC_INITIAL_SIZE),
|
|
||||||
.allocListSize = MEM_CONTEXT_ALLOC_INITIAL_SIZE,
|
|
||||||
|
|
||||||
// Set the context name
|
// Set the context name
|
||||||
.name = name,
|
.name = name,
|
||||||
|
|
||||||
|
// Set extra allocation
|
||||||
|
.allocExtra = param.allocExtra,
|
||||||
|
|
||||||
// Set new context active
|
// Set new context active
|
||||||
.state = memContextStateActive,
|
.state = memContextStateActive,
|
||||||
|
|
||||||
@ -317,6 +311,47 @@ memContextNew(const char *name)
|
|||||||
FUNCTION_TEST_RETURN(this);
|
FUNCTION_TEST_RETURN(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**********************************************************************************************************************************/
|
||||||
|
void *
|
||||||
|
memContextAllocExtra(MemContext *const this)
|
||||||
|
{
|
||||||
|
FUNCTION_TEST_BEGIN();
|
||||||
|
FUNCTION_TEST_PARAM(MEM_CONTEXT, this);
|
||||||
|
FUNCTION_TEST_END();
|
||||||
|
|
||||||
|
ASSERT(this != NULL);
|
||||||
|
ASSERT(this->allocExtra != 0);
|
||||||
|
|
||||||
|
FUNCTION_TEST_RETURN(this + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************************************************************************************************************/
|
||||||
|
MemContext *
|
||||||
|
memContextFromAllocExtra(void *const allocExtra)
|
||||||
|
{
|
||||||
|
FUNCTION_TEST_BEGIN();
|
||||||
|
FUNCTION_TEST_PARAM_P(VOID, allocExtra);
|
||||||
|
FUNCTION_TEST_END();
|
||||||
|
|
||||||
|
ASSERT(allocExtra != NULL);
|
||||||
|
ASSERT(((MemContext *)allocExtra - 1)->allocExtra != 0);
|
||||||
|
|
||||||
|
FUNCTION_TEST_RETURN((MemContext *)allocExtra - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const MemContext *
|
||||||
|
memContextConstFromAllocExtra(const void *const allocExtra)
|
||||||
|
{
|
||||||
|
FUNCTION_TEST_BEGIN();
|
||||||
|
FUNCTION_TEST_PARAM_P(VOID, allocExtra);
|
||||||
|
FUNCTION_TEST_END();
|
||||||
|
|
||||||
|
ASSERT(allocExtra != NULL);
|
||||||
|
ASSERT(((MemContext *)allocExtra - 1)->allocExtra != 0);
|
||||||
|
|
||||||
|
FUNCTION_TEST_RETURN((MemContext *)allocExtra - 1);
|
||||||
|
}
|
||||||
|
|
||||||
/**********************************************************************************************************************************/
|
/**********************************************************************************************************************************/
|
||||||
void
|
void
|
||||||
memContextCallbackSet(MemContext *this, void (*callbackFunction)(void *), void *callbackArgument)
|
memContextCallbackSet(MemContext *this, void (*callbackFunction)(void *), void *callbackArgument)
|
||||||
@ -544,8 +579,7 @@ memContextMove(MemContext *this, MemContext *parentNew)
|
|||||||
// Find a place in the new parent context and assign it. The child list may be moved while finding a new index so store the
|
// Find a place in the new parent context and assign it. The child list may be moved while finding a new index so store the
|
||||||
// index and use it with (what might be) the new pointer.
|
// index and use it with (what might be) the new pointer.
|
||||||
this->contextParent = parentNew;
|
this->contextParent = parentNew;
|
||||||
this->contextParentIdx = memContextNewIndex(parentNew, false);
|
this->contextParentIdx = memContextNewIndex(parentNew);
|
||||||
ASSERT(parentNew->contextChildList[this->contextParentIdx] == NULL);
|
|
||||||
parentNew->contextChildList[this->contextParentIdx] = this;
|
parentNew->contextChildList[this->contextParentIdx] = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -727,7 +761,7 @@ memContextSize(const MemContext *this)
|
|||||||
|
|
||||||
// Size of struct and child context/alloc arrays
|
// Size of struct and child context/alloc arrays
|
||||||
size_t result =
|
size_t result =
|
||||||
sizeof(MemContext) + (this->contextChildListSize * sizeof(MemContext *)) +
|
sizeof(MemContext) + this->allocExtra + (this->contextChildListSize * sizeof(MemContext *)) +
|
||||||
(this->allocListSize * sizeof(MemContextAlloc *));
|
(this->allocListSize * sizeof(MemContextAlloc *));
|
||||||
|
|
||||||
// Add child contexts
|
// Add child contexts
|
||||||
@ -797,14 +831,12 @@ memContextFree(MemContext *this)
|
|||||||
if (this == memContextStack[memContextCurrentStackIdx].memContext && this != &contextTop)
|
if (this == memContextStack[memContextCurrentStackIdx].memContext && this != &contextTop)
|
||||||
THROW_FMT(AssertError, "cannot free current context '%s'", this->name);
|
THROW_FMT(AssertError, "cannot free current context '%s'", this->name);
|
||||||
|
|
||||||
// Error if context is not active
|
|
||||||
if (this->state != memContextStateActive)
|
|
||||||
THROW(AssertError, "cannot free inactive context");
|
|
||||||
|
|
||||||
// Free child contexts
|
// Free child contexts
|
||||||
for (unsigned int contextIdx = 0; contextIdx < this->contextChildListSize; contextIdx++)
|
for (unsigned int contextIdx = 0; contextIdx < this->contextChildListSize; contextIdx++)
|
||||||
if (this->contextChildList[contextIdx] && this->contextChildList[contextIdx]->state == memContextStateActive)
|
{
|
||||||
|
if (this->contextChildList[contextIdx] != NULL)
|
||||||
memContextFree(this->contextChildList[contextIdx]);
|
memContextFree(this->contextChildList[contextIdx]);
|
||||||
|
}
|
||||||
|
|
||||||
// Set state to freeing now that there are no child contexts. Child contexts might need to interact with their parent while
|
// Set state to freeing now that there are no child contexts. Child contexts might need to interact with their parent while
|
||||||
// freeing so the parent needs to remain active until they are all gone.
|
// freeing so the parent needs to remain active until they are all gone.
|
||||||
@ -819,18 +851,14 @@ memContextFree(MemContext *this)
|
|||||||
// Finish cleanup even if the callback fails
|
// Finish cleanup even if the callback fails
|
||||||
FINALLY()
|
FINALLY()
|
||||||
{
|
{
|
||||||
// Free child context allocations
|
// Free child context allocation list
|
||||||
if (this->contextChildListSize > 0)
|
if (this->contextChildListSize > 0)
|
||||||
{
|
{
|
||||||
for (unsigned int contextIdx = 0; contextIdx < this->contextChildListSize; contextIdx++)
|
|
||||||
if (this->contextChildList[contextIdx])
|
|
||||||
memFreeInternal(this->contextChildList[contextIdx]);
|
|
||||||
|
|
||||||
memFreeInternal(this->contextChildList);
|
memFreeInternal(this->contextChildList);
|
||||||
this->contextChildListSize = 0;
|
this->contextChildListSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free memory allocations
|
// Free memory allocations and list
|
||||||
if (this->allocListSize > 0)
|
if (this->allocListSize > 0)
|
||||||
{
|
{
|
||||||
for (unsigned int allocIdx = 0; allocIdx < this->allocListSize; allocIdx++)
|
for (unsigned int allocIdx = 0; allocIdx < this->allocListSize; allocIdx++)
|
||||||
@ -847,10 +875,17 @@ memContextFree(MemContext *this)
|
|||||||
|
|
||||||
// Make top context active again
|
// Make top context active again
|
||||||
if (this == &contextTop)
|
if (this == &contextTop)
|
||||||
|
{
|
||||||
this->state = memContextStateActive;
|
this->state = memContextStateActive;
|
||||||
// Else reset the memory context so it can be reused
|
}
|
||||||
|
// Else free the memory context so the slot can be reused
|
||||||
else
|
else
|
||||||
*this = (MemContext){.state = memContextStateFree};
|
{
|
||||||
|
ASSERT(this->contextParent != NULL);
|
||||||
|
|
||||||
|
this->contextParent->contextChildList[this->contextParentIdx] = NULL;
|
||||||
|
memFreeInternal(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TRY_END();
|
TRY_END();
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ See the sections on memory context management and memory allocations below for m
|
|||||||
#define COMMON_MEMCONTEXT_H
|
#define COMMON_MEMCONTEXT_H
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Memory context object
|
Memory context object
|
||||||
@ -20,6 +21,7 @@ Memory context object
|
|||||||
typedef struct MemContext MemContext;
|
typedef struct MemContext MemContext;
|
||||||
|
|
||||||
#include "common/error.h"
|
#include "common/error.h"
|
||||||
|
#include "common/type/param.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Define initial number of memory contexts
|
Define initial number of memory contexts
|
||||||
@ -97,13 +99,10 @@ MEM_CONTEXT_PRIOR_END();
|
|||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Create a new context and make sure it is freed on error and prior context is restored in all cases
|
Create a new context and make sure it is freed on error and prior context is restored in all cases
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN(memContextName)
|
MEM_CONTEXT_NEW_BEGIN(memContextName, ...)
|
||||||
{
|
{
|
||||||
<The mem context created is now the current context and can be accessed with the MEM_CONTEXT_NEW() macro>
|
<The mem context created is now the current context and can be accessed with the MEM_CONTEXT_NEW() macro>
|
||||||
|
<If extra memory was allocation with the context if can be accessed with the MEM_CONTEXT_NEW_ALLOC() macro>
|
||||||
ObjectType *object = memNew(sizeof(ObjectType));
|
|
||||||
object->memContext = MEM_CONTEXT_NEW();
|
|
||||||
|
|
||||||
<Prior context can be accessed with the memContextPrior() function>
|
<Prior context can be accessed with the memContextPrior() function>
|
||||||
<On error the newly created context will be freed and the error rethrown>
|
<On error the newly created context will be freed and the error rethrown>
|
||||||
}
|
}
|
||||||
@ -116,12 +115,15 @@ Note that memory context names are expected to live for the lifetime of the cont
|
|||||||
#define MEM_CONTEXT_NEW() \
|
#define MEM_CONTEXT_NEW() \
|
||||||
MEM_CONTEXT_NEW_memContext
|
MEM_CONTEXT_NEW_memContext
|
||||||
|
|
||||||
#define MEM_CONTEXT_NEW_BEGIN(memContextName) \
|
#define MEM_CONTEXT_NEW_BEGIN(memContextName, ...) \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
MemContext *MEM_CONTEXT_NEW() = memContextNew(memContextName); \
|
MemContext *MEM_CONTEXT_NEW() = memContextNewP(memContextName, __VA_ARGS__); \
|
||||||
memContextSwitch(MEM_CONTEXT_NEW());
|
memContextSwitch(MEM_CONTEXT_NEW());
|
||||||
|
|
||||||
|
#define MEM_CONTEXT_NEW_ALLOC() \
|
||||||
|
memContextAllocExtra(MEM_CONTEXT_NEW())
|
||||||
|
|
||||||
#define MEM_CONTEXT_NEW_END() \
|
#define MEM_CONTEXT_NEW_END() \
|
||||||
memContextSwitchBack(); \
|
memContextSwitchBack(); \
|
||||||
memContextKeep(); \
|
memContextKeep(); \
|
||||||
@ -148,7 +150,7 @@ MEM_CONTEXT_TEMP_END();
|
|||||||
#define MEM_CONTEXT_TEMP_BEGIN() \
|
#define MEM_CONTEXT_TEMP_BEGIN() \
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
MemContext *MEM_CONTEXT_TEMP() = memContextNew("temporary"); \
|
MemContext *MEM_CONTEXT_TEMP() = memContextNewP("temporary"); \
|
||||||
memContextSwitch(MEM_CONTEXT_TEMP());
|
memContextSwitch(MEM_CONTEXT_TEMP());
|
||||||
|
|
||||||
#define MEM_CONTEXT_TEMP_RESET_BEGIN() \
|
#define MEM_CONTEXT_TEMP_RESET_BEGIN() \
|
||||||
@ -164,7 +166,7 @@ MEM_CONTEXT_TEMP_END();
|
|||||||
{ \
|
{ \
|
||||||
memContextSwitchBack(); \
|
memContextSwitchBack(); \
|
||||||
memContextDiscard(); \
|
memContextDiscard(); \
|
||||||
MEM_CONTEXT_TEMP() = memContextNew("temporary"); \
|
MEM_CONTEXT_TEMP() = memContextNewP("temporary"); \
|
||||||
memContextSwitch(MEM_CONTEXT_TEMP()); \
|
memContextSwitch(MEM_CONTEXT_TEMP()); \
|
||||||
MEM_CONTEXT_TEMP_loopTotal = 0; \
|
MEM_CONTEXT_TEMP_loopTotal = 0; \
|
||||||
} \
|
} \
|
||||||
@ -180,7 +182,7 @@ MEM_CONTEXT_TEMP_END();
|
|||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Memory context management functions
|
Memory context management functions
|
||||||
|
|
||||||
memContextSwitch(memContextNew());
|
memContextSwitch(memContextNewP());
|
||||||
|
|
||||||
<Do something with the memory context, e.g. allocation memory with memNew()>
|
<Do something with the memory context, e.g. allocation memory with memNew()>
|
||||||
<Current memory context can be accessed with memContextCurrent()>
|
<Current memory context can be accessed with memContextCurrent()>
|
||||||
@ -199,22 +201,31 @@ Use the MEM_CONTEXT*() macros when possible rather than reimplement the boilerpl
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
// Create a new mem context in the current mem context. The new context must be either kept with memContextKeep() or discarded with
|
// Create a new mem context in the current mem context. The new context must be either kept with memContextKeep() or discarded with
|
||||||
// memContextDisard() before switching back from the parent context.
|
// memContextDisard() before switching back from the parent context.
|
||||||
MemContext *memContextNew(const char *name);
|
typedef struct MemContextNewParam
|
||||||
|
{
|
||||||
|
VAR_PARAM_HEADER;
|
||||||
|
uint16_t allocExtra; // Extra memory to allocate with the context
|
||||||
|
} MemContextNewParam;
|
||||||
|
|
||||||
|
#define memContextNewP(name, ...) \
|
||||||
|
memContextNew(name, (MemContextNewParam){VAR_PARAM_INIT, __VA_ARGS__})
|
||||||
|
|
||||||
|
MemContext *memContextNew(const char *name, MemContextNewParam param);
|
||||||
|
|
||||||
// Switch to a context making it the current mem context
|
// Switch to a context making it the current mem context
|
||||||
void memContextSwitch(MemContext *this);
|
void memContextSwitch(MemContext *this);
|
||||||
|
|
||||||
// Switch back to the context that was current before the last switch. If the last function called was memContextNew(), then
|
// Switch back to the context that was current before the last switch. If the last function called was memContextNewP(), then
|
||||||
// memContextKeep()/memContextDiscard() must be called before calling memContextSwitchBack(), otherwise an error will occur in
|
// memContextKeep()/memContextDiscard() must be called before calling memContextSwitchBack(), otherwise an error will occur in
|
||||||
// debug builds and the behavior is undefined in production builds.
|
// debug builds and the behavior is undefined in production builds.
|
||||||
void memContextSwitchBack(void);
|
void memContextSwitchBack(void);
|
||||||
|
|
||||||
// Keep a context created by memContextNew() so that it will not be automatically freed if an error occurs. If the context was
|
// Keep a context created by memContextNewP() so that it will not be automatically freed if an error occurs. If the context was
|
||||||
// switched after the call to memContextNew(), then it must be switched back before calling memContextKeep() or an error will occur
|
// switched after the call to memContextNewP(), then it must be switched back before calling memContextKeep() or an error will occur
|
||||||
// in debug builds and the behavior is undefined in production builds.
|
// in debug builds and the behavior is undefined in production builds.
|
||||||
void memContextKeep(void);
|
void memContextKeep(void);
|
||||||
|
|
||||||
// Discard a context created by memContextNew(). If the context was switched after the call to memContextNew(), then it must be
|
// Discard a context created by memContextNewP(). If the context was switched after the call to memContextNewP(), then it must be
|
||||||
// switched back before calling memContextDiscard() or an error will occur in debug builds and the behavior is undefined in
|
// switched back before calling memContextDiscard() or an error will occur in debug builds and the behavior is undefined in
|
||||||
// production builds.
|
// production builds.
|
||||||
void memContextDiscard(void);
|
void memContextDiscard(void);
|
||||||
@ -237,6 +248,13 @@ void memContextFree(MemContext *this);
|
|||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Memory context getters
|
Memory context getters
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
|
// Pointer to the extra memory allocated with the mem context
|
||||||
|
void *memContextAllocExtra(MemContext *this);
|
||||||
|
|
||||||
|
// Get mem context using pointer to the memory allocated with the mem context
|
||||||
|
MemContext *memContextFromAllocExtra(void *allocExtra);
|
||||||
|
const MemContext *memContextConstFromAllocExtra(const void *allocExtra);
|
||||||
|
|
||||||
// Current memory context
|
// Current memory context
|
||||||
MemContext *memContextCurrent(void);
|
MemContext *memContextCurrent(void);
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ Regular Expression Handler
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/regExp.h"
|
#include "common/regExp.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -15,7 +14,6 @@ Contains information about the regular expression handler
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
struct RegExp
|
struct RegExp
|
||||||
{
|
{
|
||||||
MemContext *memContext;
|
|
||||||
regex_t regExp;
|
regex_t regExp;
|
||||||
const char *matchPtr;
|
const char *matchPtr;
|
||||||
size_t matchSize;
|
size_t matchSize;
|
||||||
@ -76,14 +74,10 @@ regExpNew(const String *expression)
|
|||||||
|
|
||||||
RegExp *this = NULL;
|
RegExp *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("RegExp")
|
OBJ_NEW_BEGIN(RegExp)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(RegExp));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
*this = (RegExp){{0}}; // Extra braces are required for older gcc versions
|
||||||
*this = (RegExp)
|
|
||||||
{
|
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Compile the regexp and process errors
|
// Compile the regexp and process errors
|
||||||
int result = 0;
|
int result = 0;
|
||||||
@ -92,9 +86,9 @@ regExpNew(const String *expression)
|
|||||||
regExpError(result);
|
regExpError(result);
|
||||||
|
|
||||||
// Set free callback to ensure cipher context is freed
|
// Set free callback to ensure cipher context is freed
|
||||||
memContextCallbackSet(this->memContext, regExpFreeResource, this);
|
memContextCallbackSet(objMemContext(this), regExpFreeResource, this);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(this);
|
FUNCTION_TEST_RETURN(this);
|
||||||
}
|
}
|
||||||
|
@ -41,16 +41,15 @@ bufNew(size_t size)
|
|||||||
|
|
||||||
Buffer *this = NULL;
|
Buffer *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("Buffer")
|
OBJ_NEW_BEGIN(Buffer)
|
||||||
{
|
{
|
||||||
// Create object
|
// Create object
|
||||||
this = memNew(sizeof(Buffer));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (Buffer)
|
*this = (Buffer)
|
||||||
{
|
{
|
||||||
.pub =
|
.pub =
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.sizeAlloc = size,
|
.sizeAlloc = size,
|
||||||
.size = size,
|
.size = size,
|
||||||
},
|
},
|
||||||
@ -60,7 +59,7 @@ bufNew(size_t size)
|
|||||||
if (size > 0)
|
if (size > 0)
|
||||||
this->pub.buffer = memNew(this->pub.sizeAlloc);
|
this->pub.buffer = memNew(this->pub.sizeAlloc);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(this);
|
FUNCTION_TEST_RETURN(this);
|
||||||
}
|
}
|
||||||
@ -245,7 +244,7 @@ bufResize(Buffer *this, size_t size)
|
|||||||
// When setting size down to 0 the buffer should always be allocated
|
// When setting size down to 0 the buffer should always be allocated
|
||||||
ASSERT(bufPtrConst(this) != NULL);
|
ASSERT(bufPtrConst(this) != NULL);
|
||||||
|
|
||||||
MEM_CONTEXT_BEGIN(this->pub.memContext)
|
MEM_CONTEXT_BEGIN(objMemContext(this))
|
||||||
{
|
{
|
||||||
memFree(bufPtr(this));
|
memFree(bufPtr(this));
|
||||||
}
|
}
|
||||||
@ -257,7 +256,7 @@ bufResize(Buffer *this, size_t size)
|
|||||||
// Else allocate or resize
|
// Else allocate or resize
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MEM_CONTEXT_BEGIN(this->pub.memContext)
|
MEM_CONTEXT_BEGIN(objMemContext(this))
|
||||||
{
|
{
|
||||||
if (bufPtrConst(this) == NULL)
|
if (bufPtrConst(this) == NULL)
|
||||||
this->pub.buffer = memNew(size);
|
this->pub.buffer = memNew(size);
|
||||||
|
@ -32,7 +32,6 @@ Getters/Setters
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct BufferPub
|
typedef struct BufferPub
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
size_t sizeAlloc; // Allocated size of the buffer
|
size_t sizeAlloc; // Allocated size of the buffer
|
||||||
size_t size; // Reported size of the buffer
|
size_t size; // Reported size of the buffer
|
||||||
bool sizeLimit; // Is the size limited to make the buffer appear smaller?
|
bool sizeLimit; // Is the size limited to make the buffer appear smaller?
|
||||||
|
@ -6,7 +6,6 @@ Key Value Handler
|
|||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/keyValue.h"
|
#include "common/type/keyValue.h"
|
||||||
#include "common/type/list.h"
|
#include "common/type/list.h"
|
||||||
#include "common/type/variantList.h"
|
#include "common/type/variantList.h"
|
||||||
@ -37,22 +36,21 @@ kvNew(void)
|
|||||||
|
|
||||||
KeyValue *this = NULL;
|
KeyValue *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("KeyValue")
|
OBJ_NEW_BEGIN(KeyValue)
|
||||||
{
|
{
|
||||||
// Allocate state and set context
|
// Allocate state and set context
|
||||||
this = memNew(sizeof(KeyValue));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (KeyValue)
|
*this = (KeyValue)
|
||||||
{
|
{
|
||||||
.pub =
|
.pub =
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.keyList = varLstNew(),
|
.keyList = varLstNew(),
|
||||||
},
|
},
|
||||||
.list = lstNewP(sizeof(KeyValuePair)),
|
.list = lstNewP(sizeof(KeyValuePair)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(this);
|
FUNCTION_TEST_RETURN(this);
|
||||||
}
|
}
|
||||||
@ -179,7 +177,7 @@ kvPut(KeyValue *this, const Variant *key, const Variant *value)
|
|||||||
ASSERT(this != NULL);
|
ASSERT(this != NULL);
|
||||||
ASSERT(key != NULL);
|
ASSERT(key != NULL);
|
||||||
|
|
||||||
MEM_CONTEXT_BEGIN(this->pub.memContext)
|
MEM_CONTEXT_BEGIN(objMemContext(this))
|
||||||
{
|
{
|
||||||
kvPutInternal(this, key, varDup(value));
|
kvPutInternal(this, key, varDup(value));
|
||||||
}
|
}
|
||||||
@ -201,7 +199,7 @@ kvAdd(KeyValue *this, const Variant *key, const Variant *value)
|
|||||||
ASSERT(this != NULL);
|
ASSERT(this != NULL);
|
||||||
ASSERT(key != NULL);
|
ASSERT(key != NULL);
|
||||||
|
|
||||||
MEM_CONTEXT_BEGIN(this->pub.memContext)
|
MEM_CONTEXT_BEGIN(objMemContext(this))
|
||||||
{
|
{
|
||||||
// Find the key
|
// Find the key
|
||||||
unsigned int listIdx = kvGetIdx(this, key);
|
unsigned int listIdx = kvGetIdx(this, key);
|
||||||
@ -248,7 +246,7 @@ kvPutKv(KeyValue *this, const Variant *key)
|
|||||||
|
|
||||||
KeyValue *result = NULL;
|
KeyValue *result = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_BEGIN(this->pub.memContext)
|
MEM_CONTEXT_BEGIN(objMemContext(this))
|
||||||
{
|
{
|
||||||
result = kvNew();
|
result = kvNew();
|
||||||
kvPutInternal(this, key, varNewKv(result));
|
kvPutInternal(this, key, varNewKv(result));
|
||||||
|
@ -28,7 +28,6 @@ Getters/Setters
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct KeyValuePub
|
typedef struct KeyValuePub
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
VariantList *keyList; // List of keys
|
VariantList *keyList; // List of keys
|
||||||
} KeyValuePub;
|
} KeyValuePub;
|
||||||
|
|
||||||
|
@ -36,23 +36,19 @@ lstNew(size_t itemSize, ListParam param)
|
|||||||
|
|
||||||
List *this = NULL;
|
List *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("List")
|
OBJ_NEW_BEGIN(List)
|
||||||
{
|
{
|
||||||
// Create object
|
// Create object
|
||||||
this = memNew(sizeof(List));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (List)
|
*this = (List)
|
||||||
{
|
{
|
||||||
.pub =
|
|
||||||
{
|
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
},
|
|
||||||
.itemSize = itemSize,
|
.itemSize = itemSize,
|
||||||
.sortOrder = param.sortOrder,
|
.sortOrder = param.sortOrder,
|
||||||
.comparator = param.comparator,
|
.comparator = param.comparator,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(this);
|
FUNCTION_TEST_RETURN(this);
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,6 @@ Getters/Setters
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct ListPub
|
typedef struct ListPub
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
unsigned int listSize; // List size
|
unsigned int listSize; // List size
|
||||||
} ListPub;
|
} ListPub;
|
||||||
|
|
||||||
@ -78,9 +77,9 @@ List *lstComparatorSet(List *this, ListComparator *comparator);
|
|||||||
|
|
||||||
// Memory context for this list
|
// Memory context for this list
|
||||||
__attribute__((always_inline)) static inline MemContext *
|
__attribute__((always_inline)) static inline MemContext *
|
||||||
lstMemContext(const List *const this)
|
lstMemContext(List *const this)
|
||||||
{
|
{
|
||||||
return THIS_PUB(List)->memContext;
|
return objMemContext(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// List size
|
// List size
|
||||||
|
@ -13,7 +13,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
struct MostCommonValue
|
struct MostCommonValue
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
List *list; // List of unique values
|
List *list; // List of unique values
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -31,17 +30,16 @@ mcvNew(void)
|
|||||||
|
|
||||||
MostCommonValue *this = NULL;
|
MostCommonValue *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("MostCommonValue")
|
OBJ_NEW_BEGIN(MostCommonValue)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(MostCommonValue));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (MostCommonValue)
|
*this = (MostCommonValue)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.list = lstNewP(sizeof(MostCommonValueEntry)),
|
.list = lstNewP(sizeof(MostCommonValueEntry)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(this);
|
FUNCTION_TEST_RETURN(this);
|
||||||
}
|
}
|
||||||
@ -75,7 +73,7 @@ mcvUpdate(MostCommonValue *this, const Variant *value)
|
|||||||
// Add the value if it doesn't
|
// Add the value if it doesn't
|
||||||
if (!found)
|
if (!found)
|
||||||
{
|
{
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(objMemContext(this))
|
||||||
{
|
{
|
||||||
MostCommonValueEntry entry = {.value = varDup(value), .total = 1};
|
MostCommonValueEntry entry = {.value = varDup(value), .total = 1};
|
||||||
lstAdd(this->list, &entry);
|
lstAdd(this->list, &entry);
|
||||||
|
@ -8,6 +8,16 @@ Object Helper Macros and Functions
|
|||||||
/**********************************************************************************************************************************/
|
/**********************************************************************************************************************************/
|
||||||
void *
|
void *
|
||||||
objMove(THIS_VOID, MemContext *parentNew)
|
objMove(THIS_VOID, MemContext *parentNew)
|
||||||
|
{
|
||||||
|
if (thisVoid != NULL)
|
||||||
|
memContextMove(memContextFromAllocExtra(thisVoid), parentNew);
|
||||||
|
|
||||||
|
return thisVoid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************************************************************************************************************/
|
||||||
|
void *
|
||||||
|
objMoveContext(THIS_VOID, MemContext *parentNew)
|
||||||
{
|
{
|
||||||
if (thisVoid != NULL)
|
if (thisVoid != NULL)
|
||||||
memContextMove(*(MemContext **)thisVoid, parentNew);
|
memContextMove(*(MemContext **)thisVoid, parentNew);
|
||||||
@ -18,6 +28,14 @@ objMove(THIS_VOID, MemContext *parentNew)
|
|||||||
/**********************************************************************************************************************************/
|
/**********************************************************************************************************************************/
|
||||||
void
|
void
|
||||||
objFree(THIS_VOID)
|
objFree(THIS_VOID)
|
||||||
|
{
|
||||||
|
if (thisVoid != NULL)
|
||||||
|
memContextFree(memContextFromAllocExtra(thisVoid));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************************************************************************************************************/
|
||||||
|
void
|
||||||
|
objFreeContext(THIS_VOID)
|
||||||
{
|
{
|
||||||
if (thisVoid != NULL)
|
if (thisVoid != NULL)
|
||||||
memContextFree(*(MemContext **)thisVoid);
|
memContextFree(*(MemContext **)thisVoid);
|
||||||
|
@ -7,8 +7,37 @@ These macros and functions implement common object functionality.
|
|||||||
#define COMMON_TYPE_OBJECT_H
|
#define COMMON_TYPE_OBJECT_H
|
||||||
|
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
|
#include "common/macro.h"
|
||||||
#include "common/memContext.h"
|
#include "common/memContext.h"
|
||||||
|
|
||||||
|
/***********************************************************************************************************************************
|
||||||
|
Create a new object
|
||||||
|
|
||||||
|
This is a thin wrapper on MEM_CONTEXT_NEW_*() to do object specific initialization. The general pattern
|
||||||
|
for a new object is:
|
||||||
|
|
||||||
|
MyObj *this = NULL;
|
||||||
|
|
||||||
|
OBJ_NEW_BEGIN(MyObj)
|
||||||
|
{
|
||||||
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
|
*this = (MyObj)
|
||||||
|
{
|
||||||
|
.data = ...
|
||||||
|
};
|
||||||
|
}
|
||||||
|
OBJ_NEW_END();
|
||||||
|
***********************************************************************************************************************************/
|
||||||
|
#define OBJ_NEW_BEGIN(type) \
|
||||||
|
MEM_CONTEXT_NEW_BEGIN(STRINGIFY(type), .allocExtra = sizeof(type))
|
||||||
|
|
||||||
|
#define OBJ_NEW_ALLOC() \
|
||||||
|
memContextAllocExtra(memContextCurrent())
|
||||||
|
|
||||||
|
#define OBJ_NEW_END() \
|
||||||
|
MEM_CONTEXT_NEW_END()
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Used in interface function parameter lists to discourage use of the untyped thisVoid parameter, e.g.:
|
Used in interface function parameter lists to discourage use of the untyped thisVoid parameter, e.g.:
|
||||||
|
|
||||||
@ -23,6 +52,12 @@ Create a local "this" variable of the correct type from a THIS_VOID parameter
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
#define THIS(type) type *this = thisVoid
|
#define THIS(type) type *this = thisVoid
|
||||||
|
|
||||||
|
/***********************************************************************************************************************************
|
||||||
|
Get the mem context of this object
|
||||||
|
***********************************************************************************************************************************/
|
||||||
|
#define THIS_MEM_CONTEXT() \
|
||||||
|
memContextFromAllocExtra(this)
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Cast this private struct, e.g. List, to the associated public struct, e.g. ListPub. Note that the public struct must be the first
|
Cast this private struct, e.g. List, to the associated public struct, e.g. ListPub. Note that the public struct must be the first
|
||||||
member of the private struct. For example:
|
member of the private struct. For example:
|
||||||
@ -55,10 +90,32 @@ storageFree(Storage *this)
|
|||||||
objFree(this);
|
objFree(this);
|
||||||
}
|
}
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
// Move an object to a new context if this != NULL. The mem context to move must be the first member of the object struct.
|
// Get the object mem context
|
||||||
|
__attribute__((always_inline)) static inline MemContext *
|
||||||
|
objMemContext(void *const this)
|
||||||
|
{
|
||||||
|
return memContextFromAllocExtra(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Is the object mem context currently being freed?
|
||||||
|
__attribute__((always_inline)) static inline bool
|
||||||
|
objMemContextFreeing(const void *const this)
|
||||||
|
{
|
||||||
|
return memContextFreeing(memContextConstFromAllocExtra(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move an object to a new context if this != NULL
|
||||||
void *objMove(THIS_VOID, MemContext *parentNew);
|
void *objMove(THIS_VOID, MemContext *parentNew);
|
||||||
|
|
||||||
// Free the object mem context if this != NULL. The mem context to be freed must be the first member of the object struct.
|
// Move an object to a new context if this != NULL. The mem context to move must be the first member of the object struct. This
|
||||||
|
// pattern is typically used by interfaces.
|
||||||
|
void *objMoveContext(THIS_VOID, MemContext *parentNew);
|
||||||
|
|
||||||
|
// Free the object mem context if this != NULL
|
||||||
void objFree(THIS_VOID);
|
void objFree(THIS_VOID);
|
||||||
|
|
||||||
|
// Free the object mem context if not NULL. The mem context to be freed must be the first member of the object struct. This pattern
|
||||||
|
// is typically used by interfaces.
|
||||||
|
void objFreeContext(THIS_VOID);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -229,7 +229,6 @@ typedef struct PackTagStack
|
|||||||
|
|
||||||
struct PackRead
|
struct PackRead
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
IoRead *read; // Read pack from
|
IoRead *read; // Read pack from
|
||||||
Buffer *buffer; // Buffer containing read data
|
Buffer *buffer; // Buffer containing read data
|
||||||
const uint8_t *bufferPtr; // Pointer to buffer
|
const uint8_t *bufferPtr; // Pointer to buffer
|
||||||
@ -246,7 +245,6 @@ struct PackRead
|
|||||||
|
|
||||||
struct PackWrite
|
struct PackWrite
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
IoWrite *write; // Write pack to
|
IoWrite *write; // Write pack to
|
||||||
Buffer *buffer; // Buffer to contain write data
|
Buffer *buffer; // Buffer to contain write data
|
||||||
|
|
||||||
@ -263,19 +261,18 @@ pckReadNewInternal(void)
|
|||||||
|
|
||||||
PackRead *this = NULL;
|
PackRead *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("PackRead")
|
OBJ_NEW_BEGIN(PackRead)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(PackRead));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (PackRead)
|
*this = (PackRead)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.tagStack = lstNewP(sizeof(PackTagStack)),
|
.tagStack = lstNewP(sizeof(PackTagStack)),
|
||||||
};
|
};
|
||||||
|
|
||||||
this->tagStackTop = lstAdd(this->tagStack, &(PackTagStack){.typeMap = pckTypeMapObj});
|
this->tagStackTop = lstAdd(this->tagStack, &(PackTagStack){.typeMap = pckTypeMapObj});
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(this);
|
FUNCTION_TEST_RETURN(this);
|
||||||
}
|
}
|
||||||
@ -291,7 +288,7 @@ pckReadNew(IoRead *read)
|
|||||||
|
|
||||||
PackRead *this = pckReadNewInternal();
|
PackRead *this = pckReadNewInternal();
|
||||||
|
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(objMemContext(this))
|
||||||
{
|
{
|
||||||
this->read = read;
|
this->read = read;
|
||||||
this->buffer = bufNew(ioBufferSize());
|
this->buffer = bufNew(ioBufferSize());
|
||||||
@ -887,7 +884,7 @@ pckReadPack(PackRead *this, PckReadPackParam param)
|
|||||||
PackRead *const result = pckReadNewBuf(buffer);
|
PackRead *const result = pckReadNewBuf(buffer);
|
||||||
|
|
||||||
if (result != NULL)
|
if (result != NULL)
|
||||||
bufMove(buffer, result->memContext);
|
bufMove(buffer, objMemContext(result));
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(result);
|
FUNCTION_TEST_RETURN(result);
|
||||||
}
|
}
|
||||||
@ -1121,19 +1118,18 @@ pckWriteNewInternal(void)
|
|||||||
|
|
||||||
PackWrite *this = NULL;
|
PackWrite *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("PackWrite")
|
OBJ_NEW_BEGIN(PackWrite)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(PackWrite));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (PackWrite)
|
*this = (PackWrite)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.tagStack = lstNewP(sizeof(PackTagStack)),
|
.tagStack = lstNewP(sizeof(PackTagStack)),
|
||||||
};
|
};
|
||||||
|
|
||||||
this->tagStackTop = lstAdd(this->tagStack, &(PackTagStack){.typeMap = pckTypeMapObj});
|
this->tagStackTop = lstAdd(this->tagStack, &(PackTagStack){.typeMap = pckTypeMapObj});
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(this);
|
FUNCTION_TEST_RETURN(this);
|
||||||
}
|
}
|
||||||
@ -1149,7 +1145,7 @@ pckWriteNew(IoWrite *write)
|
|||||||
|
|
||||||
PackWrite *this = pckWriteNewInternal();
|
PackWrite *this = pckWriteNewInternal();
|
||||||
|
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(objMemContext(this))
|
||||||
{
|
{
|
||||||
this->write = write;
|
this->write = write;
|
||||||
this->buffer = bufNew(ioBufferSize());
|
this->buffer = bufNew(ioBufferSize());
|
||||||
|
@ -332,26 +332,22 @@ xmlDocumentNew(const String *rootName)
|
|||||||
// Create object
|
// Create object
|
||||||
XmlDocument *this = NULL;
|
XmlDocument *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("XmlDocument")
|
OBJ_NEW_BEGIN(XmlDocument)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(XmlDocument));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (XmlDocument)
|
*this = (XmlDocument)
|
||||||
{
|
{
|
||||||
.pub =
|
|
||||||
{
|
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
},
|
|
||||||
.xml = xmlNewDoc(BAD_CAST "1.0"),
|
.xml = xmlNewDoc(BAD_CAST "1.0"),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Set callback to ensure xml document is freed
|
// Set callback to ensure xml document is freed
|
||||||
memContextCallbackSet(this->pub.memContext, xmlDocumentFreeResource, this);
|
memContextCallbackSet(objMemContext(this), xmlDocumentFreeResource, this);
|
||||||
|
|
||||||
this->pub.root = xmlNodeNew(xmlNewNode(NULL, BAD_CAST strZ(rootName)));
|
this->pub.root = xmlNodeNew(xmlNewNode(NULL, BAD_CAST strZ(rootName)));
|
||||||
xmlDocSetRootElement(this->xml, xmlDocumentRoot(this)->node);
|
xmlDocSetRootElement(this->xml, xmlDocumentRoot(this)->node);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(this);
|
FUNCTION_TEST_RETURN(this);
|
||||||
}
|
}
|
||||||
@ -372,28 +368,21 @@ xmlDocumentNewBuf(const Buffer *buffer)
|
|||||||
// Create object
|
// Create object
|
||||||
XmlDocument *this = NULL;
|
XmlDocument *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("XmlDocument")
|
OBJ_NEW_BEGIN(XmlDocument)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(XmlDocument));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
*this = (XmlDocument){{0}}; // Extra braces are required for older gcc versions
|
||||||
*this = (XmlDocument)
|
|
||||||
{
|
|
||||||
.pub =
|
|
||||||
{
|
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
if ((this->xml = xmlReadMemory((const char *)bufPtrConst(buffer), (int)bufUsed(buffer), "noname.xml", NULL, 0)) == NULL)
|
if ((this->xml = xmlReadMemory((const char *)bufPtrConst(buffer), (int)bufUsed(buffer), "noname.xml", NULL, 0)) == NULL)
|
||||||
THROW_FMT(FormatError, "invalid xml");
|
THROW_FMT(FormatError, "invalid xml");
|
||||||
|
|
||||||
// Set callback to ensure xml document is freed
|
// Set callback to ensure xml document is freed
|
||||||
memContextCallbackSet(this->pub.memContext, xmlDocumentFreeResource, this);
|
memContextCallbackSet(objMemContext(this), xmlDocumentFreeResource, this);
|
||||||
|
|
||||||
// Get the root node
|
// Get the root node
|
||||||
this->pub.root = xmlNodeNew(xmlDocGetRootElement(this->xml));
|
this->pub.root = xmlNodeNew(xmlDocGetRootElement(this->xml));
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(this);
|
FUNCTION_TEST_RETURN(this);
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,6 @@ Document Getters
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct XmlDocumentPub
|
typedef struct XmlDocumentPub
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
XmlNode *root; // Root node
|
XmlNode *root; // Root node
|
||||||
} XmlDocumentPub;
|
} XmlDocumentPub;
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ Wait Handler
|
|||||||
|
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/wait.h"
|
#include "common/wait.h"
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -33,16 +32,15 @@ waitNew(TimeMSec waitTime)
|
|||||||
// Allocate wait object
|
// Allocate wait object
|
||||||
Wait *this = NULL;
|
Wait *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("wait")
|
OBJ_NEW_BEGIN(Wait)
|
||||||
{
|
{
|
||||||
// Create object
|
// Create object
|
||||||
this = memNew(sizeof(Wait));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (Wait)
|
*this = (Wait)
|
||||||
{
|
{
|
||||||
.pub =
|
.pub =
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.remainTime = waitTime,
|
.remainTime = waitTime,
|
||||||
},
|
},
|
||||||
.waitTime = waitTime,
|
.waitTime = waitTime,
|
||||||
@ -58,7 +56,7 @@ waitNew(TimeMSec waitTime)
|
|||||||
// Get beginning time
|
// Get beginning time
|
||||||
this->beginTime = timeMSec();
|
this->beginTime = timeMSec();
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(WAIT, this);
|
FUNCTION_LOG_RETURN(WAIT, this);
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ Getters/Setters
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct WaitPub
|
typedef struct WaitPub
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
TimeMSec remainTime; // Wait time remaining (in usec)
|
TimeMSec remainTime; // Wait time remaining (in usec)
|
||||||
} WaitPub;
|
} WaitPub;
|
||||||
|
|
||||||
|
@ -1170,9 +1170,9 @@ configParse(const Storage *storage, unsigned int argListSize, const char *argLis
|
|||||||
// Create the config struct
|
// Create the config struct
|
||||||
Config *config;
|
Config *config;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("Config")
|
OBJ_NEW_BEGIN(Config)
|
||||||
{
|
{
|
||||||
config = memNew(sizeof(Config));
|
config = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*config = (Config)
|
*config = (Config)
|
||||||
{
|
{
|
||||||
@ -1181,7 +1181,7 @@ configParse(const Storage *storage, unsigned int argListSize, const char *argLis
|
|||||||
.exe = strNewZ(argList[0]),
|
.exe = strNewZ(argList[0]),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
// Phase 1: parse command line parameters
|
// Phase 1: parse command line parameters
|
||||||
// -------------------------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -5,7 +5,6 @@ Database Client
|
|||||||
|
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/json.h"
|
#include "common/type/json.h"
|
||||||
#include "common/wait.h"
|
#include "common/wait.h"
|
||||||
#include "db/db.h"
|
#include "db/db.h"
|
||||||
@ -69,9 +68,9 @@ dbNew(PgClient *client, ProtocolClient *remoteClient, const String *applicationN
|
|||||||
|
|
||||||
Db *this = NULL;
|
Db *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("Db")
|
OBJ_NEW_BEGIN(Db)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(Db));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (Db)
|
*this = (Db)
|
||||||
{
|
{
|
||||||
@ -85,7 +84,7 @@ dbNew(PgClient *client, ProtocolClient *remoteClient, const String *applicationN
|
|||||||
|
|
||||||
this->client = pgClientMove(client, this->pub.memContext);
|
this->client = pgClientMove(client, this->pub.memContext);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(DB, this);
|
FUNCTION_LOG_RETURN(DB, this);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ Info Handler
|
|||||||
#include "common/io/filter/filter.h"
|
#include "common/io/filter/filter.h"
|
||||||
#include "common/ini.h"
|
#include "common/ini.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/json.h"
|
#include "common/type/json.h"
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
#include "info/info.h"
|
#include "info/info.h"
|
||||||
@ -115,7 +114,7 @@ infoNewInternal(void)
|
|||||||
{
|
{
|
||||||
FUNCTION_TEST_VOID();
|
FUNCTION_TEST_VOID();
|
||||||
|
|
||||||
Info *this = memNew(sizeof(Info));
|
Info *this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (Info)
|
*this = (Info)
|
||||||
{
|
{
|
||||||
@ -135,7 +134,7 @@ infoNew(const String *cipherPass)
|
|||||||
|
|
||||||
Info *this = NULL;
|
Info *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("Info")
|
OBJ_NEW_BEGIN(Info)
|
||||||
{
|
{
|
||||||
this = infoNewInternal();
|
this = infoNewInternal();
|
||||||
|
|
||||||
@ -143,7 +142,7 @@ infoNew(const String *cipherPass)
|
|||||||
infoCipherPassSet(this, cipherPass);
|
infoCipherPassSet(this, cipherPass);
|
||||||
this->pub.backrestVersion = STRDEF(PROJECT_VERSION);
|
this->pub.backrestVersion = STRDEF(PROJECT_VERSION);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(INFO, this);
|
FUNCTION_LOG_RETURN(INFO, this);
|
||||||
}
|
}
|
||||||
@ -270,7 +269,7 @@ infoNewLoad(IoRead *read, InfoLoadNewCallback *callbackFunction, void *callbackD
|
|||||||
|
|
||||||
Info *this = NULL;
|
Info *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("Info")
|
OBJ_NEW_BEGIN(Info)
|
||||||
{
|
{
|
||||||
this = infoNewInternal();
|
this = infoNewInternal();
|
||||||
|
|
||||||
@ -314,7 +313,7 @@ infoNewLoad(IoRead *read, InfoLoadNewCallback *callbackFunction, void *callbackD
|
|||||||
}
|
}
|
||||||
MEM_CONTEXT_TEMP_END();
|
MEM_CONTEXT_TEMP_END();
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(INFO, this);
|
FUNCTION_LOG_RETURN(INFO, this);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ Archive Info Handler
|
|||||||
#include "common/ini.h"
|
#include "common/ini.h"
|
||||||
#include "common/io/bufferWrite.h"
|
#include "common/io/bufferWrite.h"
|
||||||
#include "common/io/io.h"
|
#include "common/io/io.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "info/infoArchive.h"
|
#include "info/infoArchive.h"
|
||||||
#include "info/infoPg.h"
|
#include "info/infoPg.h"
|
||||||
#include "postgres/interface.h"
|
#include "postgres/interface.h"
|
||||||
@ -43,7 +42,7 @@ infoArchiveNewInternal(void)
|
|||||||
{
|
{
|
||||||
FUNCTION_TEST_VOID();
|
FUNCTION_TEST_VOID();
|
||||||
|
|
||||||
InfoArchive *this = memNew(sizeof(InfoArchive));
|
InfoArchive *this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (InfoArchive)
|
*this = (InfoArchive)
|
||||||
{
|
{
|
||||||
@ -70,7 +69,7 @@ infoArchiveNew(unsigned int pgVersion, uint64_t pgSystemId, const String *cipher
|
|||||||
|
|
||||||
InfoArchive *this = NULL;
|
InfoArchive *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("InfoArchive")
|
OBJ_NEW_BEGIN(InfoArchive)
|
||||||
{
|
{
|
||||||
this = infoArchiveNewInternal();
|
this = infoArchiveNewInternal();
|
||||||
|
|
||||||
@ -78,7 +77,7 @@ infoArchiveNew(unsigned int pgVersion, uint64_t pgSystemId, const String *cipher
|
|||||||
this->pub.infoPg = infoPgNew(infoPgArchive, cipherPassSub);
|
this->pub.infoPg = infoPgNew(infoPgArchive, cipherPassSub);
|
||||||
infoArchivePgSet(this, pgVersion, pgSystemId);
|
infoArchivePgSet(this, pgVersion, pgSystemId);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(INFO_ARCHIVE, this);
|
FUNCTION_LOG_RETURN(INFO_ARCHIVE, this);
|
||||||
}
|
}
|
||||||
@ -95,12 +94,12 @@ infoArchiveNewLoad(IoRead *read)
|
|||||||
|
|
||||||
InfoArchive *this = NULL;
|
InfoArchive *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("InfoArchive")
|
OBJ_NEW_BEGIN(InfoArchive)
|
||||||
{
|
{
|
||||||
this = infoArchiveNewInternal();
|
this = infoArchiveNewInternal();
|
||||||
this->pub.infoPg = infoPgNewLoad(read, infoPgArchive, NULL, NULL);
|
this->pub.infoPg = infoPgNewLoad(read, infoPgArchive, NULL, NULL);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(INFO_ARCHIVE, this);
|
FUNCTION_LOG_RETURN(INFO_ARCHIVE, this);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ Backup Info Handler
|
|||||||
#include "common/io/bufferWrite.h"
|
#include "common/io/bufferWrite.h"
|
||||||
#include "common/io/io.h"
|
#include "common/io/io.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/regExp.h"
|
#include "common/regExp.h"
|
||||||
#include "common/type/json.h"
|
#include "common/type/json.h"
|
||||||
#include "common/type/list.h"
|
#include "common/type/list.h"
|
||||||
@ -71,7 +70,7 @@ infoBackupNewInternal(void)
|
|||||||
{
|
{
|
||||||
FUNCTION_TEST_VOID();
|
FUNCTION_TEST_VOID();
|
||||||
|
|
||||||
InfoBackup *this = memNew(sizeof(InfoBackup));
|
InfoBackup *this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (InfoBackup)
|
*this = (InfoBackup)
|
||||||
{
|
{
|
||||||
@ -100,7 +99,7 @@ infoBackupNew(unsigned int pgVersion, uint64_t pgSystemId, unsigned int pgCatalo
|
|||||||
|
|
||||||
InfoBackup *this = NULL;
|
InfoBackup *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("InfoBackup")
|
OBJ_NEW_BEGIN(InfoBackup)
|
||||||
{
|
{
|
||||||
this = infoBackupNewInternal();
|
this = infoBackupNewInternal();
|
||||||
|
|
||||||
@ -108,7 +107,7 @@ infoBackupNew(unsigned int pgVersion, uint64_t pgSystemId, unsigned int pgCatalo
|
|||||||
this->pub.infoPg = infoPgNew(infoPgBackup, cipherPassSub);
|
this->pub.infoPg = infoPgNew(infoPgBackup, cipherPassSub);
|
||||||
infoBackupPgSet(this, pgVersion, pgSystemId, pgCatalogVersion);
|
infoBackupPgSet(this, pgVersion, pgSystemId, pgCatalogVersion);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(INFO_BACKUP, this);
|
FUNCTION_LOG_RETURN(INFO_BACKUP, this);
|
||||||
}
|
}
|
||||||
@ -199,12 +198,12 @@ infoBackupNewLoad(IoRead *read)
|
|||||||
|
|
||||||
InfoBackup *this = NULL;
|
InfoBackup *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("InfoBackup")
|
OBJ_NEW_BEGIN(InfoBackup)
|
||||||
{
|
{
|
||||||
this = infoBackupNewInternal();
|
this = infoBackupNewInternal();
|
||||||
this->pub.infoPg = infoPgNewLoad(read, infoPgBackup, infoBackupLoadCallback, this);
|
this->pub.infoPg = infoPgNewLoad(read, infoPgBackup, infoBackupLoadCallback, this);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(INFO_BACKUP, this);
|
FUNCTION_LOG_RETURN(INFO_BACKUP, this);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ PostgreSQL Info Handler
|
|||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/ini.h"
|
#include "common/ini.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/json.h"
|
#include "common/type/json.h"
|
||||||
#include "common/type/list.h"
|
#include "common/type/list.h"
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
@ -57,7 +56,7 @@ infoPgNewInternal(InfoPgType type)
|
|||||||
FUNCTION_TEST_PARAM(STRING_ID, type);
|
FUNCTION_TEST_PARAM(STRING_ID, type);
|
||||||
FUNCTION_TEST_END();
|
FUNCTION_TEST_END();
|
||||||
|
|
||||||
InfoPg *this = memNew(sizeof(InfoPg));
|
InfoPg *this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (InfoPg)
|
*this = (InfoPg)
|
||||||
{
|
{
|
||||||
@ -83,12 +82,12 @@ infoPgNew(InfoPgType type, const String *cipherPassSub)
|
|||||||
|
|
||||||
InfoPg *this = NULL;
|
InfoPg *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("InfoPg")
|
OBJ_NEW_BEGIN(InfoPg)
|
||||||
{
|
{
|
||||||
this = infoPgNewInternal(type);
|
this = infoPgNewInternal(type);
|
||||||
this->pub.info = infoNew(cipherPassSub);
|
this->pub.info = infoNew(cipherPassSub);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(INFO_PG, this);
|
FUNCTION_LOG_RETURN(INFO_PG, this);
|
||||||
}
|
}
|
||||||
@ -169,7 +168,7 @@ infoPgNewLoad(IoRead *read, InfoPgType type, InfoLoadNewCallback *callbackFuncti
|
|||||||
|
|
||||||
InfoPg *this = NULL;
|
InfoPg *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("InfoPg")
|
OBJ_NEW_BEGIN(InfoPg)
|
||||||
{
|
{
|
||||||
this = infoPgNewInternal(type);
|
this = infoPgNewInternal(type);
|
||||||
|
|
||||||
@ -202,7 +201,7 @@ infoPgNewLoad(IoRead *read, InfoPgType type, InfoLoadNewCallback *callbackFuncti
|
|||||||
// If the current id did not match the history list then the file is corrupt
|
// If the current id did not match the history list then the file is corrupt
|
||||||
CHECK(this->historyCurrent != UINT_MAX);
|
CHECK(this->historyCurrent != UINT_MAX);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(INFO_PG, this);
|
FUNCTION_LOG_RETURN(INFO_PG, this);
|
||||||
}
|
}
|
||||||
|
@ -361,7 +361,7 @@ manifestNewInternal(void)
|
|||||||
{
|
{
|
||||||
FUNCTION_TEST_VOID();
|
FUNCTION_TEST_VOID();
|
||||||
|
|
||||||
Manifest *this = memNew(sizeof(Manifest));
|
Manifest *this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (Manifest)
|
*this = (Manifest)
|
||||||
{
|
{
|
||||||
@ -1065,7 +1065,7 @@ manifestNewBuild(
|
|||||||
|
|
||||||
Manifest *this = NULL;
|
Manifest *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("Manifest")
|
OBJ_NEW_BEGIN(Manifest)
|
||||||
{
|
{
|
||||||
this = manifestNewInternal();
|
this = manifestNewInternal();
|
||||||
this->pub.info = infoNew(NULL);
|
this->pub.info = infoNew(NULL);
|
||||||
@ -1251,7 +1251,7 @@ manifestNewBuild(
|
|||||||
}
|
}
|
||||||
MEM_CONTEXT_TEMP_END();
|
MEM_CONTEXT_TEMP_END();
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(MANIFEST, this);
|
FUNCTION_LOG_RETURN(MANIFEST, this);
|
||||||
}
|
}
|
||||||
@ -1942,14 +1942,14 @@ manifestNewLoad(IoRead *read)
|
|||||||
|
|
||||||
Manifest *this = NULL;
|
Manifest *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("Manifest")
|
OBJ_NEW_BEGIN(Manifest)
|
||||||
{
|
{
|
||||||
this = manifestNewInternal();
|
this = manifestNewInternal();
|
||||||
|
|
||||||
// Load the manifest
|
// Load the manifest
|
||||||
ManifestLoadData loadData =
|
ManifestLoadData loadData =
|
||||||
{
|
{
|
||||||
.memContext = memContextNew("load"),
|
.memContext = memContextNewP("load"),
|
||||||
.manifest = this,
|
.manifest = this,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2029,7 +2029,7 @@ manifestNewLoad(IoRead *read)
|
|||||||
// Discard the context holding temporary load data
|
// Discard the context holding temporary load data
|
||||||
memContextDiscard();
|
memContextDiscard();
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(MANIFEST, this);
|
FUNCTION_LOG_RETURN(MANIFEST, this);
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ Postgres Client
|
|||||||
|
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/list.h"
|
#include "common/type/list.h"
|
||||||
#include "common/wait.h"
|
#include "common/wait.h"
|
||||||
#include "postgres/client.h"
|
#include "postgres/client.h"
|
||||||
@ -17,7 +16,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
struct PgClient
|
struct PgClient
|
||||||
{
|
{
|
||||||
MemContext *memContext;
|
|
||||||
const String *host;
|
const String *host;
|
||||||
unsigned int port;
|
unsigned int port;
|
||||||
const String *database;
|
const String *database;
|
||||||
@ -63,13 +61,12 @@ pgClientNew(const String *host, const unsigned int port, const String *database,
|
|||||||
|
|
||||||
PgClient *this = NULL;
|
PgClient *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("PgClient")
|
OBJ_NEW_BEGIN(PgClient)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(PgClient));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (PgClient)
|
*this = (PgClient)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.host = strDup(host),
|
.host = strDup(host),
|
||||||
.port = port,
|
.port = port,
|
||||||
.database = strDup(database),
|
.database = strDup(database),
|
||||||
@ -77,7 +74,7 @@ pgClientNew(const String *host, const unsigned int port, const String *database,
|
|||||||
.queryTimeout = queryTimeout,
|
.queryTimeout = queryTimeout,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(PG_CLIENT, this);
|
FUNCTION_LOG_RETURN(PG_CLIENT, this);
|
||||||
}
|
}
|
||||||
@ -151,7 +148,7 @@ pgClientOpen(PgClient *this)
|
|||||||
this->connection = PQconnectdb(strZ(connInfo));
|
this->connection = PQconnectdb(strZ(connInfo));
|
||||||
|
|
||||||
// Set a callback to shutdown the connection
|
// Set a callback to shutdown the connection
|
||||||
memContextCallbackSet(this->memContext, pgClientFreeResource, this);
|
memContextCallbackSet(objMemContext(this), pgClientFreeResource, this);
|
||||||
|
|
||||||
// Handle errors
|
// Handle errors
|
||||||
if (PQstatus(this->connection) != CONNECTION_OK)
|
if (PQstatus(this->connection) != CONNECTION_OK)
|
||||||
@ -347,7 +344,7 @@ pgClientClose(PgClient *this)
|
|||||||
|
|
||||||
if (this->connection != NULL)
|
if (this->connection != NULL)
|
||||||
{
|
{
|
||||||
memContextCallbackClear(this->memContext);
|
memContextCallbackClear(objMemContext(this));
|
||||||
PQfinish(this->connection);
|
PQfinish(this->connection);
|
||||||
this->connection = NULL;
|
this->connection = NULL;
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ Protocol Client
|
|||||||
|
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/time.h"
|
#include "common/time.h"
|
||||||
#include "common/type/json.h"
|
#include "common/type/json.h"
|
||||||
#include "common/type/keyValue.h"
|
#include "common/type/keyValue.h"
|
||||||
@ -73,15 +72,14 @@ protocolClientNew(const String *name, const String *service, IoRead *read, IoWri
|
|||||||
|
|
||||||
ProtocolClient *this = NULL;
|
ProtocolClient *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("ProtocolClient")
|
OBJ_NEW_BEGIN(ProtocolClient)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(ProtocolClient));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (ProtocolClient)
|
*this = (ProtocolClient)
|
||||||
{
|
{
|
||||||
.pub =
|
.pub =
|
||||||
{
|
{
|
||||||
.memContext = memContextCurrent(),
|
|
||||||
.read = read,
|
.read = read,
|
||||||
},
|
},
|
||||||
.write = write,
|
.write = write,
|
||||||
@ -129,9 +127,9 @@ protocolClientNew(const String *name, const String *service, IoRead *read, IoWri
|
|||||||
MEM_CONTEXT_TEMP_END();
|
MEM_CONTEXT_TEMP_END();
|
||||||
|
|
||||||
// Set a callback to shutdown the protocol
|
// Set a callback to shutdown the protocol
|
||||||
memContextCallbackSet(this->pub.memContext, protocolClientFreeResource, this);
|
memContextCallbackSet(objMemContext(this), protocolClientFreeResource, this);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(PROTOCOL_CLIENT, this);
|
FUNCTION_LOG_RETURN(PROTOCOL_CLIENT, this);
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,6 @@ Getters/Setters
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct ProtocolClientPub
|
typedef struct ProtocolClientPub
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
IoRead *read; // Read interface
|
IoRead *read; // Read interface
|
||||||
} ProtocolClientPub;
|
} ProtocolClientPub;
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ Protocol Command
|
|||||||
|
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/keyValue.h"
|
#include "common/type/keyValue.h"
|
||||||
#include "protocol/command.h"
|
#include "protocol/command.h"
|
||||||
#include "protocol/client.h"
|
#include "protocol/client.h"
|
||||||
@ -15,7 +14,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
struct ProtocolCommand
|
struct ProtocolCommand
|
||||||
{
|
{
|
||||||
MemContext *memContext;
|
|
||||||
StringId command;
|
StringId command;
|
||||||
PackWrite *pack;
|
PackWrite *pack;
|
||||||
};
|
};
|
||||||
@ -32,17 +30,16 @@ protocolCommandNew(const StringId command)
|
|||||||
|
|
||||||
ProtocolCommand *this = NULL;
|
ProtocolCommand *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("ProtocolCommand")
|
OBJ_NEW_BEGIN(ProtocolCommand)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(ProtocolCommand));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (ProtocolCommand)
|
*this = (ProtocolCommand)
|
||||||
{
|
{
|
||||||
.memContext = memContextCurrent(),
|
|
||||||
.command = command,
|
.command = command,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_TEST_RETURN(this);
|
FUNCTION_TEST_RETURN(this);
|
||||||
}
|
}
|
||||||
@ -94,7 +91,7 @@ protocolCommandParam(ProtocolCommand *this)
|
|||||||
|
|
||||||
if (this->pack == NULL)
|
if (this->pack == NULL)
|
||||||
{
|
{
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(objMemContext(this))
|
||||||
{
|
{
|
||||||
this->pack = protocolPackNew();
|
this->pack = protocolPackNew();
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ Protocol Parallel Executor
|
|||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/macro.h"
|
#include "common/macro.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/keyValue.h"
|
#include "common/type/keyValue.h"
|
||||||
#include "common/type/list.h"
|
#include "common/type/list.h"
|
||||||
#include "protocol/command.h"
|
#include "protocol/command.h"
|
||||||
@ -21,7 +20,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
struct ProtocolParallel
|
struct ProtocolParallel
|
||||||
{
|
{
|
||||||
MemContext *memContext;
|
|
||||||
TimeMSec timeout; // Max time to wait for jobs before returning
|
TimeMSec timeout; // Max time to wait for jobs before returning
|
||||||
ParallelJobCallback *callbackFunction; // Function to get new jobs
|
ParallelJobCallback *callbackFunction; // Function to get new jobs
|
||||||
void *callbackData; // Data to pass to callback function
|
void *callbackData; // Data to pass to callback function
|
||||||
@ -49,13 +47,12 @@ protocolParallelNew(TimeMSec timeout, ParallelJobCallback *callbackFunction, voi
|
|||||||
|
|
||||||
ProtocolParallel *this = NULL;
|
ProtocolParallel *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("ProtocolParallel")
|
OBJ_NEW_BEGIN(ProtocolParallel)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(ProtocolParallel));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (ProtocolParallel)
|
*this = (ProtocolParallel)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.timeout = timeout,
|
.timeout = timeout,
|
||||||
.callbackFunction = callbackFunction,
|
.callbackFunction = callbackFunction,
|
||||||
.callbackData = callbackData,
|
.callbackData = callbackData,
|
||||||
@ -64,7 +61,7 @@ protocolParallelNew(TimeMSec timeout, ParallelJobCallback *callbackFunction, voi
|
|||||||
.state = protocolParallelJobStatePending,
|
.state = protocolParallelJobStatePending,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(PROTOCOL_PARALLEL, this);
|
FUNCTION_LOG_RETURN(PROTOCOL_PARALLEL, this);
|
||||||
}
|
}
|
||||||
@ -108,7 +105,7 @@ protocolParallelProcess(ProtocolParallel *this)
|
|||||||
// If called for the first time, initialize processing
|
// If called for the first time, initialize processing
|
||||||
if (this->state == protocolParallelJobStatePending)
|
if (this->state == protocolParallelJobStatePending)
|
||||||
{
|
{
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(objMemContext(this))
|
||||||
{
|
{
|
||||||
this->clientJobList = memNewPtrArray(lstSize(this->clientList));
|
this->clientJobList = memNewPtrArray(lstSize(this->clientList));
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ Protocol Parallel Job
|
|||||||
|
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "protocol/command.h"
|
#include "protocol/command.h"
|
||||||
#include "protocol/parallelJob.h"
|
#include "protocol/parallelJob.h"
|
||||||
|
|
||||||
@ -28,23 +27,22 @@ protocolParallelJobNew(const Variant *key, ProtocolCommand *command)
|
|||||||
|
|
||||||
ProtocolParallelJob *this = NULL;
|
ProtocolParallelJob *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("ProtocolParallelJob")
|
OBJ_NEW_BEGIN(ProtocolParallelJob)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(ProtocolParallelJob));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (ProtocolParallelJob)
|
*this = (ProtocolParallelJob)
|
||||||
{
|
{
|
||||||
.pub =
|
.pub =
|
||||||
{
|
{
|
||||||
.memContext = memContextCurrent(),
|
|
||||||
.state = protocolParallelJobStatePending,
|
.state = protocolParallelJobStatePending,
|
||||||
.key = varDup(key),
|
.key = varDup(key),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
this->pub.command = protocolCommandMove(command, this->pub.memContext);
|
this->pub.command = protocolCommandMove(command, objMemContext(this));
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(PROTOCOL_PARALLEL_JOB, this);
|
FUNCTION_LOG_RETURN(PROTOCOL_PARALLEL_JOB, this);
|
||||||
}
|
}
|
||||||
@ -63,7 +61,7 @@ protocolParallelJobErrorSet(ProtocolParallelJob *this, int code, const String *m
|
|||||||
ASSERT(code != 0);
|
ASSERT(code != 0);
|
||||||
ASSERT(message != NULL);
|
ASSERT(message != NULL);
|
||||||
|
|
||||||
MEM_CONTEXT_BEGIN(this->pub.memContext)
|
MEM_CONTEXT_BEGIN(objMemContext(this))
|
||||||
{
|
{
|
||||||
this->pub.code = code;
|
this->pub.code = code;
|
||||||
this->pub.message = strDup(message);
|
this->pub.message = strDup(message);
|
||||||
@ -102,7 +100,7 @@ protocolParallelJobResultSet(ProtocolParallelJob *const this, PackRead *const re
|
|||||||
ASSERT(this != NULL);
|
ASSERT(this != NULL);
|
||||||
ASSERT(protocolParallelJobErrorCode(this) == 0);
|
ASSERT(protocolParallelJobErrorCode(this) == 0);
|
||||||
|
|
||||||
this->pub.result = pckReadMove(result, this->pub.memContext);
|
this->pub.result = pckReadMove(result, objMemContext(this));
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN_VOID();
|
FUNCTION_LOG_RETURN_VOID();
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,6 @@ Getters/Setters
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct ProtocolParallelJobPub
|
typedef struct ProtocolParallelJobPub
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
const Variant *key; // Unique key used to identify the job
|
const Variant *key; // Unique key used to identify the job
|
||||||
ProtocolCommand *command; // Command to be executed
|
ProtocolCommand *command; // Command to be executed
|
||||||
unsigned int processId; // Process that executed this job
|
unsigned int processId; // Process that executed this job
|
||||||
|
@ -7,7 +7,6 @@ Protocol Server
|
|||||||
|
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/time.h"
|
#include "common/time.h"
|
||||||
#include "common/type/json.h"
|
#include "common/type/json.h"
|
||||||
#include "common/type/keyValue.h"
|
#include "common/type/keyValue.h"
|
||||||
@ -21,7 +20,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
struct ProtocolServer
|
struct ProtocolServer
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Mem context
|
|
||||||
IoRead *read; // Read interface
|
IoRead *read; // Read interface
|
||||||
IoWrite *write; // Write interface
|
IoWrite *write; // Write interface
|
||||||
const String *name; // Name displayed in logging
|
const String *name; // Name displayed in logging
|
||||||
@ -44,13 +42,12 @@ protocolServerNew(const String *name, const String *service, IoRead *read, IoWri
|
|||||||
|
|
||||||
ProtocolServer *this = NULL;
|
ProtocolServer *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("ProtocolServer")
|
OBJ_NEW_BEGIN(ProtocolServer)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(ProtocolServer));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (ProtocolServer)
|
*this = (ProtocolServer)
|
||||||
{
|
{
|
||||||
.memContext = memContextCurrent(),
|
|
||||||
.read = read,
|
.read = read,
|
||||||
.write = write,
|
.write = write,
|
||||||
.name = strDup(name),
|
.name = strDup(name),
|
||||||
@ -69,7 +66,7 @@ protocolServerNew(const String *name, const String *service, IoRead *read, IoWri
|
|||||||
}
|
}
|
||||||
MEM_CONTEXT_TEMP_END();
|
MEM_CONTEXT_TEMP_END();
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(PROTOCOL_SERVER, this);
|
FUNCTION_LOG_RETURN(PROTOCOL_SERVER, this);
|
||||||
}
|
}
|
||||||
@ -184,7 +181,7 @@ protocolServerProcess(
|
|||||||
{
|
{
|
||||||
// Send the command to the handler. Run the handler in the server's memory context in case any persistent data
|
// Send the command to the handler. Run the handler in the server's memory context in case any persistent data
|
||||||
// needs to be stored by the handler.
|
// needs to be stored by the handler.
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(objMemContext(this))
|
||||||
{
|
{
|
||||||
// Initialize retries in case of command failure
|
// Initialize retries in case of command failure
|
||||||
bool retry = false;
|
bool retry = false;
|
||||||
|
@ -6,7 +6,6 @@ Azure Storage Read
|
|||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/io/http/client.h"
|
#include "common/io/http/client.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
#include "storage/azure/read.h"
|
#include "storage/azure/read.h"
|
||||||
#include "storage/read.intern.h"
|
#include "storage/read.intern.h"
|
||||||
@ -16,7 +15,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct StorageReadAzure
|
typedef struct StorageReadAzure
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Object mem context
|
|
||||||
StorageReadInterface interface; // Interface
|
StorageReadInterface interface; // Interface
|
||||||
StorageAzure *storage; // Storage that created this object
|
StorageAzure *storage; // Storage that created this object
|
||||||
|
|
||||||
@ -49,7 +47,7 @@ storageReadAzureOpen(THIS_VOID)
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
// Request the file
|
// Request the file
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
|
||||||
{
|
{
|
||||||
this->httpResponse = storageAzureRequestP(
|
this->httpResponse = storageAzureRequestP(
|
||||||
this->storage, HTTP_VERB_GET_STR, .path = this->interface.name, .allowMissing = true, .contentIo = true);
|
this->storage, HTTP_VERB_GET_STR, .path = this->interface.name, .allowMissing = true, .contentIo = true);
|
||||||
@ -121,13 +119,12 @@ storageReadAzureNew(StorageAzure *storage, const String *name, bool ignoreMissin
|
|||||||
|
|
||||||
StorageRead *this = NULL;
|
StorageRead *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("StorageReadAzure")
|
OBJ_NEW_BEGIN(StorageReadAzure)
|
||||||
{
|
{
|
||||||
StorageReadAzure *driver = memNew(sizeof(StorageReadAzure));
|
StorageReadAzure *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (StorageReadAzure)
|
*driver = (StorageReadAzure)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.storage = storage,
|
.storage = storage,
|
||||||
|
|
||||||
.interface = (StorageReadInterface)
|
.interface = (StorageReadInterface)
|
||||||
@ -147,7 +144,7 @@ storageReadAzureNew(StorageAzure *storage, const String *name, bool ignoreMissin
|
|||||||
|
|
||||||
this = storageReadNew(driver, &driver->interface);
|
this = storageReadNew(driver, &driver->interface);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(STORAGE_READ, this);
|
FUNCTION_LOG_RETURN(STORAGE_READ, this);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ Azure Storage
|
|||||||
#include "common/io/socket/client.h"
|
#include "common/io/socket/client.h"
|
||||||
#include "common/io/tls/client.h"
|
#include "common/io/tls/client.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/regExp.h"
|
#include "common/regExp.h"
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
#include "common/type/xml.h"
|
#include "common/type/xml.h"
|
||||||
@ -58,7 +57,6 @@ Object type
|
|||||||
struct StorageAzure
|
struct StorageAzure
|
||||||
{
|
{
|
||||||
STORAGE_COMMON_MEMBER;
|
STORAGE_COMMON_MEMBER;
|
||||||
MemContext *memContext;
|
|
||||||
HttpClient *httpClient; // Http client to service requests
|
HttpClient *httpClient; // Http client to service requests
|
||||||
StringList *headerRedactList; // List of headers to redact from logging
|
StringList *headerRedactList; // List of headers to redact from logging
|
||||||
StringList *queryRedactList; // List of query keys to redact from logging
|
StringList *queryRedactList; // List of query keys to redact from logging
|
||||||
@ -714,13 +712,12 @@ storageAzureNew(
|
|||||||
|
|
||||||
Storage *this = NULL;
|
Storage *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("StorageAzure")
|
OBJ_NEW_BEGIN(StorageAzure)
|
||||||
{
|
{
|
||||||
StorageAzure *driver = memNew(sizeof(StorageAzure));
|
StorageAzure *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (StorageAzure)
|
*driver = (StorageAzure)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.interface = storageInterfaceAzure,
|
.interface = storageInterfaceAzure,
|
||||||
.container = strDup(container),
|
.container = strDup(container),
|
||||||
.account = strDup(account),
|
.account = strDup(account),
|
||||||
@ -753,7 +750,7 @@ storageAzureNew(
|
|||||||
|
|
||||||
this = storageNew(STORAGE_AZURE_TYPE, path, 0, 0, write, pathExpressionFunction, driver, driver->interface);
|
this = storageNew(STORAGE_AZURE_TYPE, path, 0, 0, write, pathExpressionFunction, driver, driver->interface);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(STORAGE, this);
|
FUNCTION_LOG_RETURN(STORAGE, this);
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ Azure Storage File Write
|
|||||||
|
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
#include "common/type/xml.h"
|
#include "common/type/xml.h"
|
||||||
#include "storage/azure/write.h"
|
#include "storage/azure/write.h"
|
||||||
@ -38,7 +37,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct StorageWriteAzure
|
typedef struct StorageWriteAzure
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Object mem context
|
|
||||||
StorageWriteInterface interface; // Interface
|
StorageWriteInterface interface; // Interface
|
||||||
StorageAzure *storage; // Storage that created this object
|
StorageAzure *storage; // Storage that created this object
|
||||||
|
|
||||||
@ -73,7 +71,7 @@ storageWriteAzureOpen(THIS_VOID)
|
|||||||
ASSERT(this->blockBuffer == NULL);
|
ASSERT(this->blockBuffer == NULL);
|
||||||
|
|
||||||
// Allocate the block buffer
|
// Allocate the block buffer
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
|
||||||
{
|
{
|
||||||
this->blockBuffer = bufNew(this->blockSize);
|
this->blockBuffer = bufNew(this->blockSize);
|
||||||
}
|
}
|
||||||
@ -125,7 +123,7 @@ storageWriteAzureBlockAsync(StorageWriteAzure *this)
|
|||||||
// Create the block id list
|
// Create the block id list
|
||||||
if (this->blockIdList == NULL)
|
if (this->blockIdList == NULL)
|
||||||
{
|
{
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
|
||||||
{
|
{
|
||||||
this->blockIdList = strLstNew();
|
this->blockIdList = strLstNew();
|
||||||
}
|
}
|
||||||
@ -143,7 +141,7 @@ storageWriteAzureBlockAsync(StorageWriteAzure *this)
|
|||||||
httpQueryAdd(query, AZURE_QUERY_COMP_STR, AZURE_QUERY_VALUE_BLOCK_STR);
|
httpQueryAdd(query, AZURE_QUERY_COMP_STR, AZURE_QUERY_VALUE_BLOCK_STR);
|
||||||
httpQueryAdd(query, AZURE_QUERY_BLOCK_ID_STR, blockId);
|
httpQueryAdd(query, AZURE_QUERY_BLOCK_ID_STR, blockId);
|
||||||
|
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
|
||||||
{
|
{
|
||||||
this->request = storageAzureRequestAsyncP(
|
this->request = storageAzureRequestAsyncP(
|
||||||
this->storage, HTTP_VERB_PUT_STR, .path = this->interface.name, .query = query, .content = this->blockBuffer);
|
this->storage, HTTP_VERB_PUT_STR, .path = this->interface.name, .query = query, .content = this->blockBuffer);
|
||||||
@ -276,13 +274,12 @@ storageWriteAzureNew(StorageAzure *storage, const String *name, uint64_t fileId,
|
|||||||
|
|
||||||
StorageWrite *this = NULL;
|
StorageWrite *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("StorageWriteAzure")
|
OBJ_NEW_BEGIN(StorageWriteAzure)
|
||||||
{
|
{
|
||||||
StorageWriteAzure *driver = memNew(sizeof(StorageWriteAzure));
|
StorageWriteAzure *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (StorageWriteAzure)
|
*driver = (StorageWriteAzure)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.storage = storage,
|
.storage = storage,
|
||||||
.fileId = fileId,
|
.fileId = fileId,
|
||||||
.blockSize = blockSize,
|
.blockSize = blockSize,
|
||||||
@ -307,7 +304,7 @@ storageWriteAzureNew(StorageAzure *storage, const String *name, uint64_t fileId,
|
|||||||
|
|
||||||
this = storageWriteNew(driver, &driver->interface);
|
this = storageWriteNew(driver, &driver->interface);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(STORAGE_WRITE, this);
|
FUNCTION_LOG_RETURN(STORAGE_WRITE, this);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ CIFS Storage
|
|||||||
|
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/regExp.h"
|
#include "common/regExp.h"
|
||||||
#include "storage/cifs/storage.h"
|
#include "storage/cifs/storage.h"
|
||||||
#include "storage/posix/storage.intern.h"
|
#include "storage/posix/storage.intern.h"
|
||||||
|
@ -7,7 +7,6 @@ GCS Storage Read
|
|||||||
#include "common/io/http/client.h"
|
#include "common/io/http/client.h"
|
||||||
#include "common/io/read.h"
|
#include "common/io/read.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
#include "storage/gcs/read.h"
|
#include "storage/gcs/read.h"
|
||||||
#include "storage/read.intern.h"
|
#include "storage/read.intern.h"
|
||||||
@ -22,7 +21,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct StorageReadGcs
|
typedef struct StorageReadGcs
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Object mem context
|
|
||||||
StorageReadInterface interface; // Interface
|
StorageReadInterface interface; // Interface
|
||||||
StorageGcs *storage; // Storage that created this object
|
StorageGcs *storage; // Storage that created this object
|
||||||
|
|
||||||
@ -55,7 +53,7 @@ storageReadGcsOpen(THIS_VOID)
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
// Request the file
|
// Request the file
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
|
||||||
{
|
{
|
||||||
this->httpResponse = storageGcsRequestP(
|
this->httpResponse = storageGcsRequestP(
|
||||||
this->storage, HTTP_VERB_GET_STR, .object = this->interface.name, .allowMissing = true, .contentIo = true,
|
this->storage, HTTP_VERB_GET_STR, .object = this->interface.name, .allowMissing = true, .contentIo = true,
|
||||||
@ -128,13 +126,12 @@ storageReadGcsNew(StorageGcs *storage, const String *name, bool ignoreMissing)
|
|||||||
|
|
||||||
StorageRead *this = NULL;
|
StorageRead *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("StorageReadGcs")
|
OBJ_NEW_BEGIN(StorageReadGcs)
|
||||||
{
|
{
|
||||||
StorageReadGcs *driver = memNew(sizeof(StorageReadGcs));
|
StorageReadGcs *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (StorageReadGcs)
|
*driver = (StorageReadGcs)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.storage = storage,
|
.storage = storage,
|
||||||
|
|
||||||
.interface = (StorageReadInterface)
|
.interface = (StorageReadInterface)
|
||||||
@ -154,7 +151,7 @@ storageReadGcsNew(StorageGcs *storage, const String *name, bool ignoreMissing)
|
|||||||
|
|
||||||
this = storageReadNew(driver, &driver->interface);
|
this = storageReadNew(driver, &driver->interface);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(STORAGE_READ, this);
|
FUNCTION_LOG_RETURN(STORAGE_READ, this);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ GCS Storage
|
|||||||
#include "common/io/socket/client.h"
|
#include "common/io/socket/client.h"
|
||||||
#include "common/io/tls/client.h"
|
#include "common/io/tls/client.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/regExp.h"
|
#include "common/regExp.h"
|
||||||
#include "common/type/json.h"
|
#include "common/type/json.h"
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
@ -81,7 +80,6 @@ Object type
|
|||||||
struct StorageGcs
|
struct StorageGcs
|
||||||
{
|
{
|
||||||
STORAGE_COMMON_MEMBER;
|
STORAGE_COMMON_MEMBER;
|
||||||
MemContext *memContext;
|
|
||||||
HttpClient *httpClient; // Http client to service requests
|
HttpClient *httpClient; // Http client to service requests
|
||||||
StringList *headerRedactList; // List of headers to redact from logging
|
StringList *headerRedactList; // List of headers to redact from logging
|
||||||
StringList *queryRedactList; // List of query keys to redact from logging
|
StringList *queryRedactList; // List of query keys to redact from logging
|
||||||
@ -336,7 +334,7 @@ storageGcsAuth(StorageGcs *this, HttpHeader *httpHeader)
|
|||||||
StorageGcsAuthTokenResult tokenResult = this->keyType == storageGcsKeyTypeAuto ?
|
StorageGcsAuthTokenResult tokenResult = this->keyType == storageGcsKeyTypeAuto ?
|
||||||
storageGcsAuthAuto(this, timeBegin) : storageGcsAuthService(this, timeBegin);
|
storageGcsAuthAuto(this, timeBegin) : storageGcsAuthService(this, timeBegin);
|
||||||
|
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
|
||||||
{
|
{
|
||||||
strFree(this->token);
|
strFree(this->token);
|
||||||
this->token = strNewFmt("%s %s", strZ(tokenResult.tokenType), strZ(tokenResult.token));
|
this->token = strNewFmt("%s %s", strZ(tokenResult.tokenType), strZ(tokenResult.token));
|
||||||
@ -934,13 +932,12 @@ storageGcsNew(
|
|||||||
|
|
||||||
Storage *this = NULL;
|
Storage *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("StorageGcs")
|
OBJ_NEW_BEGIN(StorageGcs)
|
||||||
{
|
{
|
||||||
StorageGcs *driver = memNew(sizeof(StorageGcs));
|
StorageGcs *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (StorageGcs)
|
*driver = (StorageGcs)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.interface = storageInterfaceGcs,
|
.interface = storageInterfaceGcs,
|
||||||
.write = write,
|
.write = write,
|
||||||
.bucket = strDup(bucket),
|
.bucket = strDup(bucket),
|
||||||
@ -1007,7 +1004,7 @@ storageGcsNew(
|
|||||||
|
|
||||||
this = storageNew(STORAGE_GCS_TYPE, path, 0, 0, write, pathExpressionFunction, driver, driver->interface);
|
this = storageNew(STORAGE_GCS_TYPE, path, 0, 0, write, pathExpressionFunction, driver, driver->interface);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(STORAGE, this);
|
FUNCTION_LOG_RETURN(STORAGE, this);
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ GCS Storage File Write
|
|||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/io/filter/filter.h"
|
#include "common/io/filter/filter.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/json.h"
|
#include "common/type/json.h"
|
||||||
#include "common/type/keyValue.h"
|
#include "common/type/keyValue.h"
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
@ -26,7 +25,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct StorageWriteGcs
|
typedef struct StorageWriteGcs
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Object mem context
|
|
||||||
StorageWriteInterface interface; // Interface
|
StorageWriteInterface interface; // Interface
|
||||||
StorageGcs *storage; // Storage that created this object
|
StorageGcs *storage; // Storage that created this object
|
||||||
|
|
||||||
@ -62,7 +60,7 @@ storageWriteGcsOpen(THIS_VOID)
|
|||||||
ASSERT(this->chunkBuffer == NULL);
|
ASSERT(this->chunkBuffer == NULL);
|
||||||
|
|
||||||
// Allocate the chunk buffer
|
// Allocate the chunk buffer
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
|
||||||
{
|
{
|
||||||
this->chunkBuffer = bufNew(this->chunkSize);
|
this->chunkBuffer = bufNew(this->chunkSize);
|
||||||
this->md5hash = cryptoHashNew(HASH_TYPE_MD5_STR);
|
this->md5hash = cryptoHashNew(HASH_TYPE_MD5_STR);
|
||||||
@ -174,7 +172,7 @@ storageWriteGcsBlockAsync(StorageWriteGcs *this, bool done)
|
|||||||
{
|
{
|
||||||
HttpResponse *response = storageGcsRequestP(this->storage, HTTP_VERB_POST_STR, .upload = true, .query = query);
|
HttpResponse *response = storageGcsRequestP(this->storage, HTTP_VERB_POST_STR, .upload = true, .query = query);
|
||||||
|
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
|
||||||
{
|
{
|
||||||
this->uploadId = strDup(httpHeaderGet(httpResponseHeader(response), GCS_HEADER_UPLOAD_ID_STR));
|
this->uploadId = strDup(httpHeaderGet(httpResponseHeader(response), GCS_HEADER_UPLOAD_ID_STR));
|
||||||
CHECK(this->uploadId != NULL);
|
CHECK(this->uploadId != NULL);
|
||||||
@ -200,7 +198,7 @@ storageWriteGcsBlockAsync(StorageWriteGcs *this, bool done)
|
|||||||
if (done)
|
if (done)
|
||||||
httpQueryAdd(query, GCS_QUERY_FIELDS_STR, GCS_QUERY_FIELDS_VALUE_STR);
|
httpQueryAdd(query, GCS_QUERY_FIELDS_STR, GCS_QUERY_FIELDS_VALUE_STR);
|
||||||
|
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
|
||||||
{
|
{
|
||||||
this->request = storageGcsRequestAsyncP(
|
this->request = storageGcsRequestAsyncP(
|
||||||
this->storage, HTTP_VERB_PUT_STR, .upload = true, .noAuth = true, .header = header, .query = query,
|
this->storage, HTTP_VERB_PUT_STR, .upload = true, .noAuth = true, .header = header, .query = query,
|
||||||
@ -330,13 +328,12 @@ storageWriteGcsNew(StorageGcs *storage, const String *name, size_t chunkSize)
|
|||||||
|
|
||||||
StorageWrite *this = NULL;
|
StorageWrite *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("StorageWriteGcs")
|
OBJ_NEW_BEGIN(StorageWriteGcs)
|
||||||
{
|
{
|
||||||
StorageWriteGcs *driver = memNew(sizeof(StorageWriteGcs));
|
StorageWriteGcs *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (StorageWriteGcs)
|
*driver = (StorageWriteGcs)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.storage = storage,
|
.storage = storage,
|
||||||
.chunkSize = chunkSize,
|
.chunkSize = chunkSize,
|
||||||
|
|
||||||
@ -360,7 +357,7 @@ storageWriteGcsNew(StorageGcs *storage, const String *name, size_t chunkSize)
|
|||||||
|
|
||||||
this = storageWriteNew(driver, &driver->interface);
|
this = storageWriteNew(driver, &driver->interface);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(STORAGE_WRITE, this);
|
FUNCTION_LOG_RETURN(STORAGE_WRITE, this);
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ Posix Storage Read
|
|||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/io/read.h"
|
#include "common/io/read.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
#include "storage/posix/read.h"
|
#include "storage/posix/read.h"
|
||||||
#include "storage/posix/storage.intern.h"
|
#include "storage/posix/storage.intern.h"
|
||||||
@ -20,7 +19,6 @@ Object types
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct StorageReadPosix
|
typedef struct StorageReadPosix
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Object mem context
|
|
||||||
StorageReadInterface interface; // Interface
|
StorageReadInterface interface; // Interface
|
||||||
StoragePosix *storage; // Storage that created this object
|
StoragePosix *storage; // Storage that created this object
|
||||||
|
|
||||||
@ -93,7 +91,7 @@ storageReadPosixOpen(THIS_VOID)
|
|||||||
// On success set free callback to ensure the file descriptor is freed
|
// On success set free callback to ensure the file descriptor is freed
|
||||||
if (this->fd != -1)
|
if (this->fd != -1)
|
||||||
{
|
{
|
||||||
memContextCallbackSet(this->memContext, storageReadPosixFreeResource, this);
|
memContextCallbackSet(THIS_MEM_CONTEXT(), storageReadPosixFreeResource, this);
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +160,7 @@ storageReadPosixClose(THIS_VOID)
|
|||||||
|
|
||||||
ASSERT(this != NULL);
|
ASSERT(this != NULL);
|
||||||
|
|
||||||
memContextCallbackClear(this->memContext);
|
memContextCallbackClear(THIS_MEM_CONTEXT());
|
||||||
storageReadPosixFreeResource(this);
|
storageReadPosixFreeResource(this);
|
||||||
this->fd = -1;
|
this->fd = -1;
|
||||||
|
|
||||||
@ -217,13 +215,12 @@ storageReadPosixNew(StoragePosix *storage, const String *name, bool ignoreMissin
|
|||||||
|
|
||||||
StorageRead *this = NULL;
|
StorageRead *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("StorageReadPosix")
|
OBJ_NEW_BEGIN(StorageReadPosix)
|
||||||
{
|
{
|
||||||
StorageReadPosix *driver = memNew(sizeof(StorageReadPosix));
|
StorageReadPosix *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (StorageReadPosix)
|
*driver = (StorageReadPosix)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.storage = storage,
|
.storage = storage,
|
||||||
.fd = -1,
|
.fd = -1,
|
||||||
|
|
||||||
@ -252,7 +249,7 @@ storageReadPosixNew(StoragePosix *storage, const String *name, bool ignoreMissin
|
|||||||
|
|
||||||
this = storageReadNew(driver, &driver->interface);
|
this = storageReadNew(driver, &driver->interface);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(STORAGE_READ, this);
|
FUNCTION_LOG_RETURN(STORAGE_READ, this);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ Posix Storage
|
|||||||
|
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/regExp.h"
|
#include "common/regExp.h"
|
||||||
#include "common/user.h"
|
#include "common/user.h"
|
||||||
#include "storage/posix/read.h"
|
#include "storage/posix/read.h"
|
||||||
@ -34,7 +33,6 @@ Object type
|
|||||||
struct StoragePosix
|
struct StoragePosix
|
||||||
{
|
{
|
||||||
STORAGE_COMMON_MEMBER;
|
STORAGE_COMMON_MEMBER;
|
||||||
MemContext *memContext; // Object memory context
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**********************************************************************************************************************************/
|
/**********************************************************************************************************************************/
|
||||||
@ -586,13 +584,12 @@ storagePosixNewInternal(
|
|||||||
// Create the object
|
// Create the object
|
||||||
Storage *this = NULL;
|
Storage *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("StoragePosix")
|
OBJ_NEW_BEGIN(StoragePosix)
|
||||||
{
|
{
|
||||||
StoragePosix *driver = memNew(sizeof(StoragePosix));
|
StoragePosix *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (StoragePosix)
|
*driver = (StoragePosix)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.interface = storageInterfacePosix,
|
.interface = storageInterfacePosix,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -608,7 +605,7 @@ storagePosixNewInternal(
|
|||||||
|
|
||||||
this = storageNew(type, path, modeFile, modePath, write, pathExpressionFunction, driver, driver->interface);
|
this = storageNew(type, path, modeFile, modePath, write, pathExpressionFunction, driver, driver->interface);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(STORAGE, this);
|
FUNCTION_LOG_RETURN(STORAGE, this);
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ Posix Storage File write
|
|||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/io/write.h"
|
#include "common/io/write.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
#include "common/user.h"
|
#include "common/user.h"
|
||||||
#include "storage/posix/storage.intern.h"
|
#include "storage/posix/storage.intern.h"
|
||||||
@ -23,7 +22,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct StorageWritePosix
|
typedef struct StorageWritePosix
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Object mem context
|
|
||||||
StorageWriteInterface interface; // Interface
|
StorageWriteInterface interface; // Interface
|
||||||
StoragePosix *storage; // Storage that created this object
|
StoragePosix *storage; // Storage that created this object
|
||||||
|
|
||||||
@ -105,7 +103,7 @@ storageWritePosixOpen(THIS_VOID)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set free callback to ensure the file descriptor is freed
|
// Set free callback to ensure the file descriptor is freed
|
||||||
memContextCallbackSet(this->memContext, storageWritePosixFreeResource, this);
|
memContextCallbackSet(THIS_MEM_CONTEXT(), storageWritePosixFreeResource, this);
|
||||||
|
|
||||||
// Update user/group owner
|
// Update user/group owner
|
||||||
if (this->interface.user != NULL || this->interface.group != NULL)
|
if (this->interface.user != NULL || this->interface.group != NULL)
|
||||||
@ -174,7 +172,7 @@ storageWritePosixClose(THIS_VOID)
|
|||||||
THROW_ON_SYS_ERROR_FMT(fsync(this->fd) == -1, FileSyncError, STORAGE_ERROR_WRITE_SYNC, strZ(this->nameTmp));
|
THROW_ON_SYS_ERROR_FMT(fsync(this->fd) == -1, FileSyncError, STORAGE_ERROR_WRITE_SYNC, strZ(this->nameTmp));
|
||||||
|
|
||||||
// Close the file
|
// Close the file
|
||||||
memContextCallbackClear(this->memContext);
|
memContextCallbackClear(THIS_MEM_CONTEXT());
|
||||||
THROW_ON_SYS_ERROR_FMT(close(this->fd) == -1, FileCloseError, STORAGE_ERROR_WRITE_CLOSE, strZ(this->nameTmp));
|
THROW_ON_SYS_ERROR_FMT(close(this->fd) == -1, FileCloseError, STORAGE_ERROR_WRITE_CLOSE, strZ(this->nameTmp));
|
||||||
this->fd = -1;
|
this->fd = -1;
|
||||||
|
|
||||||
@ -247,13 +245,12 @@ storageWritePosixNew(
|
|||||||
|
|
||||||
StorageWrite *this = NULL;
|
StorageWrite *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("StorageWritePosix")
|
OBJ_NEW_BEGIN(StorageWritePosix)
|
||||||
{
|
{
|
||||||
StorageWritePosix *driver = memNew(sizeof(StorageWritePosix));
|
StorageWritePosix *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (StorageWritePosix)
|
*driver = (StorageWritePosix)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.storage = storage,
|
.storage = storage,
|
||||||
.path = strPath(name),
|
.path = strPath(name),
|
||||||
.fd = -1,
|
.fd = -1,
|
||||||
@ -287,7 +284,7 @@ storageWritePosixNew(
|
|||||||
|
|
||||||
this = storageWriteNew(driver, &driver->interface);
|
this = storageWriteNew(driver, &driver->interface);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(STORAGE_WRITE, this);
|
FUNCTION_LOG_RETURN(STORAGE_WRITE, this);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ Functions
|
|||||||
__attribute__((always_inline)) static inline StorageRead *
|
__attribute__((always_inline)) static inline StorageRead *
|
||||||
storageReadMove(StorageRead *const this, MemContext *const parentNew)
|
storageReadMove(StorageRead *const this, MemContext *const parentNew)
|
||||||
{
|
{
|
||||||
return objMove(this, parentNew);
|
return objMoveContext(this, parentNew);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
@ -74,7 +74,7 @@ Destructor
|
|||||||
__attribute__((always_inline)) static inline void
|
__attribute__((always_inline)) static inline void
|
||||||
storageReadFree(StorageRead *const this)
|
storageReadFree(StorageRead *const this)
|
||||||
{
|
{
|
||||||
objFree(this);
|
objFreeContext(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
|
@ -12,7 +12,6 @@ Remote Storage Protocol Handler
|
|||||||
#include "common/io/filter/size.h"
|
#include "common/io/filter/size.h"
|
||||||
#include "common/io/io.h"
|
#include "common/io/io.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/regExp.h"
|
#include "common/regExp.h"
|
||||||
#include "common/type/pack.h"
|
#include "common/type/pack.h"
|
||||||
#include "common/type/json.h"
|
#include "common/type/json.h"
|
||||||
|
@ -10,7 +10,6 @@ Remote Storage Read
|
|||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/io/read.h"
|
#include "common/io/read.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/convert.h"
|
#include "common/type/convert.h"
|
||||||
#include "common/type/json.h"
|
#include "common/type/json.h"
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
@ -23,7 +22,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct StorageReadRemote
|
typedef struct StorageReadRemote
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Object mem context
|
|
||||||
StorageReadInterface interface; // Interface
|
StorageReadInterface interface; // Interface
|
||||||
StorageRemote *storage; // Storage that created this object
|
StorageRemote *storage; // Storage that created this object
|
||||||
StorageRead *read; // Storage read interface
|
StorageRead *read; // Storage read interface
|
||||||
@ -137,7 +135,7 @@ storageReadRemote(THIS_VOID, Buffer *buffer, bool block)
|
|||||||
// If binary then read the next block
|
// If binary then read the next block
|
||||||
if (pckReadType(read) == pckTypeBin)
|
if (pckReadType(read) == pckTypeBin)
|
||||||
{
|
{
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
|
||||||
{
|
{
|
||||||
this->block = pckReadBinP(read);
|
this->block = pckReadBinP(read);
|
||||||
this->remaining = bufUsed(this->block);
|
this->remaining = bufUsed(this->block);
|
||||||
@ -228,13 +226,12 @@ storageReadRemoteNew(
|
|||||||
|
|
||||||
StorageReadRemote *this = NULL;
|
StorageReadRemote *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("StorageReadRemote")
|
OBJ_NEW_BEGIN(StorageReadRemote)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(StorageReadRemote));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (StorageReadRemote)
|
*this = (StorageReadRemote)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.storage = storage,
|
.storage = storage,
|
||||||
.client = client,
|
.client = client,
|
||||||
|
|
||||||
@ -258,7 +255,7 @@ storageReadRemoteNew(
|
|||||||
|
|
||||||
this->read = storageReadNew(this, &this->interface);
|
this->read = storageReadNew(this, &this->interface);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
ASSERT(this != NULL);
|
ASSERT(this != NULL);
|
||||||
FUNCTION_LOG_RETURN(STORAGE_READ, this->read);
|
FUNCTION_LOG_RETURN(STORAGE_READ, this->read);
|
||||||
|
@ -20,7 +20,6 @@ Object type
|
|||||||
struct StorageRemote
|
struct StorageRemote
|
||||||
{
|
{
|
||||||
STORAGE_COMMON_MEMBER;
|
STORAGE_COMMON_MEMBER;
|
||||||
MemContext *memContext;
|
|
||||||
ProtocolClient *client; // Protocol client
|
ProtocolClient *client; // Protocol client
|
||||||
unsigned int compressLevel; // Protocol compression level
|
unsigned int compressLevel; // Protocol compression level
|
||||||
};
|
};
|
||||||
@ -452,13 +451,12 @@ storageRemoteNew(
|
|||||||
|
|
||||||
Storage *this = NULL;
|
Storage *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("StorageRemote")
|
OBJ_NEW_BEGIN(StorageRemote)
|
||||||
{
|
{
|
||||||
StorageRemote *driver = memNew(sizeof(StorageRemote));
|
StorageRemote *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (StorageRemote)
|
*driver = (StorageRemote)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.client = client,
|
.client = client,
|
||||||
.compressLevel = compressLevel,
|
.compressLevel = compressLevel,
|
||||||
.interface = storageInterfaceRemote,
|
.interface = storageInterfaceRemote,
|
||||||
@ -485,7 +483,7 @@ storageRemoteNew(
|
|||||||
|
|
||||||
this = storageNew(STORAGE_REMOTE_TYPE, path, modeFile, modePath, write, pathExpressionFunction, driver, driver->interface);
|
this = storageNew(STORAGE_REMOTE_TYPE, path, modeFile, modePath, write, pathExpressionFunction, driver, driver->interface);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(STORAGE, this);
|
FUNCTION_LOG_RETURN(STORAGE, this);
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ Remote Storage File write
|
|||||||
#include "common/io/io.h"
|
#include "common/io/io.h"
|
||||||
#include "common/io/write.h"
|
#include "common/io/write.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/json.h"
|
#include "common/type/json.h"
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
#include "storage/remote/protocol.h"
|
#include "storage/remote/protocol.h"
|
||||||
@ -20,7 +19,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct StorageWriteRemote
|
typedef struct StorageWriteRemote
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Object mem context
|
|
||||||
StorageWriteInterface interface; // Interface
|
StorageWriteInterface interface; // Interface
|
||||||
StorageRemote *storage; // Storage that created this object
|
StorageRemote *storage; // Storage that created this object
|
||||||
StorageWrite *write; // Storage write interface
|
StorageWrite *write; // Storage write interface
|
||||||
@ -110,7 +108,7 @@ storageWriteRemoteOpen(THIS_VOID)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set free callback to ensure remote file is freed
|
// Set free callback to ensure remote file is freed
|
||||||
memContextCallbackSet(this->memContext, storageWriteRemoteFreeResource, this);
|
memContextCallbackSet(THIS_MEM_CONTEXT(), storageWriteRemoteFreeResource, this);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_TEMP_END();
|
MEM_CONTEXT_TEMP_END();
|
||||||
|
|
||||||
@ -174,7 +172,7 @@ storageWriteRemoteClose(THIS_VOID)
|
|||||||
MEM_CONTEXT_TEMP_END();
|
MEM_CONTEXT_TEMP_END();
|
||||||
|
|
||||||
this->client = NULL;
|
this->client = NULL;
|
||||||
memContextCallbackClear(this->memContext);
|
memContextCallbackClear(THIS_MEM_CONTEXT());
|
||||||
}
|
}
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN_VOID();
|
FUNCTION_LOG_RETURN_VOID();
|
||||||
@ -211,13 +209,12 @@ storageWriteRemoteNew(
|
|||||||
|
|
||||||
StorageWriteRemote *this = NULL;
|
StorageWriteRemote *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("StorageWriteRemote")
|
OBJ_NEW_BEGIN(StorageWriteRemote)
|
||||||
{
|
{
|
||||||
this = memNew(sizeof(StorageWriteRemote));
|
this = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*this = (StorageWriteRemote)
|
*this = (StorageWriteRemote)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.storage = storage,
|
.storage = storage,
|
||||||
.client = client,
|
.client = client,
|
||||||
|
|
||||||
@ -248,7 +245,7 @@ storageWriteRemoteNew(
|
|||||||
|
|
||||||
this->write = storageWriteNew(this, &this->interface);
|
this->write = storageWriteNew(this, &this->interface);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
ASSERT(this != NULL);
|
ASSERT(this != NULL);
|
||||||
FUNCTION_LOG_RETURN(STORAGE_WRITE, this->write);
|
FUNCTION_LOG_RETURN(STORAGE_WRITE, this->write);
|
||||||
|
@ -6,7 +6,6 @@ S3 Storage Read
|
|||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/io/http/client.h"
|
#include "common/io/http/client.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
#include "storage/s3/read.h"
|
#include "storage/s3/read.h"
|
||||||
#include "storage/read.intern.h"
|
#include "storage/read.intern.h"
|
||||||
@ -19,7 +18,6 @@ Object type
|
|||||||
|
|
||||||
typedef struct StorageReadS3
|
typedef struct StorageReadS3
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Object mem context
|
|
||||||
StorageReadInterface interface; // Interface
|
StorageReadInterface interface; // Interface
|
||||||
StorageS3 *storage; // Storage that created this object
|
StorageS3 *storage; // Storage that created this object
|
||||||
|
|
||||||
@ -52,7 +50,7 @@ storageReadS3Open(THIS_VOID)
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
// Request the file
|
// Request the file
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
|
||||||
{
|
{
|
||||||
this->httpResponse = storageS3RequestP(
|
this->httpResponse = storageS3RequestP(
|
||||||
this->storage, HTTP_VERB_GET_STR, this->interface.name, .allowMissing = true, .contentIo = true);
|
this->storage, HTTP_VERB_GET_STR, this->interface.name, .allowMissing = true, .contentIo = true);
|
||||||
@ -124,13 +122,12 @@ storageReadS3New(StorageS3 *storage, const String *name, bool ignoreMissing)
|
|||||||
|
|
||||||
StorageRead *this = NULL;
|
StorageRead *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("StorageReadS3")
|
OBJ_NEW_BEGIN(StorageReadS3)
|
||||||
{
|
{
|
||||||
StorageReadS3 *driver = memNew(sizeof(StorageReadS3));
|
StorageReadS3 *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (StorageReadS3)
|
*driver = (StorageReadS3)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.storage = storage,
|
.storage = storage,
|
||||||
|
|
||||||
.interface = (StorageReadInterface)
|
.interface = (StorageReadInterface)
|
||||||
@ -150,7 +147,7 @@ storageReadS3New(StorageS3 *storage, const String *name, bool ignoreMissing)
|
|||||||
|
|
||||||
this = storageReadNew(driver, &driver->interface);
|
this = storageReadNew(driver, &driver->interface);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(STORAGE_READ, this);
|
FUNCTION_LOG_RETURN(STORAGE_READ, this);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ S3 Storage
|
|||||||
#include "common/io/socket/client.h"
|
#include "common/io/socket/client.h"
|
||||||
#include "common/io/tls/client.h"
|
#include "common/io/tls/client.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/regExp.h"
|
#include "common/regExp.h"
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
#include "common/type/json.h"
|
#include "common/type/json.h"
|
||||||
@ -100,7 +99,6 @@ Object type
|
|||||||
struct StorageS3
|
struct StorageS3
|
||||||
{
|
{
|
||||||
STORAGE_COMMON_MEMBER;
|
STORAGE_COMMON_MEMBER;
|
||||||
MemContext *memContext;
|
|
||||||
HttpClient *httpClient; // HTTP client to service requests
|
HttpClient *httpClient; // HTTP client to service requests
|
||||||
StringList *headerRedactList; // List of headers to redact from logging
|
StringList *headerRedactList; // List of headers to redact from logging
|
||||||
|
|
||||||
@ -232,7 +230,7 @@ storageS3Auth(
|
|||||||
const Buffer *serviceKey = cryptoHmacOne(HASH_TYPE_SHA256_STR, regionKey, S3_BUF);
|
const Buffer *serviceKey = cryptoHmacOne(HASH_TYPE_SHA256_STR, regionKey, S3_BUF);
|
||||||
|
|
||||||
// Switch to the object context so signing key and date are not lost
|
// Switch to the object context so signing key and date are not lost
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
|
||||||
{
|
{
|
||||||
this->signingKey = cryptoHmacOne(HASH_TYPE_SHA256_STR, serviceKey, AWS4_REQUEST_BUF);
|
this->signingKey = cryptoHmacOne(HASH_TYPE_SHA256_STR, serviceKey, AWS4_REQUEST_BUF);
|
||||||
this->signingKeyDate = strDup(date);
|
this->signingKeyDate = strDup(date);
|
||||||
@ -339,7 +337,7 @@ storageS3RequestAsync(StorageS3 *this, const String *verb, const String *path, S
|
|||||||
httpRequestError(request, response);
|
httpRequestError(request, response);
|
||||||
|
|
||||||
// Get role from the text response
|
// Get role from the text response
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
|
||||||
{
|
{
|
||||||
this->credRole = strNewBuf(httpResponseContent(response));
|
this->credRole = strNewBuf(httpResponseContent(response));
|
||||||
}
|
}
|
||||||
@ -373,7 +371,7 @@ storageS3RequestAsync(StorageS3 *this, const String *verb, const String *path, S
|
|||||||
// Get credentials from the JSON response
|
// Get credentials from the JSON response
|
||||||
KeyValue *credential = jsonToKv(strNewBuf(httpResponseContent(response)));
|
KeyValue *credential = jsonToKv(strNewBuf(httpResponseContent(response)));
|
||||||
|
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
|
||||||
{
|
{
|
||||||
// Check the code field for errors
|
// Check the code field for errors
|
||||||
const Variant *code = kvGetDefault(credential, S3_JSON_TAG_CODE_VAR, VARSTRDEF("code field is missing"));
|
const Variant *code = kvGetDefault(credential, S3_JSON_TAG_CODE_VAR, VARSTRDEF("code field is missing"));
|
||||||
@ -969,13 +967,12 @@ storageS3New(
|
|||||||
|
|
||||||
Storage *this = NULL;
|
Storage *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("StorageS3")
|
OBJ_NEW_BEGIN(StorageS3)
|
||||||
{
|
{
|
||||||
StorageS3 *driver = memNew(sizeof(StorageS3));
|
StorageS3 *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (StorageS3)
|
*driver = (StorageS3)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.interface = storageInterfaceS3,
|
.interface = storageInterfaceS3,
|
||||||
.bucket = strDup(bucket),
|
.bucket = strDup(bucket),
|
||||||
.region = strDup(region),
|
.region = strDup(region),
|
||||||
@ -1014,7 +1011,7 @@ storageS3New(
|
|||||||
|
|
||||||
this = storageNew(STORAGE_S3_TYPE, path, 0, 0, write, pathExpressionFunction, driver, driver->interface);
|
this = storageNew(STORAGE_S3_TYPE, path, 0, 0, write, pathExpressionFunction, driver, driver->interface);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(STORAGE, this);
|
FUNCTION_LOG_RETURN(STORAGE, this);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ S3 Storage File Write
|
|||||||
|
|
||||||
#include "common/debug.h"
|
#include "common/debug.h"
|
||||||
#include "common/log.h"
|
#include "common/log.h"
|
||||||
#include "common/memContext.h"
|
|
||||||
#include "common/type/object.h"
|
#include "common/type/object.h"
|
||||||
#include "common/type/xml.h"
|
#include "common/type/xml.h"
|
||||||
#include "storage/s3/write.h"
|
#include "storage/s3/write.h"
|
||||||
@ -32,7 +31,6 @@ Object type
|
|||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
typedef struct StorageWriteS3
|
typedef struct StorageWriteS3
|
||||||
{
|
{
|
||||||
MemContext *memContext; // Object mem context
|
|
||||||
StorageWriteInterface interface; // Interface
|
StorageWriteInterface interface; // Interface
|
||||||
StorageS3 *storage; // Storage that created this object
|
StorageS3 *storage; // Storage that created this object
|
||||||
|
|
||||||
@ -67,7 +65,7 @@ storageWriteS3Open(THIS_VOID)
|
|||||||
ASSERT(this->partBuffer == NULL);
|
ASSERT(this->partBuffer == NULL);
|
||||||
|
|
||||||
// Allocate the part buffer
|
// Allocate the part buffer
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
|
||||||
{
|
{
|
||||||
this->partBuffer = bufNew(this->partSize);
|
this->partBuffer = bufNew(this->partSize);
|
||||||
}
|
}
|
||||||
@ -130,7 +128,7 @@ storageWriteS3PartAsync(StorageWriteS3 *this)
|
|||||||
.query = httpQueryAdd(httpQueryNewP(), S3_QUERY_UPLOADS_STR, EMPTY_STR)))));
|
.query = httpQueryAdd(httpQueryNewP(), S3_QUERY_UPLOADS_STR, EMPTY_STR)))));
|
||||||
|
|
||||||
// Store the upload id
|
// Store the upload id
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
|
||||||
{
|
{
|
||||||
this->uploadId = xmlNodeContent(xmlNodeChild(xmlRoot, S3_XML_TAG_UPLOAD_ID_STR, true));
|
this->uploadId = xmlNodeContent(xmlNodeChild(xmlRoot, S3_XML_TAG_UPLOAD_ID_STR, true));
|
||||||
this->uploadPartList = strLstNew();
|
this->uploadPartList = strLstNew();
|
||||||
@ -143,7 +141,7 @@ storageWriteS3PartAsync(StorageWriteS3 *this)
|
|||||||
httpQueryAdd(query, S3_QUERY_UPLOAD_ID_STR, this->uploadId);
|
httpQueryAdd(query, S3_QUERY_UPLOAD_ID_STR, this->uploadId);
|
||||||
httpQueryAdd(query, S3_QUERY_PART_NUMBER_STR, strNewFmt("%u", strLstSize(this->uploadPartList) + 1));
|
httpQueryAdd(query, S3_QUERY_PART_NUMBER_STR, strNewFmt("%u", strLstSize(this->uploadPartList) + 1));
|
||||||
|
|
||||||
MEM_CONTEXT_BEGIN(this->memContext)
|
MEM_CONTEXT_BEGIN(THIS_MEM_CONTEXT())
|
||||||
{
|
{
|
||||||
this->request = storageS3RequestAsyncP(
|
this->request = storageS3RequestAsyncP(
|
||||||
this->storage, HTTP_VERB_PUT_STR, this->interface.name, .query = query, .content = this->partBuffer);
|
this->storage, HTTP_VERB_PUT_STR, this->interface.name, .query = query, .content = this->partBuffer);
|
||||||
@ -275,13 +273,12 @@ storageWriteS3New(StorageS3 *storage, const String *name, size_t partSize)
|
|||||||
|
|
||||||
StorageWrite *this = NULL;
|
StorageWrite *this = NULL;
|
||||||
|
|
||||||
MEM_CONTEXT_NEW_BEGIN("StorageWriteS3")
|
OBJ_NEW_BEGIN(StorageWriteS3)
|
||||||
{
|
{
|
||||||
StorageWriteS3 *driver = memNew(sizeof(StorageWriteS3));
|
StorageWriteS3 *driver = OBJ_NEW_ALLOC();
|
||||||
|
|
||||||
*driver = (StorageWriteS3)
|
*driver = (StorageWriteS3)
|
||||||
{
|
{
|
||||||
.memContext = MEM_CONTEXT_NEW(),
|
|
||||||
.storage = storage,
|
.storage = storage,
|
||||||
.partSize = partSize,
|
.partSize = partSize,
|
||||||
|
|
||||||
@ -305,7 +302,7 @@ storageWriteS3New(StorageS3 *storage, const String *name, size_t partSize)
|
|||||||
|
|
||||||
this = storageWriteNew(driver, &driver->interface);
|
this = storageWriteNew(driver, &driver->interface);
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_NEW_END();
|
OBJ_NEW_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN(STORAGE_WRITE, this);
|
FUNCTION_LOG_RETURN(STORAGE_WRITE, this);
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user