permissions: use perm prefix for global param variables
authorDaniel-Constantin Mierla <miconda@gmail.com>
Fri, 1 May 2020 11:50:54 +0000 (13:50 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Fri, 1 May 2020 11:50:54 +0000 (13:50 +0200)
src/modules/permissions/address.c
src/modules/permissions/address.h
src/modules/permissions/hash.c
src/modules/permissions/permissions.c
src/modules/permissions/permissions.h
src/modules/permissions/rpc.c
src/modules/permissions/trusted.c
src/modules/permissions/trusted.h

index 6cbc8c4..6120392 100644 (file)
 
 #define TABLE_VERSION 6
 
-struct addr_list ***addr_hash_table = NULL; /* Ptr to current hash table ptr */
-struct addr_list **addr_hash_table_1 = NULL; /* Pointer to hash table 1 */
-struct addr_list **addr_hash_table_2 = NULL; /* Pointer to hash table 2 */
+struct addr_list ***perm_addr_table = NULL; /* Ptr to current address hash table ptr */
+struct addr_list **perm_addr_table_1 = NULL; /* Pointer to address hash table 1 */
+struct addr_list **perm_addr_table_2 = NULL; /* Pointer to address hash table 2 */
 
-struct subnet **subnet_table = NULL;  /* Ptr to current subnet table */
-struct subnet *subnet_table_1 = NULL; /* Ptr to subnet table 1 */
-struct subnet *subnet_table_2 = NULL; /* Ptr to subnet table 2 */
+struct subnet **perm_subnet_table = NULL;  /* Ptr to current subnet table */
+struct subnet *perm_subnet_table_1 = NULL; /* Ptr to subnet table 1 */
+struct subnet *perm_subnet_table_2 = NULL; /* Ptr to subnet table 2 */
 
-struct domain_name_list ***domain_list_table = NULL; /* Ptr to current domain name table */
-static struct domain_name_list **domain_list_table_1 = NULL; /* Ptr to domain name table 1 */
-static struct domain_name_list **domain_list_table_2 = NULL; /* Ptr to domain name table 2 */
+struct domain_name_list ***perm_domain_table = NULL; /* Ptr to current domain name table */
+static struct domain_name_list **perm_domain_table_1 = NULL; /* Ptr to domain name table 1 */
+static struct domain_name_list **perm_domain_table_2 = NULL; /* Ptr to domain name table 2 */
 
-static db1_con_t* db_handle = 0;
+static db1_con_t* perm_db_handle = 0;
 static db_func_t perm_dbf;
 
-extern str address_file;
+extern str perm_address_file;
 
 typedef struct address_tables_group {
        struct addr_list **address_table;
@@ -158,18 +158,18 @@ int reload_address_db_table(address_tables_group_t *atg)
        str ips;
        str tagv;
 
-       cols[0] = &grp_col;
-       cols[1] = &ip_addr_col;
-       cols[2] = &mask_col;
-       cols[3] = &port_col;
-       cols[4] = &tag_col;
+       cols[0] = &perm_grp_col;
+       cols[1] = &perm_ip_addr_col;
+       cols[2] = &perm_mask_col;
+       cols[3] = &perm_port_col;
+       cols[4] = &perm_tag_col;
 
-       if (perm_dbf.use_table(db_handle, &address_table) < 0) {
+       if (perm_dbf.use_table(perm_db_handle, &perm_address_table) < 0) {
                LM_ERR("failed to use table\n");
                return -1;
        }
 
-       if (perm_dbf.query(db_handle, NULL, 0, NULL, cols, 0, 5, 0, &res) < 0) {
+       if (perm_dbf.query(perm_db_handle, NULL, 0, NULL, cols, 0, 5, 0, &res) < 0) {
                LM_ERR("failed to query database\n");
                return -1;
        }
@@ -225,13 +225,13 @@ int reload_address_db_table(address_tables_group_t *atg)
                }
        }
 
-       perm_dbf.free_result(db_handle, res);
+       perm_dbf.free_result(perm_db_handle, res);
 
        return 1;
 
 dberror:
        LM_ERR("database problem - invalid record\n");
-       perm_dbf.free_result(db_handle, res);
+       perm_dbf.free_result(perm_db_handle, res);
        return -1;
 }
 
@@ -284,9 +284,9 @@ int reload_address_file_table(address_tables_group_t *atg)
        str ips;
        str tagv;
 
-       f = fopen(address_file.s, "r");
+       f = fopen(perm_address_file.s, "r");
        if(f == NULL) {
-               LM_ERR("can't open list file [%s]\n", address_file.s);
+               LM_ERR("can't open list file [%s]\n", perm_address_file.s);
                return -1;
        }
 
@@ -342,8 +342,8 @@ next_line:
                p = fgets(line, 1024, f);
        }
 
-       LM_DBG("processed file: %s (%d lines)- added %d records\n", address_file.s,
-                       i, n);
+       LM_DBG("processed file: %s (%d lines)- added %d records\n",
+                       perm_address_file.s, i, n);
 
        fclose(f);
        return 1;
@@ -366,33 +366,33 @@ int reload_address_table(void)
        address_tables_group_t atg;
 
        /* Choose new hash table and free its old contents */
