| 1 | /** |
| 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | * SPDX-License-Identifier: Apache-2.0. |
| 4 | */ |
| 5 | |
| 6 | #ifndef AWS_MQTT_IOT_METRICS_H |
| 7 | #define AWS_MQTT_IOT_METRICS_H |
| 8 | |
| 9 | #include <aws/mqtt/mqtt.h> |
| 10 | |
| 11 | /* Storage for `aws_mqtt_iot_metrics`. */ |
| 12 | struct aws_mqtt_iot_metrics_storage { |
| 13 | struct aws_allocator *allocator; |
| 14 | |
| 15 | struct aws_mqtt_iot_metrics storage_view; |
| 16 | |
| 17 | struct aws_byte_cursor library_name; |
| 18 | |
| 19 | struct aws_array_list metadata_entries; |
| 20 | |
| 21 | struct aws_byte_buf storage; |
| 22 | }; |
| 23 | |
| 24 | AWS_MQTT_API struct aws_mqtt_iot_metrics_storage *aws_mqtt_iot_metrics_storage_new( |
| 25 | struct aws_allocator *allocator, |
| 26 | const struct aws_mqtt_iot_metrics *metrics_options); |
| 27 | |
| 28 | AWS_MQTT_API void aws_mqtt_iot_metrics_storage_destroy(struct aws_mqtt_iot_metrics_storage *metrics_storage); |
| 29 | |
| 30 | /** |
| 31 | * Builds a new username by appending SDK metrics to the original username. |
| 32 | * |
| 33 | * @param allocator The allocator to use for memory allocation |
| 34 | * @param original_username The original username |
| 35 | * @param metrics The metrics configuration |
| 36 | * @param output_username Buffer that will be initialized and populated with the new final username. The function |
| 37 | * expects this buffer to be uninitialized. On success, the caller is responsible for cleaning up the buffer. |
| 38 | * @param out_full_username_size If not NULL, will be set to the full size of the final username |
| 39 | * |
| 40 | * @return AWS_OP_SUCCESS on success, AWS_OP_ERR on failure |
| 41 | */ |
| 42 | AWS_MQTT_API |
| 43 | int aws_mqtt_append_sdk_metrics_to_username( |
| 44 | struct aws_allocator *allocator, |
| 45 | const struct aws_byte_cursor *original_username, |
| 46 | const struct aws_mqtt_iot_metrics *metrics, |
| 47 | struct aws_byte_buf *output_username, |
| 48 | size_t *out_full_username_size); |
| 49 | |
| 50 | /** |
| 51 | * Validates all string fields in aws_mqtt_iot_metrics |
| 52 | * |
| 53 | * @param metrics The metrics structure to validate |
| 54 | * @return AWS_OP_SUCCESS if metrics is not null and all metrics value are valid, AWS_OP_ERR otherwise |
| 55 | */ |
| 56 | AWS_MQTT_API |
| 57 | int aws_mqtt_validate_iot_metrics(const struct aws_mqtt_iot_metrics *metrics); |
| 58 | |
| 59 | /** |
| 60 | * Checks if username should be included in the CONNECT packet. |
| 61 | * Returns true if either username is provided or metrics are configured. |
| 62 | * |
| 63 | * @param username The username cursor (can be NULL) |
| 64 | * @param metrics_storage The metrics storage (can be NULL) |
| 65 | * @return true if username should be included, false otherwise |
| 66 | */ |
| 67 | AWS_MQTT_API |
| 68 | bool aws_mqtt_has_non_empty_username( |
| 69 | const struct aws_byte_cursor *username, |
| 70 | const struct aws_mqtt_iot_metrics_storage *metrics_storage); |
| 71 | |
| 72 | #endif /* AWS_MQTT_IOT_METRICS_H */ |