static ib_status_t modpcre_init(ib_engine_t *ib, ib_module_t *m, void *cbdata) { IB_FTRACE_INIT(); ib_status_t rc; /* Register as a matcher provider. */ rc = ib_provider_register(ib, IB_PROVIDER_TYPE_MATCHER, MODULE_NAME_STR, NULL, &modpcre_matcher_iface, NULL); if (rc != IB_OK) { ib_log_error(ib, MODULE_NAME_STR ": Error registering pcre matcher provider: " "%s", ib_status_to_string(rc)); IB_FTRACE_RET_STATUS(IB_OK); } ib_log_debug(ib,"PCRE Status: compiled=\"%d.%d %s\" loaded=\"%s\"", PCRE_MAJOR, PCRE_MINOR, IB_XSTRINGIFY(PCRE_DATE), pcre_version()); /* Register operators. */ ib_operator_register(ib, "pcre", (IB_OP_FLAG_PHASE | IB_OP_FLAG_CAPTURE), pcre_operator_create, NULL, pcre_operator_destroy, NULL, pcre_operator_execute, NULL); /* An alias of pcre. The same callbacks are registered. */ ib_operator_register(ib, "rx", (IB_OP_FLAG_PHASE | IB_OP_FLAG_CAPTURE), pcre_operator_create, NULL, pcre_operator_destroy, NULL, pcre_operator_execute, NULL); /* Register a pcre operator that uses pcre_dfa_exec to match streams. */ ib_operator_register(ib, "dfa", (IB_OP_FLAG_PHASE | IB_OP_FLAG_STREAM), dfa_operator_create, NULL, dfa_operator_destroy, NULL, dfa_operator_execute, NULL); IB_FTRACE_RET_STATUS(IB_OK); }
TEST_F(OperatorTest, OperatorCallTest) { ib_status_t status; ib_num_t call_result; ib_rule_t *rule = NULL; /* Unused by this operator. */ ib_operator_inst_t *op; status = ib_operator_register(ib_engine, "test_op", IB_OP_FLAG_PHASE, test_create_fn, NULL, test_destroy_fn, NULL, test_execute_fn, NULL); ASSERT_EQ(IB_OK, status); status = ib_operator_inst_create(ib_engine, NULL, rule, IB_OP_FLAG_PHASE, "test_op", "INVALID", IB_OPINST_FLAG_NONE, &op); ASSERT_EQ(IB_EINVAL, status); status = ib_operator_inst_create(ib_engine, NULL, rule, IB_OP_FLAG_PHASE, "test_op", "data", IB_OPINST_FLAG_NONE, &op); ASSERT_EQ(IB_OK, status); ib_rule_exec_t rule_exec; memset(&rule_exec, 0, sizeof(rule_exec)); rule_exec.ib = ib_engine; rule_exec.rule = rule; ib_field_t *field; const char *matching = "data matching string"; const char *nonmatching = "non matching string"; ib_field_create( &field, ib_engine_pool_main_get(ib_engine), IB_FIELD_NAME("testfield"), IB_FTYPE_NULSTR, NULL ); ib_field_setv(field, ib_ftype_nulstr_in(matching)); status = ib_operator_execute(&rule_exec, op, field, &call_result); ASSERT_EQ(IB_OK, status); EXPECT_EQ(1, call_result); ib_field_setv(field, ib_ftype_nulstr_in(nonmatching)); status = ib_operator_execute(&rule_exec, op, field, &call_result); ASSERT_EQ(IB_OK, status); EXPECT_EQ(0, call_result); status = ib_operator_inst_destroy(op); ASSERT_EQ(IB_OK, status); }
void ConstOperator::register_with(Engine engine) { throw_if_error(ib_operator_register(engine.ib(), ib())); }