~ubuntu-branches/ubuntu/maverick/audit/maverick

« back to all changes in this revision

Viewing changes to docs/auparse_feed.3

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2007-06-29 13:05:14 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070629130514-z798cz4lebiahj5w
Tags: 1.5.4-0ubuntu1
* New upstream version.
* debian/patches/audit-1.5.1-dist.patch:
  * update so that it applies for 1.5.4.
* debian/control:
  * update Maintainer and XSBC-Original-Maintainer fields.
* debian/rules:
  * enable apparmor support: add --with-apparmor to configure options.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
.TH "AUPARSE_FEED" "3" "May 2007" "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
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 "EXAMPLE"
 
43
.nf
 
44
void
 
45
auparse_callback(auparse_state_t *au, auparse_cb_event_t cb_event_type,
 
46
                 void *user_data)
 
47
{
 
48
    int *event_cnt = (int *)user_data;
 
49
 
 
50
    if (cb_event_type == AUPARSE_CB_EVENT_READY) {
 
51
        if (auparse_first_record(au) <= 0) return;
 
52
        printf("event: %d\\n", *event_cnt);
 
53
        printf("records:%d\\n", auparse_get_num_records(au));
 
54
        do {
 
55
            printf("fields:%d\\n", auparse_get_num_fields(au));
 
56
            printf("type=%d ", auparse_get_type(au));
 
57
            const au_event_t *e = auparse_get_timestamp(au);
 
58
            if (e == NULL) return;
 
59
            printf("event time: %u.%u:%lu\\n",
 
60
                    (unsigned)e->sec, e->milli, e->serial);
 
61
            auparse_first_field(au);
 
62
            do {
 
63
                printf("%s=%s (%s)\\n", auparse_get_field_name(au),
 
64
                       auparse_get_field_str(au),
 
65
                       auparse_interpret_field(au));
 
66
            } while (auparse_next_field(au) > 0);
 
67
            printf("\\n");
 
68
 
 
69
        } while(auparse_next_record(au) > 0);
 
70
        (*event_cnt)++;
 
71
    }
 
72
}
 
73
 
 
74
main(int argc, char **argv)
 
75
{       
 
76
    char *filename = argv[1];
 
77
    FILE *fp;
 
78
    char buf[256];
 
79
    size_t len;
 
80
    int *event_cnt = malloc(sizeof(int));
 
81
 
 
82
    au = auparse_init(AUSOURCE_FEED, 0);
 
83
 
 
84
    *event_cnt = 1;
 
85
    auparse_add_callback(au, auparse_callback, event_cnt, free);
 
86
 
 
87
    if ((fp = fopen(filename, "r")) == NULL) {
 
88
        fprintf(stderr, "could not open '%s', %s\n", filename, strerror(errno));
 
89
        return 1;
 
90
    }
 
91
 
 
92
    while ((len = fread(buf, 1, sizeof(buf), fp))) {
 
93
        auparse_feed(au, buf, len);
 
94
    }
 
95
    auparse_flush_feed(au);
 
96
}
 
97
.fi
 
98
 
 
99
.SH "RETURN VALUE"
 
100
 
 
101
Returns -1 if an error occurs; otherwise, 0 for success.
 
102
 
 
103
.SH "SEE ALSO"
 
104
 
 
105
.BR auparse_add_callback (3),
 
106
.BR auparse_flush_feed (3)
 
107
 
 
108
 
 
109
.SH AUTHOR
 
110
John Dennis