Skip to content

Commit

Permalink
dmq: 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 a288219 commit 85783de
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 91 deletions.
69 changes: 34 additions & 35 deletions src/modules/dmq/dmq.c
Expand Up @@ -81,7 +81,7 @@ dmq_node_list_t *dmq_node_list = NULL;
/* dmq module is a peer itself for receiving notifications regarding nodes */
dmq_peer_t *dmq_notification_peer = NULL;
/* add notification servers */
static int dmq_add_notification_address(modparam_t type, void * val);
static int dmq_add_notification_address(modparam_t type, void *val);


/** module functions */
Expand Down Expand Up @@ -160,7 +160,7 @@ static int make_socket_str_from_uri(struct sip_uri *uri, str *socket)
return -1;
}

if(get_valid_proto_string(uri->proto, 0, 0, &sproto)<0) {
if(get_valid_proto_string(uri->proto, 0, 0, &sproto) < 0) {
LM_INFO("unknown transport protocol - fall back to udp\n");
sproto.s = "udp";
sproto.len = 3;
Expand Down Expand Up @@ -230,7 +230,7 @@ static int mod_init(void)
return -1;
}

if(dmq_server_socket.s==NULL || dmq_server_socket.len<=0) {
if(dmq_server_socket.s == NULL || dmq_server_socket.len <= 0) {
/* create socket string out of the server_uri */
if(make_socket_str_from_uri(&dmq_server_uri, &dmq_server_socket) < 0) {
LM_ERR("failed to create socket out of server_uri\n");
Expand Down Expand Up @@ -298,7 +298,7 @@ static int child_init(int rank)

if(rank == PROC_INIT) {
for(i = 0; i < dmq_num_workers; i++) {
if (init_worker(&dmq_workers[i]) < 0) {
if(init_worker(&dmq_workers[i]) < 0) {
LM_ERR("failed to init struct for worker[%d]\n", i);
return -1;
}
Expand All @@ -315,7 +315,8 @@ static int child_init(int rank)
LM_ERR("failed to fork worker process %d\n", i);
return -1;
} else if(newpid == 0) {
if (cfg_child_init()) return -1;
if(cfg_child_init())
return -1;
/* child - this will loop forever */
worker_loop(i);
} else {
Expand All @@ -336,9 +337,9 @@ static int child_init(int rank)
dmq_notification_node =
add_server_and_notify(dmq_notification_address_list);
if(!dmq_notification_node) {
LM_WARN("cannot retrieve initial nodelist, first list entry %.*s\n",
LM_WARN("cannot retrieve initial nodelist, first list entry "
"%.*s\n",
STR_FMT(&dmq_notification_address_list->s));

}
}
}
Expand All @@ -353,7 +354,8 @@ static int child_init(int rank)
static void destroy(void)
{
/* TODO unregister dmq node, free resources */
if(dmq_notification_address_list && dmq_notification_node && dmq_self_node) {
if(dmq_notification_address_list && dmq_notification_node
&& dmq_self_node) {
LM_DBG("unregistering node %.*s\n", STR_FMT(&dmq_self_node->orig_uri));
dmq_self_node->status = DMQ_NODE_DISABLED;
request_nodelist(dmq_notification_node, 1);
Expand All @@ -363,42 +365,44 @@ static void destroy(void)
}
}

static int dmq_add_notification_address(modparam_t type, void * val)
static int dmq_add_notification_address(modparam_t type, void *val)
{
str tmp_str;
int total_list = 0; /* not used */

if(val==NULL) {
if(val == NULL) {
LM_ERR("invalid notification address parameter value\n");
return -1;
}
tmp_str.s = ((str*) val)->s;
tmp_str.len = ((str*) val)->len;
if(parse_uri(tmp_str.s, tmp_str.len, &dmq_notification_uri) < 0) {
tmp_str.s = ((str *)val)->s;
tmp_str.len = ((str *)val)->len;
if(parse_uri(tmp_str.s, tmp_str.len, &dmq_notification_uri) < 0) {
LM_ERR("could not parse notification address\n");
return -1;
}

/* initial allocation */
if (dmq_notification_address_list == NULL) {
if(dmq_notification_address_list == NULL) {
dmq_notification_address_list = pkg_malloc(sizeof(str_list_t));
if (dmq_notification_address_list == NULL) {
if(dmq_notification_address_list == NULL) {
PKG_MEM_ERROR;
return -1;
}
dmq_tmp_list = dmq_notification_address_list;
dmq_tmp_list->s = tmp_str;
dmq_tmp_list->next = NULL;
LM_DBG("Created list and added new notification address to the list %.*s\n",
dmq_tmp_list->s.len, dmq_tmp_list->s.s);
LM_DBG("Created list and added new notification address to the list "
"%.*s\n",
dmq_tmp_list->s.len, dmq_tmp_list->s.s);
} else {
dmq_tmp_list = append_str_list(tmp_str.s, tmp_str.len, &dmq_tmp_list, &total_list);
if (dmq_tmp_list == NULL) {
dmq_tmp_list = append_str_list(
tmp_str.s, tmp_str.len, &dmq_tmp_list, &total_list);
if(dmq_tmp_list == NULL) {
LM_ERR("could not append to list\n");
return -1;
}
LM_DBG("added new notification address to the list %.*s\n",
dmq_tmp_list->s.len, dmq_tmp_list->s.s);
dmq_tmp_list->s.len, dmq_tmp_list->s.s);
}
return 0;
}
Expand All @@ -418,8 +422,8 @@ static void dmq_rpc_list_nodes(rpc_t *rpc, void *c)
if(rpc->struct_add(h, "SSssSdd", "host", &cur->uri.host, "port",
&cur->uri.port, "proto", get_proto_name(cur->uri.proto),
"resolved_ip", ip, "status", dmq_get_status_str(cur->status),
"last_notification", cur->last_notification,
"local", cur->local)
"last_notification", cur->last_notification, "local",
cur->local)
< 0)
goto error;
cur = cur->next;
Expand All @@ -433,32 +437,27 @@ static void dmq_rpc_list_nodes(rpc_t *rpc, void *c)

static const char *dmq_rpc_list_nodes_doc[2] = {"Print all nodes", 0};

void rpc_dmq_remove(rpc_t* rpc, void* ctx)
void rpc_dmq_remove(rpc_t *rpc, void *ctx)
{
str taddr = STR_NULL;

if (rpc->scan(ctx, ".S", &taddr) < 1) {
if(rpc->scan(ctx, ".S", &taddr) < 1) {
rpc->fault(ctx, 500, "Invalid Parameters");
return;
}
if(dmq_node_del_by_uri(dmq_node_list, &taddr)<0) {
if(dmq_node_del_by_uri(dmq_node_list, &taddr) < 0) {
rpc->fault(ctx, 500, "Failure");
return;
}
rpc->rpl_printf(ctx, "Ok. DMQ node removed.");
}

static const char* rpc_dmq_remove_doc[3] = {
"Remove a DMQ node",
"address - the DMQ node address",
0
};
static const char *rpc_dmq_remove_doc[3] = {
"Remove a DMQ node", "address - the DMQ node address", 0};

static rpc_export_t rpc_methods[] = {
{"dmq.list_nodes", dmq_rpc_list_nodes, dmq_rpc_list_nodes_doc, RET_ARRAY},
{"dmq.remove", rpc_dmq_remove, rpc_dmq_remove_doc, 0},
{0, 0, 0, 0}
};
static rpc_export_t rpc_methods[] = {{"dmq.list_nodes", dmq_rpc_list_nodes,
dmq_rpc_list_nodes_doc, RET_ARRAY},
{"dmq.remove", rpc_dmq_remove, rpc_dmq_remove_doc, 0}, {0, 0, 0, 0}};

/**
*
Expand Down
38 changes: 21 additions & 17 deletions src/modules/dmq/dmq_funcs.c
Expand Up @@ -88,7 +88,7 @@ int build_uri_str(str *username, struct sip_uri *uri, str *from)
}

from_len = username->len + uri->host.len + uri->port.len + 12
+ TRANSPORT_PARAM_LEN;
+ TRANSPORT_PARAM_LEN;
from->s = pkg_malloc(from_len);
if(from->s == NULL) {
PKG_MEM_ERROR;
Expand All @@ -115,9 +115,9 @@ int build_uri_str(str *username, struct sip_uri *uri, str *from)
from->len += uri->port.len;
}

if(uri->proto!=PROTO_NONE && uri->proto!=PROTO_UDP
&& uri->proto!=PROTO_OTHER) {
if(get_valid_proto_string(uri->proto, 1, 0, &sproto)<0) {
if(uri->proto != PROTO_NONE && uri->proto != PROTO_UDP
&& uri->proto != PROTO_OTHER) {
if(get_valid_proto_string(uri->proto, 1, 0, &sproto) < 0) {
LM_WARN("unknown transport protocol - fall back to udp\n");
sproto.s = "udp";
sproto.len = 3;
Expand Down Expand Up @@ -202,7 +202,8 @@ int bcast_dmq_message1(dmq_peer_t *peer, str *body, dmq_node_t *except,
int bcast_dmq_message(dmq_peer_t *peer, str *body, dmq_node_t *except,
dmq_resp_cback_t *resp_cback, int max_forwards, str *content_type)
{
return bcast_dmq_message1(peer, body, except, resp_cback, max_forwards, content_type, 0);
return bcast_dmq_message1(
peer, body, except, resp_cback, max_forwards, content_type, 0);
}

/**
Expand Down Expand Up @@ -291,8 +292,8 @@ int dmq_send_message(dmq_peer_t *peer, str *body, dmq_node_t *node,
/**
* @brief kemi function for sending dmq message
*/
int ki_dmq_send_message(sip_msg_t *msg, str *peer_str, str *to_str,
str *body_str, str *ct_str)
int ki_dmq_send_message(
sip_msg_t *msg, str *peer_str, str *to_str, str *body_str, str *ct_str)
{
LM_DBG("cfg_dmq_send_message: %.*s - %.*s - %.*s - %.*s\n", peer_str->len,
peer_str->s, to_str->len, to_str->s, body_str->len, body_str->s,
Expand Down Expand Up @@ -362,8 +363,8 @@ int cfg_dmq_send_message(struct sip_msg *msg, char *peer, char *to, char *body,
/**
* @brief config file function for broadcasting dmq message
*/
int ki_dmq_bcast_message(sip_msg_t *msg, str *peer_str, str *body_str,
str *ct_str)
int ki_dmq_bcast_message(
sip_msg_t *msg, str *peer_str, str *body_str, str *ct_str)
{
LM_DBG("cfg_dmq_bcast_message: %.*s - %.*s - %.*s\n", peer_str->len,
peer_str->s, body_str->len, body_str->s, ct_str->len, ct_str->s);
Expand All @@ -383,8 +384,9 @@ int ki_dmq_bcast_message(sip_msg_t *msg, str *peer_str, str *body_str,
goto error;
}
}
if(bcast_dmq_message(destination_peer, body_str, 0, &dmq_notification_resp_callback,
1, ct_str) < 0) {
if(bcast_dmq_message(destination_peer, body_str, 0,
&dmq_notification_resp_callback, 1, ct_str)
< 0) {
LM_ERR("cannot send dmq message\n");
goto error;
}
Expand All @@ -396,8 +398,8 @@ int ki_dmq_bcast_message(sip_msg_t *msg, str *peer_str, str *body_str,
/**
* @brief config file function for broadcasting dmq message
*/
int cfg_dmq_bcast_message(sip_msg_t *msg, char *peer, char *body,
char *content_type)
int cfg_dmq_bcast_message(
sip_msg_t *msg, char *peer, char *body, char *content_type)
{
str peer_str;
str body_str;
Expand Down Expand Up @@ -431,7 +433,7 @@ int ki_dmq_t_replicate_mode(struct sip_msg *msg, int mode)
/* avoid loops - do not replicate if message has come from another node
* (override if optional parameter is set)
*/
if(mode==0 && is_from_remote_node(msg) > 0) {
if(mode == 0 && is_from_remote_node(msg) > 0) {
LM_DBG("message is from another node - skipping replication\n");
return -1;
}
Expand Down Expand Up @@ -491,7 +493,7 @@ int ki_dmq_t_replicate(sip_msg_t *msg)
int cfg_dmq_t_replicate(struct sip_msg *msg, char *s, char *p2)
{
int i = 0;
if(s!=NULL && get_int_fparam(&i, msg, (fparam_t *)s) < 0) {
if(s != NULL && get_int_fparam(&i, msg, (fparam_t *)s) < 0) {
LM_ERR("failed to get parameter value\n");
return -1;
}
Expand Down Expand Up @@ -530,7 +532,8 @@ void ping_servers(unsigned int ticks, void *param)
dmq_notification_node =
add_server_and_notify(dmq_notification_address_list);
if(!dmq_notification_node) {
LM_ERR("cannot retrieve initial nodelist, first list entry%.*s\n",
LM_ERR("cannot retrieve initial nodelist, first list "
"entry%.*s\n",
STR_FMT(&dmq_notification_address_list->s));
}
} else {
Expand All @@ -545,7 +548,8 @@ void ping_servers(unsigned int ticks, void *param)
return;
}
ret = bcast_dmq_message1(dmq_notification_peer, body, NULL,
&dmq_notification_resp_callback, 1, &dmq_notification_content_type, 1);
&dmq_notification_resp_callback, 1, &dmq_notification_content_type,
1);
pkg_free(body->s);
pkg_free(body);
if(ret < 0) {
Expand Down
12 changes: 6 additions & 6 deletions src/modules/dmq/dmq_funcs.h
Expand Up @@ -48,8 +48,8 @@ typedef struct dmq_cback_param

int cfg_dmq_send_message(struct sip_msg *msg, char *peer, char *to, char *body,
char *content_type);
int cfg_dmq_bcast_message(struct sip_msg *msg, char *peer, char *body,
char *content_type);
int cfg_dmq_bcast_message(
struct sip_msg *msg, char *peer, char *body, char *content_type);
int cfg_dmq_t_replicate(struct sip_msg *msg, char *s, char *p2);
int cfg_dmq_is_from_node(struct sip_msg *msg, char *p1, char *p2);
dmq_peer_t *register_dmq_peer(dmq_peer_t *peer);
Expand All @@ -61,10 +61,10 @@ int bcast_dmq_message1(dmq_peer_t *peer, str *body, dmq_node_t *except,
int bcast_dmq_message(dmq_peer_t *peer, str *body, dmq_node_t *except,
dmq_resp_cback_t *resp_cback, int max_forwards, str *content_type);

int ki_dmq_send_message(sip_msg_t *msg, str *peer_str, str *to_str,
str *body_str, str *ct_str);
int ki_dmq_bcast_message(sip_msg_t *msg, str *peer_str, str *body_str,
str *ct_str);
int ki_dmq_send_message(
sip_msg_t *msg, str *peer_str, str *to_str, str *body_str, str *ct_str);
int ki_dmq_bcast_message(
sip_msg_t *msg, str *peer_str, str *body_str, str *ct_str);
int is_from_remote_node(sip_msg_t *msg);
int ki_dmq_t_replicate(struct sip_msg *msg);
int ki_dmq_t_replicate_mode(struct sip_msg *msg, int mode);
Expand Down
10 changes: 5 additions & 5 deletions src/modules/dmq/dmqnode.c
Expand Up @@ -341,7 +341,7 @@ int dmq_node_del_filter(dmq_node_list_t *list, dmq_node_t *node, int filter)
prev = &list->nodes;
while(cur) {
if(cmp_dmq_node(cur, node)) {
if(filter==0 || cur->local==0) {
if(filter == 0 || cur->local == 0) {
*prev = cur->next;
destroy_dmq_node(cur, 1);
}
Expand All @@ -360,7 +360,7 @@ int dmq_node_del_filter(dmq_node_list_t *list, dmq_node_t *node, int filter)
*/
int del_dmq_node(dmq_node_list_t *list, dmq_node_t *node)
{
return dmq_node_del_filter(list, node, 0);
return dmq_node_del_filter(list, node, 0);
}

/**
Expand Down Expand Up @@ -443,9 +443,9 @@ int build_node_str(dmq_node_t *node, char *buf, int buflen)
len += 1;
memcpy(buf + len, node->uri.port.s, node->uri.port.len);
len += node->uri.port.len;
if(node->uri.proto!=PROTO_NONE && node->uri.proto!=PROTO_UDP
&& node->uri.proto!=PROTO_OTHER) {
if(get_valid_proto_string(node->uri.proto, 1, 0, &sproto)<0) {
if(node->uri.proto != PROTO_NONE && node->uri.proto != PROTO_UDP
&& node->uri.proto != PROTO_OTHER) {
if(get_valid_proto_string(node->uri.proto, 1, 0, &sproto) < 0) {
LM_WARN("unknown transport protocol - fall back to udp\n");
sproto.s = "udp";
sproto.len = 3;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/dmq/dmqnode.h
Expand Up @@ -41,7 +41,7 @@

typedef struct dmq_node
{
int local; /* local type set means the dmq dmqnode == self */
int local; /* local type set means the dmq dmqnode == self */
str orig_uri; /* original uri string - e.g. sip:127.0.0.1:5060;passive=true */
struct sip_uri uri; /* parsed uri string */
struct ip_addr ip_address; /* resolved IP address */
Expand Down
19 changes: 11 additions & 8 deletions src/modules/dmq/message.c
Expand Up @@ -121,9 +121,11 @@ int w_dmq_handle_message(struct sip_msg *msg, char *str1, char *str2)
{
int i = 0;
if(str1) {
if(get_int_fparam(&i, msg, (fparam_t*)str1)<0) return -1;
if(get_int_fparam(&i, msg, (fparam_t *)str1) < 0)
return -1;
}
if(i>1) i = 1;
if(i > 1)
i = 1;
return ki_dmq_handle_message_rc(msg, i);
}

Expand Down Expand Up @@ -186,10 +188,9 @@ int ki_dmq_process_message_rc(sip_msg_t *msg, int returnval)
}
}
/* send the reply */
if(peer_response.resp_code>0 && peer_response.reason.s!=NULL
&& peer_response.reason.len>0) {
if(slb.freply(msg, peer_response.resp_code,
&peer_response.reason)
if(peer_response.resp_code > 0 && peer_response.reason.s != NULL
&& peer_response.reason.len > 0) {
if(slb.freply(msg, peer_response.resp_code, &peer_response.reason)
< 0) {
LM_ERR("error sending reply\n");
} else {
Expand All @@ -214,9 +215,11 @@ int w_dmq_process_message(struct sip_msg *msg, char *str1, char *str2)
{
int i = 0;
if(str1) {
if(get_int_fparam(&i, msg, (fparam_t*)str1)<0) return -1;
if(get_int_fparam(&i, msg, (fparam_t *)str1) < 0)
return -1;
}
if(i>1) i = 1;
if(i > 1)
i = 1;
return ki_dmq_process_message_rc(msg, i);
}

Expand Down

0 comments on commit 85783de

Please sign in to comment.