Browse Source

- results stack enriched with contextual information

- preliminary xml renderer added
- rm_type_t extended to indicate combined errors from logical_or operations
- internal parser structure changed from list/tree to stacks-based engine,
  the engine has an internal execution stack which allows to handle
  logical_or combinations and is prepared for enhancing the parser to
  support header-entries in checkit_tiff configs to check other TIFF types, as well
pull/4/head
Andreas Romeyke 5 years ago
parent
commit
8a98266332
  1. 282
      src/checkit_tiff.c
  2. 8
      src/headers/check.h
  3. 3
      src/headers/check_helper.h
  4. 153
      src/headers/config_parser.h
  5. 4
      src/helper/check_helper.c
  6. 48
      src/helper/check_print.c
  7. 59
      src/helper/check_renderer.c
  8. 1314
      src/parser/config_parser.c

282
src/checkit_tiff.c

@ -48,50 +48,63 @@ void help () {
printf ("\n");
}
void simplified_result_push(ret_t res, function_t func) {
full_res_t full;
full.tag = -1;
full.function=func;
full.lineno=-1;
full.result=res;
result_push( full );
}
int check_specific_tiff_file( const char * tiff_file, int use_memmapped) {
// printf("tiff file=%s\n", tiff_file);
tif_files(tiff_file);
ret_t res;
ctiff_t * ctif = initialize_ctif( tiff_file );
int is_valid = 0;
/* special checks */
res = check_all_IFDs_are_word_aligned( ctif); if (0 != res.returncode) {is_valid++;}
free (res.returnmsg);
res = check_has_only_one_ifd( ctif); if (0 != res.returncode) {is_valid++;}
free (res.returnmsg);
res = check_tagorder( ctif); if (0 != res.returncode) {is_valid++;}
free (res.returnmsg);
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( ctif ); if (0 != res.returncode) {is_valid++;}
free (res.returnmsg);
/* datetime */
res = check_tag_quiet( ctif, TIFFTAG_DATETIME);
free (res.returnmsg);
if (res.returncode == 0) {
res = check_datetime( ctif );
free (res.returnmsg);
if (0 != res.returncode) {is_valid++;}
}
/* ICC */
res = check_tag_quiet( ctif, TIFFTAG_ICCPROFILE);
free (res.returnmsg);
if (res.returncode == 0) {
res = check_icc( ctif );
free (res.returnmsg);
if (0 != res.returncode) {is_valid++;}
}
is_valid += execute_plan(ctif);
/* TODO: colorize? */
if (is_valid > 0) {
printf("found %i errors\n", is_valid);
} else {
printf("the given tif is valid\n");
}
//print_plan_results();
free_ctif( ctif );
return is_valid;
// printf("tiff file=%s\n", tiff_file);
tif_files(tiff_file);
ctiff_t * ctif = initialize_ctif( tiff_file );
int is_valid = 0;
ret_t res = _empty_result();
/* special checks */
res = check_all_IFDs_are_word_aligned( ctif);
if (0 != res.returncode) is_valid++;
simplified_result_push(res, fc_all_IFDs_are_word_aligned);
res = check_has_only_one_ifd( ctif);
if (0 != res.returncode) is_valid++;
simplified_result_push(res, fc_has_only_one_ifd);
res = check_tagorder( ctif);
if (0 != res.returncode) is_valid++;
simplified_result_push(res, fc_tagorder);
res = check_all_offsets_are_used_once_only( ctif );
if (0 != res.returncode) is_valid++;
simplified_result_push(res, fc_all_offsets_are_used_once_only);
res = check_all_offsets_are_word_aligned( ctif );
if (0 != res.returncode) is_valid++;
simplified_result_push(res, fc_all_offsets_are_word_aligned);
/* datetime */
res = check_tag_quiet( ctif, TIFFTAG_DATETIME);
if (res.returncode == 0) {
res = check_datetime( ctif );
if (0 != res.returncode) {is_valid++;}
simplified_result_push(res, fc_datetime);
}
/* ICC */
res = check_tag_quiet( ctif, TIFFTAG_ICCPROFILE);
if (res.returncode == 0) {
res = check_icc( ctif );
if (0 != res.returncode) {is_valid++;}
simplified_result_push(res, fc_icc);
}
execute_plan(ctif);
/* TODO: colorize? */
/* TODO: parse results */
is_valid = print_plan_results();
free_ctif( ctif );
return is_valid;
}
@ -103,47 +116,50 @@ int main (int argc, char * argv[]) {
int c;
int flag_check_directory=UNFLAGGED;
int flag_use_memorymapped_io=UNFLAGGED;
while ((c = getopt (argc, argv, "chmd")) != -1) {
switch (c)
{
case 'h': /* help */
help();
exit (0);
case 'c': /* colorize output */
set_renderer_to_ansi();
break;
case 'd': /* check directory */
flag_check_directory = FLAGGED;
printf("\nCheck all files in given directory\n");
break;
case 'm': /* use memory mapped I/O */
flag_use_memorymapped_io=FLAGGED;
break;
case '?': /* something goes wrong */
/*
if (optopt == 'r') {
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
return (-1);
}
else*/ if (isprint (optopt)) {
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
return (-1);
}
else if (0 !=optopt) {
fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
return (-1);
}
break;
default:
abort();
}
while ((c = getopt (argc, argv, "chmdx")) != -1) {
switch (c)
{
case 'h': /* help */
help();
exit (0);
case 'c': /* colorize output */
set_renderer_to_ansi();
break;
case 'x': /* colorize output */
set_renderer_to_xml();
break;
case 'd': /* check directory */
flag_check_directory = FLAGGED;
printf("\nCheck all files in given directory\n");
break;
case 'm': /* use memory mapped I/O */
flag_use_memorymapped_io=FLAGGED;
break;
case '?': /* something goes wrong */
/*
if (optopt == 'r') {
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
return (-1);
}
else*/ if (isprint (optopt)) {
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
return (-1);
}
else if (0 !=optopt) {
fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
return (-1);
}
break;
default:
abort();
}
}
if (argc - optind != 2) {
help();
fprintf( stderr, "%s needs at least two arguments, first should be the tiff-filename, second the config-file, example:\n\t %s tiffs_should_pass/minimal_valid.tiff example_configs/baseline_minimal.cfg\n", argv[0], argv[0]);
exit (EXIT_FAILURE);
help();
fprintf( stderr, "%s needs at least two arguments, first should be the tiff-filename, second the config-file, example:\n\t %s tiffs_should_pass/minimal_valid.tiff example_configs/baseline_minimal.cfg\n", argv[0], argv[0]);
exit (EXIT_FAILURE);
}
const char *tiff_file_or_dir=argv[optind];
const char *cfg_file=argv[optind+1];
@ -152,62 +168,62 @@ int main (int argc, char * argv[]) {
int is_valid = 0;
if (flag_check_directory == FLAGGED) {
/* iterate through all files */
size_t len = strlen( tiff_file_or_dir);
char tiff_dir [ len ];
strncpy(tiff_dir, tiff_file_or_dir, len);
tiff_dir[ len ] = 0;
/* printf ("tiffdir='%s'\n\n", tiff_dir);*/
DIR *dir;
struct dirent *ent;
/* remove trailing / */
char *dirsuffix = strrchr(tiff_dir, '/');
if (dirsuffix != NULL) { /* found a / */
/* printf ("len = %i dir = '%s' dirsuffix = '%s'\n", len, tiff_dir, dirsuffix);*/
if ( 0 == strcmp( dirsuffix, "/" ) ) { /* ok, ends with / */
/* remove last / */
assert(len >= 1); // or whatever you want to do with short strings
tiff_dir[len-1] = 0;
/* printf("tiffdir2 = '%s'\n", tiff_dir); */
}
}
/* iterate through all files in given dir */
if ((dir = opendir (tiff_file_or_dir)) != NULL) {
/* print all the files and directories within directory */
while ((ent = readdir (dir)) != NULL) {
struct stat attribute;
len = strlen( tiff_dir ) + strlen( ent->d_name ) + 2;
char fqname [ len ];
snprintf( fqname, len, "%s/%s", tiff_dir, ent->d_name);
if (stat( fqname, &attribute) == -1) {
fprintf (stderr, "could not stat on file '%s' in directory '%s' (%s)\n", ent->d_name, tiff_dir, fqname);
exit(EXIT_FAILURE);
}
if(attribute.st_mode & S_IFREG) {
/* printf ("%s\n", fqname); */
parse_plan_via_file(cfg_file);
is_valid += check_specific_tiff_file( fqname, flag_use_memorymapped_io);
clean_plan();
printf("\n");
}
}
closedir (dir);
} else {
/* could not open directory */
fprintf( stderr, "directory '%s' could not be opened\n", tiff_file_or_dir);
exit(EXIT_FAILURE);
}
/* iterate through all files */
size_t len = strlen( tiff_file_or_dir);
char tiff_dir [ len ];
strncpy(tiff_dir, tiff_file_or_dir, len);
tiff_dir[ len ] = 0;
/* printf ("tiffdir='%s'\n\n", tiff_dir);*/
DIR *dir;
struct dirent *ent;
/* remove trailing / */
char *dirsuffix = strrchr(tiff_dir, '/');
if (dirsuffix != NULL) { /* found a / */
/* printf ("len = %i dir = '%s' dirsuffix = '%s'\n", len, tiff_dir, dirsuffix);*/
if ( 0 == strcmp( dirsuffix, "/" ) ) { /* ok, ends with / */
/* remove last / */
assert(len >= 1); // or whatever you want to do with short strings
tiff_dir[len-1] = 0;
/* printf("tiffdir2 = '%s'\n", tiff_dir); */
}
}
/* iterate through all files in given dir */
if ((dir = opendir (tiff_file_or_dir)) != NULL) {
/* print all the files and directories within directory */
while ((ent = readdir (dir)) != NULL) {
struct stat attribute;
len = strlen( tiff_dir ) + strlen( ent->d_name ) + 2;
char fqname [ len ];
snprintf( fqname, len, "%s/%s", tiff_dir, ent->d_name);
if (stat( fqname, &attribute) == -1) {
fprintf (stderr, "could not stat on file '%s' in directory '%s' (%s)\n", ent->d_name, tiff_dir, fqname);
exit(EXIT_FAILURE);
}
if(attribute.st_mode & S_IFREG) {
/* printf ("%s\n", fqname); */
parse_plan_via_file(cfg_file);
is_valid += check_specific_tiff_file( fqname, flag_use_memorymapped_io);
clean_plan();
printf("\n");
}
}
closedir (dir);
} else {
/* could not open directory */
fprintf( stderr, "directory '%s' could not be opened\n", tiff_file_or_dir);
exit(EXIT_FAILURE);
}
} else {
/* use tiff_file_or_dir */
parse_plan_via_file(cfg_file);
is_valid = check_specific_tiff_file( tiff_file_or_dir, flag_use_memorymapped_io);
clean_plan();
/* use tiff_file_or_dir */
parse_plan_via_file(cfg_file);
is_valid = check_specific_tiff_file( tiff_file_or_dir, flag_use_memorymapped_io);
clean_plan();
}
if (0 == is_valid) {
exit(EXIT_SUCCESS);
exit(EXIT_SUCCESS);
} else {
exit(EXIT_FAILURE);
exit(EXIT_FAILURE);
}
}

8
src/headers/check.h

@ -24,9 +24,11 @@ typedef struct ctiff_s {
/* TODO: add file size */
} ctiff_t;
typedef enum{ rm_default, rm_file, rm_rule, rm_tag, rm_value, rm_expected, rm_hard_error, rm_error, rm_warning, rm_precondition, rm_logicalor_error } rm_type_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;
rm_type_t rm_type;
char * rm_msg;
} retmsg_t;
typedef struct ret_s {
@ -72,7 +74,7 @@ typedef uint16 tag_t;
#define EXPECTSTRLEN 160
#define VALUESTRLEN 160
#define TIFFAILSTRLEN (EXPECTSTRLEN + VALUESTRLEN)
#define MAXRESULT 200000
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);
@ -83,6 +85,8 @@ ret_t tif_rules(const char *msg);
ret_t tif_files(const char *msg);
ret_t tif_no_tag(tag_t tag);
ret_t _empty_result();
const char * float2str(float v);
const char* tag2str(tag_t tag);
const char* int2str(int v);

3
src/headers/check_helper.h

@ -12,7 +12,7 @@
#include <tiff.h>
#include <tiffio.h>
typedef enum{ render_default, render_debug, render_ansi} render_type;
typedef enum{ render_default, render_debug, render_ansi, render_xml} render_type;
/* helper */
ret_t check_tag_has_fvalue(ctiff_t * ctif, tag_t tag, float value);
@ -31,6 +31,7 @@ offset_t read_offsetdata( ctiff_t * ctif, uint32 address, uint16 count, uint16 d
//int TIFFIsByteSwapped(TIFF * tif);
const char * renderer ( const ret_t ret );
void set_renderer_to_ansi();
void set_renderer_to_xml();
char * secstrcat (char * dest, const char * src, int maxsize);
ctiff_t * initialize_ctif( const char * filename );
void free_ctif( ctiff_t * ctif);

153
src/headers/config_parser.h

@ -11,116 +11,107 @@
#include "check.h"
/* struct to hold parsing configuration */
typedef struct funcu * funcp;
typedef struct {
funcp fu_p;
char * name;
void * next;
ret_t result;
} executionentry_t;
typedef struct {
executionentry_t * start;
executionentry_t * last;
} executionplan_t;
typedef enum { mandatory, ifdepends, optdepends, optional } requirements_t;
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)(ctiff_t *);
} f_tifp_t;
typedef struct f_tifp_tag_s {
int 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)(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)(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)(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)(ctiff_t *, tag_t a, const char * b);
} f_tifp_tag_charp_t;
typedef enum { f_dummy, f_tifp, f_tifp_tag, f_tifp_tag_uint, f_tifp_tag_uint_uint, f_tifp_tag_int_uintp, f_tifp_tag_charp } ftype_t;
struct funcu {
ftype_t ftype;
funcp pred;
tag_t tag;
union {
struct f_tifp_s * ftifp;
struct f_tifp_tag_s * ftifp_tag;
struct f_tifp_tag_uint_s * ftifp_tag_uint;
struct f_tifp_tag_uint_uint_s * ftifp_tag_uint_uint;
struct f_tifp_tag_int_uintp_s * ftifp_tag_int_uintp;
struct f_tifp_tag_charp_s * ftifp_tag_charp;
} fu;
};
typedef enum { range, logical_or, any, only, regex, ntupel } values_t;
typedef enum { no_ref, any_ref, only_ref, range_ref, ntupel_ref, regex_ref } reference_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
typedef enum {
fc_true,
fc_false,
fc_tag_has_some_of_these_values,
fc_tag_has_valuelist,
fc_tag_has_value_in_range,
fc_tag_has_value,
fc_tag_has_value_quiet,
fc_tag,
fc_tag_quiet,
fc_notag,
fc_tag_has_valid_type,
fc_datetime,
fc_icc,
fc_has_only_one_ifd,
fc_tagorder,
fc_tag_has_valid_asciivalue,
fc_tag_has_value_matching_regex,
fc_all_offsets_are_word_aligned,
fc_all_offsets_are_used_once_only,
fc_all_IFDs_are_word_aligned,
fc_internal_logic_combine,
fc_dummy
} function_t;
#define INTERNALSTACKDEPTH 10
typedef struct internal_entry_s {
int lineno;
int is_precondition;
tag_t tag;
function_t function;
values_t val_stack[INTERNALSTACKDEPTH];
const 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;
ret_t result;
} full_res_t;
typedef struct parser_state_s {
// TODO: Anzahl le-Werte für Tupel in Stack speichern
int lineno;
int valuelist;
int lelist;
tag_t tag;
values_t val;
tag_t tagref;
values_t val_stack[MAXSTACKDEPTH];
const char * regex_stack[MAXSTACKDEPTH];
requirements_t req;
unsigned int i_stack[40];
unsigned int i_stack[MAXSTACKDEPTH];
int i_stackp;
int val_stackp;
int regex_stackp;
int called_tags[MAXTAGS];
FILE * stream;
int any_reference;
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];
} 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, rm_type_t type);
full_res_t _helper_get_nth(int n);
void set_parse_error(char * msg, char * yytext);
int execute_plan (ctiff_t * ctif) ;
void execute_plan (ctiff_t * ctif);
void print_plan ();
void print_plan_results ();
int print_plan_results ();
void clean_plan ();
void parse_plan ();
void parse_plan_via_stream (FILE * stream);
void parse_plan_via_file (const char * filename);
void add_default_rules_to_plan();
void set_include( const char * );
/* helper */
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);
void result_push(full_res_t);
#endif
/* _FIXIT_TIFF_CONFIG_PARSER */

