28 Commits

Author SHA1 Message Date
  Andreas Romeyke ae3824fcac - fixed package name (removing underscore, because not allowed in *.deb) 2 days ago
  Andreas Romeyke b80a0d7bd8 - fixed version detection 2 weeks ago
  Andreas Romeyke 10634909b8 - using unsigned int 2 weeks ago
  Andreas Romeyke 8d8460ab77 - using unsigned int for testpos 2 weeks ago
  Andreas Romeyke 290099a3d0 - empty 2 weeks ago
  Andreas Romeyke 621025c6c2 - using memcpy instead strncpy 2 weeks ago
  Andreas Romeyke 7343d94a04 - reenabled calloc instead malloc 2 weeks ago
  art1pirat 0d99d0e059 - added hint to memory mapped I/O 3 weeks ago
  art1pirat 34e6d2bf01 - bugfix, if mmap detected, the macro _HAVE_MMAP should be defined 3 weeks ago
  art1pirat 7e8263e9ba - bugfix, malloc with correct size 3 weeks ago
  art1pirat 505323a0d0 - bugfix, malloc with correct size 3 weeks ago
  art1pirat 7f150e7ee4 -reduced RENDERMINSIZE 3 weeks ago
  art1pirat 6441c2c19b - rewritten secstrcat() using strbuff_t 3 weeks ago
  art1pirat 7b60d4fe20 - added strbuff_t type 3 weeks ago
  art1pirat c3ea1c7064 - removed xml renderer 3 weeks ago
  Andreas Romeyke 36bcd5261f - fixed loop 5 months ago
  Andreas Romeyke 4f566bccae - fixed index variable type 5 months ago
  Andreas Romeyke 4d9d00968b - fixed sign-warning in snprintf/printf 5 months ago
  Andreas Romeyke de0a07425a - replaced literal with constant macro 5 months ago
  Andreas Romeyke b815fcde22 - moved MINTAGS and MAXTAGS to check.h 5 months ago
  Andreas Romeyke 69e557b6fc - minor, invert condition 5 months ago
  Andreas Romeyke 61c7ad4c99 - minor fixes 5 months ago
  Andreas Romeyke cc23acf6d1 - reordered structures to avoid padding and to improve cache hits 6 months ago
  Andreas Romeyke 1ebe0b54a9 - added improved message if GNU11 support not detected 6 months ago
  Andreas Romeyke c8b2bb534c - fixed gcc format-truncation-warnings 6 months ago
  Andreas Romeyke aedd23bde0 - added fix to reenable MS Windows Support via MinGW 6 months ago
  Andreas Romeyke 27809aed3d - fixed to define _GNU_SOURCE only once 6 months ago
  Andreas Romeyke 21a547e34a - add some function static 6 months ago
20 changed files with 340 additions and 454 deletions
Split View
  1. +1
    -0
      FAQ
  2. +20
    -15
      src/CMakeLists.txt
  3. +0
    -3
      src/checkit_tiff.c
  4. +25
    -11
      src/headers/check.h
  5. +1
    -1
      src/headers/check_helper.h
  6. +2
    -4
      src/headers/check_renderer.h
  7. +32
    -35
      src/headers/config_parser.h
  8. +17
    -17
      src/helper/check_helper.c
  9. +3
    -3
      src/helper/check_print.c
  10. +0
    -8
      src/helper/check_renderer.c
  11. +16
    -17
      src/helper/check_tiffparse.c
  12. +75
    -69
      src/helper/renderer/check_renderer_ansi.c
  13. +57
    -52
      src/helper/renderer/check_renderer_default.c
  14. +0
    -131
      src/helper/renderer/check_renderer_xml.c
  15. +69
    -70
      src/parser/config_parser.c
  16. +1
    -1
      src/tagrules/check_tag_has_valid_asciivalue.c
  17. +0
    -1
      src/tagrules/check_tag_has_value_in_range.c
  18. +3
    -2
      src/tagrules/check_tag_has_value_matching_regex.c
  19. +6
    -6
      src/tagrules/check_tag_has_valuelist.c
  20. +12
    -8
      src/validate_icc/check_icc_header.c

+ 1
- 0
FAQ View File

@ -61,6 +61,7 @@ A: No, the tool is optimized for very fast processing. On a NVME-based SSD it
cornercase, if you have a broken TIFF with very large IFDs. Because
checkit_tiff tries to find all errors in a given TIFF file it does not use
early aborts than some other tools.
You could also try the memory mapped I/O, which should be very fast on supported filesystems.
Q: I have a fully destroyed TIFF because checkit_tiff reports IFD errors. Is
there any chance to repair the file?


+ 20
- 15
src/CMakeLists.txt View File

