Commit 87f53c3c authored by Daniel Salzman's avatar Daniel Salzman

zscanner: refactor error state handling

parent e2d027de
......@@ -32776,32 +32776,33 @@ tr925:
s->state = ZS_STATE_INCLUDE;
escape = true;
} else {
// Create new scanner for included zone file.
zs_scanner_t *ss = malloc(sizeof(zs_scanner_t));
if (ss == NULL) {
ERR(ZS_UNPROCESSED_INCLUDE);
p--; {goto st253;}
}
// Parse included zone file.
if (zs_init(ss, (char *)s->buffer, s->default_class, s->default_ttl) != 0 ||
zs_set_input_file(ss, (char *)(s->include_filename)) != 0 ||
zs_set_processing(ss, s->process.record, s->process.error, s->process.data) != 0 ||
zs_parse_all(ss) != 0) {
// File internal errors are handled by error callback.
if (ss->error.counter > 0) {
// Create new scanner for included zone file.
zs_scanner_t *ss = malloc(sizeof(zs_scanner_t));
if (ss == NULL) {
ERR(ZS_UNPROCESSED_INCLUDE);
// General include file error.
} else {
ERR(ss->error.code);
p--; {goto st253;}
}
// Parse included zone file.
if (zs_init(ss, (char *)s->buffer, s->default_class,
s->default_ttl) != 0 ||
zs_set_input_file(ss, (char *)(s->include_filename)) != 0 ||
zs_set_processing(ss, s->process.record, s->process.error,
s->process.data) != 0 ||
zs_parse_all(ss) != 0) {
// File internal errors are handled by error callback.
if (ss->error.counter > 0) {
ERR(ZS_UNPROCESSED_INCLUDE);
// General include file error.
} else {
ERR(ss->error.code);
}
zs_deinit(ss);
free(ss);
p--; {goto st253;}
}
zs_deinit(ss);
free(ss);
p--; {goto st253;}
}
zs_deinit(ss);
free(ss);
}
}
{
......@@ -32840,32 +32841,33 @@ tr935:
s->state = ZS_STATE_INCLUDE;
escape = true;
} else {
// Create new scanner for included zone file.
zs_scanner_t *ss = malloc(sizeof(zs_scanner_t));
if (ss == NULL) {
ERR(ZS_UNPROCESSED_INCLUDE);
p--; {goto st253;}
}
// Parse included zone file.
if (zs_init(ss, (char *)s->buffer, s->default_class, s->default_ttl) != 0 ||
zs_set_input_file(ss, (char *)(s->include_filename)) != 0 ||
zs_set_processing(ss, s->process.record, s->process.error, s->process.data) != 0 ||
zs_parse_all(ss) != 0) {
// File internal errors are handled by error callback.
if (ss->error.counter > 0) {
// Create new scanner for included zone file.
zs_scanner_t *ss = malloc(sizeof(zs_scanner_t));
if (ss == NULL) {
ERR(ZS_UNPROCESSED_INCLUDE);
// General include file error.
} else {
ERR(ss->error.code);
p--; {goto st253;}
}
// Parse included zone file.
if (zs_init(ss, (char *)s->buffer, s->default_class,
s->default_ttl) != 0 ||
zs_set_input_file(ss, (char *)(s->include_filename)) != 0 ||
zs_set_processing(ss, s->process.record, s->process.error,
s->process.data) != 0 ||
zs_parse_all(ss) != 0) {
// File internal errors are handled by error callback.
if (ss->error.counter > 0) {
ERR(ZS_UNPROCESSED_INCLUDE);
// General include file error.
} else {
ERR(ss->error.code);
}
zs_deinit(ss);
free(ss);
p--; {goto st253;}
}
zs_deinit(ss);
free(ss);
p--; {goto st253;}
}
zs_deinit(ss);
free(ss);
}
}
{
......@@ -32911,32 +32913,33 @@ tr947:
s->state = ZS_STATE_INCLUDE;
escape = true;
} else {
// Create new scanner for included zone file.
zs_scanner_t *ss = malloc(sizeof(zs_scanner_t));
if (ss == NULL) {
ERR(ZS_UNPROCESSED_INCLUDE);
p--; {goto st253;}
}
// Parse included zone file.
if (zs_init(ss, (char *)s->buffer, s->default_class, s->default_ttl) != 0 ||
zs_set_input_file(ss, (char *)(s->include_filename)) != 0 ||
zs_set_processing(ss, s->process.record, s->process.error, s->process.data) != 0 ||
zs_parse_all(ss) != 0) {
// File internal errors are handled by error callback.
if (ss->error.counter > 0) {
// Create new scanner for included zone file.
zs_scanner_t *ss = malloc(sizeof(zs_scanner_t));
if (ss == NULL) {
ERR(ZS_UNPROCESSED_INCLUDE);
// General include file error.
} else {
ERR(ss->error.code);
p--; {goto st253;}
}
// Parse included zone file.
if (zs_init(ss, (char *)s->buffer, s->default_class,
s->default_ttl) != 0 ||
zs_set_input_file(ss, (char *)(s->include_filename)) != 0 ||
zs_set_processing(ss, s->process.record, s->process.error,
s->process.data) != 0 ||
zs_parse_all(ss) != 0) {
// File internal errors are handled by error callback.
if (ss->error.counter > 0) {
ERR(ZS_UNPROCESSED_INCLUDE);
// General include file error.
} else {
ERR(ss->error.code);
}
zs_deinit(ss);
free(ss);
p--; {goto st253;}
}
zs_deinit(ss);
free(ss);
p--; {goto st253;}
}
zs_deinit(ss);
free(ss);
}
}
{
......@@ -33190,32 +33193,33 @@ tr959:
s->state = ZS_STATE_INCLUDE;
escape = true;
} else {
// Create new scanner for included zone file.
zs_scanner_t *ss = malloc(sizeof(zs_scanner_t));
if (ss == NULL) {
ERR(ZS_UNPROCESSED_INCLUDE);
p--; {goto st253;}
}
// Parse included zone file.
if (zs_init(ss, (char *)s->buffer, s->default_class, s->default_ttl) != 0 ||
zs_set_input_file(ss, (char *)(s->include_filename)) != 0 ||
zs_set_processing(ss, s->process.record, s->process.error, s->process.data) != 0 ||
zs_parse_all(ss) != 0) {
// File internal errors are handled by error callback.
if (ss->error.counter > 0) {
// Create new scanner for included zone file.
zs_scanner_t *ss = malloc(sizeof(zs_scanner_t));
if (ss == NULL) {
ERR(ZS_UNPROCESSED_INCLUDE);
// General include file error.
} else {
ERR(ss->error.code);
p--; {goto st253;}
}
// Parse included zone file.
if (zs_init(ss, (char *)s->buffer, s->default_class,
s->default_ttl) != 0 ||
zs_set_input_file(ss, (char *)(s->include_filename)) != 0 ||
zs_set_processing(ss, s->process.record, s->process.error,
s->process.data) != 0 ||
zs_parse_all(ss) != 0) {
// File internal errors are handled by error callback.
if (ss->error.counter > 0) {
ERR(ZS_UNPROCESSED_INCLUDE);
// General include file error.
} else {
ERR(ss->error.code);
}
zs_deinit(ss);
free(ss);
p--; {goto st253;}
}
zs_deinit(ss);
free(ss);
p--; {goto st253;}
}
zs_deinit(ss);
free(ss);
}
}
{
......@@ -75386,43 +75390,28 @@ case 1161:
// Check if the scanner state machine is in an uncovered state.
bool extra_error = false;
if (cs == 0) {
ERR(ZS_UNCOVERED_STATE);
s->error.counter++;
// Fill error context data.
for (s->buffer_length = 0;
((p + s->buffer_length) < pe) &&
(s->buffer_length < sizeof(s->buffer) - 1);
s->buffer_length++)
{
// Only rest of the current line.
if (*(p + s->buffer_length) == '\n') {
break;
}
s->buffer[s->buffer_length] = *(p + s->buffer_length);
}
// Ending string in buffer.
s->buffer[s->buffer_length++] = 0;
s->state = ZS_STATE_ERROR;
// Execute the error callback.
if (s->process.automatic && s->process.error != NULL) {
s->process.error(s);
}
return;
extra_error = true;
// Check for an unclosed multiline record.
} else if (s->input.eof && s->multiline) {
ERR(ZS_UNCLOSED_MULTILINE);
extra_error = true;
}
// Check unclosed multiline record.
if (s->input.eof && s->multiline) {
ERR(ZS_UNCLOSED_MULTILINE);
// Treat the extra error.
if (extra_error) {
s->error.counter++;
s->state = ZS_STATE_ERROR;
// Copy the error context just for the part of the current line.
s->buffer_length = 0;
while (p < pe && *p != '\n' && s->buffer_length < 50) {
s->buffer[s->buffer_length++] = *p++;
}
s->buffer[s->buffer_length++] = 0;
// Execute the error callback.
if (s->process.automatic && s->process.error != NULL) {
s->process.error(s);
......@@ -6111,32 +6111,33 @@ _match:
s->state = ZS_STATE_INCLUDE;
escape = true;
} else {
// Create new scanner for included zone file.
zs_scanner_t *ss = malloc(sizeof(zs_scanner_t));
if (ss == NULL) {
ERR(ZS_UNPROCESSED_INCLUDE);
p--; {cs = 253; goto _again;}
}
// Parse included zone file.
if (zs_init(ss, (char *)s->buffer, s->default_class, s->default_ttl) != 0 ||
zs_set_input_file(ss, (char *)(s->include_filename)) != 0 ||
zs_set_processing(ss, s->process.record, s->process.error, s->process.data) != 0 ||
zs_parse_all(ss) != 0) {
// File internal errors are handled by error callback.
if (ss->error.counter > 0) {
// Create new scanner for included zone file.
zs_scanner_t *ss = malloc(sizeof(zs_scanner_t));
if (ss == NULL) {
ERR(ZS_UNPROCESSED_INCLUDE);
// General include file error.
} else {
ERR(ss->error.code);
p--; {cs = 253; goto _again;}
}
// Parse included zone file.
if (zs_init(ss, (char *)s->buffer, s->default_class,
s->default_ttl) != 0 ||
zs_set_input_file(ss, (char *)(s->include_filename)) != 0 ||
zs_set_processing(ss, s->process.record, s->process.error,
s->process.data) != 0 ||
zs_parse_all(ss) != 0) {
// File internal errors are handled by error callback.
if (ss->error.counter > 0) {
ERR(ZS_UNPROCESSED_INCLUDE);
// General include file error.
} else {
ERR(ss->error.code);
}
zs_deinit(ss);
free(ss);
p--; {cs = 253; goto _again;}
}
zs_deinit(ss);
free(ss);
p--; {cs = 253; goto _again;}
}
zs_deinit(ss);
free(ss);
}
}
break;
......@@ -7697,43 +7698,28 @@ _again:
// Check if the scanner state machine is in an uncovered state.
bool extra_error = false;
if (cs == 0) {
ERR(ZS_UNCOVERED_STATE);
s->error.counter++;
// Fill error context data.
for (s->buffer_length = 0;
((p + s->buffer_length) < pe) &&
(s->buffer_length < sizeof(s->buffer) - 1);
s->buffer_length++)
{
// Only rest of the current line.
if (*(p + s->buffer_length) == '\n') {
break;
}
s->buffer[s->buffer_length] = *(p + s->buffer_length);
}
// Ending string in buffer.
s->buffer[s->buffer_length++] = 0;
s->state = ZS_STATE_ERROR;
// Execute the error callback.
if (s->process.automatic && s->process.error != NULL) {
s->process.error(s);
}
return;
extra_error = true;
// Check for an unclosed multiline record.
} else if (s->input.eof && s->multiline) {
ERR(ZS_UNCLOSED_MULTILINE);
extra_error = true;
}
// Check unclosed multiline record.
if (s->input.eof && s->multiline) {
ERR(ZS_UNCLOSED_MULTILINE);
// Treat the extra error.
if (extra_error) {
s->error.counter++;
s->state = ZS_STATE_ERROR;
// Copy the error context just for the part of the current line.
s->buffer_length = 0;
while (p < pe && *p != '\n' && s->buffer_length < 50) {
s->buffer[s->buffer_length++] = *p++;
}
s->buffer[s->buffer_length++] = 0;
// Execute the error callback.
if (s->process.automatic && s->process.error != NULL) {
s->process.error(s);
......
......@@ -341,43 +341,28 @@ static void parse(
%% write exec;
// Check if the scanner state machine is in an uncovered state.
bool extra_error = false;
if (cs == %%{ write error; }%%) {
ERR(ZS_UNCOVERED_STATE);
s->error.counter++;
// Fill error context data.
for (s->buffer_length = 0;
((p + s->buffer_length) < pe) &&
(s->buffer_length < sizeof(s->buffer) - 1);
s->buffer_length++)
{
// Only rest of the current line.
if (*(p + s->buffer_length) == '\n') {
break;
}
s->buffer[s->buffer_length] = *(p + s->buffer_length);
}
// Ending string in buffer.
s->buffer[s->buffer_length++] = 0;
s->state = ZS_STATE_ERROR;
// Execute the error callback.
if (s->process.automatic && s->process.error != NULL) {
s->process.error(s);
}
return;
extra_error = true;
// Check for an unclosed multiline record.
} else if (s->input.eof && s->multiline) {
ERR(ZS_UNCLOSED_MULTILINE);
extra_error = true;
}
// Check unclosed multiline record.
if (s->input.eof && s->multiline) {
ERR(ZS_UNCLOSED_MULTILINE);
// Treat the extra error.
if (extra_error) {
s->error.counter++;
s->state = ZS_STATE_ERROR;
// Copy the error context just for the part of the current line.
s->buffer_length = 0;
while (p < pe && *p != '\n' && s->buffer_length < 50) {
s->buffer[s->buffer_length++] = *p++;
}
s->buffer[s->buffer_length++] = 0;
// Execute the error callback.
if (s->process.automatic && s->process.error != NULL) {
s->process.error(s);
......
......@@ -735,32 +735,33 @@
s->state = ZS_STATE_INCLUDE;
escape = true;
} else {
// Create new scanner for included zone file.
zs_scanner_t *ss = malloc(sizeof(zs_scanner_t));
if (ss == NULL) {
ERR(ZS_UNPROCESSED_INCLUDE);
fhold; fgoto err_line;
}
// Parse included zone file.
if (zs_init(ss, (char *)s->buffer, s->default_class, s->default_ttl) != 0 ||
zs_set_input_file(ss, (char *)(s->include_filename)) != 0 ||
zs_set_processing(ss, s->process.record, s->process.error, s->process.data) != 0 ||
zs_parse_all(ss) != 0) {
// File internal errors are handled by error callback.
if (ss->error.counter > 0) {
// Create new scanner for included zone file.
zs_scanner_t *ss = malloc(sizeof(zs_scanner_t));
if (ss == NULL) {
ERR(ZS_UNPROCESSED_INCLUDE);
// General include file error.
} else {
ERR(ss->error.code);
fhold; fgoto err_line;
}
// Parse included zone file.
if (zs_init(ss, (char *)s->buffer, s->default_class,
s->default_ttl) != 0 ||
zs_set_input_file(ss, (char *)(s->include_filename)) != 0 ||
zs_set_processing(ss, s->process.record, s->process.error,
s->process.data) != 0 ||
zs_parse_all(ss) != 0) {
// File internal errors are handled by error callback.
if (ss->error.counter > 0) {
ERR(ZS_UNPROCESSED_INCLUDE);
// General include file error.
} else {
ERR(ss->error.code);
}
zs_deinit(ss);
free(ss);
fhold; fgoto err_line;
}
zs_deinit(ss);
free(ss);
fhold; fgoto err_line;
}
zs_deinit(ss);
free(ss);
}
}
......
Markdown is supported
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