示例#1
0
void ConstTransformation::register_with(Engine engine)
{
    throw_if_error(ib_tfn_register(
        engine.ib(),
        ib()
    ));
}
示例#2
0
/// @test Test ironbee library - transformation registration
TEST(TestIronBee, test_tfn)
{
    ib_engine_t *ib;
    ib_status_t rc;
    ib_tfn_t *tfn = (ib_tfn_t *)-1;
    ib_flags_t flags;
    uint8_t data_in[128];
    ib_field_t *fin;
    const ib_field_t *fout;
    ib_bytestr_t *bs;

    ibtest_engine_create(&ib);

    ASSERT_EQ(IB_OK, ib_tfn_register(ib, "foo2bar", foo2bar,
                                     IB_TFN_FLAG_NONE, NULL));
    ASSERT_EQ(IB_OK, ib_tfn_lookup(ib, "foo2bar", &tfn));
    ASSERT_NE((ib_tfn_t *)-1, tfn);
    ASSERT_TRUE(tfn);

    ib_bytestr_dup_nulstr(&bs, ib->mp, "foo");
    fin = NULL;
    ib_field_create(
        &fin, ib->mp, IB_FIELD_NAME("ByteStr"),
        IB_FTYPE_BYTESTR, ib_ftype_bytestr_in(bs)
    );
    fout = NULL;
    flags = 0;
    rc = ib_tfn_transform(ib, ib->mp, tfn, fin, &fout, &flags);
    ASSERT_EQ(rc, IB_OK);
    ASSERT_NE((ib_tfn_t *)-1, tfn);
    ASSERT_TRUE(IB_TFN_CHECK_FMODIFIED(flags));
    ASSERT_NE(fin, fout);

    strcpy((char *)data_in, "foo");
    fin = NULL;
    ib_field_create(
        &fin, ib->mp, IB_FIELD_NAME("NulStr"),
        IB_FTYPE_NULSTR,
        ib_ftype_nulstr_in((char *)data_in)
    );
    fout = NULL;
    flags = 0;
    rc = ib_tfn_transform(ib, ib->mp, tfn, fin, &fout, &flags);
    ASSERT_EQ(rc, IB_OK);
    ASSERT_NE((ib_tfn_t *)-1, tfn);
    ASSERT_TRUE(IB_TFN_CHECK_FMODIFIED(flags));
    ASSERT_NE(fin, fout);

    ibtest_engine_destroy(ib);
}
示例#3
0
/* Called to initialize a module (on load). */
static ib_status_t sqltfn_init(ib_engine_t *ib, ib_module_t *m, void *cbdata)
{
    ib_status_t rc;

    ib_log_debug(ib, "Initializing %s module.", MODULE_NAME_STR);

    rc = ib_tfn_register(ib, "normalizeSqlPg", sqltfn_normalize_pg_tfn,
                         IB_TFN_FLAG_NONE, NULL);
    if (rc != IB_OK) {
        return rc;
    }

    return IB_OK;
}
示例#4
0
ib_status_t ib_tfn_create_and_register(
    const ib_tfn_t **ptfn,
    ib_engine_t     *ib,
    const char      *name,
    bool             handle_list,
    ib_tfn_fn_t      fn_execute,
    void            *cbdata
)
{
    assert(ib != NULL);
    assert(name != NULL);
    assert(fn_execute != NULL);

    const ib_tfn_t *tfn;
    ib_status_t rc;

    rc = ib_tfn_create(
        &tfn,
        ib->mp,
        name,
        handle_list,
        fn_execute, cbdata
    );
    if (rc != IB_OK) {
        return rc;
    }

    rc = ib_tfn_register(ib, tfn);
    if (rc != IB_OK) {
        return rc;
    }

    if (ptfn != NULL) {
        *ptfn = tfn;
    }
    return IB_OK;
}