Skip to content

Commit

Permalink
secfilter: add "secf_" prefix to generic RPC and DB functions, use st…
Browse files Browse the repository at this point in the history
…atic

- add "secf_" prefix to generic RPC and DB functions
- add static qualifier to internal check_version and append_str_list functions
  • Loading branch information
henningw committed Jan 1, 2019
1 parent 5b259f6 commit 2ebd6a5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
18 changes: 9 additions & 9 deletions src/modules/secfilter/secfilter.c
Expand Up @@ -117,11 +117,11 @@ static const char *rpc_add_bl_doc[2] = {"Add new values to blacklist", NULL};
static const char *rpc_add_wl_doc[2] = {"Add new values to whitelist", NULL};

rpc_export_t secfilter_rpc[] = {
{"secfilter.reload", rpc_reload, rpc_reload_doc, 0},
{"secfilter.print", rpc_print, rpc_print_doc, 0},
{"secfilter.add_dst", rpc_add_dst, rpc_add_dst_doc, 0},
{"secfilter.add_bl", rpc_add_bl, rpc_add_bl_doc, 0},
{"secfilter.add_wl", rpc_add_wl, rpc_add_wl_doc, 0}, {0, 0, 0, 0}};
{"secfilter.reload", secf_rpc_reload, rpc_reload_doc, 0},
{"secfilter.print", secf_rpc_print, rpc_print_doc, 0},
{"secfilter.add_dst", secf_rpc_add_dst, rpc_add_dst_doc, 0},
{"secfilter.add_bl", secf_rpc_add_bl, rpc_add_bl_doc, 0},
{"secfilter.add_wl", secf_rpc_add_wl, rpc_add_wl_doc, 0}, {0, 0, 0, 0}};
/* clang-format on */

/***
Expand Down Expand Up @@ -600,7 +600,7 @@ INIT AND DESTROY FUNCTIONS
***/

