Commit | Line | Data |
---|---|---|
eb5c4f4e JG |
1 | /* |
2 | * event.c | |
3 | * | |
4 | * Linux Trace Toolkit Control Library | |
5 | * | |
6 | * Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
7 | * | |
8 | * This library is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU Lesser General Public License, version 2.1 only, | |
10 | * as published by the Free Software Foundation. | |
11 | * | |
12 | * This library is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * Lesser General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU Lesser General Public License | |
18 | * along with this library; if not, write to the Free Software Foundation, | |
19 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | */ | |
21 | ||
22 | #define _LGPL_SOURCE | |
23 | #include <lttng/event.h> | |
24 | #include <lttng/lttng-error.h> | |
25 | #include <stddef.h> | |
26 | #include <common/sessiond-comm/sessiond-comm.h> | |
27 | ||
28 | int lttng_event_get_filter_expression(struct lttng_event *event, | |
29 | const char **filter_expression) | |
30 | { | |
31 | int ret = 0; | |
32 | struct lttcomm_event_extended_header *ext_header; | |
33 | ||
34 | if (!event || !filter_expression) { | |
35 | ret = -LTTNG_ERR_INVALID; | |
36 | goto end; | |
37 | } | |
38 | ||
39 | ext_header = event->extended.ptr; | |
40 | ||
41 | if (!ext_header) { | |
42 | /* | |
43 | * This can happen since the lttng_event structure is | |
44 | * used for other tasks where this pointer is never set. | |
45 | */ | |
46 | *filter_expression = NULL; | |
47 | goto end; | |
48 | } | |
49 | ||
50 | if (ext_header->filter_len) { | |
51 | *filter_expression = ((const char *) (ext_header)) + | |
52 | sizeof(*ext_header); | |
53 | } else { | |
54 | *filter_expression = NULL; | |
55 | } | |
56 | ||
57 | end: | |
58 | return ret; | |
59 | } | |
60 | ||
61 | int lttng_event_get_exclusion_name_count(struct lttng_event *event) | |
62 | { | |
63 | int ret; | |
64 | struct lttcomm_event_extended_header *ext_header; | |
65 | ||
66 | if (!event) { | |
67 | ret = -LTTNG_ERR_INVALID; | |
68 | goto end; | |
69 | } | |
70 | ||
71 | ext_header = event->extended.ptr; | |
72 | if (!ext_header) { | |
73 | /* | |
74 | * This can happen since the lttng_event structure is | |
75 | * used for other tasks where this pointer is never set. | |
76 | */ | |
77 | ret = 0; | |
78 | goto end; | |
79 | } | |
80 | ||
81 | if (ext_header->nb_exclusions > INT_MAX) { | |
82 | ret = -LTTNG_ERR_OVERFLOW; | |
83 | goto end; | |
84 | } | |
85 | ret = (int) ext_header->nb_exclusions; | |
86 | end: | |
87 | return ret; | |
88 | } | |
89 | ||
90 | int lttng_event_get_exclusion_name(struct lttng_event *event, | |
91 | size_t index, const char **exclusion_name) | |
92 | { | |
93 | int ret = 0; | |
94 | struct lttcomm_event_extended_header *ext_header; | |
95 | void *at; | |
96 | ||
97 | if (!event || !exclusion_name) { | |
98 | ret = -LTTNG_ERR_INVALID; | |
99 | goto end; | |
100 | } | |
101 | ||
102 | ext_header = event->extended.ptr; | |
103 | if (!ext_header) { | |
104 | ret = -LTTNG_ERR_INVALID; | |
105 | goto end; | |
106 | } | |
107 | ||
108 | if (index >= ext_header->nb_exclusions) { | |
109 | ret = -LTTNG_ERR_INVALID; | |
110 | goto end; | |
111 | } | |
112 | ||
113 | at = (void *) ext_header + sizeof(*ext_header); | |
114 | at += ext_header->filter_len; | |
115 | at += index * LTTNG_SYMBOL_NAME_LEN; | |
116 | *exclusion_name = at; | |
117 | ||
118 | end: | |
119 | return ret; | |
120 | } |