Go to the documentation of this file.
43 #define CONTAINER_URLRANGE_HASH_SIZE 256
65 static int ContainerUrlRangeSet(
void *
dst,
void *
src)
71 if (dst_s->
key == NULL)
73 memcpy(dst_s->
key, src_s->
key, dst_s->
len);
75 if (dst_s->
files == NULL) {
88 static bool ContainerUrlRangeCompare(
void *a,
void *b)
99 if (SCBufferCmp(as->
key, as->
len, bs->
key, bs->
len) == 0) {
105 static uint32_t ContainerUrlRangeHash(
void *s)
113 static void ContainerUrlRangeFree(
void *s)
147 #define HTTP_RANGE_DEFAULT_TIMEOUT 60
148 #define HTTP_RANGE_DEFAULT_MEMCAP 100 * 1024 * 1024
153 const char *
str = NULL;
156 if (
ConfGet(
"app-layer.protocols.http.byterange.memcap", &
str) == 1) {
159 " resetting to default",
164 if (
ConfGet(
"app-layer.protocols.http.byterange.timeout", &
str) == 1) {
165 size_t slen = strlen(
str);
168 " resetting to default",
176 ContainerUrlRangeSet, ContainerUrlRangeFree, ContainerUrlRangeHash,
204 if (ContainerValueRangeTimeout(h->
data,
ts)) {
219 ContainerUrlRangeFree(h->
data);
238 static void *HttpRangeContainerUrlGet(
const uint8_t *key, uint32_t keylen,
const Flow *f)
242 memset(&lookup, 0,
sizeof(lookup));
244 lookup.
key = (uint8_t *)key;
260 uint16_t name_len, uint16_t
flags)
284 const uint64_t buflen = end - start + 1;
301 }
else if (start < c->lastsize && c->
lastsize - start >= buflen) {
306 }
else if (start < c->lastsize && c->
lastsize - start < buflen && c->files != NULL) {
333 if (range->
buffer == NULL) {
341 range->
start = start;
350 uint16_t name_len, uint16_t
flags,
const uint8_t *
data, uint32_t
len)
353 HttpRangeOpenFileAux(c, start, end, total, sbcfg, name, name_len,
flags);
355 SCLogDebug(
"Failed to append data while openeing");
362 const uint8_t *name, uint16_t name_len, uint16_t
flags,
const uint8_t *
data,
366 if (file_range_container == NULL) {
370 file_range_container->
sbcfg = sbcfg;
373 crparsed->end, crparsed->size, sbcfg, name, name_len,
flags,
data, data_len);
379 THashDataUnlock(file_range_container->
hdata);
392 THashDataUnlock(file_range_container->
hdata);
397 const uint8_t *
data, uint32_t
len)
432 SCLogDebug(
"update current: adding %u bytes to block %p",
len, c);
455 static void HttpRangeFileClose(
514 SCLogDebug(
"c->current was set, file incomplete so return NULL");
515 }
else if (c->
toskip > 0) {
544 if (range->
gap > 0) {
561 uint64_t overlap = f->
size - range->
start;
562 if (overlap < range->
offset) {
563 if (range->
gap > 0) {
575 range->
offset - overlap) != 0) {
619 HttpRangeBlockDerefContainer(b);
628 if (b->
files != NULL) {
FileContainer * FileContainerAlloc(void)
allocate a FileContainer
#define RB_REMOVE(name, x, y)
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.
#define HRLOCK_UNLOCK(fb)
File * HttpRangeClose(const StreamingBufferConfig *sbcfg, HttpRangeContainerBlock *c, uint16_t flags)
RB_GENERATE(HTTP_RANGES, HttpRangeContainerBuffer, rb, HttpRangeContainerBufferCompare)
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.
THashTableContext * THashInit(const char *cnf_prefix, size_t data_size, int(*DataSet)(void *, void *), void(*DataFree)(void *), uint32_t(*DataHash)(void *), bool(*DataCompare)(void *, void *), bool reset_memcap, uint64_t memcap, uint32_t hashsize)
#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 THashDataMoveToSpare(THashTableContext *ctx, THashData *h)
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 HRLOCK_TRYLOCK(fb)
void HttpRangeContainersDestroy(void)
struct HTTP_RANGES fragment_tree
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
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 StringHashDjb2(const uint8_t *data, uint32_t datalen)
uint32_t HttpRangeContainersTimeoutHash(const SCTime_t ts)