Skip to content

Commit

Permalink
statistics: 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 578a17a commit 972777a
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 124 deletions.
189 changes: 93 additions & 96 deletions src/modules/statistics/statistics.c
Expand Up @@ -46,146 +46,144 @@

MODULE_VERSION

static int reg_param_stat( modparam_t type, void* val);
static int reg_param_stat(modparam_t type, void *val);
static int mod_init(void);
static int w_update_stat(struct sip_msg* msg, char* stat, char* n);
static int w_reset_stat(struct sip_msg* msg, char* stat, char* foo);
static int fixup_stat(void** param, int param_no);
static int w_update_stat(struct sip_msg *msg, char *stat, char *n);
static int w_reset_stat(struct sip_msg *msg, char *stat, char *foo);
static int fixup_stat(void **param, int param_no);

struct stat_or_pv {
stat_var *stat;
pv_spec_t *pv;
};

struct long_or_pv {
long val;
pv_spec_t *pv;
};



static cmd_export_t cmds[]={
{"update_stat", (cmd_function)w_update_stat, 2, fixup_stat, 0,
ANY_ROUTE},
{"reset_stat", (cmd_function)w_reset_stat, 1, fixup_stat, 0,
REQUEST_ROUTE|BRANCH_ROUTE|FAILURE_ROUTE|ONREPLY_ROUTE|LOCAL_ROUTE},
{0,0,0,0,0,0}
struct stat_or_pv
{
stat_var *stat;
pv_spec_t *pv;
};

static param_export_t mod_params[]={
{ "variable", PARAM_STRING|USE_FUNC_PARAM, (void*)reg_param_stat },
{ 0,0,0 }
struct long_or_pv
{
long val;
pv_spec_t *pv;
};


struct module_exports exports= {
"statistics", /* module name */
DEFAULT_DLFLAGS, /* dlopen flags */
cmds, /* exported functions */
mod_params, /* exported parameters */
0, /* exported rpc functions */
0, /* exported pseudo-variables */
0, /* reply processing function */
mod_init, /* module init function */
0, /* per-child init function */
0 /* module destroy function */
static cmd_export_t cmds[] = {{"update_stat", (cmd_function)w_update_stat, 2,
fixup_stat, 0, ANY_ROUTE},
{"reset_stat", (cmd_function)w_reset_stat, 1, fixup_stat, 0,
REQUEST_ROUTE | BRANCH_ROUTE | FAILURE_ROUTE | ONREPLY_ROUTE
| LOCAL_ROUTE},
{0, 0, 0, 0, 0, 0}};

static param_export_t mod_params[] = {
{"variable", PARAM_STRING | USE_FUNC_PARAM, (void *)reg_param_stat},
{0, 0, 0}};


struct module_exports exports = {
"statistics", /* module name */
DEFAULT_DLFLAGS, /* dlopen flags */
cmds, /* exported functions */
mod_params, /* exported parameters */
0, /* exported rpc functions */
0, /* exported pseudo-variables */
0, /* reply processing function */
mod_init, /* module init function */
0, /* per-child init function */
0 /* module destroy function */
};



static int reg_param_stat( modparam_t type, void* val)
static int reg_param_stat(modparam_t type, void *val)
{
return reg_statistic( (char*)val);
return reg_statistic((char *)val);
}



static int mod_init(void)
{
if (register_all_mod_stats()!=0) {
if(register_all_mod_stats() != 0) {
LM_ERR("failed to register statistic variables\n");
return E_UNSPEC;
}
return 0;
}



static int fixup_stat(void** param, int param_no)
static int fixup_stat(void **param, int param_no)
{
struct stat_or_pv *sopv;
struct long_or_pv *lopv;
str s;
long n=0;
int err=0;
long n = 0;
int err = 0;

s.s = (char*)*param;
s.s = (char *)*param;
s.len = strlen(s.s);
if (param_no==1) {
if(param_no == 1) {
/* var name - string or pv */
sopv = (struct stat_or_pv *)pkg_malloc(sizeof(struct stat_or_pv));
if (sopv==NULL) {
if(sopv == NULL) {
PKG_MEM_ERROR;
return E_OUT_OF_MEM;
}
memset( sopv, 0 , sizeof(struct stat_or_pv) );
memset(sopv, 0, sizeof(struct stat_or_pv));
/* is it pv? */
if (s.s[0]=='$') {
if (fixup_pvar_null(param, 1)!=0) {
LM_ERR("invalid pv %s as parameter\n",s.s);
if(s.s[0] == '$') {
if(fixup_pvar_null(param, 1) != 0) {
LM_ERR("invalid pv %s as parameter\n", s.s);
pkg_free(sopv);
return E_CFG;
}
sopv->pv = (pv_spec_t*)(*param);
sopv->pv = (pv_spec_t *)(*param);
} else {
/* it is string */
sopv->stat = get_stat( &s );
if (sopv->stat==0) {
sopv->stat = get_stat(&s);
if(sopv->stat == 0) {
LM_ERR("variable <%s> not defined\n", s.s);
pkg_free(sopv);
return E_CFG;
}
}
*param=(void*)sopv;
*param = (void *)sopv;
return 0;
} else if (param_no==2) {
lopv = (struct long_or_pv *) pkg_malloc(sizeof(struct long_or_pv));
if (lopv == NULL) {
} else if(param_no == 2) {
lopv = (struct long_or_pv *)pkg_malloc(sizeof(struct long_or_pv));
if(lopv == NULL) {
PKG_MEM_ERROR;
return E_OUT_OF_MEM;
}
memset(lopv, 0, sizeof(struct long_or_pv));
/* is it pv? */
if (s.s[0] == '$') {
if (fixup_pvar_pvar(param, 2) != 0) {
LM_ERR("invalid pv %s as parameter\n",s.s);
if(s.s[0] == '$') {
if(fixup_pvar_pvar(param, 2) != 0) {
LM_ERR("invalid pv %s as parameter\n", s.s);
pkg_free(lopv);
return E_CFG;
}
lopv->pv = (pv_spec_t*) (*param);
lopv->pv = (pv_spec_t *)(*param);
} else {
/* it is string */
/* update value - integer */
if (s.s[0] == '-' || s.s[0] == '+') {
if(s.s[0] == '-' || s.s[0] == '+') {
n = str2s(s.s + 1, s.len - 1, &err);
if (s.s[0] == '-')
if(s.s[0] == '-')
n = -n;
} else {
n = str2s(s.s, s.len, &err);
}
lopv->val = n;
}

if (err==0){
if (n==0 && (s.s[0]!='$')) { //we can't check the value of the pvar so have to ignore this check if it is a pvar
if(err == 0) {
if(n == 0
&& (s.s[0]
!= '$')) { //we can't check the value of the pvar so have to ignore this check if it is a pvar
LM_ERR("update with 0 has no sense\n");
pkg_free(lopv);
return E_CFG;
}
*param=(void*)lopv;
*param = (void *)lopv;
return 0;
}else{
LM_ERR("bad update number <%s>\n",(char*)(*param));
} else {
LM_ERR("bad update number <%s>\n", (char *)(*param));
pkg_free(lopv);
return E_CFG;
}
Expand All @@ -203,40 +201,40 @@ static int w_update_stat(struct sip_msg *msg, char *stat_p, char *long_p)
long n = 0;
int err;

if (lopv->val) {
n=lopv->val;
if(lopv->val) {
n = lopv->val;
} else {
if (pv_get_spec_value(msg, lopv->pv, &pv_val) != 0 || (pv_val.flags & PV_VAL_STR) == 0) {
if(pv_get_spec_value(msg, lopv->pv, &pv_val) != 0
|| (pv_val.flags & PV_VAL_STR) == 0) {
LM_ERR("failed to get pv string value\n");
return -1;
}
str s = pv_val.rs;
/* it is string */
/* update value - integer */
if (s.s[0] == '-' || s.s[0] == '+') {
if(s.s[0] == '-' || s.s[0] == '+') {
n = str2s(s.s + 1, s.len - 1, &err);
if (s.s[0] == '-')
if(s.s[0] == '-')
n = -n;
} else {
n = str2s(s.s, s.len, &err);
}
}

if (sopv->stat) {
update_stat( sopv->stat, (long)n);
if(sopv->stat) {
update_stat(sopv->stat, (long)n);
} else {
if (pv_get_spec_value(msg, sopv->pv, &pv_val)!=0 ||
(pv_val.flags & PV_VAL_STR)==0 ) {
if(pv_get_spec_value(msg, sopv->pv, &pv_val) != 0
|| (pv_val.flags & PV_VAL_STR) == 0) {
LM_ERR("failed to get pv string value\n");
return -1;
}
stat = get_stat( &(pv_val.rs) );
if ( stat == 0 ) {
LM_ERR("variable <%.*s> not defined\n",
pv_val.rs.len, pv_val.rs.s);
stat = get_stat(&(pv_val.rs));
if(stat == 0) {
LM_ERR("variable <%.*s> not defined\n", pv_val.rs.len, pv_val.rs.s);
return -1;
}
update_stat( stat, (long)n);
update_stat(stat, (long)n);
}

return 1;
Expand All @@ -255,33 +253,32 @@ static int ki_update_stat(sip_msg_t *msg, str *sname, int sval)
return 1;
}

static int w_reset_stat(struct sip_msg *msg, char* stat_p, char *foo)
static int w_reset_stat(struct sip_msg *msg, char *stat_p, char *foo)
{
struct stat_or_pv *sopv = (struct stat_or_pv *)stat_p;
pv_value_t pv_val;
stat_var *stat;

if (sopv->stat) {
reset_stat( sopv->stat );
if(sopv->stat) {
reset_stat(sopv->stat);
} else {
if (pv_get_spec_value(msg, sopv->pv, &pv_val)!=0 ||
(pv_val.flags & PV_VAL_STR)==0 ) {
if(pv_get_spec_value(msg, sopv->pv, &pv_val) != 0
|| (pv_val.flags & PV_VAL_STR) == 0) {
LM_ERR("failed to get pv string value\n");
return -1;
}
stat = get_stat( &(pv_val.rs) );
if ( stat == 0 ) {
LM_ERR("variable <%.*s> not defined\n",
pv_val.rs.len, pv_val.rs.s);
stat = get_stat(&(pv_val.rs));
if(stat == 0) {
LM_ERR("variable <%.*s> not defined\n", pv_val.rs.len, pv_val.rs.s);
return -1;
}
reset_stat( stat );
reset_stat(stat);
}

return 1;
}

static int ki_reset_stat(sip_msg_t *msg, str* sname)
static int ki_reset_stat(sip_msg_t *msg, str *sname)
{
stat_var *stat;

Expand All @@ -290,7 +287,7 @@ static int ki_reset_stat(sip_msg_t *msg, str* sname)
LM_ERR("variable <%.*s> not defined\n", sname->len, sname->s);
return -1;
}
reset_stat( stat );
reset_stat(stat);
return 1;
}

Expand Down

0 comments on commit 972777a

Please sign in to comment.