/** * Create an instance of the @c ee_match_any operator. * * Looks up the automata name and adds the automata to the operator instance. * * @param[in] ctx Current context. * @param[in] parameters Automata name. * @param[out] instance_data Instance data. * @param[in] cbdata Callback data. */ static ib_status_t ee_match_any_operator_create( ib_context_t *ctx, const char *parameters, void *instance_data, void *cbdata ) { assert(ctx != NULL); assert(parameters != NULL); assert(instance_data != NULL); ib_status_t rc; ia_eudoxus_t* eudoxus; ee_operator_data_t *operator_data; ib_module_t *module; ib_engine_t *ib = ib_context_get_engine(ctx); ib_mpool_t *pool = ib_context_get_mpool(ctx); const ee_config_t *config = ee_get_config(ib); const ib_hash_t *eudoxus_pattern_hash; assert(config != NULL); assert(config->eudoxus_pattern_hash != NULL); /* Get my module object */ rc = ib_engine_module_get(ib, MODULE_NAME_STR, &module); if (rc != IB_OK) { ib_log_error(ib, "Failed to get eudoxus operator module object: %s", ib_status_to_string(rc)); return rc; } /* Allocate a rule data object, populate it */ operator_data = ib_mpool_alloc(pool, sizeof(*operator_data)); if (operator_data == NULL) { return IB_EALLOC; } eudoxus_pattern_hash = config->eudoxus_pattern_hash; rc = ib_hash_get(eudoxus_pattern_hash, &eudoxus, parameters); if (rc == IB_ENOENT ) { ib_log_error(ib, MODULE_NAME_STR ": No eudoxus automata named %s found.", parameters); return rc; } else if (rc != IB_OK) { ib_log_error(ib, MODULE_NAME_STR ": Error setting up eudoxus automata operator."); return rc; } operator_data->eudoxus = eudoxus; *(ee_operator_data_t **)instance_data = operator_data; ib_log_debug(ib, "Found compiled eudoxus pattern \"%s\"", parameters); return IB_OK; }
ib_status_t test_create_fn( ib_context_t *ctx, const char *parameters, void **instance_data, void *cbdata ) { assert(ctx != NULL); char *str; ib_mpool_t *pool = ib_context_get_mpool(ctx); if (strcmp(parameters, "INVALID") == 0) { return IB_EINVAL; } str = ib_mpool_strdup(pool, parameters); if (str == NULL) { return IB_EALLOC; } *instance_data = str; return IB_OK; }
/** * Create the PCRE operator. * * @param[in] ctx Current context. * @param[in] parameters Unparsed string with the parameters to * initialize the operator instance. * @param[out] instance_data Instance data. * @param[in] cbdata Callback data. * * @returns IB_OK on success or IB_EALLOC on any other type of error. */ static ib_status_t dfa_operator_create( ib_context_t *ctx, const char *parameters, void *instance_data, void *cbdata ) { assert(ctx != NULL); assert(parameters != NULL); assert(instance_data != NULL); ib_engine_t *ib = ib_context_get_engine(ctx); ib_mpool_t *pool = ib_context_get_mpool(ctx); assert(ib != NULL); assert(pool != NULL); modpcre_cpat_data_t *cpdata; modpcre_operator_data_t *operator_data; ib_module_t *module; modpcre_cfg_t *config; ib_status_t rc; const char *errptr; int erroffset; /* Get my module object */ rc = ib_engine_module_get(ib, MODULE_NAME_STR, &module); if (rc != IB_OK) { ib_log_error(ib, "Failed to get pcre module object: %s", ib_status_to_string(rc)); return rc; } /* Get the context configuration */ rc = ib_context_module_config(ctx, module, &config); if (rc != IB_OK) { ib_log_error(ib, "Failed to get pcre module configuration: %s", ib_status_to_string(rc)); return rc; } rc = pcre_compile_internal(ib, pool, config, true, &cpdata, parameters, &errptr, &erroffset); if (rc != IB_OK) { ib_log_error(ib, "Failed to parse DFA operator pattern \"%s\":%s", parameters, ib_status_to_string(rc)); return rc; } /* Allocate a rule data object, populate it */ operator_data = ib_mpool_alloc(pool, sizeof(*operator_data)); if (operator_data == NULL) { return IB_EALLOC; } operator_data->cpdata = cpdata; rc = dfa_id_set(pool, operator_data); if (rc != IB_OK) { ib_log_error(ib, "Error creating ID for DFA: %s", ib_status_to_string(rc)); return rc; } ib_log_debug(ib, "Compiled DFA id=\"%s\" operator pattern \"%s\" @ %p", operator_data->id, parameters, (void *)cpdata->cpatt); *(modpcre_operator_data_t **)instance_data = operator_data; return IB_OK; }
/** * Create the PCRE operator. * * @param[in] ctx Current context. * @param[in] parameters Unparsed string with the parameters to * initialize the operator instance. * @param[out] instance_data Instance data. * @param[in] cbdata Callback data. * * @returns IB_OK on success or IB_EALLOC on any other type of error. */ static ib_status_t pcre_operator_create( ib_context_t *ctx, const char *parameters, void *instance_data, void *cbdata ) { assert(ctx != NULL); assert(parameters != NULL); assert(instance_data != NULL); ib_engine_t *ib = ib_context_get_engine(ctx); ib_mpool_t *pool = ib_context_get_mpool(ctx); assert(ib != NULL); assert(pool != NULL); modpcre_cpat_data_t *cpdata = NULL; modpcre_operator_data_t *operator_data = NULL; ib_module_t *module; modpcre_cfg_t *config; ib_status_t rc; const char *errptr; int erroffset; if (parameters == NULL) { ib_log_error(ib, "No pattern for operator"); return IB_EINVAL; } /* Get my module object */ rc = ib_engine_module_get(ib, MODULE_NAME_STR, &module); if (rc != IB_OK) { ib_log_error(ib, "Failed to get pcre module object: %s", ib_status_to_string(rc)); return rc; } /* Get the context configuration */ rc = ib_context_module_config(ctx, module, &config); if (rc != IB_OK) { ib_log_error(ib, "Failed to get pcre module configuration: %s", ib_status_to_string(rc)); return rc; } /* Compile the pattern. Note that the rule data is an alias for * the compiled pattern type */ rc = pcre_compile_internal(ib, pool, config, false, &cpdata, parameters, &errptr, &erroffset); if (rc != IB_OK) { return rc; } /* Allocate a rule data object, populate it */ operator_data = ib_mpool_alloc(pool, sizeof(*operator_data)); if (operator_data == NULL) { return IB_EALLOC; } operator_data->cpdata = cpdata; operator_data->id = NULL; /* Not needed for rx rules */ /* Rule data is an alias for the compiled pattern data */ *(modpcre_operator_data_t **)instance_data = operator_data; return rc; }