/src/libewf/libewf/libewf_attribute.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Attribute functions |
3 | | * |
4 | | * Copyright (C) 2006-2024, 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 | | |
22 | | #include <common.h> |
23 | | #include <memory.h> |
24 | | #include <types.h> |
25 | | |
26 | | #include "libewf_attribute.h" |
27 | | #include "libewf_lef_extended_attribute.h" |
28 | | #include "libewf_libcerror.h" |
29 | | #include "libewf_libcthreads.h" |
30 | | #include "libewf_types.h" |
31 | | |
32 | | /* Creates a attribute |
33 | | * Make sure the value attribute is referencing, is set to NULL |
34 | | * Returns 1 if successful or -1 on error |
35 | | */ |
36 | | int libewf_attribute_initialize( |
37 | | libewf_attribute_t **attribute, |
38 | | libewf_lef_extended_attribute_t *lef_extended_attribute, |
39 | | libcerror_error_t **error ) |
40 | 0 | { |
41 | 0 | libewf_internal_attribute_t *internal_attribute = NULL; |
42 | 0 | static char *function = "libewf_attribute_initialize"; |
43 | |
|
44 | 0 | if( attribute == NULL ) |
45 | 0 | { |
46 | 0 | libcerror_error_set( |
47 | 0 | error, |
48 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
49 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
50 | 0 | "%s: invalid attribute.", |
51 | 0 | function ); |
52 | |
|
53 | 0 | return( -1 ); |
54 | 0 | } |
55 | 0 | if( *attribute != NULL ) |
56 | 0 | { |
57 | 0 | libcerror_error_set( |
58 | 0 | error, |
59 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
60 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
61 | 0 | "%s: invalid attribute value already set.", |
62 | 0 | function ); |
63 | |
|
64 | 0 | return( -1 ); |
65 | 0 | } |
66 | 0 | if( lef_extended_attribute == NULL ) |
67 | 0 | { |
68 | 0 | libcerror_error_set( |
69 | 0 | error, |
70 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
71 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
72 | 0 | "%s: invalid extended attribute.", |
73 | 0 | function ); |
74 | |
|
75 | 0 | return( -1 ); |
76 | 0 | } |
77 | 0 | internal_attribute = memory_allocate_structure( |
78 | 0 | libewf_internal_attribute_t ); |
79 | |
|
80 | 0 | if( internal_attribute == NULL ) |
81 | 0 | { |
82 | 0 | libcerror_error_set( |
83 | 0 | error, |
84 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
85 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
86 | 0 | "%s: unable to create attribute.", |
87 | 0 | function ); |
88 | |
|
89 | 0 | goto on_error; |
90 | 0 | } |
91 | 0 | if( memory_set( |
92 | 0 | internal_attribute, |
93 | 0 | 0, |
94 | 0 | sizeof( libewf_internal_attribute_t ) ) == NULL ) |
95 | 0 | { |
96 | 0 | libcerror_error_set( |
97 | 0 | error, |
98 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
99 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
100 | 0 | "%s: unable to clear attribute.", |
101 | 0 | function ); |
102 | |
|
103 | 0 | memory_free( |
104 | 0 | internal_attribute ); |
105 | |
|
106 | 0 | return( -1 ); |
107 | 0 | } |
108 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
109 | 0 | if( libcthreads_read_write_lock_initialize( |
110 | 0 | &( internal_attribute->read_write_lock ), |
111 | 0 | error ) != 1 ) |
112 | 0 | { |
113 | 0 | libcerror_error_set( |
114 | 0 | error, |
115 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
116 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
117 | 0 | "%s: unable to initialize read/write lock.", |
118 | 0 | function ); |
119 | |
|
120 | 0 | goto on_error; |
121 | 0 | } |
122 | 0 | #endif |
123 | 0 | internal_attribute->lef_extended_attribute = lef_extended_attribute; |
124 | |
|
125 | 0 | *attribute = (libewf_attribute_t *) internal_attribute; |
126 | |
|
127 | 0 | return( 1 ); |
128 | | |
129 | 0 | on_error: |
130 | 0 | if( internal_attribute != NULL ) |
131 | 0 | { |
132 | 0 | memory_free( |
133 | 0 | internal_attribute ); |
134 | 0 | } |
135 | 0 | return( -1 ); |
136 | 0 | } |
137 | | |
138 | | /* Frees a attribute |
139 | | * Returns 1 if successful or -1 on error |
140 | | */ |
141 | | int libewf_attribute_free( |
142 | | libewf_attribute_t **attribute, |
143 | | libcerror_error_t **error ) |
144 | 0 | { |
145 | 0 | libewf_internal_attribute_t *internal_attribute = NULL; |
146 | 0 | static char *function = "libewf_attribute_free"; |
147 | 0 | int result = 1; |
148 | |
|
149 | 0 | if( attribute == NULL ) |
150 | 0 | { |
151 | 0 | libcerror_error_set( |
152 | 0 | error, |
153 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
154 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
155 | 0 | "%s: invalid attribute.", |
156 | 0 | function ); |
157 | |
|
158 | 0 | return( -1 ); |
159 | 0 | } |
160 | 0 | if( *attribute != NULL ) |
161 | 0 | { |
162 | 0 | internal_attribute = (libewf_internal_attribute_t *) *attribute; |
163 | 0 | *attribute = NULL; |
164 | |
|
165 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
166 | 0 | if( libcthreads_read_write_lock_free( |
167 | 0 | &( internal_attribute->read_write_lock ), |
168 | 0 | error ) != 1 ) |
169 | 0 | { |
170 | 0 | libcerror_error_set( |
171 | 0 | error, |
172 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
173 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
174 | 0 | "%s: unable to free read/write lock.", |
175 | 0 | function ); |
176 | |
|
177 | 0 | result = -1; |
178 | 0 | } |
179 | 0 | #endif |
180 | 0 | memory_free( |
181 | 0 | internal_attribute ); |
182 | 0 | } |
183 | 0 | return( result ); |
184 | 0 | } |
185 | | |
186 | | /* Retrieves the size of the UTF-8 encoded name |
187 | | * The returned size includes the end of string character |
188 | | * Returns 1 if successful, 0 if not set or -1 on error |
189 | | */ |
190 | | int libewf_attribute_get_utf8_name_size( |
191 | | libewf_attribute_t *attribute, |
192 | | size_t *utf8_string_size, |
193 | | libcerror_error_t **error ) |
194 | 0 | { |
195 | 0 | libewf_internal_attribute_t *internal_attribute = NULL; |
196 | 0 | static char *function = "libewf_attribute_get_utf8_name_size"; |
197 | 0 | int result = 0; |
198 | |
|
199 | 0 | if( attribute == NULL ) |
200 | 0 | { |
201 | 0 | libcerror_error_set( |
202 | 0 | error, |
203 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
204 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
205 | 0 | "%s: invalid attribute.", |
206 | 0 | function ); |
207 | |
|
208 | 0 | return( -1 ); |
209 | 0 | } |
210 | 0 | internal_attribute = (libewf_internal_attribute_t *) attribute; |
211 | |
|
212 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
213 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
214 | 0 | internal_attribute->read_write_lock, |
215 | 0 | error ) != 1 ) |
216 | 0 | { |
217 | 0 | libcerror_error_set( |
218 | 0 | error, |
219 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
220 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
221 | 0 | "%s: unable to grab read/write lock for reading.", |
222 | 0 | function ); |
223 | |
|
224 | 0 | return( -1 ); |
225 | 0 | } |
226 | 0 | #endif |
227 | 0 | result = libewf_lef_extended_attribute_get_utf8_name_size( |
228 | 0 | internal_attribute->lef_extended_attribute, |
229 | 0 | utf8_string_size, |
230 | 0 | error ); |
231 | |
|
232 | 0 | if( result == -1 ) |
233 | 0 | { |
234 | 0 | libcerror_error_set( |
235 | 0 | error, |
236 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
237 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
238 | 0 | "%s: unable to retrieve UTF-8 name size.", |
239 | 0 | function ); |
240 | |
|
241 | 0 | result = -1; |
242 | 0 | } |
243 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
244 | 0 | if( libcthreads_read_write_lock_release_for_read( |
245 | 0 | internal_attribute->read_write_lock, |
246 | 0 | error ) != 1 ) |
247 | 0 | { |
248 | 0 | libcerror_error_set( |
249 | 0 | error, |
250 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
251 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
252 | 0 | "%s: unable to release read/write lock for reading.", |
253 | 0 | function ); |
254 | |
|
255 | 0 | return( -1 ); |
256 | 0 | } |
257 | 0 | #endif |
258 | 0 | return( result ); |
259 | 0 | } |
260 | | |
261 | | /* Retrieves the UTF-8 encoded name |
262 | | * The size should include the end of string character |
263 | | * Returns 1 if successful, 0 if not set or -1 on error |
264 | | */ |
265 | | int libewf_attribute_get_utf8_name( |
266 | | libewf_attribute_t *attribute, |
267 | | uint8_t *utf8_string, |
268 | | size_t utf8_string_size, |
269 | | libcerror_error_t **error ) |
270 | 0 | { |
271 | 0 | libewf_internal_attribute_t *internal_attribute = NULL; |
272 | 0 | static char *function = "libewf_attribute_get_utf8_name"; |
273 | 0 | int result = 0; |
274 | |
|
275 | 0 | if( attribute == NULL ) |
276 | 0 | { |
277 | 0 | libcerror_error_set( |
278 | 0 | error, |
279 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
280 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
281 | 0 | "%s: invalid attribute.", |
282 | 0 | function ); |
283 | |
|
284 | 0 | return( -1 ); |
285 | 0 | } |
286 | 0 | internal_attribute = (libewf_internal_attribute_t *) attribute; |
287 | |
|
288 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
289 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
290 | 0 | internal_attribute->read_write_lock, |
291 | 0 | error ) != 1 ) |
292 | 0 | { |
293 | 0 | libcerror_error_set( |
294 | 0 | error, |
295 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
296 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
297 | 0 | "%s: unable to grab read/write lock for reading.", |
298 | 0 | function ); |
299 | |
|
300 | 0 | return( -1 ); |
301 | 0 | } |
302 | 0 | #endif |
303 | 0 | result = libewf_lef_extended_attribute_get_utf8_name( |
304 | 0 | internal_attribute->lef_extended_attribute, |
305 | 0 | utf8_string, |
306 | 0 | utf8_string_size, |
307 | 0 | error ); |
308 | |
|
309 | 0 | if( result == -1 ) |
310 | 0 | { |
311 | 0 | libcerror_error_set( |
312 | 0 | error, |
313 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
314 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
315 | 0 | "%s: unable to retrieve UTF-8 name size.", |
316 | 0 | function ); |
317 | |
|
318 | 0 | result = -1; |
319 | 0 | } |
320 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
321 | 0 | if( libcthreads_read_write_lock_release_for_read( |
322 | 0 | internal_attribute->read_write_lock, |
323 | 0 | error ) != 1 ) |
324 | 0 | { |
325 | 0 | libcerror_error_set( |
326 | 0 | error, |
327 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
328 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
329 | 0 | "%s: unable to release read/write lock for reading.", |
330 | 0 | function ); |
331 | |
|
332 | 0 | return( -1 ); |
333 | 0 | } |
334 | 0 | #endif |
335 | 0 | return( result ); |
336 | 0 | } |
337 | | |
338 | | /* Retrieves the size of the UTF-16 encoded name |
339 | | * The returned size includes the end of string character |
340 | | * Returns 1 if successful, 0 if not set or -1 on error |
341 | | */ |
342 | | int libewf_attribute_get_utf16_name_size( |
343 | | libewf_attribute_t *attribute, |
344 | | size_t *utf16_string_size, |
345 | | libcerror_error_t **error ) |
346 | 0 | { |
347 | 0 | libewf_internal_attribute_t *internal_attribute = NULL; |
348 | 0 | static char *function = "libewf_attribute_get_utf16_name_size"; |
349 | 0 | int result = 0; |
350 | |
|
351 | 0 | if( attribute == NULL ) |
352 | 0 | { |
353 | 0 | libcerror_error_set( |
354 | 0 | error, |
355 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
356 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
357 | 0 | "%s: invalid attribute.", |
358 | 0 | function ); |
359 | |
|
360 | 0 | return( -1 ); |
361 | 0 | } |
362 | 0 | internal_attribute = (libewf_internal_attribute_t *) attribute; |
363 | |
|
364 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
365 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
366 | 0 | internal_attribute->read_write_lock, |
367 | 0 | error ) != 1 ) |
368 | 0 | { |
369 | 0 | libcerror_error_set( |
370 | 0 | error, |
371 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
372 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
373 | 0 | "%s: unable to grab read/write lock for reading.", |
374 | 0 | function ); |
375 | |
|
376 | 0 | return( -1 ); |
377 | 0 | } |
378 | 0 | #endif |
379 | 0 | result = libewf_lef_extended_attribute_get_utf16_name_size( |
380 | 0 | internal_attribute->lef_extended_attribute, |
381 | 0 | utf16_string_size, |
382 | 0 | error ); |
383 | |
|
384 | 0 | if( result == -1 ) |
385 | 0 | { |
386 | 0 | libcerror_error_set( |
387 | 0 | error, |
388 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
389 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
390 | 0 | "%s: unable to retrieve UTF-16 name size.", |
391 | 0 | function ); |
392 | |
|
393 | 0 | result = -1; |
394 | 0 | } |
395 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
396 | 0 | if( libcthreads_read_write_lock_release_for_read( |
397 | 0 | internal_attribute->read_write_lock, |
398 | 0 | error ) != 1 ) |
399 | 0 | { |
400 | 0 | libcerror_error_set( |
401 | 0 | error, |
402 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
403 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
404 | 0 | "%s: unable to release read/write lock for reading.", |
405 | 0 | function ); |
406 | |
|
407 | 0 | return( -1 ); |
408 | 0 | } |
409 | 0 | #endif |
410 | 0 | return( result ); |
411 | 0 | } |
412 | | |
413 | | /* Retrieves the UTF-16 encoded name |
414 | | * The size should include the end of string character |
415 | | * Returns 1 if successful, 0 if not set or -1 on error |
416 | | */ |
417 | | int libewf_attribute_get_utf16_name( |
418 | | libewf_attribute_t *attribute, |
419 | | uint16_t *utf16_string, |
420 | | size_t utf16_string_size, |
421 | | libcerror_error_t **error ) |
422 | 0 | { |
423 | 0 | libewf_internal_attribute_t *internal_attribute = NULL; |
424 | 0 | static char *function = "libewf_attribute_get_utf16_name"; |
425 | 0 | int result = 0; |
426 | |
|
427 | 0 | if( attribute == NULL ) |
428 | 0 | { |
429 | 0 | libcerror_error_set( |
430 | 0 | error, |
431 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
432 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
433 | 0 | "%s: invalid attribute.", |
434 | 0 | function ); |
435 | |
|
436 | 0 | return( -1 ); |
437 | 0 | } |
438 | 0 | internal_attribute = (libewf_internal_attribute_t *) attribute; |
439 | |
|
440 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
441 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
442 | 0 | internal_attribute->read_write_lock, |
443 | 0 | error ) != 1 ) |
444 | 0 | { |
445 | 0 | libcerror_error_set( |
446 | 0 | error, |
447 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
448 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
449 | 0 | "%s: unable to grab read/write lock for reading.", |
450 | 0 | function ); |
451 | |
|
452 | 0 | return( -1 ); |
453 | 0 | } |
454 | 0 | #endif |
455 | 0 | result = libewf_lef_extended_attribute_get_utf16_name( |
456 | 0 | internal_attribute->lef_extended_attribute, |
457 | 0 | utf16_string, |
458 | 0 | utf16_string_size, |
459 | 0 | error ); |
460 | |
|
461 | 0 | if( result == -1 ) |
462 | 0 | { |
463 | 0 | libcerror_error_set( |
464 | 0 | error, |
465 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
466 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
467 | 0 | "%s: unable to retrieve UTF-16 name size.", |
468 | 0 | function ); |
469 | |
|
470 | 0 | result = -1; |
471 | 0 | } |
472 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
473 | 0 | if( libcthreads_read_write_lock_release_for_read( |
474 | 0 | internal_attribute->read_write_lock, |
475 | 0 | error ) != 1 ) |
476 | 0 | { |
477 | 0 | libcerror_error_set( |
478 | 0 | error, |
479 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
480 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
481 | 0 | "%s: unable to release read/write lock for reading.", |
482 | 0 | function ); |
483 | |
|
484 | 0 | return( -1 ); |
485 | 0 | } |
486 | 0 | #endif |
487 | 0 | return( result ); |
488 | 0 | } |
489 | | |
490 | | /* Retrieves the size of the UTF-8 encoded value |
491 | | * The returned size includes the end of string character |
492 | | * Returns 1 if successful, 0 if not set or -1 on error |
493 | | */ |
494 | | int libewf_attribute_get_utf8_value_size( |
495 | | libewf_attribute_t *attribute, |
496 | | size_t *utf8_string_size, |
497 | | libcerror_error_t **error ) |
498 | 0 | { |
499 | 0 | libewf_internal_attribute_t *internal_attribute = NULL; |
500 | 0 | static char *function = "libewf_attribute_get_utf8_value_size"; |
501 | 0 | int result = 0; |
502 | |
|
503 | 0 | if( attribute == NULL ) |
504 | 0 | { |
505 | 0 | libcerror_error_set( |
506 | 0 | error, |
507 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
508 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
509 | 0 | "%s: invalid attribute.", |
510 | 0 | function ); |
511 | |
|
512 | 0 | return( -1 ); |
513 | 0 | } |
514 | 0 | internal_attribute = (libewf_internal_attribute_t *) attribute; |
515 | |
|
516 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
517 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
518 | 0 | internal_attribute->read_write_lock, |
519 | 0 | error ) != 1 ) |
520 | 0 | { |
521 | 0 | libcerror_error_set( |
522 | 0 | error, |
523 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
524 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
525 | 0 | "%s: unable to grab read/write lock for reading.", |
526 | 0 | function ); |
527 | |
|
528 | 0 | return( -1 ); |
529 | 0 | } |
530 | 0 | #endif |
531 | 0 | result = libewf_lef_extended_attribute_get_utf8_value_size( |
532 | 0 | internal_attribute->lef_extended_attribute, |
533 | 0 | utf8_string_size, |
534 | 0 | error ); |
535 | |
|
536 | 0 | if( result == -1 ) |
537 | 0 | { |
538 | 0 | libcerror_error_set( |
539 | 0 | error, |
540 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
541 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
542 | 0 | "%s: unable to retrieve UTF-8 value size.", |
543 | 0 | function ); |
544 | |
|
545 | 0 | result = -1; |
546 | 0 | } |
547 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
548 | 0 | if( libcthreads_read_write_lock_release_for_read( |
549 | 0 | internal_attribute->read_write_lock, |
550 | 0 | error ) != 1 ) |
551 | 0 | { |
552 | 0 | libcerror_error_set( |
553 | 0 | error, |
554 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
555 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
556 | 0 | "%s: unable to release read/write lock for reading.", |
557 | 0 | function ); |
558 | |
|
559 | 0 | return( -1 ); |
560 | 0 | } |
561 | 0 | #endif |
562 | 0 | return( result ); |
563 | 0 | } |
564 | | |
565 | | /* Retrieves the UTF-8 encoded value |
566 | | * The size should include the end of string character |
567 | | * Returns 1 if successful, 0 if not set or -1 on error |
568 | | */ |
569 | | int libewf_attribute_get_utf8_value( |
570 | | libewf_attribute_t *attribute, |
571 | | uint8_t *utf8_string, |
572 | | size_t utf8_string_size, |
573 | | libcerror_error_t **error ) |
574 | 0 | { |
575 | 0 | libewf_internal_attribute_t *internal_attribute = NULL; |
576 | 0 | static char *function = "libewf_attribute_get_utf8_value"; |
577 | 0 | int result = 0; |
578 | |
|
579 | 0 | if( attribute == NULL ) |
580 | 0 | { |
581 | 0 | libcerror_error_set( |
582 | 0 | error, |
583 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
584 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
585 | 0 | "%s: invalid attribute.", |
586 | 0 | function ); |
587 | |
|
588 | 0 | return( -1 ); |
589 | 0 | } |
590 | 0 | internal_attribute = (libewf_internal_attribute_t *) attribute; |
591 | |
|
592 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
593 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
594 | 0 | internal_attribute->read_write_lock, |
595 | 0 | error ) != 1 ) |
596 | 0 | { |
597 | 0 | libcerror_error_set( |
598 | 0 | error, |
599 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
600 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
601 | 0 | "%s: unable to grab read/write lock for reading.", |
602 | 0 | function ); |
603 | |
|
604 | 0 | return( -1 ); |
605 | 0 | } |
606 | 0 | #endif |
607 | 0 | result = libewf_lef_extended_attribute_get_utf8_value( |
608 | 0 | internal_attribute->lef_extended_attribute, |
609 | 0 | utf8_string, |
610 | 0 | utf8_string_size, |
611 | 0 | error ); |
612 | |
|
613 | 0 | if( result == -1 ) |
614 | 0 | { |
615 | 0 | libcerror_error_set( |
616 | 0 | error, |
617 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
618 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
619 | 0 | "%s: unable to retrieve UTF-8 value size.", |
620 | 0 | function ); |
621 | |
|
622 | 0 | result = -1; |
623 | 0 | } |
624 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
625 | 0 | if( libcthreads_read_write_lock_release_for_read( |
626 | 0 | internal_attribute->read_write_lock, |
627 | 0 | error ) != 1 ) |
628 | 0 | { |
629 | 0 | libcerror_error_set( |
630 | 0 | error, |
631 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
632 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
633 | 0 | "%s: unable to release read/write lock for reading.", |
634 | 0 | function ); |
635 | |
|
636 | 0 | return( -1 ); |
637 | 0 | } |
638 | 0 | #endif |
639 | 0 | return( result ); |
640 | 0 | } |
641 | | |
642 | | /* Retrieves the size of the UTF-16 encoded value |
643 | | * The returned size includes the end of string character |
644 | | * Returns 1 if successful, 0 if not set or -1 on error |
645 | | */ |
646 | | int libewf_attribute_get_utf16_value_size( |
647 | | libewf_attribute_t *attribute, |
648 | | size_t *utf16_string_size, |
649 | | libcerror_error_t **error ) |
650 | 0 | { |
651 | 0 | libewf_internal_attribute_t *internal_attribute = NULL; |
652 | 0 | static char *function = "libewf_attribute_get_utf16_value_size"; |
653 | 0 | int result = 0; |
654 | |
|
655 | 0 | if( attribute == NULL ) |
656 | 0 | { |
657 | 0 | libcerror_error_set( |
658 | 0 | error, |
659 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
660 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
661 | 0 | "%s: invalid attribute.", |
662 | 0 | function ); |
663 | |
|
664 | 0 | return( -1 ); |
665 | 0 | } |
666 | 0 | internal_attribute = (libewf_internal_attribute_t *) attribute; |
667 | |
|
668 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
669 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
670 | 0 | internal_attribute->read_write_lock, |
671 | 0 | error ) != 1 ) |
672 | 0 | { |
673 | 0 | libcerror_error_set( |
674 | 0 | error, |
675 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
676 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
677 | 0 | "%s: unable to grab read/write lock for reading.", |
678 | 0 | function ); |
679 | |
|
680 | 0 | return( -1 ); |
681 | 0 | } |
682 | 0 | #endif |
683 | 0 | result = libewf_lef_extended_attribute_get_utf16_value_size( |
684 | 0 | internal_attribute->lef_extended_attribute, |
685 | 0 | utf16_string_size, |
686 | 0 | error ); |
687 | |
|
688 | 0 | if( result == -1 ) |
689 | 0 | { |
690 | 0 | libcerror_error_set( |
691 | 0 | error, |
692 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
693 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
694 | 0 | "%s: unable to retrieve UTF-16 value size.", |
695 | 0 | function ); |
696 | |
|
697 | 0 | result = -1; |
698 | 0 | } |
699 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
700 | 0 | if( libcthreads_read_write_lock_release_for_read( |
701 | 0 | internal_attribute->read_write_lock, |
702 | 0 | error ) != 1 ) |
703 | 0 | { |
704 | 0 | libcerror_error_set( |
705 | 0 | error, |
706 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
707 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
708 | 0 | "%s: unable to release read/write lock for reading.", |
709 | 0 | function ); |
710 | |
|
711 | 0 | return( -1 ); |
712 | 0 | } |
713 | 0 | #endif |
714 | 0 | return( result ); |
715 | 0 | } |
716 | | |
717 | | /* Retrieves the UTF-16 encoded |
718 | | * The size should include the end of string character |
719 | | * Returns 1 if successful, 0 if not set or -1 on error |
720 | | */ |
721 | | int libewf_attribute_get_utf16_value( |
722 | | libewf_attribute_t *attribute, |
723 | | uint16_t *utf16_string, |
724 | | size_t utf16_string_size, |
725 | | libcerror_error_t **error ) |
726 | 0 | { |
727 | 0 | libewf_internal_attribute_t *internal_attribute = NULL; |
728 | 0 | static char *function = "libewf_attribute_get_utf16_value"; |
729 | 0 | int result = 0; |
730 | |
|
731 | 0 | if( attribute == NULL ) |
732 | 0 | { |
733 | 0 | libcerror_error_set( |
734 | 0 | error, |
735 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
736 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
737 | 0 | "%s: invalid attribute.", |
738 | 0 | function ); |
739 | |
|
740 | 0 | return( -1 ); |
741 | 0 | } |
742 | 0 | internal_attribute = (libewf_internal_attribute_t *) attribute; |
743 | |
|
744 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
745 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
746 | 0 | internal_attribute->read_write_lock, |
747 | 0 | error ) != 1 ) |
748 | 0 | { |
749 | 0 | libcerror_error_set( |
750 | 0 | error, |
751 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
752 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
753 | 0 | "%s: unable to grab read/write lock for reading.", |
754 | 0 | function ); |
755 | |
|
756 | 0 | return( -1 ); |
757 | 0 | } |
758 | 0 | #endif |
759 | 0 | result = libewf_lef_extended_attribute_get_utf16_value( |
760 | 0 | internal_attribute->lef_extended_attribute, |
761 | 0 | utf16_string, |
762 | 0 | utf16_string_size, |
763 | 0 | error ); |
764 | |
|
765 | 0 | if( result == -1 ) |
766 | 0 | { |
767 | 0 | libcerror_error_set( |
768 | 0 | error, |
769 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
770 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
771 | 0 | "%s: unable to retrieve UTF-16 value size.", |
772 | 0 | function ); |
773 | |
|
774 | 0 | result = -1; |
775 | 0 | } |
776 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
777 | 0 | if( libcthreads_read_write_lock_release_for_read( |
778 | 0 | internal_attribute->read_write_lock, |
779 | 0 | error ) != 1 ) |
780 | 0 | { |
781 | 0 | libcerror_error_set( |
782 | 0 | error, |
783 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
784 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
785 | 0 | "%s: unable to release read/write lock for reading.", |
786 | 0 | function ); |
787 | |
|
788 | 0 | return( -1 ); |
789 | 0 | } |
790 | 0 | #endif |
791 | 0 | return( result ); |
792 | 0 | } |
793 | | |