Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore negotiated settings copy #330

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions include/aws/mqtt/v5/mqtt5_client.h
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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