Go to the documentation of this file.
43 #define CONTAINER_URLRANGE_HASH_SIZE 256
87 static int ContainerUrlRangeSet(
void *
dst,
void *
src)
93 if (dst_s->
key == NULL)
95 memcpy(dst_s->
key, src_s->
key, dst_s->
len);
97 if (dst_s->
files == NULL) {
106 dst_s->
error =
false;
110 static bool ContainerUrlRangeCompare(
void *a,
void *b)
121 if (SCBufferCmp(as->
key, as->
len, bs->
key, bs->
len) == 0) {
127 static uint32_t ContainerUrlRangeHash(uint32_t hash_seed,
void *s)
135 static void ContainerUrlRangeFree(
void *s)
152 static inline bool ContainerValueRangeTimeout(
void *data,
const SCTime_t ts)
168 #define HTTP_RANGE_DEFAULT_TIMEOUT 60
169 #define HTTP_RANGE_DEFAULT_MEMCAP 100 * 1024 * 1024
174 const char *
str = NULL;
177 if (
ConfGet(
"app-layer.protocols.http.byterange.memcap", &
str) == 1) {
180 " resetting to default",
185 if (
ConfGet(
"app-layer.protocols.http.byterange.timeout", &
str) == 1) {
186 size_t slen = strlen(
str);
189 " resetting to default",
197 ContainerUrlRangeHash, ContainerUrlRangeCompare, ContainerValueRangeTimeout, NULL,
217 static void *HttpRangeContainerUrlGet(
const uint8_t *key, uint32_t keylen,
const Flow *f)
221 memset(&lookup, 0,
sizeof(lookup));
223 lookup.
key = (uint8_t *)key;
239 uint16_t name_len, uint16_t
flags)
263 const uint64_t buflen = end - start + 1;
280 }
else if (start < c->lastsize && c->
lastsize - start >= buflen) {
285 }
else if (start < c->lastsize && c->
lastsize - start < buflen && c->files != NULL) {
312 if (range->
buffer == NULL) {
320 range->
start = start;
329 uint16_t name_len, uint16_t
flags,
const uint8_t *
data, uint32_t
len)
332 HttpRangeOpenFileAux(c, start, end, total, sbcfg, name, name_len,
flags);
335 SCLogDebug(
"Failed to append data while opening");
343 const uint8_t *name, uint16_t name_len, uint16_t
flags,
const uint8_t *
data,
347 if (file_range_container == NULL) {
351 file_range_container->
sbcfg = sbcfg;
354 crparsed->end, crparsed->size, sbcfg, name, name_len,
flags,
data, data_len);
360 THashDataUnlock(file_range_container->
hdata);
373 THashDataUnlock(file_range_container->
hdata);
378 const uint8_t *
data, uint32_t
len)
413 SCLogDebug(
"update current: adding %u bytes to block %p",
len, c);
436 static void HttpRangeFileClose(
495 SCLogDebug(
"c->current was set, file incomplete so return NULL");
496 }
else if (c->
toskip > 0) {
525 if (range->
gap > 0) {
527 uint32_t gap = range->
gap <= UINT32_MAX ? (uint32_t)range->
gap : UINT32_MAX;
535 if (range->
offset > UINT32_MAX) {
541 (uint32_t)range->
offset) != 0) {
549 uint64_t overlap = f->
size - range->
start;
550 if (overlap < range->
offset) {
551 if (range->
gap > 0) {
553 uint32_t gap = range->
gap <= UINT32_MAX ? (uint32_t)range->
gap : UINT32_MAX;
563 if (range->
offset - overlap > UINT32_MAX) {
569 (uint32_t)(range->
offset - overlap)) != 0) {
613 HttpRangeBlockDerefContainer(b);
622 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
HttpRangeContainerBlock * HttpRangeContainerOpenFile(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)
int HttpRangeAppendData(const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock *c, const uint8_t *data, uint32_t len)
int HttpRangeContainerBufferCompare(HttpRangeContainerBuffer *a, HttpRangeContainerBuffer *b)
int ConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
int HTPByteRangeSetMemcap(uint64_t size)
File * HttpRangeClose(const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock *c, uint16_t flags)
RB_GENERATE(HTTP_RANGES, HttpRangeContainerBuffer, rb, HttpRangeContainerBufferCompare)
uint64_t HTPByteRangeMemuseGlobalCounter(void)
void HttpRangeContainersInit(void)
#define RB_FOREACH_SAFE(x, name, head, y)
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...
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)
void HttpRangeFreeBlock(HttpRangeContainerBlock *b)
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)
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...
THashTableContext * THashInit(const char *cnf_prefix, size_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)
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)