Skip to content

Commit

Permalink
phonenum: 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 71571d6 commit 1560509
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 47 deletions.
42 changes: 22 additions & 20 deletions src/modules/phonenum/cphonenumber.h
Expand Up @@ -25,30 +25,32 @@
#define _CPHONENUMBER_H_

#ifdef __cplusplus
extern "C" {
extern "C"
{
#endif
// Phone number details
typedef struct telnum {
char* number;
char* normalized;
char* ltype;
char* ndesc;
char* ccname;
char* error;
int cctel;
int valid;
} telnum_t;
// Phone number details
typedef struct telnum
{
char *number;
char *normalized;
char *ltype;
char *ndesc;
char *ccname;
char *error;
int cctel;
int valid;
} telnum_t;

telnum_t* telnum_new(char*);
void telnum_free(telnum_t*);
telnum_t *telnum_new(char *);
void telnum_free(telnum_t *);

// test if number is possible
int telnum_possible(char* number, char* region);
// parse a number
telnum_t* telnum_parse(char* number, char* region);
// get country code for number
char* telnum_cc(char* number);
// test if number is possible
int telnum_possible(char *number, char *region);
// parse a number
telnum_t *telnum_parse(char *number, char *region);
// get country code for number
char *telnum_cc(char *number);

#ifdef __cplusplus
}
Expand Down
21 changes: 11 additions & 10 deletions src/modules/phonenum/phonenum_mod.c
Expand Up @@ -43,11 +43,11 @@ static int mod_init(void);
static void mod_destroy(void);

static int w_phonenum_match(struct sip_msg *msg, char *str1, char *str2);
static int w_phonenum_match_cn(struct sip_msg *msg, char *str1, char *str2,
char *str3);
static int w_phonenum_match_cn(
struct sip_msg *msg, char *str1, char *str2, char *str3);
static int phonenum_match(sip_msg_t *msg, str *tomatch, str *pvclass);

static int phonenum_resid_param(modparam_t type, void* val);
static int phonenum_resid_param(modparam_t type, void *val);

/* clang-format off */
static pv_export_t mod_pvs[] = {
Expand Down Expand Up @@ -108,14 +108,14 @@ static void mod_destroy(void)
/**
*
*/
static int phonenum_resid_param(modparam_t type, void* val)
static int phonenum_resid_param(modparam_t type, void *val)
{
str rname;

rname = *((str*)val);
rname = *((str *)val);
if(sr_phonenum_add_resid(&rname) < 0) {
LM_ERR("failed to register result container with id: %.*s\n",
rname.len, rname.s);
LM_ERR("failed to register result container with id: %.*s\n", rname.len,
rname.s);
return -1;
}
return 0;
Expand Down Expand Up @@ -150,15 +150,16 @@ static int w_phonenum_match(sip_msg_t *msg, char *target, char *pvname)
return phonenum_match(msg, &tomatch, &pvclass);
}

static int phonenum_match_cn(sip_msg_t *msg, str *tomatch, str *cnc, str *pvclass)
static int phonenum_match_cn(
sip_msg_t *msg, str *tomatch, str *cnc, str *pvclass)
{
phonenum_pv_reset(pvclass);

return phonenum_update_pv(tomatch, cnc, pvclass);
}

static int w_phonenum_match_cn(sip_msg_t *msg, char *target, char *cncstr,
char *pvname)
static int w_phonenum_match_cn(
sip_msg_t *msg, char *target, char *cncstr, char *pvname)
{
str tomatch = STR_NULL;
str pvclass = STR_NULL;
Expand Down
28 changes: 14 additions & 14 deletions src/modules/phonenum/phonenum_pv.c
Expand Up @@ -113,7 +113,7 @@ sr_phonenum_item_t *sr_phonenum_add_item(str *name)

int sr_phonenum_add_resid(str *rname)
{
if(sr_phonenum_add_item(rname)==NULL) {
if(sr_phonenum_add_item(rname) == NULL) {
return -1;
}
return 0;
Expand Down Expand Up @@ -239,37 +239,37 @@ int pv_get_phonenum(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
return -1;
if(gpv->item == NULL)
return pv_get_null(msg, param, res);
if(gpv->item->r.record==NULL)
if(gpv->item->r.record == NULL)
return pv_get_null(msg, param, res);

switch(gpv->type) {
case 1: /* normalized */
if(gpv->item->r.record->normalized==NULL)
if(gpv->item->r.record->normalized == NULL)
return pv_get_null(msg, param, res);
return pv_get_strzval(msg, param, res,
gpv->item->r.record->normalized);
return pv_get_strzval(
msg, param, res, gpv->item->r.record->normalized);
case 2: /* ltype */
if(gpv->item->r.record->ltype==NULL)
if(gpv->item->r.record->ltype == NULL)
return pv_get_null(msg, param, res);
return pv_get_strzval(msg, param, res, gpv->item->r.record->ltype);
case 3: /* ndesc */
if(gpv->item->r.record->ndesc==NULL)
if(gpv->item->r.record->ndesc == NULL)
return pv_get_null(msg, param, res);
return pv_get_strzval(msg, param, res, gpv->item->r.record->ndesc);
case 4: /* error */
if(gpv->item->r.record->error==NULL)
if(gpv->item->r.record->error == NULL)
return pv_get_null(msg, param, res);
return pv_get_strzval(msg, param, res, gpv->item->r.record->error);
case 5: /* cctel */
return pv_get_sintval(msg, param, res, gpv->item->r.record->cctel);
case 6: /* valid */
return pv_get_sintval(msg, param, res, gpv->item->r.record->valid);
case 7: /* ccname */
if(gpv->item->r.record->ccname==NULL)
if(gpv->item->r.record->ccname == NULL)
return pv_get_null(msg, param, res);
return pv_get_strzval(msg, param, res, gpv->item->r.record->ccname);
default: /* number */
if(gpv->item->r.record->number==NULL)
if(gpv->item->r.record->number == NULL)
return pv_get_null(msg, param, res);
return pv_get_strzval(msg, param, res, gpv->item->r.record->number);
}
Expand Down Expand Up @@ -323,16 +323,16 @@ int phonenum_update_pv(str *tomatch, str *cncode, str *name)
strncpy(gr->tomatch, tomatch->s, tomatch->len);
gr->tomatch[tomatch->len] = '\0';
LM_DBG("attempt to match: %s\n", gr->tomatch);
gr->record = telnum_parse(gr->tomatch,
(cncode && cncode->len>0)?cncode->s:"ZZ");
gr->record = telnum_parse(
gr->tomatch, (cncode && cncode->len > 0) ? cncode->s : "ZZ");
if(gr->record == NULL) {
LM_DBG("no match for: %s\n", gr->tomatch);
return -2;
}
LM_DBG("phonenum PV updated for: %s (%d/%s/%s)\n", gr->tomatch,
gr->record->valid,
(gr->record->normalized)?gr->record->normalized:"none",
(gr->record->error)?gr->record->error:"none");
(gr->record->normalized) ? gr->record->normalized : "none",
(gr->record->error) ? gr->record->error : "none");

return 1;
}
4 changes: 1 addition & 3 deletions src/modules/phonenum/phonenum_pv.h
Expand Up @@ -27,8 +27,7 @@
#include "../../core/pvar.h"

int pv_parse_phonenum_name(pv_spec_p sp, str *in);
int pv_get_phonenum(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res);
int pv_get_phonenum(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);

int phonenum_init_pv(int smode);
void phonenum_destroy_pv(void);
Expand All @@ -37,4 +36,3 @@ int phonenum_update_pv(str *tomatch, str *cncode, str *pvclass);
int sr_phonenum_add_resid(str *rname);

#endif

0 comments on commit 1560509

Please sign in to comment.