|
|
|
|
@ -67,6 +67,7 @@ int32_t MpmFactoryRegisterMpmCtxProfile(
|
|
|
|
|
FatalError(SC_ERR_FATAL, "Error allocating memory");
|
|
|
|
|
}
|
|
|
|
|
memset(de_ctx->mpm_ctx_factory_container, 0, sizeof(MpmCtxFactoryContainer));
|
|
|
|
|
de_ctx->mpm_ctx_factory_container->max_id = ENGINE_SGH_MPM_FACTORY_CONTEXT_START_ID_RANGE;
|
|
|
|
|
|
|
|
|
|
MpmCtxFactoryItem *item = SCMalloc(sizeof(MpmCtxFactoryItem));
|
|
|
|
|
if (unlikely(item == NULL)) {
|
|
|
|
|
@ -91,10 +92,7 @@ int32_t MpmFactoryRegisterMpmCtxProfile(
|
|
|
|
|
}
|
|
|
|
|
memset(item[0].mpm_ctx_tc, 0, sizeof(MpmCtx));
|
|
|
|
|
item[0].mpm_ctx_tc->flags |= MPMCTX_FLAGS_GLOBAL;
|
|
|
|
|
|
|
|
|
|
/* our id starts from 0 always. Helps us with the ctx retrieval from
|
|
|
|
|
* the array */
|
|
|
|
|
item[0].id = 0;
|
|
|
|
|
item[0].id = de_ctx->mpm_ctx_factory_container->max_id++;
|
|
|
|
|
|
|
|
|
|
/* store the newly created item */
|
|
|
|
|
de_ctx->mpm_ctx_factory_container->items = item;
|
|
|
|
|
@ -161,7 +159,7 @@ int32_t MpmFactoryRegisterMpmCtxProfile(
|
|
|
|
|
memset(new_item[0].mpm_ctx_tc, 0, sizeof(MpmCtx));
|
|
|
|
|
new_item[0].mpm_ctx_tc->flags |= MPMCTX_FLAGS_GLOBAL;
|
|
|
|
|
|
|
|
|
|
new_item[0].id = de_ctx->mpm_ctx_factory_container->no_of_items;
|
|
|
|
|
new_item[0].id = de_ctx->mpm_ctx_factory_container->max_id++;
|
|
|
|
|
de_ctx->mpm_ctx_factory_container->no_of_items++;
|
|
|
|
|
|
|
|
|
|
/* the newly created id */
|
|
|
|
|
@ -200,13 +198,17 @@ MpmCtx *MpmFactoryGetMpmCtxForProfile(const DetectEngineCtx *de_ctx, int32_t id,
|
|
|
|
|
} else if (id < -1) {
|
|
|
|
|
SCLogError(SC_ERR_INVALID_ARGUMENTS, "Invalid argument - %d\n", id);
|
|
|
|
|
return NULL;
|
|
|
|
|
} else if (id >= de_ctx->mpm_ctx_factory_container->no_of_items) {
|
|
|
|
|
} else if (id >= de_ctx->mpm_ctx_factory_container->max_id) {
|
|
|
|
|
/* this id does not exist */
|
|
|
|
|
return NULL;
|
|
|
|
|
} else {
|
|
|
|
|
return (direction == 0) ?
|
|
|
|
|
de_ctx->mpm_ctx_factory_container->items[id].mpm_ctx_ts :
|
|
|
|
|
de_ctx->mpm_ctx_factory_container->items[id].mpm_ctx_tc;
|
|
|
|
|
for (int i = 0; i < de_ctx->mpm_ctx_factory_container->no_of_items; i++) {
|
|
|
|
|
if (id == de_ctx->mpm_ctx_factory_container->items[i].id) {
|
|
|
|
|
return (direction == 0) ? de_ctx->mpm_ctx_factory_container->items[i].mpm_ctx_ts
|
|
|
|
|
: de_ctx->mpm_ctx_factory_container->items[i].mpm_ctx_tc;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|