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

Adding MQTTv5 Properties (Publish) #2613

Merged
merged 5 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
327 changes: 17 additions & 310 deletions sdk/inc/azure/core/az_mqtt5.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <azure/core/az_config.h>
#include <azure/core/az_event.h>
#include <azure/core/az_log.h>
#include <azure/core/az_mqtt5_property_bag.h>
#include <azure/core/az_result.h>
#include <azure/core/az_span.h>
#include <stdbool.h>
Expand All @@ -49,18 +50,6 @@

#include <azure/core/_az_cfg_prefix.h>

/**
* @brief Defines the key storage types.
*/
typedef enum
{
/// The key is stored in memory.
AZ_MQTT5_X509_CLIENT_CERTIFICATE_KEY_MEMORY = 0,

/// The key is stored in a security module.
AZ_MQTT5_X509_CLIENT_CERTIFICATE_KEY_SECURITY_MODULE = 1,
} az_mqtt5_x509_client_certificate_key_type;

/**
* @brief x509 certificate definition.
*/
Expand Down Expand Up @@ -149,6 +138,11 @@ typedef struct
*/
typedef struct
{
/**
* @brief The puback properties.
*/
az_mqtt5_property_bag* properties;

/**
* @brief The publish request ID.
*/
Expand Down Expand Up @@ -187,6 +181,11 @@ typedef struct
*/
typedef struct
{
/**
* @brief The suback properties.
*/
az_mqtt5_property_bag* properties;

/**
* @brief The subscribe request ID.
*/
Expand Down Expand Up @@ -241,6 +240,12 @@ typedef struct
*/
typedef struct
{

/**
* @brief The properties of the connect acknowledgement.
*/
az_mqtt5_property_bag* properties;

/**
* @brief Connection acknowledgement reason code. Indicates success or reason for failure.
*/
Expand Down Expand Up @@ -269,95 +274,6 @@ typedef struct
bool disconnect_requested;
} az_mqtt5_disconnect_data;

/**
* @brief MQTT 5 property string.
*/
typedef struct
{
/**
* @brief The string value of the property.
*/
az_span str;
} az_mqtt5_property_string;

/**
* @brief Gets the string value of an MQTT 5 property string.
*
* @param[in] prop_str The MQTT 5 property string.
*
* @return The string value of the property.
*/
AZ_NODISCARD AZ_INLINE az_span az_mqtt5_property_string_get(az_mqtt5_property_string* prop_str)
{
return prop_str->str;
}

/**
* @brief MQTT 5 property string pair.
*/
typedef struct
{
/**
* @brief The key of the property.
*/
az_span key;

/**
* @brief The value of the property.
*/
az_span value;
} az_mqtt5_property_stringpair;

/**
* @brief Gets the key of an MQTT 5 property string pair.
*
* @param[in] prop_strpair The MQTT 5 property string pair.
*
* @return The key of the property.
*/
AZ_NODISCARD AZ_INLINE az_span
az_mqtt5_property_stringpair_key_get(az_mqtt5_property_stringpair* prop_strpair)
{
return prop_strpair->key;
}

/**
* @brief Gets the value of an MQTT 5 property string pair.
*
* @param[in] prop_strpair The MQTT 5 property string pair.
*
* @return The value of the property.
*/
AZ_NODISCARD AZ_INLINE az_span
az_mqtt5_property_stringpair_value_get(az_mqtt5_property_stringpair* prop_strpair)
{
return prop_strpair->value;
}

/**
* @brief MQTT 5 property binary data.
*/
typedef struct
{
/**
* @brief The binary data value of the property.
*/
az_span bindata;
} az_mqtt5_property_binary_data;

/**
* @brief Gets the binary data value of an MQTT 5 property binary data.
*
* @param[in] prop_bindata The MQTT 5 property binary data.
*
* @return The binary data value of the property.
*/
AZ_NODISCARD AZ_INLINE az_span
az_mqtt5_property_binary_data_get(az_mqtt5_property_binary_data* prop_bindata)
{
return prop_bindata->bindata;
}

/**
* @brief Log classifications for MQTT 5.
*
Expand Down Expand Up @@ -402,31 +318,6 @@ enum az_event_type_mqtt5
AZ_MQTT5_EVENT_SUBACK_RSP = _az_MAKE_EVENT(_az_FACILITY_CORE_MQTT5, 18),
};

/**
* @brief MQTT 5 property types.
*
*/
typedef enum
{
/// Payload format indicator property type.
AZ_MQTT5_PROPERTY_TYPE_PAYLOAD_FORMAT_INDICATOR = 1,

/// Message expiry interval property type.
AZ_MQTT5_PROPERTY_TYPE_MESSAGE_EXPIRY_INTERVAL = 2,

/// Content type property type (usually UTF-8 MIME type)
AZ_MQTT5_PROPERTY_TYPE_CONTENT_TYPE = 3,

/// Response topic property type.
AZ_MQTT5_PROPERTY_TYPE_RESPONSE_TOPIC = 8,

/// Correlation data property type.
AZ_MQTT5_PROPERTY_TYPE_CORRELATION_DATA = 9,

/// User property property type.
AZ_MQTT5_PROPERTY_TYPE_USER_PROPERTY = 38,
} az_mqtt5_property_type;

// Porting 1. The following functions must be called by the implementation when data is received:

/**
Expand Down Expand Up @@ -595,190 +486,6 @@ AZ_NODISCARD az_result az_mqtt5_outbound_pub(az_mqtt5* mqtt5, az_mqtt5_pub_data*
*/
AZ_NODISCARD az_result az_mqtt5_outbound_disconnect(az_mqtt5* mqtt5);

/**
* @brief Initializes an MQTT 5 property bag instance.
*
* @param property_bag The MQTT 5 property bag instance.
* @param mqtt5 The MQTT 5 instance.
* @param options The MQTT 5 property bag options.
*
* @return An #az_result value indicating the result of the operation.
*/
AZ_NODISCARD az_result az_mqtt5_property_bag_init(
az_mqtt5_property_bag* property_bag,
az_mqtt5* mqtt5,
az_mqtt5_property_bag_options const* options);

/**
* @brief Returns the default MQTT 5 property bag options.
*
* @return An #az_mqtt5_property_bag_options value.
*/
AZ_NODISCARD az_mqtt5_property_bag_options az_mqtt5_property_bag_options_default();

/**
* @brief Appends an MQTT 5 string property to the property bag.
*
* @param property_bag The MQTT 5 property bag instance.
* @param type The MQTT 5 property type.
* @param prop_str The MQTT 5 string property.
*
* @return An #az_result value indicating the result of the operation.
*/
AZ_NODISCARD az_result az_mqtt5_property_bag_string_append(
az_mqtt5_property_bag* property_bag,
az_mqtt5_property_type type,
az_mqtt5_property_string* prop_str);

/**
* @brief Appends an MQTT 5 string pair property to the property bag.
*
* @param property_bag The MQTT 5 property bag instance.
* @param type The MQTT 5 property type.
* @param prop_strpair The MQTT 5 string pair property.
*
* @return An #az_result value indicating the result of the operation.
*/
AZ_NODISCARD az_result az_mqtt5_property_bag_stringpair_append(
az_mqtt5_property_bag* property_bag,
az_mqtt5_property_type type,
az_mqtt5_property_stringpair* prop_strpair);

/**
* @brief Appends an MQTT 5 byte property to the property bag.
*
* @param property_bag The MQTT 5 property bag instance.
* @param type The MQTT 5 property type.
* @param prop_byte The MQTT 5 byte property.
*
* @return An #az_result value indicating the result of the operation.
*/
AZ_NODISCARD az_result az_mqtt5_property_bag_byte_append(
az_mqtt5_property_bag* property_bag,
az_mqtt5_property_type type,
uint8_t prop_byte);

/**
* @brief Appends an MQTT 5 integer property to the property bag.
*
* @param property_bag The MQTT 5 property bag instance.
* @param type The MQTT 5 property type.
* @param prop_int The MQTT 5 integer property.
*
* @return An #az_result value indicating the result of the operation.
*/
AZ_NODISCARD az_result az_mqtt5_property_bag_int_append(
az_mqtt5_property_bag* property_bag,
az_mqtt5_property_type type,
uint32_t prop_int);

/**
* @brief Appends an MQTT 5 binary data property to the property bag.
*
* @param property_bag The MQTT 5 property bag instance.
* @param type The MQTT 5 property type.
* @param prop_bindata The MQTT 5 binary data property.
*
* @return An #az_result value indicating the result of the operation.
*/
AZ_NODISCARD az_result az_mqtt5_property_bag_binary_append(
az_mqtt5_property_bag* property_bag,
az_mqtt5_property_type type,
az_mqtt5_property_binary_data* prop_bindata);

/**
* @brief Reads an MQTT 5 string property from the property bag.
*
* @param property_bag The MQTT 5 property bag instance.
* @param type The MQTT 5 property type.
* @param out_prop_str The output MQTT 5 string property.
*
* @return An #az_result value indicating the result of the operation.
*/
AZ_NODISCARD az_result az_mqtt5_property_bag_string_read(
az_mqtt5_property_bag* property_bag,
az_mqtt5_property_type type,
az_mqtt5_property_string* out_prop_str);

/**
* @brief Finds an MQTT 5 string pair property in the property bag.
*
* @param property_bag The MQTT 5 property bag instance.
* @param type The MQTT 5 property type.
* @param key The key of the MQTT 5 string pair property.
* @param out_prop_strpair The output MQTT 5 string pair property.
*
* @return An #az_result value indicating the result of the operation.
*/
AZ_NODISCARD az_result az_mqtt5_property_bag_stringpair_find(
az_mqtt5_property_bag* property_bag,
az_mqtt5_property_type type,
az_span key,
az_mqtt5_property_stringpair* out_prop_strpair);

/**
* @brief Reads an MQTT 5 byte property from the property bag.
*
* @param property_bag The MQTT 5 property bag instance.
* @param type The MQTT 5 property type.
* @param out_prop_byte The output MQTT 5 byte property.
*
* @return An #az_result value indicating the result of the operation.
*/
AZ_NODISCARD az_result az_mqtt5_property_bag_byte_read(
az_mqtt5_property_bag* property_bag,
az_mqtt5_property_type type,
uint8_t* out_prop_byte);

/**
* @brief Reads an MQTT 5 integer property from the property bag.
*
* @param property_bag The MQTT 5 property bag instance.
* @param type The MQTT 5 property type.
* @param out_prop_int The output MQTT 5 integer property.
*
* @return An #az_result value indicating the result of the operation.
*/
AZ_NODISCARD az_result az_mqtt5_property_bag_int_read(
az_mqtt5_property_bag* property_bag,
az_mqtt5_property_type type,
uint32_t* out_prop_int);

/**
* @brief Reads an MQTT 5 binary data property from the property bag.
*
* @param property_bag The MQTT 5 property bag instance.
* @param type The MQTT 5 property type.
* @param out_prop_bindata The output MQTT 5 binary data property.
*
* @return An #az_result value indicating the result of the operation.
*/
AZ_NODISCARD az_result az_mqtt5_property_bag_binary_read(
az_mqtt5_property_bag* property_bag,
az_mqtt5_property_type type,
az_mqtt5_property_binary_data* out_prop_bindata);

/**
* @brief Frees an MQTT 5 string property.
*
* @param prop_str The MQTT 5 string property.
*/
void az_mqtt5_property_bag_string_free(az_mqtt5_property_string* prop_str);

/**
* @brief Frees an MQTT 5 string pair property.
*
* @param prop_strpair The MQTT 5 string pair property.
*/
void az_mqtt5_property_bag_stringpair_free(az_mqtt5_property_stringpair* prop_strpair);

/**
* @brief Frees an MQTT 5 binary data property.
*
* @param prop_bindata The MQTT 5 binary data property.
*/
void az_mqtt5_property_bag_binary_free(az_mqtt5_property_binary_data* prop_bindata);

#include <azure/core/_az_cfg_suffix.h>

#endif // _az_MQTT5_H
4 changes: 2 additions & 2 deletions sdk/inc/azure/core/az_mqtt5_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ enum az_event_type_mqtt5_connection
* @brief Event representing a request to open the MQTT 5 connection.
*
*/
AZ_EVENT_MQTT5_CONNECTION_OPEN_REQ = _az_MAKE_EVENT(_az_FACILITY_IOT, 10),
AZ_EVENT_MQTT5_CONNECTION_OPEN_REQ = _az_MAKE_EVENT(_az_FACILITY_CORE_MQTT5, 19),

/**
* @brief Event representing a request to close the MQTT 5 connection.
*
*/
AZ_EVENT_MQTT5_CONNECTION_CLOSE_REQ = _az_MAKE_EVENT(_az_FACILITY_IOT, 11),
AZ_EVENT_MQTT5_CONNECTION_CLOSE_REQ = _az_MAKE_EVENT(_az_FACILITY_CORE_MQTT5, 20),
};

/**
Expand Down
Loading