Skip to content

Commit

Permalink
tsilo: 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 f57e9aa commit 8187f19
Show file tree
Hide file tree
Showing 10 changed files with 424 additions and 406 deletions.
57 changes: 32 additions & 25 deletions src/modules/tsilo/ts_append.c
Expand Up @@ -36,9 +36,10 @@
#include "ts_hash.h"
#include "ts_append.h"

int ts_append(struct sip_msg* msg, str *ruri, str *contact, char *table) {
ts_urecord_t* _r;
ts_transaction_t* ptr;
int ts_append(struct sip_msg *msg, str *ruri, str *contact, char *table)
{
ts_urecord_t *_r;
ts_transaction_t *ptr;

struct sip_uri p_uri;
struct sip_uri c_uri;
Expand All @@ -48,7 +49,7 @@ int ts_append(struct sip_msg* msg, str *ruri, str *contact, char *table) {
int appended;

/* parse R-URI */
if (use_domain) {
if(use_domain) {
t_uri = ruri;
} else {
if(parse_uri(ruri->s, ruri->len, &p_uri) < 0) {
Expand All @@ -60,7 +61,7 @@ int ts_append(struct sip_msg* msg, str *ruri, str *contact, char *table) {

/* parse contact if given */
if(contact->s != NULL && contact->len != 0) {
if (parse_uri(contact->s, contact->len, &c_uri) < 0) {
if(parse_uri(contact->s, contact->len, &c_uri) < 0) {
LM_ERR("failed to parse contact %.*s\n", contact->len, contact->s);
return -1;
}
Expand All @@ -71,7 +72,7 @@ int ts_append(struct sip_msg* msg, str *ruri, str *contact, char *table) {

res = get_ts_urecord(t_uri, &_r);

if (res != 0) {
if(res != 0) {
LM_DBG("no record for %.*s\n", t_uri->len, t_uri->s);
unlock_entry_by_ruri(t_uri);
return -2;
Expand All @@ -81,10 +82,12 @@ int ts_append(struct sip_msg* msg, str *ruri, str *contact, char *table) {
ptr = _r->transactions;

while(ptr) {
LM_DBG("transaction %u:%u found for %.*s, going to append branches\n",ptr->tindex, ptr->tlabel, t_uri->len, t_uri->s);
LM_DBG("transaction %u:%u found for %.*s, going to append branches\n",
ptr->tindex, ptr->tlabel, t_uri->len, t_uri->s);

appended = ts_append_to(msg, ptr->tindex, ptr->tlabel, table, ruri, contact);
if (appended > 0)
appended = ts_append_to(
msg, ptr->tindex, ptr->tlabel, table, ruri, contact);
if(appended > 0)
update_stat(added_branches, appended);
ptr = ptr->next;
}
Expand All @@ -94,38 +97,40 @@ int ts_append(struct sip_msg* msg, str *ruri, str *contact, char *table) {
return 1;
}

int ts_append_to(struct sip_msg* msg, int tindex, int tlabel, char *table, str *uri, str *contact) {
struct cell *t=0;
struct cell *orig_t; /* a pointer to an existing transaction or 0 if lookup fails */
int ts_append_to(struct sip_msg *msg, int tindex, int tlabel, char *table,
str *uri, str *contact)
{
struct cell *t = 0;
struct cell *
orig_t; /* a pointer to an existing transaction or 0 if lookup fails */
struct sip_msg *orig_msg;
int ret;
str stable;
int orig_branch;

if(contact->s!=NULL && contact->len > 0) {
LM_DBG("trying to append based on specific contact <%.*s>\n", contact->len, contact->s);
if(contact->s != NULL && contact->len > 0) {
LM_DBG("trying to append based on specific contact <%.*s>\n",
contact->len, contact->s);
}

orig_t = _tmb.t_gett();
orig_branch = _tmb.t_gett_branch();
orig_branch = _tmb.t_gett_branch();

/* lookup a transaction based on its identifier (hash_index:label) */
if(_tmb.t_lookup_ident(&t, tindex, tlabel) < 0)
{
LM_ERR("transaction [%u:%u] not found\n", tindex, tlabel);
if(_tmb.t_lookup_ident(&t, tindex, tlabel) < 0) {
LM_ERR("transaction [%u:%u] not found\n", tindex, tlabel);
ret = -1;
goto done;
}

/* check if the dialog is still in the early stage */
if (t->flags & T_CANCELED) {
LM_DBG("trasaction [%u:%u] was cancelled\n",
tindex, tlabel);
if(t->flags & T_CANCELED) {
LM_DBG("trasaction [%u:%u] was cancelled\n", tindex, tlabel);
ret = -2;
goto done;
}

if (t->uas.status >= 200) {
if(t->uas.status >= 200) {
LM_DBG("trasaction [%u:%u] sent out a final response already - %d\n",
tindex, tlabel, t->uas.status);
ret = -3;
Expand All @@ -137,14 +142,15 @@ int ts_append_to(struct sip_msg* msg, int tindex, int tlabel, char *table, str *
stable.s = table;
stable.len = strlen(stable.s);

if(uri==NULL || uri->s==NULL || uri->len<=0) {
if(uri == NULL || uri->s == NULL || uri->len <= 0) {
ret = _regapi.lookup_to_dset(orig_msg, &stable, NULL);
} else {
ret = _regapi.lookup_to_dset(orig_msg, &stable, uri);
}

if(ret != 1) {
LM_ERR("transaction %u:%u: error updating dset (%d)\n", tindex, tlabel, ret);
LM_ERR("transaction %u:%u: error updating dset (%d)\n", tindex, tlabel,
ret);
ret = -4;
goto done;
}
Expand All @@ -156,7 +162,8 @@ int ts_append_to(struct sip_msg* msg, int tindex, int tlabel, char *table, str *
done:
/* unref the transaction which had been referred by t_lookup_ident() call.
* Restore the original transaction (if any) */
if(t) _tmb.unref_cell(t);
if(t)
_tmb.unref_cell(t);
_tmb.t_sett(orig_t, orig_branch);

return ret;
Expand Down
5 changes: 3 additions & 2 deletions src/modules/tsilo/ts_append.h
Expand Up @@ -22,7 +22,8 @@
#ifndef _TS_APPEND_H
#define _TS_APPEND_H

int ts_append(struct sip_msg* msg, str *ruri, str *contact, char *table);
int ts_append_to(struct sip_msg* msg, int tindex, int tlabel, char *table, str *uri, str *contact);
int ts_append(struct sip_msg *msg, str *ruri, str *contact, char *table);
int ts_append_to(struct sip_msg *msg, int tindex, int tlabel, char *table,
str *uri, str *contact);

#endif
48 changes: 28 additions & 20 deletions src/modules/tsilo/ts_handlers.c
Expand Up @@ -38,61 +38,69 @@ extern struct ts_table *t_table;
*/
int ts_set_tm_callbacks(struct cell *t, sip_msg_t *req, ts_transaction_t *ts)
{
ts_transaction_t* ts_clone;
ts_transaction_t *ts_clone;

if(t==NULL)
if(t == NULL)
return -1;

if ( (ts_clone=clone_ts_transaction(ts)) == NULL ) {
if((ts_clone = clone_ts_transaction(ts)) == NULL) {
LM_ERR("failed to clone transaction\n");
return -1;
}

if ( _tmb.register_tmcb( req, t,TMCB_DESTROY,
ts_onreply, (void*)ts_clone, free_ts_transaction)<0 ) {
LM_ERR("failed to register TMCB for transaction %d:%d\n", t->hash_index, t->label);
if(_tmb.register_tmcb(req, t, TMCB_DESTROY, ts_onreply, (void *)ts_clone,
free_ts_transaction)
< 0) {
LM_ERR("failed to register TMCB for transaction %d:%d\n", t->hash_index,
t->label);
return -1;
}
LM_DBG("registered TMCB for transaction %d:%d\n", ts_clone->tindex, ts_clone->tlabel);
LM_DBG("registered TMCB for transaction %d:%d\n", ts_clone->tindex,
ts_clone->tlabel);

return 0;
}

void ts_onreply(struct cell* t, int type, struct tmcb_params *param)
void ts_onreply(struct cell *t, int type, struct tmcb_params *param)
{
ts_urecord_t* _r;
ts_entry_t* _e;
ts_urecord_t *_r;
ts_entry_t *_e;
ts_transaction_t *cb_ptr, *ptr;

if(t_table==0) return;
if((type & (TMCB_DESTROY)) && destroy_modules_phase()) return;
if(t_table == 0)
return;
if((type & (TMCB_DESTROY)) && destroy_modules_phase())
return;

cb_ptr = (ts_transaction_t*)(*param->param);
if (cb_ptr == NULL) {
cb_ptr = (ts_transaction_t *)(*param->param);
if(cb_ptr == NULL) {
LM_DBG("NULL param for type %d\n", type);
return;
}

if (type &(TMCB_DESTROY)) {
LM_DBG("TMCB_DESTROY called for transaction %u:%u\n", cb_ptr->tindex, cb_ptr->tlabel);
if(type & (TMCB_DESTROY)) {
LM_DBG("TMCB_DESTROY called for transaction %u:%u\n", cb_ptr->tindex,
cb_ptr->tlabel);
_r = cb_ptr->urecord;
_e = _r->entry;
lock_entry(_e);
ptr = _r->transactions;
while(ptr) {
if ((ptr->tindex == cb_ptr->tindex) && (ptr->tlabel == cb_ptr->tlabel)) {
if((ptr->tindex == cb_ptr->tindex)
&& (ptr->tlabel == cb_ptr->tlabel)) {
remove_ts_transaction(ptr);

if (_r->transactions == NULL) {
LM_DBG("last transaction for %.*s, removing urecord\n", _r->ruri.len, _r->ruri.s);
if(_r->transactions == NULL) {
LM_DBG("last transaction for %.*s, removing urecord\n",
_r->ruri.len, _r->ruri.s);
remove_ts_urecord(_r);
}
unlock_entry(_e);
return;
}
ptr = ptr->next;
}
LM_DBG("transaction %u:%u not found\n",cb_ptr->tindex, cb_ptr->tlabel);
LM_DBG("transaction %u:%u not found\n", cb_ptr->tindex, cb_ptr->tlabel);
unlock_entry(_e);
} else {
LM_DBG("called with unknown type %d\n", type);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/tsilo/ts_handlers.h
Expand Up @@ -36,6 +36,6 @@ int ts_set_tm_callbacks(struct cell *t, sip_msg_t *req, ts_transaction_t *ts);
/*
*
*/
void ts_onreply(struct cell* t, int type, struct tmcb_params *param);
void ts_onreply(struct cell *t, int type, struct tmcb_params *param);

#endif

0 comments on commit 8187f19

Please sign in to comment.