Skip to content

Commit

Permalink
msilo: 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 31af21a commit 44e5ec3
Show file tree
Hide file tree
Showing 6 changed files with 659 additions and 791 deletions.
10 changes: 5 additions & 5 deletions src/modules/msilo/api.h
Expand Up @@ -8,13 +8,14 @@

//#include "../../core/sr_module.h"

typedef int (*msilo_f)(struct sip_msg*, str*);
typedef struct msilo_api {
typedef int (*msilo_f)(struct sip_msg *, str *);
typedef struct msilo_api
{
msilo_f m_store;
msilo_f m_dump;
} msilo_api_t;

typedef int (*bind_msilo_f)(msilo_api_t* api);
typedef int (*bind_msilo_f)(msilo_api_t *api);

/**
* @brief Load the MSILO API
Expand All @@ -28,8 +29,7 @@ static inline int load_msilo_api(msilo_api_t *api)
LM_ERR("cannot find bind_msilo\n");
return -1;
}
if(bindmsilo(api)<0)
{
if(bindmsilo(api) < 0) {
LM_ERR("cannot bind msilo api\n");
return -1;
}
Expand Down
104 changes: 45 additions & 59 deletions src/modules/msilo/ms_msg_list.c
Expand Up @@ -63,14 +63,13 @@ void msg_list_el_free(msg_list_el mle)
*/
void msg_list_el_free_all(msg_list_el mle)
{
msg_list_el p0, p1;
msg_list_el p0, p1;

if(!mle)
return;

p0 = mle;
while(p0)
{
while(p0) {
p1 = p0;
p0 = p0->next;
msg_list_el_free(p1);
Expand All @@ -83,16 +82,16 @@ void msg_list_el_free_all(msg_list_el mle)
msg_list msg_list_init(void)
{
msg_list ml = NULL;

ml = (msg_list)shm_malloc(sizeof(t_msg_list));
if(ml == NULL)
return NULL;
/* init locks */
if (lock_init(&ml->sem_sent)==0){
if(lock_init(&ml->sem_sent) == 0) {
LM_CRIT("could not initialize a lock\n");
goto clean;
};
if (lock_init(&ml->sem_done)==0){
if(lock_init(&ml->sem_done) == 0) {
LM_CRIT("could not initialize a lock\n");
lock_destroy(&ml->sem_sent);
goto clean;
Expand All @@ -101,7 +100,7 @@ msg_list msg_list_init(void)
ml->nrdone = 0;
ml->lsent = NULL;
ml->ldone = NULL;

return ml;

clean:
Expand All @@ -122,76 +121,69 @@ void msg_list_free(msg_list ml)
lock_destroy(&ml->sem_sent);
lock_destroy(&ml->sem_done);

if(ml->nrsent>0 && ml->lsent)
{ // free sent list
if(ml->nrsent > 0 && ml->lsent) { // free sent list
p0 = ml->lsent;
ml->lsent = NULL;
ml->nrsent = 0;
while(p0)
{
while(p0) {
p1 = p0->next;
msg_list_el_free(p0);
p0 = p1;
}
}
}

if(ml->nrdone>0 && ml->ldone)
{ // free done list
if(ml->nrdone > 0 && ml->ldone) { // free done list
p0 = ml->ldone;
ml->ldone = NULL;
ml->nrdone = 0;
while(p0)
{
while(p0) {
p1 = p0->next;
msg_list_el_free(p0);
p0 = p1;
}
}
shm_free(ml);

shm_free(ml);
}

/**
* check if a message is in list
*/
int msg_list_check_msg(msg_list ml, int mid)
{
msg_list_el p0, p1;
if(!ml || mid==0)
msg_list_el p0, p1;

if(!ml || mid == 0)
goto errorx;

LM_DBG("checking msgid=%d\n", mid);

lock_get(&ml->sem_sent);

p0 = p1 = ml->lsent;
while(p0)
{
if(p0->msgid==mid)
while(p0) {
if(p0->msgid == mid)
goto exist;
p1 = p0;
p0 = p0->next;
}

p0 = msg_list_el_new();
if(!p0)
{
if(!p0) {
LM_ERR("failed to create new msg elem.\n");
goto error;
}
p0->msgid = mid;
p0->flag |= MS_MSG_SENT;

if(p1)
{
if(p1) {
p1->next = p0;
p0->prev = p1;
goto done;
}

ml->lsent = p0;

done:
ml->nrsent++;
lock_release(&ml->sem_sent);
Expand All @@ -200,7 +192,7 @@ int msg_list_check_msg(msg_list ml, int mid)
exist:
lock_release(&ml->sem_sent);
LM_DBG("msg already in sent list.\n");
return MSG_LIST_EXIST;
return MSG_LIST_EXIST;
error:
lock_release(&ml->sem_sent);
errorx:
Expand All @@ -212,21 +204,18 @@ int msg_list_check_msg(msg_list ml, int mid)
*/
int msg_list_set_flag(msg_list ml, int mid, int fl)
{
msg_list_el p0;

if(ml==0 || mid==0)
{
msg_list_el p0;

if(ml == 0 || mid == 0) {
LM_ERR("bad param %p / %d\n", ml, fl);
goto errorx;
}

lock_get(&ml->sem_sent);

p0 = ml->lsent;
while(p0)
{
if(p0->msgid==mid)
{
while(p0) {
if(p0->msgid == mid) {
p0->flag |= fl;
LM_DBG("mid:%d fl:%d\n", p0->msgid, fl);
goto done;
Expand All @@ -248,27 +237,25 @@ int msg_list_check(msg_list ml)
{
msg_list_el p0;
msg_list_el p1;

if(!ml)
goto errorx;

lock_get(&ml->sem_sent);
if(ml->nrsent<=0)
if(ml->nrsent <= 0)
goto done;

lock_get(&ml->sem_done);

p0 = ml->lsent;
while(p0)
{
while(p0) {
p1 = p0->next;
if(p0->flag & MS_MSG_DONE || p0->flag & MS_MSG_ERRO)
{
if(p0->flag & MS_MSG_DONE || p0->flag & MS_MSG_ERRO) {
LM_DBG("mid:%d got reply\n", p0->msgid);
if(p0->prev)
(p0->prev)->next = p0->next;
else
ml->lsent = p0->next;
ml->lsent = p0->next;
if(p0->next)
(p0->next)->prev = p0->prev;
ml->nrsent--;
Expand All @@ -278,7 +265,7 @@ int msg_list_check(msg_list ml)
if(ml->ldone)
(ml->ldone)->prev = p0;
p0->next = ml->ldone;

p0->prev = NULL;

ml->ldone = p0;
Expand All @@ -302,17 +289,16 @@ int msg_list_check(msg_list ml)
*/
msg_list_el msg_list_reset(msg_list ml)
{
msg_list_el p0;
msg_list_el p0;

if(!ml)
return NULL;

lock_get(&ml->sem_done);
p0 = ml->ldone;
ml->ldone = NULL;
ml->nrdone = 0;
lock_release(&ml->sem_done);

return p0;
}

27 changes: 13 additions & 14 deletions src/modules/msilo/ms_msg_list.h
Expand Up @@ -27,25 +27,25 @@

#include "../../core/locking.h"

#define MS_MSG_NULL 0
#define MS_MSG_SENT 1
#define MS_MSG_DONE 4
#define MS_MSG_ERRO 8
#define MS_MSG_TSND 16
#define MS_MSG_NULL 0
#define MS_MSG_SENT 1
#define MS_MSG_DONE 4
#define MS_MSG_ERRO 8
#define MS_MSG_TSND 16

#define MS_SEM_SENT 0
#define MS_SEM_SENT 0
#define MS_SEM_DONE 1

#define MSG_LIST_OK 0
#define MSG_LIST_ERR -1
#define MSG_LIST_EXIST 1
#define MSG_LIST_OK 0
#define MSG_LIST_ERR -1
#define MSG_LIST_EXIST 1

typedef struct _msg_list_el
{
int msgid;
int flag;
struct _msg_list_el * prev;
struct _msg_list_el * next;
struct _msg_list_el *prev;
struct _msg_list_el *next;
} t_msg_list_el, *msg_list_el;

typedef struct _msg_list
Expand All @@ -54,8 +54,8 @@ typedef struct _msg_list
int nrdone;
msg_list_el lsent;
msg_list_el ldone;
gen_lock_t sem_sent;
gen_lock_t sem_done;
gen_lock_t sem_sent;
gen_lock_t sem_done;
} t_msg_list, *msg_list;

msg_list_el msg_list_el_new(void);
Expand All @@ -70,4 +70,3 @@ int msg_list_check(msg_list);
msg_list_el msg_list_reset(msg_list);

#endif

0 comments on commit 44e5ec3

Please sign in to comment.