-       if (*addr_hash_table == addr_hash_table_1) {
-               empty_addr_hash_table(addr_hash_table_2);
-               atg.address_table = addr_hash_table_2;
+       if (*perm_addr_table == perm_addr_table_1) {
+               empty_addr_hash_table(perm_addr_table_2);
+               atg.address_table = perm_addr_table_2;
        } else {
-               empty_addr_hash_table(addr_hash_table_1);
-               atg.address_table = addr_hash_table_1;
+               empty_addr_hash_table(perm_addr_table_1);
+               atg.address_table = perm_addr_table_1;
        }
 
        /* Choose new subnet table */
-       if (*subnet_table == subnet_table_1) {
-               empty_subnet_table(subnet_table_2);
-               atg.subnet_table = subnet_table_2;
+       if (*perm_subnet_table == perm_subnet_table_1) {
+               empty_subnet_table(perm_subnet_table_2);
+               atg.subnet_table = perm_subnet_table_2;
        } else {
-               empty_subnet_table(subnet_table_1);
-               atg.subnet_table = subnet_table_1;
+               empty_subnet_table(perm_subnet_table_1);
+               atg.subnet_table = perm_subnet_table_1;
        }
 
        /* Choose new domain name table */
-       if (*domain_list_table == domain_list_table_1) {
-               empty_domain_name_table(domain_list_table_2);
-               atg.domain_table = domain_list_table_2;
+       if (*perm_domain_table == perm_domain_table_1) {
+               empty_domain_name_table(perm_domain_table_2);
+               atg.domain_table = perm_domain_table_2;
        } else {
-               empty_domain_name_table(domain_list_table_1);
-               atg.domain_table = domain_list_table_1;
+               empty_domain_name_table(perm_domain_table_1);
+               atg.domain_table = perm_domain_table_1;
        }
 
-       if(address_file.s==NULL) {
+       if(perm_address_file.s==NULL) {
                ret = reload_address_db_table(&atg);
        } else {
                ret = reload_address_file_table(&atg);
@@ -401,9 +401,9 @@ int reload_address_table(void)
                return ret;
        }
 
-       *addr_hash_table = atg.address_table;
-       *subnet_table = atg.subnet_table;
-       *domain_list_table = atg.domain_table;
+       *perm_addr_table = atg.address_table;
+       *perm_subnet_table = atg.subnet_table;
+       *perm_domain_table = atg.domain_table;
 
        LM_DBG("address table reloaded successfully.\n");
 
@@ -417,15 +417,15 @@ int reload_address_table(void)
  */
 int reload_address_table_cmd(void)
 {
-       if(address_file.s==NULL) {
-               if(!db_url.s) {
+       if(perm_address_file.s==NULL) {
+               if(!perm_db_url.s) {
                        LM_ERR("db_url not set\n");
                        return -1;
                }
 
-               if (!db_handle) {
-                       db_handle = perm_dbf.init(&db_url);
-                       if (!db_handle) {
+               if (!perm_db_handle) {
+                       perm_db_handle = perm_dbf.init(&perm_db_url);
+                       if (!perm_db_handle) {
                                LM_ERR("unable to connect database\n");
                                return -1;
                        }
@@ -433,16 +433,16 @@ int reload_address_table_cmd(void)
        }
 
        if (reload_address_table () != 1) {
-               if(address_file.s==NULL) {
-                       perm_dbf.close(db_handle);
-                       db_handle = 0;
+               if(perm_address_file.s==NULL) {
+                       perm_dbf.close(perm_db_handle);
+                       perm_db_handle = 0;
                }
                return -1;
        }
 
-       if(address_file.s==NULL) {
-               perm_dbf.close(db_handle);
-               db_handle = 0;
+       if(perm_address_file.s==NULL) {
+               perm_dbf.close(perm_db_handle);
+               perm_db_handle = 0;
        }
 
        return 1;
@@ -453,16 +453,16 @@ int reload_address_table_cmd(void)
  */
 int init_addresses(void)
 {
-       addr_hash_table_1 = addr_hash_table_2 = 0;
-       addr_hash_table = 0;
+       perm_addr_table_1 = perm_addr_table_2 = 0;
+       perm_addr_table = 0;
 
-       if(address_file.s==NULL) {
-               if (!db_url.s) {
+       if(perm_address_file.s==NULL) {
+               if (!perm_db_url.s) {
                        LM_INFO("db_url parameter of permissions module not set, "
                                        "disabling allow_address\n");
                        return 0;
                } else {
-                       if (db_bind_mod(&db_url, &perm_dbf) < 0) {
+                       if (db_bind_mod(&perm_db_url, &perm_dbf) < 0) {
                                LM_ERR("load a database support module\n");
                                return -1;
                        }
@@ -473,62 +473,63 @@ int init_addresses(void)
                        }
                }
 
-               db_handle = perm_dbf.init(&db_url);
-               if (!db_handle) {
+               perm_db_handle = perm_dbf.init(&perm_db_url);
+               if (!perm_db_handle) {
                        LM_ERR("unable to connect database\n");
                        return -1;
                }
 
-               if(db_check_table_version(&perm_dbf, db_handle, &address_table, TABLE_VERSION) < 0) {
-                       DB_TABLE_VERSION_ERROR(address_table);
-                       perm_dbf.close(db_handle);
-                       db_handle = 0;
+               if(db_check_table_version(&perm_dbf, perm_db_handle, &perm_address_table,
+                                       TABLE_VERSION) < 0) {
+                       DB_TABLE_VERSION_ERROR(perm_address_table);
+                       perm_dbf.close(perm_db_handle);
+                       perm_db_handle = 0;
                        return -1;
                }
        }
 
-       addr_hash_table_1 = new_addr_hash_table();
-       if (!addr_hash_table_1) return -1;
+       perm_addr_table_1 = new_addr_hash_table();
+       if (!perm_addr_table_1) return -1;
 
-       addr_hash_table_2  = new_addr_hash_table();
-       if (!addr_hash_table_2) goto error;
+       perm_addr_table_2  = new_addr_hash_table();
+       if (!perm_addr_table_2) goto error;
 
-       addr_hash_table = (struct addr_list ***)shm_malloc
+       perm_addr_table = (struct addr_list ***)shm_malloc
                (sizeof(struct addr_list **));
-       if (!addr_hash_table) {
+       if (!perm_addr_table) {
                LM_ERR("no more shm memory for addr_hash_table\n");
                goto error;
        }
 
-       *addr_hash_table = addr_hash_table_1;
+       *perm_addr_table = perm_addr_table_1;
 
-       subnet_table_1 = new_subnet_table();
-       if (!subnet_table_1) goto error;
+       perm_subnet_table_1 = new_subnet_table();
+       if (!perm_subnet_table_1) goto error;
 
-       subnet_table_2 = new_subnet_table();
-       if (!subnet_table_2) goto error;
+       perm_subnet_table_2 = new_subnet_table();
+       if (!perm_subnet_table_2) goto error;
 
-       subnet_table = (struct subnet **)shm_malloc(sizeof(struct subnet *));
-       if (!subnet_table) {
+       perm_subnet_table = (struct subnet **)shm_malloc(sizeof(struct subnet *));
+       if (!perm_subnet_table) {
                LM_ERR("no more shm memory for subnet_table\n");
                goto error;
        }
 
-       *subnet_table = subnet_table_1;
+       *perm_subnet_table = perm_subnet_table_1;
 
-       domain_list_table_1 = new_domain_name_table();
-       if (!domain_list_table_1) goto error;
+       perm_domain_table_1 = new_domain_name_table();
+       if (!perm_domain_table_1) goto error;
 
-       domain_list_table_2 = new_domain_name_table();
-       if (!domain_list_table_2) goto error;
+       perm_domain_table_2 = new_domain_name_table();
+       if (!perm_domain_table_2) goto error;
 
-       domain_list_table = (struct domain_name_list ***)shm_malloc(sizeof(struct domain_name_list **));
-       if (!domain_list_table) {
+       perm_domain_table = (struct domain_name_list ***)shm_malloc(sizeof(struct domain_name_list **));
+       if (!perm_domain_table) {
                LM_ERR("no more shm memory for domain name table\n");
                goto error;
        }
 
-       *domain_list_table = domain_list_table_1;
+       *perm_domain_table = perm_domain_table_1;
 
 
        if (reload_address_table() == -1) {
@@ -536,55 +537,55 @@ int init_addresses(void)
                goto error;
        }
 
-       if(address_file.s==NULL) {
-               perm_dbf.close(db_handle);
-               db_handle = 0;
+       if(perm_address_file.s==NULL) {
+               perm_dbf.close(perm_db_handle);
+               perm_db_handle = 0;
        }
 
        return 0;
 
 error:
-       if (addr_hash_table_1) {
-               free_addr_hash_table(addr_hash_table_1);
-               addr_hash_table_1 = 0;
+       if (perm_addr_table_1) {
+               free_addr_hash_table(perm_addr_table_1);
+               perm_addr_table_1 = 0;
        }
-       if (addr_hash_table_2) {
-               free_addr_hash_table(addr_hash_table_2);
-               addr_hash_table_2 = 0;
+       if (perm_addr_table_2) {
+               free_addr_hash_table(perm_addr_table_2);
+               perm_addr_table_2 = 0;
        }
-       if (addr_hash_table) {
-               shm_free(addr_hash_table);
-               addr_hash_table = 0;
+       if (perm_addr_table) {
+               shm_free(perm_addr_table);
+               perm_addr_table = 0;
        }
-       if (subnet_table_1) {
-               free_subnet_table(subnet_table_1);
-               subnet_table_1 = 0;
+       if (perm_subnet_table_1) {
+               free_subnet_table(perm_subnet_table_1);
+               perm_subnet_table_1 = 0;
        }
-       if (subnet_table_2) {
-               free_subnet_table(subnet_table_2);
-               subnet_table_2 = 0;
+       if (perm_subnet_table_2) {
+               free_subnet_table(perm_subnet_table_2);
+               perm_subnet_table_2 = 0;
        }
-       if (subnet_table) {
-               shm_free(subnet_table);
-               subnet_table = 0;
+       if (perm_subnet_table) {
+               shm_free(perm_subnet_table);
+               perm_subnet_table = 0;
        }
 
-       if (domain_list_table_1) {
-               free_domain_name_table(domain_list_table_1);
-               domain_list_table_1 = 0;
+       if (perm_domain_table_1) {
+               free_domain_name_table(perm_domain_table_1);
+               perm_domain_table_1 = 0;
        }
-       if (domain_list_table_2) {
-               free_domain_name_table(domain_list_table_2);
-               domain_list_table_2 = 0;
+       if (perm_domain_table_2) {
+               free_domain_name_table(perm_domain_table_2);
+               perm_domain_table_2 = 0;
        }
-       if (domain_list_table) {
-               shm_free(domain_list_table);
-               domain_list_table = 0;
+       if (perm_domain_table) {
+               shm_free(perm_domain_table);
+               perm_domain_table = 0;
        }
 
-       if(address_file.s==NULL) {
-               perm_dbf.close(db_handle);
-               db_handle = 0;
+       if(perm_address_file.s==NULL) {
+               perm_dbf.close(perm_db_handle);
+               perm_db_handle = 0;
        }
        return -1;
 }
@@ -595,15 +596,15 @@ error:
  */
 void clean_addresses(void)
 {
-       if (addr_hash_table_1) free_addr_hash_table(addr_hash_table_1);
-       if (addr_hash_table_2) free_addr_hash_table(addr_hash_table_2);
-       if (addr_hash_table) shm_free(addr_hash_table);
-       if (subnet_table_1) free_subnet_table(subnet_table_1);
-       if (subnet_table_2) free_subnet_table(subnet_table_2);
-       if (subnet_table) shm_free(subnet_table);
-       if (domain_list_table_1) free_domain_name_table(domain_list_table_1);
-       if (domain_list_table_2) free_domain_name_table(domain_list_table_2);
-       if (domain_list_table) shm_free(domain_list_table);
+       if (perm_addr_table_1) free_addr_hash_table(perm_addr_table_1);
+       if (perm_addr_table_2) free_addr_hash_table(perm_addr_table_2);
+       if (perm_addr_table) shm_free(perm_addr_table);
+       if (perm_subnet_table_1) free_subnet_table(perm_subnet_table_1);
+       if (perm_subnet_table_2) free_subnet_table(perm_subnet_table_2);
+       if (perm_subnet_table) shm_free(perm_subnet_table);
+       if (perm_domain_table_1) free_domain_name_table(perm_domain_table_1);
+       if (perm_domain_table_2) free_domain_name_table(perm_domain_table_2);
+       if (perm_domain_table) shm_free(perm_domain_table);
 }
 
 
@@ -614,19 +615,19 @@ int allow_address(sip_msg_t *_msg, int addr_group, str *ips, int port)
        ipa=strtoipX(ips);
 
        if ( ipa ) {
-               if (addr_hash_table
-                               && match_addr_hash_table(*addr_hash_table, addr_group,
+               if (perm_addr_table
+                               && match_addr_hash_table(*perm_addr_table, addr_group,
                                        ipa, (unsigned int)port) == 1) {
                        return 1;
                } else {
-                       if(subnet_table) {
-                               return match_subnet_table(*subnet_table, addr_group, ipa,
+                       if(perm_subnet_table) {
+                               return match_subnet_table(*perm_subnet_table, addr_group, ipa,
                                                (unsigned int)port);
                        }
                }
        } else {
-               if(domain_list_table) {
-                       return match_domain_name_table(*domain_list_table, addr_group, ips,
+               if(perm_domain_table) {
+                       return match_domain_name_table(*perm_domain_table, addr_group, ips,
                                        (unsigned int)port);
                }
        }
@@ -670,12 +671,12 @@ int allow_source_address(sip_msg_t *_msg, int addr_group)
        LM_DBG("looking for <%u, %x, %u>\n",
                        addr_group, _msg->rcv.src_ip.u.addr32[0], _msg->rcv.src_port);
 
-       if (addr_hash_table && match_addr_hash_table(*addr_hash_table, addr_group,
+       if (perm_addr_table && match_addr_hash_table(*perm_addr_table, addr_group,
                                &_msg->rcv.src_ip, _msg->rcv.src_port) == 1) {
                return 1;
        } else {
-               if(subnet_table) {
-                       return match_subnet_table(*subnet_table, addr_group,
+               if(perm_subnet_table) {
+                       return match_subnet_table(*perm_subnet_table, addr_group,
                                        &_msg->rcv.src_ip,
                                        _msg->rcv.src_port);
                }
@@ -711,8 +712,8 @@ int ki_allow_source_address_group(sip_msg_t* _msg)
 
        LM_DBG("looking for <%x, %u> in address table\n",
                        _msg->rcv.src_ip.u.addr32[0], _msg->rcv.src_port);
-       if(addr_hash_table) {
-               group = find_group_in_addr_hash_table(*addr_hash_table,
+       if(perm_addr_table) {
+               group = find_group_in_addr_hash_table(*perm_addr_table,
                                &_msg->rcv.src_ip, _msg->rcv.src_port);
                LM_DBG("Found <%d>\n", group);
 
@@ -721,8 +722,8 @@ int ki_allow_source_address_group(sip_msg_t* _msg)
 
        LM_DBG("looking for <%x, %u> in subnet table\n",
                        _msg->rcv.src_ip.u.addr32[0], _msg->rcv.src_port);
-       if(subnet_table) {
-               group = find_group_in_subnet_table(*subnet_table,
+       if(perm_subnet_table) {
+               group = find_group_in_subnet_table(*perm_subnet_table,
                                &_msg->rcv.src_ip, _msg->rcv.src_port);
        }
        LM_DBG("Found <%d>\n", group);
@@ -756,25 +757,25 @@ int ki_allow_address_group(sip_msg_t* _msg, str* _addr, int _port)
        if ( ipa ) {
                LM_DBG("looking for <%.*s, %u> in address table\n",
                                _addr->len, _addr->s, (unsigned int)_port);
-               if(addr_hash_table) {
-                       group = find_group_in_addr_hash_table(*addr_hash_table,
+               if(perm_addr_table) {
+                       group = find_group_in_addr_hash_table(*perm_addr_table,
                                        ipa, (unsigned int)_port);
                        LM_DBG("Found address in group <%d>\n", group);
 
                        if (group != -1) return group;
                }
-               if(subnet_table) {
+               if(perm_subnet_table) {
                        LM_DBG("looking for <%.*s, %u> in subnet table\n",
                                        _addr->len, _addr->s, _port);
-                       group = find_group_in_subnet_table(*subnet_table,
+                       group = find_group_in_subnet_table(*perm_subnet_table,
                                        ipa, (unsigned int)_port);
                        LM_DBG("Found a match of subnet in group <%d>\n", group);
                }
        } else {
                LM_DBG("looking for <%.*s, %u> in domain_name table\n",
                                _addr->len, _addr->s, (unsigned int)_port);
-               if(domain_list_table) {
-                       group = find_group_in_domain_name_table(*domain_list_table,
+               if(perm_domain_table) {
+                       group = find_group_in_domain_name_table(*perm_domain_table,
                                        _addr, (unsigned int)_port);
                        LM_DBG("Found a match of domain_name in group <%d>\n", group);
                }
index 5693ce1..a86dea5 100644 (file)
 
 
 /* Pointer to current address hash table pointer */
-extern struct addr_list ***addr_hash_table;
+extern struct addr_list ***perm_addr_table;
 
 
 /* Pointer to current subnet table */
-extern struct subnet **subnet_table;
+extern struct subnet **perm_subnet_table;
 
 
 /* Pointer to current domain name table */
-extern struct domain_name_list ***domain_list_table;
+extern struct domain_name_list ***perm_domain_table;
 
 /*
  * Initialize data structures
index a7169a6..40dd460 100644 (file)
@@ -41,7 +41,7 @@
 static int     tag_avp_type;
 static int_str tag_avp;
 
-extern int peer_tag_mode;
+extern int perm_peer_tag_mode;
 
 
 extern int _perm_max_subnets;
@@ -321,7 +321,7 @@ int match_hash_table(struct trusted_list** table, struct sip_msg* msg,
                                        return -1;
                                }
                        }
-                       if (!peer_tag_mode)
+                       if (!perm_peer_tag_mode)
                                return 1;
                        count++;
                }
index d6bb9d9..18cf398 100644 (file)
 
 MODULE_VERSION
 
-static rule_file_t allow[MAX_RULE_FILES]; /* Parsed allow files */
-static rule_file_t deny[MAX_RULE_FILES];  /* Parsed deny files */
-static int rules_num = 0;  /* Number of parsed allow/deny files */
+static rule_file_t perm_allow[MAX_RULE_FILES]; /* Parsed allow files */
+static rule_file_t perm_deny[MAX_RULE_FILES];  /* Parsed deny files */
+static int perm_rules_num = 0;  /* Number of parsed allow/deny files */
 
 
 /* Module parameter variables */
-static char* default_allow_file = DEFAULT_ALLOW_FILE;
-static char* default_deny_file = DEFAULT_DENY_FILE;
-char* allow_suffix = ".allow";
-static char* deny_suffix = ".deny";
+static char* perm_default_allow_file = DEFAULT_ALLOW_FILE;
+static char* perm_default_deny_file = DEFAULT_DENY_FILE;
+char* perm_allow_suffix = ".allow";
+static char* perm_deny_suffix = ".deny";
 
 
 /* for allow_trusted and allow_address function */
-str db_url = {NULL, 0};                    /* Don't connect to the database by default */
+str perm_db_url = {NULL, 0};                    /* Don't connect to the database by default */
 
 /* for allow_trusted function */
-int db_mode = DISABLE_CACHE;               /* Database usage mode: 0=no cache, 1=cache */
-str trusted_table = str_init("trusted");   /* Name of trusted table */
-str source_col = str_init("src_ip");       /* Name of source address column */
-str proto_col = str_init("proto");         /* Name of protocol column */
-str from_col = str_init("from_pattern");   /* Name of from pattern column */
-str ruri_col = str_init("ruri_pattern");   /* Name of RURI pattern column */
-str tag_col = str_init("tag");             /* Name of tag column */
-str priority_col = str_init("priority");   /* Name of priority column */
-str tag_avp_param = {NULL, 0};             /* Peer tag AVP spec */
-int peer_tag_mode = 0;                     /* Add tags form all mathcing peers to avp */
+int perm_db_mode = DISABLE_CACHE;               /* Database usage mode: 0=no cache, 1=cache */
+str perm_trusted_table = str_init("trusted");   /* Name of trusted table */
+str perm_source_col = str_init("src_ip");       /* Name of source address column */
+str perm_proto_col = str_init("proto");         /* Name of protocol column */
+str perm_from_col = str_init("from_pattern");   /* Name of from pattern column */
+str perm_ruri_col = str_init("ruri_pattern");   /* Name of RURI pattern column */
+str perm_tag_col = str_init("tag");             /* Name of tag column */
+str perm_priority_col = str_init("priority");   /* Name of priority column */
+str perm_tag_avp_param = {NULL, 0};             /* Peer tag AVP spec */
+int perm_peer_tag_mode = 0;                     /* Add tags form all mathcing peers to avp */
 
 /* for allow_address function */
-str address_table = str_init("address");   /* Name of address table */
-str grp_col = str_init("grp");             /* Name of address group column */
-str ip_addr_col = str_init("ip_addr");     /* Name of ip address column */
-str mask_col = str_init("mask");           /* Name of mask column */
-str port_col = str_init("port");           /* Name of port column */
+str perm_address_table = str_init("address");   /* Name of address table */
+str perm_grp_col = str_init("grp");             /* Name of address group column */
+str perm_ip_addr_col = str_init("ip_addr");     /* Name of ip address column */
+str perm_mask_col = str_init("mask");           /* Name of mask column */
+str perm_port_col = str_init("port");           /* Name of port column */
 
-static str address_file_param = STR_NULL;  /* Path to file with address records */
-str address_file = STR_NULL;                      /* Full path to file with address records */
+static str perm_address_file_param = STR_NULL;  /* Path to file with address records */
+str perm_address_file = STR_NULL;                         /* Full path to file with address records */
 
 /*
  * By default we check all branches
  */
-static int check_all_branches = 1;
+static int perm_check_all_branches = 1;
 
 
 int _perm_max_subnets = 512;
@@ -162,30 +162,30 @@ static cmd_export_t cmds[] = {
 
 /* Exported parameters */
 static param_export_t params[] = {
-       {"default_allow_file", PARAM_STRING, &default_allow_file},
-       {"default_deny_file",  PARAM_STRING, &default_deny_file },
-       {"check_all_branches", INT_PARAM, &check_all_branches},
-       {"allow_suffix",       PARAM_STRING, &allow_suffix      },
-       {"deny_suffix",        PARAM_STRING, &deny_suffix       },
-       {"db_url",             PARAM_STR, &db_url          },
-       {"db_mode",            INT_PARAM, &db_mode           },
-       {"trusted_table",      PARAM_STR, &trusted_table   },
-       {"source_col",         PARAM_STR, &source_col      },
-       {"proto_col",          PARAM_STR, &proto_col       },
-       {"from_col",           PARAM_STR, &from_col        },
-       {"ruri_col",           PARAM_STR, &ruri_col        },
-       {"tag_col",            PARAM_STR, &tag_col         },
-       {"priority_col",       PARAM_STR, &priority_col    },
-       {"peer_tag_avp",       PARAM_STR, &tag_avp_param   },
-       {"peer_tag_mode",      INT_PARAM, &peer_tag_mode     },
-       {"address_table",      PARAM_STR, &address_table   },
-       {"address_file",       PARAM_STR, &address_file_param   },
-       {"grp_col",            PARAM_STR, &grp_col         },
-       {"ip_addr_col",        PARAM_STR, &ip_addr_col     },
-       {"mask_col",           PARAM_STR, &mask_col        },
-       {"port_col",           PARAM_STR, &port_col        },
-       {"max_subnets",        PARAM_INT, &_perm_max_subnets },
-       {"load_backends",      PARAM_INT, &_perm_load_backends },
+       {"default_allow_file", PARAM_STRING, &perm_default_allow_file},
+       {"default_deny_file",  PARAM_STRING, &perm_default_deny_file },
+       {"check_all_branches", INT_PARAM, &perm_check_all_branches   },
+       {"allow_suffix",       PARAM_STRING, &perm_allow_suffix      },
+       {"deny_suffix",        PARAM_STRING, &perm_deny_suffix       },
+       {"db_url",             PARAM_STR, &perm_db_url          },
+       {"db_mode",            INT_PARAM, &perm_db_mode         },
+       {"trusted_table",      PARAM_STR, &perm_trusted_table   },
+       {"source_col",         PARAM_STR, &perm_source_col      },
+       {"proto_col",          PARAM_STR, &perm_proto_col       },
+       {"from_col",           PARAM_STR, &perm_from_col        },
+       {"ruri_col",           PARAM_STR, &perm_ruri_col        },
+       {"tag_col",            PARAM_STR, &perm_tag_col         },
+       {"priority_col",       PARAM_STR, &perm_priority_col    },
+       {"peer_tag_avp",       PARAM_STR, &perm_tag_avp_param   },
+       {"peer_tag_mode",      INT_PARAM, &perm_peer_tag_mode   },
+       {"address_table",      PARAM_STR, &perm_address_table   },
+       {"address_file",       PARAM_STR, &perm_address_file_param   },
+       {"grp_col",            PARAM_STR, &perm_grp_col         },
+       {"ip_addr_col",        PARAM_STR, &perm_ip_addr_col     },
+       {"mask_col",           PARAM_STR, &perm_mask_col        },
+       {"port_col",           PARAM_STR, &perm_port_col        },
+       {"max_subnets",        PARAM_INT, &_perm_max_subnets    },
+       {"load_backends",      PARAM_INT, &_perm_load_backends  },
        {0, 0, 0}
 };
 
@@ -264,7 +264,7 @@ static int find_index(rule_file_t* array, char* pathname)
 {
        int i;
 
-       for(i = 0; i < rules_num; i++) {
+       for(i = 0; i < perm_rules_num; i++) {
                if (!strcmp(pathname, array[i].filename)) return i;
        }
 
@@ -332,7 +332,7 @@ static int check_routing(struct sip_msg* msg, int idx)
        int br_idx;
 
        /* turn off control, allow any routing */
-       if ((!allow[idx].rules) && (!deny[idx].rules)) {
+       if ((!perm_allow[idx].rules) && (!perm_deny[idx].rules)) {
                LM_DBG("no rules => allow any routing\n");
                return 1;
        }
@@ -383,19 +383,19 @@ static int check_routing(struct sip_msg* msg, int idx)
 
        LM_DBG("looking for From: %s Request-URI: %s\n", from_str, ruri_str);
        /* rule exists in allow file */
-       if (search_rule(allow[idx].rules, from_str, ruri_str)) {
-               if (check_all_branches) goto check_branches;
+       if (search_rule(perm_allow[idx].rules, from_str, ruri_str)) {
+               if (perm_check_all_branches) goto check_branches;
                LM_DBG("allow rule found => routing is allowed\n");
                return 1;
        }
 
        /* rule exists in deny file */
-       if (search_rule(deny[idx].rules, from_str, ruri_str)) {
+       if (search_rule(perm_deny[idx].rules, from_str, ruri_str)) {
                LM_DBG("deny rule found => routing is denied\n");
                return -1;
        }
 
-       if (!check_all_branches) {
+       if (!perm_check_all_branches) {
                LM_DBG("neither allow nor deny rule found => routing is allowed\n");
                return 1;
        }
@@ -410,11 +410,11 @@ check_branches:
                }
                LM_DBG("looking for From: %s Branch: %s\n", from_str, uri_str);
 
-               if (search_rule(allow[idx].rules, from_str, uri_str)) {
+               if (search_rule(perm_allow[idx].rules, from_str, uri_str)) {
                        continue;
                }
 
-               if (search_rule(deny[idx].rules, from_str, uri_str)) {
+               if (search_rule(perm_deny[idx].rules, from_str, uri_str)) {
                        LM_DBG("deny rule found for one of branches => routing"
                                        "is denied\n");
                        return -1;
@@ -436,9 +436,9 @@ static int load_fixup(void** param, int param_no)
        rule_file_t* table;
 
        if (param_no == 1) {
-               table = allow;
+               table = perm_allow;
        } else {
-               table = deny;
+               table = perm_deny;
        }
 
        pathname = get_pathname(*param);
@@ -446,15 +446,15 @@ static int load_fixup(void** param, int param_no)
 
        if (idx == -1) {
                /* Not opened yet, open the file and parse it */
-               table[rules_num].filename = pathname;
-               table[rules_num].rules = parse_config_file(pathname);
-               if (table[rules_num].rules) {
+               table[perm_rules_num].filename = pathname;
+               table[perm_rules_num].rules = parse_config_file(pathname);
+               if (table[perm_rules_num].rules) {
                        LM_DBG("file (%s) parsed\n", pathname);
                } else {
                        LM_INFO("file (%s) not parsed properly => empty rule set\n", pathname);
                }
-               *param = (void*)(long)rules_num;
-               if (param_no == 2) rules_num++;
+               *param = (void*)(long)perm_rules_num;
+               if (param_no == 2) perm_rules_num++;
        } else {
                /* File already parsed, re-use it */
                LM_DBG("file (%s) already loaded, re-using\n", pathname);
@@ -478,10 +478,10 @@ static int single_fixup(void** param, int param_no)
        if (param_no != 1) return 0;
 
        param_len = strlen((char*)*param);
-       if (strlen(allow_suffix) > strlen(deny_suffix)) {
-               suffix_len = strlen(allow_suffix);
+       if (strlen(perm_allow_suffix) > strlen(perm_deny_suffix)) {
+               suffix_len = strlen(perm_allow_suffix);
        } else {
-               suffix_len = strlen(deny_suffix);
+               suffix_len = strlen(perm_deny_suffix);
        }
 
        buffer = pkg_malloc(param_len + suffix_len + 1);
@@ -491,11 +491,11 @@ static int single_fixup(void** param, int param_no)
        }
 
        strcpy(buffer, (char*)*param);
-       strcat(buffer, allow_suffix);
+       strcat(buffer, perm_allow_suffix);
        tmp = buffer;
        ret = load_fixup(&tmp, 1);
 
-       strcpy(buffer + param_len, deny_suffix);
+       strcpy(buffer + param_len, perm_deny_suffix);
        tmp = buffer;
        ret |= load_fixup(&tmp, 2);
 
@@ -520,10 +520,10 @@ static int double_fixup(void** param, int param_no)
 
        if (param_no == 1) { /* basename */
                param_len = strlen((char*)*param);
-               if (strlen(allow_suffix) > strlen(deny_suffix)) {
-                       suffix_len = strlen(allow_suffix);
+               if (strlen(perm_allow_suffix) > strlen(perm_deny_suffix)) {
+                       suffix_len = strlen(perm_allow_suffix);
                } else {
-                       suffix_len = strlen(deny_suffix);
+                       suffix_len = strlen(perm_deny_suffix);
                }
 
                buffer = pkg_malloc(param_len + suffix_len + 1);
@@ -533,11 +533,11 @@ static int double_fixup(void** param, int param_no)
                }
 
                strcpy(buffer, (char*)*param);
-               strcat(buffer, allow_suffix);
+               strcat(buffer, perm_allow_suffix);
                tmp = buffer;
                ret = load_fixup(&tmp, 1);
 
-               strcpy(buffer + param_len, deny_suffix);
+               strcpy(buffer + param_len, perm_deny_suffix);
                tmp = buffer;
                ret |= load_fixup(&tmp, 2);
 
@@ -593,34 +593,34 @@ static int mod_init(void)
        }
 
        if(_perm_load_backends&PERM_LOAD_ALLOWFILE) {
-               allow[0].filename = get_pathname(default_allow_file);
-               allow[0].rules = parse_config_file(allow[0].filename);
-               if (allow[0].rules) {
-                       LM_DBG("default allow file (%s) parsed\n", allow[0].filename);
+               perm_allow[0].filename = get_pathname(perm_default_allow_file);
+               perm_allow[0].rules = parse_config_file(perm_allow[0].filename);
+               if (perm_allow[0].rules) {
+                       LM_DBG("default allow file (%s) parsed\n", perm_allow[0].filename);
                } else {
                        LM_INFO("default allow file (%s) not found => empty rule set\n",
-                                       allow[0].filename);
+                                       perm_allow[0].filename);
                }
        } else {
-               allow[0].filename = NULL;
-               allow[0].rules = NULL;
+               perm_allow[0].filename = NULL;
+               perm_allow[0].rules = NULL;
        }
 
        if(_perm_load_backends&PERM_LOAD_DENYFILE) {
-               deny[0].filename = get_pathname(default_deny_file);
-               deny[0].rules = parse_config_file(deny[0].filename);
-               if (deny[0].rules) {
-                       LM_DBG("default deny file (%s) parsed\n", deny[0].filename);
+               perm_deny[0].filename = get_pathname(perm_default_deny_file);
+               perm_deny[0].rules = parse_config_file(perm_deny[0].filename);
+               if (perm_deny[0].rules) {
+                       LM_DBG("default deny file (%s) parsed\n", perm_deny[0].filename);
                } else {
                        LM_INFO("default deny file (%s) not found => empty rule set\n",
-                                       deny[0].filename);
+                                       perm_deny[0].filename);
                }
        } else {
-               deny[0].filename = NULL;
-               deny[0].rules = NULL;
+               perm_deny[0].filename = NULL;
+               perm_deny[0].rules = NULL;
        }
 
-       if (init_tag_avp(&tag_avp_param) < 0) {
+       if (init_tag_avp(&perm_tag_avp_param) < 0) {
                LM_ERR("failed to process peer_tag_avp AVP param\n");
                return -1;
        }
@@ -633,13 +633,13 @@ static int mod_init(void)
        }
 
        if(_perm_load_backends&PERM_LOAD_ADDRESSDB) {
-               if(address_file_param.s!=NULL && address_file_param.len>0) {
-                       address_file.s = get_pathname(address_file_param.s);
-                       if(address_file.s==NULL) {
+               if(perm_address_file_param.s!=NULL && perm_address_file_param.len>0) {
+                       perm_address_file.s = get_pathname(perm_address_file_param.s);
+                       if(perm_address_file.s==NULL) {
                                LM_ERR("failed to set full path to address file\n");
                                return -1;
                        }
-                       address_file.len = strlen(address_file.s);
+                       perm_address_file.len = strlen(perm_address_file.s);
                }
                if (init_addresses() != 0) {
                        LM_ERR("failed to initialize the allow_address function\n");
@@ -647,12 +647,12 @@ static int mod_init(void)
                }
        }
 
-       if ((db_mode != DISABLE_CACHE) && (db_mode != ENABLE_CACHE)) {
-               LM_ERR("invalid db_mode value: %d\n", db_mode);
+       if ((perm_db_mode != DISABLE_CACHE) && (perm_db_mode != ENABLE_CACHE)) {
+               LM_ERR("invalid db_mode value: %d\n", perm_db_mode);
                return -1;
        }
 
-       rules_num = 1;
+       perm_rules_num = 1;
        return 0;
 }
 
@@ -674,12 +674,12 @@ static void mod_exit(void)
 {
        int i;
 
-       for(i = 0; i < rules_num; i++) {
-               if(allow[i].rules) free_rule(allow[i].rules);
-               if(allow[i].filename) pkg_free(allow[i].filename);
+       for(i = 0; i < perm_rules_num; i++) {
+               if(perm_allow[i].rules) free_rule(perm_allow[i].rules);
+               if(perm_allow[i].filename) pkg_free(perm_allow[i].filename);
 
-               if(deny[i].rules) free_rule(deny[i].rules);
-               if(deny[i].filename) pkg_free(deny[i].filename);
+               if(perm_deny[i].rules) free_rule(perm_deny[i].rules);
+               if(perm_deny[i].filename) pkg_free(perm_deny[i].filename);
        }
 
        clean_trusted();
@@ -728,7 +728,7 @@ static int check_register(struct sip_msg* msg, int idx)
        contact_t* c;
 
        /* turn off control, allow any routing */
-       if ((!allow[idx].rules) && (!deny[idx].rules)) {
+       if ((!perm_allow[idx].rules) && (!perm_deny[idx].rules)) {
                LM_DBG("no rules => allow any registration\n");
                return 1;
        }
@@ -793,12 +793,12 @@ static int check_register(struct sip_msg* msg, int idx)
                LM_DBG("looking for To: %s Contact: %s\n", to_str, contact_str);
 
                /* rule exists in allow file */
-               if (search_rule(allow[idx].rules, to_str, contact_str)) {
-                       if (check_all_branches) goto skip_deny;
+               if (search_rule(perm_allow[idx].rules, to_str, contact_str)) {
+                       if (perm_check_all_branches) goto skip_deny;
                }
 
                /* rule exists in deny file */
-               if (search_rule(deny[idx].rules, to_str, contact_str)) {
+               if (search_rule(perm_deny[idx].rules, to_str, contact_str)) {
                        LM_DBG("deny rule found => Register denied\n");
                        return -1;
                }
@@ -845,7 +845,7 @@ static int allow_uri(struct sip_msg* msg, char* _idx, char* _sp)
        sp = (pv_spec_t *)_sp;
 
        /* turn off control, allow any uri */
-       if ((!allow[idx].rules) && (!deny[idx].rules)) {
+       if ((!perm_allow[idx].rules) && (!perm_deny[idx].rules)) {
                LM_DBG("no rules => allow any uri\n");
                return 1;
        }
@@ -896,13 +896,13 @@ static int allow_uri(struct sip_msg* msg, char* _idx, char* _sp)
 
        LM_DBG("looking for From: %s URI: %s\n", from_str, uri_str);
        /* rule exists in allow file */
-       if (search_rule(allow[idx].rules, from_str, uri_str)) {
+       if (search_rule(perm_allow[idx].rules, from_str, uri_str)) {
                LM_DBG("allow rule found => URI is allowed\n");
                return 1;
        }
 
        /* rule exists in deny file */
-       if (search_rule(deny[idx].rules, from_str, uri_str)) {
+       if (search_rule(perm_deny[idx].rules, from_str, uri_str)) {
                LM_DBG("deny rule found => URI is denied\n");
                return -1;
        }
@@ -927,7 +927,7 @@ int allow_test(char *file, char *uri, char *contact)
                return 0;
        }
 
-       idx = find_index(allow, pathname);
+       idx = find_index(perm_allow, pathname);
        if (idx == -1) {
                LM_ERR("File <%s> has not been loaded\n", pathname);
                pkg_free(pathname);
@@ -937,7 +937,7 @@ int allow_test(char *file, char *uri, char *contact)
        pkg_free(pathname);
 
        /* turn off control, allow any routing */
-       if ((!allow[idx].rules) && (!deny[idx].rules)) {
+       if ((!perm_allow[idx].rules) && (!perm_deny[idx].rules)) {
                LM_DBG("No rules => Allowed\n");
                return 1;
        }
@@ -945,13 +945,13 @@ int allow_test(char *file, char *uri, char *contact)
        LM_DBG("Looking for URI: %s, Contact: %s\n", uri, contact);
 
        /* rule exists in allow file */
-       if (search_rule(allow[idx].rules, uri, contact)) {
+       if (search_rule(perm_allow[idx].rules, uri, contact)) {
                LM_DBG("Allow rule found => Allowed\n");
                return 1;
        }
 
        /* rule exists in deny file */
-       if (search_rule(deny[idx].rules, uri, contact)) {
+       if (search_rule(perm_deny[idx].rules, uri, contact)) {
                LM_DBG("Deny rule found => Denied\n");
                return 0;
        }
index bec8a7c..785d6c9 100644 (file)
@@ -44,21 +44,21 @@ typedef struct rule_file {
  */
 #define MAX_RULE_FILES 64
 
-extern str db_url;        /* Database URL */
-extern int db_mode;       /* Database usage mode: 0=no cache, 1=cache */
-extern str trusted_table; /* Name of trusted table */
-extern str source_col;    /* Name of source address column */
-extern str proto_col;     /* Name of protocol column */
-extern str from_col;      /* Name of from pattern column */
-extern str ruri_col;      /* Name of RURI pattern column */
-extern str tag_col;       /* Name of tag column */
-extern str priority_col;  /* Name of priority column */
-extern str address_table; /* Name of address table */
-extern str grp_col;       /* Name of address group column */
-extern str ip_addr_col;   /* Name of ip address column */
-extern str mask_col;      /* Name of mask column */
-extern str port_col;      /* Name of port column */
-extern int peer_tag_mode; /* Matching mode */
+extern str perm_db_url;        /* Database URL */
+extern int perm_db_mode;       /* Database usage mode: 0=no cache, 1=cache */
+extern str perm_trusted_table; /* Name of trusted table */
+extern str perm_source_col;    /* Name of source address column */
+extern str perm_proto_col;     /* Name of protocol column */
+extern str perm_from_col;      /* Name of from pattern column */
+extern str perm_ruri_col;      /* Name of RURI pattern column */
+extern str perm_tag_col;       /* Name of tag column */
+extern str perm_priority_col;  /* Name of priority column */
+extern str perm_address_table; /* Name of address table */
+extern str perm_grp_col;       /* Name of address group column */
+extern str perm_ip_addr_col;   /* Name of ip address column */
+extern str perm_mask_col;      /* Name of mask column */
+extern str perm_port_col;      /* Name of port column */
+extern int perm_peer_tag_mode; /* Matching mode */
 
 /* backends to be loaded */
 #define PERM_LOAD_ADDRESSDB    (1<<0)
@@ -75,7 +75,7 @@ typedef struct int_or_pvar {
 #define DISABLE_CACHE 0
 #define ENABLE_CACHE 1
 
-extern char *allow_suffix;
+extern char *perm_allow_suffix;
 int allow_test(char *file, char *uri, char *contact);
 
 #endif
index 4d28aac..844cdec 100644 (file)
@@ -49,12 +49,12 @@ void rpc_trusted_reload(rpc_t* rpc, void* c) {
  */
 void rpc_trusted_dump(rpc_t* rpc, void* c) {
 
-       if (hash_table==NULL) {
+       if (perm_trust_table==NULL) {
                rpc->fault(c, 500, "No trusted table");
                return;
        }
 
-       if(hash_table_rpc_print(*hash_table, rpc, c) < 0) {
+       if(hash_table_rpc_print(*perm_trust_table, rpc, c) < 0) {
                LM_DBG("failed to print a hash_table dump\n");
                return;
        }
@@ -82,11 +82,11 @@ void rpc_address_reload(rpc_t* rpc, void* c) {
  */
 void rpc_address_dump(rpc_t* rpc, void* c) {
 
-       if(addr_hash_table==NULL) {
+       if(perm_addr_table==NULL) {
                rpc->fault(c, 500, "No address table");
                return;
        }
-       if(addr_hash_table_rpc_print(*addr_hash_table, rpc, c) < 0 ) {
+       if(addr_hash_table_rpc_print(*perm_addr_table, rpc, c) < 0 ) {
                LM_DBG("failed to print address table dump\n");
        }
        return;
@@ -97,11 +97,11 @@ void rpc_address_dump(rpc_t* rpc, void* c) {
  * RPC function to dump subnet table
  */
 void rpc_subnet_dump(rpc_t* rpc, void* c) {
-       if(subnet_table==NULL) {
+       if(perm_subnet_table==NULL) {
                rpc->fault(c, 500, "No subnet table");
                return;
        }
-       if(subnet_table_rpc_print(*subnet_table, rpc, c) < 0) {
+       if(subnet_table_rpc_print(*perm_subnet_table, rpc, c) < 0) {
                LM_DBG("failed to print subnet table dump\n");
        }
 
@@ -114,11 +114,11 @@ void rpc_subnet_dump(rpc_t* rpc, void* c) {
  */
 void rpc_domain_name_dump(rpc_t* rpc, void* c) {
 
-       if(domain_list_table==NULL) {
+       if(perm_domain_table==NULL) {
                rpc->fault(c, 500, "No domain list table");
                return;
        }
-       if ( domain_name_table_rpc_print(*domain_list_table, rpc, c) < 0 ) {
+       if ( domain_name_table_rpc_print(*perm_domain_table, rpc, c) < 0 ) {
                LM_DBG("failed to print domain table dump\n");
        }
        return;
@@ -155,14 +155,14 @@ void rpc_test_uri(rpc_t* rpc, void* c)
                rpc->fault(c, 500, "Contact is too long");
                return;
        }
-       allow_suffix_len = strlen(allow_suffix);
+       allow_suffix_len = strlen(perm_allow_suffix);
        if (basenamep.len + allow_suffix_len + 1 > MAX_FILE_LEN) {
                rpc->fault(c, 500, "Basename is too long");
                return;
        }
 
        memcpy(basename, basenamep.s, basenamep.len);
-       memcpy(basename + basenamep.len, allow_suffix, allow_suffix_len);
+       memcpy(basename + basenamep.len, perm_allow_suffix, allow_suffix_len);
        basename[basenamep.len + allow_suffix_len] = 0;
        memcpy(uri, urip.s, urip.len);
        memcpy(contact, contactp.s, contactp.len);
index 0381646..eed1041 100644 (file)
 
 #define TABLE_VERSION 6
 
-struct trusted_list ***hash_table = 0;    /* Pointer to current hash table pointer */
-struct trusted_list **hash_table_1 = 0;   /* Pointer to hash table 1 */
-struct trusted_list **hash_table_2 = 0;   /* Pointer to hash table 2 */
+struct trusted_list ***perm_trust_table = 0;    /* Pointer to current hash table pointer */
+struct trusted_list **perm_trust_table_1 = 0;   /* Pointer to hash table 1 */
+struct trusted_list **perm_trust_table_2 = 0;   /* Pointer to hash table 2 */
 
 
-static db1_con_t* db_handle = 0;
+static db1_con_t* perm_db_handle = 0;
 static db_func_t perm_dbf;
 
 
@@ -65,38 +65,38 @@ int reload_trusted_table(void)
 
        char *pattern, *ruri_pattern, *tag;
 
-       if (hash_table == 0) {
+       if (perm_trust_table == 0) {
                LM_ERR("in-memory hash table not initialized\n");
                return -1;
        }
 
-       if (db_handle == 0) {
+       if (perm_db_handle == 0) {
                LM_ERR("no connection to database\n");
                return -1;
        }
 
-       cols[0] = &source_col;
-       cols[1] = &proto_col;
-       cols[2] = &from_col;
-       cols[3] = &ruri_col;
-       cols[4] = &tag_col;
-       cols[5] = &priority_col;
+       cols[0] = &perm_source_col;
+       cols[1] = &perm_proto_col;
+       cols[2] = &perm_from_col;
+       cols[3] = &perm_ruri_col;
+       cols[4] = &perm_tag_col;
+       cols[5] = &perm_priority_col;
 
-       if (perm_dbf.use_table(db_handle, &trusted_table) < 0) {
+       if (perm_dbf.use_table(perm_db_handle, &perm_trusted_table) < 0) {
                LM_ERR("failed to use trusted table\n");
                return -1;
        }
 
-       if (perm_dbf.query(db_handle, NULL, 0, NULL, cols, 0, 6, 0, &res) < 0) {
+       if (perm_dbf.query(perm_db_handle, NULL, 0, NULL, cols, 0, 6, 0, &res) < 0) {
                LM_ERR("failed to query database\n");
                return -1;
        }
 
        /* Choose new hash table and free its old contents */
-       if (*hash_table == hash_table_1) {
-               new_hash_table = hash_table_2;
+       if (*perm_trust_table == perm_trust_table_1) {
+               new_hash_table = perm_trust_table_2;
        } else {
-               new_hash_table = hash_table_1;
+               new_hash_table = perm_trust_table_1;
        }
        empty_hash_table(new_hash_table);
 
@@ -143,7 +143,7 @@ int reload_trusted_table(void)
                                                (char *)VAL_STRING(val + 1),
                                                pattern, ruri_pattern, tag, priority) == -1) {
                                LM_ERR("hash table problem\n");
-                               perm_dbf.free_result(db_handle, res);
+                               perm_dbf.free_result(perm_db_handle, res);
                                empty_hash_table(new_hash_table);
                                return -1;
                        }
@@ -152,16 +152,16 @@ int reload_trusted_table(void)
                                        pattern, ruri_pattern, tag);
                } else {
                        LM_ERR("database problem\n");
-                       perm_dbf.free_result(db_handle, res);
+                       perm_dbf.free_result(perm_db_handle, res);
                        empty_hash_table(new_hash_table);
                        return -1;
                }
        }
 
-       perm_dbf.free_result(db_handle, res);
+       perm_dbf.free_result(perm_db_handle, res);
 
-       old_hash_table = *hash_table;
-       *hash_table = new_hash_table;
+       old_hash_table = *perm_trust_table;
+       *perm_trust_table = new_hash_table;
        empty_hash_table(old_hash_table);
 
        LM_DBG("trusted table reloaded successfully.\n");
@@ -176,12 +176,12 @@ int reload_trusted_table(void)
 int init_trusted(void)
 {
        /* Check if hash table needs to be loaded from trusted table */
-       if (!db_url.s) {
+       if (!perm_db_url.s) {
                LM_INFO("db_url parameter of permissions module not set, "
                                "disabling allow_trusted\n");
                return 0;
        } else {
-               if (db_bind_mod(&db_url, &perm_dbf) < 0) {
+               if (db_bind_mod(&perm_db_url, &perm_dbf) < 0) {
                        LM_ERR("load a database support module\n");
                        return -1;
                }
@@ -192,60 +192,61 @@ int init_trusted(void)
                }
        }
 
-       hash_table_1 = hash_table_2 = 0;
-       hash_table = 0;
+       perm_trust_table_1 = perm_trust_table_2 = 0;
+       perm_trust_table = 0;
 
-       if (db_mode == ENABLE_CACHE) {
-               db_handle = perm_dbf.init(&db_url);
-               if (!db_handle) {
+       if (perm_db_mode == ENABLE_CACHE) {
+               perm_db_handle = perm_dbf.init(&perm_db_url);
+               if (!perm_db_handle) {
                        LM_ERR("unable to connect database\n");
                        return -1;
                }
 
-               if(db_check_table_version(&perm_dbf, db_handle, &trusted_table, TABLE_VERSION) < 0) {
-                       DB_TABLE_VERSION_ERROR(trusted_table);
-                       perm_dbf.close(db_handle);
-                       db_handle = 0;
+               if(db_check_table_version(&perm_dbf, perm_db_handle, &perm_trusted_table,
+                                       TABLE_VERSION) < 0) {
+                       DB_TABLE_VERSION_ERROR(perm_trusted_table);
+                       perm_dbf.close(perm_db_handle);
+                       perm_db_handle = 0;
                        return -1;
                }
 
-               hash_table_1 = new_hash_table();
-               if (!hash_table_1) return -1;
+               perm_trust_table_1 = new_hash_table();
+               if (!perm_trust_table_1) return -1;
 
-               hash_table_2  = new_hash_table();
-               if (!hash_table_2) goto error;
+               perm_trust_table_2  = new_hash_table();
+               if (!perm_trust_table_2) goto error;
 
-               hash_table = (struct trusted_list ***)shm_malloc
+               perm_trust_table = (struct trusted_list ***)shm_malloc
                        (sizeof(struct trusted_list **));
-               if (!hash_table) goto error;
+               if (!perm_trust_table) goto error;
 
-               *hash_table = hash_table_1;
+               *perm_trust_table = perm_trust_table_1;
 
                if (reload_trusted_table() == -1) {
                        LM_CRIT("reload of trusted table failed\n");
                        goto error;
                }
 
-               perm_dbf.close(db_handle);
-               db_handle = 0;
+               perm_dbf.close(perm_db_handle);
+               perm_db_handle = 0;
        }
        return 0;
 
 error:
-       if (hash_table_1) {
-               free_hash_table(hash_table_1);
-               hash_table_1 = 0;
+       if (perm_trust_table_1) {
+               free_hash_table(perm_trust_table_1);
+               perm_trust_table_1 = 0;
        }
-       if (hash_table_2) {
-               free_hash_table(hash_table_2);
-               hash_table_2 = 0;
+       if (perm_trust_table_2) {
+               free_hash_table(perm_trust_table_2);
+               perm_trust_table_2 = 0;
        }
-       if (hash_table) {
-               shm_free(hash_table);
-               hash_table = 0;
+       if (perm_trust_table) {
+               shm_free(perm_trust_table);
+               perm_trust_table = 0;
        }
-       perm_dbf.close(db_handle);
-       db_handle = 0;
+       perm_dbf.close(perm_db_handle);
+       perm_db_handle = 0;
        return -1;
 }
 
@@ -255,26 +256,26 @@ error:
  */
 int init_child_trusted(int rank)
 {
-       if (db_mode == ENABLE_CACHE)
+       if (perm_db_mode == ENABLE_CACHE)
                return 0;
 
        if ((rank <= 0) && (rank != PROC_RPC) && (rank != PROC_UNIXSOCK))
                return 0;
 
-       if (!db_url.s) {
+       if (!perm_db_url.s) {
                return 0;
        }
 
-       db_handle = perm_dbf.init(&db_url);
-       if (!db_handle) {
+       perm_db_handle = perm_dbf.init(&perm_db_url);
+       if (!perm_db_handle) {
                LM_ERR("unable to connect database\n");
                return -1;
        }
 
-       if (db_check_table_version(&perm_dbf, db_handle, &trusted_table,
+       if (db_check_table_version(&perm_dbf, perm_db_handle, &perm_trusted_table,
                                TABLE_VERSION) < 0) {
-               DB_TABLE_VERSION_ERROR(trusted_table);
-               perm_dbf.close(db_handle);
+               DB_TABLE_VERSION_ERROR(perm_trusted_table);
+               perm_dbf.close(perm_db_handle);
                return -1;
        }
 
@@ -287,9 +288,9 @@ int init_child_trusted(int rank)
  */
 void clean_trusted(void)
 {
-       if (hash_table_1) free_hash_table(hash_table_1);
-       if (hash_table_2) free_hash_table(hash_table_2);
-       if (hash_table) shm_free(hash_table);
+       if (perm_trust_table_1) free_hash_table(perm_trust_table_1);
+       if (perm_trust_table_2) free_hash_table(perm_trust_table_2);
+       if (perm_trust_table) shm_free(perm_trust_table);
 }
 
 
@@ -435,7 +436,7 @@ static int match_res(struct sip_msg* msg, int proto, db1_res_t* _r, char* uri)
                                        return -1;
                                }
                        }
-                       if (!peer_tag_mode)
+                       if (!perm_peer_tag_mode)
                                return 1;
                        count++;
                }
@@ -459,21 +460,21 @@ int allow_trusted(struct sip_msg* msg, char *src_ip, int proto, char *from_uri)
        db_val_t vals[1];
        db_key_t cols[4];
 
-       if (db_mode == DISABLE_CACHE) {
-               db_key_t order = &priority_col;
+       if (perm_db_mode == DISABLE_CACHE) {
+               db_key_t order = &perm_priority_col;
 
-               if (db_handle == 0) {
+               if (perm_db_handle == 0) {
                        LM_ERR("no connection to database\n");
                        return -1;
                }
 
-               keys[0] = &source_col;
-               cols[0] = &proto_col;
-               cols[1] = &from_col;
-               cols[2] = &ruri_col;
-               cols[3] = &tag_col;
+               keys[0] = &perm_source_col;
+               cols[0] = &perm_proto_col;
+               cols[1] = &perm_from_col;
+               cols[2] = &perm_ruri_col;
+               cols[3] = &perm_tag_col;
 
-               if (perm_dbf.use_table(db_handle, &trusted_table) < 0) {
+               if (perm_dbf.use_table(perm_db_handle, &perm_trusted_table) < 0) {
                        LM_ERR("failed to use trusted table\n");
                        return -1;
                }
@@ -482,22 +483,22 @@ int allow_trusted(struct sip_msg* msg, char *src_ip, int proto, char *from_uri)
                VAL_NULL(vals) = 0;
                VAL_STRING(vals) = src_ip;
 
-               if (perm_dbf.query(db_handle, keys, 0, vals, cols, 1, 4, order,
+               if (perm_dbf.query(perm_db_handle, keys, 0, vals, cols, 1, 4, order,
                                        &res) < 0){
                        LM_ERR("failed to query database\n");
                        return -1;
                }
 
                if (RES_ROW_N(res) == 0) {
-                       perm_dbf.free_result(db_handle, res);
+                       perm_dbf.free_result(perm_db_handle, res);
                        return -1;
                }
 
                result = match_res(msg, proto, res, from_uri);
-               perm_dbf.free_result(db_handle, res);
+               perm_dbf.free_result(perm_db_handle, res);
                return result;
        } else {
-               return match_hash_table(*hash_table, msg, src_ip, proto, from_uri);
+               return match_hash_table(*perm_trust_table, msg, src_ip, proto, from_uri);
        }
 }
 
@@ -637,26 +638,26 @@ int allow_trusted_3(struct sip_msg* _msg, char* _src_ip_sp, char* _proto_sp,
 
 int reload_trusted_table_cmd(void)
 {
-       if(!db_url.s) {
+       if(!perm_db_url.s) {
                LM_ERR("db_url not set\n");
                return -1;
        }
 
-       if (!db_handle) {
-               db_handle = perm_dbf.init(&db_url);
-               if (!db_handle) {
+       if (!perm_db_handle) {
+               perm_db_handle = perm_dbf.init(&perm_db_url);
+               if (!perm_db_handle) {
                        LM_ERR("unable to connect database\n");
                        return -1;
                }
        }
        if (reload_trusted_table () != 1) {
-               perm_dbf.close(db_handle);
-               db_handle = 0;
+               perm_dbf.close(perm_db_handle);
+               perm_db_handle = 0;
                return -1;
        }
 
-       perm_dbf.close(db_handle);
-       db_handle = 0;
+       perm_dbf.close(perm_db_handle);
+       perm_db_handle = 0;
 
        return 1;
 }
index d8dfae0..8a8ab2c 100644 (file)
@@ -26,9 +26,9 @@
 #include "../../core/parser/msg_parser.h"
 
 
-extern struct trusted_list ***hash_table;     /* Pointer to current hash table pointer */
-extern struct trusted_list **hash_table_1;   /* Pointer to hash table 1 */
-extern struct trusted_list **hash_table_2;   /* Pointer to hash table 2 */
+extern struct trusted_list ***perm_trust_table;    /* Pointer to current trusted hash table pointer */
+extern struct trusted_list **perm_trust_table_1;   /* Pointer to trusted hash table 1 */
+extern struct trusted_list **perm_trust_table_2;   /* Pointer to trusted hash table 2 */
 
 
 /*