| 1 |
.TH "AUPARSE_FEED" "3" "Sept 2023" "Red Hat" "Linux Audit API" |
| 2 |
.SH NAME |
| 3 |
auparse_feed \- feed data into parser |
| 4 |
.SH "SYNOPSIS" |
| 5 |
.B #include <auparse.h> |
| 6 |
.sp |
| 7 |
.nf |
| 8 |
.BI "int auparse_feed(auparse_state_t *" au, const char *" data, size_t" data_len);" |
| 9 |
.fi |
| 10 |
|
| 11 |
.TP |
| 12 |
.I au |
| 13 |
The audit parse state |
| 14 |
.TP |
| 15 |
.I data |
| 16 |
a buffer of data to feed into the parser, it is |
| 17 |
.I data_len |
| 18 |
bytes long. The data is copied in the parser, upon return the caller may free or reuse the data buffer. |
| 19 |
.TP |
| 20 |
.I data_len |
| 21 |
number of bytes in |
| 22 |
.I data |
| 23 |
|
| 24 |
.SH "DESCRIPTION" |
| 25 |
|
| 26 |
.I auparse_feed |
| 27 |
supplies new data for the parser to consume. |
| 28 |
.I auparse_init() |
| 29 |
must have been called with a source type of AUSOURCE_FEED and a NULL pointer. |
| 30 |
.br |
| 31 |
.sp |
| 32 |
The parser consumes as much data |
| 33 |
as it can invoking a user supplied callback specified with |
| 34 |
.I auparse_add_callback |
| 35 |
with a cb_event_type of |
| 36 |
.I AUPARSE_CB_EVENT_READY |
| 37 |
each time the parser recognizes a complete event in the data stream. Data not fully parsed will persist and be |
| 38 |
prepended to the next feed data. After all data has been feed to the parser |
| 39 |
.I auparse_flush_feed |
| 40 |
should be called to signal the end of input data and flush any pending parse data through the parsing system. |
| 41 |
|
| 42 |
.SH "RETURN VALUE" |
| 43 |
|
| 44 |
Returns \-1 if an error occurs; otherwise, 0 for success. |
| 45 |
|
| 46 |
.SH "EXAMPLE" |
| 47 |
.nf |
| 48 |
void |
| 49 |
auparse_callback(auparse_state_t *au, auparse_cb_event_t cb_event_type, |
| 50 |
void *user_data) |
| 51 |
{ |
| 52 |
int *event_cnt = (int *)user_data; |
| 53 |
|
| 54 |
if (cb_event_type == AUPARSE_CB_EVENT_READY) { |
| 55 |
if (auparse_first_record(au) <= 0) return; |
| 56 |
printf("event: %d\\n", *event_cnt); |
| 57 |
printf("records:%d\\n", auparse_get_num_records(au)); |
| 58 |
do { |
| 59 |
printf("fields:%d\\n", auparse_get_num_fields(au)); |
| 60 |
printf("type=%d ", auparse_get_type(au)); |
| 61 |
const au_event_t *e = auparse_get_timestamp(au); |
| 62 |
if (e == NULL) return; |
| 63 |
printf("event time: %lu.%u:%lu\\n", |
| 64 |
(long unsigned)e\->sec, e\->milli, e\->serial); |
| 65 |
auparse_first_field(au); |
| 66 |
do { |
| 67 |
printf("%s=%s (%s)\\n", auparse_get_field_name(au), |
| 68 |
auparse_get_field_str(au), |
| 69 |
auparse_interpret_field(au)); |
| 70 |
} while (auparse_next_field(au) > 0); |
| 71 |
printf("\\n"); |
| 72 |
|
| 73 |
} while(auparse_next_record(au) > 0); |
| 74 |
(*event_cnt)++; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
main(int argc, char **argv) |
| 79 |
{ |
| 80 |
char *filename = argv[1]; |
| 81 |
FILE *fp; |
| 82 |
char buf[256]; |
| 83 |
size_t len; |
| 84 |
int *event_cnt = malloc(sizeof(int)); |
| 85 |
|
| 86 |
au = auparse_init(AUSOURCE_FEED, 0); |
| 87 |
auparse_set_eoe_timeout(2); |
| 88 |
|
| 89 |
*event_cnt = 1; |
| 90 |
auparse_add_callback(au, auparse_callback, event_cnt, free); |
| 91 |
|
| 92 |
if ((fp = fopen(filename, "r")) == NULL) { |
| 93 |
fprintf(stderr, "could not open '%s', %s\\n", filename, strerror(errno)); |
| 94 |
return 1; |
| 95 |
} |
| 96 |
|
| 97 |
while ((len = fread(buf, 1, sizeof(buf), fp))) { |
| 98 |
auparse_feed(au, buf, len); |
| 99 |
} |
| 100 |
auparse_flush_feed(au); |
| 101 |
auparse_destroy(au); |
| 102 |
} |
| 103 |
.fi |
| 104 |
|
| 105 |
.SH "SEE ALSO" |
| 106 |
|
| 107 |
.BR auparse_add_callback (3), |
| 108 |
.BR auparse_flush_feed (3), |
| 109 |
.BR auparse_feed_age_events (3), |
| 110 |
.BR auparse_feed_has_data (3), |
| 111 |
.BR auparse_metrics (3) |
| 112 |
|
| 113 |
|
| 114 |
.SH AUTHOR |
| 115 |
John Dennis |