Go to the documentation of this file.
44 #define CONTAINER_URLRANGE_HASH_SIZE 256
88 static int ContainerUrlRangeSet(
void *
dst,
void *
src)
94 if (dst_s->
key == NULL)
96 memcpy(dst_s->
key, src_s->
key, dst_s->
len);
98 if (dst_s->
files == NULL) {
107 dst_s->
error =
false;
111 static bool ContainerUrlRangeCompare(
void *a,
void *b)
122 if (SCBufferCmp(as->
key, as->
len, bs->
key, bs->
len) == 0) {
128 static uint32_t ContainerUrlRangeHash(uint32_t hash_seed,
void *s)
136 static void ContainerUrlRangeFree(
void *s)
153 static inline bool ContainerValueRangeTimeout(
void *data,
const SCTime_t ts)
169 #define HTTP_RANGE_DEFAULT_TIMEOUT 60
170 #define HTTP_RANGE_DEFAULT_MEMCAP 100 * 1024 * 1024
175 const char *
str = NULL;
178 if (
SCConfGet(
"app-layer.protocols.http.byterange.memcap", &
str) == 1) {
181 " resetting to default",
186 if (
SCConfGet(
"app-layer.protocols.http.byterange.timeout", &
str) == 1) {
187 size_t slen = strlen(
str);
190 " resetting to default",
198 ContainerUrlRangeHash, ContainerUrlRangeCompare, ContainerValueRangeTimeout, NULL,
218 static void *HttpRangeContainerUrlGet(
const uint8_t *key, uint32_t keylen,
const Flow *f)
222 memset(&lookup, 0,
sizeof(lookup));
224 lookup.
key = (uint8_t *)key;
240 uint16_t name_len, uint16_t
flags)
264 const uint64_t buflen = end - start + 1;
281 }
else if (start < c->lastsize && c->
lastsize - start >= buflen) {
286 }
else if (start < c->lastsize && c->
lastsize - start < buflen && c->files != NULL) {
313 if (range->
buffer == NULL) {
321 range->
start = start;
330 uint16_t name_len, uint16_t
flags,
const uint8_t *
data, uint32_t
len)
333 HttpRangeOpenFileAux(c, start, end, total, sbcfg,
name, name_len,
flags);
336 SCLogDebug(
"Failed to append data while opening");
344 const uint8_t *
name, uint16_t name_len, uint16_t
flags,
const uint8_t *
data,
348 if (file_range_container == NULL) {
352 file_range_container->
sbcfg = sbcfg;
355 crparsed->end, crparsed->size, sbcfg,
name, name_len,
flags,
data, data_len);
361 THashDataUnlock(file_range_container->
hdata);
374 THashDataUnlock(file_range_container->
hdata);
379 const uint8_t *
data, uint32_t
len)
414 SCLogDebug(
"update current: adding %u bytes to block %p",
len, c);
437 static void HttpRangeFileClose(
496 SCLogDebug(
"c->current was set, file incomplete so return NULL");
497 }
else if (c->
toskip > 0) {
526 if (range->
gap > 0) {
528 uint32_t gap = range->
gap <= UINT32_MAX ? (uint32_t)range->
gap : UINT32_MAX;
536 if (range->
offset > UINT32_MAX) {
542 (uint32_t)range->
offset) != 0) {
550 uint64_t overlap = f->
size - range->
start;
551 if (overlap < range->
offset) {
552 if (range->
gap > 0) {
554 uint32_t gap = range->
gap <= UINT32_MAX ? (uint32_t)range->
gap : UINT32_MAX;
564 if (range->
offset - overlap > UINT32_MAX) {
570 (uint32_t)(range->
offset - overlap)) != 0) {
614 HttpRangeBlockDerefContainer(b);
623 if (b->
files != NULL) {
FileContainer * FileContainerAlloc(void)
allocate a FileContainer
#define RB_REMOVE(name, x, y)
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
int ParseSizeStringU64(const char *size, uint64_t *res)
void FileContainerFree(FileContainer *ffc, const StreamingBufferConfig *cfg)
Free a FileContainer.
#define HTTP_RANGE_DEFAULT_MEMCAP
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
int SCConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
int HttpRangeContainerBufferCompare(HttpRangeContainerBuffer *a, HttpRangeContainerBuffer *b)
int HTPByteRangeSetMemcap(uint64_t size)
File * HttpRangeClose(const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock *c, uint16_t flags)
struct HTTPContentRange HTTPContentRange
RB_GENERATE(HTTP_RANGES, HttpRangeContainerBuffer, rb, HttpRangeContainerBufferCompare)
uint64_t HTPByteRangeMemuseGlobalCounter(void)
void HttpRangeContainersInit(void)
#define RB_FOREACH_SAFE(x, name, head, y)
HttpRangeContainerBlock * SCHttpRangeContainerOpenFile(const uint8_t *key, uint32_t keylen, const Flow *f, const HTTPContentRange *crparsed, const StreamingBufferConfig *sbcfg, const uint8_t *name, uint16_t name_len, uint16_t flags, const uint8_t *data, uint32_t data_len)
HttpRangeContainerBuffer * current
struct ContainerTHashTable ContainerTHashTable
int StringParseUint32(uint32_t *res, int base, size_t len, const char *str)
#define SCLogWarning(...)
Macro used to log WARNING messages.
uint32_t hashlittle_safe(const void *key, size_t length, uint32_t initval)
#define SC_ATOMIC_SUB(name, val)
sub a value from our atomic variable
int FileOpenFileWithId(FileContainer *ffc, const StreamingBufferConfig *sbcfg, uint32_t track_id, const uint8_t *name, uint16_t name_len, const uint8_t *data, uint32_t data_len, uint16_t flags)
Open a new File.
int FileAppendData(FileContainer *ffc, const StreamingBufferConfig *sbcfg, const uint8_t *data, uint32_t data_len)
Store/handle a chunk of file data in the File structure The last file in the FileContainer will be us...
int SCHttpRangeAppendData(const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock *c, const uint8_t *data, uint32_t len)
void THashShutdown(THashTableContext *ctx)
shutdown the flow engine
HttpRangeContainerFile * container
#define CONTAINER_URLRANGE_HASH_SIZE
ContainerTHashTable ContainerUrlRangeList
struct THashDataGetResult THashGetFromHash(THashTableContext *ctx, void *data)
#define THashDecrUsecnt(h)
int FileCloseFile(FileContainer *ffc, const StreamingBufferConfig *sbcfg, const uint8_t *data, uint32_t data_len, uint16_t flags)
Close a File.
#define SCTIME_CMP_GTE(a, b)
uint64_t HTPByteRangeMemcapGlobalCounter(void)
void SCHttpRangeFreeBlock(HttpRangeContainerBlock *b)
THashTableContext * THashInit(const char *cnf_prefix, uint32_t data_size, int(*DataSet)(void *, void *), void(*DataFree)(void *), uint32_t(*DataHash)(uint32_t, void *), bool(*DataCompare)(void *, void *), bool(*DataExpired)(void *, SCTime_t), uint32_t(*DataSize)(void *), bool reset_memcap, uint64_t memcap, uint32_t hashsize)
uint32_t THashExpire(THashTableContext *ctx, const SCTime_t ts)
expire data from the hash Walk the hash table and remove data that is exprired according to the DataE...
void HttpRangeContainersDestroy(void)
struct HTTP_RANGES fragment_tree
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
#define SCTIME_ADD_SECS(ts, s)
const StreamingBufferConfig * sbcfg
#define THASH_CHECK_MEMCAP(ctx, size)
check if a memory alloc would fit in the memcap
#define DEBUG_VALIDATE_BUG_ON(exp)
#define HTTP_RANGE_DEFAULT_TIMEOUT
uint32_t HttpRangeContainersTimeoutHash(const SCTime_t ts)