Skip to content
Snippets Groups Projects
Commit 6199dcbc authored by Daniel Salzman's avatar Daniel Salzman
Browse files

Added another processing mode suitable for testing

refs #2041 @30m
parent 19cecad7
Branches
Tags
No related merge requests found
......@@ -919,7 +919,7 @@
# }
#}
# Hex array or empty with control to forward length statement.
# Hex array with control to forward length statement.
type_data = hex_array ;#%_type_data_exit $!_hex_char_error;
# END
......
......@@ -25,6 +25,8 @@
#include "zscanner/scanner.h"
const char *separator = "------\n";
static void print_wire_dname(const uint8_t *dname, uint32_t dname_length)
{
uint32_t label_length = 0, i = 0;
......@@ -40,7 +42,11 @@ static void print_wire_dname(const uint8_t *dname, uint32_t dname_length)
}
}
void process_error(const scanner_t *s)
void empty_process_record(const scanner_t *s) { };
void empty_process_error(const scanner_t *s) { };
void debug_process_error(const scanner_t *s)
{
printf("LINE(%03"PRIu64") ERROR(%s) FILE(%s) NEAR(%s)\n",
s->line_counter,
......@@ -50,7 +56,7 @@ void process_error(const scanner_t *s)
fflush(stdout);
}
void process_record(const scanner_t *s)
void debug_process_record(const scanner_t *s)
{
uint32_t item, item_length, i;
......@@ -70,11 +76,43 @@ void process_record(const scanner_t *s)
printf(" (%u)", item_length);
for (i = s->r_data_items[item - 1]; i < s->r_data_items[item]; i++) {
printf("%02x", (s->r_data)[i]);
printf("%02X", (s->r_data)[i]);
}
}
printf("\n");
fflush(stdout);
}
void test_process_error(const scanner_t *s)
{
printf("ERROR=%i\n%s", s->error_code, separator);
fflush(stdout);
}
void test_process_record(const scanner_t *s)
{
uint32_t item, i;
printf("OWNER=");
for (i = 0; i < s->r_owner_length; i++) {
printf("%02x", s->r_owner[i]);
}
printf("\n");
printf("CLASS=%02X\n", s->r_class);
printf("RRTTL=%04X\n", s->r_ttl);
printf("RTYPE=%02X\n", s->r_type);
printf("ITEMS=%04X\n", s->r_data_items_count);
printf("RDATA=");
for (item = 1; item <= s->r_data_items_count; item++) {
if (item > 1) {
printf(" ");
}
for (i = s->r_data_items[item - 1]; i < s->r_data_items[item]; i++) {
printf("%02X", (s->r_data)[i]);
}
}
printf("\n%s", separator);
fflush(stdout);
}
......@@ -82,9 +120,9 @@ void dump_rdata(const scanner_t *s)
{
uint32_t item, i;
for (item = 1; item <= s->r_data_items_count; item++) {
for (i = s->r_data_items[item - 1]; i < s->r_data_items[item]; i++) {
printf("%c", (s->r_data)[i]);
for (item = 1; item <= s->r_data_items_count; item++) {
for (i = s->r_data_items[item - 1]; i < s->r_data_items[item]; i++) {
printf("%c", (s->r_data)[i]);
}
}
}
......
......@@ -29,12 +29,19 @@
#include "zscanner/scanner.h"
void empty_process_record(const scanner_t *scanner);
void process_error(const scanner_t *scanner);
void empty_process_error(const scanner_t *scanner);
void process_record(const scanner_t *scanner);
void debug_process_error(const scanner_t *scanner);
void dump_rdata(const scanner_t *s);
void debug_process_record(const scanner_t *scanner);
void test_process_error(const scanner_t *scanner);
void test_process_record(const scanner_t *scanner);
void dump_rdata(const scanner_t *scanner);
#endif // _ZSCANNER__TEST_FUNCTIONS_H_
......
......@@ -30,7 +30,10 @@ void help(int argc, char **argv)
printf("\nZone scanner testing tool.\n"
"Usage: %s [parameters] origin zonefile\n", argv[0]);
printf("Parameters:\n"
" -e Empty processing.\n"
" -m [0,1,2] Processing mode.\n"
" 0 empty output\n"
" 1 debug output (DEFAULT)\n"
" 2 test output\n"
" -t Launch unit tests.\n"
" -h Print this help.\n");
}
......@@ -39,24 +42,24 @@ int main(int argc, char *argv[])
{
// Parsed command line arguments.
int c = 0, li = 0;
int ret, empty = 0, test = 0;
int ret, mode = 1, test = 0;
file_loader_t *fl;
const char *origin;
const char *zone_file;
// Command line long options.
struct option opts[] = {
{"empty", no_argument, 0, 'e'},
{"mode", required_argument, 0, 'm'},
{"test", no_argument, 0, 't'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
// Command line options processing.
while ((c = getopt_long(argc, argv, "eth", opts, &li)) != -1) {
while ((c = getopt_long(argc, argv, "m:th", opts, &li)) != -1) {
switch (c) {
case 'e':
empty = 1;
case 'm':
mode = atoi(optarg);
break;
case 't':
test = 1;
......@@ -81,24 +84,35 @@ int main(int argc, char *argv[])
zone_file = argv[optind];
origin = argv[optind + 1];
if (empty == 1) {
void empty_process_record(const scanner_t *s) { };
void empty_process_error(const scanner_t *s) { };
fl = file_loader_create(origin,
zone_file,
DEFAULT_CLASS,
DEFAULT_TTL,
&empty_process_record,
&empty_process_error);
}
else {
fl = file_loader_create(origin,
zone_file,
DEFAULT_CLASS,
DEFAULT_TTL,
&process_record,
&process_error);
switch (mode) {
case 0:
fl = file_loader_create(origin,
zone_file,
DEFAULT_CLASS,
DEFAULT_TTL,
&empty_process_record,
&empty_process_error);
break;
case 1:
fl = file_loader_create(origin,
zone_file,
DEFAULT_CLASS,
DEFAULT_TTL,
&debug_process_record,
&debug_process_error);
break;
case 2:
fl = file_loader_create(origin,
zone_file,
DEFAULT_CLASS,
DEFAULT_TTL,
&test_process_record,
&test_process_error);
break;
default:
printf("Bad mode number!\n");
help(argc, argv);
return EXIT_FAILURE;
}
if (fl != NULL) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment