* Copyright 2016-2017 Philippe Proulx <pproulx@efficios.com>
*/
-#include <glib.h>
+#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
-#include <string.h>
-
-#include <babeltrace2/babeltrace.h>
-
-#define BT_COMP_LOG_SELF_COMP self_comp
-#define BT_COMP_LOG_SELF_COMP_CLASS self_comp_class
-#define BT_LOG_OUTPUT_LEVEL log_level
-#define BT_LOG_TAG "PLUGIN/CTF/META/DECODER-DECODE-PACKET"
-#include "logging.hpp"
-#include "logging/comp-logging.h"
#include "common/uuid.h"
#include "compat/memstream.h"
} __attribute__((__packed__));
static int decode_packet(FILE *in_fp, FILE *out_fp, int byte_order, bool *is_uuid_set,
- uint8_t *uuid, bt_logging_level log_level, bt_self_component *self_comp,
- bt_self_component_class *self_comp_class)
+ uint8_t *uuid, const bt2c::Logger& logger)
{
struct packet_header header;
size_t readlen, writelen, toread;
const long offset = ftell(in_fp);
if (offset < 0) {
- BT_COMP_LOGE_APPEND_CAUSE_ERRNO(BT_COMP_LOG_SELF_COMP,
- "Failed to get current metadata file position", ".");
+ BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(logger, "Failed to get current metadata file position",
+ ".");
goto error;
}
- BT_COMP_LOGD("Decoding metadata packet: offset=%ld", offset);
+ BT_CPPLOGD_SPEC(logger, "Decoding metadata packet: offset={}", offset);
readlen = fread(&header, sizeof(header), 1, in_fp);
if (feof(in_fp) != 0) {
- BT_COMP_LOGI("Reached end of file: offset=%ld", ftell(in_fp));
+ BT_CPPLOGI_SPEC(logger, "Reached end of file: offset={}", ftell(in_fp));
goto end;
}
if (readlen < 1) {
- _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot decode metadata packet: offset=%ld",
- offset);
+ BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Cannot decode metadata packet: offset={}", offset);
goto error;
}
}
if (header.compression_scheme) {
- _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
+ BT_CPPLOGE_APPEND_CAUSE_SPEC(
+ logger,
"Metadata packet compression is not supported as of this version: "
- "compression-scheme=%u, offset=%ld",
+ "compression-scheme={}, offset={}",
(unsigned int) header.compression_scheme, offset);
goto error;
}
if (header.encryption_scheme) {
- _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
+ BT_CPPLOGE_APPEND_CAUSE_SPEC(
+ logger,
"Metadata packet encryption is not supported as of this version: "
- "encryption-scheme=%u, offset=%ld",
+ "encryption-scheme={}, offset={}",
(unsigned int) header.encryption_scheme, offset);
goto error;
}
if (header.checksum || header.checksum_scheme) {
- _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
+ auto checksum = header.checksum;
+
+ BT_CPPLOGE_APPEND_CAUSE_SPEC(
+ logger,
"Metadata packet checksum verification is not supported as of this version: "
- "checksum-scheme=%u, checksum=%x, offset=%ld",
- (unsigned int) header.checksum_scheme, header.checksum, offset);
+ "checksum-scheme={}, checksum={}, offset={}",
+ (unsigned int) header.checksum_scheme, checksum, offset);
goto error;
}
if (!ctf_metadata_decoder_is_packet_version_valid(header.major, header.minor)) {
- _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Invalid metadata packet version: "
- "version=%u.%u, offset=%ld",
- header.major, header.minor, offset);
+ BT_CPPLOGE_APPEND_CAUSE_SPEC(logger,
+ "Invalid metadata packet version: "
+ "version={}.{}, offset={}",
+ header.major, header.minor, offset);
goto error;
}
bt_uuid_copy(uuid, header.uuid);
*is_uuid_set = true;
} else if (bt_uuid_compare(header.uuid, uuid)) {
- _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
+ BT_CPPLOGE_APPEND_CAUSE_SPEC(
+ logger,
"Metadata UUID mismatch between packets of the same stream: "
"packet-uuid=\"" BT_UUID_FMT "\", "
"expected-uuid=\"" BT_UUID_FMT "\", "
- "offset=%ld",
+ "offset={}",
BT_UUID_FMT_VALUES(header.uuid), BT_UUID_FMT_VALUES(uuid), offset);
goto error;
}
}
if ((header.content_size / CHAR_BIT) < sizeof(header)) {
- _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
- "Bad metadata packet content size: content-size=%u, "
- "offset=%ld",
- header.content_size, offset);
+ auto content_size = header.content_size;
+
+ BT_CPPLOGE_APPEND_CAUSE_SPEC(logger,
+ "Bad metadata packet content size: content-size={}, "
+ "offset={}",
+ content_size, offset);
goto error;
}
loop_read = MIN(sizeof(buf) - 1, toread);
readlen = fread(buf, sizeof(uint8_t), loop_read, in_fp);
if (ferror(in_fp)) {
- _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot read metadata packet buffer: "
- "offset=%ld, read-size=%zu",
- ftell(in_fp), loop_read);
+ BT_CPPLOGE_APPEND_CAUSE_SPEC(logger,
+ "Cannot read metadata packet buffer: "
+ "offset={}, read-size={}",
+ ftell(in_fp), loop_read);
goto error;
}
if (readlen > loop_read) {
- _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("fread returned more byte than expected: "
- "read-size-asked=%zu, read-size-returned=%zu",
- loop_read, readlen);
+ BT_CPPLOGE_APPEND_CAUSE_SPEC(logger,
+ "fread returned more byte than expected: "
+ "read-size-asked={}, read-size-returned={}",
+ loop_read, readlen);
goto error;
}
writelen = fwrite(buf, sizeof(uint8_t), readlen, out_fp);
if (writelen < readlen || ferror(out_fp)) {
- _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
- "Cannot write decoded metadata text to buffer: "
- "read-offset=%ld, write-size=%zu",
- ftell(in_fp), readlen);
+ BT_CPPLOGE_APPEND_CAUSE_SPEC(logger,
+ "Cannot write decoded metadata text to buffer: "
+ "read-offset={}, write-size={}",
+ ftell(in_fp), readlen);
goto error;
}
toread = (header.packet_size - header.content_size) / CHAR_BIT;
fseek_ret = fseek(in_fp, toread, SEEK_CUR);
if (fseek_ret < 0) {
- BT_COMP_LOGW_STR("Missing padding at the end of the metadata stream.");
+ BT_CPPLOGW_STR_SPEC(logger, "Missing padding at the end of the metadata stream.");
}
break;
}
int ctf_metadata_decoder_packetized_file_stream_to_buf(FILE *fp, char **buf, int byte_order,
bool *is_uuid_set, uint8_t *uuid,
- bt_logging_level log_level,
- bt_self_component *self_comp,
- bt_self_component_class *self_comp_class)
+ const bt2c::Logger& parentLogger)
{
FILE *out_fp;
size_t size;
int ret = 0;
int tret;
size_t packet_index = 0;
+ bt2c::Logger logger {parentLogger, "PLUGIN/CTF/META/DECODER-DECODE-PACKET"};
out_fp = bt_open_memstream(buf, &size);
if (!out_fp) {
- _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot open memory stream: %s.", strerror(errno));
+ BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Cannot open memory stream: {}.", strerror(errno));
goto error;
}
break;
}
- tret = decode_packet(fp, out_fp, byte_order, is_uuid_set, uuid, log_level, self_comp,
- self_comp_class);
+ tret = decode_packet(fp, out_fp, byte_order, is_uuid_set, uuid, logger);
if (tret) {
- _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE("Cannot decode packet: index=%zu",
- packet_index);
+ BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Cannot decode packet: index={}", packet_index);
goto error;
}
/* Make sure the whole string ends with a null character */
tret = fputc('\0', out_fp);
if (tret == EOF) {
- _BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(
- "Cannot append '\\0' to the decoded metadata buffer.");
+ BT_CPPLOGE_APPEND_CAUSE_SPEC(logger, "Cannot append '\\0' to the decoded metadata buffer.");
goto error;
}
*/
out_fp = NULL;
if (ret < 0) {
- BT_COMP_LOGE_APPEND_CAUSE_ERRNO(BT_COMP_LOG_SELF_COMP, "Cannot close memory stream", ".");
+ BT_CPPLOGE_ERRNO_APPEND_CAUSE_SPEC(logger, "Cannot close memory stream", ".");
goto error;
}
if (out_fp) {
if (bt_close_memstream(buf, &size, out_fp)) {
- BT_COMP_LOGE_ERRNO("Cannot close memory stream", ".");
+ BT_CPPLOGE_ERRNO_SPEC(logger, "Cannot close memory stream", ".");
}
}