Skip to content

Commit

Permalink
rabbitmq: clang-format for coherent indentation and coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxmaniac committed May 18, 2023
1 parent 08b5cbc commit cf19782
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 48 deletions.
89 changes: 43 additions & 46 deletions src/modules/rabbitmq/rabbitmq.c
Expand Up @@ -116,34 +116,30 @@ static int rbmq_fixup_free_params(void **param, int param_no)

/* module commands */
static cmd_export_t cmds[] = {
{"rabbitmq_publish", (cmd_function)rabbitmq_publish, 4, fixup_spve_all,
fixup_free_spve_all, REQUEST_ROUTE},
{"rabbitmq_publish_consume", (cmd_function)rabbitmq_publish_consume, 5,
rbmq_fixup_params, rbmq_fixup_free_params, REQUEST_ROUTE},
{0, 0, 0, 0, 0, 0}
};
{"rabbitmq_publish", (cmd_function)rabbitmq_publish, 4, fixup_spve_all,
fixup_free_spve_all, REQUEST_ROUTE},
{"rabbitmq_publish_consume", (cmd_function)rabbitmq_publish_consume, 5,
rbmq_fixup_params, rbmq_fixup_free_params, REQUEST_ROUTE},
{0, 0, 0, 0, 0, 0}};

/* module parameters */
static param_export_t params[] = {
{"url", PARAM_STRING, &amqp_url},
{"timeout_sec", PARAM_INT, &timeout_sec},
{"timeout_usec", PARAM_INT, &timeout_usec},
{"direct_reply_to", PARAM_INT, &direct_reply_to},
{0, 0, 0}
};
static param_export_t params[] = {{"url", PARAM_STRING, &amqp_url},
{"timeout_sec", PARAM_INT, &timeout_sec},
{"timeout_usec", PARAM_INT, &timeout_usec},
{"direct_reply_to", PARAM_INT, &direct_reply_to}, {0, 0, 0}};

/* module exports */
struct module_exports exports = {
"rabbitmq", /* module name */
DEFAULT_DLFLAGS, /* dlopen flags */
cmds, /* exported functions */
params, /* exported parameters */
0, /* RPC method exports */
0, /* exported pseudo-variables */
0, /* response handling function */
mod_init, /* module initialization function */
mod_child_init, /* per-child init function */
0 /* module destroy function */
"rabbitmq", /* module name */
DEFAULT_DLFLAGS, /* dlopen flags */
cmds, /* exported functions */
params, /* exported parameters */
0, /* RPC method exports */
0, /* exported pseudo-variables */
0, /* response handling function */
mod_init, /* module initialization function */
mod_child_init, /* per-child init function */
0 /* module destroy function */
};

/* module init */
Expand Down Expand Up @@ -180,16 +176,16 @@ static int mod_child_init(int rank)

