Skip to content

Commit

Permalink
Restore negotiated settings copy (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiazhvera committed Oct 12, 2023
1 parent 7c467e4 commit 0cc50d1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
14 changes: 14 additions & 0 deletions include/aws/mqtt/v5/mqtt5_client.h
Expand Up @@ -787,6 +787,20 @@ AWS_MQTT_API int aws_mqtt5_negotiated_settings_init(
struct aws_mqtt5_negotiated_settings *negotiated_settings,
const struct aws_byte_cursor *client_id);

/**
* Makes an owning copy of a negotiated settings structure.
*
* @param source settings to copy from
* @param dest settings to copy into. Must be in a zeroed or initialized state because it gets clean up
* called on it as the first step of the copy process.
* @return success/failure
*
* Used in downstream.
*/
AWS_MQTT_API int aws_mqtt5_negotiated_settings_copy(
const struct aws_mqtt5_negotiated_settings *source,
struct aws_mqtt5_negotiated_settings *dest);

/**
* Clean up owned memory in negotiated_settings
*
Expand Down
18 changes: 18 additions & 0 deletions source/v5/mqtt5_utils.c
Expand Up @@ -123,6 +123,24 @@ int aws_mqtt5_negotiated_settings_init(
return AWS_OP_SUCCESS;
}

int aws_mqtt5_negotiated_settings_copy(
const struct aws_mqtt5_negotiated_settings *source,
struct aws_mqtt5_negotiated_settings *dest) {
aws_mqtt5_negotiated_settings_clean_up(dest);

*dest = *source;
AWS_ZERO_STRUCT(dest->client_id_storage);

if (source->client_id_storage.allocator != NULL) {
return aws_byte_buf_init_copy_from_cursor(
&dest->client_id_storage,
source->client_id_storage.allocator,
aws_byte_cursor_from_buf(&source->client_id_storage));
}

return AWS_OP_SUCCESS;
}

int aws_mqtt5_negotiated_settings_apply_client_id(
struct aws_mqtt5_negotiated_settings *negotiated_settings,
const struct aws_byte_cursor *client_id) {
Expand Down

0 comments on commit 0cc50d1

Please sign in to comment.