Commit 073e7581 authored by Daniel Salzman's avatar Daniel Salzman Committed by Libor Peltan

zscanner: add comment callback processing support

parent af3a9826
This diff is collapsed.
......@@ -5739,6 +5739,20 @@ int zs_set_processing(
return 0;
}
__attribute__((visibility("default")))
int zs_set_processing_comment(
zs_scanner_t *s,
void (*process_comment)(zs_scanner_t *))
{
if (s == NULL) {
return -1;
}
s->process.comment = process_comment;
return 0;
}
typedef enum {
WRAP_NONE, // Initial state.
WRAP_DETECTED, // Input block end is a first '\' in rdata.
......@@ -6003,6 +6017,16 @@ _match:
case 6:
{
s->buffer[s->buffer_length++] = 0;
// Execute the comment callback.
if (s->process.automatic && s->process.comment != NULL) {
s->process.comment(s);
// Stop if required from the callback.
if (s->state == ZS_STATE_STOP) {
{p++; goto _out; }
}
}
}
break;
case 7:
......
......@@ -179,6 +179,8 @@ struct zs_scanner {
void (*record)(zs_scanner_t *);
/*! Callback function for wrong situations. */
void (*error)(zs_scanner_t *);
/*! Callback function for pure comment line. */
void (*comment)(zs_scanner_t *);
/*! Arbitrary data useful inside callback functions. */
void *data;
} process;
......@@ -299,7 +301,7 @@ int zs_set_input_string(
);
/*!
* \brief Sets the scanner to parse a zone file..
* \brief Sets the scanner to parse a zone file.
*
* \note Error code is stored in the scanner context.
*
......@@ -334,6 +336,24 @@ int zs_set_processing(
void *data
);
/*!
* \brief Sets the scanner comment processing callback for automatic processing.
*
* \note If the comment is after a valid resource record, the callback is
* executed before a record processing callback!
* \note Optional data must be set via zs_set_processing.
*
* \param scanner Scanner context.
* \param process_comment Processing callback function (may be NULL).
*
* \retval 0 if success.
* \retval -1 if error.
*/
int zs_set_processing_comment(
zs_scanner_t *scanner,
void (*process_comment)(zs_scanner_t *)
);
/*!
* \brief Parses one record from the input.
*
......
......@@ -377,6 +377,20 @@ int zs_set_processing(
return 0;
}
__attribute__((visibility("default")))
int zs_set_processing_comment(
zs_scanner_t *s,
void (*process_comment)(zs_scanner_t *))
{
if (s == NULL) {
return -1;
}
s->process.comment = process_comment;
return 0;
}
typedef enum {
WRAP_NONE, // Initial state.
WRAP_DETECTED, // Input block end is a first '\' in rdata.
......
......@@ -51,6 +51,16 @@
}
action _comment_exit {
s->buffer[s->buffer_length++] = 0;
// Execute the comment callback.
if (s->process.automatic && s->process.comment != NULL) {
s->process.comment(s);
// Stop if required from the callback.
if (s->state == ZS_STATE_STOP) {
fbreak;
}
}
}
action _rest_init {
......
......@@ -86,6 +86,13 @@ void debug_process_record(zs_scanner_t *s)
fflush(stdout);
}
void debug_process_comment(zs_scanner_t *s)
{
printf("LINE(%03"PRIu64") COMMENT(%.*s)\n", s->line_counter,
(int)s->buffer_length, s->buffer);
fflush(stdout);
}
void test_process_error(zs_scanner_t *s)
{
if (s->error.fatal) {
......
......@@ -22,6 +22,8 @@ void debug_process_error(zs_scanner_t *scanner);
void debug_process_record(zs_scanner_t *scanner);
void debug_process_comment(zs_scanner_t *scanner);
void test_process_error(zs_scanner_t *scanner);
void test_process_record(zs_scanner_t *scanner);
......
......@@ -211,6 +211,7 @@ int main(int argc, char *argv[])
break;
case 1:
ret = zs_set_processing(s, debug_process_record, debug_process_error, NULL);
ret += zs_set_processing_comment(s, debug_process_comment);
break;
case 2:
ret = zs_set_processing(s, test_process_record, test_process_error, NULL);
......
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