You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

153 lines
3.6 KiB

  1. /*
  2. * Column definition functions
  3. *
  4. * Copyright (C) 2008-2019, Joachim Metz <joachim.metz@gmail.com>
  5. *
  6. * Refer to AUTHORS for acknowledgements.
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. #include <common.h>
  22. #include <memory.h>
  23. #include <types.h>
  24. #include "libpff_column_definition.h"
  25. #include "libpff_libcerror.h"
  26. #include "libpff_table.h"
  27. #include "libpff_types.h"
  28. /* Creates a column definition
  29. * Make sure the value column_definition is referencing, is set to NULL
  30. * Returns 1 if successful or -1 on error
  31. */
  32. int libpff_column_definition_initialize(
  33. libpff_column_definition_t **column_definition,
  34. libcerror_error_t **error )
  35. {
  36. static char *function = "libpff_column_definition_initialize";
  37. if( column_definition == NULL )
  38. {
  39. libcerror_error_set(
  40. error,
  41. LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
  42. LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
  43. "%s: invalid column_definition.",
  44. function );
  45. return( -1 );
  46. }
  47. if( *column_definition != NULL )
  48. {
  49. libcerror_error_set(
  50. error,
  51. LIBCERROR_ERROR_DOMAIN_RUNTIME,
  52. LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
  53. "%s: invalid column definition value already set.",
  54. function );
  55. return( -1 );
  56. }
  57. *column_definition = memory_allocate_structure(
  58. libpff_column_definition_t );
  59. if( *column_definition == NULL )
  60. {
  61. libcerror_error_set(
  62. error,
  63. LIBCERROR_ERROR_DOMAIN_RUNTIME,
  64. LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
  65. "%s: unable to create column definition.",
  66. function );
  67. goto on_error;
  68. }
  69. if( memory_set(
  70. *column_definition,
  71. 0,
  72. sizeof( libpff_column_definition_t ) ) == NULL )
  73. {
  74. libcerror_error_set(
  75. error,
  76. LIBCERROR_ERROR_DOMAIN_MEMORY,
  77. LIBCERROR_MEMORY_ERROR_SET_FAILED,
  78. "%s: unable to clear column definition.",
  79. function );
  80. goto on_error;
  81. }
  82. return( 1 );
  83. on_error:
  84. if( *column_definition != NULL )
  85. {
  86. memory_free(
  87. *column_definition );
  88. *column_definition = NULL;
  89. }
  90. return( -1 );
  91. }
  92. /* Frees a column definition
  93. * Returns 1 if successful or -1 on error
  94. */
  95. int libpff_column_definition_free(
  96. libpff_column_definition_t **column_definition,
  97. libcerror_error_t **error )
  98. {
  99. static char *function = "libpff_column_definition_free";
  100. int result = 1;
  101. if( column_definition == NULL )
  102. {
  103. libcerror_error_set(
  104. error,
  105. LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
  106. LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
  107. "%s: invalid column definition.",
  108. function );
  109. return( -1 );
  110. }
  111. if( *column_definition != NULL )
  112. {
  113. /* The name_to_id_map_entry reference is freed elsewhere
  114. */
  115. if( ( *column_definition )->record_entry_values_table != NULL )
  116. {
  117. if( libpff_table_free(
  118. &( ( *column_definition )->record_entry_values_table ),
  119. error ) != 1 )
  120. {
  121. libcerror_error_set(
  122. error,
  123. LIBCERROR_ERROR_DOMAIN_RUNTIME,
  124. LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
  125. "%s: unable to free record entry values table.",
  126. function );
  127. result = -1;
  128. }
  129. }
  130. memory_free(
  131. *column_definition );
  132. *column_definition = NULL;
  133. }
  134. return( result );
  135. }