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 (
ConfGetValue(
"app-layer.protocols.http.byterange.memcap", &
str) == 1) {
159 "memcap value cannot be deduced: %s,"
160 " resetting to default",
165 if (
ConfGetValue(
"app-layer.protocols.http.byterange.timeout", &
str) == 1) {
166 size_t slen = strlen(
str);
169 "timeout value cannot be deduced: %s,"
170 " resetting to default",
178 ContainerUrlRangeSet, ContainerUrlRangeFree, ContainerUrlRangeHash,
206 if (ContainerValueRangeTimeout(h->
data,
ts)) {
221 ContainerUrlRangeFree(h->
data);
240 static void *HttpRangeContainerUrlGet(
const uint8_t *key, uint32_t keylen,
const Flow *f)
242 const struct timeval *
ts = &f->
lastts;
244 memset(&lookup, 0,
sizeof(lookup));
246 lookup.
key = (uint8_t *)key;
255 return res.data->data;
262 uint16_t name_len, uint16_t
flags)
286 const uint64_t buflen = end - start + 1;
303 }
else if (start < c->lastsize && c->
lastsize - start >= buflen) {
308 }
else if (start < c->lastsize && c->
lastsize - start < buflen && c->files != NULL) {
335 if (range->
buffer == NULL) {
343 range->
start = start;
352 uint16_t name_len, uint16_t
flags,
const uint8_t *
data, uint32_t
len)
355 HttpRangeOpenFileAux(c, start, end, total, sbcfg, name, name_len,
flags);
357 SCLogDebug(
"Failed to append data while openeing");
364 const uint8_t *name, uint16_t name_len, uint16_t
flags,
const uint8_t *
data,
368 if (file_range_container == NULL) {
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);
431 SCLogDebug(
"update current: adding %u bytes to block %p",
len, c);
512 SCLogDebug(
"c->current was set, file incomplete so return NULL");
513 }
else if (c->
toskip > 0) {
542 if (range->
gap > 0) {
559 uint64_t overlap = f->
size - range->
start;
560 if (overlap < range->
offset) {
561 if (range->
gap > 0) {
573 range->
offset - overlap) != 0) {
614 HttpRangeBlockDerefContainer(b);
623 if (b->
files != NULL) {
FileContainer * FileContainerAlloc(void)
allocate a FileContainer
#define RB_REMOVE(name, x, y)
int ParseSizeStringU64(const char *size, uint64_t *res)
#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 HttpRangeContainerBufferCompare(HttpRangeContainerBuffer *a, HttpRangeContainerBuffer *b)
int FileAppendData(FileContainer *ffc, 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...
#define HRLOCK_UNLOCK(fb)
RB_GENERATE(HTTP_RANGES, HttpRangeContainerBuffer, rb, HttpRangeContainerBufferCompare)
File * HttpRangeClose(HttpRangeContainerBlock *c, uint16_t flags)
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)
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.
void THashDataMoveToSpare(THashTableContext *ctx, THashData *h)
uint32_t HttpRangeContainersTimeoutHash(struct timeval *ts)
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)
#define SCLogWarning(err_code,...)
Macro used to log WARNING messages.
#define HRLOCK_TRYLOCK(fb)
int HttpRangeAppendData(HttpRangeContainerBlock *c, const uint8_t *data, uint32_t len)
int ConfGetValue(const char *name, const char **vptr)
Retrieve the value of a configuration node.
void HttpRangeContainersDestroy(void)
struct HTTP_RANGES fragment_tree
void FileContainerFree(FileContainer *ffc)
Free a FileContainer.
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
int FileCloseFile(FileContainer *ffc, const uint8_t *data, uint32_t data_len, uint16_t flags)
Close a File.
#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)