Beispiel #1
0
 virtual void SetUp() {
     mkdir("TestKVStore.d", 0777);
     ib_uuid_initialize();
     ib_kvstore_filesystem_init(&kvstore, "TestKVStore.d");
     ib_mpool_create(&mp, "TestKVStore", NULL);
     mm = ib_mm_mpool(mp);
 }
Beispiel #2
0
 virtual void SetUp( void )
 {
     ib_status_t rc = ib_mpool_create(&m_mpool, NULL, NULL);
     if (rc != IB_OK) {
         throw std::runtime_error("Could not create memory pool");
     }
 }
Beispiel #3
0
ib_status_t ib_cfgparser_create(ib_cfgparser_t **pcp,
                                ib_engine_t *ib)
{
    IB_FTRACE_INIT(ib_cfgparser_create);
    ib_mpool_t *pool;
    ib_status_t rc;

    /* Create parser memory pool */
    rc = ib_mpool_create(&pool, ib->mp);
    if (rc != IB_OK) {
        rc = IB_EALLOC;
        goto failed;
    }

    /* Create the main structure in the memory pool */
    *pcp = (ib_cfgparser_t *)ib_mpool_calloc(pool, 1, sizeof(**pcp));
    if (*pcp == NULL) {
        rc = IB_EALLOC;
        goto failed;
    }
    (*pcp)->ib = ib;
    (*pcp)->mp = pool;

    /* Create the stack */
    rc = ib_list_create(&((*pcp)->stack), pool);
    if (rc != IB_OK) {
        goto failed;
    }
    (*pcp)->cur_ctx = ib_context_main(ib);
    ib_list_push((*pcp)->stack, (*pcp)->cur_ctx);

    /* Create the block tracking list */
    rc = ib_list_create(&((*pcp)->block), pool);
    if (rc != IB_OK) {
        goto failed;
    }

    /* Other fields are NULLed via calloc */

    ib_log_debug(ib, 9, "Stack: ctx=%p site=%p(%s) loc=%p(%s)",
                 (*pcp)->cur_ctx,
                 (*pcp)->cur_site, (*pcp)->cur_site?(*pcp)->cur_site->name:"NONE",
                 (*pcp)->cur_loc, (*pcp)->cur_loc?(*pcp)->cur_loc->path:"/");

    IB_FTRACE_RET_STATUS(rc);

failed:
    /* Make sure everything is cleaned up on failure */
    if (pool != NULL) {
        ib_mpool_destroy(pool);
    }
    *pcp = NULL;

    IB_FTRACE_RET_STATUS(rc);
}
Beispiel #4
0
 TestStringModification(size_t call_buf_size, size_t buf_size,
                        ib_strmod_fn_t fn, const char *fn_name,
                        ib_strmod_ex_fn_t ex_fn, const char *ex_fn_name)
     : m_strmod_fn(fn),
       m_callbuf(call_buf_size, fn_name),
       m_strmod_ex_fn(ex_fn),
       m_ex_callbuf(call_buf_size, ex_fn_name),
       m_op(IB_STROP_INPLACE),
       m_inbuf(buf_size),
       m_outbuf(buf_size)
 {
     ib_status_t rc = ib_mpool_create(&m_mpool, NULL, NULL);
     if (rc != IB_OK) {
         throw std::runtime_error("Could not create mpool.");
     }
 }
Beispiel #5
0
/**
 * Release resources when the module is unloaded.
 *
 * All eudoxus engines created by the LoadEudoxus directive are destroyed.
 *
 * @param[in] ib Ironbee engine.
 * @param[in] m Module instance.
 * @param[in] cbdata Not used.
 */
