Skip to content

Commit

Permalink
ims_dialog: 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 12f3e8f commit eccfa6b
Show file tree
Hide file tree
Showing 20 changed files with 5,822 additions and 5,521 deletions.
119 changes: 58 additions & 61 deletions src/modules/ims_dialog/dlg_cb.c
Expand Up @@ -36,26 +36,25 @@
#include "dlg_cb.h"


static struct dlg_head_cbl* create_cbs = 0;
static struct dlg_head_cbl *create_cbs = 0;

static struct dlg_head_cbl* load_cbs = 0;
static struct dlg_head_cbl *load_cbs = 0;

static struct dlg_cb_params params = {NULL, NULL, DLG_DIR_NONE, NULL, NULL};


#define POINTER_CLOSED_MARKER ((void *)(-1))
#define POINTER_CLOSED_MARKER ((void *)(-1))


static void run_load_callback(struct dlg_callback *cb);



static struct dlg_head_cbl* init_dlg_callback(void)
static struct dlg_head_cbl *init_dlg_callback(void)
{
struct dlg_head_cbl *new_cbs;

new_cbs = (struct dlg_head_cbl*)shm_malloc(sizeof(struct dlg_head_cbl));
if (new_cbs==0) {
new_cbs = (struct dlg_head_cbl *)shm_malloc(sizeof(struct dlg_head_cbl));
if(new_cbs == 0) {
LM_ERR("no more shm mem\n");
return 0;
}
Expand All @@ -73,7 +72,7 @@ void destroy_dlg_callbacks_list(struct dlg_callback *cb)
while(cb) {
cb_t = cb;
cb = cb->next;
if (cb_t->callback_param_free && cb_t->param) {
if(cb_t->callback_param_free && cb_t->param) {
cb_t->callback_param_free(cb_t->param);
cb_t->param = NULL;
}
Expand All @@ -84,15 +83,15 @@ void destroy_dlg_callbacks_list(struct dlg_callback *cb)

void destroy_dlg_callbacks(unsigned int types)
{
if (types&DLGCB_CREATED) {
if (create_cbs && create_cbs!=POINTER_CLOSED_MARKER) {
if(types & DLGCB_CREATED) {
if(create_cbs && create_cbs != POINTER_CLOSED_MARKER) {
destroy_dlg_callbacks_list(create_cbs->first);
shm_free(create_cbs);
create_cbs = POINTER_CLOSED_MARKER;
}
}
if (types&DLGCB_LOADED) {
if (load_cbs && load_cbs!=POINTER_CLOSED_MARKER) {
if(types & DLGCB_LOADED) {
if(load_cbs && load_cbs != POINTER_CLOSED_MARKER) {
destroy_dlg_callbacks_list(load_cbs->first);
shm_free(load_cbs);
load_cbs = POINTER_CLOSED_MARKER;
Expand All @@ -102,44 +101,44 @@ void destroy_dlg_callbacks(unsigned int types)


int register_dlgcb_nodlg(struct dlg_cell *dlg, int types, dialog_cb f,
void *param, param_free_cb ff )
void *param, param_free_cb ff)
{
if (!dlg) {
LM_ERR("Can't find dialog to register callback\n");
return -1;
}
int ret = register_dlgcb(dlg, types, f, param, ff);
unref_dlg(dlg, 1);
return ret;
if(!dlg) {
LM_ERR("Can't find dialog to register callback\n");
return -1;
}

int ret = register_dlgcb(dlg, types, f, param, ff);
unref_dlg(dlg, 1);

return ret;
}


int register_dlgcb(struct dlg_cell *dlg, int types, dialog_cb f,
void *param, param_free_cb ff )
int register_dlgcb(struct dlg_cell *dlg, int types, dialog_cb f, void *param,
param_free_cb ff)
{
struct dlg_callback *cb;

if ( types&DLGCB_LOADED ) {
if (types!=DLGCB_LOADED) {
if(types & DLGCB_LOADED) {
if(types != DLGCB_LOADED) {
LM_CRIT("DLGCB_LOADED type must be registered alone!\n");
return -1;
}
} else if ( types&DLGCB_CREATED ) {
if (types!=DLGCB_CREATED) {
} else if(types & DLGCB_CREATED) {
if(types != DLGCB_CREATED) {
LM_CRIT("DLGCB_CREATED type must be registered alone!\n");
return -1;
}
} else {
if (dlg==0) {
if(dlg == 0) {
LM_CRIT("non-DLGCB_CREATED type "
"must be registered to a dialog (dlg missing)!\n");
"must be registered to a dialog (dlg missing)!\n");
return -1;
}
}
cb = (struct dlg_callback*)shm_malloc(sizeof(struct dlg_callback));
if (cb==0) {
cb = (struct dlg_callback *)shm_malloc(sizeof(struct dlg_callback));
if(cb == 0) {
LM_ERR("no more shm mem\n");
return -1;
}
Expand All @@ -149,31 +148,31 @@ int register_dlgcb(struct dlg_cell *dlg, int types, dialog_cb f,
cb->param = param;
cb->callback_param_free = ff;

if ( types==DLGCB_CREATED ) {
if (load_cbs==POINTER_CLOSED_MARKER) {
if(types == DLGCB_CREATED) {
if(load_cbs == POINTER_CLOSED_MARKER) {
LM_CRIT("DLGCB_CREATED type registered after shutdown!?!\n");
goto error;
}
if (create_cbs==0) {
if(create_cbs == 0) {
/* not initialized yet */
if ( (create_cbs=init_dlg_callback())==NULL ) {
if((create_cbs = init_dlg_callback()) == NULL) {
LM_ERR("no more shm mem\n");
goto error;
}
}
cb->next = create_cbs->first;
create_cbs->first = cb;
create_cbs->types |= types;
} else if (types==DLGCB_LOADED) {
if (load_cbs==POINTER_CLOSED_MARKER) {
} else if(types == DLGCB_LOADED) {
if(load_cbs == POINTER_CLOSED_MARKER) {
/* run the callback on the spot */
run_load_callback(cb);
destroy_dlg_callbacks_list(cb);
return 0;
}
if (load_cbs==0) {
if(load_cbs == 0) {
/* not initialized yet */
if ( (load_cbs=init_dlg_callback())==NULL ) {
if((load_cbs = init_dlg_callback()) == NULL) {
LM_ERR("no more shm mem\n");
goto error;
}
Expand Down Expand Up @@ -204,22 +203,22 @@ static void run_load_callback(struct dlg_callback *cb)
params.direction = DLG_DIR_NONE;
params.param = &cb->param;

for( i=0 ; i<d_table->size ; i++ ) {
for( dlg=d_table->entries[i].first ; dlg ; dlg=dlg->next )
cb->callback( dlg, DLGCB_LOADED, &params );
for(i = 0; i < d_table->size; i++) {
for(dlg = d_table->entries[i].first; dlg; dlg = dlg->next)
cb->callback(dlg, DLGCB_LOADED, &params);
}

return;
}


void run_load_callbacks( void )
void run_load_callbacks(void)
{
struct dlg_callback *cb;

if (load_cbs && load_cbs!=POINTER_CLOSED_MARKER) {
for ( cb=load_cbs->first; cb; cb=cb->next )
run_load_callback( cb );
if(load_cbs && load_cbs != POINTER_CLOSED_MARKER) {
for(cb = load_cbs->first; cb; cb = cb->next)
run_load_callback(cb);
}

return;
Expand All @@ -229,9 +228,10 @@ void run_load_callbacks( void )
void run_create_callbacks(struct dlg_cell *dlg, struct sip_msg *msg)
{
struct dlg_callback *cb;
LM_DBG("Running DLG_CREATED callbacks\n");
LM_DBG("Running DLG_CREATED callbacks\n");

if (create_cbs==NULL || create_cbs==POINTER_CLOSED_MARKER || create_cbs->first==NULL)
if(create_cbs == NULL || create_cbs == POINTER_CLOSED_MARKER
|| create_cbs->first == NULL)
return;

params.req = msg;
Expand All @@ -242,20 +242,17 @@ void run_create_callbacks(struct dlg_cell *dlg, struct sip_msg *msg)
params.param = NULL;
params.dlg_data = NULL;

for ( cb=create_cbs->first; cb; cb=cb->next) {
LM_DBG("dialog=%p\n",dlg);
for(cb = create_cbs->first; cb; cb = cb->next) {
LM_DBG("dialog=%p\n", dlg);
params.param = &cb->param;
cb->callback( dlg, DLGCB_CREATED, &params );
cb->callback(dlg, DLGCB_CREATED, &params);
}
return;
}


void run_dlg_callbacks( int type ,
struct dlg_cell *dlg,
struct sip_msg *req,
struct sip_msg *rpl,
unsigned int dir, void *dlg_data)
void run_dlg_callbacks(int type, struct dlg_cell *dlg, struct sip_msg *req,
struct sip_msg *rpl, unsigned int dir, void *dlg_data)
{
struct dlg_callback *cb;

Expand All @@ -264,14 +261,14 @@ void run_dlg_callbacks( int type ,
params.direction = dir;
params.dlg_data = dlg_data;

if (dlg->cbs.first==0 || ((dlg->cbs.types)&type)==0 )
if(dlg->cbs.first == 0 || ((dlg->cbs.types) & type) == 0)
return;

for ( cb=dlg->cbs.first; cb; cb=cb->next) {
if ( (cb->types)&type ) {
for(cb = dlg->cbs.first; cb; cb = cb->next) {
if((cb->types) & type) {
LM_DBG("dialog=%p, type=%d\n", dlg, type);
params.param = &cb->param;
cb->callback( dlg, type, &params );
cb->callback(dlg, type, &params);
}
}
return;
Expand Down

0 comments on commit eccfa6b

Please sign in to comment.