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; }
/** * idmef_message_get_string: * @message: Pointer to an #idmef_message_t object. * @path: Path to retrieve the string from within @message. * @result: Pointer where the result should be stored. * * Retrieve the string stored within @path of @message and store it * in the user provided @result. * * The caller is responssible for freeing @result. * * Returns: A positive value in case @path was successfully retrieved * 0 if the path is empty, or a negative value if an error occured. */ int idmef_message_get_string(idmef_message_t *message, const char *path, char **result) { int ret; idmef_value_t *iv; prelude_string_t *str; ret = idmef_message_get_value(message, path, &iv); if ( ret <= 0 ) return ret; if ( idmef_value_get_type(iv) != IDMEF_VALUE_TYPE_STRING ) { ret = _idmef_value_cast(iv, IDMEF_VALUE_TYPE_STRING, 0); if ( ret < 0 ) goto err; } if ( ! (str = idmef_value_get_string(iv)) ) { ret = -1; goto err; } ret = prelude_string_get_string_released(str, result); err: idmef_value_destroy(iv); return ret; }
/** * idmef_message_get_string: * @message: Pointer to an #idmef_message_t object. * @path: Path to retrieve the string from within @message. * @result: Pointer where the result should be stored. * * Retrieve the string stored within @path of @message and store it * in the user provided @result. * * The caller is responssible for freeing @result. * * Returns: A positive value in case @path was successfully retrieved * 0 if the path is empty, or a negative value if an error occured. */ int idmef_message_get_string(idmef_message_t *message, const char *path, char **result) { int ret; idmef_value_t *iv; prelude_string_t *str; ret = idmef_message_get_value(message, path, &iv); if ( ret <= 0 ) return ret; if ( idmef_value_get_type(iv) != IDMEF_VALUE_TYPE_STRING ) { ret = _idmef_value_cast(iv, IDMEF_VALUE_TYPE_STRING, 0); if ( ret < 0 ) goto err; } if ( ! (str = idmef_value_get_string(iv)) ) { ret = -1; goto err; } if ( prelude_string_is_empty(str) ) { *result = NULL; return 0; } *result = strdup(prelude_string_get_string(str)); ret = prelude_string_get_len(str); err: idmef_value_destroy(iv); return ret; }
/** * idmef_message_get_number: * @message: Pointer to an #idmef_message_t object. * @path: Path to retrieve the number from within @message. * @result: Pointer where the result should be stored. * * Retrieve the number stored within @path of @message and store it * in the user provided @result. * * Returns: A positive value in case @path was successfully retrieved * 0 if the path is empty, or a negative value if an error occured. */ int idmef_message_get_number(idmef_message_t *message, const char *path, double *result) { int ret; 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_DOUBLE ) { ret = _idmef_value_cast(iv, IDMEF_VALUE_TYPE_DOUBLE, 0); if ( ret < 0 ) goto err; } *result = idmef_value_get_double(iv); err: idmef_value_destroy(iv); return ret; }