Skip to content

Commit

Permalink
auth_diameter: 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 5eed243 commit 63b1928
Show file tree
Hide file tree
Showing 11 changed files with 974 additions and 1,123 deletions.
149 changes: 67 additions & 82 deletions src/modules/auth_diameter/auth_diameter.c
Expand Up @@ -27,7 +27,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <netdb.h>

#include "../../core/sr_module.h"
#include "../../core/error.h"
Expand All @@ -46,19 +46,19 @@ MODULE_VERSION
/** SL API structure */
sl_api_t slb;

static int mod_init(void); /* Module initialization function*/
static int mod_child_init(int r); /* Child initialization function*/
static int auth_fixup(void** param, int param_no);
static int group_fixup(void** param, int param_no);
static int mod_init(void); /* Module initialization function*/
static int mod_child_init(int r); /* Child initialization function*/
static int auth_fixup(void **param, int param_no);
static int group_fixup(void **param, int param_no);

int diameter_www_authorize(struct sip_msg* _msg, char* _realm, char* _s2);
int diameter_proxy_authorize(struct sip_msg* _msg, char* _realm, char* _s2);
int diameter_is_user_in(struct sip_msg* _msg, char* group, char* _s2);
int diameter_www_authorize(struct sip_msg *_msg, char *_realm, char *_s2);
int diameter_proxy_authorize(struct sip_msg *_msg, char *_realm, char *_s2);
int diameter_is_user_in(struct sip_msg *_msg, char *group, char *_s2);

/*
* Module parameter variables
*/
char* diameter_client_host = "localhost";
char *diameter_client_host = "localhost";
int diameter_client_port = 3000;
int use_domain = 0;
int sockfd = -1;
Expand All @@ -69,41 +69,37 @@ rd_buf_t *rb;
* Exported functions
*/
static cmd_export_t cmds[] = {
{"diameter_www_authorize", (cmd_function)diameter_www_authorize, 1, auth_fixup,
0, REQUEST_ROUTE},
{"diameter_proxy_authorize", (cmd_function)diameter_proxy_authorize, 1, auth_fixup,
0, REQUEST_ROUTE},
{"diameter_is_user_in", (cmd_function)diameter_is_user_in, 2, group_fixup,
0, REQUEST_ROUTE},
{0, 0, 0, 0, 0, 0}
};
{"diameter_www_authorize", (cmd_function)diameter_www_authorize, 1,
auth_fixup, 0, REQUEST_ROUTE},
{"diameter_proxy_authorize", (cmd_function)diameter_proxy_authorize, 1,
auth_fixup, 0, REQUEST_ROUTE},
{"diameter_is_user_in", (cmd_function)diameter_is_user_in, 2,
group_fixup, 0, REQUEST_ROUTE},
{0, 0, 0, 0, 0, 0}};


/*
* Exported parameters
*/
static param_export_t params[] = {
{"diameter_client_host", PARAM_STRING, &diameter_client_host},
{"diameter_client_port", INT_PARAM, &diameter_client_port},
{"use_domain", INT_PARAM, &use_domain},
{0, 0, 0}
};
{"diameter_client_host", PARAM_STRING, &diameter_client_host},
{"diameter_client_port", INT_PARAM, &diameter_client_port},
{"use_domain", INT_PARAM, &use_domain}, {0, 0, 0}};


/*
* Module interface
*/
struct module_exports exports = {
"auth_diameter",
DEFAULT_DLFLAGS, /* dlopen flags */
cmds, /* Exported functions */
params, /* Exported parameters */
0, /* exported RPC methods */
0, /* exported pseudo-variables */
0, /* response function */
mod_init, /* module initialization function */
mod_child_init, /* child initialization function */
0 /* destroy function */
"auth_diameter", DEFAULT_DLFLAGS, /* dlopen flags */
cmds, /* Exported functions */
params, /* Exported parameters */
0, /* exported RPC methods */
0, /* exported pseudo-variables */
0, /* response function */
mod_init, /* module initialization function */
mod_child_init, /* child initialization function */
0 /* destroy function */
};


Expand All @@ -115,31 +111,29 @@ static int mod_init(void)
LM_DBG("auth_diameter - Initializing\n");

/* bind the SL API */
if (sl_load_api(&slb)!=0) {
if(sl_load_api(&slb) != 0) {
LM_ERR("cannot bind to SL API\n");
return -1;
}

return 0;
}

