diff --git a/inc/azure_uamqp_c/link.h b/inc/azure_uamqp_c/link.h index 4037fb98..2724a6e0 100644 --- a/inc/azure_uamqp_c/link.h +++ b/inc/azure_uamqp_c/link.h @@ -67,6 +67,8 @@ MOCKABLE_FUNCTION(, int, link_set_max_message_size, LINK_HANDLE, link, uint64_t, MOCKABLE_FUNCTION(, int, link_get_max_message_size, LINK_HANDLE, link, uint64_t*, max_message_size); MOCKABLE_FUNCTION(, int, link_get_peer_max_message_size, LINK_HANDLE, link, uint64_t*, peer_max_message_size); MOCKABLE_FUNCTION(, int, link_set_attach_properties, LINK_HANDLE, link, fields, attach_properties); +MOCKABLE_FUNCTION(, int, link_set_desired_capabilities, LINK_HANDLE, link, AMQP_VALUE, desired_capabilities); +MOCKABLE_FUNCTION(, int, link_get_desired_capabilities, LINK_HANDLE, link, AMQP_VALUE*, desired_capabilities); MOCKABLE_FUNCTION(, int, link_set_max_link_credit, LINK_HANDLE, link, uint32_t, max_link_credit); MOCKABLE_FUNCTION(, int, link_get_name, LINK_HANDLE, link, const char**, link_name); MOCKABLE_FUNCTION(, int, link_get_received_message_id, LINK_HANDLE, link, delivery_number*, message_id); diff --git a/src/link.c b/src/link.c index 95b24fd0..b63999cc 100644 --- a/src/link.c +++ b/src/link.c @@ -61,6 +61,7 @@ typedef struct LINK_INSTANCE_TAG uint32_t max_link_credit; uint32_t available; fields attach_properties; + AMQP_VALUE desired_capabilities; bool is_underlying_session_begun; bool is_closed; unsigned char* received_payload; @@ -279,6 +280,15 @@ static int send_attach(LINK_INSTANCE* link, const char* name, handle handle, rol (void)attach_set_properties(attach, link->attach_properties); } + if (link->desired_capabilities != NULL) + { + if(attach_set_desired_capabilities(attach, link->desired_capabilities) != 0) + { + LogError("Cannot set attach desired capabilities"); + result = MU_FAILURE; + } + } + if (role == role_sender) { if (attach_set_initial_delivery_count(attach, link->delivery_count) != 0) @@ -741,6 +751,7 @@ LINK_HANDLE link_create(SESSION_HANDLE session, const char* name, role role, AMQ result->is_underlying_session_begun = false; result->is_closed = false; result->attach_properties = NULL; + result->desired_capabilities = NULL; result->received_payload = NULL; result->received_payload_size = 0; result->received_delivery_id = 0; @@ -830,6 +841,7 @@ LINK_HANDLE link_create_from_endpoint(SESSION_HANDLE session, LINK_ENDPOINT_HAND result->is_underlying_session_begun = false; result->is_closed = false; result->attach_properties = NULL; + result->desired_capabilities = NULL; result->received_payload = NULL; result->received_payload_size = 0; result->received_delivery_id = 0; @@ -1108,6 +1120,59 @@ int link_get_peer_max_message_size(LINK_HANDLE link, uint64_t* peer_max_message_ return result; } +int link_get_desired_capabilities(LINK_HANDLE link, AMQP_VALUE* desired_capabilities) +{ + int result; + if((link == NULL) || + (desired_capabilities == NULL)) + { + LogError("Bad arguments: link = %p, desired_capabilities = %p", + link, desired_capabilities); + result = MU_FAILURE; + } + else + { + AMQP_VALUE link_desired_capabilties = amqpvalue_clone(link->desired_capabilities); + if(link_desired_capabilties == NULL) + { + LogError("Failed to clone link desired capabilities"); + result = MU_FAILURE; + } + else + { + *desired_capabilities = link_desired_capabilties; + result = 0; + } + } + return result; +} + +int link_set_desired_capabilities(LINK_HANDLE link, AMQP_VALUE desired_capabilities) +{ + int result; + + if (link == NULL) + { + LogError("NULL link"); + result = MU_FAILURE; + } + else + { + link->desired_capabilities = amqpvalue_clone(desired_capabilities); + if (link->desired_capabilities == NULL) + { + LogError("Failed cloning desired capabilities"); + result = MU_FAILURE; + } + else + { + result = 0; + } + } + + return result; +} + int link_set_attach_properties(LINK_HANDLE link, fields attach_properties) { int result;