/* module helper functions */
static int ki_rabbitmq_publish(sip_msg_t *msg, str *exchange, str *routingkey,
str *contenttype, str *messagebody)
str *contenttype, str *messagebody)
{
int reconnect_attempts = 0;
int log_ret;

reconnect:
// open channel
amqp_channel_open(amqp_conn, 1);
log_ret =
log_on_amqp_error(amqp_get_rpc_reply(amqp_conn), "amqp_channel_open()");
log_ret = log_on_amqp_error(
amqp_get_rpc_reply(amqp_conn), "amqp_channel_open()");

// open channel - failed
if(log_ret != AMQP_RESPONSE_NORMAL) {
Expand Down Expand Up @@ -228,9 +224,10 @@ static int ki_rabbitmq_publish(sip_msg_t *msg, str *exchange, str *routingkey,
props.correlation_id = amqp_cstring_bytes("1");

// publish
if(log_on_error(amqp_basic_publish(amqp_conn, 1, amqp_cstring_bytes(exchange->s),
amqp_cstring_bytes(routingkey->s), 0, 0, &props,
amqp_cstring_bytes(messagebody->s)),
if(log_on_error(
amqp_basic_publish(amqp_conn, 1, amqp_cstring_bytes(exchange->s),
amqp_cstring_bytes(routingkey->s), 0, 0, &props,
amqp_cstring_bytes(messagebody->s)),
"amqp_basic_publish()")
!= AMQP_RESPONSE_NORMAL) {
// debug
Expand Down Expand Up @@ -282,13 +279,12 @@ static int rabbitmq_publish(struct sip_msg *msg, char *in_exchange,
return -1;
}

return ki_rabbitmq_publish(msg, &exchange, &routingkey, &contenttype,
&messagebody);
return ki_rabbitmq_publish(
msg, &exchange, &routingkey, &contenttype, &messagebody);
}

static int rabbitmq_publish_consume_helper(sip_msg_t *msg, str *exchange,
str *routingkey, str *contenttype, str *messagebody,
pv_spec_t *dst)
str *routingkey, str *contenttype, str *messagebody, pv_spec_t *dst)
{
pv_value_t val;
amqp_frame_t frame;
Expand All @@ -313,8 +309,8 @@ static int rabbitmq_publish_consume_helper(sip_msg_t *msg, str *exchange,
reconnect:
// open channel
amqp_channel_open(amqp_conn, 1);
log_ret =
log_on_amqp_error(amqp_get_rpc_reply(amqp_conn), "amqp_channel_open()");
log_ret = log_on_amqp_error(
amqp_get_rpc_reply(amqp_conn), "amqp_channel_open()");

// open channel - failed
if(log_ret != AMQP_RESPONSE_NORMAL) {
Expand Down Expand Up @@ -356,9 +352,9 @@ static int rabbitmq_publish_consume_helper(sip_msg_t *msg, str *exchange,
strcpy(reply_to_buffer, "kamailio-");
strcat(reply_to_buffer, uuid_buffer);

reply_to =
amqp_queue_declare(amqp_conn, 1, amqp_cstring_bytes(reply_to_buffer),
0, 0, 1, 1, amqp_empty_table);
reply_to = amqp_queue_declare(amqp_conn, 1,
amqp_cstring_bytes(reply_to_buffer), 0, 0, 1, 1,
amqp_empty_table);
}

if(log_on_amqp_error(amqp_get_rpc_reply(amqp_conn), "amqp_queue_declare()")
Expand Down Expand Up @@ -396,9 +392,10 @@ static int rabbitmq_publish_consume_helper(sip_msg_t *msg, str *exchange,
}

// publish
if(log_on_error(amqp_basic_publish(amqp_conn, 1, amqp_cstring_bytes(exchange->s),
amqp_cstring_bytes(routingkey->s), 0, 0, &props,
amqp_cstring_bytes(messagebody->s)),
if(log_on_error(
amqp_basic_publish(amqp_conn, 1, amqp_cstring_bytes(exchange->s),
amqp_cstring_bytes(routingkey->s), 0, 0, &props,
amqp_cstring_bytes(messagebody->s)),
"amqp_basic_publish()")
!= AMQP_RESPONSE_NORMAL) {
LM_ERR("FAIL: amqp_basic_publish()\n");
Expand Down Expand Up @@ -508,7 +505,7 @@ static int ki_rabbitmq_publish_consume(sip_msg_t *msg, str *exchange,

dst = pv_cache_get(dpv);

if(dst==NULL) {
if(dst == NULL) {
LM_ERR("failed getting pv: %.*s\n", dpv->len, dpv->s);
return -1;
}
Expand All @@ -517,8 +514,8 @@ static int ki_rabbitmq_publish_consume(sip_msg_t *msg, str *exchange,
return -1;
}

return rabbitmq_publish_consume_helper(msg, exchange, routingkey,
contenttype, messagebody, dst);
return rabbitmq_publish_consume_helper(
msg, exchange, routingkey, contenttype, messagebody, dst);
}

static int rabbitmq_publish_consume(struct sip_msg *msg, char *in_exchange,
Expand Down Expand Up @@ -551,8 +548,8 @@ static int rabbitmq_publish_consume(struct sip_msg *msg, char *in_exchange,

dst = (pv_spec_t *)reply;

return rabbitmq_publish_consume_helper(msg, &exchange, &routingkey,
&contenttype, &messagebody, dst);
return rabbitmq_publish_consume_helper(
msg, &exchange, &routingkey, &contenttype, &messagebody, dst);
}

static int rabbitmq_connect(amqp_connection_state_t *conn)
Expand Down
3 changes: 2 additions & 1 deletion src/modules/rabbitmq/rabbitmq.h
Expand Up @@ -42,7 +42,8 @@

#define RABBITMQ_DEFAULT_AMQP_URL "amqp://guest:guest@localhost:5672/%2F"

typedef enum {
typedef enum
{
RABBITMQ_OK = 1,
RABBITMQ_ERR_CONNECT,
RABBITMQ_ERR_CHANNEL,
Expand Down
3 changes: 2 additions & 1 deletion src/modules/rabbitmq/utils.c
Expand Up @@ -175,7 +175,8 @@ void amqp_dump(void const *buffer, size_t len)
if(rows_eq(oldchs, chs)) {
if(!showed_dots) {
showed_dots = 1;
printf(" .. .. .. .. .. .. .. .. : .. .. "
printf(" .. .. .. .. .. .. .. .. : .. "
".. "
".. .. .. .. .. ..\n");
}
} else {
Expand Down

0 comments on commit cf19782

Please sign in to comment.