ib_status_t ib_config_register_directive(ib_engine_t *ib, const char *name, ib_dirtype_t type, ib_void_fn_t fn_config, ib_config_cb_blkend_fn_t fn_blkend, void *cbdata) { IB_FTRACE_INIT(ib_conf_register_directive); ib_dirmap_init_t *rec; ib_status_t rc; rec = (ib_dirmap_init_t *)ib_mpool_alloc(ib->config_mp, sizeof(*rec)); if (rec == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } rec->name = name; rec->type = type; rec->cb._init = fn_config; rec->fn_blkend = fn_blkend; rec->cbdata = cbdata; rc = ib_hash_set(ib->dirmap, rec->name, (void *)rec); IB_FTRACE_RET_STATUS(rc); }
ib_status_t ib_provider_define(ib_engine_t *ib, const char *type, ib_provider_register_fn_t fn_reg, void *api) { IB_FTRACE_INIT(ib_provider_define); ib_status_t rc; ib_provider_def_t *prd; char *type_copy; /* Create the provider definition. */ prd = (ib_provider_def_t *)ib_mpool_calloc(ib->config_mp, 1, sizeof(*prd)); if (prd == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } prd->mp = ib->config_mp; prd->fn_reg = fn_reg; prd->api = api; /* Copy the type. */ type_copy = (char *)ib_mpool_alloc(prd->mp, strlen(type) + 1); if (type_copy == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } strcpy(type_copy, type); prd->type = (const char *)type_copy; rc = ib_hash_set(ib->apis, type, prd); if (rc != IB_OK) { IB_FTRACE_RET_STATUS(rc); } IB_FTRACE_RET_STATUS(IB_OK); }
/** * Perf Event Start Event Callback. * * On a connection started event we register connection * counters for the connection. * * @param[in] ib IronBee object. * @param[in] event Event type. * @param[in] connp Connection object. * @param[in] cbdata Callback data: actually an perf_info_t describing the * event. */ static ib_status_t mod_perf_stats_reg_conn_counter( ib_engine_t *ib, ib_state_event_type_t event_type, ib_conn_t *connp, void *cbdata ) { IB_FTRACE_INIT(); perf_info_t *perf_info; event_info_t *eventp = (event_info_t *)cbdata; int cevent = eventp->number; int rc; int event; perf_info = ib_mpool_alloc(connp->mp, sizeof(*perf_info) * IB_STATE_EVENT_NUM); for (event = 0; event < IB_STATE_EVENT_NUM; ++event) { if ((eventp->cbdata_type == IB_CBDATA_NONE) || (eventp->cbdata_type == IB_CBDATA_CONN_DATA_T)) { ib_log_error(ib, "Cannot collect stats for:%d name:%s cbdata_type: %d", eventp->number, eventp->name, eventp->cbdata_type); } else { perf_info_t *perfp = &perf_info[event]; /* Does this event match conn_started_event? * If so we should init counters for this event. */ if (event == cevent) { perfp->call_cnt = 1; perfp->start_usec = ib_clock_get_time(); } else { perfp->call_cnt = 0; perfp->start_usec = 0; } /* Setup other defaults */ perfp->number = event; perfp->name = ib_state_event_name((ib_state_event_type_t)event); perfp->cbdata_type = ib_state_event_cbdata_type(event); perfp->max_usec = 0; perfp->total_usec = 0; perfp->stop_usec = 0; ib_log_debug(ib, "Perf callback registered %s (%d) (%d)", perfp->name, perfp->number, perfp->cbdata_type); } } rc = ib_hash_set(connp->data, "MOD_PERF_STATS" ,perf_info); if (rc != IB_OK) { ib_log_debug(ib, "Failed to store perf stats in connection data: %s", ib_status_to_string(rc)); IB_FTRACE_RET_STATUS(rc); } IB_FTRACE_RET_STATUS(IB_OK); }
ib_status_t ib_action_register( ib_engine_t *ib, const char *name, ib_flags_t flags, ib_action_create_fn_t fn_create, void *cbdata_create, ib_action_destroy_fn_t fn_destroy, void *cbdata_destroy, ib_action_execute_fn_t fn_execute, void *cbdata_execute ) { IB_FTRACE_INIT(); ib_hash_t *action_hash = ib->actions; ib_mpool_t *pool = ib_engine_pool_main_get(ib); ib_status_t rc; char *name_copy; ib_action_t *act; rc = ib_hash_get(action_hash, &act, name); if (rc == IB_OK) { /* name already is registered */ IB_FTRACE_RET_STATUS(IB_EINVAL); } name_copy = ib_mpool_strdup(pool, name); if (name_copy == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } act = (ib_action_t *)ib_mpool_alloc(pool, sizeof(*act)); if (act == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } act->name = name_copy; act->flags = flags; act->fn_create = fn_create; act->cbdata_create = cbdata_create; act->fn_destroy = fn_destroy; act->cbdata_destroy = cbdata_destroy; act->fn_execute = fn_execute; act->cbdata_execute = cbdata_execute; rc = ib_hash_set(action_hash, name_copy, act); IB_FTRACE_RET_STATUS(rc); }
static ib_status_t cpy_psntsfw_cfg( ib_engine_t *ib, ib_mpool_t *mp, ib_mpool_t *local_mp, const ib_persist_fw_cfg_t *persist_fw_src, ib_persist_fw_cfg_t **persist_fw_dst ) { assert(ib != NULL); assert(mp != NULL); assert(local_mp != NULL); assert(persist_fw_src != NULL); assert(persist_fw_dst != NULL); ib_list_t *list = NULL; ib_list_node_t *list_node; ib_status_t rc; ib_persist_fw_cfg_t *persist_fw_out; rc = ib_persist_fw_cfg_create(mp, &persist_fw_out); if (rc != IB_OK) { ib_log_error(ib, "Failed to create new persist_fw_cfg."); return rc; } rc = ib_list_create(&list, local_mp); if (rc != IB_OK) { return rc; } /* Copy the src store hash to the dst store hash. */ if (ib_hash_size(persist_fw_src->stores) > 0) { rc = ib_hash_get_all(persist_fw_src->stores, list); if (rc != IB_OK) { ib_log_error(ib, "Failed to get entries from hash."); return rc; } IB_LIST_LOOP(list, list_node) { ib_persist_fw_store_t *store = (ib_persist_fw_store_t *)ib_list_node_data_const(list_node); rc = ib_hash_set(persist_fw_out->stores, store->name, store); if (rc != IB_OK) { ib_log_error(ib, "Failed to set store %s", store->name); return rc; } }
ib_status_t ib_tfn_create(ib_engine_t *ib, const char *name, ib_tfn_fn_t transform, void *fndata, ib_tfn_t **ptfn) { IB_FTRACE_INIT(ib_tfn_create); ib_status_t rc; ib_tfn_t *tfn; char *name_copy; size_t name_len = strlen(name) + 1; name_copy = (char *)ib_mpool_alloc(ib->mp, name_len); if (name_copy == NULL) { if (ptfn != NULL) { *ptfn = NULL; } IB_FTRACE_RET_STATUS(IB_EALLOC); } memcpy(name_copy, name, name_len); tfn = (ib_tfn_t *)ib_mpool_alloc(ib->mp, sizeof(*tfn)); if (tfn == NULL) { if (ptfn != NULL) { *ptfn = NULL; } IB_FTRACE_RET_STATUS(IB_EALLOC); } tfn->name = name_copy; tfn->transform = transform; tfn->fndata = fndata; rc = ib_hash_set(ib->tfns, name_copy, tfn); if (rc != IB_OK) { if (ptfn != NULL) { *ptfn = NULL; } IB_FTRACE_RET_STATUS(rc); } if (ptfn != NULL) { *ptfn = tfn; } IB_FTRACE_RET_STATUS(IB_OK); }
ib_status_t ib_config_register_directives(ib_engine_t *ib, const ib_dirmap_init_t *init) { IB_FTRACE_INIT(ib_conf_register_directives); const ib_dirmap_init_t *rec = init; ib_status_t rc; while ((rec != NULL) && (rec->name != NULL)) { rc = ib_hash_set(ib->dirmap, rec->name, (void *)rec); if (rc != IB_OK) { IB_FTRACE_RET_STATUS(rc); } rec++; } IB_FTRACE_RET_STATUS(IB_OK); }
ib_status_t ib_action_register( ib_engine_t *ib, const char *name, ib_action_create_fn_t fn_create, void *cbdata_create, ib_action_destroy_fn_t fn_destroy, void *cbdata_destroy, ib_action_execute_fn_t fn_execute, void *cbdata_execute ) { ib_hash_t *action_hash = ib->actions; ib_mpool_t *pool = ib_engine_pool_main_get(ib); ib_status_t rc; char *name_copy; ib_action_t *act; rc = ib_hash_get(action_hash, &act, name); if (rc == IB_OK) { /* name already is registered */ return IB_EINVAL; } name_copy = ib_mpool_strdup(pool, name); if (name_copy == NULL) { return IB_EALLOC; } act = (ib_action_t *)ib_mpool_alloc(pool, sizeof(*act)); if (act == NULL) { return IB_EALLOC; } act->name = name_copy; act->fn_create = fn_create; act->cbdata_create = cbdata_create; act->fn_destroy = fn_destroy; act->cbdata_destroy = cbdata_destroy; act->fn_execute = fn_execute; act->cbdata_execute = cbdata_execute; rc = ib_hash_set(action_hash, name_copy, act); return rc; }
/** * Create the per-transaction data for use with the dfa operator. * * @param[in] m PCRE module. * @param[in,out] tx Transaction to store the value in. * @param[in] cpatt_data Compiled pattern data * @param[in] id The operator identifier used to get it's workspace. * @param[out] workspace Created. * * @returns * - IB_OK on success. * - IB_EALLOC on an allocation error. */ static ib_status_t alloc_dfa_tx_data( const ib_module_t *m, ib_tx_t *tx, const modpcre_cpat_data_t *cpatt_data, const char *id, dfa_workspace_t **workspace ) { assert(tx); assert(tx->mp); assert(id); assert(workspace); ib_hash_t *hash; ib_status_t rc; dfa_workspace_t *ws; size_t size; *workspace = NULL; rc = get_or_create_operator_data_hash(m, tx, &hash); if (rc != IB_OK) { return rc; } ws = (dfa_workspace_t *)ib_mpool_alloc(tx->mp, sizeof(*ws)); if (ws == NULL) { return IB_EALLOC; } ws->wscount = cpatt_data->dfa_ws_size; size = sizeof(*(ws->workspace)) * (ws->wscount); ws->workspace = (int *)ib_mpool_alloc(tx->mp, size); if (ws->workspace == NULL) { return IB_EALLOC; } rc = ib_hash_set(hash, id, ws); if (rc == IB_OK) { *workspace = ws; } return rc; }
/** * Get or create an ib_hash_t inside of @c tx->data for storing dfa rule data. * * The hash is stored at the key @c MODULE_DATA_STR. * * @param[in] tx The transaction containing @c tx->data which holds * the @a rule_data object. * @param[out] rule_data The fetched or created rule data hash. This is set * to NULL on failure. * * @return * - IB_OK on success. * - IB_EALLOC on allocation failure */ static ib_status_t get_or_create_rule_data_hash(ib_tx_t *tx, ib_hash_t **rule_data) { IB_FTRACE_INIT(); assert(tx); assert(tx->mp); ib_status_t rc; /* Get or create the hash that contains the rule data. */ rc = ib_hash_get(tx->data, rule_data, MODULE_DATA_STR); if (rc == IB_OK && *rule_data != NULL) { ib_log_debug2_tx(tx, "Found rule data hash in tx data named " MODULE_DATA_STR); IB_FTRACE_RET_STATUS(IB_OK); } ib_log_debug2_tx(tx, "Rule data hash did not exist in tx data."); ib_log_debug2_tx(tx, "Creating rule data hash " MODULE_DATA_STR); rc = ib_hash_create(rule_data, tx->mp); if (rc != IB_OK) { ib_log_debug2_tx(tx, "Failed to create hash " MODULE_DATA_STR ": %d", rc); IB_FTRACE_RET_STATUS(rc); } rc = ib_hash_set(tx->data, MODULE_DATA_STR, *rule_data); if (rc != IB_OK) { ib_log_debug2_tx(tx, "Failed to store hash " MODULE_DATA_STR ": %d", rc); *rule_data = NULL; } ib_log_debug2_tx(tx, "Returning rule hash " MODULE_DATA_STR " at %p.", *rule_data); IB_FTRACE_RET_STATUS(rc); }
/** * Function exported to enable a module to register an ident provider * * @param engine Engine to register with * @param name Provider name (referenced in IdentType directive) * @param provider The identity provider * @return status */ ib_status_t ib_ident_provider_register(ib_engine_t *engine, const char *name, ib_ident_provider_t *provider) { ident_cfg_t *cfg; ib_status_t rc; ib_module_t *m; rc = ib_engine_module_get(engine, MODULE_NAME_STR, &m); assert((rc == IB_OK) && (m != NULL)); rc = ib_context_module_config(ib_context_main(engine), m, &cfg); assert((rc == IB_OK) && (cfg != NULL)); if (cfg->providers == NULL) { rc = ib_hash_create(&cfg->providers, ib_engine_mm_main_get(engine)); assert((rc == IB_OK) && (cfg->providers != NULL)); } return ib_hash_set(cfg->providers, name, provider); }
ib_status_t ib_cfgmap_init(ib_cfgmap_t *cm, const void *base, const ib_cfgmap_init_t *init, int usedefaults) { IB_FTRACE_INIT(ib_cfgmap_init); ib_cfgmap_init_t *rec = (ib_cfgmap_init_t *)init; ib_field_t *f; ib_status_t rc; /* Add tree entries that just point into the base structure. */ ib_util_log_debug(9, "Initializing: t=%p init=%p", cm, init); while (rec->name != NULL) { void *val = (void *)(((uint8_t *)base) + rec->offset); ib_util_log_debug(9, "INIT: %s type=%d base=%p offset=%d dlen=%d %p", rec->name, rec->type, base, (int)rec->offset, (int)rec->dlen, val); /* Copy the default value if required. */ if (usedefaults) { memcpy(val, &rec->defval, rec->dlen); } /* Create a field with data that points to the base+offset. */ rc = ib_field_createn(&f, cm->mp, rec->name, rec->type, val); if (rc != IB_OK) { IB_FTRACE_RET_STATUS(rc); } /* Add the field. */ rc = ib_hash_set(cm->hash, rec->name, (void *)f); if (rc != IB_OK) { IB_FTRACE_RET_STATUS(rc); } rec++; } IB_FTRACE_RET_STATUS(IB_OK); }
ib_status_t ib_action_register( ib_engine_t *ib, const ib_action_t *action ) { assert(ib != NULL); assert(action != NULL); ib_status_t rc; ib_hash_t *action_hash = ib->actions; rc = ib_hash_get(action_hash, NULL, action->name); if (rc == IB_OK) { /* Already exists. */ return IB_EINVAL; } rc = ib_hash_set(action_hash, ib_action_name(action), (void *)action); return rc; }
/** * Create the per-transaction data for use with the dfa operator. * * @param[in,out] tx Transaction to store the value in. * @param[in] id The operator identifier used to get it's workspace. * @param[out] workspace Created. * * @returns * - IB_OK on success. * - IB_EALLOC on an allocation error. */ static ib_status_t alloc_dfa_tx_data(ib_tx_t *tx, const char *id, dfa_workspace_t **workspace) { IB_FTRACE_INIT(); assert(tx); assert(tx->mp); assert(id); assert(workspace); ib_hash_t *rule_data; ib_status_t rc; rc = get_or_create_rule_data_hash(tx, &rule_data); if (rc != IB_OK) { IB_FTRACE_RET_STATUS(rc); } *workspace = (dfa_workspace_t *)ib_mpool_alloc(tx->mp, sizeof(**workspace)); if (*workspace == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } (*workspace)->wscount = WORKSPACE_SIZE_DEFAULT; (*workspace)->workspace = (int *)ib_mpool_alloc(tx->mp, sizeof(*((*workspace)->workspace)) * (*workspace)->wscount); if ((*workspace)->workspace == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } rc = ib_hash_set(rule_data, id, *workspace); if (rc != IB_OK) { *workspace = NULL; } IB_FTRACE_RET_STATUS(rc); }
ib_status_t ib_tfn_register( ib_engine_t *ib, const ib_tfn_t *tfn ) { assert(ib != NULL); assert(tfn != NULL); ib_status_t rc; rc = ib_hash_get(ib->tfns, NULL, ib_tfn_name(tfn)); if (rc != IB_ENOENT) { /* Already exists. */ return IB_EINVAL; } rc = ib_hash_set(ib->tfns, ib_tfn_name(tfn), (void *)tfn); if (rc != IB_OK) { return rc; } return IB_OK; }
ib_status_t ib_tfn_register(ib_engine_t *ib, const char *name, ib_tfn_fn_t fn_execute, ib_flags_t flags, void *fndata) { assert(ib != NULL); assert(name != NULL); assert(fn_execute != NULL); ib_hash_t *tfn_hash = ib->tfns; ib_status_t rc; ib_tfn_t *tfn; char *name_copy; name_copy = ib_mpool_strdup(ib->mp, name); if (name_copy == NULL) { return IB_EALLOC; } tfn = (ib_tfn_t *)ib_mpool_alloc(ib->mp, sizeof(*tfn)); if (tfn == NULL) { return IB_EALLOC; } tfn->name = name_copy; tfn->fn_execute = fn_execute; tfn->tfn_flags = flags; tfn->fndata = fndata; rc = ib_hash_set(tfn_hash, name_copy, tfn); if (rc != IB_OK) { return rc; } return IB_OK; }
ib_status_t ib_cfgmap_init(ib_cfgmap_t *cm, void *base, const ib_cfgmap_init_t *init) { ib_cfgmap_init_t *rec = (ib_cfgmap_init_t *)init; ib_field_t *f; ib_status_t rc; /* Add tree entries that just point into the base structure. */ ib_util_log_debug("Initializing: t=%p init=%p", cm, init); cm->base = base; while (rec->name != NULL) { if (rec->fn_set != NULL && rec->fn_get != NULL) { ib_util_log_debug("INIT: %s type=%d set=%p/%p get=%p/%p", rec->name, rec->type, rec->fn_set, rec->cbdata_set, rec->fn_get, rec->cbdata_get); ib_cfgmap_handlers_data_t *data = (ib_cfgmap_handlers_data_t *)ib_mpool_alloc( cm->mp, sizeof(*data) ); if (data == NULL) { return IB_EALLOC; } data->base = base; data->init = rec; rc = ib_field_create_dynamic( &f, cm->mp, rec->name, strlen(rec->name), rec->type, ib_cfgmap_handle_get, data, ib_cfgmap_handle_set, data ); if (rc != IB_OK) { return rc; } } else { if (rec->fn_get != NULL || rec->fn_set != NULL) { return IB_EINVAL; } void *val = (void *)(((uint8_t *)base) + rec->offset); ib_util_log_debug("INIT: %s type=%d base=%p offset=%d dlen=%d %p", rec->name, rec->type, base, (int)rec->offset, (int)rec->dlen, val); /* Create a field with data that points to the base+offset. */ rc = ib_field_create_alias( &f, cm->mp, rec->name, strlen(rec->name), rec->type, val ); if (rc != IB_OK) { return rc; } } /* Add the field. */ rc = ib_hash_set(cm->hash, rec->name, (void *)f); if (rc != IB_OK) { return rc; } ++rec; } return IB_OK; }
ib_status_t ib_provider_register(ib_engine_t *ib, const char *type, const char *key, ib_provider_t **ppr, void *iface, ib_provider_inst_init_fn_t fn_init) { IB_FTRACE_INIT(); char *pr_key; ib_status_t rc; ib_provider_def_t *prd; ib_provider_t *pr; if (ppr != NULL) { *ppr = NULL; } /* Get the API, if any */ rc = ib_hash_get(ib->apis, &prd, type); if (rc != IB_OK) { ib_log_error(ib, "Error registering provider \"%s\": " "Unknown provider type \"%s\"", key, type); IB_FTRACE_RET_STATUS(rc); } /* Create the provider. */ pr = (ib_provider_t *)ib_mpool_calloc(prd->mp, 1, sizeof(*pr)); if (pr == NULL) { IB_FTRACE_RET_STATUS(IB_EALLOC); } pr->ib = ib; pr->mp = prd->mp; pr->type = prd->type; pr->iface = iface; pr->api = prd->api; pr->fn_init = fn_init; if (ppr != NULL) { *ppr = pr; } /* Register. */ /// @todo Hash of hash? Hash of list? pr_key = (char *)ib_mpool_alloc(ib->mp, strlen(type) + strlen(key) + 2); memcpy(pr_key, type, strlen(type)); pr_key[strlen(type)] = '.'; memcpy(pr_key + strlen(type) + 1, key, strlen(key)); pr_key[strlen(type) + strlen(key) + 1] = '\0'; rc = ib_hash_set(ib->providers, pr_key, pr); if (rc != IB_OK) { IB_FTRACE_RET_STATUS(rc); } /* If available, call the registration callback, * de-registering on failure. */ if (prd->fn_reg != NULL) { rc = prd->fn_reg(ib, pr); if (rc != IB_OK) { ib_hash_remove(ib->providers, NULL, pr_key); } IB_FTRACE_RET_STATUS(rc); } IB_FTRACE_RET_STATUS(IB_OK); }
static ib_status_t sqli_dir_fingerprint_set( ib_cfgparser_t *cp, const char *directive_name, const char *set_name, const char *set_path, void *cbdata ) { assert(cp != NULL); assert(directive_name != NULL); assert(set_name != NULL); assert(set_path != NULL); ib_status_t rc; ib_context_t *ctx = NULL; ib_module_t *m = NULL; sqli_module_config_t *cfg = NULL; sqli_fingerprint_set_t *ps = NULL; ib_mm_t mm; char *abs_set_path = NULL; rc = ib_cfgparser_context_current(cp, &ctx); assert(rc == IB_OK); assert(ctx != NULL); if (ctx != ib_context_main(cp->ib)) { ib_cfg_log_error(cp, "%s: Only valid at main context.", directive_name ); return IB_EINVAL; } if (strcmp("default", set_name) == 0) { ib_cfg_log_error(cp, "%s: default is a reserved set name.", directive_name ); return IB_EINVAL; } mm = ib_engine_mm_main_get(cp->ib); rc = ib_engine_module_get( ib_context_get_engine(ctx), MODULE_NAME_STR, &m ); assert(rc == IB_OK); rc = ib_context_module_config(ctx, m, &cfg); assert(rc == IB_OK); if (cfg->fingerprint_sets == NULL) { rc = ib_hash_create(&cfg->fingerprint_sets, mm); assert(rc == IB_OK); } assert(cfg->fingerprint_sets != NULL); rc = ib_hash_get(cfg->fingerprint_sets, NULL, set_name); if (rc == IB_OK) { ib_cfg_log_error(cp, "%s: Duplicate fingerprint set definition: %s", directive_name, set_name ); return IB_EINVAL; } assert(rc == IB_ENOENT); abs_set_path = ib_util_relative_file( ib_engine_mm_config_get(cp->ib), ib_cfgparser_curr_file(cp), set_path ); if (abs_set_path == NULL) { return IB_EALLOC; } rc = sqli_create_fingerprint_set_from_file(&ps, abs_set_path, mm); if (rc != IB_OK) { ib_cfg_log_error(cp, "%s: Failure to load fingerprint set from file: %s", directive_name, abs_set_path ); return IB_EINVAL; } assert(ps != NULL); rc = ib_hash_set(cfg->fingerprint_sets, ib_mm_strdup(mm, set_name), ps); assert(rc == IB_OK); return IB_OK; }
/** * Load a eudoxus pattern so it can be used in rules. * * The filename should point to a compiled automata. If a relative path is * given, it will be loaded relative to the current configuration file. * * @param[in] cp Configuration parser. * @param[in] name Directive name. * @param[in] pattern_name Name to associate with the pattern. * @param[in] filename Filename to load. * @param[in] cbdata Callback data (unused) * @return * - IB_OK on success. * - IB_EEXIST if the pattern has already been defined. * - IB_EINVAL if there was an error loading the automata. */ static ib_status_t load_eudoxus_pattern_param2(ib_cfgparser_t *cp, const char *name, const char *pattern_name, const char *filename, void *cbdata) { ib_engine_t *ib; ib_status_t rc; const char *automata_file; ia_eudoxus_result_t ia_rc; ib_hash_t *eudoxus_pattern_hash; ia_eudoxus_t *eudoxus; const ee_config_t* config; ib_mm_t mm_tmp; void *tmp; assert(cp != NULL); assert(cp->ib != NULL); assert(pattern_name != NULL); assert(filename != NULL); mm_tmp = ib_engine_mm_temp_get(cp->ib); ib = cp->ib; config = ee_get_config(ib); assert(config != NULL); eudoxus_pattern_hash = config->eudoxus_pattern_hash; assert(eudoxus_pattern_hash != NULL); /* Check if the pattern name is already in use */ rc = ib_hash_get(eudoxus_pattern_hash, &tmp, pattern_name); if (rc == IB_OK) { ib_log_error(cp->ib, MODULE_NAME_STR ": Pattern named \"%s\" already defined", pattern_name); return IB_EEXIST; } automata_file = ib_util_relative_file(mm_tmp, cp->curr->file, filename); if (access(automata_file, R_OK) != 0) { ib_log_error(cp->ib, MODULE_NAME_STR ": Error accessing eudoxus automata file: %s.", automata_file); return IB_EINVAL; } ia_rc = ia_eudoxus_create_from_path(&eudoxus, automata_file); if (ia_rc != IA_EUDOXUS_OK) { ib_log_error(cp->ib, MODULE_NAME_STR ": Error loading eudoxus automata file[%d]: %s.", ia_rc, automata_file); return IB_EINVAL; } rc = ib_hash_set(eudoxus_pattern_hash, pattern_name, eudoxus); if (rc != IB_OK) { ia_eudoxus_destroy(eudoxus); return rc; } return IB_OK; }