Browse Source

- changed to use new type ctiff_t, to held ifd0 and avoid multiple stream seeks

- fixed some bugs where output messages are cutted
- removed deprecated code
- some improvements in loops
pull/1/head
andreas.romeyke@slub-dresden.de 5 years ago
parent
commit
6cbe0bad4b
  1. 32
      src/checkit_tiff.c
  2. 48
      src/headers/check.h
  3. 30
      src/headers/check_helper.h
  4. 24
      src/headers/config_parser.h
  5. 5
      src/helper/check_print.c
  6. 277
      src/helper/check_tiffparse.c
  7. 6
      src/ifdrules/check_all_IFDs_are_word_aligned.c
  8. 8
      src/ifdrules/check_all_offsets_are_used_once_only.c
  9. 8
      src/ifdrules/check_all_offsets_are_word_aligned.c
  10. 65
      src/ifdrules/check_has_only_one_ifd.c
  11. 20
      src/ifdrules/check_tagorder.c
  12. 37
      src/parser/config_parser.c
  13. 6
      src/tagrules/check_datetime.c
  14. 6
      src/tagrules/check_notag.c
  15. 10
      src/tagrules/check_tag.c
  16. 20
      src/tagrules/check_tag_has_some_of_these_values.c
  17. 8
      src/tagrules/check_tag_has_valid_asciivalue.c
  18. 6
      src/tagrules/check_tag_has_valid_type.c
  19. 8
      src/tagrules/check_tag_has_value.c
  20. 14
      src/tagrules/check_tag_has_value_in_range.c
  21. 10
      src/tagrules/check_tag_has_value_matching_regex.c
  22. 6
      src/tagrules/check_tag_has_value_quiet.c
  23. 16
      src/tagrules/check_tag_has_valuelist.c
  24. 8
      src/tagrules/check_tag_quiet.c

32
src/checkit_tiff.c