static
ib_status_t ee_module_finish(ib_engine_t *ib,
                             ib_module_t *m,
                             void        *cbdata)
{
    ib_status_t rc;
    ia_eudoxus_t *eudoxus;
    ib_mpool_t *pool;
    const ee_config_t *config = ee_get_config(ib);
    ib_hash_t *eudoxus_pattern_hash;
    ib_hash_iterator_t *iterator;

    if (
        config                       == NULL ||
        config->eudoxus_pattern_hash == NULL
    ) {
        return IB_OK;
    }

    eudoxus_pattern_hash = config->eudoxus_pattern_hash;

    rc = ib_mpool_create(&pool, "temp", NULL);
    if (rc != IB_OK) {
        return rc;
    }

    iterator = ib_hash_iterator_create(pool);
    if (iterator == NULL) {
        ib_mpool_destroy(pool);
        return IB_EALLOC;
    }
    for (
        ib_hash_iterator_first(iterator, eudoxus_pattern_hash);
        ! ib_hash_iterator_at_end(iterator);
        ib_hash_iterator_next(iterator)
    ) {
        ib_hash_iterator_fetch(NULL, NULL, &eudoxus, iterator);
        if (eudoxus != NULL) {
            ia_eudoxus_destroy(eudoxus);
        }
    }
    ib_hash_clear(eudoxus_pattern_hash);
    ib_mpool_release(pool);

    return IB_OK;
}
Beispiel #6
0
/**
 * Destroy the eudoxus state when the transaction is complete.
 *
 * After the transaction is complete iterate over all of the states create
 * during the transaction and destroy them.
 *
 * @param[in] ib IronBee engine.
 * @param[in] tx Current transaction.
 * @param[in] event Event type (should always be @ref tx_finished_event)
 * @param[in] cbdata Callback data -- pointer to this module (@ref ib_module_t).
 *
 * @returns IB_OK on success.
 */
static
ib_status_t ee_tx_finished_handler(ib_engine_t *ib,
                                   ib_tx_t *tx,
                                   ib_state_event_type_t event,
                                   void *cbdata)
{
    ib_status_t rc;
    ib_hash_t *hash;
    ib_mpool_t *pool;
    const ib_module_t *m = (const ib_module_t *)cbdata;
    ia_eudoxus_state_t *state;
    ib_hash_iterator_t *iterator;

    rc = ib_tx_get_module_data(tx, m, &hash);
    if (rc != IB_OK || hash == NULL) {
        return rc;
    }

    rc = ib_mpool_create(&pool, "temp", NULL);
    if (rc != IB_OK) {
        return rc;
    }

    iterator = ib_hash_iterator_create(pool);
    if (iterator == NULL) {
        ib_mpool_destroy(pool);
        return IB_EALLOC;
    }
    for (
        ib_hash_iterator_first(iterator, hash);
        ! ib_hash_iterator_at_end(iterator);
        ib_hash_iterator_next(iterator)
    ) {
        ib_hash_iterator_fetch(NULL, NULL, &state, iterator);
        if (state != NULL) {
            ia_eudoxus_destroy_state(state);
            state = NULL;
        }
    }

    ib_mpool_destroy(pool);

    return IB_OK;
}
 virtual void SetUp()
 {
     ASSERT_EQ(IB_OK, ib_mpool_create(&m_mp, "ResourcePoolTest", NULL));
     m_cbdata.mm = ib_mm_mpool(m_mp);
     void *cbdata = reinterpret_cast<void *>(&m_cbdata);
     ASSERT_EQ(IB_OK, ib_resource_pool_create(
         &m_rp,
         ib_mm_mpool(m_mp),
         1,
         10,
         &create_fn,
         cbdata,
         &destroy_fn,
         cbdata,
         &preuse_fn,
         cbdata,
         &postuse_fn,
         cbdata
     ));
 }
Beispiel #8
0
/*********************************
 * Helper Functions
 *********************************/
