File: events.h

package info (click to toggle)
clamav 0.98.7+dfsg-0+deb6u2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze-lts
  • size: 60,204 kB
  • ctags: 49,129
  • sloc: cpp: 267,090; ansic: 152,211; sh: 35,196; python: 2,630; makefile: 2,220; perl: 1,690; pascal: 1,218; lisp: 184; csh: 117; xml: 38; asm: 32; exp: 4
file content (124 lines) | stat: -rw-r--r-- 3,916 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
 *  (bytecode) events
 *
 *  Copyright (C) 2010-2012 Sourcefire, Inc.
 *
 *  Authors: Török Edvin
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *  MA 02110-1301, USA.
 */

#ifndef EVENTS_H
#define EVENTS_H

#include "cltypes.h"

struct cli_events;
typedef struct cli_events cli_events_t;

cli_events_t *cli_events_new(unsigned max_event);
void cli_events_free(cli_events_t*);

enum ev_type {
    ev_none = 0,
    ev_string,
    ev_data,
    ev_data_fast,/* checksum, and length */
    ev_int,
    ev_time/* implicit time measurement */
};

enum multiple_handling {
    multiple_last,/* keep only last */
    multiple_chain,/* chain them */
    multiple_sum,/* sum, only for ev_int and ev_time */
    multiple_concat
};

union ev_val {
    const char *v_string;
    void *v_data;
    uint64_t v_int;
    union ev_val *v_chain;
};

/* Defines a new event with the given id, name, type. If event is triggered
 * multiple times then it is handled according to the event type. */
int cli_event_define(cli_events_t *ctx, unsigned id,
		     const char *name, enum ev_type type,
		     enum multiple_handling multiple);

/* error events */
void cli_event_error_str(cli_events_t *ctx, const char *str);
void cli_event_error_oom(cli_events_t *ctx, uint32_t amount);

/* record a data event */
void cli_event_int(cli_events_t *ctx, unsigned id, uint64_t arg);
/* for strings live at _diff_all, usually constant strings */
void cli_event_string(cli_events_t *ctx, unsigned id, const char *str);
/* for random data, alloced and copied */
void cli_event_data(cli_events_t *ctx, unsigned id, const void* data, uint32_t len);
/* don't record data, just a checksum and size */
void cli_event_fastdata(cli_events_t *ctx, unsigned id, const void *data, uint32_t len);

void cli_event_time_start(cli_events_t *ctx, unsigned id);
void cli_event_time_stop(cli_events_t *ctx, unsigned id);
void cli_event_time_nested_start(cli_events_t *ctx, unsigned id, unsigned nestedid);
void cli_event_time_nested_stop(cli_events_t *ctx, unsigned id, unsigned nestedid);

/* event_count is implemented as ev_int, with ev_multiple_sum multiple */
void cli_event_count(cli_events_t *ctx, unsigned id);

void cli_event_get(cli_events_t* ctx, unsigned id, union ev_val *val, uint32_t *count);

const char * cli_event_get_name(cli_events_t* ctx, unsigned id);

/* print all recorded events */
void cli_event_debug_all(cli_events_t *ctx);

/* print specified recorded event */
void cli_event_debug(cli_events_t *ctx, unsigned id);

/* compare 2 events, print diff to debug, and return 0 on equal, 1 on
 * different  */
int cli_event_diff(cli_events_t *ctx1, cli_events_t *ctx2, unsigned id);

/* compare all events, with the specified filter (time events are always
 * ignored), and return 0 for equal, 1 for different */
typedef int (*compare_filter_t)(unsigned id, enum ev_type type);
int cli_event_diff_all(cli_events_t *ctx1, cli_events_t *ctx2, compare_filter_t filter);

/* returns whether the given context had errors */
int cli_event_errors(cli_events_t *ctx);

enum perfev {
    PERFT_SCAN,
    PERFT_PRECB,
    PERFT_POSTCB,
    PERFT_CACHE,
    PERFT_FT,
    PERFT_CONTAINER,
    PERFT_SCRIPT,
    PERFT_PE,
    PERFT_RAW,
    PERFT_RAWTYPENO,
    PERFT_MAP,
    PERFT_BYTECODE,
    PERFT_KTIME,
    PERFT_UTIME,
    PERFT_LAST
};

#endif