Skip to content

Commit

Permalink
add amqp_literal_bytes macro
Browse files Browse the repository at this point in the history
  • Loading branch information
vfjpl authored Oct 24, 2024
1 parent 7d12118 commit a391153
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
17 changes: 17 additions & 0 deletions include/rabbitmq-c/amqp.h
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,23 @@ AMQP_EXPORT
void AMQP_CALL amqp_pool_alloc_bytes(amqp_pool_t *pool, size_t amount,
amqp_bytes_t *output);

/**
* Wraps a c string literal in an amqp_bytes_t
*
* Takes a string literal, calculates its length and creates an
* amqp_bytes_t that points to it. The string literal is not duplicated.
*
* For a given input str, The amqp_bytes_t output.bytes is the
* same as str, output.len is the length of the string literal not including
* the \0 terminator
*
* \param [in] str the c string literal to wrap
* \return an amqp_bytes_t that describes the string literal
*
* \since v0.15
*/
#define amqp_literal_bytes(str) (amqp_bytes_t){sizeof(str) - 1, str}

/**
* Wraps a c string in an amqp_bytes_t
*
Expand Down
6 changes: 3 additions & 3 deletions librabbitmq/amqp_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,10 @@ static amqp_bytes_t sasl_method_name(amqp_sasl_method_enum method) {

switch (method) {
case AMQP_SASL_METHOD_PLAIN:
res = amqp_cstring_bytes("PLAIN");
res = amqp_literal_bytes("PLAIN");
break;
case AMQP_SASL_METHOD_EXTERNAL:
res = amqp_cstring_bytes("EXTERNAL");
res = amqp_literal_bytes("EXTERNAL");
break;

default:
Expand Down Expand Up @@ -1332,7 +1332,7 @@ static amqp_rpc_reply_t amqp_login_inner(amqp_connection_state_t state,
s.client_properties = state->client_properties;
s.mechanism = sasl_method_name(sasl_method);
s.response = response_bytes;
s.locale = amqp_cstring_bytes("en_US");
s.locale = amqp_literal_bytes("en_US");

res = amqp_send_method_inner(state, 0, AMQP_CONNECTION_START_OK_METHOD, &s,
AMQP_SF_NONE, deadline);
Expand Down

0 comments on commit a391153

Please sign in to comment.