Exemplo n.º 1
0
/**
 * Get or create an ib_hash_t inside of @c tx for storing the operator state.
 *
 * The hash is stored at the key @c HASH_NAME_STR.
 *
 * @param[in] m  This module.
 * @param[in] tx The transaction containing @c tx->data which holds
 *            the @a operator_data object.
 * @param[out] hash 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_operator_data_hash(
    const ib_module_t  *m,
    ib_tx_t            *tx,
    ib_hash_t         **hash
)
{
    assert(tx != NULL);

    ib_status_t rc;

    /* Get or create the hash that contains the rule data. */
    rc = ib_tx_get_module_data(tx, m, hash);
    if ( (rc == IB_OK) && (*hash != NULL) ) {
        return IB_OK;
    }

    rc = ib_hash_create(hash, tx->mm);
    if (rc != IB_OK) {
        return rc;
    }

    rc = ib_tx_set_module_data(tx, m, *hash);
    if (rc != IB_OK) {
        *hash = NULL;
    }

    return rc;
}
Exemplo n.º 2
0
Arquivo: pcre.c Projeto: niubl/ironbee
/**
 * Get or create an ib_hash_t inside of @c tx for storing dfa rule data.
 *
 * The hash is stored at the key @c HASH_NAME_STR.
 *
 * @param[in] m  PCRE module.
 * @param[in] tx The transaction containing @c tx->data which holds
 *            the @a operator_data object.
 * @param[out] hash 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_operator_data_hash(
    const ib_module_t  *m,
    ib_tx_t            *tx,
    ib_hash_t         **hash
)
{
    assert(tx);
    assert(tx->mp);

    ib_status_t rc;

    /* Get or create the hash that contains the rule data. */
    rc = ib_tx_get_module_data(tx, m, hash);
    if ( (rc == IB_OK) && (*hash != NULL) ) {
        ib_log_debug2_tx(tx, "Found rule data hash in tx.");
        return IB_OK;
    }

    ib_log_debug2_tx(tx, "Rule data hash did not exist in tx.");

    rc = ib_hash_create(hash, tx->mp);
    if (rc != IB_OK) {
        ib_log_debug2_tx(tx, "Failed to create hash: %s",
                         ib_status_to_string(rc));
        return rc;
    }

    rc = ib_tx_set_module_data(tx, m, *hash);
    if (rc != IB_OK) {
        ib_log_debug2_tx(tx, "Failed to store hash: %s",
                         ib_status_to_string(rc));
        *hash = NULL;
    }

    ib_log_debug2_tx(tx, "Returning rule hash at %p.", *hash);

    return rc;

}