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

link desired capabilities support #361

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions inc/azure_uamqp_c/link.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
65 changes: 65 additions & 0 deletions src/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (link == NULL)

There should probably be a check for desired_capabilities here also.

{
LogError("NULL link");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rror("NULL link");

Consider logging desired_capabilities also.

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;
Expand Down