diff --git a/include/aws/mqtt/v5/mqtt5_client.h b/include/aws/mqtt/v5/mqtt5_client.h index 70206906..004feca4 100644 --- a/include/aws/mqtt/v5/mqtt5_client.h +++ b/include/aws/mqtt/v5/mqtt5_client.h @@ -89,13 +89,12 @@ enum aws_mqtt5_client_outbound_topic_alias_behavior_type { AWS_MQTT5_COTABT_USER, /** - * Client fails any user-specified topic aliasing and acts on the outbound alias set as an LRU cache. + * Client ignores any user-specified topic aliasing and acts on the outbound alias set as an LRU cache. */ AWS_MQTT5_COTABT_LRU, /** - * Completely disable outbound topic aliasing. Attempting to set a topic alias on a PUBLISH results in - * an error. + * Completely disable outbound topic aliasing. */ AWS_MQTT5_COTABT_DISABLED }; diff --git a/source/v5/mqtt5_encoder.c b/source/v5/mqtt5_encoder.c index b9a3ec56..fe1ab3ab 100644 --- a/source/v5/mqtt5_encoder.c +++ b/source/v5/mqtt5_encoder.c @@ -800,7 +800,25 @@ static int s_aws_mqtt5_encoder_begin_publish(struct aws_mqtt5_encoder *encoder, local_publish_view.topic = outbound_topic; if (outbound_topic_alias != 0) { + AWS_LOGF_DEBUG( + AWS_LS_MQTT5_GENERAL, + "(%p) mqtt5 client encoder - PUBLISH packet using topic alias value %" PRIu16, + (void *)encoder->config.client, + outbound_topic_alias); + if (outbound_topic.len == 0) { + AWS_LOGF_DEBUG( + AWS_LS_MQTT5_GENERAL, + "(%p) mqtt5 client encoder - PUBLISH packet dropping topic field for previously established alias", + (void *)encoder->config.client); + } local_publish_view.topic_alias = &outbound_topic_alias; + } else { + AWS_FATAL_ASSERT(local_publish_view.topic.len > 0); + AWS_LOGF_DEBUG( + AWS_LS_MQTT5_GENERAL, + "(%p) mqtt5 client encoder - PUBLISH packet not using a topic alias", + (void *)encoder->config.client); + local_publish_view.topic_alias = NULL; } } diff --git a/source/v5/mqtt5_options_storage.c b/source/v5/mqtt5_options_storage.c index 22888e77..48deee01 100644 --- a/source/v5/mqtt5_options_storage.c +++ b/source/v5/mqtt5_options_storage.c @@ -1743,30 +1743,6 @@ static int s_aws_mqtt5_packet_publish_view_validate_vs_connection_settings( return aws_raise_error(AWS_ERROR_MQTT5_PUBLISH_OPTIONS_VALIDATION); } - if (publish_view->topic_alias != NULL) { - const struct aws_mqtt5_client_options_storage *client_options = client->config; - if (client_options->topic_aliasing_options.outbound_topic_alias_behavior != AWS_MQTT5_COTABT_USER) { - AWS_LOGF_ERROR( - AWS_LS_MQTT5_GENERAL, - "id=%p: aws_mqtt5_packet_publish_view - topic alias set but outbound topic alias behavior has not " - "been set to user controlled", - (void *)publish_view); - return aws_raise_error(AWS_ERROR_MQTT5_PUBLISH_OPTIONS_VALIDATION); - } - - if (*publish_view->topic_alias > settings->topic_alias_maximum_to_server) { - AWS_LOGF_ERROR( - AWS_LS_MQTT5_GENERAL, - "id=%p: aws_mqtt5_packet_publish_view - outbound topic alias (%d) exceeds server's topic alias " - "maximum " - "(%d)", - (void *)publish_view, - (int)(*publish_view->topic_alias), - (int)settings->topic_alias_maximum_to_server); - return aws_raise_error(AWS_ERROR_MQTT5_PUBLISH_OPTIONS_VALIDATION); - } - } - if (publish_view->retain && settings->retain_available == false) { AWS_LOGF_ERROR( AWS_LS_MQTT5_GENERAL, diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 70e6c76a..5cb79f57 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -247,7 +247,6 @@ add_test_case(mqtt5_client_options_validation_failure_invalid_keep_alive) add_test_case(mqtt5_operation_subscribe_connection_settings_validation_failure_exceeds_maximum_packet_size) add_test_case(mqtt5_operation_unsubscribe_connection_settings_validation_failure_exceeds_maximum_packet_size) add_test_case(mqtt5_operation_publish_connection_settings_validation_failure_exceeds_maximum_packet_size) -add_test_case(mqtt5_operation_publish_connection_settings_validation_failure_exceeds_topic_alias_maximum) add_test_case(mqtt5_operation_publish_connection_settings_validation_failure_exceeds_maximum_qos) add_test_case(mqtt5_operation_publish_connection_settings_validation_failure_invalid_retain) add_test_case(mqtt5_operation_disconnect_connection_settings_validation_failure_exceeds_maximum_packet_size) @@ -365,9 +364,7 @@ add_test_case(mqtt5_client_inbound_alias_failure_disabled) add_test_case(mqtt5_client_inbound_alias_failure_zero_id) add_test_case(mqtt5_client_inbound_alias_failure_too_large_id) add_test_case(mqtt5_client_inbound_alias_failure_unbound_id) -add_test_case(mqtt5_client_outbound_alias_disabled_failure_alias_set) add_test_case(mqtt5_client_outbound_alias_user_failure_empty_topic) -add_test_case(mqtt5_client_outbound_alias_lru_failure_alias_set) # a, b, c, r imply notation as the outbound resolver unit tests above add_test_case(mqtt5_client_outbound_alias_user_success_a_b_ar_br) diff --git a/tests/v5/mqtt5_client_tests.c b/tests/v5/mqtt5_client_tests.c index 911b1822..081ec080 100644 --- a/tests/v5/mqtt5_client_tests.c +++ b/tests/v5/mqtt5_client_tests.c @@ -5842,18 +5842,6 @@ static int s_do_mqtt5_client_outbound_alias_failure_test( return AWS_OP_SUCCESS; } -static int s_mqtt5_client_outbound_alias_disabled_failure_alias_set_fn(struct aws_allocator *allocator, void *ctx) { - (void)ctx; - - ASSERT_SUCCESS(s_do_mqtt5_client_outbound_alias_failure_test(allocator, AWS_MQTT5_COTABT_DISABLED)); - - return AWS_OP_SUCCESS; -} - -AWS_TEST_CASE( - mqtt5_client_outbound_alias_disabled_failure_alias_set, - s_mqtt5_client_outbound_alias_disabled_failure_alias_set_fn) - static int s_mqtt5_client_outbound_alias_user_failure_empty_topic_fn(struct aws_allocator *allocator, void *ctx) { (void)ctx; @@ -5866,16 +5854,6 @@ AWS_TEST_CASE( mqtt5_client_outbound_alias_user_failure_empty_topic, s_mqtt5_client_outbound_alias_user_failure_empty_topic_fn) -static int s_mqtt5_client_outbound_alias_lru_failure_alias_set_fn(struct aws_allocator *allocator, void *ctx) { - (void)ctx; - - ASSERT_SUCCESS(s_do_mqtt5_client_outbound_alias_failure_test(allocator, AWS_MQTT5_COTABT_LRU)); - - return AWS_OP_SUCCESS; -} - -AWS_TEST_CASE(mqtt5_client_outbound_alias_lru_failure_alias_set, s_mqtt5_client_outbound_alias_lru_failure_alias_set_fn) - struct outbound_alias_publish { struct aws_byte_cursor topic; uint16_t topic_alias; diff --git a/tests/v5/mqtt5_operation_validation_failure_tests.c b/tests/v5/mqtt5_operation_validation_failure_tests.c index 6ef34c9f..1bb2b814 100644 --- a/tests/v5/mqtt5_operation_validation_failure_tests.c +++ b/tests/v5/mqtt5_operation_validation_failure_tests.c @@ -1271,39 +1271,6 @@ AWS_CONNECTION_SETTINGS_VALIDATION_FAILURE_TEST3( s_packet_size_init_settings_success_fn, s_packet_size_init_settings_failure_fn) -static const uint16_t s_topic_alias = 5; - -static struct aws_mqtt5_packet_publish_view s_exceeds_topic_alias_maximum_publish_view = { - .topic = - { - .ptr = s_good_topic, - .len = AWS_ARRAY_SIZE(s_good_topic) - 1, - }, - .topic_alias = &s_topic_alias, -}; - -static struct aws_mqtt5_client_options_storage s_dummy_client_options; - -static void s_topic_alias_init_settings_success_fn(struct aws_mqtt5_client *dummy_client) { - AWS_ZERO_STRUCT(s_dummy_client_options); - s_dummy_client_options.topic_aliasing_options.outbound_topic_alias_behavior = AWS_MQTT5_COTABT_USER; - - dummy_client->config = &s_dummy_client_options; - dummy_client->negotiated_settings.maximum_packet_size_to_server = 100; - dummy_client->negotiated_settings.topic_alias_maximum_to_server = 10; -} - -static void s_topic_alias_init_settings_failure_fn(struct aws_mqtt5_client *dummy_client) { - dummy_client->negotiated_settings.topic_alias_maximum_to_server = 2; -} - -AWS_CONNECTION_SETTINGS_VALIDATION_FAILURE_TEST3( - publish, - exceeds_topic_alias_maximum, - s_exceeds_topic_alias_maximum_publish_view, - s_topic_alias_init_settings_success_fn, - s_topic_alias_init_settings_failure_fn) - static struct aws_mqtt5_packet_publish_view s_exceeds_maximum_qos_publish_view = { .topic = {