Exemplo n.º 1
0
int idmef_message_get_data(idmef_message_t *message, const char *path, unsigned char **data, size_t *size)
{
        int ret;
        idmef_data_t *dp;
        idmef_value_t *iv;

        ret = idmef_message_get_value(message, path, &iv);
        if ( ret <= 0 )
                return ret;

        if ( idmef_value_get_type(iv) != IDMEF_VALUE_TYPE_DATA || ! (dp = idmef_value_get_data(iv)) ) {
                ret = -1;
                goto err;
        }

        *size = idmef_data_get_len(dp);
        *data = malloc(*size);
        if ( ! *data ) {
                ret = -1;
                goto err;
        }

        memcpy(*data, idmef_data_get_data(dp), *size);

err:
        idmef_value_destroy(iv);
        return ret;
}
Exemplo n.º 2
0
static void cast_int8(void)
{
        idmef_value_t *value;

        assert(idmef_value_new_int8(&value, INT8_MIN) == 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_UINT8, -1) < 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_UINT16, -1) < 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_UINT32, -1) < 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_UINT64, -1) < 0);

        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_INT16, -1) == 0);
        assert(idmef_value_get_type(value) == IDMEF_VALUE_TYPE_INT16);
        assert(idmef_value_get_int16(value) == INT8_MIN);
        idmef_value_destroy(value);

        assert(idmef_value_new_int8(&value, INT8_MIN) == 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_INT32, -1) == 0);
        assert(idmef_value_get_type(value) == IDMEF_VALUE_TYPE_INT32);
        assert(idmef_value_get_int32(value) == INT8_MIN);
        idmef_value_destroy(value);

        assert(idmef_value_new_int8(&value, INT8_MIN) == 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_INT64, -1) == 0);
        assert(idmef_value_get_type(value) == IDMEF_VALUE_TYPE_INT64);
        assert(idmef_value_get_int64(value) == INT8_MIN);
        idmef_value_destroy(value);

        assert(idmef_value_new_int8(&value, INT8_MIN) == 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_FLOAT, -1) == 0);
        assert(idmef_value_get_type(value) == IDMEF_VALUE_TYPE_FLOAT);
        assert(idmef_value_get_float(value) == INT8_MIN);
        idmef_value_destroy(value);

        assert(idmef_value_new_int8(&value, INT8_MIN) == 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_DOUBLE, -1) == 0);
        assert(idmef_value_get_type(value) == IDMEF_VALUE_TYPE_DOUBLE);
        assert(idmef_value_get_double(value) == INT8_MIN);
        idmef_value_destroy(value);

        assert(idmef_value_new_int8(&value, INT8_MIN) == 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_DATA, -1) == 0);
        assert(idmef_value_get_type(value) == IDMEF_VALUE_TYPE_DATA);
        assert((int) idmef_data_get_uint32(idmef_value_get_data(value)) == INT8_MIN);
        idmef_value_destroy(value);
}
Exemplo n.º 3
0
static void cast_string(void)
{
        idmef_data_t *data;
        idmef_value_t *value;
        requiem_string_t *str;

        assert(requiem_string_new_ref(&str, "abcdefgh") == 0);
        assert(idmef_value_new_string(&value, str) == 0);
        idmef_value_dont_have_own_data(value);

        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_INT8, -1) < 0);
//        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_UINT8, -1) < 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_INT16, -1) < 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_UINT16, -1) < 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_INT32, -1) < 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_UINT32, -1) < 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_INT64, -1) < 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_UINT64, -1) < 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_FLOAT, -1) < 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_DOUBLE, -1) < 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_TIME, -1) < 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_ENUM, -1) < 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_LIST, -1) < 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_CLASS, -1) < 0);

        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_DATA, -1) == 0);
        assert(idmef_value_get_type(value) == IDMEF_VALUE_TYPE_DATA);
        assert(data = idmef_value_get_data(value));
        assert(idmef_data_get_len(data) == (requiem_string_get_len(str) + 1));
        assert(memcmp(requiem_string_get_string(str), idmef_data_get_data(data), idmef_data_get_len(data)) == 0);
        requiem_string_destroy(str);

        cast_data(value);
        idmef_value_destroy(value);

        assert(requiem_string_new_ref(&str, "2008-01-01 20:42:31") == 0);
        assert(idmef_value_new_string(&value, str) == 0);
        assert(_idmef_value_cast(value, IDMEF_VALUE_TYPE_TIME, -1) == 0);
        idmef_value_destroy(value);
}
Exemplo n.º 4
0
        const char *str = NULL;
        idmef_class_id_t class;
        struct regex_value *rv = cv->value;

        if ( idmef_value_get_type(value) == IDMEF_VALUE_TYPE_STRING )
                str = prelude_string_get_string(idmef_value_get_string(value));

        else if ( idmef_value_get_type(value) == IDMEF_VALUE_TYPE_ENUM ) {
                class = idmef_value_get_class(value);
                str = idmef_class_enum_to_string(class, idmef_value_get_enum(value));
        }

        else if ( idmef_value_get_type(value) == IDMEF_VALUE_TYPE_DATA ) {
                idmef_data_t *data;

                data = idmef_value_get_data(value);
                if ( idmef_data_get_type(data) == IDMEF_DATA_TYPE_CHAR_STRING )
                        str = idmef_data_get_data(data);
        }

        if ( ! str )
                return 0;

        ret = regexec(&rv->regex, str, 0, NULL, 0);
        if ( operator & IDMEF_CRITERION_OPERATOR_NOT )
                return (ret == REG_NOMATCH) ? 1 : 0;
        else
                return (ret != REG_NOMATCH) ? 1 : 0;
}