static int mod_child_init(int r)
{
{
/* open TCP connection */
LM_DBG("initializing TCP connection\n");

sockfd = init_mytcp(diameter_client_host, diameter_client_port);
if(sockfd==-1)
{
if(sockfd == -1) {
LM_DBG("the TCP connection was not established\n");
return -1;
}

LM_DBG("the TCP connection was established on socket=%d\n", sockfd);

rb = (rd_buf_t*)pkg_malloc(sizeof(rd_buf_t));
if(!rb)
{

rb = (rd_buf_t *)pkg_malloc(sizeof(rd_buf_t));
if(!rb) {
PKG_MEM_ERROR;
return -1;
}
Expand All @@ -160,23 +154,23 @@ static void destroy(void)
/*
* Convert char* parameter to pv_elem_t* parameter
*/
static int auth_fixup(void** param, int param_no)
static int auth_fixup(void **param, int param_no)
{
pv_elem_t *model;
str s;

if (param_no == 1) {
s.s = (char*)*param;
if (s.s==0 || s.s[0]==0) {
if(param_no == 1) {
s.s = (char *)*param;
if(s.s == 0 || s.s[0] == 0) {
model = 0;
} else {
s.len = strlen(s.s);
if (pv_parse_format(&s,&model)<0) {
if(pv_parse_format(&s, &model) < 0) {
LM_ERR("pv_parse_format failed\n");
return E_OUT_OF_MEM;
}
}
*param = (void*)model;
*param = (void *)model;
}

return 0;
Expand All @@ -186,71 +180,62 @@ static int auth_fixup(void** param, int param_no)
/*
* Authorize using Proxy-Authorization header field
*/
int diameter_proxy_authorize(struct sip_msg* _msg, char* _realm, char* _s2)
int diameter_proxy_authorize(struct sip_msg *_msg, char *_realm, char *_s2)
{
/* realm parameter is converted in fixup */
return authorize(_msg, (pv_elem_t*)_realm, HDR_PROXYAUTH_T);
return authorize(_msg, (pv_elem_t *)_realm, HDR_PROXYAUTH_T);
}


/*
* Authorize using WWW-Authorization header field
*/
int diameter_www_authorize(struct sip_msg* _msg, char* _realm, char* _s2)
int diameter_www_authorize(struct sip_msg *_msg, char *_realm, char *_s2)
{
return authorize(_msg, (pv_elem_t*)_realm, HDR_AUTHORIZATION_T);
return authorize(_msg, (pv_elem_t *)_realm, HDR_AUTHORIZATION_T);
}


static int group_fixup(void** param, int param_no)
static int group_fixup(void **param, int param_no)
{
str* s;
str *s;

if (param_no == 1)
{
if (!strcasecmp((char*)*param, "Request-URI"))
{
*param = (void*)1;
if(param_no == 1) {
if(!strcasecmp((char *)*param, "Request-URI")) {
*param = (void *)1;
goto end;
}
}

if(!strcasecmp((char*)*param, "To"))
{
*param = (void*)2;
if(!strcasecmp((char *)*param, "To")) {
*param = (void *)2;
goto end;
}
}

if (!strcasecmp((char*)*param, "From"))
{
*param = (void*)3;
if(!strcasecmp((char *)*param, "From")) {
*param = (void *)3;
goto end;
}
}

if (!strcasecmp((char*)*param, "Credentials"))
{
*param = (void*)4;
if(!strcasecmp((char *)*param, "Credentials")) {
*param = (void *)4;
goto end;
}

LM_ERR("unsupported Header Field identifier\n");
return E_UNSPEC;
}

if (param_no == 2)
{
s = (str*)pkg_malloc(sizeof(str));
if (!s)
{
}

if(param_no == 2) {
s = (str *)pkg_malloc(sizeof(str));
if(!s) {
PKG_MEM_ERROR;
return E_UNSPEC;
}
s->s = (char*)*param;
s->s = (char *)*param;
s->len = strlen(s->s);
*param = (void*)s;
*param = (void *)s;
}

end:
return 0;
}


1 change: 0 additions & 1 deletion src/modules/auth_diameter/auth_diameter.h
Expand Up @@ -41,4 +41,3 @@ extern rd_buf_t *rb;


#endif /* AUTHDIAM_MOD_H */

0 comments on commit 63b1928

Please sign in to comment.