浏览代码

secfilter: add "secf_" prefix to generic RPC and DB functions, use static

- add "secf_" prefix to generic RPC and DB functions
- add static qualifier to internal check_version and append_str_list functions
Henning Westerholt 6 年之前
父节点
当前提交
2ebd6a5b85

+ 9 - 9
src/modules/secfilter/secfilter.c

@@ -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 */
 
 /***
@@ -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) {
@@ -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;
 	}
@@ -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);
 

+ 10 - 10
src/modules/secfilter/secfilter.h

@@ -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);
@@ -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;
@@ -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

+ 6 - 6
src/modules/secfilter/secfilter_db.c

@@ -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");
 
@@ -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;
@@ -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;
@@ -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;
@@ -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);
@@ -253,7 +253,7 @@ clean:
 
 
 /* Init database connection */
-int init_db(void)
+int secf_init_db(void)
 {
 	if(secf_db_url.s == NULL) {
 		LM_ERR("Database not configured\n");

+ 5 - 5
src/modules/secfilter/secfilter_rpc.c

@@ -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 {
@@ -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 {
@@ -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 {
@@ -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");