Ejemplo n.º 1
0
HooksRegistrar& HooksRegistrar::transaction_data(
    Engine::state_event_e event,
    transaction_data_t    f
)
{
    if (f.empty()) {
        BOOST_THROW_EXCEPTION(einval() << errinfo_what(
            "Empty functional passed to hook registrarion."
        ));
    }

    throw_if_error(
        ib_hook_txdata_register(
            m_engine.ib(),
            static_cast<ib_state_event_type_t>(event),
            &Internal::Hooks::transaction_data,
            value_to_data<transaction_data_t>(
                f,
                m_engine.main_memory_pool().ib()
            )
        )
    );

    return *this;
}
Ejemplo n.º 2
0
void check_type(Field::type_e expected, Field::type_e actual)
{
    if (expected != actual) {
        BOOST_THROW_EXCEPTION(
           einval() << errinfo_what(
              "Expected field type " + type_as_s(expected) +
              " but is field type " + type_as_s(actual)
           )
        );
    }
}
Ejemplo n.º 3
0
MemoryPool MemoryPool::create(
    const char* name,
    MemoryPool  parent
)
{
    if (! parent) {
        BOOST_THROW_EXCEPTION(
          einval() << errinfo_what(
            "Singular parent provided to memory pool."
          )
        );

    }
    return Internal::create_memory_pool(name, parent.ib());
}
Ejemplo n.º 4
0
std::string ConstField::to_s() const
{
    switch (type()) {
        case TIME:
            return boost::lexical_cast<std::string>(value_as_time());
        case NUMBER:
            return boost::lexical_cast<std::string>(value_as_number());
        case FLOAT:
            return
                boost::lexical_cast<std::string>(value_as_float());
        case NULL_STRING:
            return std::string(value_as_null_string());
        case BYTE_STRING:
            return value_as_byte_string().to_s();
        default:
            BOOST_THROW_EXCEPTION(
                einval() << errinfo_what(
                    "ConstField::to_s() does not support field type: " +
                    Internal::type_as_s(type())
                )
            );
    }
}
Ejemplo n.º 5
0
ib_status_t field_dynamic_set(
    ib_field_t* field,
    const void* arg,
    size_t      arg_length,
    void*       in_value,
    void*       cbdata
)
{
    const char* carg = reinterpret_cast<const char*>(arg);

    // No engine available.
    try {
        switch (field->type) {
            case IB_FTYPE_TIME:
                data_to_value<Field::time_set_t>(cbdata)(
                    Field(field),
                    carg, arg_length,
                    *reinterpret_cast<const uint64_t*>(in_value)
                );
                break;
            case IB_FTYPE_NUM:
                data_to_value<Field::number_set_t>(cbdata)(
                    Field(field),
                    carg, arg_length,
                    *reinterpret_cast<const int64_t*>(in_value)
                );
                break;
            case IB_FTYPE_FLOAT:
                data_to_value<Field::float_set_t>(cbdata)(
                    Field(field),
                    carg, arg_length,
                    *reinterpret_cast<const long double*>(in_value)
                );
                break;
            case IB_FTYPE_NULSTR:
                data_to_value<Field::null_string_set_t>(cbdata)(
                    Field(field),
                    carg, arg_length,
                    reinterpret_cast<const char*>(in_value)
                );
                break;
            case IB_FTYPE_BYTESTR: {
                // Const cast, but then immeidately store as const.
                const ConstByteString value(
                    reinterpret_cast<const ib_bytestr_t*>(in_value)
                );
                data_to_value<Field::byte_string_set_t>(cbdata)(
                    Field(field),
                    carg, arg_length,
                    value
                );
                break;
            }
            case IB_FTYPE_LIST: {
                const ib_list_t* value =
                    reinterpret_cast<const ib_list_t*>(in_value);
                data_to_value<
                    Internal::dynamic_list_setter_translator_t
                >(cbdata)(
                    Field(field),
                    carg, arg_length,
                    value
                );
                break;
            }
            default:
                BOOST_THROW_EXCEPTION(
                    einval() << errinfo_what(
                        "Unsupported field type: " + type_as_s(field->type)
                    )
                );
        }
    }
    catch (...) {
        return convert_exception();
    }
    return IB_OK;
}
Ejemplo n.º 6
0
ib_status_t field_dynamic_get(
    const ib_field_t* field,
    void*             out_val,
    const void*       arg,
    size_t            arg_length,
    void*             cbdata
)
{
    // We will only pass this as as a const reference.
    ConstField fieldpp(field);

    const char* carg = reinterpret_cast<const char*>(arg);

    // No engine available.
    ib_status_t rc = IB_OK;
    try {
        switch (field->type) {
            case IB_FTYPE_TIME: {
                ib_time_t* n = reinterpret_cast<ib_time_t*>(out_val);
                *n = data_to_value<Field::time_get_t>(cbdata)(
                    fieldpp, carg, arg_length
                );
                return IB_OK;
            }
            case IB_FTYPE_NUM: {
                ib_num_t* n = reinterpret_cast<ib_num_t*>(out_val);
                *n = data_to_value<Field::number_get_t>(cbdata)(
                    fieldpp, carg, arg_length
                );
                return IB_OK;
            }
            case IB_FTYPE_FLOAT: {
                ib_float_t* u = reinterpret_cast<ib_float_t*>(out_val);
                *u = data_to_value<
                    Field::float_get_t
                >(cbdata)(
                    fieldpp, carg, arg_length
                );
                return IB_OK;
            }
            case IB_FTYPE_NULSTR:
            {
                const char** ns = reinterpret_cast<const char**>(out_val);
                *ns = data_to_value<
                    Field::null_string_get_t
                >(cbdata)(
                    fieldpp, carg, arg_length
                );
                return IB_OK;
            }
            case IB_FTYPE_BYTESTR:
            {
                const ib_bytestr_t** bs
                    = reinterpret_cast<const ib_bytestr_t**>(out_val);
                *bs = data_to_value<
                    Field::byte_string_get_t
                >(cbdata)(
                    fieldpp, carg, arg_length
                ).ib();
                return IB_OK;
            }
            case IB_FTYPE_LIST:
            {
                const ib_list_t** l
                    = reinterpret_cast<const ib_list_t**>(out_val);
                *l = data_to_value<
                    Internal::dynamic_list_getter_translator_t
                >(cbdata)(
                    fieldpp, carg, arg_length
                );
                return IB_OK;
            }
            default:
                BOOST_THROW_EXCEPTION(
                    einval() << errinfo_what(
                        "Unsupported field type: " + type_as_s(field->type)
                    )
                );
        }
    }
    catch (...) {
        return convert_exception();
    }

    // If we got here, it is in error.
    assert(rc != IB_OK);
    return rc;
}
Ejemplo n.º 7
0
int
main(int argc, char **argv)
{
#ifdef USE_LIBICONV_DLL
    /* test use of dll if $DEFAULT_LIBICONV_DLL was defined. */
    if (setdll(""))
    {
        success("ascii", "ABC", "ascii", "ABC");
        success("ascii", "ABC", "utf-16be", "\x00\x41\x00\x42\x00\x43");
    }
    else
    {
        printf("\nDLL TEST IS SKIPPED\n\n");
    }

    setdll("none");
#endif

    if (check_enc("ascii", 20127))
    {
        success("ascii", "ABC", "ascii", "ABC");
        eilseq("ascii", "\x80", "ascii", "");
        eilseq("ascii", "\xFF", "ascii", "");
    }

    /* unicode (CP1200 CP1201 CP12000 CP12001 CP65001) */
    if (check_enc("utf-8", 65001)
            && check_enc("utf-16be", 1201) && check_enc("utf-16le", 1200)
            && check_enc("utf-32be", 12001) && check_enc("utf-32le", 12000)
            )
    {
        /* Test the BOM behavior
         * 1. Remove the BOM when "fromcode" is utf-16 or utf-32.
         * 2. Add the BOM when "tocode" is utf-16 or utf-32.  */
        success("utf-16", "\xFE\xFF\x01\x02", "utf-16be", "\x01\x02");
        success("utf-16", "\xFF\xFE\x02\x01", "utf-16be", "\x01\x02");
        success("utf-32", "\x00\x00\xFE\xFF\x00\x00\x01\x02", "utf-32be", "\x00\x00\x01\x02");
        success("utf-32", "\xFF\xFE\x00\x00\x02\x01\x00\x00", "utf-32be", "\x00\x00\x01\x02");
        success("utf-16", "\xFE\xFF\x00\x01", "utf-8", "\x01");
#ifndef GLIB_COMPILATION
        success("utf-8", "\x01", "utf-16", "\xFE\xFF\x00\x01");
        success("utf-8", "\x01", "utf-32", "\x00\x00\xFE\xFF\x00\x00\x00\x01");
#else
        success("utf-8", "\x01", "utf-16", "\xFF\xFE\x01\x00");
        success("utf-8", "\x01", "utf-32", "\xFF\xFE\x00\x00\x01\x00\x00\x00");
#endif

        success("utf-16be", "\xFE\xFF\x01\x02", "utf-16be", "\xFE\xFF\x01\x02");
        success("utf-16le", "\xFF\xFE\x02\x01", "utf-16be", "\xFE\xFF\x01\x02");
        success("utf-32be", "\x00\x00\xFE\xFF\x00\x00\x01\x02", "utf-32be", "\x00\x00\xFE\xFF\x00\x00\x01\x02");
        success("utf-32le", "\xFF\xFE\x00\x00\x02\x01\x00\x00", "utf-32be", "\x00\x00\xFE\xFF\x00\x00\x01\x02");
        success("utf-16be", "\xFE\xFF\x00\x01", "utf-8", "\xEF\xBB\xBF\x01");
        success("utf-8", "\xEF\xBB\xBF\x01", "utf-8", "\xEF\xBB\xBF\x01");

        success("utf-16be", "\x01\x02", "utf-16le", "\x02\x01");
        success("utf-16le", "\x02\x01", "utf-16be", "\x01\x02");
        success("utf-16be", "\xFE\xFF", "utf-16le", "\xFF\xFE");
        success("utf-16le", "\xFF\xFE", "utf-16be", "\xFE\xFF");
        success("utf-32be", "\x00\x00\x03\x04", "utf-32le", "\x04\x03\x00\x00");
        success("utf-32le", "\x04\x03\x00\x00", "utf-32be", "\x00\x00\x03\x04");
        success("utf-32be", "\x00\x00\xFF\xFF", "utf-16be", "\xFF\xFF");
        success("utf-16be", "\xFF\xFF", "utf-32be", "\x00\x00\xFF\xFF");
        success("utf-32be", "\x00\x01\x00\x00", "utf-16be", "\xD8\x00\xDC\x00");
        success("utf-16be", "\xD8\x00\xDC\x00", "utf-32be", "\x00\x01\x00\x00");
        success("utf-32be", "\x00\x10\xFF\xFF", "utf-16be", "\xDB\xFF\xDF\xFF");
        success("utf-16be", "\xDB\xFF\xDF\xFF", "utf-32be", "\x00\x10\xFF\xFF");
        eilseq("utf-32be", "\x00\x11\x00\x00", "utf-16be", "");
        eilseq("utf-16be", "\xDB\xFF\xE0\x00", "utf-32be", "");
        success("utf-8", "\xE3\x81\x82", "utf-16be", "\x30\x42");
        einval("utf-8", "\xE3", "utf-16be", "");
    }

    /* Japanese (CP932 CP20932 CP50220 CP50221 CP50222 CP51932) */
    if (check_enc("cp932", 932)
            && check_enc("cp20932", 20932) && check_enc("euc-jp", 51932)
            && check_enc("cp50220", 50220) && check_enc("cp50221", 50221)
            && check_enc("cp50222", 50222) && check_enc("iso-2022-jp", 50221))
    {
        /* Test the compatibility for each other Japanese codepage.
         * And validate the escape sequence handling for iso-2022-jp. */
        success("utf-16be", "\xFF\x5E", "cp932", "\x81\x60");
        success("utf-16be", "\x30\x1C", "cp932", "\x81\x60");
        success("utf-16be", "\xFF\x5E", "cp932//nocompat", "\x81\x60");
        eilseq("utf-16be", "\x30\x1C", "cp932//nocompat", "");
        success("euc-jp", "\xA4\xA2", "utf-16be", "\x30\x42");
        einval("euc-jp", "\xA4\xA2\xA4", "utf-16be", "\x30\x42");
        eilseq("euc-jp", "\xA4\xA2\xFF\xFF", "utf-16be", "\x30\x42");
        success("cp932", "\x81\x60", "iso-2022-jp", "\x1B\x24\x42\x21\x41\x1B\x28\x42");
        success("UTF-16BE", "\xFF\x5E", "iso-2022-jp", "\x1B\x24\x42\x21\x41\x1B\x28\x42");
        eilseq("UTF-16BE", "\x30\x1C", "iso-2022-jp//nocompat", "");
        success("UTF-16BE", "\x30\x42\x30\x44", "iso-2022-jp", "\x1B\x24\x42\x24\x22\x24\x24\x1B\x28\x42");
        success("iso-2022-jp", "\x1B\x24\x42\x21\x41\x1B\x28\x42", "UTF-16BE", "\xFF\x5E");
    }

    /*
     * test for //translit
     * U+FF41 (FULLWIDTH LATIN SMALL LETTER A) <-> U+0062 (LATIN SMALL LETTER A)
     */
    eilseq("UTF-16BE", "\xFF\x41", "iso-8859-1", "");
    success("UTF-16BE", "\xFF\x41", "iso-8859-1//translit", "a");

    /*
     * test for //translit
     * Some character, not in "to" encoding -> DEFAULT CHARACTER (maybe "?")
     */
    eilseq("UTF-16BE", "\x30\x42", "ascii", "");
    success("UTF-16BE", "\x30\x42", "ascii//translit", "?");

    /*
     * test for //ignore
     */
    eilseq("UTF-8", "\xFF A \xFF B", "ascii//ignore", " A  B");
    eilseq("UTF-8", "\xEF\xBC\xA1 A \xEF\xBC\xA2 B", "ascii//ignore", " A  B");
    eilseq("UTF-8", "\xEF\x01 A \xEF\x02 B", "ascii//ignore", "\x01 A \x02 B");

    /*
     * TODO:
     * Test for state after iconv() failed.
     * Ensure iconv() error is safe and continuable.
     */

    return 0;
}