in source/secure_tunneling.c [512:544]
static int s_init_data_tunnel_pair(
struct data_tunnel_pair *pair,
struct aws_secure_tunnel *secure_tunnel,
const struct aws_byte_cursor *data,
enum aws_iot_st_message_type type) {
struct aws_iot_st_msg message;
message.stream_id = secure_tunnel->stream_id;
message.ignorable = 0;
message.type = type;
if (data != NULL) {
message.payload.buffer = data->ptr;
message.payload.len = data->len;
} else {
message.payload.buffer = NULL;
message.payload.len = 0;
}
pair->secure_tunnel = secure_tunnel;
pair->length_prefix_written = false;
if (aws_iot_st_msg_serialize_from_struct(&pair->buf, secure_tunnel->alloc, message) != AWS_OP_SUCCESS) {
AWS_LOGF_ERROR(AWS_LS_IOTDEVICE_SECURE_TUNNELING, "Failure serializing message");
goto cleanup;
}
if (pair->buf.len > AWS_IOT_ST_MAX_MESSAGE_SIZE) {
AWS_LOGF_ERROR(AWS_LS_IOTDEVICE_SECURE_TUNNELING, "Message size greater than AWS_IOT_ST_MAX_MESSAGE_SIZE");
goto cleanup;
}
pair->cur = aws_byte_cursor_from_buf(&pair->buf);
return AWS_OP_SUCCESS;
cleanup:
aws_byte_buf_clean_up(&pair->buf);
aws_mem_release(pair->secure_tunnel->alloc, (void *)pair);
return AWS_OP_ERR;
}