Пример #1
0
ib_status_t ib_bytestr_dup_mem(
    ib_bytestr_t  **pdst,
    ib_mpool_t     *pool,
    const uint8_t  *data,
    size_t          data_length
) {
    IB_FTRACE_INIT();

    assert(pdst != NULL);
    assert(pool != NULL);

    if (data == NULL && data_length != 0) {
        IB_FTRACE_RET_STATUS(IB_EINVAL);
    }

    ib_status_t rc = ib_bytestr_create(pdst, pool, data_length);
    if (rc != IB_OK) {
        IB_FTRACE_RET_STATUS(rc);
    }

    if (data != NULL) {
        assert((*pdst)->size >= data_length);

        memcpy(ib_bytestr_ptr(*pdst), data, data_length);
        (*pdst)->length = data_length;
    }
    IB_FTRACE_RET_STATUS(IB_OK);
}
Пример #2
0
ib_status_t ib_bytestr_dup_mem(
    ib_bytestr_t  **pdst,
    ib_mm_t         mm,
    const uint8_t  *data,
    size_t          data_length
) {
    assert(pdst != NULL);

    if (data == NULL && data_length != 0) {
        return IB_EINVAL;
    }

    ib_status_t rc = ib_bytestr_create(pdst, mm, data_length);
    if (rc != IB_OK) {
        return rc;
    }

    if (data != NULL) {
        assert((*pdst)->size >= data_length);

        memcpy(ib_bytestr_ptr(*pdst), data, data_length);
        (*pdst)->length = data_length;
    }
    return IB_OK;
}
Пример #3
0
Файл: tfn.c Проект: niq/ironbee
ib_status_t ib_tfn_transform_field(ib_tfn_t *tfn,
                                   ib_field_t *f,
                                   ib_flags_t *pflags)
{
    IB_FTRACE_INIT(ib_tfn_transform);
    ib_bytestr_t *bs;
    char *str;
    uint8_t *data_out;
    size_t dlen_out;
    ib_status_t rc;

    switch(f->type) {
        case IB_FTYPE_BYTESTR:
            bs = ib_field_value_bytestr(f);

            rc = tfn->transform(tfn->fndata,
                                f->mp,
                                ib_bytestr_ptr(bs),
                                ib_bytestr_length(bs),
                                &data_out,
                                &dlen_out,
                                pflags);

            /* If it is modified and not done inplace, then the
             * field value needs to be updated.
             */
            if (   IB_TFN_CHECK_FMODIFIED(*pflags)
                && !IB_TFN_CHECK_FINPLACE(*pflags))
            {
                ib_bytestr_t *bs_new;

                rc = ib_bytestr_alias_mem(&bs_new, f->mp, data_out, dlen_out);
                if (rc != IB_OK) {
                    IB_FTRACE_RET_STATUS(rc);
                }

                rc = ib_field_setv(f, bs_new);
            }

            IB_FTRACE_RET_STATUS(rc);

        case IB_FTYPE_NULSTR:
            str = ib_field_value_nulstr(f),

            rc = tfn->transform(tfn->fndata,
                                f->mp,
                                (uint8_t *)str,
                                strlen(str),
                                &data_out,
                                &dlen_out,
                                pflags);

            /* If it is modified and not done inplace, then the
             * field value needs to be updated.
             *
             * NOTE: Anytime a transformation modifies data it
             *       MUST NUL terminate the data and it is a bug
             *       if this is not done.
             */
            if (   IB_TFN_CHECK_FMODIFIED(*pflags)
                && !IB_TFN_CHECK_FINPLACE(*pflags))
            {
                rc = ib_field_setv(f, data_out);
            }

            IB_FTRACE_RET_STATUS(rc);
    }


    IB_FTRACE_RET_STATUS(IB_EINVAL);
}
Пример #4
0
/**
 * Create an alias list collection.
 *
 * @param ib Engine.
 * @param tx Transaction.
 * @param name Collection name
 * @param header Header list to alias
 *
 * @returns Status code
 */
static ib_status_t create_header_alias_list(
    ib_engine_t *ib,
    ib_tx_t *tx,
    const char *name,
    ib_parsed_header_wrapper_t *header)
{
    ib_field_t *f;
    ib_list_t *header_list;
    ib_status_t rc;
    ib_parsed_name_value_pair_list_t *nvpair;

    assert(ib != NULL);
    assert(tx != NULL);
    assert(name != NULL);
    assert(header != NULL);

    /* Create the list */
    rc = ib_data_get(tx->data, name, &f);
    if (rc == IB_ENOENT) {
        rc = ib_data_add_list(tx->data, name, &f);
        if (rc != IB_OK) {
            return rc;
        }
    }
    else if (rc != IB_OK) {
        return rc;
    }
    rc = ib_field_mutable_value(f, ib_ftype_list_mutable_out(&header_list));
    if (rc != IB_OK) {
        return rc;
    }

    /* Loop through the list & alias everything */
    for(nvpair = header->head;  nvpair != NULL;  nvpair = nvpair->next) {
        assert(nvpair);
        assert(nvpair->value);
        ib_bytestr_t *bs = NULL;
        if (ib_bytestr_ptr(nvpair->value) != NULL) {
            rc = ib_bytestr_alias_mem(
                &bs,
                tx->mp,
                ib_bytestr_ptr(nvpair->value),
                ib_bytestr_length(nvpair->value)
            );
        }
        else {
            rc = ib_bytestr_dup_mem(&bs, tx->mp, (const uint8_t *)"", 0);
        }
        if (rc != IB_OK) {
            ib_log_error_tx(
                tx,
                "Error creating bytestring of '%.*s' for %s: %s",
                (int)ib_bytestr_length(nvpair->name),
                (const char *)ib_bytestr_ptr(nvpair->name),
                name,
                ib_status_to_string(rc)
            );
            return rc;
        }

        /* Create a byte string field */
        rc = ib_field_create(
            &f,
            tx->mp,
            (const char *)ib_bytestr_const_ptr(nvpair->name),
            ib_bytestr_length(nvpair->name),
            IB_FTYPE_BYTESTR,
            ib_ftype_bytestr_in(bs)
        );
        if (rc != IB_OK) {
            ib_log_error_tx(tx,
                            "Error creating field of '%.*s' for %s: %s",
                            (int)ib_bytestr_length(nvpair->name),
                            (const char *)ib_bytestr_ptr(nvpair->name),
                            name,
                            ib_status_to_string(rc));
            return rc;
        }

        /* Add the field to the list */
        rc = ib_list_push(header_list, f);
        if (rc != IB_OK) {
            ib_log_error_tx(tx, "Error adding alias of '%.*s' to %s list: %s",
                            (int)ib_bytestr_length(nvpair->name),
                            (const char *)ib_bytestr_ptr(nvpair->name),
                            name,
                            ib_status_to_string(rc));
            return rc;
        }
    }

    return IB_OK;
}