Skip to content

Commit

Permalink
qos: 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 d56093d commit 08b5cbc
Show file tree
Hide file tree
Showing 8 changed files with 474 additions and 345 deletions.
57 changes: 26 additions & 31 deletions src/modules/qos/qos.c
Expand Up @@ -48,34 +48,30 @@ struct dlg_binds dialog_st;
struct dlg_binds *dlg_binds = &dialog_st;


static cmd_export_t cmds[]={
{"load_qos", (cmd_function)load_qos, 0, 0, 0, 0},
{0,0,0,0,0,0}
};
static cmd_export_t cmds[] = {
{"load_qos", (cmd_function)load_qos, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}};

/*
* Script parameters
*/
static param_export_t mod_params[]={
{ "qos_flag", INT_PARAM, &qos_flag},
{ 0,0,0 }
static param_export_t mod_params[] = {
{"qos_flag", INT_PARAM, &qos_flag}, {0, 0, 0}};


struct module_exports exports = {
"qos", /* module's name */
DEFAULT_DLFLAGS, /* dlopen flags */
cmds, /* exported functions */
mod_params, /* param exports */
0, /* exported RPC functions */
0, /* exported pseudo-variables */
0, /* reply processing function */
mod_init, /* module initialization function */
0, /* per-child init function */
mod_destroy /* module destroy function */
};


struct module_exports exports= {
"qos", /* module's name */
DEFAULT_DLFLAGS, /* dlopen flags */
cmds, /* exported functions */
mod_params, /* param exports */
0, /* exported RPC functions */
0, /* exported pseudo-variables */
0, /* reply processing function */
mod_init, /* module initialization function */
0, /* per-child init function */
mod_destroy /* module destroy function */
};

int load_qos( struct qos_binds *qosb)
int load_qos(struct qos_binds *qosb)
{
qosb->register_qoscb = register_qoscb;
return 1;
Expand All @@ -89,31 +85,31 @@ int load_qos( struct qos_binds *qosb)
* Bind to the dialog module and setup the callbacks. Also initialize
* the shared memory to store our interninal information in.
*/
static int mod_init(void)
static int mod_init(void)
{
if (qos_flag == -1) {
if(qos_flag == -1) {
LM_ERR("no qos flag set!!\n");
return -1;
}
else if (qos_flag > MAX_FLAG) {
} else if(qos_flag > MAX_FLAG) {
LM_ERR("invalid qos flag %d!!\n", qos_flag);
return -1;
}

/* init callbacks */
if (init_qos_callbacks()!=0) {
if(init_qos_callbacks() != 0) {
LM_ERR("cannot init callbacks\n");
return -1;
}

/* Register the main (static) dialog call back. */
if (load_dlg_api(&dialog_st) != 0) {
if(load_dlg_api(&dialog_st) != 0) {
LM_ERR("Can't load dialog hooks\n");
return(-1);
return (-1);
}

/* Load dialog hooks */
dialog_st.register_dlgcb(NULL, DLGCB_CREATED, qos_dialog_created_CB, NULL, NULL);
dialog_st.register_dlgcb(
NULL, DLGCB_CREATED, qos_dialog_created_CB, NULL, NULL);

/*
* We are GOOD-TO-GO.
Expand All @@ -125,4 +121,3 @@ static void mod_destroy(void)
{
destroy_qos_callbacks();
}

55 changes: 27 additions & 28 deletions src/modules/qos/qos_cb.c
Expand Up @@ -26,14 +26,14 @@
#include "qos_ctx_helpers.h"
#include "qos_cb.h"

static struct qos_head_cbl* create_cbs = 0;
static struct qos_head_cbl *create_cbs = 0;

static struct qos_cb_params params = {NULL, NULL, 0, NULL};

int init_qos_callbacks(void)
{
create_cbs = (struct qos_head_cbl*)shm_malloc(sizeof(struct qos_head_cbl));
if (create_cbs==0) {
create_cbs = (struct qos_head_cbl *)shm_malloc(sizeof(struct qos_head_cbl));
if(create_cbs == 0) {
SHM_MEM_ERROR;
return -1;
}
Expand All @@ -59,7 +59,7 @@ void destroy_qos_callbacks_list(struct qos_callback *cb)

void destroy_qos_callbacks(void)
{
if (create_cbs==0)
if(create_cbs == 0)
return;

destroy_qos_callbacks_list(create_cbs->first);
Expand All @@ -68,26 +68,26 @@ void destroy_qos_callbacks(void)
}


int register_qoscb(qos_ctx_t *qos, int types, qos_cb f, void *param )
int register_qoscb(qos_ctx_t *qos, int types, qos_cb f, void *param)
{
struct qos_callback *cb;

LM_DBG("registering qos CB\n");

if ( types&QOSCB_CREATED ) {
if (types!=QOSCB_CREATED) {
if(types & QOSCB_CREATED) {
if(types != QOSCB_CREATED) {
LM_CRIT("QOSCB_CREATED type must be register alone!\n");
return -1;
}
} else {
if (qos==0) {
if(qos == 0) {
LM_CRIT("non-QOSCB_CREATED type "
"must be register to a qos (qos missing)!\n");
"must be register to a qos (qos missing)!\n");
return -1;
}
}
cb = (struct qos_callback*)shm_malloc(sizeof(struct qos_callback));
if (cb==0) {
cb = (struct qos_callback *)shm_malloc(sizeof(struct qos_callback));
if(cb == 0) {
SHM_MEM_ERROR;
return -1;
}
Expand All @@ -98,16 +98,16 @@ int register_qoscb(qos_ctx_t *qos, int types, qos_cb f, void *param )
cb->callback = f;
cb->param = param;

if ( types&QOSCB_CREATED ) {
if(types & QOSCB_CREATED) {
cb->next = create_cbs->first;
create_cbs->first = cb;
create_cbs->types |= types;
} else {
cb->next = qos->cbs.first;
qos->cbs.first = cb;
qos->cbs.types |= types;
LM_DBG("qos=%p qos->cbs=%p types=%d\n",
qos, &(qos->cbs), qos->cbs.types);
LM_DBG("qos=%p qos->cbs=%p types=%d\n", qos, &(qos->cbs),
qos->cbs.types);
}

return 0;
Expand All @@ -118,7 +118,7 @@ void run_create_cbs(struct qos_ctx_st *qos, struct sip_msg *msg)
{
struct qos_callback *cb;

if (create_cbs->first==0)
if(create_cbs->first == 0)
return;

params.msg = msg;
Expand All @@ -127,39 +127,38 @@ void run_create_cbs(struct qos_ctx_st *qos, struct sip_msg *msg)
params.role = 0;
params.param = NULL;

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


void run_qos_callbacks(int type, struct qos_ctx_st *qos,
struct qos_sdp_st *sdp, unsigned int role,
struct sip_msg *msg)
void run_qos_callbacks(int type, struct qos_ctx_st *qos, struct qos_sdp_st *sdp,
unsigned int role, struct sip_msg *msg)
{
struct qos_callback *cb;

if (qos == NULL)
if(qos == NULL)
return;

LM_DBG("qos=%p qos->cbs=%p, qos->cbs.types=%d\n",
qos, &(qos->cbs), qos->cbs.types);
if (qos->cbs.first==0 || ((qos->cbs.types)&type)==0 )
LM_DBG("qos=%p qos->cbs=%p, qos->cbs.types=%d\n", qos, &(qos->cbs),
qos->cbs.types);
if(qos->cbs.first == 0 || ((qos->cbs.types) & type) == 0)
return;

params.sdp = sdp;
params.role = role;
params.msg = msg;

LM_DBG("searching in %p\n", qos->cbs.first);
for ( cb=qos->cbs.first; cb; cb=cb->next) {
if ( (cb->types)&type ) {
for(cb = qos->cbs.first; cb; cb = cb->next) {
if((cb->types) & type) {
LM_DBG("qos=%p, type=%d\n", qos, type);
params.param = &cb->param;
cb->callback( qos, type, &params );
cb->callback(qos, type, &params);
}
}
return;
Expand Down
45 changes: 24 additions & 21 deletions src/modules/qos/qos_cb.h
Expand Up @@ -27,26 +27,28 @@

struct qos_ctx_st;

struct qos_cb_params {
struct sip_msg *msg; /* sip msg related to the callback event */
struct qos_sdp_st *sdp; /* pointer to the sdp that is added/updated/removed */
struct qos_cb_params
{
struct sip_msg *msg; /* sip msg related to the callback event */
struct qos_sdp_st
*sdp; /* pointer to the sdp that is added/updated/removed */
unsigned int role;
void **param; /* parameter passed at callback registration*/
void **param; /* parameter passed at callback registration*/
};

/* callback function prototype */
typedef void (qos_cb) (struct qos_ctx_st *qos, int type,
struct qos_cb_params *params);
typedef void(qos_cb)(
struct qos_ctx_st *qos, int type, struct qos_cb_params *params);
/* register callback function prototype */
typedef int (*register_qoscb_f)(struct qos_ctx_st *qos, int cb_types,
qos_cb f, void *param);
typedef int (*register_qoscb_f)(
struct qos_ctx_st *qos, int cb_types, qos_cb f, void *param);


#define QOSCB_CREATED (1<<0)
#define QOSCB_ADD_SDP (1<<1)
#define QOSCB_UPDATE_SDP (1<<2)
#define QOSCB_REMOVE_SDP (1<<3)
#define QOSCB_TERMINATED (1<<4)
#define QOSCB_CREATED (1 << 0)
#define QOSCB_ADD_SDP (1 << 1)
#define QOSCB_UPDATE_SDP (1 << 2)
#define QOSCB_REMOVE_SDP (1 << 3)
#define QOSCB_TERMINATED (1 << 4)

/*
* Callback logic ....
Expand All @@ -69,15 +71,17 @@ typedef int (*register_qoscb_f)(struct qos_ctx_st *qos, int cb_types,
*/

struct qos_callback {
struct qos_callback
{
int types;
qos_cb* callback;
qos_cb *callback;
void *param;
struct qos_callback* next;
struct qos_callback *next;
};


struct qos_head_cbl {
struct qos_head_cbl
{
struct qos_callback *first;
int types;
};
Expand All @@ -88,13 +92,12 @@ void destroy_qos_callbacks();

void destroy_qos_callbacks_list(struct qos_callback *cb);

int register_qoscb(struct qos_ctx_st* qos, int types, qos_cb f, void *param);
int register_qoscb(struct qos_ctx_st *qos, int types, qos_cb f, void *param);

void run_create_cbs(struct qos_ctx_st *qos, struct sip_msg *msg);

void run_qos_callbacks( int type, struct qos_ctx_st *qos,
struct qos_sdp_st *sdp, unsigned int role,
struct sip_msg *msg);
void run_qos_callbacks(int type, struct qos_ctx_st *qos, struct qos_sdp_st *sdp,
unsigned int role, struct sip_msg *msg);


#endif

0 comments on commit 08b5cbc

Please sign in to comment.