Skip to content

Commit

Permalink
diversion: clang-format for coherent indentation and coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxmaniac committed Nov 11, 2023
1 parent a0ed9e7 commit 5ae2966
Showing 1 changed file with 40 additions and 46 deletions.
86 changes: 40 additions & 46 deletions src/modules/diversion/diversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,84 +38,79 @@ MODULE_VERSION
#define DIVERSION_HF "Diversion"
#define DIVERSION_HF_LEN (sizeof(DIVERSION_HF) - 1)

#define DIVERSION_PREFIX DIVERSION_HF ": <"
#define DIVERSION_PREFIX DIVERSION_HF ": <"
#define DIVERSION_PREFIX_LEN (sizeof(DIVERSION_PREFIX) - 1)

#define DIVERSION_SUFFIX ">;reason="
#define DIVERSION_SUFFIX ">;reason="
#define DIVERSION_SUFFIX_LEN (sizeof(DIVERSION_SUFFIX) - 1)



str suffix = {"", 0};

int w_add_diversion(struct sip_msg* msg, char* r, char* u);
int w_add_diversion(struct sip_msg *msg, char *r, char *u);


/*
* Exported functions
*/
static cmd_export_t cmds[] = {
{"add_diversion", (cmd_function)w_add_diversion, 1, fixup_spve_null,
0, REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE},
{"add_diversion", (cmd_function)w_add_diversion, 2, fixup_spve_spve,
0, REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE},
{0, 0, 0, 0, 0, 0}
};
{"add_diversion", (cmd_function)w_add_diversion, 1, fixup_spve_null, 0,
REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE},
{"add_diversion", (cmd_function)w_add_diversion, 2, fixup_spve_spve, 0,
REQUEST_ROUTE | FAILURE_ROUTE | BRANCH_ROUTE},
{0, 0, 0, 0, 0, 0}};


/*
* Exported parameters
*/
static param_export_t params[] = {
{"suffix", PARAM_STR, &suffix},
{0, 0, 0}
};
static param_export_t params[] = {{"suffix", PARAM_STR, &suffix}, {0, 0, 0}};


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


static inline int add_diversion_helper(struct sip_msg* msg, str* s)
static inline int add_diversion_helper(struct sip_msg *msg, str *s)
{
char *ptr;
int is_ref;

struct lump* anchor = 0;
struct lump *anchor = 0;

if (!msg->diversion && parse_headers(msg, HDR_DIVERSION_F, 0) == -1) {
if(!msg->diversion && parse_headers(msg, HDR_DIVERSION_F, 0) == -1) {
LM_ERR("header parsing failed\n");
return -1;
}
if (msg->diversion) {
/* Insert just before the topmost Diversion header */

if(msg->diversion) {
/* Insert just before the topmost Diversion header */
ptr = msg->diversion->name.s;
} else {
/* Insert at the end */
/* Insert at the end */
ptr = msg->unparsed;
}

anchor = anchor_lump2(msg, ptr - msg->buf, 0, 0, &is_ref);
if (!anchor) {
if(!anchor) {
LM_ERR("can't get anchor\n");
return -2;
}
if (!insert_new_lump_before(anchor, s->s, s->len, 0)) {

if(!insert_new_lump_before(anchor, s->s, s->len, 0)) {
LM_ERR("can't insert lump\n");
return -3;
}
Expand All @@ -124,20 +119,20 @@ static inline int add_diversion_helper(struct sip_msg* msg, str* s)
}


int add_diversion_uri(sip_msg_t* msg, str* reason, str* uri)
int add_diversion_uri(sip_msg_t *msg, str *reason, str *uri)
{
str div_hf;
char *at;

if(reason==NULL || reason->s==NULL || uri==NULL || uri->s==NULL) {
if(reason == NULL || reason->s == NULL || uri == NULL || uri->s == NULL) {
LM_ERR("invalid parameters\n");
return -1;
}

div_hf.len = DIVERSION_PREFIX_LEN + uri->len + DIVERSION_SUFFIX_LEN
+ reason->len + CRLF_LEN;
+ reason->len + CRLF_LEN;
div_hf.s = pkg_malloc(div_hf.len);
if (!div_hf.s) {
if(!div_hf.s) {
LM_ERR("no pkg memory left\n");
return -1;
}
Expand All @@ -157,33 +152,32 @@ int add_diversion_uri(sip_msg_t* msg, str* reason, str* uri)

memcpy(at, CRLF, CRLF_LEN);

if (add_diversion_helper(msg, &div_hf) < 0) {
if(add_diversion_helper(msg, &div_hf) < 0) {
pkg_free(div_hf.s);
return -1;
}

return 1;
}

int w_add_diversion(struct sip_msg* msg, char* r, char* u)
int w_add_diversion(struct sip_msg *msg, char *r, char *u)
{
str uri;
str reason;

if(fixup_get_svalue(msg, (gparam_t*)r, &reason)<0) {
if(fixup_get_svalue(msg, (gparam_t *)r, &reason) < 0) {
LM_ERR("cannot get the reason parameter\n");
return -1;
}

if(u==NULL) {
if(parse_sip_msg_uri(msg)<0) {
if(u == NULL) {
if(parse_sip_msg_uri(msg) < 0) {
LM_ERR("failed to parse sip msg uri\n");
return -1;
}
uri = msg->first_line.u.request.uri;
} else {
if(fixup_get_svalue(msg, (gparam_t*)u, &uri)<0)
{
if(fixup_get_svalue(msg, (gparam_t *)u, &uri) < 0) {
LM_ERR("cannot get the uri parameter\n");
return -1;
}
Expand All @@ -196,7 +190,7 @@ int w_add_diversion(struct sip_msg* msg, char* r, char* u)
*/
static int ki_add_diversion(sip_msg_t *msg, str *reason)
{
if(parse_sip_msg_uri(msg)<0) {
if(parse_sip_msg_uri(msg) < 0) {
LM_ERR("failed to parse sip msg uri\n");
return -1;
}
Expand Down

0 comments on commit 5ae2966

Please sign in to comment.