2 * Copyright (C) 2020 Simon Marchi <simon.marchi@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
8 #include <common/sessiond-comm/payload.h>
9 #include <common/sessiond-comm/payload-view.h>
10 #include <common/snapshot.h>
11 #include <lttng/snapshot-internal.h>
12 #include <lttng/snapshot.h>
18 bool lttng_snapshot_output_validate(const struct lttng_snapshot_output
*output
)
24 * It is mandatory to have a ctrl_url. If there is only one output
25 * URL (in the net://, net6:// or file:// form), it will be in this
28 len
= lttng_strnlen(output
->ctrl_url
, sizeof(output
->ctrl_url
));
29 if (len
== 0 || len
>= sizeof(output
->ctrl_url
)) {
33 len
= lttng_strnlen(output
->data_url
, sizeof(output
->data_url
));
34 if (len
>= sizeof(output
->data_url
)) {
38 len
= lttng_strnlen(output
->name
, sizeof(output
->name
));
39 if (len
>= sizeof(output
->name
)) {
50 bool lttng_snapshot_output_is_equal(
51 const struct lttng_snapshot_output
*a
,
52 const struct lttng_snapshot_output
*b
)
59 if (a
->max_size
!= b
->max_size
) {
63 if (strcmp(a
->name
, b
->name
) != 0) {
67 if (strcmp(a
->ctrl_url
, b
->ctrl_url
) != 0) {
71 if (strcmp(a
->data_url
, b
->data_url
) != 0) {
82 * This is essentially the same as `struct lttng_snapshot_output`, but packed.
84 struct lttng_snapshot_output_comm
{
87 char name
[LTTNG_NAME_MAX
];
88 char ctrl_url
[PATH_MAX
];
89 char data_url
[PATH_MAX
];
93 int lttng_snapshot_output_serialize(
94 const struct lttng_snapshot_output
*output
,
95 struct lttng_payload
*payload
)
97 struct lttng_snapshot_output_comm comm
;
100 comm
.id
= output
->id
;
101 comm
.max_size
= output
->max_size
;
103 ret
= lttng_strncpy(comm
.name
, output
->name
, sizeof(comm
.name
));
109 comm
.ctrl_url
, output
->ctrl_url
, sizeof(comm
.ctrl_url
));
115 comm
.data_url
, output
->data_url
, sizeof(comm
.data_url
));
120 ret
= lttng_dynamic_buffer_append(
121 &payload
->buffer
, &comm
, sizeof(comm
));
131 ssize_t
lttng_snapshot_output_create_from_payload(
132 struct lttng_payload_view
*view
,
133 struct lttng_snapshot_output
**output_p
)
135 const struct lttng_snapshot_output_comm
*comm
;
136 struct lttng_snapshot_output
*output
= NULL
;
139 if (view
->buffer
.size
!= sizeof(*comm
)) {
144 output
= lttng_snapshot_output_create();
150 comm
= (typeof(comm
)) view
->buffer
.data
;
152 output
->id
= comm
->id
;
153 output
->max_size
= comm
->max_size
;
155 ret
= lttng_strncpy(output
->name
, comm
->name
, sizeof(output
->name
));
160 ret
= lttng_strncpy(output
->ctrl_url
, comm
->ctrl_url
,
161 sizeof(output
->ctrl_url
));
166 ret
= lttng_strncpy(output
->data_url
, comm
->data_url
,
167 sizeof(output
->data_url
));
177 lttng_snapshot_output_destroy(output
);