/* Initialize data */
int init_data(void)
int secf_init_data(void)
{
secf_data = (secf_data_p)shm_malloc(sizeof(secf_data_t));
if(!secf_data) {
Expand Down Expand Up @@ -632,10 +632,10 @@ static int mod_init(void)
return -1;
}
/* Init database connection and check version */
if(init_db() == -1)
if(secf_init_db() == -1)
return -1;
/* Load data from database */
if(load_db() == -1) {
if(secf_load_db() == -1) {
LM_ERR("Error loading data from database\n");
return -1;
}
Expand Down Expand Up @@ -713,7 +713,7 @@ static void free_sec_info(secf_info_p info)
}


void free_data(void)
void secf_free_data(void)
{
lock_get(&secf_data->lock);

Expand Down
20 changes: 10 additions & 10 deletions src/modules/secfilter/secfilter.h
Expand Up @@ -26,7 +26,7 @@ typedef struct _secf_data

extern secf_data_p secf_data;

int append_rule(int action, int type, str *value);
int secf_append_rule(int action, int type, str *value);

/* Get header values from message */
int secf_get_ua(struct sip_msg *msg, str *ua);
Expand All @@ -35,10 +35,10 @@ int secf_get_to(struct sip_msg *msg, str *name, str *user, str *domain);
int secf_get_contact(struct sip_msg *msg, str *user, str *domain);

/* Database functions */
int init_db(void);
int init_data(void);
void free_data(void);
int load_db(void);
int secf_init_db(void);
int secf_init_data(void);
void secf_free_data(void);
int secf_load_db(void);

/* Extern variables */
extern str secf_db_url;
Expand All @@ -49,10 +49,10 @@ extern str secf_data_col;
extern int secf_dst_exact_match;

/* RPC commands */
void rpc_reload(rpc_t *rpc, void *ctx);
void rpc_print(rpc_t *rpc, void *ctx);
void rpc_add_dst(rpc_t *rpc, void *ctx);
void rpc_add_bl(rpc_t *rpc, void *ctx);
void rpc_add_wl(rpc_t *rpc, void *ctx);
void secf_rpc_reload(rpc_t *rpc, void *ctx);
void secf_rpc_print(rpc_t *rpc, void *ctx);
void secf_rpc_add_dst(rpc_t *rpc, void *ctx);
void secf_rpc_add_bl(rpc_t *rpc, void *ctx);
void secf_rpc_add_wl(rpc_t *rpc, void *ctx);

#endif
12 changes: 6 additions & 6 deletions src/modules/secfilter/secfilter_db.c
Expand Up @@ -33,7 +33,7 @@ static db1_con_t *db_handle = 0; /* Database connection handle */


/* Check module version */
int check_version(void)
static int check_version(void)
{
str table = str_init("secfilter");

Expand Down Expand Up @@ -65,7 +65,7 @@ int check_version(void)
* @param total length of total characters in list
* @return extended list
**/
struct str_list *shm_append_str_list(
static struct str_list *shm_append_str_list(
char *s, int len, struct str_list **last, int *total)
{
struct str_list *new;
Expand Down Expand Up @@ -99,7 +99,7 @@ struct str_list *shm_append_str_list(
3 = IP address
4 = user
**/
int append_rule(int action, int type, str *value)
int secf_append_rule(int action, int type, str *value)
{
secf_info_p ini = NULL;
secf_info_p last = NULL;
Expand Down Expand Up @@ -182,7 +182,7 @@ int append_rule(int action, int type, str *value)


/* Load data from database */
int load_db(void)
int secf_load_db(void)
{
db_key_t db_cols[3];
db1_res_t *db_res = NULL;
Expand Down Expand Up @@ -232,7 +232,7 @@ int load_db(void)
LM_DBG("[%d] append_rule for action:%d type:%d data:%.*s\n", i, action,
type, str_data.len, str_data.s);

if(append_rule(action, type, &str_data) < 0) {
if(secf_append_rule(action, type, &str_data) < 0) {
LM_ERR("Can't append_rule with action:%d type:%d\n", action, type);
res = -1;
lock_release(&secf_data->lock);
Expand All @@ -253,7 +253,7 @@ int load_db(void)


/* Init database connection */
int init_db(void)
int secf_init_db(void)
{
if(secf_db_url.s == NULL) {
LM_ERR("Database not configured\n");
Expand Down
10 changes: 5 additions & 5 deletions src/modules/secfilter/secfilter_rpc.c
Expand Up @@ -76,7 +76,7 @@ void rpc_add_dst(rpc_t *rpc, void *ctx)
}
memcpy(data.s, text, data.len);
lock_get(&secf_data->lock);
if(append_rule(2, 0, &data) == 0) {
if(secf_append_rule(2, 0, &data) == 0) {
rpc->rpl_printf(ctx,
"Values (%s) inserted into blacklist destinations", data);
} else {
Expand Down Expand Up @@ -105,7 +105,7 @@ void rpc_add_bl(rpc_t *rpc, void *ctx)
type = get_type(ctype);

lock_get(&secf_data->lock);
if(append_rule(0, type, &data) == 0) {
if(secf_append_rule(0, type, &data) == 0) {
rpc->rpl_printf(ctx, "Values (%s, %s) inserted into blacklist",
ctype, data);
} else {
Expand Down Expand Up @@ -133,7 +133,7 @@ void rpc_add_wl(rpc_t *rpc, void *ctx)
type = get_type(ctype);

lock_get(&secf_data->lock);
if(append_rule(1, type, &data) == 0) {
if(secf_append_rule(1, type, &data) == 0) {
rpc->rpl_printf(
ctx, "Values (%s, %s) inserted into whitelist", type, data);
} else {
Expand All @@ -144,9 +144,9 @@ void rpc_add_wl(rpc_t *rpc, void *ctx)


/* Reload arrays */
void rpc_reload(rpc_t *rpc, void *ctx)
void secf_rpc_reload(rpc_t *rpc, void *ctx)
{
free_data();
secf_free_data();

if(load_db() == -1) {
LM_ERR("Error loading data from database\n");
Expand Down

0 comments on commit 2ebd6a5

Please sign in to comment.