@ -45,7 +45,6 @@ else()
message(STATUS "IPO / LTO unsupported: <${LTO_CHECK_ERROR}>")
endif()
# add default CFLAGS
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong -Wformat -Werror=format-security")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro -fPIE")
@ -57,7 +56,9 @@ CHECK_C_COMPILER_FLAG("-std=gnu11" COMPILER_SUPPORTS_GNU11)
if(COMPILER_SUPPORTS_GNU11)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
else()
message(STATUS "Your compiler (${CMAKE_C_COMPILER}) has no gnu11 support. If you are using clang on Apple OS X, please switch to gcc (version > 4.7) which is compliant with the C11 standard.")
message(STATUS "Your compiler (${CMAKE_C_COMPILER}) has no gnu11 support.")
message(STATUS "If you are using clang on Apple OS X, please switch to gcc (version > 4.7) which is compliant with the C11 standard.")
message(STATUS "If you are using MinGW or compile under MS Windows, the code could compile, but without any warranty and without any support!")
endif()
@ -109,6 +110,7 @@ CHECK_FUNCTION_EXISTS(munmap _HAVE_MUNMAP)
if(_HAVE_MMAP AND _HAVE_MUNMAP)
message(INFO "mmap found")
set(_HAVE__MMAP 1)
add_definitions(-D_HAVE_MMAP)
endif()
@ -147,32 +149,35 @@ include(InstallRequiredSystemLibraries)
set (CPACK_PACKAGE_VENDOR "Andreas Romeyke")
string(REGEX REPLACE "^v([0-9]+).*" "\\1" MAJOR_VERSION ${BUILD_TAG})
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+)\\.[0-9]+[^0-9].*" "\\1" MINOR_VERSION ${BUILD_TAG})
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+)[^0-9].*" "\\1" PATCH_VERSION ${BUILD_TAG})
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" MINOR_VERSION ${BUILD_TAG})
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" PATCH_VERSION ${BUILD_TAG})
message( "BUILDTAG (after) : '${BUILD_TAG}'")
message( "MAJOR VERSION: ${MAJOR_VERSION}")
message( "MINOR VERSION: ${MINOR_VERSION}")
message( "PATCH VERSION: ${PATCH_VERSION}")
set (CPACK_PACKAGE_NAME "checkit-tiff")
set (CPACK_PACKAGE_VERSION_MAJOR ${MAJOR_VERSION})
set (CPACK_PACKAGE_VERSION_MINOR ${MINOR_VERSION})
set (CPACK_PACKAGE_VERSION_PATCH ${PATCH_VERSION})
set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/../LICENSE")
set (CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/../README.1st_checkit")
set (CPACK_GENERATOR "TGZ;STGZ;TZ;DEB;RPM")
#set (CPACK_GENERATOR "DEB")
set (CPACK_PACKAGE_CONTACT "Andreas Romeyke checkit_tiff@andreas-romeyke.de")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "checkit-tiff is a policy-oriented conformance checker for baseline TIFFs")
set(CPACK_PACKAGE_DESCRIPTION "checkit-tiff is a conformance checker for baseline TIFFs (with various extensions). It works in different way than other tools. Instead to use a hardcoded rule set with predefined values, you are able to define tags and corresponding values more fine granulary. The rulesets are human readable and could be adapted to own needs.")
# Debian related
#set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc (>= 6.0)")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "checkit_tiff is a policy-oriented conformance checker for baseline TIFFs")
set(CPACK_PACKAGE_DESCRIPTION "checkit_tiff is a conformance checker for baseline TIFFs (with various
extensions). It works in different way than other tools. Instead to use a
hardcoded rule set with predefined values, you are able to define tags and
corresponding values more fine granulary. The rulesets are human readable and
could be adapted to own needs.")
set(CPACK_DEBIAN_PACKAGE_SECTION "misc")
set(CPACK_DEBIAN_COMPRESSION_TYPE "xz")
include(CPack)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set (CPACK_DEBIAN_PACKAGE_VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION})
#set (CPACK_DEBIAN_PACKAGE_ARCHITECTURE amd64)
set (CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT})
set (CPACK_DEBIAN_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}
${CPACK_PACKAGE_DESCRIPTION}")
set (CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
include(CPack)

+ 0
- 3
src/checkit_tiff.c View File

@ -114,9 +114,6 @@ int main (int argc, char * argv[]) {
case 'c': /* colorize output */
set_renderer_to_ansi();
break;
case 'x': /* xml output */
set_renderer_to_xml( optarg);
break;
case 'd': /* check directory */
flag_check_directory = FLAGGED;
printf("\nCheck all files in given directory\n");


+ 25
- 11
src/headers/check.h View File

@ -8,6 +8,9 @@
#ifndef _FIXIT_TIFF_CHECK
#define _FIXIT_TIFF_CHECK
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stdlib.h>
#include "tiff.h"
#include <stdio.h>
@ -19,7 +22,13 @@ typedef int thandle_t;
typedef uint16 tag_t;
typedef enum{ true=1, false=0 } bool_t;
typedef unsigned short int bool_t;
static const bool_t false = 0;
static const bool_t true = 1;
/* MINTAGS - MAXTAGS is range of possible existing TAG numbers */
#define MINTAGS 254U
#define MAXTAGS 65536U
typedef enum{ is_memmap, is_filep } ct_ioflag_t ; /* flag */
@ -28,15 +37,15 @@ typedef enum{ has_sorted_tags, has_unsorted_tags, unknown_tag_order } tagorder_t
typedef struct ctiff_s {
ct_ioflag_t ioflag;
tagorder_t tagorder;
int tag_cache[65536];
char *filename; /* filename */
uint8 * streamp; /* address of memory-mapped tif stream */
uint8 * actual_streamp;
uint32 streamlen; /* length of tif stream/file (in bytes) */
thandle_t fd; /* filedescriptor */
uint32 ifd0pos; /* offset in tif stream (in bytes) */
uint16 ifd0c; /* count of tags in first ifd */
int isbyteswapped; /* true if BigEndian */
char *filename; /* filename */
bool_t isbyteswapped; /* true if BigEndian */
int tag_cache[MAXTAGS];
} ctiff_t;
typedef enum{
@ -63,9 +72,9 @@ typedef enum{
} rm_type_t;
typedef struct retmsg_s {
rm_type_t rm_type;
char * rm_msg;
struct retmsg_s * next;
rm_type_t rm_type;
} retmsg_t;
#define ICC_ERROR_OFFSET 100
@ -134,12 +143,10 @@ typedef enum {
typedef struct ret_s {
returncode_t returncode;
char * value_found;
int logical_or_count;
char * value_found;
} ret_t;
typedef struct ifd_entry_s {
uint32 count; /* count of data */
TIFFDataType datatype;
@ -217,17 +224,17 @@ typedef struct mem_map_entry_s {
} mem_map_entry_t;
typedef struct mem_map_s {
mem_map_entry_t * base_p;
int count;
mem_map_entry_t * base_p;
uint32 max_len; /* TIFF length */
int max_entries;
uint32 max_len; /* TIFF length */
} mem_map_t;
#define EXPECTSTRLEN 500
#define VALUESTRLEN 500
#define TIFFAILSTRLEN (EXPECTSTRLEN + VALUESTRLEN)
#define MAXRESULT 200000
#define MAXRESULT 48000U
#ifdef HARDEN
#define TIFP_CHECK( ctif, ret ) \
@ -240,6 +247,13 @@ typedef struct mem_map_s {
#define TIFP_CHECK( ctif, ret ) ;
#endif
typedef struct strbuff_s {
size_t bufsize;
size_t pos;
char * bufpos;
char * buf;
} strbuff_t;
//returncode_t tifp_check( ctiff_t * ctif);
/*
ret_t tif_returns(tag_t tag, const char* expected, const char* value);


+ 1
- 1
src/headers/check_helper.h View File

@ -33,7 +33,7 @@ ret_t TIFFGetFieldLONG(ctiff_t * ctif, const tag_t tag, uint32 ** result_long_p,
ret_t TIFFGetFieldSHORT(ctiff_t * ctif, const tag_t tag, uint16 ** result_short_p, uint32 * result_countp);
ret_t TIFFGetFieldRATIONAL(ctiff_t * ctif, const tag_t tag, float ** result_float_p, uint32 * result_countp);
ret_t read_offsetdata(ctiff_t * ctif, const uint32 address, const uint32 count, const uint16 datatype, offset_t * result_offsetp, ret_t * ret_p);
char * secstrcat (char * dest, const char * src, const size_t * maxsize_p);
strbuff_t * secstrcat (strbuff_t * dest, const char * src);
ctiff_t * initialize_ctif( const char * tiff_file, ct_ioflag_t );
void free_ctif( ctiff_t * ctif);
uint32 get_ifd0_pos( ctiff_t * ctif);


+ 2
- 4
src/headers/check_renderer.h View File

@ -13,18 +13,16 @@
/* 65536 Tags a 256 chars message + 100 Messages */
/* #define RENDERSIZE (65536*256 + 100*256) */
#define RENDERMINSIZE (1024)
#define RENDERMINSIZE (512)
#define RENDERMAXSIZE (33554432)
typedef enum{ render_default, render_ansi, render_xml} render_type;
typedef enum{ render_default, render_ansi} render_type;
typedef enum{ within_valid, within_error, within_file, within_summaryerror, within_harderror } render_context_t;
const char * renderer ( const retmsg_t * ret );
void set_renderer_to_ansi();
void set_renderer_to_xml(const char *);
void set_renderer_to_quiet();
const char * renderer_ansi ( const retmsg_t * ret, short int );
const char * renderer_default ( const retmsg_t * ret, short int );
const char * renderer_xml ( const retmsg_t * ret, const char * xml );
#endif


+ 32
- 35
src/headers/config_parser.h View File

@ -1,7 +1,7 @@
/* rule based checks if given TIFF is a specific baseline TIFF
*
*
* author: Andreas Romeyke, 2015
* licensed under conditions of libtiff
* licensed under conditions of libtiff
* (see http://libtiff.maptools.org/misc.html)
*
*/
@ -24,15 +24,11 @@ typedef enum {
mode_enable_deep_geotiff_checks=16,
} modes_t;
/* MINTAGS - MAXTAGS is range of possible existing TAG numbers */
#define MINTAGS 254
#define MAXTAGS 65536
#define MAXINCLUDEDEPTH 1
/* the stack size depends on count of rules and count of numbers, in general
* 65536 should be enough. Otherwise you need to increase it */
#define MAXSTACKDEPTH 65536
#define MAXSTACKDEPTH 65536u
typedef enum {
fc_true,
fc_false,
@ -62,27 +58,28 @@ typedef enum {
fc_dummy
} function_t;
#define INTERNALSTACKDEPTH 10
#define INTERNALSTACKDEPTH 8u
typedef struct internal_entry_s {
int lineno;
bool_t is_precondition;
tag_t tag;
function_t function;
short int i_stackp;
short int val_stackp;
short int regex_stackp;
unsigned int i_stack[INTERNALSTACKDEPTH];
values_t val_stack[INTERNALSTACKDEPTH];
char * regex_stack[INTERNALSTACKDEPTH];
unsigned int i_stack[INTERNALSTACKDEPTH];
int i_stackp;
int val_stackp;
int regex_stackp;
} internal_entry_t;
typedef struct full_res_s {
int lineno;
tag_t tag;
function_t function;
returncode_t returncode;
tag_t tag;
char * expected_value;
char * found_value;
returncode_t returncode;
} full_res_t;
typedef struct parser_state_s {
@ -91,33 +88,33 @@ typedef struct parser_state_s {
int valuelist;
tag_t tag;
tag_t tagref;
values_t val_stack[MAXSTACKDEPTH];
char * regex_stack[MAXSTACKDEPTH];
reference_t any_reference;
requirements_t req;
unsigned int i_stack[MAXSTACKDEPTH];
int i_stackp;
int val_stackp;
int regex_stackp;
int called_tags[MAXTAGS];
int mode;
int logical_elements;
short int i_stackp;
short int val_stackp;
FILE * stream;
reference_t any_reference;
const char * regex_string;
int includedepth;
full_res_t result_stack[MAXRESULT];
int result_stackp;
int exe_stackp;
internal_entry_t exe_stack[MAXSTACKDEPTH];
int mode;
bool_t within_logical_or;
int logical_elements;
short int regex_stackp;
int called_tags[MAXTAGS];
full_res_t result_stack[MAXRESULT];
values_t val_stack[MAXSTACKDEPTH];
char * regex_stack[MAXSTACKDEPTH];
unsigned int i_stack[MAXSTACKDEPTH];
internal_entry_t exe_stack[MAXSTACKDEPTH];
} parser_state_t;
void _helper_push_result(full_res_t res);
full_res_t _helper_pop_result();
void _helper_mark_top_n_results(int n, returncode_t type);
full_res_t _helper_get_nth(int n);
ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t * exep);
void set_parse_error(char * msg, char * yytext);
static void _helper_push_result(full_res_t res);
static full_res_t _helper_pop_result();
static void _helper_mark_top_n_results(int n, returncode_t type);
static full_res_t _helper_get_nth(int n);
static ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t * exep);
static void set_parse_error(char * msg, char * yytext);
void execute_plan (ctiff_t * ctif);
void print_plan ();
ret_t print_plan_results (retmsg_t *);
@ -125,9 +122,9 @@ void clean_plan ();
void parse_plan ();
void parse_plan_via_stream (FILE * file);
void parse_plan_via_file (const char * cfg_file);
void add_default_rules_to_plan();
void set_include( const char * );
static void add_default_rules_to_plan();
static void set_include( const char * );
void exe_printstack_human_readable ();
void result_push(full_res_t);
static void result_push(full_res_t);
#endif
/* _FIXIT_TIFF_CONFIG_PARSER */

+ 17
- 17
src/helper/check_helper.c View File

@ -6,35 +6,35 @@
*
*/
#define _GNU_SOURCE
#include "check.h"
#include "check_helper.h"
#include <sys/stat.h>
#include <assert.h>
#ifndef _WIN32
#include <byteswap.h>
#endif
#ifdef _WIN32
#define bswap_16 _byteswap_ushort
#define bswap_32 _byteswap_ulong
#endif
/*
#define DEBUG
*/
/* dest should not exceed maxsize */
char * secstrcat (char * dest, const char * src, const size_t * maxsize_p) {
if (NULL == dest) {
fprintf(stderr, "internal error, dest is NULL!\n");
exit(EXIT_FAILURE);
}
if (NULL == src) {
} else {
assert(NULL != maxsize_p);
size_t maxsize = *maxsize_p;
size_t destsize = strnlen(dest, maxsize);
size_t srclen = strnlen(src, maxsize);
size_t maxdest = destsize + srclen;
if (maxdest < maxsize-1) {
strncat( dest, src, srclen);
} else {
fprintf(stderr, "max string length of dest + src (%zu + %zu) exceeds maxsize %zu\n", destsize, srclen, maxsize);
strbuff_t * secstrcat (strbuff_t * dest, const char * src) {
if (NULL != src) {
assert(NULL != dest );
size_t srclen = strlen(src);
if ((dest->pos + srclen) > dest->bufsize) {
fprintf(stderr, "max string length of dest + src (%zu + %zu) exceeds maxsize %zu\n", dest->pos, srclen, dest->bufsize);
exit(EXIT_FAILURE);
}
memcpy(dest->bufpos, src, srclen);
dest->bufpos += srclen;
// fprintf(stderr, "DEBUG: dest->pos=%zu, src len=%zu", dest->pos, srclen);
dest->pos += srclen;
// fprintf(stderr, " new dest_pos=%zu\n", dest->pos);
}
return dest;
}


+ 3
- 3
src/helper/check_print.c View File

@ -6,7 +6,6 @@
*
*/
#define _GNU_SOURCE
#include <assert.h>
#include <string.h>
@ -44,7 +43,8 @@ returncode_t __add_to_render_pipeline_via_strncpy (retmsg_t ** pointer, const ch
exit (could_not_allocate_memory);
// return could_not_allocate_memory;
}
strncpy(msg, src, src_len );
//strncpy(msg, src, src_len );
memcpy(msg, src,src_len);
actual_render->next = next;
actual_render->next->rm_msg = msg;
actual_render->next->rm_type = src_type;
@ -72,7 +72,7 @@ void __clean_render_pipeline( retmsg_t ** pointer ) {
}
}
/*
/*
returncode_t tifp_check( ctiff_t * ctif) {
if (NULL == ctif) { return code_error_ctif_empty; };
if (0 > ctif->fd) { return code_error_filedescriptor_empty; };


+ 0
- 8
src/helper/check_renderer.c View File

@ -6,14 +6,11 @@
*
*/
#define _GNU_SOURCE
#include "check.h"
#include "check_renderer.h"
render_type render_engine=render_default;
short int is_quiet = 1;
const char * xmlfile = NULL;
void set_renderer_to_quiet() {
is_quiet=0;
@ -24,15 +21,10 @@ void set_renderer_to_ansi() {
render_engine=render_ansi;
}
}
void set_renderer_to_xml( const char * given_xmlfile) {
render_engine=render_xml;
xmlfile = given_xmlfile;
}
const char * renderer ( const retmsg_t * ret ) {
// call debug renderer
switch (render_engine) {
case render_xml: return renderer_xml( ret, xmlfile);
case render_ansi: return renderer_ansi( ret, is_quiet );
default: return renderer_default( ret, is_quiet );
}


+ 16
- 17
src/helper/check_tiffparse.c View File

@ -6,20 +6,20 @@
*
*/
#define _GNU_SOURCE
#include <math.h>
#include "check.h"
#include "check_helper.h"
#include <assert.h>
#include <fcntl.h>
#ifdef _HAVE__MMAP
#ifdef _HAVE_MMAP
#include <sys/mman.h>
#include <errno.h>
#endif
off_t ct_seek(ctiff_t * ctif, off_t pos, int whence) {
#ifdef _HAVE__MMAP
#ifdef _HAVE_MMAP
switch (ctif->ioflag) {
case is_filep:
assert(ctif->fd >= 0);
@ -41,7 +41,7 @@ off_t ct_seek(ctiff_t * ctif, off_t pos, int whence) {
ctif->actual_streamp = ctif->streamp + ctif->streamlen + pos;
break;
}
int testpos = ctif->actual_streamp - ctif->streamp;
uint32 testpos = ctif->actual_streamp - ctif->streamp;
if ( testpos > ctif->streamlen) {
/*
* fprintf(stderr, "seek offset outside of file on new pos=%i (filesize=%i)\n", testpos, ctif->streamlen);
@ -72,7 +72,7 @@ ssize_t ct_read(ctiff_t * ctif, void *buf, size_t count) {
perror("Buffer buf is a NULL-pointer");
exit( EXIT_FAILURE );
}
#ifdef _HAVE__MMAP
#ifdef _HAVE_MMAP
switch (ctif->ioflag) {
case is_filep:
// TODO: add checks if seek will be outside of file!!!
@ -83,7 +83,7 @@ ssize_t ct_read(ctiff_t * ctif, void *buf, size_t count) {
assert( ctif->streamp != NULL);
assert( ctif->actual_streamp != NULL);
int testpos = (ctif->actual_streamp+count) - (ctif->streamp);
uint32 testpos = (ctif->actual_streamp+count) - (ctif->streamp);
if ( testpos > ctif->streamlen) {
/*
* fprintf(stderr, "read offset outside of file on new pos=%i (filesize=%i)\n", testpos, ctif->streamlen);
@ -334,9 +334,8 @@ ret_t get_first_IFD(ctiff_t * ctif, uint32 * ifd) {
}
/* scans first IDF and returns the n-th tag */
/* scans first IDF and returns the n-th tag, if errorneous it returns a value 0 */
tag_t TIFFGetRawTagListEntry( ctiff_t * ctif, int tagidx ) {
int byteswapped = is_byteswapped(ctif);
get_ifd0_count( ctif); /* return code ignored, used to read TIFF header */
/* ct_read count of tags (2 Bytes) */
uint32 adress = ctif->ifd0pos+2+tagidx*12;
@ -351,9 +350,9 @@ tag_t TIFFGetRawTagListEntry( ctiff_t * ctif, int tagidx ) {
// exit( EXIT_FAILURE );
return 0;
}
if (byteswapped) {
if (is_byteswapped(ctif)) {
TIFFSwabShort(&tagid);
}
}
//printf("tag idx=%i, tag=%u (0x%04x) (0x%02x) (0x%02x)\n", i, tagid, tagid, hi, lo);
return tagid;
}
@ -532,16 +531,15 @@ ifd_entry_t TIFFGetRawTagIFDListEntry( ctiff_t * ctif, int tagidx ) {
}
if (byteswapped) {
TIFFSwabShort(&tagtype);
}
}
uint32 count;
if ( ct_read( ctif, &count, 4) != 4) {
perror ("TIFF Header ct_read error4, reading count from ifd0 (4bytes)");
return ifd_entry;
}
if (byteswapped) {
TIFFSwabLong( &count);
}
}
#ifdef DEBUG
printf("\ncount=%0x\n\n", count);
#endif
@ -637,7 +635,7 @@ ifd_entry_t TIFFGetRawTagIFDListEntry( ctiff_t * ctif, int tagidx ) {
ifd_entry_t TIFFGetRawIFDEntry( ctiff_t * ctif, tag_t tag) {
int tagidx = -1;
for (uint16 i= 0; i < get_ifd0_count( ctif ); i++) {
if (tag > 253 && tag == TIFFGetRawTagListEntry( ctif, i )) {
if ((tag >= MINTAGS) && (tag == TIFFGetRawTagListEntry( ctif, i ))) {
tagidx= i;
break;
};
@ -675,7 +673,7 @@ if (tagidx >= 0) {
TIFFDataType TIFFGetRawTagType(ctiff_t * ctif, tag_t tag) {
int tagidx = -1;
for (uint16 i= 0; i < get_ifd0_count( ctif ); i++) {
if (tag > 253 && tag == TIFFGetRawTagListEntry( ctif, i )) {
if ((tag >= MINTAGS) && (tag == TIFFGetRawTagListEntry( ctif, i ))) {
tagidx= i;
break;
};
@ -713,16 +711,17 @@ ctiff_t * initialize_ctif(const char * tiff_file, ct_ioflag_t ioflag) {
ctif->streamp = NULL;
ctif->actual_streamp = NULL;
ctif->tagorder=unknown_tag_order;
for (int i= 0; i < 65536; i++) {
for (unsigned int i= 0; i<MAXTAGS; i++) { /* init with -1 indicating 'not found' */
ctif->tag_cache[i]= -1;
}
#ifdef _HAVE__MMAP
#ifdef _HAVE_MMAP
switch (ioflag) {
case is_filep: {
/* streamlen */
break;
}
case is_memmap: {
void * tifmap = mmap( NULL, ctif->streamlen, PROT_READ, MAP_PRIVATE, tif, 0 );
if (MAP_FAILED == tifmap) {
fprintf( stderr, "file '%s' could not be mem-mapped, %s\n", tiff_file, strerror(errno));


+ 75
- 69
src/helper/renderer/check_renderer_ansi.c View File

@ -6,7 +6,6 @@
*
*/
#define _GNU_SOURCE
#include "check_renderer.h"
#include <assert.h>
@ -54,122 +53,129 @@
const char * renderer_ansi ( const retmsg_t * ret, short int is_quiet ) {
assert (ret != NULL);
/*
char * res = malloc( sizeof(char) * RENDERSIZE);
strbuff_t * res = malloc(sizeof(strbuff_t));
if (NULL == res) {
exit(could_not_allocate_memory);
}
memset( res, '\0', RENDERSIZE);
*/
char * res = calloc(RENDERMAXSIZE, sizeof(char));
if (NULL == res) {
res->buf = calloc( RENDERMAXSIZE, sizeof(char));
if (NULL == res->buf) {
exit(could_not_allocate_memory);
}
size_t rendersize_res = RENDERMAXSIZE;
/*
char * tmp = malloc( sizeof(char) * RENDERSIZE);
res->bufpos = res->buf;
res->pos=0;
res->bufsize = RENDERMAXSIZE;
strbuff_t * tmp;
tmp = malloc( sizeof( strbuff_t ) );
if (NULL == tmp) {
exit(could_not_allocate_memory);
}
memset( tmp, '\0', RENDERSIZE);
*/
char * tmp = calloc( RENDERMINSIZE, sizeof(char));
if (NULL == tmp) {
tmp->buf = calloc( RENDERMINSIZE, sizeof(char));
if (NULL == tmp->buf) {
exit(could_not_allocate_memory);
}
size_t rendersize_tmp = RENDERMINSIZE;
tmp->bufpos = tmp->buf;
tmp->pos=0;
tmp->bufsize = RENDERMINSIZE;
const retmsg_t * startp = ret;
short int rc_is_valid = 1;
while (NULL != startp) {
assert(startp->rm_msg != NULL);
switch (startp->rm_type) {
case rm_rule: tmp=secstrcat(tmp, ANSI_NORMAL , & rendersize_tmp);
tmp=secstrcat(tmp, "\t--> ", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_rule: tmp=secstrcat(tmp, ANSI_NORMAL );
tmp=secstrcat(tmp, "\t--> ");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_tag:
case rm_mode: tmp=secstrcat(tmp, "\t", & rendersize_tmp );
tmp=secstrcat(tmp, ANSI_BOLD , & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_mode: tmp=secstrcat(tmp, "\t" );
tmp=secstrcat(tmp, ANSI_BOLD );
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_value: tmp=secstrcat(tmp, ANSI_RED , & rendersize_tmp);
tmp=secstrcat(tmp, " found: ", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_value: tmp=secstrcat(tmp, ANSI_RED );
tmp=secstrcat(tmp, " found: ");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_expected: tmp=secstrcat(tmp, ANSI_BLUE, & rendersize_tmp);
tmp=secstrcat(tmp, " expected: " , & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_expected: tmp=secstrcat(tmp, ANSI_BLUE);
tmp=secstrcat(tmp, " expected: " );
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_hard_error: tmp=secstrcat(tmp, ANSI_RED_BOLD , & rendersize_tmp);
tmp=secstrcat(tmp, "(HE)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_hard_error: tmp=secstrcat(tmp, ANSI_RED_BOLD );
tmp=secstrcat(tmp, "(HE)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_error: tmp=secstrcat(tmp, ANSI_RED , & rendersize_tmp);
tmp=secstrcat(tmp, "(EE)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_error: tmp=secstrcat(tmp, ANSI_RED );
tmp=secstrcat(tmp, "(EE)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_error_description:
tmp=secstrcat(tmp, ANSI_RED , & rendersize_tmp);
tmp=secstrcat(tmp, " ", & rendersize_tmp );
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
tmp=secstrcat(tmp, ANSI_RED );
tmp=secstrcat(tmp, " " );
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_warning: tmp=secstrcat(tmp, ANSI_GREY , & rendersize_tmp);
tmp=secstrcat(tmp, "(WW)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_warning: tmp=secstrcat(tmp, ANSI_GREY );
tmp=secstrcat(tmp, "(WW)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_logicalor_error:
tmp=secstrcat(tmp, ANSI_YELLOW , & rendersize_tmp);
tmp=secstrcat(tmp, "(LE)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
tmp=secstrcat(tmp, ANSI_YELLOW );
tmp=secstrcat(tmp, "(LE)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_file: res=secstrcat(res, "file: ", & rendersize_res );
res=secstrcat(res, ANSI_BLUE_BOLD, & rendersize_res);
res=secstrcat(res, startp->rm_msg, & rendersize_res);
res=secstrcat(res, ANSI_NORMAL , & rendersize_res);
res=secstrcat(res, "\n", & rendersize_res);
case rm_file: res=secstrcat(res, "file: ");
res=secstrcat(res, ANSI_BLUE_BOLD);
res=secstrcat(res, startp->rm_msg);
res=secstrcat(res, ANSI_NORMAL );
res=secstrcat(res, "\n");
break;
case rm_lineno: tmp=secstrcat(tmp, ANSI_GREY, & rendersize_tmp);
tmp=secstrcat(tmp, " (lineno: ", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
tmp=secstrcat(tmp, ")", & rendersize_tmp);
case rm_lineno: tmp=secstrcat(tmp, ANSI_GREY);
tmp=secstrcat(tmp, " (lineno: ");
tmp=secstrcat(tmp, startp->rm_msg);
tmp=secstrcat(tmp, ")");
break;
case rm_endrule:
case rm_endtiff:
tmp=secstrcat(tmp, ANSI_NORMAL, & rendersize_tmp);
tmp=secstrcat(tmp, "\n", & rendersize_tmp);
tmp=secstrcat(tmp, ANSI_NORMAL);
tmp=secstrcat(tmp, "\n");
/* copy tmp to res, reset tmp */
if ((rc_is_valid == 0) && (is_quiet == 0)) {
} else {
res=secstrcat(res, tmp, & rendersize_res);
res=secstrcat(res, tmp->buf);
}
memset( tmp, '\0', rendersize_tmp);
memset(tmp->buf, 0, tmp->bufsize);
tmp->bufpos= tmp->buf;
tmp->pos = 0;
rc_is_valid =1;
break;
case rm_is_valid: tmp=secstrcat(tmp, ANSI_GREEN_BOLD, & rendersize_tmp);
tmp=secstrcat(tmp, "(./)", & rendersize_tmp);
case rm_is_valid: tmp=secstrcat(tmp, ANSI_GREEN_BOLD);
tmp=secstrcat(tmp, "(./)");
rc_is_valid = 0;
break;
case rm_summary_valid:
tmp=secstrcat(tmp, ANSI_GREEN_BOLD, & rendersize_tmp);
tmp=secstrcat(tmp, "\n(./)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
tmp=secstrcat(tmp, ANSI_GREEN_BOLD);
tmp=secstrcat(tmp, "\n(./)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_summary_invalid:
tmp=secstrcat(tmp, ANSI_RED_BOLD , & rendersize_tmp);
tmp=secstrcat(tmp, "\n(EE)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
tmp=secstrcat(tmp, ANSI_RED_BOLD );
tmp=secstrcat(tmp, "\n(EE)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
default: tmp=secstrcat(tmp, ANSI_NORMAL , & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
default: tmp=secstrcat(tmp, ANSI_NORMAL );
tmp=secstrcat(tmp, startp->rm_msg);
}
startp=startp->next;
}
res=secstrcat( res, ANSI_NORMAL, & rendersize_res);
res=secstrcat( res, "\n", & rendersize_res);
res=secstrcat( res, ANSI_NORMAL);
res=secstrcat( res, "\n");
if (NULL != tmp->buf) {
free(tmp->buf);
}
if (NULL != tmp) {
free(tmp);
}
return res;
char * result_string = res->buf;
if (NULL != res) {
free(res);
}
return result_string;
}
/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 smarttab expandtab :*/

+ 57
- 52
src/helper/renderer/check_renderer_default.c View File

@ -6,111 +6,116 @@
*
*/
#define _GNU_SOURCE
#include "check_renderer.h"
#include <assert.h>
const char * renderer_default ( const retmsg_t * ret, short int is_quiet ) {
assert (ret != NULL);
/*
char * res = malloc( sizeof(char) * RENDERSIZE);
strbuff_t * res = malloc(sizeof(strbuff_t));
if (NULL == res) {
exit(could_not_allocate_memory);
}
memset( res, '\0', RENDERSIZE);
*/
char * res = calloc(RENDERMAXSIZE, sizeof(char));
if (NULL == res) {
res->buf = calloc( RENDERMAXSIZE, sizeof(char));
if (NULL == res->buf) {
exit(could_not_allocate_memory);
}
size_t rendersize_res = RENDERMAXSIZE;
/*
char * tmp = malloc( sizeof(char) * RENDERSIZE);
res->bufpos = res->buf;
res->pos=0;
res->bufsize = RENDERMAXSIZE;
strbuff_t * tmp;
tmp = malloc( sizeof( strbuff_t ) );
if (NULL == tmp) {
exit(could_not_allocate_memory);
}
memset( tmp, '\0', RENDERSIZE);
*/
char * tmp = calloc( RENDERMINSIZE, sizeof(char));
if (NULL == tmp) {
tmp->buf = calloc( RENDERMINSIZE, sizeof(char));
if (NULL == tmp->buf) {
exit(could_not_allocate_memory);
}
size_t rendersize_tmp = RENDERMINSIZE;
tmp->bufpos = tmp->buf;
tmp->pos=0;
tmp->bufsize = RENDERMINSIZE;
const retmsg_t * startp = ret;
short int rc_is_valid = 1;
while (NULL != startp) {
assert(startp->rm_msg != NULL);
switch (startp->rm_type) {
case rm_rule: tmp=secstrcat(tmp, "\t--> ", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_rule: tmp=secstrcat(tmp, "\t--> ");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_tag:
case rm_mode: tmp=secstrcat(tmp, "\t", & rendersize_tmp );
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_mode: tmp=secstrcat(tmp, "\t");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_value: tmp=secstrcat(tmp, "; found: ", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_value: tmp=secstrcat(tmp, "; found: ");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_expected: tmp=secstrcat(tmp, "; expected: " , & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_expected: tmp=secstrcat(tmp, "; expected: ");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_hard_error: tmp=secstrcat(tmp, "(HE)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_hard_error: tmp=secstrcat(tmp, "(HE)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_error: tmp=secstrcat(tmp, "(EE)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_error: tmp=secstrcat(tmp, "(EE)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_error_description:
tmp=secstrcat(tmp, " ", & rendersize_tmp );
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
tmp=secstrcat(tmp, " ");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_warning: tmp=secstrcat(tmp, "(WW)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_warning: tmp=secstrcat(tmp, "(WW)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_logicalor_error: tmp=secstrcat(tmp, "(LE)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
case rm_logicalor_error: tmp=secstrcat(tmp, "(LE)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_file: res=secstrcat(res, "file: ", & rendersize_res );
res=secstrcat(res, startp->rm_msg, & rendersize_res);
res=secstrcat(res, "\n", & rendersize_res);
case rm_file: res=secstrcat(res, "file: ");
res=secstrcat(res, startp->rm_msg);
res=secstrcat(res, "\n");
break;
case rm_lineno: tmp=secstrcat(tmp, " (lineno: ", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
tmp=secstrcat(tmp, ")", & rendersize_tmp);
case rm_lineno: tmp=secstrcat(tmp, " (lineno: ");
tmp=secstrcat(tmp, startp->rm_msg);
tmp=secstrcat(tmp, ")");
break;
case rm_endrule:
case rm_endtiff:
tmp=secstrcat(tmp, "\n", & rendersize_tmp);
tmp=secstrcat(tmp, "\n");
/* copy tmp to res, reset tmp */
if ((rc_is_valid == 0) && (is_quiet == 0)) {
} else {
res=secstrcat(res, tmp, & rendersize_res);
res=secstrcat(res, tmp->buf);
}
memset( tmp, '\0', rendersize_tmp);
memset(tmp->buf, 0, tmp->bufsize);
tmp->bufpos= tmp->buf;
tmp->pos = 0;
rc_is_valid =1;
break;
case rm_is_valid: tmp=secstrcat(tmp, "(./)", & rendersize_tmp);
case rm_is_valid: tmp=secstrcat(tmp, "(./)");
rc_is_valid = 0;
break;
case rm_summary_valid:
tmp=secstrcat(tmp, "\n(./)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
tmp=secstrcat(tmp, "\n(./)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
case rm_summary_invalid:
tmp=secstrcat(tmp, "\n(EE)", & rendersize_tmp);
tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
tmp=secstrcat(tmp, "\n(EE)");
tmp=secstrcat(tmp, startp->rm_msg);
break;
default: tmp=secstrcat(tmp, startp->rm_msg, & rendersize_tmp);
default: tmp=secstrcat(tmp, startp->rm_msg);
}
startp=startp->next;
}
res=secstrcat(res, "\n", & rendersize_res);
res=secstrcat( res, "\n");
if (NULL != tmp->buf) {
free(tmp->buf);
}
if (NULL != tmp) {
free(tmp);
}
return res;
char * result_string = res->buf;
if (NULL != res) {
free(res);
}
return result_string;
}
/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 smarttab expandtab :*/

+ 0
- 131
src/helper/renderer/check_renderer_xml.c View File

@ -1,131 +0,0 @@
/* rule based checks if given TIFF is a specific baseline TIFF
*
* author: Andreas Romeyke, 2015-2017
* licensed under conditions of libtiff
* (see http://libtiff.maptools.org/misc.html)
*
*/
#define _GNU_SOURCE
#include "check_renderer.h"
#include <assert.h>
const char * renderer_xml ( const retmsg_t * ret, const char * xmlfile ) {
assert (ret != NULL);
if (xmlfile == NULL) {
fprintf(stderr, "no given XML file for option '-x'\n");
exit(EXIT_FAILURE);
}
FILE *f = fopen(xmlfile, "w");
if (NULL == f) {
fprintf(stderr, "Could not open file '%s' for writing\n", xmlfile);
exit(EXIT_FAILURE);
}
/*
char * res = malloc( sizeof(char) * RENDERSIZE);
if (NULL == res) {
exit(could_not_allocate_memory);
}
memset( res, '\0', RENDERSIZE);
*/
char * res = calloc(RENDERMAXSIZE, sizeof(char));
if (NULL == res) {
exit(could_not_allocate_memory);
}
size_t rendersize_res = RENDERMAXSIZE;
const retmsg_t * startp = ret;
res=secstrcat(res, "<checkit_tiff_result>\n", &rendersize_res);
render_context_t rc_is_valid=within_valid;
while (NULL != startp) {
assert(startp->rm_msg != NULL);
switch (startp->rm_type) {
case rm_rule: res=secstrcat(res, "<rule>", & rendersize_res);
res=secstrcat(res, startp->rm_msg, &rendersize_res);
res=secstrcat(res, "</rule>", & rendersize_res);
break;
case rm_tag: res=secstrcat(res, "<tag>", & rendersize_res );
res=secstrcat(res, startp->rm_msg, & rendersize_res);
res=secstrcat(res, "</tag>", & rendersize_res);
break;
case rm_mode: res=secstrcat(res, "<mode>", & rendersize_res );
res=secstrcat(res, startp->rm_msg, & rendersize_res);
res=secstrcat(res, "</mode>", & rendersize_res);
break;
case rm_value: res=secstrcat(res, "<value_found>", & rendersize_res);
res=secstrcat(res, startp->rm_msg, & rendersize_res);
res=secstrcat(res, "</value_found>", & rendersize_res);
break;
case rm_expected: res=secstrcat(res, "<value_expected>" , & rendersize_res);
res=secstrcat(res, startp->rm_msg, & rendersize_res);
res=secstrcat(res, "</value_expected>", & rendersize_res);
break;
case rm_hard_error: res=secstrcat(res, "<error level=\"critical\">", & rendersize_res);
res=secstrcat(res, startp->rm_msg, & rendersize_res);
rc_is_valid = within_harderror;
break;
case rm_error: if (strlen(startp->rm_msg) > 0) {
res=secstrcat(res, "<error level=\"summary\">", & rendersize_res);
res=secstrcat(res, startp->rm_msg, & rendersize_res);
res=secstrcat(res, "</error>", & rendersize_res);
rc_is_valid = within_summaryerror;
} else {
res=secstrcat(res, "<error level=\"error\">", & rendersize_res);
rc_is_valid = within_error;
}
break;
case rm_error_description:
res=secstrcat(res, "<description>", & rendersize_res );
res=secstrcat(res, startp->rm_msg, & rendersize_res);
res=secstrcat(res, "</description>", & rendersize_res);
break;
case rm_warning: res=secstrcat(res, "<error level=\"warning\">", & rendersize_res);
res=secstrcat(res, startp->rm_msg, & rendersize_res);
rc_is_valid = within_error;
break;
case rm_logicalor_error: res=secstrcat(res, "<error level=\"logical or error\">", & rendersize_res);
res=secstrcat(res, startp->rm_msg, & rendersize_res);
rc_is_valid = within_error;
break;
case rm_file: res=secstrcat(res, "<file>", & rendersize_res );
res=secstrcat(res, startp->rm_msg, & rendersize_res);
res=secstrcat(res, "</file>\n", & rendersize_res);
break;
case rm_lineno: res=secstrcat(res, "<lineno>", & rendersize_res);
res=secstrcat(res, startp->rm_msg, & rendersize_res);
res=secstrcat(res, "</lineno>", & rendersize_res);
break;
case rm_endrule:
case rm_endtiff:
if (rc_is_valid == within_valid) {
res=secstrcat(res, "</valid>", & rendersize_res);
} else if (rc_is_valid == within_error) {
res=secstrcat(res, "</error>", & rendersize_res);
} else if (rc_is_valid == within_harderror) {
res=secstrcat(res, "</error>", & rendersize_res);
}
res=secstrcat(res, "\n", & rendersize_res);
break;
case rm_is_valid: res=secstrcat(res, "<valid>", & rendersize_res);
rc_is_valid = within_valid;
break;
case rm_summary_valid:
case rm_summary_invalid: break;
default: res=secstrcat(res, "<dummy>", & rendersize_res);
res=secstrcat(res, startp->rm_msg, & rendersize_res);
res=secstrcat(res, "</dummy>", & rendersize_res);
}
startp=startp->next;
}
res=secstrcat(res, "</checkit_tiff_result>", & rendersize_res);
res=secstrcat(res, "\n", & rendersize_res);
fprintf(f, "%s", res);
fclose(f);
memset( res, '\0', RENDERMAXSIZE);
return res;
}
/* vim: set tabstop=2 softtabstop=2 shiftwidth=2 smarttab expandtab :*/

+ 69
- 70
src/parser/config_parser.c View File

@ -51,14 +51,14 @@ void print_plan () {
#define CHECKUNDERFLOW(SPACE_P, NAME) \
if (((SPACE_P)->NAME ## _stackp) >=MAXRESULT) {\
fprintf(stderr, "stackoverflow in " #SPACE_P "->" #NAME "_stack at lineno=%i, only %i results could be stored, increase MAXRESULT\n", parser_state.lineno, MAXRESULT);\
fprintf(stderr, "stackoverflow in " #SPACE_P "->" #NAME "_stack at lineno=%i, only %u results could be stored, increase MAXRESULT\n", parser_state.lineno, MAXRESULT);\
exit(EXIT_FAILURE);\
}
// endmacro CHECKUNDERFLOW
#define CHECKOVERFLOW(SPACE_P, NAME) \
if (((SPACE_P)->NAME ## _stackp) >=MAXRESULT) {\
fprintf(stderr, "stackoverflow in " #SPACE_P "->" #NAME "_stack at lineno=%i, only %i results could be stored, increase MAXRESULT\n", parser_state.lineno, MAXRESULT);\
fprintf(stderr, "stackoverflow in " #SPACE_P "->" #NAME "_stack at lineno=%i, only %u results could be stored, increase MAXRESULT\n", parser_state.lineno, MAXRESULT);\
exit(EXIT_FAILURE);\
}
// endmacro CHECKOVERFLOW
@ -76,19 +76,19 @@ void print_plan () {
#define PRINT(SPACE_P, TYPESIG, NAME) \
CHECKOVERFLOW(SPACE_P, NAME) \
CHECKUNDERFLOW(SPACE_P, NAME) \
for (int j=0; j< (SPACE_P)->NAME ## _stackp; j++)\
for (unsigned int j=0; j< (SPACE_P)->NAME ## _stackp; j++)\
printf(" " #SPACE_P "->" #NAME "-stack value[ %i ] --> " #TYPESIG "\n", j, (SPACE_P)->NAME ## _stack[j]);\
//endmacro PRINT
#define PRINTV(SPACE_P, VSTRINGARRAY, NAME) \
CHECKOVERFLOW(SPACE_P, NAME) \
CHECKUNDERFLOW(SPACE_P, NAME) \
for (int j=0; j< (SPACE_P)->NAME ## _stackp; j++)\
for (unsigned int j=0; j< (SPACE_P)->NAME ## _stackp; j++)\
printf(" " #SPACE_P "->" #NAME "-stack value[ %i ] --> %s\n", j, (VSTRINGARRAY)[(SPACE_P)->NAME ## _stack[j]]);\
//endmacro PRINTV
void result_push(full_res_t r) { PUSH(&parser_state, result, r); }
void result_printstack() {
static void result_push(full_res_t r) { PUSH(&parser_state, result, r); }
static void result_printstack() {
printf("=== BEGIN result_printstack\n");
for (int i = 0; i < parser_state.result_stackp; i++) {
@ -105,10 +105,10 @@ void result_printstack() {
printf("=== END result_printstack\n");
}
void i_printstack () { PRINT(&parser_state, "%u", i); }
void i_push (unsigned int i) { PUSH(&parser_state, i, i);}
unsigned int i_pop () { unsigned i; POP(&parser_state, i, i); return i; }
void v_printstack () {
static void i_printstack () { PRINT(&parser_state, "%u", i); }
static void i_push (unsigned int i) { PUSH(&parser_state, i, i);}
static unsigned int i_pop () { unsigned i; POP(&parser_state, i, i); return i; }
static void v_printstack () {
const char * vname[] = {
"range",
"logical_or",
@ -119,14 +119,14 @@ void v_printstack () {
};
PRINTV(&parser_state, vname, val);
}
void v_push ( values_t v) { PUSH(&parser_state, val, v);}
values_t v_pop () { values_t v; POP(&parser_state, val, v); return v; }
static void v_push ( values_t v) { PUSH(&parser_state, val, v);}
static values_t v_pop () { values_t v; POP(&parser_state, val, v); return v; }
void r_printstack () { PRINT(&parser_state, "%s", regex); }
void r_push (char * r) { PUSH(&parser_state, regex, r); }
char * r_pop () { char * v; POP(&parser_state, regex, v); return v; }
void exe_push (internal_entry_t i) { PUSH(&parser_state, exe, i);}
internal_entry_t exe_pop () { internal_entry_t e; POP(&parser_state, exe, e); return e; }
static void r_printstack () { PRINT(&parser_state, "%s", regex); }
static void r_push (char * r) { PUSH(&parser_state, regex, r); }
static char * r_pop () { char * v; POP(&parser_state, regex, v); return v; }
static void exe_push (internal_entry_t i) { PUSH(&parser_state, exe, i);}
static internal_entry_t exe_pop () { internal_entry_t e; POP(&parser_state, exe, e); return e; }
void exe_printstack_human_readable () {
CHECKOVERFLOW(&parser_state, exe);
@ -153,7 +153,7 @@ void exe_printstack_human_readable () {
}
/* help function to print exe stack */
void exe_printstack () {
static void exe_printstack () {
CHECKOVERFLOW(&parser_state, exe);
CHECKUNDERFLOW(&parser_state, exe);
printf("=== BEGIN exe_printstack\n");
@ -186,7 +186,7 @@ void exe_printstack () {
/* reduce results */
void reduce_results() {
static void reduce_results() {
#ifdef DEBUG
printf("---------------------------------------------------------------------\n");
printf("begin REDUCE\n");
@ -260,14 +260,14 @@ void reduce_results() {
}
/* stack function for parser */
void exe_i_push (internal_entry_t * ep, unsigned int i) {
static void exe_i_push (internal_entry_t * ep, unsigned int i) {
PUSH( ep, i, i)
}
unsigned int exe_i_pop(internal_entry_t * ep) {
static unsigned int exe_i_pop(internal_entry_t * ep) {
unsigned int i; POP( ep, i, i); return i;
}
/* stack function for parser */
internal_entry_t * exe_regex_push (internal_entry_t * ep, const char * s) {
static internal_entry_t * exe_regex_push (internal_entry_t * ep, const char * s) {
#ifdef EXE_DEBUG
printf("-------------------\n");
printf("\tpush REGEX='%s'\n", s);
@ -279,7 +279,7 @@ internal_entry_t * exe_regex_push (internal_entry_t * ep, const char * s) {
#endif
return ep;
}
char * exe_regex_pop(internal_entry_t * ep) {
static char * exe_regex_pop(internal_entry_t * ep) {
char * s;
POP( ep, regex, s);
#ifdef EXE_DEBUG
@ -291,7 +291,7 @@ char * exe_regex_pop(internal_entry_t * ep) {
return s;
}
char * __ch_malloc(char * msg) {
static char * __ch_malloc(char * msg) {
assert( msg == NULL);
msg = calloc(VALUESTRLEN, sizeof(char));
if (NULL == msg) {
@ -301,7 +301,7 @@ char * __ch_malloc(char * msg) {
}
ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t * exep) {
static ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t * exep) {
ret_t ret = *retp;
internal_entry_t exe = *exep;
char * expected_value=NULL;
@ -314,12 +314,12 @@ ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t * exep)
char * strp = expected_value;
for (unsigned int j=0; j<count; j++) values[j]=exe_i_pop(&exe);
int all_printed = 0;
int printed = snprintf(strp, VALUESTRLEN, "count=%i, values ", count);
int printed = snprintf(strp, VALUESTRLEN, "count=%u, values ", count);
strp+=printed;
all_printed+=printed;
for (unsigned int j=0; j<count; j++) {
/* reduce VALUESTRLEN with n*printed */
printed = snprintf(strp, (size_t) (VALUESTRLEN - all_printed), " [%i]=%u", j, values[j]);
printed = snprintf(strp, (size_t) (VALUESTRLEN - all_printed), " [%u]=%u", j, values[j]);
strp+=printed;
all_printed+=printed;
}
@ -332,12 +332,12 @@ ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t * exep)
char * strp = expected_value;
for (unsigned int j=0; j<count; j++) values[j]=exe_i_pop(&exe);
int all_printed = 0;
int printed = snprintf(expected_value, VALUESTRLEN, "count=%i, values", count);
int printed = snprintf(expected_value, VALUESTRLEN, "count=%u, values", count);
strp+=printed;
all_printed+=printed;
for (unsigned int j=0; j<count; j++) {
/* reduce VALUESTRLEN with n*printed */
printed = snprintf(strp, VALUESTRLEN, " [%i]=%u",j, values[j]);
printed = snprintf(strp, VALUESTRLEN, " [%u]=%u",j, values[j]);
strp+=printed;
all_printed+=printed;
}
@ -347,19 +347,19 @@ ret_t call_exec_function(ctiff_t * ctif, ret_t * retp, internal_entry_t * exep)
case fc_tag_has_value_in_range: { unsigned int a = exe_i_pop(&exe);
unsigned int b = exe_i_pop(&exe);
expected_value = __ch_malloc(expected_value);
snprintf(expected_value, VALUESTRLEN, "%i -- %i", a, b);
snprintf(expected_value, VALUESTRLEN, "%u -- %u", a, b);
ret = check_tag_has_value_in_range(ctif, exe.tag, a, b);
break;
}
case fc_tag_has_value: { unsigned int a = exe_i_pop(&exe);
expected_value = __ch_malloc(expected_value);
snprintf(expected_value, VALUESTRLEN, <