4
src/helper/check_helper.c

@ -19,6 +19,10 @@
*/
char * secstrcat (char * dest, const char * src, int maxsize) {
if (NULL == dest) {
fprintf(stderr, "internal error, dest is NULL!\n");
exit(EXIT_FAILURE);
}
int destsize = strlen(dest);
int srclen = strlen(src);
//fprintf(stderr, "1dest='%s' , src='%s', destsize=%i, srclen=%i\n", dest, src, destsize, srclen);

48
src/helper/check_print.c

@ -5,7 +5,7 @@
* (see http://libtiff.maptools.org/misc.html)
*
*/
#define DEBUG
#define _GNU_SOURCE
#include <string.h>
@ -43,18 +43,14 @@ ret_t tif_fails(const char* fail_message) {
res.returnmsg->rm_type=rm_hard_error;
res.count = 1;
res.returnmsg->rm_msg = str;
printf( "%s", renderer( res) );
// free (str);
// free (res.returnmsg);
//printf( "%s", renderer( res) );
return res;
}
ret_t tif_fails_tag(tag_t tag, const char* expected, const char* value) {
ret_t res = tif_returns( tag, expected, value);
// call renderer
printf( "%s", renderer( res) );
// free (str);
// free (res.returnmsg);
//printf( "%s", renderer( res) );
return res;
}
@ -86,9 +82,7 @@ ret_t tif_rules_tag(tag_t tag, const char *msg) {
p++;
p->rm_type=rm_rule;
p->rm_msg = strndup( msg, MAXSTRLEN);
printf( "%s", renderer( res) );
// free (str);
// free (res.returnmsg);
// printf( "%s", renderer( res) );
return res;
}
@ -124,10 +118,8 @@ ret_t tif_no_tag(tag_t tag) {
p++;
p->rm_type=rm_value;
p->rm_msg = ", but is not whitelisted (or rule has no matched dependency)";
//
printf( "%s", renderer( res) );
// free (str);
// free (res.returnmsg);
// printf( "%s", renderer( res) );
return res;
}
@ -149,9 +141,7 @@ ret_t tif_rules(const char *msg) {
p++;
p->rm_type=rm_rule;
p->rm_msg = strndup( msg, MAXSTRLEN);
printf( "%s", renderer( res) );
// free (str);
// free (res.returnmsg);
//printf( "%s", renderer( res) );
return res;
}
ret_t tif_files(const char *msg) {
@ -172,9 +162,7 @@ ret_t tif_files(const char *msg) {
p++;
p->rm_type=rm_file;
p->rm_msg = strndup( msg, MAXSTRLEN);
printf( "%s", renderer( res) );
// free (str);
// free (res.returnmsg);
// printf( "%s", renderer( res) );
return res;
}
@ -239,8 +227,26 @@ ret_t tif_returns(tag_t tag, const char* expected, const char* value) {
}
ret_t tif_fails_by_returns( ret_t ret ) {
printf( "%s", renderer( ret) );
// printf( "%s", renderer( ret) );
return ret;
}
ret_t _empty_result() {
ret_t t;
t.returncode=0;
t.returnmsg=NULL;
t.count=1;
t.returnmsg = malloc( sizeof( retmsg_t) * t.count );
retmsg_t * p = t.returnmsg;
if (NULL==t.returnmsg) {
fprintf(stderr, "could not allocate memory for _empty_result\n");
exit(EXIT_FAILURE);
};
// header
p->rm_type=rm_default;
p->rm_msg = "ok";
return t;
}

59
src/helper/check_renderer.c

@ -67,6 +67,9 @@ void set_renderer_to_ansi() {
render_engine=render_ansi;
}
}
void set_renderer_to_xml() {
render_engine=render_xml;
}
const char * renderer_debug ( ret_t ret ) {
char res[1024] = "";
@ -137,7 +140,8 @@ const char * renderer_ansi ( ret_t ret ) {
case rm_expected: secstrcat( res, ANSI_RED , 1024); break;
case rm_hard_error: secstrcat( res, ANSI_RED_BOLD , 1024); break;
case rm_error: secstrcat( res, ANSI_RED , 1024); break;
case rm_warning: secstrcat( res, ANSI_YELLOW , 1024); break;
case rm_warning: secstrcat( res, ANSI_GREY , 1024); break;
case rm_logicalor_error: secstrcat( res, ANSI_YELLOW , 1024); break;
case rm_file: secstrcat( res, ANSI_BLUE_BOLD, 1024); break;
default: secstrcat( res, ANSI_NORMAL , 1024);
}
@ -152,13 +156,60 @@ const char * renderer_ansi ( ret_t ret ) {
secstrcat(res, "\n", 1024);
return strdup( res );
}
const char * renderer_xml ( ret_t ret ) {
char res[1024] = "<checkit_tiff_result>";
if (0 == ret.returncode) {
secstrcat( res, "<is_valid>true</is_valid>", 1024 );
} else {
secstrcat( res, "<is_valid>false</is_valid>", 1024 );
}
retmsg_t * startp = ret.returnmsg;
int c = 0;
while (NULL != startp && c < ret.count) {
switch (startp->rm_type) {
case rm_rule: secstrcat( res, "<rule>" , 1024); break;
case rm_tag: secstrcat( res, "<tag>" , 1024); break;
case rm_value: secstrcat( res, "<value>" , 1024); break;
case rm_expected: secstrcat( res, "<expected>" , 1024); break;
case rm_hard_error: secstrcat( res, "<harderror>" , 1024); break;
case rm_error: secstrcat( res, "<error>" , 1024); break;
case rm_warning: secstrcat( res, "<warn>" , 1024); break;
case rm_logicalor_error: secstrcat( res, "<partial_logical_or_error>" , 1024); break;
case rm_file: secstrcat( res, "<file>", 1024); break;
default: secstrcat( res, "" , 1024);
}
/* FIXME: replace all occurrences of a space, backslash, caret, or
any control character anywhere in the string, as well as a hash mark as
the first character. */
secstrcat(res, startp->rm_msg, 1024);
switch (startp->rm_type) {
case rm_rule: secstrcat( res, "</rule>" , 1024); break;
case rm_tag: secstrcat( res, "</tag>" , 1024); break;
case rm_value: secstrcat( res, "</value>" , 1024); break;
case rm_expected: secstrcat( res, "</expected>" , 1024); break;
case rm_hard_error: secstrcat( res, "</harderror>" , 1024); break;
case rm_error: secstrcat( res, "</error>" , 1024); break;
case rm_warning: secstrcat( res, "</warn>" , 1024); break;
case rm_logicalor_error: secstrcat( res, "</partial_logical_or_error>" , 1024); break;
case rm_file: secstrcat( res, "</file>", 1024); break;
default: secstrcat( res, "" , 1024);
}
startp++;
c++;
}
secstrcat(res, "</checkit_tiff_result>", 1024);
secstrcat(res, "\n", 1024);
return strdup( res );
}
const char * renderer ( ret_t ret ) {
// call debug renderer
switch (render_engine) {
case render_ansi: return renderer_ansi( ret );
case render_debug: return renderer_debug( ret );
default: return renderer_default( ret );
case render_xml: return renderer_xml( ret );
case render_ansi: return renderer_ansi( ret );
case render_debug: return renderer_debug( ret );
default: return renderer_default( ret );
}
return "";
}

1314
src/parser/config_parser.c
File diff suppressed because it is too large
View File

Loading…
Cancel
Save