2 * Copyright (C) 2019 - Jonathan Rajotte-Julien
3 * <jonathan.rajotte-julien@efficios.com>
5 * This library is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License, version 2.1 only,
7 * as published by the Free Software Foundation.
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef LTTNG_EVENT_RULE_INTERNAL_H
20 #define LTTNG_EVENT_RULE_INTERNAL_H
22 #include <common/buffer-view.h>
23 #include <common/dynamic-buffer.h>
24 #include <common/macros.h>
25 #include <lttng/event.h>
26 #include <lttng/event-rule/event-rule.h>
27 #include <lttng/lttng-error.h>
30 #include <sys/types.h>
33 typedef void (*event_rule_destroy_cb
)(struct lttng_event_rule
*event_rule
);
34 typedef bool (*event_rule_validate_cb
)(
35 const struct lttng_event_rule
*event_rule
);
36 typedef int (*event_rule_serialize_cb
)(
37 const struct lttng_event_rule
*event_rule
,
38 struct lttng_dynamic_buffer
*buf
,
40 typedef bool (*event_rule_equal_cb
)(const struct lttng_event_rule
*a
,
41 const struct lttng_event_rule
*b
);
42 typedef ssize_t (*event_rule_create_from_buffer_cb
)(
43 const struct lttng_buffer_view
*view
,
44 struct lttng_event_rule
**event_rule
);
45 typedef enum lttng_error_code (*event_rule_populate_cb
)(
46 struct lttng_event_rule
*event_rule
, uid_t uid
, gid_t gid
);
47 typedef const char *(*event_rule_get_filter_cb
)(
48 const struct lttng_event_rule
*event_rule
);
49 typedef const struct lttng_filter_bytecode
*(
50 *event_rule_get_filter_bytecode_cb
)(
51 const struct lttng_event_rule
*event_rule
);
52 typedef struct lttng_event_exclusion
*(*event_rule_generate_exclusions_cb
)(
53 struct lttng_event_rule
*event_rule
);
54 typedef struct lttng_event
*(*event_rule_generate_lttng_event_cb
)(
55 const struct lttng_event_rule
*event_rule
);
57 struct lttng_event_rule
{
59 enum lttng_event_rule_type type
;
60 event_rule_validate_cb validate
;
61 event_rule_serialize_cb serialize
;
62 event_rule_equal_cb equal
;
63 event_rule_destroy_cb destroy
;
64 event_rule_populate_cb populate
;
66 event_rule_get_filter_cb get_filter
;
67 event_rule_get_filter_bytecode_cb get_filter_bytecode
;
68 event_rule_generate_exclusions_cb generate_exclusions
;
69 event_rule_generate_lttng_event_cb generate_lttng_event
;
72 struct lttng_event_rule_comm
{
73 /* enum lttng_event_rule_type */
74 int8_t event_rule_type
;
79 void lttng_event_rule_init(struct lttng_event_rule
*event_rule
,
80 enum lttng_event_rule_type type
);
83 bool lttng_event_rule_validate(const struct lttng_event_rule
*event_rule
);
86 ssize_t
lttng_event_rule_create_from_buffer(
87 const struct lttng_buffer_view
*buffer
,
88 struct lttng_event_rule
**event_rule
);
91 int lttng_event_rule_serialize(const struct lttng_event_rule
*event_rule
,
92 struct lttng_dynamic_buffer
*buf
,
96 bool lttng_event_rule_is_equal(const struct lttng_event_rule
*a
,
97 const struct lttng_event_rule
*b
);
100 bool lttng_event_rule_get(struct lttng_event_rule
*rule
);
103 void lttng_event_rule_put(struct lttng_event_rule
*rule
);
106 enum lttng_domain_type
lttng_event_rule_get_domain_type(
107 const struct lttng_event_rule
*rule
);
110 enum lttng_error_code
lttng_event_rule_populate(
111 struct lttng_event_rule
*rule
, uid_t uid
, gid_t gid
);
113 /* If not present return NULL
114 * Caller DO NOT own the returned object
117 const char *lttng_event_rule_get_filter(const struct lttng_event_rule
*rule
);
119 /* If not present return NULL
120 * Caller DO NOT own the returned object
123 const struct lttng_filter_bytecode
*lttng_event_rule_get_filter_bytecode(
124 const struct lttng_event_rule
*rule
);
127 * If not present return NULL
128 * Caller OWN the returned object
129 * TODO: should this be done another way?
132 struct lttng_event_exclusion
*lttng_event_rule_generate_exclusions(
133 struct lttng_event_rule
*rule
);
136 * This is compatibility helper, allowing us to generate a sessiond side (not
137 * communication) struct lttng_event object. This facilitate integration with
139 * Caller OWN the returned object
142 struct lttng_event
*lttng_event_rule_generate_lttng_event(
143 const struct lttng_event_rule
*rule
);
145 /* Quick helper to test if the event rule apply to an agent domain */
147 bool lttng_event_rule_is_agent(const struct lttng_event_rule
*rule
);
150 const char *lttng_event_rule_type_str(enum lttng_event_rule_type type
);
152 #endif /* LTTNG_EVENT_RULE_INTERNAL_H */