static
ib_status_t sqli_create_pattern_set_from_file(
    sqli_pattern_set_t **out_ps,
    const char         *path,
    ib_mpool_t         *mp
)
{
    assert(out_ps != NULL);
    assert(path   != NULL);
    assert(mp     != NULL);

    ib_status_t  rc;
    FILE               *fp          = NULL;
    char               *buffer      = NULL;
    size_t              buffer_size = 0;
    ib_list_t          *items       = NULL;
    ib_list_node_t     *n           = NULL;
    ib_mpool_t         *tmp         = NULL;
    sqli_pattern_set_t *ps          = NULL;
    size_t              i           = 0;

    /* Temporary memory pool for this function only. */
    rc = ib_mpool_create(&tmp, "sqli tmp", NULL);
    assert(rc == IB_OK);
    assert(tmp != NULL);

    fp = fopen(path, "r");
    if (fp == NULL) {
        goto fail;
    }

    rc = ib_list_create(&items, tmp);
    assert(rc    == IB_OK);
    assert(items != NULL);

    for (;;) {
        char *buffer_copy;
        int   read = getline(&buffer, &buffer_size, fp);

        if (read == -1) {
            if (! feof(fp)) {
                fclose(fp);
                goto fail;
            }
            else {
                break;
            }
        }

        buffer_copy = ib_mpool_memdup(mp, buffer, read);
        assert(buffer_copy != NULL);
        while (buffer_copy[read-1] == '\n' || buffer_copy[read-1] == '\r') {
            buffer_copy[read-1] = '\0';
            --read;
        }

        rc = ib_list_push(items, (void *)buffer_copy);
        assert(rc == IB_OK);
    }

    fclose(fp);

    ps = ib_mpool_alloc(mp, sizeof(*ps));
    assert(ps != NULL);

    ps->num_patterns = ib_list_elements(items);
    ps->patterns =
        ib_mpool_alloc(mp, ps->num_patterns * sizeof(*ps->patterns));
    assert(ps->patterns != NULL);

    i = 0;
    IB_LIST_LOOP(items, n) {
        ps->patterns[i] = ib_list_node_data(n);
        ++i;
    }
Beispiel #9
0
/**
 * Initialize the eudoxus operator module.
 *
 * Registers the operators and the hash for storing the eudoxus engine
 * instances created by the LoadEudoxus directive.
 *
 * @param[in] ib Ironbee engine.
 * @param[in] m Module instance.
 * @param[in] cbdata Not used.
 */
static
ib_status_t ee_module_init(ib_engine_t *ib,
                           ib_module_t *m,
                           void        *cbdata)
{
    ib_status_t rc;
    ib_mpool_t *main_mp;
    ib_mpool_t *mod_mp;
    ee_config_t *config;

    main_mp = ib_engine_pool_main_get(ib);
    config = ee_get_config(ib);
    assert(config != NULL);

    rc = ib_mpool_create(&mod_mp, "ee_module", main_mp);
    if (rc != IB_OK ) {
        ib_log_error(ib, MODULE_NAME_STR ": Error allocating module mpool.");
        return rc;
    }
    if (config->eudoxus_pattern_hash == NULL) {
        rc = ib_hash_create_nocase(&(config->eudoxus_pattern_hash), mod_mp);
        if (rc != IB_OK ) {
            ib_log_error(ib, MODULE_NAME_STR ": Error initializing module.");
            return rc;
        }
    }

    rc = ib_operator_create_and_register(
        NULL,
        ib,
        "ee_match_any",
        ( IB_OP_CAPABILITY_NON_STREAM |
          IB_OP_CAPABILITY_STREAM |
          IB_OP_CAPABILITY_CAPTURE ),
        &ee_match_any_operator_create, NULL,
        NULL, NULL,
        &ee_match_any_operator_execute, m
    );

    if (rc != IB_OK) {
        ib_log_error(
            ib,
            "Failed to register ee_match_any operator: %s",
            ib_status_to_string(rc));
        return rc;
    }

    rc = ib_hook_tx_register(ib,
                             tx_finished_event,
                             ee_tx_finished_handler,
                             m);

    if (rc != IB_OK) {
        ib_log_error(
            ib,
            "Failed to register transaction finished event for ee_match_any operator: %s",
            ib_status_to_string(rc));
        return rc;
    }

    return IB_OK;
}