1 /***************************************************************************/
2 /* */
3 /* ftrfork.c */
4 /* */
5 /* Embedded resource forks accessor (body). */
6 /* */
7 /* Copyright 2004-2018 by */
8 /* Masatake YAMATO and Redhat K.K. */
9 /* */
10 /* FT_Raccess_Get_HeaderInfo() and raccess_guess_darwin_hfsplus() are */
11 /* derived from ftobjs.c. */
12 /* */
13 /* This file is part of the FreeType project, and may only be used, */
14 /* modified, and distributed under the terms of the FreeType project */
15 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
16 /* this file you indicate that you have read the license and */
17 /* understand and accept it fully. */
18 /* */
19 /***************************************************************************/
20
21 /***************************************************************************/
22 /* Development of the code in this file is support of */
23 /* Information-technology Promotion Agency, Japan. */
24 /***************************************************************************/
25
26
27 #include <ft2build.h>
28 #include FT_INTERNAL_DEBUG_H
29 #include FT_INTERNAL_STREAM_H
30 #include FT_INTERNAL_RFORK_H
31 #include "basepic.h"
32 #include "ftbase.h"
33
34 #undef FT_COMPONENT
35 #define FT_COMPONENT trace_raccess
36
37
38 /*************************************************************************/
39 /*************************************************************************/
40 /*************************************************************************/
41 /**** ****/
42 /**** ****/
43 /**** Resource fork directory access ****/
44 /**** ****/
45 /**** ****/
46 /*************************************************************************/
47 /*************************************************************************/
48 /*************************************************************************/
49
50 FT_BASE_DEF( FT_Error )
51 FT_Raccess_Get_HeaderInfo( FT_Library library,
52 FT_Stream stream,
53 FT_Long rfork_offset,
54 FT_Long *map_offset,
55 FT_Long *rdata_pos )
421 CONST_FT_RFORK_RULE_ARRAY_ENTRY(linux_double, linux_double)
422 CONST_FT_RFORK_RULE_ARRAY_ENTRY(linux_netatalk, linux_netatalk)
423 CONST_FT_RFORK_RULE_ARRAY_END
424
425
426 /*************************************************************************/
427 /**** ****/
428 /**** Helper functions ****/
429 /**** ****/
430 /*************************************************************************/
431
432 static FT_Error
433 raccess_guess_apple_generic( FT_Library library,
434 FT_Stream stream,
435 char *base_file_name,
436 FT_Int32 magic,
437 FT_Long *result_offset );
438
439 static FT_Error
440 raccess_guess_linux_double_from_file_name( FT_Library library,
441 char * file_name,
442 FT_Long *result_offset );
443
444 static char *
445 raccess_make_file_name( FT_Memory memory,
446 const char *original_name,
447 const char *insertion );
448
449 FT_BASE_DEF( void )
450 FT_Raccess_Guess( FT_Library library,
451 FT_Stream stream,
452 char* base_name,
453 char **new_names,
454 FT_Long *offsets,
455 FT_Error *errors )
456 {
457 FT_Int i;
458
459
460 for ( i = 0; i < FT_RACCESS_N_RULES; i++ )
461 {
462 new_names[i] = NULL;
463 if ( NULL != stream )
464 errors[i] = FT_Stream_Seek( stream, 0 );
465 else
466 errors[i] = FT_Err_Ok;
467
468 if ( errors[i] )
469 continue;
470
471 errors[i] = (FT_RACCESS_GUESS_TABLE_GET[i].func)( library,
472 stream, base_name,
473 &(new_names[i]),
474 &(offsets[i]) );
475 }
476
477 return;
478 }
479
480
481 #if defined( FT_CONFIG_OPTION_MAC_FONTS ) && !defined( FT_MACINTOSH )
482 static FT_RFork_Rule
483 raccess_get_rule_type_from_rule_index( FT_Library library,
484 FT_UInt rule_index )
485 {
486 FT_UNUSED( library );
487
488 if ( rule_index >= FT_RACCESS_N_RULES )
489 return FT_RFork_Rule_invalid;
490
491 return FT_RACCESS_GUESS_TABLE_GET[rule_index].type;
492 }
493
494
495 /*
496 * For this function, refer ftbase.h.
497 */
498 FT_LOCAL_DEF( FT_Bool )
499 ft_raccess_rule_by_darwin_vfs( FT_Library library,
500 FT_UInt rule_index )
501 {
502 switch( raccess_get_rule_type_from_rule_index( library, rule_index ) )
503 {
504 case FT_RFork_Rule_darwin_newvfs:
505 case FT_RFork_Rule_darwin_hfsplus:
506 return TRUE;
507
508 default:
509 return FALSE;
510 }
511 }
830 }
831 else
832 {
833 error = FT_Stream_Skip( stream, 4 + 4 ); /* offset + length */
834 if ( error )
835 return error;
836 }
837 }
838
839 return FT_THROW( Unknown_File_Format );
840 }
841
842
843 static FT_Error
844 raccess_guess_linux_double_from_file_name( FT_Library library,
845 char *file_name,
846 FT_Long *result_offset )
847 {
848 FT_Open_Args args2;
849 FT_Stream stream2;
850 char * nouse = NULL;
851 FT_Error error;
852
853
854 args2.flags = FT_OPEN_PATHNAME;
855 args2.pathname = file_name;
856 error = FT_Stream_New( library, &args2, &stream2 );
857 if ( error )
858 return error;
859
860 error = raccess_guess_apple_double( library, stream2, file_name,
861 &nouse, result_offset );
862
863 FT_Stream_Free( stream2, 0 );
864
865 return error;
866 }
867
868
869 static char*
870 raccess_make_file_name( FT_Memory memory,
892 (size_t)( tmp - original_name + 1 ) );
893 new_name[tmp - original_name + 1] = '\0';
894 slash = tmp + 1;
895 }
896 else
897 {
898 slash = original_name;
899 new_name[0] = '\0';
900 }
901
902 ft_strcat( new_name, insertion );
903 ft_strcat( new_name, slash );
904
905 return new_name;
906 }
907
908
909 #else /* !FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */
910
911
912 /*************************************************************************/
913 /* Dummy function; just sets errors */
914 /*************************************************************************/
915
916 FT_BASE_DEF( void )
917 FT_Raccess_Guess( FT_Library library,
918 FT_Stream stream,
919 char *base_name,
920 char **new_names,
921 FT_Long *offsets,
922 FT_Error *errors )
923 {
924 FT_Int i;
925
926 FT_UNUSED( library );
927 FT_UNUSED( stream );
928 FT_UNUSED( base_name );
929
930
931 for ( i = 0; i < FT_RACCESS_N_RULES; i++ )
932 {
933 new_names[i] = NULL;
934 offsets[i] = 0;
|
1 /****************************************************************************
2 *
3 * ftrfork.c
4 *
5 * Embedded resource forks accessor (body).
6 *
7 * Copyright (C) 2004-2019 by
8 * Masatake YAMATO and Redhat K.K.
9 *
10 * FT_Raccess_Get_HeaderInfo() and raccess_guess_darwin_hfsplus() are
11 * derived from ftobjs.c.
12 *
13 * This file is part of the FreeType project, and may only be used,
14 * modified, and distributed under the terms of the FreeType project
15 * license, LICENSE.TXT. By continuing to use, modify, or distribute
16 * this file you indicate that you have read the license and
17 * understand and accept it fully.
18 *
19 */
20
21 /****************************************************************************
22 * Development of the code in this file is support of
23 * Information-technology Promotion Agency, Japan.
24 */
25
26
27 #include <ft2build.h>
28 #include FT_INTERNAL_DEBUG_H
29 #include FT_INTERNAL_STREAM_H
30 #include FT_INTERNAL_RFORK_H
31
32 #include "ftbase.h"
33
34 #undef FT_COMPONENT
35 #define FT_COMPONENT raccess
36
37
38 /*************************************************************************/
39 /*************************************************************************/
40 /*************************************************************************/
41 /**** ****/
42 /**** ****/
43 /**** Resource fork directory access ****/
44 /**** ****/
45 /**** ****/
46 /*************************************************************************/
47 /*************************************************************************/
48 /*************************************************************************/
49
50 FT_BASE_DEF( FT_Error )
51 FT_Raccess_Get_HeaderInfo( FT_Library library,
52 FT_Stream stream,
53 FT_Long rfork_offset,
54 FT_Long *map_offset,
55 FT_Long *rdata_pos )
421 CONST_FT_RFORK_RULE_ARRAY_ENTRY(linux_double, linux_double)
422 CONST_FT_RFORK_RULE_ARRAY_ENTRY(linux_netatalk, linux_netatalk)
423 CONST_FT_RFORK_RULE_ARRAY_END
424
425
426 /*************************************************************************/
427 /**** ****/
428 /**** Helper functions ****/
429 /**** ****/
430 /*************************************************************************/
431
432 static FT_Error
433 raccess_guess_apple_generic( FT_Library library,
434 FT_Stream stream,
435 char *base_file_name,
436 FT_Int32 magic,
437 FT_Long *result_offset );
438
439 static FT_Error
440 raccess_guess_linux_double_from_file_name( FT_Library library,
441 char* file_name,
442 FT_Long *result_offset );
443
444 static char *
445 raccess_make_file_name( FT_Memory memory,
446 const char *original_name,
447 const char *insertion );
448
449 FT_BASE_DEF( void )
450 FT_Raccess_Guess( FT_Library library,
451 FT_Stream stream,
452 char* base_name,
453 char **new_names,
454 FT_Long *offsets,
455 FT_Error *errors )
456 {
457 FT_Int i;
458
459
460 for ( i = 0; i < FT_RACCESS_N_RULES; i++ )
461 {
462 new_names[i] = NULL;
463 if ( NULL != stream )
464 errors[i] = FT_Stream_Seek( stream, 0 );
465 else
466 errors[i] = FT_Err_Ok;
467
468 if ( errors[i] )
469 continue;
470
471 errors[i] = ft_raccess_guess_table[i].func( library,
472 stream, base_name,
473 &(new_names[i]),
474 &(offsets[i]) );
475 }
476
477 return;
478 }
479
480
481 #if defined( FT_CONFIG_OPTION_MAC_FONTS ) && !defined( FT_MACINTOSH )
482 static FT_RFork_Rule
483 raccess_get_rule_type_from_rule_index( FT_Library library,
484 FT_UInt rule_index )
485 {
486 FT_UNUSED( library );
487
488 if ( rule_index >= FT_RACCESS_N_RULES )
489 return FT_RFork_Rule_invalid;
490
491 return ft_raccess_guess_table[rule_index].type;
492 }
493
494
495 /*
496 * For this function, refer ftbase.h.
497 */
498 FT_LOCAL_DEF( FT_Bool )
499 ft_raccess_rule_by_darwin_vfs( FT_Library library,
500 FT_UInt rule_index )
501 {
502 switch( raccess_get_rule_type_from_rule_index( library, rule_index ) )
503 {
504 case FT_RFork_Rule_darwin_newvfs:
505 case FT_RFork_Rule_darwin_hfsplus:
506 return TRUE;
507
508 default:
509 return FALSE;
510 }
511 }
830 }
831 else
832 {
833 error = FT_Stream_Skip( stream, 4 + 4 ); /* offset + length */
834 if ( error )
835 return error;
836 }
837 }
838
839 return FT_THROW( Unknown_File_Format );
840 }
841
842
843 static FT_Error
844 raccess_guess_linux_double_from_file_name( FT_Library library,
845 char *file_name,
846 FT_Long *result_offset )
847 {
848 FT_Open_Args args2;
849 FT_Stream stream2;
850 char* nouse = NULL;
851 FT_Error error;
852
853
854 args2.flags = FT_OPEN_PATHNAME;
855 args2.pathname = file_name;
856 error = FT_Stream_New( library, &args2, &stream2 );
857 if ( error )
858 return error;
859
860 error = raccess_guess_apple_double( library, stream2, file_name,
861 &nouse, result_offset );
862
863 FT_Stream_Free( stream2, 0 );
864
865 return error;
866 }
867
868
869 static char*
870 raccess_make_file_name( FT_Memory memory,
892 (size_t)( tmp - original_name + 1 ) );
893 new_name[tmp - original_name + 1] = '\0';
894 slash = tmp + 1;
895 }
896 else
897 {
898 slash = original_name;
899 new_name[0] = '\0';
900 }
901
902 ft_strcat( new_name, insertion );
903 ft_strcat( new_name, slash );
904
905 return new_name;
906 }
907
908
909 #else /* !FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */
910
911
912 /**************************************************************************
913 * Dummy function; just sets errors
914 */
915
916 FT_BASE_DEF( void )
917 FT_Raccess_Guess( FT_Library library,
918 FT_Stream stream,
919 char *base_name,
920 char **new_names,
921 FT_Long *offsets,
922 FT_Error *errors )
923 {
924 FT_Int i;
925
926 FT_UNUSED( library );
927 FT_UNUSED( stream );
928 FT_UNUSED( base_name );
929
930
931 for ( i = 0; i < FT_RACCESS_N_RULES; i++ )
932 {
933 new_names[i] = NULL;
934 offsets[i] = 0;
|