2 * Copyright (C) 2018 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License, version 2.1 only,
6 * as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 #include <lttng/location-internal.h>
19 #include <common/macros.h>
23 struct lttng_trace_archive_location
*lttng_trace_archive_location_create(
24 enum lttng_trace_archive_location_type type
)
26 struct lttng_trace_archive_location
*location
;
28 location
= zmalloc(sizeof(*location
));
33 location
->type
= type
;
39 void lttng_trace_archive_location_destroy(
40 struct lttng_trace_archive_location
*location
)
46 switch (location
->type
) {
47 case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_LOCAL
:
48 free(location
->types
.local
.absolute_path
);
50 case LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY
:
51 free(location
->types
.relay
.host
);
52 free(location
->types
.relay
.relative_path
);
62 struct lttng_trace_archive_location
*lttng_trace_archive_location_local_create(
63 const char *absolute_path
)
65 struct lttng_trace_archive_location
*location
= NULL
;
71 location
= lttng_trace_archive_location_create(
72 LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_LOCAL
);
77 location
->types
.local
.absolute_path
= strdup(absolute_path
);
78 if (!location
->types
.local
.absolute_path
) {
85 lttng_trace_archive_location_destroy(location
);
90 struct lttng_trace_archive_location
*lttng_trace_archive_location_relay_create(
92 enum lttng_trace_archive_location_relay_protocol_type protocol
,
93 uint16_t control_port
, uint16_t data_port
,
94 const char *relative_path
)
96 struct lttng_trace_archive_location
*location
= NULL
;
98 if (!host
|| !relative_path
) {
102 location
= lttng_trace_archive_location_create(
103 LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY
);
108 location
->types
.relay
.host
= strdup(host
);
109 if (!location
->types
.relay
.host
) {
112 location
->types
.relay
.relative_path
= strdup(relative_path
);
113 if (!location
->types
.relay
.relative_path
) {
117 location
->types
.relay
.protocol
= protocol
;
118 location
->types
.relay
.ports
.control
= control_port
;
119 location
->types
.relay
.ports
.data
= data_port
;
123 lttng_trace_archive_location_destroy(location
);
127 enum lttng_trace_archive_location_type
lttng_trace_archive_location_get_type(
128 const struct lttng_trace_archive_location
*location
)
130 enum lttng_trace_archive_location_type type
;
133 type
= LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_UNKNOWN
;
137 type
= location
->type
;
142 enum lttng_trace_archive_location_status
143 lttng_trace_archive_location_local_get_absolute_path(
144 const struct lttng_trace_archive_location
*location
,
145 const char **absolute_path
)
147 enum lttng_trace_archive_location_status status
=
148 LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
;
150 if (!location
|| !absolute_path
||
151 location
->type
!= LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_LOCAL
) {
152 status
= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_INVALID
;
156 *absolute_path
= location
->types
.local
.absolute_path
;
161 enum lttng_trace_archive_location_status
162 lttng_trace_archive_location_relay_get_host(
163 const struct lttng_trace_archive_location
*location
,
164 const char **relay_host
)
166 enum lttng_trace_archive_location_status status
=
167 LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
;
169 if (!location
|| !relay_host
||
170 location
->type
!= LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY
) {
171 status
= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_INVALID
;
175 *relay_host
= location
->types
.relay
.host
;
180 enum lttng_trace_archive_location_status
181 lttng_trace_archive_location_relay_get_relative_path(
182 const struct lttng_trace_archive_location
*location
,
183 const char **relative_path
)
185 enum lttng_trace_archive_location_status status
=
186 LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
;
188 if (!location
|| !relative_path
||
189 location
->type
!= LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY
) {
190 status
= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_INVALID
;
194 *relative_path
= location
->types
.relay
.relative_path
;
199 enum lttng_trace_archive_location_status
200 lttng_trace_archive_location_relay_get_control_port(
201 const struct lttng_trace_archive_location
*location
,
202 uint16_t *control_port
)
204 enum lttng_trace_archive_location_status status
=
205 LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
;
207 if (!location
|| !control_port
||
208 location
->type
!= LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY
) {
209 status
= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_INVALID
;
213 *control_port
= location
->types
.relay
.ports
.control
;
218 enum lttng_trace_archive_location_status
219 lttng_trace_archive_location_relay_get_data_port(
220 const struct lttng_trace_archive_location
*location
,
223 enum lttng_trace_archive_location_status status
=
224 LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
;
226 if (!location
|| !data_port
||
227 location
->type
!= LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY
) {
228 status
= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_INVALID
;
232 *data_port
= location
->types
.relay
.ports
.data
;
237 enum lttng_trace_archive_location_status
238 lttng_trace_archive_location_relay_get_protocol_type(
239 const struct lttng_trace_archive_location
*location
,
240 enum lttng_trace_archive_location_relay_protocol_type
*protocol
)
242 enum lttng_trace_archive_location_status status
=
243 LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_OK
;
245 if (!location
|| !protocol
||
246 location
->type
!= LTTNG_TRACE_ARCHIVE_LOCATION_TYPE_RELAY
) {
247 status
= LTTNG_TRACE_ARCHIVE_LOCATION_STATUS_INVALID
;
251 *protocol
= location
->types
.relay
.protocol
;