@ -51,38 +51,28 @@ void help () {
int check_specific_tiff_file( const char * tiff_file, int use_memmapped) {
// printf("tiff file=%s\n", tiff_file);
tif_files(tiff_file);
/* load tiff file */
TIFF* tif = NULL;
if (use_memmapped == FLAGGED) {
tif = TIFFOpen(tiff_file, "rM");
} else { /* slow */
tif = TIFFOpen( tiff_file, "rm");
}
if (NULL == tif) {
fprintf( stderr, "file '%s' could not be opened\n", tiff_file);
return (EXIT_FAILURE);
};
int is_valid = 0;
ret_t res;
ctiff_t * ctif = initialize_ctif( tiff_file );
int is_valid = 0;
/* special checks */
res = check_all_IFDs_are_word_aligned( tif); if (0 != res.returncode) {is_valid++;}
res = check_all_IFDs_are_word_aligned( ctif); if (0 != res.returncode) {is_valid++;}
free (res.returnmsg);
res = check_has_only_one_ifd( tif); if (0 != res.returncode) {is_valid++;}
res = check_has_only_one_ifd( ctif); if (0 != res.returncode) {is_valid++;}
free (res.returnmsg);
res = check_tagorder( tif); if (0 != res.returncode) {is_valid++;}
res = check_tagorder( ctif); if (0 != res.returncode) {is_valid++;}
free (res.returnmsg);
res = check_all_offsets_are_used_once_only( tif ); if (0 != res.returncode) {is_valid++;}
res = check_all_offsets_are_used_once_only( ctif ); if (0 != res.returncode) {is_valid++;}
free (res.returnmsg);
res = check_all_offsets_are_word_aligned( tif ); if (0 != res.returncode) {is_valid++;}
res = check_all_offsets_are_word_aligned( ctif ); if (0 != res.returncode) {is_valid++;}
free (res.returnmsg);
res = check_tag_quiet( tif, TIFFTAG_DATETIME);
res = check_tag_quiet( ctif, TIFFTAG_DATETIME);
free (res.returnmsg);
if (res.returncode == 0) {
res = check_datetime( tif );
res = check_datetime( ctif );
free (res.returnmsg);
if (0 != res.returncode) {is_valid++;}
}
is_valid += execute_plan(tif);
is_valid += execute_plan(ctif);
/* TODO: colorize? */
if (is_valid > 0) {
printf("found %i errors\n", is_valid);
@ -90,7 +80,7 @@ int check_specific_tiff_file( const char * tiff_file, int use_memmapped) {
printf("the given tif is valid\n");
}
//print_plan_results();
TIFFClose(tif);
free_ctif( ctif );
return is_valid;
}

48
src/headers/check.h

@ -12,6 +12,18 @@
#include <tiff.h>
#include <tiffio.h>
typedef struct ctiff_s {
void * streamp; /* TODO: adress of memory-mapped tif stream */
uint32 streamlen; /* TODO: length of memory-mapped tif stream (in bytes) */
TIFF * tif;
void * ifd0p; /* adress of first ifd in memory-mapped tif stream */
uint32 ifd0pos; /* offset in tif stream (in bytes) */
uint16 ifd0c; /* count if tags in first ifd */
char isbyteswapped; /* true if BigEndian */
char *filename; /* filename */
/* TODO: add file size */
} ctiff_t;
typedef struct retmsg_s {
enum{ rm_default, rm_file, rm_rule, rm_tag, rm_value, rm_expected, rm_hard_error, rm_error, rm_warning } rm_type;
char * rm_msg;
@ -58,7 +70,7 @@ typedef uint16 tag_t;
#define MAXSTRLEN 1024
void tifp_check( TIFF * tif);
void tifp_check( ctiff_t * ctif);
ret_t tif_returns(tag_t tag, const char* expected, const char* value);
ret_t tif_fails_tag(tag_t tag, const char* expected, const char* value);
ret_t tif_fails(const char* fail_message);
@ -73,22 +85,22 @@ const char* int2str(int v);
const char* frac2str(int d, int n);
const char* range2str(int d, int n);
ret_t check_tag_has_some_of_these_values( TIFF* tif, tag_t tag, int count, unsigned int * values);
ret_t check_tag_has_valuelist( TIFF* tif, tag_t tag, int count, unsigned int * values);
ret_t check_tag_has_value_in_range(TIFF* tif, tag_t tag, unsigned int a, unsigned int b);
ret_t check_tag_has_value(TIFF* tif, tag_t tag, unsigned int value);
ret_t check_tag_has_value_quiet(TIFF* tif, tag_t tag, unsigned int value);
ret_t check_tag(TIFF* tif, tag_t tag);
ret_t check_tag_quiet(TIFF* tif, tag_t tag);
ret_t check_notag(TIFF* tif, tag_t tag);
ret_t check_tag_has_valid_type(TIFF* tiff, tag_t tag);
ret_t check_datetime(TIFF* tif);
ret_t check_has_only_one_ifd(TIFF* tif);
ret_t check_tagorder(TIFF* tif);
ret_t check_tag_has_valid_asciivalue(TIFF* tif, tag_t tag);
ret_t check_tag_has_value_matching_regex(TIFF* tif, tag_t tag, const char* value);
ret_t check_all_offsets_are_word_aligned(TIFF * tif);
ret_t check_all_offsets_are_used_once_only(TIFF * tif);
ret_t check_all_IFDs_are_word_aligned(TIFF * tif);
ret_t check_tag_has_some_of_these_values( ctiff_t * ctif, tag_t tag, int count, unsigned int * values);
ret_t check_tag_has_valuelist( ctiff_t * ctif, tag_t tag, int count, unsigned int * values);
ret_t check_tag_has_value_in_range(ctiff_t * ctif, tag_t tag, unsigned int a, unsigned int b);
ret_t check_tag_has_value(ctiff_t * ctif, tag_t tag, unsigned int value);
ret_t check_tag_has_value_quiet(ctiff_t * ctif, tag_t tag, unsigned int value);
ret_t check_tag(ctiff_t * ctif, tag_t tag);
ret_t check_tag_quiet(ctiff_t * ctif, tag_t tag);
ret_t check_notag(ctiff_t * ctif, tag_t tag);
ret_t check_tag_has_valid_type(ctiff_t * ctiff, tag_t tag);
ret_t check_datetime(ctiff_t * ctif);
ret_t check_has_only_one_ifd(ctiff_t * ctif);
ret_t check_tagorder(ctiff_t * ctif);
ret_t check_tag_has_valid_asciivalue(ctiff_t * ctif, tag_t tag);
ret_t check_tag_has_value_matching_regex(ctiff_t * ctif, tag_t tag, const char* value);
ret_t check_all_offsets_are_word_aligned(ctiff_t * ctif);
ret_t check_all_offsets_are_used_once_only(ctiff_t * ctif);
ret_t check_all_IFDs_are_word_aligned(ctiff_t * ctif);
#endif
/* _FIXIT_TIFF_CHECK */

30
src/headers/check_helper.h

@ -15,21 +15,27 @@
typedef enum{ render_default, render_debug, render_ansi} render_type;
/* helper */
ret_t check_tag_has_fvalue(TIFF* tif, tag_t tag, float value);
ret_t check_tag_has_u16value(TIFF* tif, tag_t tag, uint16 value);
ret_t check_tag_has_u32value(TIFF* tif, tag_t tag, uint32 value);
ret_t check_tag_has_fvalue(ctiff_t * ctif, tag_t tag, float value);
ret_t check_tag_has_u16value(ctiff_t * ctif, tag_t tag, uint16 value);
ret_t check_tag_has_u32value(ctiff_t * ctif, tag_t tag, uint32 value);
const char * TIFFTagName (tag_t tag);
uint32 TIFFGetRawTagTypeListEntry( TIFF * tif, int tagidx );
tag_t TIFFGetRawTagListEntry( TIFF * tif, int tagidx ) ;
int TIFFGetRawTagListCount (TIFF * tif) ;
TIFFDataType TIFFGetRawTagType(TIFF * tif, tag_t tag);
ifd_entry_t TIFFGetRawIFDEntry( TIFF * tif, tag_t tag);
ifd_entry_t TIFFGetRawTagIFDListEntry( TIFF * tif, int tagidx );
offset_t read_offsetdata( TIFF * tif, uint32 address, uint16 count, uint16 datatype);
uint32 get_first_IFD(TIFF * tif);
uint32 TIFFGetRawTagTypeListEntry( ctiff_t * ctif, int tagidx );
tag_t TIFFGetRawTagListEntry( ctiff_t * ctif, int tagidx ) ;
int TIFFGetRawTagListCount (ctiff_t * ctif, uint32 ifpos) ;
TIFFDataType TIFFGetRawTagType(ctiff_t * ctif, tag_t tag);
ifd_entry_t TIFFGetRawIFDEntry( ctiff_t * ctif, tag_t tag);
ifd_entry_t TIFFGetRawTagIFDListEntry( ctiff_t * ctif, int tagidx );
offset_t read_offsetdata( ctiff_t * ctif, uint32 address, uint16 count, uint16 datatype);
//uint32 get_first_IFD(ctiff_t * ctif);
//int parse_header_and_endianess(ctiff_t * ctif);
//int TIFFIsByteSwapped(TIFF * tif);
void clear_cache();
const char * renderer ( const ret_t ret );
void set_renderer_to_ansi();
char * secstrcat (char * dest, const char * src, int maxsize);
ctiff_t * initialize_ctif( const char * filename );
void free_ctif( ctiff_t * ctif);
uint32 get_ifd0_pos( ctiff_t * ctif );
uint32 get_next_ifd_pos( ctiff_t * ctif, uint32 actual_pos );
uint16 get_ifd0_count( ctiff_t * ctif );
char is_byteswapped( ctiff_t * ctif );
#endif

24
src/headers/config_parser.h

@ -32,38 +32,38 @@ typedef enum { range, logical_or, any, only, regex } values_t;
/* definitions of structs of function pointers to hold type information for "lazy evaluation" */
typedef struct f_tifp_s {
ret_t (*functionp)(TIFF *);
ret_t (*functionp)(ctiff_t *);
} f_tifp_t;
typedef struct f_tifp_tag_s {
int a;
ret_t (*functionp)(TIFF *, tag_t a);
ret_t (*functionp)(ctiff_t *, tag_t a);
} f_tifp_tag_t;
typedef struct f_tifp_tag_uint_s {
int a;
unsigned int b;
ret_t (*functionp)(TIFF*, tag_t a, unsigned int b);
ret_t (*functionp)(ctiff_t *, tag_t a, unsigned int b);
} f_tifp_tag_uint_t;
typedef struct f_tifp_tag_uint_uint_s {
int a;
unsigned int b;
unsigned int c;
ret_t (*functionp)(TIFF*, tag_t a, unsigned int b, unsigned int c);
ret_t (*functionp)(ctiff_t *, tag_t a, unsigned int b, unsigned int c);
} f_tifp_tag_uint_uint_t;
typedef struct f_tifp_tag_int_uintp_s {
int a;
int b;
unsigned int * c;
ret_t (*functionp)(TIFF*, tag_t a, int b, unsigned int * c);
ret_t (*functionp)(ctiff_t *, tag_t a, int b, unsigned int * c);
} f_tifp_tag_int_uintp_t;
typedef struct f_tifp_tag_charp_s {
int a;
const char * b;
ret_t (*functionp)(TIFF*, tag_t a, const char * b);
ret_t (*functionp)(ctiff_t *, tag_t a, const char * b);
} f_tifp_tag_charp_t;
@ -103,7 +103,7 @@ typedef struct parser_state_s {
} parser_state_t;
void set_parse_error(char * msg, char * yytext);
int execute_plan (TIFF * tif) ;
int execute_plan (ctiff_t * ctif) ;
void print_plan ();
void print_plan_results ();
void clean_plan ();
@ -113,11 +113,11 @@ void parse_plan_via_file (const char * filename);
void add_default_rules_to_plan();
/* helper */
void _helper_add_fsp_tifp(struct funcu * f, ret_t (* function)(TIFF *), char * fname);
void _helper_add_fsp_tifp_tag(struct funcu * f, ret_t (* function)(TIFF *, tag_t), char * fname, tag_t tag);
void _helper_add_fsp_tifp_tag_uint(struct funcu * f, ret_t (* function)(TIFF *, tag_t, unsigned int), char * fname, tag_t tag, unsigned int v);
void _helper_add_fsp_tifp_tag_uint_uint(struct funcu * f, ret_t (* function)(TIFF *, tag_t, unsigned int, unsigned int), char * fname, tag_t tag, unsigned int l, unsigned int r);
void _helper_add_fsp_tifp_tag_int_uintp(struct funcu * f, ret_t (* function)(TIFF *, tag_t, int, unsigned int *), char * fname, tag_t tag, int count_of_values, unsigned int * rp);
void _helper_add_fsp_tifp(struct funcu * f, ret_t (* function)(ctiff_t *), char * fname);
void _helper_add_fsp_tifp_tag(struct funcu * f, ret_t (* function)(ctiff_t *, tag_t), char * fname, tag_t tag);
void _helper_add_fsp_tifp_tag_uint(struct funcu * f, ret_t (* function)(ctiff_t *, tag_t, unsigned int), char * fname, tag_t tag, unsigned int v);
void _helper_add_fsp_tifp_tag_uint_uint(struct funcu * f, ret_t (* function)(ctiff_t *, tag_t, unsigned int, unsigned int), char * fname, tag_t tag, unsigned int l, unsigned int r);
void _helper_add_fsp_tifp_tag_int_uintp(struct funcu * f, ret_t (* function)(ctiff_t *, tag_t, int, unsigned int *), char * fname, tag_t tag, int count_of_values, unsigned int * rp);
#endif
/* _FIXIT_TIFF_CONFIG_PARSER */

5
src/helper/check_print.c

@ -154,8 +154,9 @@ ret_t tif_files(const char *msg) {
return res;
}
void tifp_check( TIFF * tif) {
if (NULL == tif) { tif_fails("TIFF pointer is empty\n"); };
void tifp_check( ctiff_t * ctif) {
if (NULL == ctif) { tif_fails("ctif_t pointer is empty\n"); };
if (NULL == ctif->tif) { tif_fails("TIFF pointer is empty\n"); };
}
/* TODO: add tif_returns specialized for types */

277
src/helper/check_tiffparse.c

@ -19,12 +19,17 @@
*/
/* TODO:
* initialize_ctif()
* free_ctif()
*
* get_ifd0_pos()
* get_ifd0_count()
* get_ifd0_stream()
* ...
*/
static int enabled_cache = 0;
void clear_cache () {
enabled_cache = 0;
}
const char * TIFFTagName( tag_t tag ) {
@ -232,10 +237,10 @@ const char * TIFFTagName( tag_t tag ) {
}
}
//------------------------------------------------------------------------------
ret_t check_tag_has_fvalue(TIFF* tif, tag_t tag, float value)
ret_t check_tag_has_fvalue(ctiff_t * ctif, tag_t tag, float value)
{
float val;
int found=TIFFGetField(tif, tag, &val);
int found=TIFFGetField(ctif->tif, tag, &val);
if (1 == found) {
if ( fabs(val - value) < 0.01 ) {
ret_t res;
@ -255,10 +260,10 @@ ret_t check_tag_has_fvalue(TIFF* tif, tag_t tag, float value)
}
//------------------------------------------------------------------------------
ret_t check_tag_has_u16value(TIFF* tif, tag_t tag, uint16 value)
ret_t check_tag_has_u16value(ctiff_t * ctif, tag_t tag, uint16 value)
{
uint16 val;
int found=TIFFGetField(tif, tag, &val);
int found=TIFFGetField(ctif->tif, tag, &val);
if (1 == found) {
if ( val == value ) {
ret_t res;
@ -279,10 +284,10 @@ ret_t check_tag_has_u16value(TIFF* tif, tag_t tag, uint16 value)
//------------------------------------------------------------------------------
ret_t check_tag_has_u32value(TIFF* tif, tag_t tag, uint32 value)
ret_t check_tag_has_u32value(ctiff_t * ctif, tag_t tag, uint32 value)
{
uint32 val;
int found=TIFFGetField(tif, tag, &val);
int found=TIFFGetField(ctif->tif, tag, &val);
if (1 == found) {
if ( val == value ) {
ret_t res;
@ -302,10 +307,10 @@ ret_t check_tag_has_u32value(TIFF* tif, tag_t tag, uint32 value)
}
int parse_header_and_endianess(TIFF * tif) {
thandle_t client = TIFFClientdata(tif);
TIFFReadWriteProc readproc = TIFFGetReadProc(tif);
TIFFSeekProc seekproc = TIFFGetSeekProc(tif);
int parse_header_and_endianess(ctiff_t * ctif) {
thandle_t client = TIFFClientdata(ctif->tif);
TIFFReadWriteProc readproc = TIFFGetReadProc(ctif->tif);
TIFFSeekProc seekproc = TIFFGetSeekProc(ctif->tif);
if (! seekproc) {
perror ("could not get TIFFGetSeekProc");
}
@ -337,6 +342,7 @@ int parse_header_and_endianess(TIFF * tif) {
if (header == 0x4550) fprintf( stderr, "could be a Microsoft Document Image file (little endian), if header begins with by 0x45 0x50 0x2a 0x00\n");
exit(EXIT_FAILURE);
}
ctif->isbyteswapped = ret;
/*
if (read(fd, &magic, 2) != 2) {
perror ("TIFF Header read error");
@ -364,55 +370,64 @@ int parse_header_and_endianess(TIFF * tif) {
}
}
uint32 get_first_IFD(TIFF * tif) {
/* memoize it */
static uint32 memoized_offset = 0;
static int is_memoized = 0;
static TIFF * memoized_tif = NULL;
//printf("get_first_IFD is memoized? %s\n", is_memoized ? "true" : "false");
if (! is_memoized || (memoized_tif != tif) || (!enabled_cache)) {
int isByteSwapped = parse_header_and_endianess(tif);
/* seek the image file directory (bytes 4-7) */
thandle_t client = TIFFClientdata(tif);
TIFFSeekProc seekproc = TIFFGetSeekProc(tif);
TIFFReadWriteProc readproc = TIFFGetReadProc(tif);
if (! seekproc) {
perror ("could not get TIFFGetSeekProc");
}
if (! readproc) {
perror ("could not get TIFFGetReadProc");
}
/*lseek(fd, (off_t) 4, SEEK_SET); */
seekproc(client, 4, SEEK_SET);
uint32 offset;
/*if (read(fd, &offset, 4) != 4) {
perror ("TIFF Header read error");
exit( EXIT_FAILURE );
}
*/
if ( readproc( client, &offset, 4) != 4 ) {
perror ("TIFF Header read error");
exit( EXIT_FAILURE );
}
if (isByteSwapped) {
TIFFSwabLong (&offset);
}
memoized_offset = offset;
memoized_tif = tif;
is_memoized = 1;
enabled_cache = 1;
uint32 get_first_IFD(ctiff_t * ctif) {
int isByteSwapped = parse_header_and_endianess(ctif);
assert( NULL == ctif->ifd0p);
/* seek the image file directory (bytes 4-7) */
thandle_t client = TIFFClientdata(ctif->tif);
TIFFSeekProc seekproc = TIFFGetSeekProc(ctif->tif);
TIFFReadWriteProc readproc = TIFFGetReadProc(ctif->tif);
if (! seekproc) {
perror ("could not get TIFFGetSeekProc");
}
if (! readproc) {
perror ("could not get TIFFGetReadProc");
}
/*lseek(fd, (off_t) 4, SEEK_SET); */
seekproc(client, 4, SEEK_SET);
uint32 offset;
/*if (read(fd, &offset, 4) != 4) {
perror ("TIFF Header read error");
exit( EXIT_FAILURE );
}
*/
if ( readproc( client, &offset, 4) != 4 ) {
perror ("TIFF Header read error");
exit( EXIT_FAILURE );
}
if (isByteSwapped) {
TIFFSwabLong (&offset);
}
ctif->ifd0pos=offset;
ctif->ifd0p=malloc( sizeof(char) * offset );
if (NULL == ctif->ifd0p) {
fprintf (stderr, "could not allocate memory for ifd0p\n");
exit( EXIT_FAILURE );
}
seekproc(client, offset, SEEK_SET);
uint16 count;
if ( readproc( client, &count, 2) != 2 ) {
perror ("TIFF Header read error2");
exit( EXIT_FAILURE );
}
return memoized_offset;
if (is_byteswapped(ctif))
TIFFSwabShort(&count);
ctif->ifd0c = count;
assert(0 != ctif->ifd0c);
return offset;
}
/* scans first IDF and returns count of tags
* Hint: sideeffect, if succeed the seek points to beginning of the first
* IFD-entry */
int TIFFGetRawTagListCount (TIFF * tif) {
thandle_t client = TIFFClientdata(tif);
TIFFReadWriteProc readproc = TIFFGetReadProc(tif);
TIFFSeekProc seekproc = TIFFGetSeekProc(tif);
int TIFFGetRawTagListCount (ctiff_t * ctif, uint32 ifdpos) {
/* parse TIF */
thandle_t client = TIFFClientdata(ctif->tif);
TIFFReadWriteProc readproc = TIFFGetReadProc(ctif->tif);
TIFFSeekProc seekproc = TIFFGetSeekProc(ctif->tif);
if (! seekproc) {
perror ("could not get TIFFGetSeekProc");
}
@ -422,7 +437,7 @@ int TIFFGetRawTagListCount (TIFF * tif) {
//int fd = TIFFFileno( tif);
/* seek the image file directory (bytes 4-7) */
uint32 offset = get_first_IFD( tif );
uint32 offset = ifdpos;
// printf("diroffset to %i (0x%04lx)\n", offset, offset);
//printf("byte swapped? %s\n", (TIFFIsByteSwapped(tif)?"true":"false"));
@ -441,18 +456,18 @@ int TIFFGetRawTagListCount (TIFF * tif) {
exit( EXIT_FAILURE );
}
if (TIFFIsByteSwapped(tif))
if (is_byteswapped(ctif))
TIFFSwabShort(&count);
return count;
}
/* scans first IDF and returns the n-th tag */
tag_t TIFFGetRawTagListEntry( TIFF * tif, int tagidx ) {
int byteswapped = TIFFIsByteSwapped(tif);
int count = TIFFGetRawTagListCount( tif);
thandle_t client = TIFFClientdata(tif);
TIFFReadWriteProc readproc = TIFFGetReadProc(tif);
TIFFSeekProc seekproc = TIFFGetSeekProc(tif);
tag_t TIFFGetRawTagListEntry( ctiff_t * ctif, int tagidx ) {
int byteswapped = is_byteswapped(ctif);
int count = get_ifd0_count( ctif);
thandle_t client = TIFFClientdata(ctif->tif);
TIFFReadWriteProc readproc = TIFFGetReadProc(ctif->tif);
TIFFSeekProc seekproc = TIFFGetSeekProc(ctif->tif);
if (! seekproc) {
perror ("could not get TIFFGetSeekProc");
}
@ -472,6 +487,7 @@ tag_t TIFFGetRawTagListEntry( TIFF * tif, int tagidx ) {
exit(EXIT_FAILURE);
}
*/
seekproc(client, ctif->ifd0pos+2, SEEK_SET); /* IFD0 plus 2byte to get IFD-entries */
if ( readproc( client, ifdentries, 12 * count) != 12*count ) {
perror ("TIFF Header read error3");
exit( EXIT_FAILURE );
@ -517,11 +533,11 @@ LABEL1:
/* get count-data datastream from offset-address */
offset_t read_offsetdata( TIFF * tif, uint32 address, uint16 count, uint16 datatype) {
offset_t read_offsetdata( ctiff_t * ctif, uint32 address, uint16 count, uint16 datatype) {
//int fd = TIFFFileno( tif);
thandle_t client = TIFFClientdata(tif);
TIFFReadWriteProc readproc = TIFFGetReadProc(tif);
TIFFSeekProc seekproc = TIFFGetSeekProc(tif);
thandle_t client = TIFFClientdata(ctif->tif);
TIFFReadWriteProc readproc = TIFFGetReadProc(ctif->tif);
TIFFSeekProc seekproc = TIFFGetSeekProc(ctif->tif);
if (! seekproc) {
perror ("could not get TIFFGetSeekProc");
}
@ -603,16 +619,17 @@ offset_t read_offsetdata( TIFF * tif, uint32 address, uint16 count, uint16 datat
}
/* scans first IDF and returns the type of the n-th tag */
ifd_entry_t TIFFGetRawTagIFDListEntry( TIFF * tif, int tagidx ) {
int count = TIFFGetRawTagListCount( tif);
int byteswapped = TIFFIsByteSwapped(tif);
ifd_entry_t TIFFGetRawTagIFDListEntry( ctiff_t * ctif, int tagidx ) {
int count = get_ifd0_count( ctif);
assert( count > 0);
int byteswapped = is_byteswapped(ctif);
#ifdef DEBUG
printf(" count of tags = %i\n", count);
#endif
// int fd = TIFFFileno( tif);
thandle_t client = TIFFClientdata(tif);
TIFFReadWriteProc readproc = TIFFGetReadProc(tif);
TIFFSeekProc seekproc = TIFFGetSeekProc(tif);
thandle_t client = TIFFClientdata(ctif->tif);
TIFFReadWriteProc readproc = TIFFGetReadProc(ctif->tif);
TIFFSeekProc seekproc = TIFFGetSeekProc(ctif->tif);
if (! seekproc) {
perror ("could not get TIFFGetSeekProc");
}
@ -635,6 +652,8 @@ ifd_entry_t TIFFGetRawTagIFDListEntry( TIFF * tif, int tagidx ) {
exit(EXIT_FAILURE);
}
*/
seekproc(client, ctif->ifd0pos+2, SEEK_SET); /* IFD0 plus 2byte to get IFD-entries */
if ( readproc( client, ifdentries, 12 * count) != 12*count ) {
perror ("TIFF Header read error4");
exit( EXIT_FAILURE );
@ -760,18 +779,18 @@ printf("\ncount=%0x\n\n", count);
}
/* TODO */
ifd_entry_t TIFFGetRawIFDEntry( TIFF * tif, tag_t tag) {
ifd_entry_t TIFFGetRawIFDEntry( ctiff_t * ctif, tag_t tag) {
int tagidx = -1;
int i;
for (i= 0; i < TIFFGetRawTagListCount( tif ); i++) {
if (tag > 253 && tag == TIFFGetRawTagListEntry( tif, i )) {
for (i= 0; i < get_ifd0_count( ctif ); i++) {
if (tag > 253 && tag == TIFFGetRawTagListEntry( ctif, i )) {
tagidx= i;
break;
};
};
ifd_entry_t ifd_entry;
if (tagidx >= 0) {
ifd_entry = TIFFGetRawTagIFDListEntry( tif, tagidx );
ifd_entry = TIFFGetRawTagIFDListEntry( ctif, tagidx );
} else { /* tag not defined */
printf("\ttag %u (%s) was not found, but requested because defined\n", tag, TIFFTagName(tag));
ifd_entry.value_or_offset = is_error;
@ -780,10 +799,10 @@ ifd_entry_t TIFFGetRawIFDEntry( TIFF * tif, tag_t tag) {
return ifd_entry;
}
/* scans first IDF and returns the type of the n-th tag */
uint32 TIFFGetRawTagTypeListEntry( TIFF * tif, int tagidx ) {
uint32 TIFFGetRawTagTypeListEntry( ctiff_t * ctif, int tagidx ) {
if (tagidx >= 0) {
ifd_entry_t ifd_entry;
ifd_entry = TIFFGetRawTagIFDListEntry( tif, tagidx );
ifd_entry = TIFFGetRawTagIFDListEntry( ctif, tagidx );
return ifd_entry.datatype;
} else { /* tag not defined */
fprintf(stderr, "tagidx should be greater equal 0");
@ -799,17 +818,17 @@ if (tagidx >= 0) {
* @return datatype of given tag
* if tag does not exists the function aborts with an error
*/
TIFFDataType TIFFGetRawTagType(TIFF * tif, tag_t tag) {
TIFFDataType TIFFGetRawTagType(ctiff_t * ctif, tag_t tag) {
int tagidx = -1;
int i;
for (i= 0; i < TIFFGetRawTagListCount( tif ); i++) {
if (tag > 253 && tag == TIFFGetRawTagListEntry( tif, i )) {
for (i= 0; i < get_ifd0_count( ctif ); i++) {
if (tag > 253 && tag == TIFFGetRawTagListEntry( ctif, i )) {
tagidx= i;
break;
};
};
if (tagidx >= 0) {
TIFFDataType datatype = TIFFGetRawTagTypeListEntry( tif, tagidx );
TIFFDataType datatype = TIFFGetRawTagTypeListEntry( ctif, tagidx );
#ifdef DEBUG
printf("### datatype=%i \n", datatype);
#endif
@ -820,6 +839,96 @@ TIFFDataType TIFFGetRawTagType(TIFF * tif, tag_t tag) {
}
}
ctiff_t * initialize_ctif(const char * tiff_file) {
/* load tiff file */
TIFF* tif = NULL;
tif = TIFFOpen( tiff_file, "rm");
if (NULL == tif) {
fprintf( stderr, "file '%s' could not be opened\n", tiff_file);
exit (EXIT_FAILURE);
};
ctiff_t * ctif = malloc ( sizeof( ctiff_t) );
if (NULL == ctif) {
fprintf( stderr, "could not allocate memory for ctiff_t\n");
exit (EXIT_FAILURE);
}
ctif->tif = tif;
ctif->filename = strdup(tiff_file);
ctif->ifd0p=NULL;
ctif->ifd0pos= 0;
ctif->ifd0c= 0;
parse_header_and_endianess( ctif );
get_first_IFD( ctif );
return ctif;
}
void free_ctif( ctiff_t * ctif) {
assert( NULL != ctif);
TIFFClose(ctif->tif);
free (ctif);
ctif = NULL;
}
uint32 get_ifd0_pos( ctiff_t * ctif ) {
assert( NULL != ctif);
assert( NULL != ctif->ifd0p);
return ctif->ifd0pos;
}
uint16 get_ifd0_count( ctiff_t * ctif ) {
assert( NULL != ctif);
assert( NULL != ctif->ifd0p);
return ctif->ifd0c;
}
char is_byteswapped( ctiff_t * ctif ) {
assert( NULL != ctif);
return ctif->isbyteswapped;
}
uint32 get_next_ifd_pos(ctiff_t * ctif, uint32 actual_pos) {
assert( NULL != ctif);
assert( NULL != ctif->ifd0p);
thandle_t client = TIFFClientdata(ctif->tif);
TIFFReadWriteProc readproc = TIFFGetReadProc(ctif->tif);
TIFFSeekProc seekproc = TIFFGetSeekProc(ctif->tif);
if (! seekproc) {
perror ("could not get TIFFGetSeekProc");
}
if (! readproc) {
perror ("could not get TIFFGetReadProc");
}
seekproc(client, actual_pos, SEEK_SET);
uint16 count;
/*if (read(fd, &count, 2) != 2) {
perror ("TIFF Header read error2");
exit(EXIT_FAILURE);
}
*/
if ( readproc( client, &count, 2) != 2 ) {
perror ("TIFF Header read error2");
exit( EXIT_FAILURE );
}
if (ctif->isbyteswapped)
TIFFSwabShort(&count);
seekproc(client, 12 * count, SEEK_CUR);
uint32 offset;
if ( readproc( client, &offset, 4) != 4 ) {
perror ("TIFF Header read error3");
exit( EXIT_FAILURE );
}
if (ctif->isbyteswapped)
TIFFSwabLong(&offset);
return offset;
}
/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 smarttab expandtab :*/

6
src/ifdrules/check_all_IFDs_are_word_aligned.c

@ -9,13 +9,15 @@
#include "check.h"
#include "check_helper.h"
#include <unistd.h>
#include <assert.h>
/* check if IFDs are word aligned */
ret_t check_all_IFDs_are_word_aligned(TIFF * tif) {
ret_t check_all_IFDs_are_word_aligned(ctiff_t * ctif) {
//printf("check if all IFDs are word aligned\n");
tif_rules("all IFDs are word aligned");
uint32 ifd = get_first_IFD( tif ); /* TODO: check all other IFDs, too */
// assert( NULL != ctif->ifd0p );
uint32 ifd = get_ifd0_pos( ctif ); /* TODO: check all other IFDs, too */
if ( 0 != (ifd & 1)) {
// FIXME: tif_fails?
char array[80];

8
src/ifdrules/check_all_offsets_are_used_once_only.c

@ -12,10 +12,10 @@
/* check if offsets are used only once */
ret_t check_all_offsets_are_used_once_only(TIFF * tif) {
ret_t check_all_offsets_are_used_once_only(ctiff_t * ctif) {
//printf("check if all offsets are used once only\n");
tif_rules("all offsets are used once only");
int count = TIFFGetRawTagListCount( tif);
int count = get_ifd0_count( ctif);
int tagidx;
uint32 offsets[ count ];
uint32 tags[ count ];
@ -27,10 +27,10 @@ ret_t check_all_offsets_are_used_once_only(TIFF * tif) {
tags[ tagidx ] = 0;
}
for (tagidx = 0; tagidx< count; tagidx++) {
ifd_entry_t ifd_entry = TIFFGetRawTagIFDListEntry( tif, tagidx );
ifd_entry_t ifd_entry = TIFFGetRawTagIFDListEntry( ctif, tagidx );
if (ifd_entry.value_or_offset==is_offset) {
uint32 offset = ifd_entry.data32offset;
uint32 tag = TIFFGetRawTagListEntry( tif, tagidx);
uint32 tag = TIFFGetRawTagListEntry( ctif, tagidx);
for (i=0; i< count_of_offsets; i++) {
if (offsets[ i ] == offset) {
// FIXME: tif_fails?

8
src/ifdrules/check_all_offsets_are_word_aligned.c

@ -12,17 +12,17 @@
/* check if offsets are word aligned */
ret_t check_all_offsets_are_word_aligned(TIFF * tif) {
ret_t check_all_offsets_are_word_aligned(ctiff_t * ctif) {
//printf("check if all offsets are word aligned\n");
tif_rules("all offsets are word aligned");
int count = TIFFGetRawTagListCount( tif);
int count = get_ifd0_count( ctif);
int tagidx;
for (tagidx = 0; tagidx< count; tagidx++) {
ifd_entry_t ifd_entry = TIFFGetRawTagIFDListEntry( tif, tagidx );
ifd_entry_t ifd_entry = TIFFGetRawTagIFDListEntry( ctif, tagidx );
if (ifd_entry.value_or_offset==is_offset) {
uint32 offset = ifd_entry.data32offset;
if ( 0 != (offset & 1)) {
uint32 tag = TIFFGetRawTagListEntry( tif, tagidx);
uint32 tag = TIFFGetRawTagListEntry( ctif, tagidx);
// FIXME: tif_fails?
char array[80];
snprintf(array, sizeof(array), "pointing to 0x%08x and is not word-aligned", offset);

65
src/ifdrules/check_has_only_one_ifd.c

@ -11,72 +11,15 @@
#include <unistd.h>
/* check if only one IFD exists */
ret_t check_has_only_one_ifd(TIFF* tif) {
ret_t check_has_only_one_ifd(ctiff_t * ctif) {
//printf("check if only one IFD exists\n");
tif_rules("only one IFD exists");
/* next commented lines, because TIFFNumberOfDirectories are in endless loop,
* if the TIFF file from https://github.com/EasyinnovaSL/DPFManager/blob/develop/src/test/resources/IFD%20struct/Circular%20E.tif
* is read:
if (1 == TIFFNumberOfDirectories( tif )) {
ret_t res;
res.returnmsg=NULL;
res.returncode=0;
return res;
}*/
//int fd = TIFFFileno( tif);
*/
/* seek the image file directory (bytes 4-7) */
uint32 offset = get_first_IFD( tif );
// printf("diroffset to %i (0x%04lx)\n", offset, offset);
//printf("byte swapped? %s\n", (TIFFIsByteSwapped(tif)?"true":"false"));
thandle_t client = TIFFClientdata(tif);
TIFFReadWriteProc readproc = TIFFGetReadProc(tif);
TIFFSeekProc seekproc = TIFFGetSeekProc(tif);
if (! seekproc) {
perror ("could not get TIFFGetSeekProc");
}
if (! readproc) {
perror ("could not get TIFFGetReadProc");
}
/* read and seek to IFD address */
// lseek(fd, (off_t) offset, SEEK_SET);
seekproc(client, offset, SEEK_SET);
uint16 count;
/*
if (read(fd, &count, 2) != 2) {
perror ("TIFF Header read error2");
exit(EXIT_FAILURE);
}
*/
if ( readproc( client, &count, 2) != 2 ) {
perror ("TIFF Header read error2");
exit( EXIT_FAILURE );
}
if (TIFFIsByteSwapped(tif))
TIFFSwabShort(&count);
//lseek(fd, 12 * count, SEEK_CUR);
seekproc(client, 12*count, SEEK_CUR);
/* next 4 bytes are the new IFDn entry, should be empty */
uint32 IFDn;
/*
if (read(fd, &IFDn, 4) != 4) {
perror ("TIFF Header read error3");
exit(EXIT_FAILURE);
}
*/
if ( readproc( client, &IFDn, 4) != 4 ) {
perror ("TIFF Header read error3");
exit( EXIT_FAILURE );
}
if (TIFFIsByteSwapped(tif))
TIFFSwabLong(&IFDn);
uint32 offset = get_ifd0_pos(ctif );
uint32 IFDn = get_next_ifd_pos( ctif, offset );
if (0 == IFDn) {
ret_t res;
res.returnmsg=NULL;

20
src/ifdrules/check_tagorder.c

@ -10,14 +10,11 @@
#include "check_helper.h"
#include <unistd.h>
ret_t check_tagorder(TIFF* tif) {
//printf("check if tags are in ascending order\n");
ret_t check_tagorder(ctiff_t * ctif) {
tif_rules("tags are in ascending order");
int count = TIFFGetRawTagListCount( tif);
//int fd = TIFFFileno( tif);
thandle_t client = TIFFClientdata(tif);
TIFFReadWriteProc readproc = TIFFGetReadProc(tif);
TIFFSeekProc seekproc = TIFFGetSeekProc(tif);
thandle_t client = TIFFClientdata(ctif->tif);
TIFFReadWriteProc readproc = TIFFGetReadProc(ctif->tif);
TIFFSeekProc seekproc = TIFFGetSeekProc(ctif->tif);
if (! seekproc) {
perror ("could not get TIFFGetSeekProc");
}
@ -25,8 +22,9 @@ ret_t check_tagorder(TIFF* tif) {
perror ("could not get TIFFGetReadProc");
}
uint32 offset = get_ifd0_pos(ctif);
int count = get_ifd0_count(ctif);
//printf("count %i\n", count);
/* read count of tags (2 Bytes) */
int i;
/* replace i/o operatrions with in-memory-operations */
@ -38,6 +36,8 @@ ret_t check_tagorder(TIFF* tif) {
exit(EXIT_FAILURE);
}
*/
seekproc(client, offset+2, SEEK_SET);
if ( readproc( client, ifdentries, 12 * count) != 12*count ) {
perror ("TIFF Header read error5");
exit( EXIT_FAILURE );
@ -51,13 +51,13 @@ ret_t check_tagorder(TIFF* tif) {
uint8 hi = *e;
uint16 tag = (hi << 8) + lo;
e++;
if (TIFFIsByteSwapped(tif))
if (is_byteswapped(ctif))
TIFFSwabShort(&tag);
if (i>0 && lasttag >= tag) {
// printf("tag idx=%i, tag=%u (0x%04x) (0x%02x) (0x%02x)\n", i, tag, tag, hi, lo);
free( ifdentries );
// FIXME: tif_fails?
char array[80];
char array[160];
snprintf(array, sizeof(array), "Invalid TIFF directory; tags are not sorted in ascending order, previous tag:%u (%s) , actual tag:%u (%s) at pos %i of %i\n", lasttag, TIFFTagName(lasttag), tag, TIFFTagName(tag), i, count);
return tif_fails(array);
}

37
src/parser/config_parser.c

@ -40,7 +40,7 @@ executionplan_t plan;
* @param fp pointer to funcu structure to hold function and its parameters
* @return ret_t structure for results of called function
*/
ret_t call_fp(TIFF* tif, funcp fp) {
ret_t call_fp(ctiff_t * ctif, funcp fp) {
ret_t ret;
ret.returncode=1;
ret.returnmsg=NULL; /*@null@*/
@ -53,7 +53,7 @@ ret_t call_fp(TIFF* tif, funcp fp) {
function = fp->fu.ftifp;
assert(NULL != function);
assert(NULL != function->functionp);
ret = (function->functionp)(tif);
ret = (function->functionp)(ctif);
break;
}
case f_tifp_tag:
@ -62,7 +62,7 @@ ret_t call_fp(TIFF* tif, funcp fp) {
function = fp->fu.ftifp_tag;
assert(NULL != function);
assert(NULL != function->functionp);
ret = (function->functionp)(tif, function->a);
ret = (function->functionp)(ctif, function->a);
break;
}
case f_tifp_tag_uint:
@ -74,7 +74,7 @@ ret_t call_fp(TIFF* tif, funcp fp) {
#ifdef DEBUG
printf("debug: found a=%i b=%u\n", function->a, function->b);
#endif
ret = (function->functionp)(tif, function->a, function->b);
ret = (function->functionp)(ctif, function->a, function->b);
break;
}
case f_tifp_tag_uint_uint:
@ -86,7 +86,7 @@ ret_t call_fp(TIFF* tif, funcp fp) {
#ifdef DEBUG
printf("debug: found a=%i b=%u c=%u\n", function->a, function->b, function->c);
#endif
ret = (function->functionp)(tif, function->a, function->b, function->c);
ret = (function->functionp)(ctif, function->a, function->b, function->c);
break;
}
case f_tifp_tag_int_uintp:
@ -98,7 +98,7 @@ ret_t call_fp(TIFF* tif, funcp fp) {
#ifdef DEBUG
printf("debug: found a=%i b=%i c=%p\n", function->a, function->b, function->c);
#endif
ret = (function->functionp)(tif, function->a, function->b, function->c);
ret = (function->functionp)(ctif, function->a, function->b, function->c);
break;
}
case f_tifp_tag_charp:
@ -110,7 +110,7 @@ ret_t call_fp(TIFF* tif, funcp fp) {
#ifdef DEBUG
printf("debug: found a=%i b=%s\n", function->a, function->b);
#endif
ret = (function->functionp)(tif, function->a, function->b);
ret = (function->functionp)(ctif, function->a, function->b);
break;
}
@ -127,7 +127,7 @@ ret_t call_fp(TIFF* tif, funcp fp) {
* @param tif pointer to TIFF structure
* @return return-code is 0 if all called functions are succeed
*/
int execute_plan (TIFF * tif) {
int execute_plan (ctiff_t * ctif) {
executionentry_t * this_exe_p = plan.start;
int is_valid = 0; /* 0 means valid, >0 invalid */
while (NULL != this_exe_p) {
@ -151,7 +151,7 @@ int execute_plan (TIFF * tif) {
#ifdef DEBUG
printf("execute: we have a predicate predicate... ");
#endif
res = call_fp(tif, fp->pred->pred);
res = call_fp(ctif, fp->pred->pred);
if (0 != res.returncode ) {
#ifdef DEBUG
printf("execute: predicate predicate was not successfull, skipped check\n");
@ -167,7 +167,7 @@ int execute_plan (TIFF * tif) {
}
};
/* no predicate predicate or predicate predicate successfull*/
res = call_fp(tif, fp->pred);
res = call_fp(ctif, fp->pred);
if (0 != res.returncode ) {
#ifdef DEBUG
printf("execute: predicate was not successfull, skipped check\n");
@ -185,7 +185,7 @@ int execute_plan (TIFF * tif) {
}
/* no predicate or predicate successfull*/
parser_state.called_tags[fp->tag]++;
this_exe_p->result= call_fp (tif, fp );
this_exe_p->result= call_fp (ctif, fp );
if (0 != this_exe_p->result.returncode) { is_valid++; }
}
exitcall: this_exe_p = this_exe_p->next;
@ -197,7 +197,7 @@ exitcall: this_exe_p = this_exe_p->next;
int tag;
for (tag=MINTAGS; tag<MAXTAGS; tag++) {
if (0 == parser_state.called_tags[tag]) { /* only unchecked tags */
ret_t res = check_notag( tif, tag);
ret_t res = check_notag( ctif, tag);
if (0 != res.returncode) { /* check if tag is not part of tif */
/* tag does not exist */
is_valid++;
@ -302,7 +302,7 @@ int append_function_to_plan (funcp fp, const char * name ) {
* @param function adress of function
* @param fname name of function as combined message (already allocated)
*/
void _helper_add_fsp_tifp(struct funcu * f, ret_t (* function)(TIFF *), char * fname) {
void _helper_add_fsp_tifp(struct funcu * f, ret_t (* function)(ctiff_t *), char * fname) {
/* create datastruct for fp */
struct f_tifp_s * fsp = NULL;
fsp = malloc( sizeof( struct f_tifp_s ));
@ -323,7 +323,7 @@ void _helper_add_fsp_tifp(struct funcu * f, ret_t (* function)(TIFF *), char * f
* @param fname name of function as combined message (already allocated)
* @param tag tag
*/
void _helper_add_fsp_tifp_tag(struct funcu * f, ret_t (* function)(TIFF *, tag_t), char * fname, tag_t tag) {
void _helper_add_fsp_tifp_tag(struct funcu * f, ret_t (* function)(ctiff_t *, tag_t), char * fname, tag_t tag) {
struct f_tifp_tag_s * fsp = NULL;
fsp = malloc( sizeof( struct f_tifp_tag_s ));
if (NULL == fsp) {
@ -344,7 +344,7 @@ void _helper_add_fsp_tifp_tag(struct funcu * f, ret_t (* function)(TIFF *, tag_t
* @param tag tag
* @param v param a for function
*/
void _helper_add_fsp_tifp_tag_uint(struct funcu * f, ret_t (* function)(TIFF *, tag_t, unsigned int), char * fname, tag_t tag, unsigned int v) {
void _helper_add_fsp_tifp_tag_uint(struct funcu * f, ret_t (* function)(ctiff_t *, tag_t, unsigned int), char * fname, tag_t tag, unsigned int v) {
/* create datastruct for fp */
struct f_tifp_tag_uint_s * fsp = NULL;
fsp = malloc( sizeof( struct f_tifp_tag_uint_s ));
@ -366,7 +366,7 @@ void _helper_add_fsp_tifp_tag_uint(struct funcu * f, ret_t (* function)(TIFF *,
* @param tag tag
* @param v param a for function
*/
void _helper_add_fsp_tifp_tag_charp(struct funcu * f, ret_t (* function)(TIFF *, tag_t, const char *), char * fname, tag_t tag, const char * v) {
void _helper_add_fsp_tifp_tag_charp(struct funcu * f, ret_t (* function)(ctiff_t *, tag_t, const char *), char * fname, tag_t tag, const char * v) {
/* create datastruct for fp */
struct f_tifp_tag_charp_s * fsp = NULL;
fsp = malloc( sizeof( struct f_tifp_tag_charp_s ));
@ -390,7 +390,7 @@ void _helper_add_fsp_tifp_tag_charp(struct funcu * f, ret_t (* function)(TIFF *,
* @param count_of_values count of parameters for function
* @param rp pointer to parameter values
*/
void _helper_add_fsp_tifp_tag_uint_uintp(struct funcu * f, ret_t (* function)(TIFF *, tag_t, int, unsigned int *), char * fname, tag_t tag, int count_of_values, unsigned int * rp) {
void _helper_add_fsp_tifp_tag_uint_uintp(struct funcu * f, ret_t (* function)(ctiff_t *, tag_t, int, unsigned int *), char * fname, tag_t tag, int count_of_values, unsigned int * rp) {
/* create datastruct for fp */
#ifdef DEBUG
printf("count of values = %i\n", count_of_values);
@ -417,7 +417,7 @@ void _helper_add_fsp_tifp_tag_uint_uintp(struct funcu * f, ret_t (* function)(T
* @param l param a for function
* @param r param b for function
*/
void _helper_add_fsp_tifp_tag_uint_uint(struct funcu * f, ret_t (* function)(TIFF *, tag_t, unsigned int, unsigned int), char * fname, tag_t tag, unsigned int l, unsigned int r) {
void _helper_add_fsp_tifp_tag_uint_uint(struct funcu * f, ret_t (* function)(ctiff_t *, tag_t, unsigned int, unsigned int), char * fname, tag_t tag, unsigned int l, unsigned int r) {
/* create datastruct for fp */
struct f_tifp_tag_uint_uint_s * fsp = NULL;
fsp = malloc( sizeof( struct f_tifp_tag_uint_uint_s ));
@ -876,7 +876,6 @@ void parse_plan () {
/* function to parse a config file from file stream */
void parse_plan_via_stream( FILE * file ) {
reset_parser_state();
clear_cache();
yycontext ctx;
memset(&ctx, 0, sizeof(yycontext));
parser_state.stream=file;

6
src/tagrules/check_datetime.c

@ -46,14 +46,14 @@ int test_plausibility (int * year, int * month, int * day, int * hour, int * min
/** loads a tiff, fix it if needed, stores tiff
* @param filename filename which should be processed, repaired
*/
ret_t check_datetime(TIFF* tif ) {
tifp_check( tif);
ret_t check_datetime(ctiff_t * ctif ) {
tifp_check( ctif);
//printf("check if tag %u (%s) is correct\n", TIFFTAG_DATETIME, TIFFTagName(tif, TIFFTAG_DATETIME));
tif_rules_tag(TIFFTAG_DATETIME, "is correct");
/* find date-tag and fix it */
char *datetime=NULL;
uint32 count=0;
int found=TIFFGetField(tif, TIFFTAG_DATETIME, &datetime, &count);
int found=TIFFGetField(ctif->tif, TIFFTAG_DATETIME, &datetime, &count);
if (1==found) { /* there exists a datetime field */
int day=0;
int month=0;

6
src/tagrules/check_notag.c

@ -12,9 +12,9 @@
/* checks if TIF does not have a specified tag,
* needed only for checks to ensure whitelist */
ret_t check_notag(TIFF* tif, tag_t tag) {
tifp_check( tif);
ret_t res = check_tag_quiet( tif, tag);
ret_t check_notag(ctiff_t * ctif, tag_t tag) {
tifp_check( ctif);
ret_t res = check_tag_quiet( ctif, tag);
if (res.returncode == 0) {
return tif_fails_tag( tag, "", "which is not whitelisted or rule has no matched dependency");
} else {

10
src/tagrules/check_tag.c

@ -11,15 +11,15 @@
/* #define DEBUG */
/* checks if TIF has a specified tag */
ret_t check_tag(TIFF* tif, tag_t tag) {
ret_t check_tag(ctiff_t * ctif, tag_t tag) {
//printf("check if tag %u (%s) exists\n", tag, TIFFTagName(tif, tag));
tifp_check( tif);
tifp_check( ctif);
tif_rules_tag(tag, "exists");
ret_t res = check_tag_quiet( tif, tag);
ret_t res = check_tag_quiet( ctif, tag);
if (res.returncode == 0) {
res = check_tag_has_valid_type( tif, tag);
res = check_tag_has_valid_type( ctif, tag);
if (res.returncode == 0) {
return check_tag_has_valid_asciivalue(tif, tag);
return check_tag_has_valid_asciivalue(ctif, tag);
}
return tif_fails_by_returns(res);
} else {

20
src/tagrules/check_tag_has_some_of_these_values.c

@ -13,9 +13,9 @@
#define DEBUG
*/
ret_t check_tag_has_some_of_these_values(TIFF* tif, tag_t tag, int count, unsigned int * values) {
ret_t check_tag_has_some_of_these_values(ctiff_t * ctif, tag_t tag, int count, unsigned int * values) {
//printf("check if tag %u (%s) has some of these %i-values", tag, TIFFTagName(tif, tag), count);
tifp_check( tif);
tifp_check( ctif);
char msg[200];
snprintf(msg, sizeof(msg), "has some of these %i-values: ", count);
int i;
@ -26,10 +26,10 @@ ret_t check_tag_has_some_of_these_values(TIFF* tif, tag_t tag, int count, unsign
p++;
}
tif_rules_tag(tag, strdup(msg));
ret_t res = check_tag_has_valid_type( tif, tag);
ret_t res = check_tag_has_valid_type( ctif, tag);
if (res.returncode == 0) {
TIFFDataType datatype = TIFFGetRawTagType( tif, tag );
TIFFDataType datatype = TIFFGetRawTagType( ctif, tag );
switch (datatype) {
case TIFF_LONG: {
p = values;
@ -38,12 +38,12 @@ ret_t check_tag_has_some_of_these_values(TIFF* tif, tag_t tag, int count, unsign
#ifdef DEBUG
printf("### value = %u", *p);
#endif
res = check_tag_has_u32value(tif, tag, *p);
res = check_tag_has_u32value(ctif, tag, *p);
if (res.returncode == 0) return res;
p++;
}
uint32 val;
TIFFGetField(tif, tag, &val);
TIFFGetField(ctif->tif, tag, &val);
char value[40];
snprintf(value, sizeof(value), "does not have some of expected values (but have:%u)", val);
return tif_fails_tag( tag, "", strdup(value));
@ -56,12 +56,12 @@ ret_t check_tag_has_some_of_these_values(TIFF* tif, tag_t tag, int count, unsign
#ifdef DEBUG
printf("### value = %u", *p);
#endif
res = check_tag_has_u16value(tif, tag, *p);
res = check_tag_has_u16value(ctif, tag, *p);
if (res.returncode == 0) return res;
p++;
}
uint16 val;
TIFFGetField(tif, tag, &val);
TIFFGetField(ctif->tif, tag, &val);
char value[40];
snprintf(value, sizeof(value), "does not have some of expected values (but have:%u)", val);
return tif_fails_tag( tag, "", strdup(value));
@ -74,12 +74,12 @@ ret_t check_tag_has_some_of_these_values(TIFF* tif, tag_t tag, int count, unsign
#ifdef DEBUG
printf("### value = %u", *p);
#endif
res = check_tag_has_fvalue(tif, tag, *p);
res = check_tag_has_fvalue(ctif, tag, *p);
if (res.returncode == 0) return res;
p++;
}
float val;
TIFFGetField(tif, tag, &val);
TIFFGetField(ctif->tif, tag, &val);
char value[40];
snprintf(value, sizeof(value), "does not have some of expected values (but have:%f)", val);
return tif_fails_tag( tag, "", strdup(value));

8
src/tagrules/check_tag_has_valid_asciivalue.c

@ -13,9 +13,9 @@
*/
/* checks if TIF with tag and type ASCII */
ret_t check_tag_has_valid_asciivalue(TIFF* tif, tag_t tag) {
tifp_check( tif);
TIFFDataType datatype = TIFFGetRawTagType( tif, tag );
ret_t check_tag_has_valid_asciivalue(ctiff_t * ctif, tag_t tag) {
tifp_check( ctif);
TIFFDataType datatype = TIFFGetRawTagType( ctif, tag );
#ifdef DEBUG
printf("### datatype=%i \n", datatype);
#endif
@ -26,7 +26,7 @@ ret_t check_tag_has_valid_asciivalue(TIFF* tif, tag_t tag) {
//printf("check if tag %u (%s) has valid asciivalue\n", tag, TIFFTagName(tif, tag));
tif_rules_tag(tag, "has valid asciivalue");
int found=TIFFGetField(tif, tag, &string, &count);
int found=TIFFGetField(ctif->tif, tag, &string, &count);
if (1==found) { /* there exists a tag */
int i;
for (i=0; i<count; i++) {

6
src/tagrules/check_tag_has_valid_type.c

@ -11,11 +11,11 @@
/* #define DEBUG */
/* checks if TIF has a specified tag */
ret_t check_tag_has_valid_type(TIFF* tif, tag_t tag) {
ret_t check_tag_has_valid_type(ctiff_t * ctif, tag_t tag) {
//printf("check if tag %u (%s) has valid type\n", tag, TIFFTagName(tif, tag));
tifp_check( tif);
tifp_check( ctif);
tif_rules_tag(tag, "has valid type");
TIFFDataType datatype = TIFFGetRawTagType( tif, tag );
TIFFDataType datatype = TIFFGetRawTagType( ctif, tag );
#ifdef DEBUG
printf("### datatype=%i \n", datatype);
#endif

8
src/tagrules/check_tag_has_value.c

@ -16,14 +16,14 @@
*/
ret_t check_tag_has_value(TIFF* tif, tag_t tag, unsigned int value) {
ret_t check_tag_has_value(ctiff_t * ctif, tag_t tag, unsigned int value) {
// printf("check if tag %u (%s) has value %u\n", tag, TIFFTagName(tif, tag), value);
tifp_check( tif);
tifp_check( ctif);
tif_rules_tag(tag, "has value");
ret_t ret;
ret = check_tag_has_valid_type( tif, tag);
ret = check_tag_has_valid_type( ctif, tag);
if (ret.returncode == 0) {
ret = check_tag_has_value_quiet( tif, tag, value);
ret = check_tag_has_value_quiet( ctif, tag, value);
if (ret.returncode == 0) {
return ret;
}

14
src/tagrules/check_tag_has_value_in_range.c

@ -17,21 +17,21 @@
#define DEBUG
*/
ret_t check_tag_has_value_in_range(TIFF* tif, tag_t tag, unsigned int a, unsigned int b) {
ret_t check_tag_has_value_in_range(ctiff_t * ctif, tag_t tag, unsigned int a, unsigned int b) {
//printf("check if tag %u (%s) has value in range %u - %u\n", tag, TIFFTagName(tif, tag), a, b);
tifp_check( tif);
tifp_check( ctif);
char msg[