virtual void SetUp() { ib_status_t rc; const char *s1 = "string 1"; const char *s2 = "string 2"; BaseTransactionFixture::SetUp(); configureIronBee(); performTx(); ib_mm_t mm = ib_engine_mm_main_get(ib_engine); char* str1 = (char *)ib_mm_alloc(mm, (strlen(s1)+1)); if (str1 == NULL) { throw std::runtime_error("Could not allocate string 1."); } strcpy(str1, s1); char* str2 = (char *)ib_mm_alloc(mm, (strlen(s2)+1)); if (str1 == NULL) { throw std::runtime_error("Could not allocate string 2."); } strcpy(str2, s2); // Create field 1. rc = ib_field_create(&field1, mm, IB_S2SL("field1"), IB_FTYPE_NULSTR, ib_ftype_nulstr_in(str1)); if (rc != IB_OK) { throw std::runtime_error("Could not initialize field1."); } // Create field 2. rc = ib_field_create(&field2, mm, IB_S2SL("field2"), IB_FTYPE_NULSTR, ib_ftype_nulstr_in(str2)); if (rc != IB_OK) { throw std::runtime_error("Could not initialize field2."); } /* Create rule 1 */ rc = ib_rule_create(ib_engine, ib_context_engine(ib_engine), __FILE__, __LINE__, true, &rule1); if (rc != IB_OK) { throw std::runtime_error("Could not create rule1."); } rc = ib_rule_set_id(ib_engine, rule1, "rule1"); if (rc != IB_OK) { throw std::runtime_error("Could not set ID for rule1."); } /* Create the rule execution object #1 */ memset(&rule_exec1, 0, sizeof(rule_exec1)); rule_exec1.ib = ib_engine; rule_exec1.tx = ib_tx; rule_exec1.rule = rule1; /* Create rule 2 */ rc = (ib_rule_create(ib_engine, ib_context_engine(ib_engine), __FILE__, __LINE__, true, &rule2)); if (rc != IB_OK) { throw std::runtime_error("Could not create rule2."); } rc = ib_rule_set_id(ib_engine, rule2, "rule2"); if (rc != IB_OK) { throw std::runtime_error("Could not set ID for rule2."); } rule2->flags |= IB_RULE_FLAG_CAPTURE; /* Create the rule execution object #1 */ memset(&rule_exec2, 0, sizeof(rule_exec2)); rule_exec2.ib = ib_engine; rule_exec2.tx = ib_tx; rule_exec2.rule = rule2; }
/** * Initializes and configures the ironbee engine. */ static int ironbee_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptmp, server_rec *s) { ironbee_config_t *modcfg = (ironbee_config_t *)ap_get_module_config(s->module_config, &ironbee_module); ib_cfgparser_t *cp; ib_provider_t *lpr; void *init = NULL; ib_status_t rc; /* Init IB library. */ rc = ib_initialize(); if (rc != IB_OK) { ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, IB_PRODUCT_NAME ": Error initializing ib library"); return OK; } ib_util_log_level(4); /* Detect first (validation) run vs real config run. */ apr_pool_userdata_get(&init, "ironbee-init", s->process->pool); if (init == NULL) { ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, MODULE_NAME_FULL " loading."); apr_pool_userdata_set((const void *)1, "ironbee-init", apr_pool_cleanup_null, s->process->pool); return OK; } /// @todo Tracefile needs removed //ib_trace_init("/tmp/ironbee.trace"); ib_trace_init(NULL); /* Create the engine handle. */ rc = ib_engine_create(&ironbee, &ibplugin); if (rc != IB_OK) { ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, IB_PRODUCT_NAME ": Error creating engine: %d", rc); return OK; } /* Register the logger. */ rc = ib_provider_register(ironbee, IB_PROVIDER_TYPE_LOGGER, MODULE_NAME_STR, &lpr, &ironbee_logger_iface, NULL); if (rc != IB_OK) { ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, IB_PRODUCT_NAME ": Error registering log provider: %d", rc); return OK; } ib_provider_data_set(lpr, (void *)s); /* Default logger */ /// @todo Need to add a post set hook in core for this to work correctly ib_context_set_string(ib_context_engine(ironbee), IB_PROVIDER_TYPE_LOGGER, MODULE_NAME_STR); ib_context_set_num(ib_context_engine(ironbee), IB_PROVIDER_TYPE_LOGGER ".log_level", 4); rc = ib_engine_init(ironbee); if (rc != IB_OK) { ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, IB_PRODUCT_NAME ": Error initializing engine: %d", rc); return OK; } /* Register module cleanup. */ apr_pool_cleanup_register(p, (void *)s, ironbee_module_cleanup, apr_pool_cleanup_null); /* Register conn/tx init hooks. */ ib_hook_register(ironbee, conn_opened_event, (ib_void_fn_t)ironbee_conn_init, s); /* Configure the engine. */ if (modcfg->config != NULL) { ib_context_t *ctx; /* Notify the engine that the config process has started. This * will also create a main configuration context. */ ib_state_notify_cfg_started(ironbee); /* Get the main configuration context. */ ctx = ib_context_main(ironbee); /* Set some defaults */ ib_context_set_string(ctx, IB_PROVIDER_TYPE_LOGGER, MODULE_NAME_STR); ib_context_set_num(ctx, "logger.log_level", 4); /* Parse the config file. */ rc = ib_cfgparser_create(&cp, ironbee); if ((rc == IB_OK) && (cp != NULL)) { ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, IB_PRODUCT_NAME ": Parsing config: %s", modcfg->config); ib_cfgparser_parse(cp, modcfg->config); ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, IB_PRODUCT_NAME ": Destroying config parser"); ib_cfgparser_destroy(cp); } /* Notify the engine that the config process has finished. This * will also close out the main configuration context. */ ib_state_notify_cfg_finished(ironbee); } else { ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, IB_PRODUCT_NAME ": No config specified with IronBeeConfig directive"); } ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s, MODULE_NAME_FULL " configured."); return OK; }
static int ironbee_init(const char *configfile, const char *logfile) { /* grab from httpd module's post-config */ ib_status_t rc; // ib_provider_t *lpr; ib_cfgparser_t *cp; ib_context_t *ctx; int rv; rc = ib_initialize(); if (rc != IB_OK) { return rc; } ib_util_log_level(9); ib_trace_init(TRACEFILE); rc = ib_engine_create(&ironbee, &ibplugin); if (rc != IB_OK) { return rc; } rc = ib_provider_register(ironbee, IB_PROVIDER_TYPE_LOGGER, "ironbee-ts", NULL, &ironbee_logger_iface, NULL); if (rc != IB_OK) { return rc; } ib_context_set_string(ib_context_engine(ironbee), IB_PROVIDER_TYPE_LOGGER, "ironbee-ts"); ib_context_set_num(ib_context_engine(ironbee), IB_PROVIDER_TYPE_LOGGER ".log_level", 4); rc = ib_engine_init(ironbee); if (rc != IB_OK) { return rc; } /* success is documented as TS_LOG_ERROR_NO_ERROR but that's undefined. * It's actually a TS_SUCCESS (proxy/InkAPI.cc line 6641). */ rv = TSTextLogObjectCreate(logfile, TS_LOG_MODE_ADD_TIMESTAMP, &ironbee_log); if (rv != TS_SUCCESS) { return IB_OK + rv; } rc = atexit(ibexit); if (rc != 0) { return IB_OK + rv; } ib_hook_register(ironbee, conn_opened_event, (ib_void_fn_t)ironbee_conn_init, NULL); ib_state_notify_cfg_started(ironbee); ctx = ib_context_main(ironbee); ib_context_set_string(ctx, IB_PROVIDER_TYPE_LOGGER, "ironbee-ts"); ib_context_set_num(ctx, "logger.log_level", 4); rc = ib_cfgparser_create(&cp, ironbee); if (rc != IB_OK) { return rc; } if (cp != NULL) { // huh? ib_cfgparser_parse(cp, configfile); ib_cfgparser_destroy(cp); } ib_state_notify_cfg_finished(ironbee); return IB_OK; }