Kaynağa Gözat

permissions: exported some functions to kemi

- allow_source_address() and allow_address()
- coherent indentation and whitespacing
Daniel-Constantin Mierla 9 yıl önce
ebeveyn
işleme
d2e0df53bf

+ 60 - 49
modules/permissions/address.c

@@ -15,8 +15,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
@@ -184,7 +184,7 @@ int reload_address_table(void)
 		if ( ipa==NULL )
 		{
 			LM_DBG("Domain name: %.*s\n", ips.len, ips.s);
-		//	goto dberror;
+			//	goto dberror;
 		} else {
 			if(ipa->af == AF_INET6) {
 				if((int)mask<0 || mask>128) {
@@ -211,8 +211,8 @@ int reload_address_table(void)
 						gid, ips.s, port);
 			} else {
 				if (subnet_table_insert(new_subnet_table, gid, ipa, mask,
-								port, tagv)
-							== -1) {
+							port, tagv)
+						== -1) {
 					LM_ERR("subnet table problem\n");
 					perm_dbf.free_result(db_handle, res);
 					return -1;
@@ -221,9 +221,9 @@ int reload_address_table(void)
 						gid, ips.s, port, mask);
 			}
 		} else {
-				if (domain_name_table_insert(new_domain_name_table, gid, &ips,
-							port, tagv)
-						== -1) {
+			if (domain_name_table_insert(new_domain_name_table, gid, &ips,
+						port, tagv)
+					== -1) {
 				LM_ERR("domain name table problem\n");
 				perm_dbf.free_result(db_handle, res);
 				return -1;
@@ -443,18 +443,43 @@ void clean_addresses(void)
 }
 
 
+int allow_address(sip_msg_t *_msg, int addr_group, str *ips, int port)
+{
+	struct ip_addr *ipa;
+
+	ipa=strtoipX(ips);
+
+	if ( ipa ) {
+		if (addr_hash_table
+				&& match_addr_hash_table(*addr_hash_table, addr_group,
+					ipa, (unsigned int)port) == 1) {
+			return 1;
+		} else {
+			if(subnet_table) {
+				return match_subnet_table(*subnet_table, addr_group, ipa,
+						(unsigned int)port);
+			}
+		}
+	} else {
+		if(domain_list_table) {
+			return match_domain_name_table(*domain_list_table, addr_group, ips,
+					(unsigned int)port);
+		}
+	}
+	return -1;
+}
+
 /*
  * Checks if an entry exists in cached address table that belongs to a
  * given address group and has given ip address and port.  Port value
  * 0 in cached address table matches any port.
  */
-int allow_address(struct sip_msg* _msg, char* _addr_group, char* _addr_sp,
+int w_allow_address(struct sip_msg* _msg, char* _addr_group, char* _addr_sp,
 		char* _port_sp)
 {
-	unsigned int port;
+	int port;
 	int addr_group;
 	str ips;
-	struct ip_addr *ipa;
 
 	if(fixup_get_ivalue(_msg, (gparam_p)_addr_group, &addr_group) !=0 ) {
 		LM_ERR("cannot get group value\n");
@@ -467,38 +492,38 @@ int allow_address(struct sip_msg* _msg, char* _addr_group, char* _addr_sp,
 		return -1;
 	}
 
-	ipa=strtoipX(&ips);
-
 	if (_port_sp==NULL
-			|| (fixup_get_ivalue(_msg, (gparam_p)_port_sp, (int*)&port) < 0)) {
+			|| (fixup_get_ivalue(_msg, (gparam_p)_port_sp, &port) < 0)) {
 		LM_ERR("cannot get value of port pvar\n");
 		return -1;
 	}
 
-	if ( ipa ) {
-		if (addr_hash_table
-				&& match_addr_hash_table(*addr_hash_table, addr_group,
-					ipa, port) == 1) {
-			return 1;
-		} else {
-			if(subnet_table) {
-				return match_subnet_table(*subnet_table, addr_group, ipa, port);
-			}
-		}
+	return allow_address(_msg, addr_group, &ips, port);
+}
+
+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,
+				&_msg->rcv.src_ip, _msg->rcv.src_port) == 1) {
+		return 1;
 	} else {
-		if(domain_list_table) {
-			return match_domain_name_table(*domain_list_table, addr_group, &ips, port);
+		if(subnet_table) {
+			return match_subnet_table(*subnet_table, addr_group,
+					&_msg->rcv.src_ip,
+					_msg->rcv.src_port);
 		}
 	}
 	return -1;
 }
 
-
 /*
- * allow_source_address("group") equals to allow_address("group", "$si", "$sp")
+ * w_allow_source_address("group") equals to allow_address("group", "$si", "$sp")
  * but is faster.
  */
-int allow_source_address(struct sip_msg* _msg, char* _addr_group, char* _str2) 
+int w_allow_source_address(struct sip_msg* _msg, char* _addr_group, char* _str2)
 {
 	int addr_group = 1;
 
@@ -507,21 +532,7 @@ int allow_source_address(struct sip_msg* _msg, char* _addr_group, char* _str2)
 		LM_ERR("cannot get group value\n");
 		return -1;
 	}
-
-	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,
-				&_msg->rcv.src_ip, _msg->rcv.src_port) == 1) {
-		return 1;
-	} else {
-		if(subnet_table) {
-			return match_subnet_table(*subnet_table, addr_group,
-				&_msg->rcv.src_ip,
-				_msg->rcv.src_port);
-		}
-	}
-	return -1;
+	return allow_source_address(_msg, addr_group);
 }
 
 
@@ -530,7 +541,7 @@ int allow_source_address(struct sip_msg* _msg, char* _addr_group, char* _str2)
  * subnet table in any group. If yes, returns that group. If not returns -1.
  * Port value 0 in cached address and group table matches any port.
  */
-int allow_source_address_group(struct sip_msg* _msg, char* _str1, char* _str2) 
+int allow_source_address_group(struct sip_msg* _msg, char* _str1, char* _str2)
 {
 	int group = -1;
 
@@ -538,7 +549,7 @@ int allow_source_address_group(struct sip_msg* _msg, char* _str1, char* _str2)
 			_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,
-					&_msg->rcv.src_ip, _msg->rcv.src_port);
+				&_msg->rcv.src_ip, _msg->rcv.src_port);
 		LM_DBG("Found <%d>\n", group);
 
 		if (group != -1) return group;
@@ -586,7 +597,7 @@ int allow_address_group(struct sip_msg* _msg, char* _addr, char* _port)
 				ips.len, ips.s, port);
 		if(addr_hash_table) {
 			group = find_group_in_addr_hash_table(*addr_hash_table,
-						ipa, port);
+					ipa, port);
 			LM_DBG("Found address in group <%d>\n", group);
 
 			if (group != -1) return group;
@@ -595,7 +606,7 @@ int allow_address_group(struct sip_msg* _msg, char* _addr, char* _port)
 			LM_DBG("looking for <%.*s, %u> in subnet table\n",
 					ips.len, ips.s, port);
 			group = find_group_in_subnet_table(*subnet_table,
-						ipa, port);
+					ipa, port);
 			LM_DBG("Found a match of subnet in group <%d>\n", group);
 		}
 	} else {
@@ -603,7 +614,7 @@ int allow_address_group(struct sip_msg* _msg, char* _addr, char* _port)
 				ips.len, ips.s, port);
 		if(domain_list_table) {
 			group = find_group_in_domain_name_table(*domain_list_table,
-						&ips, port);
+					&ips, port);
 			LM_DBG("Found a match of domain_name in group <%d>\n", group);
 		}
 	}

+ 13 - 9
modules/permissions/address.h

@@ -15,23 +15,23 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
 #ifndef ADDRESS_H
 #define ADDRESS_H
-		
+
 #include "../../parser/msg_parser.h"
 
 
 /* Pointer to current address hash table pointer */
-extern struct addr_list ***addr_hash_table; 
+extern struct addr_list ***addr_hash_table;
 
 
 /* Pointer to current subnet table */
-extern struct subnet **subnet_table; 
+extern struct subnet **subnet_table;
 
 
 /* Pointer to current domain name table */
@@ -67,20 +67,24 @@ int reload_address_table_cmd(void);
 void clean_addresses(void);
 
 
+int allow_address(sip_msg_t *_msg, int addr_group, str *ips, int port);
+
 /*
  * Checks if an entry exists in cached address table that belongs to a
  * given address group and has given ip address and port.  Port value
  * 0 in cached address table matches any port.
  */
-int allow_address(struct sip_msg* _msg, char* _addr_group, char* _addr_sp,
-		  char* _port_sp);
+int w_allow_address(struct sip_msg* _msg, char* _addr_group, char* _addr_sp,
+		char* _port_sp);
+
 
+int allow_source_address(sip_msg_t *_msg, int addr_group);
 
 /*
- * allow_source_address("group") equals to allow_address("group", "$si", "$sp")
+ * w_allow_source_address("group") equals to allow_address("group", "$si", "$sp")
  * but is faster.
  */
-int allow_source_address(struct sip_msg* _msg, char* _addr_group, char* _str2);
+int w_allow_source_address(struct sip_msg* _msg, char* _addr_group, char* _str2);
 
 
 /*

+ 102 - 102
modules/permissions/hash.c

@@ -15,8 +15,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
@@ -119,11 +119,11 @@ void free_hash_table(struct trusted_list** table)
 }
 
 
-/* 
+/*
  * Add <src_ip, proto, pattern, ruri_pattern, tag, priority> into hash table, where proto is integer
  * representation of string argument proto.
  */
-int hash_table_insert(struct trusted_list** table, char* src_ip, 
+int hash_table_insert(struct trusted_list** table, char* src_ip,
 		char* proto, char* pattern, char* ruri_pattern, char* tag, int priority)
 {
 	struct trusted_list *np;
@@ -243,7 +243,7 @@ int hash_table_insert(struct trusted_list** table, char* src_ip,
 }
 
 
-/* 
+/*
  * Check if an entry exists in hash table that has given src_ip and protocol
  * value and pattern that matches to From URI.  If an entry exists and tag_avp
  * has been defined, tag of the entry is added as a value to tag_avp.
@@ -284,58 +284,58 @@ int match_hash_table(struct trusted_list** table, struct sip_msg* msg,
 	}
 
 	for (np = table[perm_hash(src_ip)]; np != NULL; np = np->next) {
-	    if ((np->src_ip.len == src_ip.len) && 
-		(strncmp(np->src_ip.s, src_ip.s, src_ip.len) == 0) &&
-		((np->proto == PROTO_NONE) || (proto == PROTO_NONE) ||
-		 (np->proto == proto))) {
-		if (IS_SIP(msg)) {
-		    if (np->pattern) {
-		        if (regcomp(&preg, np->pattern, REG_NOSUB)) {
-			    LM_ERR("invalid regular expression\n");
-			    if (!np->ruri_pattern) {
-				continue;
-			    }
-		        }
-		        if (regexec(&preg, uri_string, 0, (regmatch_t *)0, 0)) {
-			    regfree(&preg);
-			    continue;
-		        }
-		        regfree(&preg);
-		    }
-		    if (np->ruri_pattern) {
-			if (regcomp(&preg, np->ruri_pattern, REG_NOSUB)) {
-			    LM_ERR("invalid regular expression\n");
-			    continue;
+		if ((np->src_ip.len == src_ip.len) &&
+				(strncmp(np->src_ip.s, src_ip.s, src_ip.len) == 0) &&
+				((np->proto == PROTO_NONE) || (proto == PROTO_NONE) ||
+				(np->proto == proto))) {
+			if (IS_SIP(msg)) {
+				if (np->pattern) {
+					if (regcomp(&preg, np->pattern, REG_NOSUB)) {
+						LM_ERR("invalid regular expression\n");
+						if (!np->ruri_pattern) {
+							continue;
+						}
+					}
+					if (regexec(&preg, uri_string, 0, (regmatch_t *)0, 0)) {
+						regfree(&preg);
+						continue;
+					}
+					regfree(&preg);
+				}
+				if (np->ruri_pattern) {
+					if (regcomp(&preg, np->ruri_pattern, REG_NOSUB)) {
+						LM_ERR("invalid regular expression\n");
+						continue;
+					}
+					if (regexec(&preg, ruri_string, 0, (regmatch_t *)0, 0)) {
+						regfree(&preg);
+						continue;
+					}
+					regfree(&preg);
+				}
 			}
-			if (regexec(&preg, ruri_string, 0, (regmatch_t *)0, 0)) {
-			    regfree(&preg);
-			    continue;
+			/* Found a match */
+			if (tag_avp.n && np->tag.s) {
+				val.s = np->tag;
+				if (add_avp(tag_avp_type|AVP_VAL_STR, tag_avp, val) != 0) {
+					LM_ERR("setting of tag_avp failed\n");
+					return -1;
+				}
 			}
-			regfree(&preg);
-		    }
+			if (!peer_tag_mode)
+				return 1;
+			count++;
 		}
-		/* Found a match */
-		if (tag_avp.n && np->tag.s) {
-		    val.s = np->tag;
-		    if (add_avp(tag_avp_type|AVP_VAL_STR, tag_avp, val) != 0) {
-			LM_ERR("setting of tag_avp failed\n");
-			return -1;
-		    }
-		}
-		if (!peer_tag_mode)
-		    return 1;
-		count++;
-	    }
 	}
 	if (!count)
-	    return -1;
-	else 
-	    return count;
+		return -1;
+	else
+		return count;
 }
 
 
 /*! \brief
- * MI Interface :: Print trusted entries stored in hash table 
+ * MI Interface :: Print trusted entries stored in hash table
  */
 int hash_table_mi_print(struct trusted_list** table, struct mi_node* rpl)
 {
@@ -363,7 +363,7 @@ int hash_table_mi_print(struct trusted_list** table, struct mi_node* rpl)
 }
 
 /*! \brief
- * RPC interface :: Print trusted entries stored in hash table 
+ * RPC interface :: Print trusted entries stored in hash table
  */
 int hash_table_rpc_print(struct trusted_list** hash_table, rpc_t* rpc, void* c)
 {
@@ -381,13 +381,13 @@ int hash_table_rpc_print(struct trusted_list** hash_table, rpc_t* rpc, void* c)
 	for (i = 0; i < PERM_HASH_SIZE; i++) {
 		np = hash_table[i];
 		while (np) {
-			if(rpc->struct_add(th, "d{", 
-					"table", i,
-					"item", &ih) < 0)
-                        {
-                                rpc->fault(c, 500, "Internal error creating rpc ih");
-                                return -1;
-                        }
+			if(rpc->struct_add(th, "d{",
+						"table", i,
+						"item", &ih) < 0)
+			{
+				rpc->fault(c, 500, "Internal error creating rpc ih");
+				return -1;
+			}
 
 			if(rpc->struct_add(ih, "s", "ip", np->src_ip.s) < 0)
 			{
@@ -409,7 +409,7 @@ int hash_table_rpc_print(struct trusted_list** hash_table, rpc_t* rpc, void* c)
 	return 0;
 }
 
-/* 
+/*
  * Free contents of hash table, it doesn't destroy the
  * hash table itself
  */
@@ -467,7 +467,7 @@ void free_addr_hash_table(struct addr_list** table)
 }
 
 
-/* 
+/*
  * Add <grp, ip_addr, port> into hash table
  */
 int addr_hash_table_insert(struct addr_list** table, unsigned int grp,
@@ -510,7 +510,7 @@ int addr_hash_table_insert(struct addr_list** table, unsigned int grp,
 }
 
 
-/* 
+/*
  * Check if an entry exists in hash table that has given group, ip_addr, and
  * port.  Port 0 in hash table matches any port.
  */
@@ -545,10 +545,10 @@ int match_addr_hash_table(struct addr_list** table, unsigned int group,
 }
 
 
-/* 
+/*
  * Check if an ip_addr/port entry exists in hash table in any group.
  * Returns first group in which ip_addr/port is found.
- * Port 0 in hash table matches any port. 
+ * Port 0 in hash table matches any port.
  */
 int find_group_in_addr_hash_table(struct addr_list** table,
 		ip_addr_t *addr, unsigned int port)
@@ -580,7 +580,7 @@ int find_group_in_addr_hash_table(struct addr_list** table,
 }
 
 /*! \brief
- * MI: Print addresses stored in hash table 
+ * MI: Print addresses stored in hash table
  */
 int addr_hash_table_mi_print(struct addr_list** table, struct mi_node* rpl)
 {
@@ -602,7 +602,7 @@ int addr_hash_table_mi_print(struct addr_list** table, struct mi_node* rpl)
 }
 
 /*! \brief
- * RPC: Print addresses stored in hash table 
+ * RPC: Print addresses stored in hash table
  */
 int addr_hash_table_rpc_print(struct addr_list** table, rpc_t* rpc, void* c)
 {
@@ -621,14 +621,14 @@ int addr_hash_table_rpc_print(struct addr_list** table, rpc_t* rpc, void* c)
 	for (i = 0; i < PERM_HASH_SIZE; i++) {
 		np = table[i];
 		while (np) {
-			if(rpc->struct_add(th, "dd{", 
-					"table", i,
-					"group", np->grp,
-					"item", &ih) < 0)
-                        {
-                                rpc->fault(c, 500, "Internal error creating rpc ih");
-                                return -1;
-                        }
+			if(rpc->struct_add(th, "dd{",
+						"table", i,
+						"group", np->grp,
+						"item", &ih) < 0)
+			{
+				rpc->fault(c, 500, "Internal error creating rpc ih");
+				return -1;
+			}
 
 			if(rpc->struct_add(ih, "s", "ip", ip_addr2a(&np->addr)) < 0)
 			{
@@ -648,7 +648,7 @@ int addr_hash_table_rpc_print(struct addr_list** table, rpc_t* rpc, void* c)
 }
 
 
-/* 
+/*
  * Free contents of hash table, it doesn't destroy the
  * hash table itself
  */
@@ -676,8 +676,8 @@ struct subnet* new_subnet_table(void)
 {
 	struct subnet* ptr;
 
-	/* subnet record [PERM_MAX_SUBNETS] contains in its grp field 
-	   the number of subnet records in the subnet table */
+	/* subnet record [PERM_MAX_SUBNETS] contains in its grp field
+	 * the number of subnet records in the subnet table */
 	ptr = (struct subnet *)shm_malloc
 		(sizeof(struct subnet) * (PERM_MAX_SUBNETS + 1));
 	if (!ptr) {
@@ -689,7 +689,7 @@ struct subnet* new_subnet_table(void)
 }
 
 
-/* 
+/*
  * Add <grp, subnet, mask, port, tag> into subnet table so that table is
  * kept in increasing ordered according to grp.
  */
@@ -742,7 +742,7 @@ int subnet_table_insert(struct subnet* table, unsigned int grp,
 }
 
 
-/* 
+/*
  * Check if an entry exists in subnet table that matches given group, ip_addr,
  * and port.  Port 0 in subnet table matches any port.
  */
@@ -762,7 +762,7 @@ int match_subnet_table(struct subnet* table, unsigned int grp,
 
 	while ((i < count) && (table[i].grp == grp)) {
 		if (((table[i].port == port) || (table[i].port == 0))
-			&& (ip_addr_match_net(addr, &table[i].subnet, table[i].mask)==0))
+				&& (ip_addr_match_net(addr, &table[i].subnet, table[i].mask)==0))
 		{
 			if (tag_avp.n && table[i].tag.s) {
 				val.s = table[i].tag;
@@ -780,7 +780,7 @@ int match_subnet_table(struct subnet* table, unsigned int grp,
 }
 
 
-/* 
+/*
  * Check if an entry exists in subnet table that matches given ip_addr,
  * and port.  Port 0 in subnet table matches any port.  Return group of
  * first match or -1 if no match is found.
@@ -796,7 +796,7 @@ int find_group_in_subnet_table(struct subnet* table,
 	i = 0;
 	while (i < count) {
 		if ( ((table[i].port == port) || (table[i].port == 0))
-			&& (ip_addr_match_net(addr, &table[i].subnet, table[i].mask)==0))
+				&& (ip_addr_match_net(addr, &table[i].subnet, table[i].mask)==0))
 		{
 			if (tag_avp.n && table[i].tag.s) {
 				val.s = table[i].tag;
@@ -814,8 +814,8 @@ int find_group_in_subnet_table(struct subnet* table,
 }
 
 
-/* 
- * Print subnets stored in subnet table 
+/*
+ * Print subnets stored in subnet table
  */
 int subnet_table_mi_print(struct subnet* table, struct mi_node* rpl)
 {
@@ -836,7 +836,7 @@ int subnet_table_mi_print(struct subnet* table, struct mi_node* rpl)
 }
 
 /*! \brief
- * RPC interface :: Print subnet entries stored in hash table 
+ * RPC interface :: Print subnet entries stored in hash table
  */
 int subnet_table_rpc_print(struct subnet* table, rpc_t* rpc, void* c)
 {
@@ -854,14 +854,14 @@ int subnet_table_rpc_print(struct subnet* table, rpc_t* rpc, void* c)
 	}
 
 	for (i = 0; i < count; i++) {
-		if(rpc->struct_add(th, "dd{", 
-				"id", i,
-				"group", table[i].grp,
-				"item", &ih) < 0)
-                {
-                        rpc->fault(c, 500, "Internal error creating rpc ih");
-                        return -1;
-                }
+		if(rpc->struct_add(th, "dd{",
+					"id", i,
+					"group", table[i].grp,
+					"item", &ih) < 0)
+		{
+			rpc->fault(c, 500, "Internal error creating rpc ih");
+			return -1;
+		}
 
 		if(rpc->struct_add(ih, "s", "ip", ip_addr2a(&table[i].subnet)) < 0)
 		{
@@ -880,7 +880,7 @@ int subnet_table_rpc_print(struct subnet* table, rpc_t* rpc, void* c)
 }
 
 
-/* 
+/*
  * Empty contents of subnet table
  */
 void empty_subnet_table(struct subnet *table)
@@ -940,7 +940,7 @@ struct domain_name_list** new_domain_name_table(void)
 }
 
 
-/* 
+/*
  * Free contents of hash table, it doesn't destroy the
  * hash table itself
  */
@@ -973,7 +973,7 @@ void free_domain_name_table(struct domain_name_list** table)
 }
 
 
-/* 
+/*
  * Check if an entry exists in hash table that has given group, domain_name, and
  * port.  Port 0 in hash table matches any port.
  */
@@ -1005,10 +1005,10 @@ int match_domain_name_table(struct domain_name_list** table, unsigned int group,
 }
 
 
-/* 
+/*
  * Check if an domain_name/port entry exists in hash table in any group.
  * Returns first group in which ip_addr/port is found.
- * Port 0 in hash table matches any port. 
+ * Port 0 in hash table matches any port.
  */
 int find_group_in_domain_name_table(struct domain_name_list** table,
 		str *domain_name, unsigned int port)
@@ -1027,7 +1027,7 @@ int find_group_in_domain_name_table(struct domain_name_list** table,
 }
 
 
-/* 
+/*
  * Add <grp, domain_name, port> into hash table
  */
 int domain_name_table_insert(struct domain_name_list** table, unsigned int grp,
@@ -1071,7 +1071,7 @@ int domain_name_table_insert(struct domain_name_list** table, unsigned int grp,
 
 
 /*! \brief
- * RPC: Print addresses stored in hash table 
+ * RPC: Print addresses stored in hash table
  */
 int domain_name_table_rpc_print(struct domain_name_list** table, rpc_t* rpc, void* c)
 {
@@ -1090,10 +1090,10 @@ int domain_name_table_rpc_print(struct domain_name_list** table, rpc_t* rpc, voi
 	for (i = 0; i < PERM_HASH_SIZE; i++) {
 		np = table[i];
 		while (np) {
-			if(rpc->struct_add(th, "dd{", 
-					"table", i,
-					"group", np->grp,
-					"item", &ih) < 0) {
+			if(rpc->struct_add(th, "dd{",
+						"table", i,
+						"group", np->grp,
+						"item", &ih) < 0) {
 				rpc->fault(c, 500, "Internal error creating rpc ih");
 				return -1;
 			}
@@ -1114,7 +1114,7 @@ int domain_name_table_rpc_print(struct domain_name_list** table, rpc_t* rpc, voi
 }
 
 /*! \brief
- * MI: Print domain name stored in hash table 
+ * MI: Print domain name stored in hash table
  */
 int domain_name_table_mi_print(struct domain_name_list** table, struct mi_node* rpl)
 {

+ 39 - 40
modules/permissions/hash.h

@@ -15,8 +15,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
@@ -76,30 +76,30 @@ void free_hash_table(struct trusted_list** table);
 void destroy_hash_table(struct trusted_list** table);
 
 
-/* 
+/*
  * Add <src_ip, proto, pattern, ruri_pattern, priority> into hash table, where proto is integer
  * representation of string argument proto.
  */
 int hash_table_insert(struct trusted_list** hash_table, char* src_ip,
-		      char* proto, char* pattern, char* ruri_pattern, char* tag, int priority);
+		char* proto, char* pattern, char* ruri_pattern, char* tag, int priority);
 
 
-/* 
+/*
  * Check if an entry exists in hash table that has given src_ip and protocol
  * value and pattern or ruri_pattern that matches to From URI.
  */
 int match_hash_table(struct trusted_list** table, struct sip_msg* msg,
-		     char *scr_ip, int proto);
+		char *scr_ip, int proto);
 
 
-/* 
- * Print entries stored in hash table 
+/*
+ * Print entries stored in hash table
  */
 void hash_table_print(struct trusted_list** hash_table, FILE* reply_file);
 int hash_table_mi_print(struct trusted_list **hash_table, struct mi_node* rpl);
 int hash_table_rpc_print(struct trusted_list **hash_table, rpc_t* rpc, void* c);
 
-/* 
+/*
  * Empty hash table
  */
 void empty_hash_table(struct trusted_list** hash_table);
@@ -109,11 +109,11 @@ void empty_hash_table(struct trusted_list** hash_table);
  * Structure stored in address hash table
  */
 struct addr_list {
-    unsigned int grp;
-    ip_addr_t addr;
-    unsigned int port;
+	unsigned int grp;
+	ip_addr_t addr;
+	unsigned int port;
 	str tag;
-    struct addr_list *next;  /* Next element in the list */
+	struct addr_list *next;  /* Next element in the list */
 };
 
 
@@ -135,54 +135,53 @@ void free_addr_hash_table(struct addr_list** table);
 void destroy_addr_hash_table(struct addr_list** table);
 
 
-/* 
+/*
  * Add <group, ip_addr, port> into hash table
  */
 int addr_hash_table_insert(struct addr_list** hash_table, unsigned int grp,
-			    ip_addr_t *addr, unsigned int port, char *tagv);
+		ip_addr_t *addr, unsigned int port, char *tagv);
 
 
-/* 
+/*
  * Check if an entry exists in hash table that has given group, ip_addr, and
  * port.  Port 0 in hash table matches any port.
  */
 int match_addr_hash_table(struct addr_list** table, unsigned int grp,
-			  ip_addr_t *addr, unsigned int port);
+		ip_addr_t *addr, unsigned int port);
 
 
-/* 
+/*
  * Checks if an ip_addr/port entry exists in address hash table in any group.
  * Port 0 in hash table matches any port.   Returns group of the first match
  * or -1 if no match is found.
  */
 int find_group_in_addr_hash_table(struct addr_list** table,
-				  ip_addr_t *addr, unsigned int port);
+		ip_addr_t *addr, unsigned int port);
 
 
-/* 
+/*
  * Print addresses stored in hash table
  */
 void addr_hash_table_print(struct addr_list** hash_table, FILE* reply_file);
 int addr_hash_table_mi_print(struct addr_list** hash_table,
-			     struct mi_node* rpl);
+		struct mi_node* rpl);
 int addr_hash_table_rpc_print(struct addr_list** table, rpc_t* rpc, void* c);
 
 
-/* 
+/*
  * Empty hash table
  */
 void empty_addr_hash_table(struct addr_list** hash_table);
 
 
-
 /*
  * Structure used to store a subnet
  */
 struct subnet {
-    unsigned int grp;        /* address group, subnet count in last record */
-    ip_addr_t  subnet;       /* IP subnet in host byte order with host bits shifted out */
-    unsigned int port;       /* port or 0 */
-    unsigned int mask;       /* how many bits belong to network part */
+	unsigned int grp;        /* address group, subnet count in last record */
+	ip_addr_t  subnet;       /* IP subnet in host byte order with host bits shifted out */
+	unsigned int port;       /* port or 0 */
+	unsigned int mask;       /* how many bits belong to network part */
 	str tag;
 };
 
@@ -193,23 +192,23 @@ struct subnet {
 struct subnet* new_subnet_table(void);
 
 
-/* 
+/*
  * Check if an entry exists in subnet table that matches given group, ip_addr,
  * and port.  Port 0 in subnet table matches any port.
  */
 int match_subnet_table(struct subnet* table, unsigned int group,
-		       ip_addr_t *addr, unsigned int port);
+		ip_addr_t *addr, unsigned int port);
 
 
-/* 
+/*
  * Checks if an entry exists in subnet table that matches given ip_addr,
  * and port.  Port 0 in subnet table matches any port.  Returns group of
  * the first match or -1 if no match is found.
  */
 int find_group_in_subnet_table(struct subnet* table,
-			       ip_addr_t *addr, unsigned int port);
+		ip_addr_t *addr, unsigned int port);
 
-/* 
+/*
  * Empty contents of subnet table
  */
 void empty_subnet_table(struct subnet *table);
@@ -221,7 +220,7 @@ void empty_subnet_table(struct subnet *table);
 void free_subnet_table(struct subnet* table);
 
 
-/* 
+/*
  * Add <grp, subnet, mask, port> into subnet table so that table is
  * kept ordered according to subnet, port, grp.
  */
@@ -230,7 +229,7 @@ int subnet_table_insert(struct subnet* table, unsigned int grp,
 			unsigned int port, char *tagv);
 
 
-/* 
+/*
  * Print subnets stored in subnet table
  */
 void subnet_table_print(struct subnet* table, FILE* reply_file);
@@ -259,34 +258,34 @@ struct domain_name_list** new_domain_name_table(void);
  */
 void free_domain_name_table(struct domain_name_list** table);
 
-/* 
+/*
  * Empty contents of domain_name hash table
  */
 void empty_domain_name_table(struct domain_name_list** table);
 
-/* 
+/*
  * Check if an entry exists in domain_name table that matches given group, domain_name,
  * and port.  Port 0 in  matches any port.
  */
 int match_domain_name_table(struct domain_name_list** table, unsigned int group,
 		str *domain_name, unsigned int port);
 
-/* 
+/*
  * Add <grp, domain_name, port> into hash table
  */
 int domain_name_table_insert(struct domain_name_list** table, unsigned int grp,
 		str *domain_name, unsigned int port, char *tagv);
 
-/* 
+/*
  * Check if an domain_name/port entry exists in hash table in any group.
  * Returns first group in which ip_addr/port is found.
- * Port 0 in hash table matches any port. 
+ * Port 0 in hash table matches any port.
  */
 int find_group_in_domain_name_table(struct domain_name_list** table,
 		str *domain_name, unsigned int port);
 
 /*! \brief
- * RPC: Print addresses stored in hash table 
+ * RPC: Print addresses stored in hash table
  */
 void domain_name_table_print(struct subnet* table, FILE* reply_file);
 int domain_name_table_rpc_print(struct domain_name_list** table, rpc_t* rpc, void* c);

+ 81 - 81
modules/permissions/mi.c

@@ -15,8 +15,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
@@ -106,11 +106,11 @@ void rpc_trusted_dump(rpc_t* rpc, void* c) {
  */
 struct mi_root* mi_address_reload(struct mi_root *cmd_tree, void *param)
 {
-    if (reload_address_table_cmd () == 1) {
-	return init_mi_tree( 200, MI_SSTR(MI_OK));
-    } else {
-	return init_mi_tree( 400, MI_SSTR("Address table reload failed"));
-    }
+	if (reload_address_table_cmd () == 1) {
+		return init_mi_tree( 200, MI_SSTR(MI_OK));
+	} else {
+		return init_mi_tree( 400, MI_SSTR("Address table reload failed"));
+	}
 }
 
 /*! \brief
@@ -131,18 +131,18 @@ void rpc_address_reload(rpc_t* rpc, void* c) {
  */
 struct mi_root* mi_address_dump(struct mi_root *cmd_tree, void *param)
 {
-    struct mi_root* rpl_tree;
-    
-    rpl_tree = init_mi_tree( 200, MI_SSTR(MI_OK));
-    if (rpl_tree==NULL) return 0;
-    
-    if(addr_hash_table_mi_print(*addr_hash_table, &rpl_tree->node) <  0) {
-	LM_ERR("failed to add a node\n");
-	free_mi_tree(rpl_tree);
-	return 0;
-    }
-
-    return rpl_tree;
+	struct mi_root* rpl_tree;
+
+	rpl_tree = init_mi_tree( 200, MI_SSTR(MI_OK));
+	if (rpl_tree==NULL) return 0;
+
+	if(addr_hash_table_mi_print(*addr_hash_table, &rpl_tree->node) <  0) {
+		LM_ERR("failed to add a node\n");
+		free_mi_tree(rpl_tree);
+		return 0;
+	}
+
+	return rpl_tree;
 }
 
 /*! \brief
@@ -167,18 +167,18 @@ void rpc_address_dump(rpc_t* rpc, void* c) {
  */
 struct mi_root* mi_subnet_dump(struct mi_root *cmd_tree, void *param)
 {
-    struct mi_root* rpl_tree;
-    
-    rpl_tree = init_mi_tree( 200, MI_SSTR(MI_OK));
-    if (rpl_tree==NULL) return 0;
-    
-    if(subnet_table && subnet_table_mi_print(*subnet_table, &rpl_tree->node) <  0) {
-	LM_ERR("failed to add a node\n");
-	free_mi_tree(rpl_tree);
-	return 0;
-    }
-
-    return rpl_tree;
+	struct mi_root* rpl_tree;
+
+	rpl_tree = init_mi_tree( 200, MI_SSTR(MI_OK));
+	if (rpl_tree==NULL) return 0;
+
+	if(subnet_table && subnet_table_mi_print(*subnet_table, &rpl_tree->node) <  0) {
+		LM_ERR("failed to add a node\n");
+		free_mi_tree(rpl_tree);
+		return 0;
+	}
+
+	return rpl_tree;
 }
 
 /*! \brief
@@ -239,51 +239,51 @@ void rpc_domain_name_dump(rpc_t* rpc, void* c) {
  */
 struct mi_root* mi_allow_uri(struct mi_root *cmd, void *param)
 {
-    struct mi_node *node;
-    str *basenamep, *urip, *contactp;
-    char basename[MAX_FILE_LEN + 1];
-    char uri[MAX_URI_SIZE + 1], contact[MAX_URI_SIZE + 1]; 
-    unsigned int allow_suffix_len;
-
-    node = cmd->node.kids;
-    if (node == NULL || node->next == NULL || node->next->next == NULL ||
-	node->next->next->next != NULL)
-	return init_mi_tree(400, MI_SSTR(MI_MISSING_PARM));
-    
-    /* look for base name */
-    basenamep = &node->value;
-    if (basenamep == NULL)
-	return init_mi_tree(404, MI_SSTR("Basename is NULL"));
-    allow_suffix_len = strlen(allow_suffix);
-    if (basenamep->len + allow_suffix_len + 1 > MAX_FILE_LEN)
-	return init_mi_tree(404, MI_SSTR("Basename is too long"));
-    memcpy(basename, basenamep->s, basenamep->len);
-    memcpy(basename + basenamep->len, allow_suffix, allow_suffix_len);
-    basename[basenamep->len + allow_suffix_len] = 0;
-
-    /* look for uri */
-    urip = &node->next->value;
-    if (urip == NULL)
-	return init_mi_tree(404, MI_SSTR("URI is NULL"));
-    if (urip->len > MAX_URI_SIZE)
-	return init_mi_tree(404, MI_SSTR("URI is too long"));
-    memcpy(uri, urip->s, urip->len);
-    uri[urip->len] = 0;
-
-    /* look for contact */
-    contactp = &node->next->next->value;
-    if (contactp == NULL)
-	return init_mi_tree(404, MI_SSTR("Contact is NULL"));
-    if (contactp->len > MAX_URI_SIZE)
-	return init_mi_tree(404, MI_SSTR("Contact is too long"));
-    memcpy(contact, contactp->s, contactp->len);
-    contact[contactp->len] = 0;
-
-    if (allow_test(basename, uri, contact) == 1) {
-	return init_mi_tree(200, MI_SSTR(MI_OK));
-    } else {
-	return init_mi_tree(403, MI_SSTR("Forbidden"));
-    }
+	struct mi_node *node;
+	str *basenamep, *urip, *contactp;
+	char basename[MAX_FILE_LEN + 1];
+	char uri[MAX_URI_SIZE + 1], contact[MAX_URI_SIZE + 1];
+	unsigned int allow_suffix_len;
+
+	node = cmd->node.kids;
+	if (node == NULL || node->next == NULL || node->next->next == NULL ||
+			node->next->next->next != NULL)
+		return init_mi_tree(400, MI_SSTR(MI_MISSING_PARM));
+
+	/* look for base name */
+	basenamep = &node->value;
+	if (basenamep == NULL)
+		return init_mi_tree(404, MI_SSTR("Basename is NULL"));
+	allow_suffix_len = strlen(allow_suffix);
+	if (basenamep->len + allow_suffix_len + 1 > MAX_FILE_LEN)
+		return init_mi_tree(404, MI_SSTR("Basename is too long"));
+	memcpy(basename, basenamep->s, basenamep->len);
+	memcpy(basename + basenamep->len, allow_suffix, allow_suffix_len);
+	basename[basenamep->len + allow_suffix_len] = 0;
+
+	/* look for uri */
+	urip = &node->next->value;
+	if (urip == NULL)
+		return init_mi_tree(404, MI_SSTR("URI is NULL"));
+	if (urip->len > MAX_URI_SIZE)
+		return init_mi_tree(404, MI_SSTR("URI is too long"));
+	memcpy(uri, urip->s, urip->len);
+	uri[urip->len] = 0;
+
+	/* look for contact */
+	contactp = &node->next->next->value;
+	if (contactp == NULL)
+		return init_mi_tree(404, MI_SSTR("Contact is NULL"));
+	if (contactp->len > MAX_URI_SIZE)
+		return init_mi_tree(404, MI_SSTR("Contact is too long"));
+	memcpy(contact, contactp->s, contactp->len);
+	contact[contactp->len] = 0;
+
+	if (allow_test(basename, uri, contact) == 1) {
+		return init_mi_tree(200, MI_SSTR(MI_OK));
+	} else {
+		return init_mi_tree(403, MI_SSTR("Forbidden"));
+	}
 }
 
 /*! \brief
@@ -291,9 +291,9 @@ struct mi_root* mi_allow_uri(struct mi_root *cmd, void *param)
  */
 void rpc_test_uri(rpc_t* rpc, void* c)
 {
-    	str basenamep, urip, contactp;
+	str basenamep, urip, contactp;
 	char basename[MAX_FILE_LEN + 1];
-	char uri[MAX_URI_SIZE + 1], contact[MAX_URI_SIZE + 1]; 
+	char uri[MAX_URI_SIZE + 1], contact[MAX_URI_SIZE + 1];
 	unsigned int allow_suffix_len;
 
 	if (rpc->scan(c, "S", &basenamep) != 1) {
@@ -310,7 +310,7 @@ void rpc_test_uri(rpc_t* rpc, void* c)
 	}
 
 	/* For some reason, rtp->scan doesn't set the length properly */
-    	if (contactp.len > MAX_URI_SIZE) {
+	if (contactp.len > MAX_URI_SIZE) {
 		rpc->fault(c, 500, "Contact is too long");
 		return;
 	}
@@ -323,10 +323,10 @@ void rpc_test_uri(rpc_t* rpc, void* c)
 	memcpy(basename, basenamep.s, basenamep.len);
 	memcpy(basename + basenamep.len, allow_suffix, allow_suffix_len);
 	basename[basenamep.len + allow_suffix_len] = 0;
-    	memcpy(uri, urip.s, urip.len);
+	memcpy(uri, urip.s, urip.len);
 	memcpy(contact, contactp.s, contactp.len);
 	contact[contactp.len] = 0;
-    	uri[urip.len] = 0;
+	uri[urip.len] = 0;
 
 	if (allow_test(basename, uri, contact) == 1) {
 		rpc->rpl_printf(c, "Allowed");

+ 2 - 2
modules/permissions/mi.h

@@ -15,8 +15,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 

+ 21 - 21
modules/permissions/parse_config.c

@@ -15,8 +15,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
@@ -34,12 +34,12 @@
  * return 0 on success, -1 on error
  * parsed expressions are returned in **e
  */
-static int parse_expression_list(char *str, expression **e) 
+static int parse_expression_list(char *str, expression **e)
 {
 	int start=0, i=-1, j=-1, apost=0;
 	char str2[EXPRESSION_LENGTH];
 	expression *e1=NULL, *e2;
-	
+
 	if (!str || !e) return -1;
 
 	*e = NULL;
@@ -64,12 +64,12 @@ static int parse_expression_list(char *str, expression **e)
 						}
 						strncpy(str2, str+start, j-start+1);
 						str2[j-start+1] = '\0';
-						
+
 						e2 = new_expression(str2);
 						if (!e2)
 							/* memory error */
 							goto error;
-						
+
 						if (e1) {
 							/* it is not the first */
 							e1->next = e2;
@@ -102,7 +102,7 @@ error:
  * return 0 on success, -1 on error
  * parsed expressions are returned in **e, and exceptions are returned in **e_exceptions
  */
-static int parse_expression(char *str, expression **e, expression **e_exceptions) 
+static int parse_expression(char *str, expression **e, expression **e_exceptions)
 {
 	char *except, str2[LINE_LENGTH+1];
 	int  i,j;
@@ -147,7 +147,7 @@ static int parse_expression(char *str, expression **e, expression **e_exceptions
  * parse one line of the config file
  * return the rule according to line
  */
-static rule *parse_config_line(char *line) 
+static rule *parse_config_line(char *line)
 {
 	rule	*rule1;
 	expression *left, *left_exceptions, *right, *right_exceptions;
@@ -165,28 +165,28 @@ static rule *parse_config_line(char *line)
 			case '"':	apost = !apost;
 					eval = 1;
 					break;
-			
+
 			case ':':	if (!apost) colon = i;
 					eval = 1;
 					break;
-			
-			case '#':	if (apost) break;			
+
+			case '#':	if (apost) break;
 			case '\0':
 			case '\n':
 					exit = 1;
 					break;
 			case ' ':	break;
 			case '\t':	break;
-				
+
 			default:	eval = 1;
-			
+
 		}
 	}
 
 	if (eval) {
 		if ((0<colon) && (colon+1<i)) {
 			/* valid line */
-			
+
 			/* left expression */
 			strncpy(str1, line, colon);
 			str1[colon] = '\0';
@@ -195,7 +195,7 @@ static rule *parse_config_line(char *line)
 				LM_ERR("failed to parse line-left: %s\n", line);
 				goto error;
 			}
-			
+
 			/* right expression */
 			strncpy(str2, line+colon+1, i-colon-1);
 			str2[i-colon-1] = '\0';
@@ -204,7 +204,7 @@ static rule *parse_config_line(char *line)
 				LM_ERR("failed to parse line-right: %s\n", line);
 				goto error;
 			}
-			
+
 			rule1 = new_rule();
 			if (!rule1) {
 				LM_ERR("can't create new rule\n");
@@ -223,13 +223,13 @@ static rule *parse_config_line(char *line)
 	}
 	return 0;
 
- error:
+error:
 	if (left) free_expression(left);
 	if (left_exceptions) free_expression(left_exceptions);
 
 	if (right) free_expression(right);
 	if (right_exceptions) free_expression(right_exceptions);
-	
+
 	return 0;
 }
 
@@ -238,7 +238,7 @@ static rule *parse_config_line(char *line)
  * parse a config file
  * return a list of rules
  */
-rule *parse_config_file(char *filename) 
+rule *parse_config_file(char *filename)
 {
 	FILE	*file;
 	char	line[LINE_LENGTH+1];
@@ -249,7 +249,7 @@ rule *parse_config_file(char *filename)
 		LM_INFO("file not found: %s\n", filename);
 		return NULL;
 	}
-	
+
 	while (fgets(line, LINE_LENGTH, file)) {
 		rule2 = parse_config_line(line);
 		if (rule2) {
@@ -263,7 +263,7 @@ rule *parse_config_file(char *filename)
 			rule1 = rule2;
 		}
 	}
-	
+
 	fclose(file);
 	return start_rule;	/* returns the linked list */
 }

+ 2 - 2
modules/permissions/parse_config.h

@@ -15,8 +15,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */

+ 44 - 16
modules/permissions/permissions.c

@@ -17,8 +17,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
@@ -42,6 +42,7 @@
 #include "../../ut.h"
 #include "../../rpc.h"
 #include "../../rpc_lookup.h"
+#include "../../kemi.h"
 
 MODULE_VERSION
 
@@ -88,7 +89,7 @@ static int check_all_branches = 1;
 
 int _perm_max_subnets = 512;
 
-/*  
+/*
  * Convert the name of the files into table index
  */
 static int load_fixup(void** param, int param_no);
@@ -142,11 +143,11 @@ static cmd_export_t cmds[] = {
 		fixup_free_spve_spve, ANY_ROUTE},
 	{"allow_uri",      (cmd_function)allow_uri, 2, double_fixup, 0,
 		REQUEST_ROUTE | FAILURE_ROUTE},
-	{"allow_address",  (cmd_function)allow_address, 3, fixup_allow_address,
+	{"allow_address",  (cmd_function)w_allow_address, 3, fixup_allow_address,
 		0, ANY_ROUTE},
-	{"allow_source_address", (cmd_function)allow_source_address, 1, fixup_igp_null, 0,
+	{"allow_source_address", (cmd_function)w_allow_source_address, 1, fixup_igp_null, 0,
 		ANY_ROUTE},
-	{"allow_source_address", (cmd_function)allow_source_address, 0, 0, 0,
+	{"allow_source_address", (cmd_function)w_allow_source_address, 0, 0, 0,
 		ANY_ROUTE},
 	{"allow_source_address_group", (cmd_function)allow_source_address_group, 0, 0, 0,
 		ANY_ROUTE},
@@ -331,7 +332,7 @@ static char* get_plain_uri(const str* uri)
  * -1:	deny
  * 1:	allow
  */
-static int check_routing(struct sip_msg* msg, int idx) 
+static int check_routing(struct sip_msg* msg, int idx)
 {
 	struct hdr_field *from;
 	int len, q;
@@ -436,7 +437,7 @@ check_branches:
 }
 
 
-/*  
+/*
  * Convert the name of the files into table index
  */
 static int load_fixup(void** param, int param_no)
@@ -502,7 +503,7 @@ static int single_fixup(void** param, int param_no)
 
 	strcpy(buffer, (char*)*param);
 	strcat(buffer, allow_suffix);
-	tmp = buffer; 
+	tmp = buffer;
 	ret = load_fixup(&tmp, 1);
 
 	strcpy(buffer + param_len, deny_suffix);
@@ -544,7 +545,7 @@ static int double_fixup(void** param, int param_no)
 
 		strcpy(buffer, (char*)*param);
 		strcat(buffer, allow_suffix);
-		tmp = buffer; 
+		tmp = buffer;
 		ret = load_fixup(&tmp, 1);
 
 		strcpy(buffer + param_len, deny_suffix);
@@ -588,7 +589,7 @@ static int double_fixup(void** param, int param_no)
 
 
 /*
- * module initialization function 
+ * module initialization function
  */
 static int mod_init(void)
 {
@@ -667,10 +668,10 @@ static int mi_addr_child_init(void)
 }
 
 
-/* 
- * destroy function 
+/*
+ * destroy function
  */
-static void mod_exit(void) 
+static void mod_exit(void)
 {
 	int i;
 
@@ -716,7 +717,7 @@ int allow_routing_2(struct sip_msg* msg, char* allow_file, char* deny_file)
 /*
  * Test of REGISTER messages. Creates To-Contact pairs and compares them
  * against rules in allow and deny files passed as parameters. The function
- * iterates over all Contacts and creates a pair with To for each contact 
+ * iterates over all Contacts and creates a pair with To for each contact
  * found. That allows to restrict what IPs may be used in registrations, for
  * example
  */
@@ -832,7 +833,7 @@ int allow_register_2(struct sip_msg* msg, char* allow_file, char* deny_file)
  * -1:	deny
  * 1:	allow
  */
-static int allow_uri(struct sip_msg* msg, char* _idx, char* _sp) 
+static int allow_uri(struct sip_msg* msg, char* _idx, char* _sp)
 {
 	struct hdr_field *from;
 	int idx, len;
@@ -1031,3 +1032,30 @@ static int permissions_init_rpc(void)
 	}
 	return 0;
 }
+
+/**
+ *
+ */
+static sr_kemi_t sr_kemi_maxfwd_exports[] = {
+	{ str_init("permissions"), str_init("allow_source_address"),
+		SR_KEMIP_INT, allow_source_address,
+		{ SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+	{ str_init("permissions"), str_init("allow_address"),
+		SR_KEMIP_INT, allow_source_address,
+		{ SR_KEMIP_INT, SR_KEMIP_STR, SR_KEMIP_INT,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+
+	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
+};
+
+/**
+ *
+ */
+int mod_register(char *path, int *dlflags, void *p1, void *p2)
+{
+	sr_kemi_modules_add(sr_kemi_maxfwd_exports);
+	return 0;
+}

+ 5 - 5
modules/permissions/permissions.h

@@ -16,12 +16,12 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
- 
+
 #ifndef PERMISSIONS_H
 #define PERMISSIONS_H 1
 
@@ -62,8 +62,8 @@ extern int peer_tag_mode; /* Matching mode */
 
 
 typedef struct int_or_pvar {
-    unsigned int i;
-    pv_spec_t *pvar;  /* zero if int */
+	unsigned int i;
+	pv_spec_t *pvar;  /* zero if int */
 } int_or_pvar_t;
 
 #define DISABLE_CACHE 0

+ 31 - 31
modules/permissions/rule.c

@@ -15,12 +15,12 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
- 
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
@@ -31,10 +31,10 @@
 #include "rule.h"
 
 
-/* 
- * allocate memory for a new rule 
+/*
+ * allocate memory for a new rule
  */
-rule *new_rule(void) 
+rule *new_rule(void)
 {
 	rule	*r;
 
@@ -49,13 +49,13 @@ rule *new_rule(void)
 }
 
 
-/* 
- * free memory allocated by a rule 
+/*
+ * free memory allocated by a rule
  */
-void free_rule(rule *r) 
+void free_rule(rule *r)
 {
 	if (!r) return;
-		
+
 	if (r->left) free_expression(r->left);
 	if (r->left_exceptions) free_expression(r->left_exceptions);
 	if (r->right) free_expression(r->right);
@@ -66,13 +66,13 @@ void free_rule(rule *r)
 }
 
 
-/* 
- * list rules 
+/*
+ * list rules
  */
-void print_rule(rule *r) 
+void print_rule(rule *r)
 {
 	if (!r) return;
-		
+
 	printf("\nNEW RULE:\n");
 	printf("\n\tLEFT: ");
 	if (r->left) print_expression(r->left);  else printf("ALL");
@@ -91,10 +91,10 @@ void print_rule(rule *r)
 }
 
 
-/* 
- * look for a proper rule matching with left:right 
+/*
+ * look for a proper rule matching with left:right
  */
-int search_rule(rule *r, char *left, char *right) 
+int search_rule(rule *r, char *left, char *right)
 {
 	rule	*r1;
 
@@ -112,14 +112,14 @@ int search_rule(rule *r, char *left, char *right)
 }
 
 
-/* 
+/*
  * allocate memory for a new expression
  * str is saved in vale, and compiled to POSIX regexp (reg_value)
  */
-expression *new_expression(char *str) 
+expression *new_expression(char *str)
 {
 	expression	*e;
-	
+
 	if (!str) return 0;
 
 	e = (expression *)pkg_malloc(sizeof(expression));
@@ -129,7 +129,7 @@ expression *new_expression(char *str)
 	}
 
 	strcpy(e->value, str);
-	
+
 	e->reg_value = (regex_t*)pkg_malloc(sizeof(regex_t));
 	if (!e->reg_value) {
 		LM_ERR("not enough pkg memory\n");
@@ -143,16 +143,16 @@ expression *new_expression(char *str)
 		pkg_free(e);
 		return NULL;
 	}
-	
+
 	e->next = 0;
 	return e;
 }
 
 
-/* 
- * free memory allocated by an expression 
+/*
+ * free memory allocated by an expression
  */
-void free_expression(expression *e) 
+void free_expression(expression *e)
 {
 	if (!e) return;
 
@@ -162,10 +162,10 @@ void free_expression(expression *e)
 }
 
 
-/* 
- * list expressions 
+/*
+ * list expressions
  */
-void print_expression(expression *e) 
+void print_expression(expression *e)
 {
 	if (!e) return;
 
@@ -174,10 +174,10 @@ void print_expression(expression *e)
 }
 
 
-/* 
- * look for matching expression 
+/*
+ * look for matching expression
  */
-int search_expression(expression *e, char *value) 
+int search_expression(expression *e, char *value)
 {
 	expression	*e1;
 

+ 4 - 4
modules/permissions/rule.h

@@ -15,12 +15,12 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
- 
+
 #ifndef RULE_H
 #define RULE_H 1
 
@@ -35,7 +35,7 @@ typedef struct rule_struct rule;
 
 struct expression_struct;
 typedef struct expression_struct expression;
-	
+
 rule *new_rule(void);
 void free_rule(rule *r);
 void print_rule(rule *r);

+ 172 - 172
modules/permissions/trusted.c

@@ -15,8 +15,8 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  *
  */
@@ -66,13 +66,13 @@ int reload_trusted_table(void)
 	char *pattern, *ruri_pattern, *tag;
 
 	if (hash_table == 0) {
-	    LM_ERR("in-memory hash table not initialized\n");
-	    return -1;
+		LM_ERR("in-memory hash table not initialized\n");
+		return -1;
 	}
 
 	if (db_handle == 0) {
-	    LM_ERR("no connection to database\n");
-	    return -1;
+		LM_ERR("no connection to database\n");
+		return -1;
 	}
 
 	cols[0] = &source_col;
@@ -103,59 +103,59 @@ int reload_trusted_table(void)
 	row = RES_ROWS(res);
 
 	LM_DBG("number of rows in trusted table: %d\n", RES_ROW_N(res));
-		
+
 	for (i = 0; i < RES_ROW_N(res); i++) {
-	    val = ROW_VALUES(row + i);
-	    if ((ROW_N(row + i) == 6) &&
-		((VAL_TYPE(val) == DB1_STRING) || (VAL_TYPE(val) == DB1_STR) ) && 
-		!VAL_NULL(val) &&
-		((VAL_TYPE(val + 1) == DB1_STRING) || (VAL_TYPE(val + 1) == DB1_STR))
-		&& !VAL_NULL(val + 1) &&
-		(VAL_NULL(val + 2) ||
-		 (((VAL_TYPE(val + 2) == DB1_STRING) || (VAL_TYPE(val + 2) == DB1_STR)) &&
-		!VAL_NULL(val + 2))) && (VAL_NULL(val + 3) ||
-		 (((VAL_TYPE(val + 3) == DB1_STRING) || (VAL_TYPE(val + 3) == DB1_STR) )&&
-		!VAL_NULL(val + 3))) && (VAL_NULL(val + 4) ||
-		 (((VAL_TYPE(val + 4) == DB1_STRING) || (VAL_TYPE(val + 4) == DB1_STR) )&&
-		!VAL_NULL(val + 4)))) {
-		if (VAL_NULL(val + 2)) {
-		    pattern = 0;
-		} else {
-		    pattern = (char *)VAL_STRING(val + 2);
-		}
-		if (VAL_NULL(val + 3)) {
-		    ruri_pattern = 0;
-		} else {
-		    ruri_pattern = (char *)VAL_STRING(val + 3);
-		}
-		if (VAL_NULL(val + 4)) {
-		    tag = 0;
-		} else {
-		    tag = (char *)VAL_STRING(val + 4);
-		}
-		if (VAL_NULL(val + 5)) {
-		    priority = 0;
+		val = ROW_VALUES(row + i);
+		if ((ROW_N(row + i) == 6) &&
+				((VAL_TYPE(val) == DB1_STRING) || (VAL_TYPE(val) == DB1_STR) ) &&
+				!VAL_NULL(val) &&
+				((VAL_TYPE(val + 1) == DB1_STRING) || (VAL_TYPE(val + 1) == DB1_STR))
+				&& !VAL_NULL(val + 1) &&
+				(VAL_NULL(val + 2) ||
+				(((VAL_TYPE(val + 2) == DB1_STRING) || (VAL_TYPE(val + 2) == DB1_STR)) &&
+				!VAL_NULL(val + 2))) && (VAL_NULL(val + 3) ||
+				(((VAL_TYPE(val + 3) == DB1_STRING) || (VAL_TYPE(val + 3) == DB1_STR) )&&
+				!VAL_NULL(val + 3))) && (VAL_NULL(val + 4) ||
+				(((VAL_TYPE(val + 4) == DB1_STRING) || (VAL_TYPE(val + 4) == DB1_STR) )&&
+				!VAL_NULL(val + 4)))) {
+			if (VAL_NULL(val + 2)) {
+				pattern = 0;
+			} else {
+				pattern = (char *)VAL_STRING(val + 2);
+			}
+			if (VAL_NULL(val + 3)) {
+				ruri_pattern = 0;
+			} else {
+				ruri_pattern = (char *)VAL_STRING(val + 3);
+			}
+			if (VAL_NULL(val + 4)) {
+				tag = 0;
+			} else {
+				tag = (char *)VAL_STRING(val + 4);
+			}
+			if (VAL_NULL(val + 5)) {
+				priority = 0;
+			} else {
+				priority = (int)VAL_INT(val + 5);
+			}
+			if (hash_table_insert(new_hash_table,
+						(char *)VAL_STRING(val),
+						(char *)VAL_STRING(val + 1),
+						pattern, ruri_pattern, tag, priority) == -1) {
+				LM_ERR("hash table problem\n");
+				perm_dbf.free_result(db_handle, res);
+				empty_hash_table(new_hash_table);
+				return -1;
+			}
+			LM_DBG("tuple <%s, %s, %s, %s, %s> inserted into trusted hash "
+					"table\n", VAL_STRING(val), VAL_STRING(val + 1),
+					pattern, ruri_pattern, tag);
 		} else {
-		    priority = (int)VAL_INT(val + 5);
-		}
-		if (hash_table_insert(new_hash_table,
-				      (char *)VAL_STRING(val),
-				      (char *)VAL_STRING(val + 1),
-				      pattern, ruri_pattern, tag, priority) == -1) {
-		    LM_ERR("hash table problem\n");
-		    perm_dbf.free_result(db_handle, res);
-		    empty_hash_table(new_hash_table);
-		    return -1;
+			LM_ERR("database problem\n");
+			perm_dbf.free_result(db_handle, res);
+			empty_hash_table(new_hash_table);
+			return -1;
 		}
-		LM_DBG("tuple <%s, %s, %s, %s, %s> inserted into trusted hash "
-		    "table\n", VAL_STRING(val), VAL_STRING(val + 1),
-		    pattern, ruri_pattern, tag);
-	    } else {
-		LM_ERR("database problem\n");
-		perm_dbf.free_result(db_handle, res);
-		empty_hash_table(new_hash_table);
-		return -1;
-	    }
 	}
 
 	perm_dbf.free_result(db_handle, res);
@@ -165,7 +165,7 @@ int reload_trusted_table(void)
 	empty_hash_table(old_hash_table);
 
 	LM_DBG("trusted table reloaded successfully.\n");
-	
+
 	return 1;
 }
 
@@ -178,7 +178,7 @@ int init_trusted(void)
 	/* Check if hash table needs to be loaded from trusted table */
 	if (!db_url.s) {
 		LM_INFO("db_url parameter of permissions module not set, "
-			"disabling allow_trusted\n");
+				"disabling allow_trusted\n");
 		return 0;
 	} else {
 		if (db_bind_mod(&db_url, &perm_dbf) < 0) {
@@ -210,10 +210,10 @@ int init_trusted(void)
 
 		hash_table_1 = new_hash_table();
 		if (!hash_table_1) return -1;
-		
+
 		hash_table_2  = new_hash_table();
 		if (!hash_table_2) goto error;
-		
+
 		hash_table = (struct trusted_list ***)shm_malloc
 			(sizeof(struct trusted_list **));
 		if (!hash_table) goto error;
@@ -271,7 +271,7 @@ int init_child_trusted(int rank)
 	}
 
 	if (db_check_table_version(&perm_dbf, db_handle, &trusted_table,
-				   TABLE_VERSION) < 0) {
+				TABLE_VERSION) < 0) {
 		LM_ERR("error during table version check.\n");
 		perm_dbf.close(db_handle);
 		return -1;
@@ -286,13 +286,13 @@ int init_child_trusted(int rank)
  */
 int mi_init_trusted(void)
 {
-    if (!db_url.s) return 0;
-    db_handle = perm_dbf.init(&db_url);
-    if (!db_handle) {
-	LM_ERR("unable to connect database\n");
-	return -1;
-    }
-    return 0;
+	if (!db_url.s) return 0;
+	db_handle = perm_dbf.init(&db_url);
+	if (!db_handle) {
+		LM_ERR("unable to connect database\n");
+		return -1;
+	}
+	return 0;
 }
 
 
@@ -313,10 +313,10 @@ void clean_trusted(void)
  */
 static inline int match_proto(const char *proto_string, int proto_int)
 {
-        if ((proto_int == PROTO_NONE) ||
-	                (strcasecmp(proto_string, "any") == 0))
-	        return 1;
-	
+	if ((proto_int == PROTO_NONE) ||
+			(strcasecmp(proto_string, "any") == 0))
+		return 1;
+
 	if (proto_int == PROTO_UDP) {
 		if (strcasecmp(proto_string, "udp") == 0) {
 			return 1;
@@ -324,7 +324,7 @@ static inline int match_proto(const char *proto_string, int proto_int)
 			return 0;
 		}
 	}
-	
+
 	if (proto_int == PROTO_TCP) {
 		if (strcasecmp(proto_string, "tcp") == 0) {
 			return 1;
@@ -332,7 +332,7 @@ static inline int match_proto(const char *proto_string, int proto_int)
 			return 0;
 		}
 	}
-	
+
 	if (proto_int == PROTO_TLS) {
 		if (strcasecmp(proto_string, "tls") == 0) {
 			return 1;
@@ -340,7 +340,7 @@ static inline int match_proto(const char *proto_string, int proto_int)
 			return 0;
 		}
 	}
-	
+
 	if (proto_int == PROTO_SCTP) {
 		if (strcasecmp(proto_string, "sctp") == 0) {
 			return 1;
@@ -356,7 +356,7 @@ static inline int match_proto(const char *proto_string, int proto_int)
 			return 0;
 		}
 	}
-	
+
 	if (proto_int == PROTO_WSS) {
 		if (strcasecmp(proto_string, "wss") == 0) {
 			return 1;
@@ -410,40 +410,40 @@ static int match_res(struct sip_msg* msg, int proto, db1_res_t* _r)
 	for(i = 0; i < RES_ROW_N(_r); i++) {
 		val = ROW_VALUES(row + i);
 		if ((ROW_N(row + i) == 4) &&
-		    (VAL_TYPE(val) == DB1_STRING) && !VAL_NULL(val) &&
-		    match_proto(VAL_STRING(val), proto) &&
-		    (VAL_NULL(val + 1) ||
-		      ((VAL_TYPE(val + 1) == DB1_STRING) && !VAL_NULL(val + 1))) &&
-		    (VAL_NULL(val + 2) ||
-		      ((VAL_TYPE(val + 2) == DB1_STRING) && !VAL_NULL(val + 2))) &&
-		    (VAL_NULL(val + 3) ||
-		      ((VAL_TYPE(val + 3) == DB1_STRING) && !VAL_NULL(val + 3))))
+				(VAL_TYPE(val) == DB1_STRING) && !VAL_NULL(val) &&
+				match_proto(VAL_STRING(val), proto) &&
+				(VAL_NULL(val + 1) ||
+				((VAL_TYPE(val + 1) == DB1_STRING) && !VAL_NULL(val + 1))) &&
+				(VAL_NULL(val + 2) ||
+				((VAL_TYPE(val + 2) == DB1_STRING) && !VAL_NULL(val + 2))) &&
+				(VAL_NULL(val + 3) ||
+				((VAL_TYPE(val + 3) == DB1_STRING) && !VAL_NULL(val + 3))))
 		{
 			if (IS_SIP(msg)) {
-			    if (!VAL_NULL(val + 1)) {
-				if (regcomp(&preg, (char *)VAL_STRING(val + 1), REG_NOSUB)) {
-					LM_ERR("invalid regular expression\n");
-					if (VAL_NULL(val + 2)) {
+				if (!VAL_NULL(val + 1)) {
+					if (regcomp(&preg, (char *)VAL_STRING(val + 1), REG_NOSUB)) {
+						LM_ERR("invalid regular expression\n");
+						if (VAL_NULL(val + 2)) {
+							continue;
+						}
+					}
+					if (regexec(&preg, uri_string, 0, (regmatch_t *)0, 0)) {
+						regfree(&preg);
 						continue;
 					}
-				}
-				if (regexec(&preg, uri_string, 0, (regmatch_t *)0, 0)) {
 					regfree(&preg);
-					continue;
-				}
-				regfree(&preg);
-			    }
-			    if (!VAL_NULL(val + 2)) {
-				if (regcomp(&preg, (char *)VAL_STRING(val + 2), REG_NOSUB)) {
-					LM_ERR("invalid regular expression\n");
-					continue;
 				}
-				if (regexec(&preg, ruri_string, 0, (regmatch_t *)0, 0)) {
+				if (!VAL_NULL(val + 2)) {
+					if (regcomp(&preg, (char *)VAL_STRING(val + 2), REG_NOSUB)) {
+						LM_ERR("invalid regular expression\n");
+						continue;
+					}
+					if (regexec(&preg, ruri_string, 0, (regmatch_t *)0, 0)) {
+						regfree(&preg);
+						continue;
+					}
 					regfree(&preg);
-					continue;
 				}
-				regfree(&preg);
-			    }
 			}
 			/* Found a match */
 			if (tag_avp.n && !VAL_NULL(val + 3)) {
@@ -454,14 +454,14 @@ static int match_res(struct sip_msg* msg, int proto, db1_res_t* _r)
 					return -1;
 				}
 			}
-			if (!peer_tag_mode) 
+			if (!peer_tag_mode)
 				return 1;
 			count++;
 		}
 	}
 	if (!count)
 		return -1;
-	else 
+	else
 		return count;
 }
 
@@ -470,22 +470,22 @@ static int match_res(struct sip_msg* msg, int proto, db1_res_t* _r)
  * Checks based on given source IP address and protocol, and From URI
  * of request if request can be trusted without authentication.
  */
-int allow_trusted(struct sip_msg* msg, char *src_ip, int proto) 
+int allow_trusted(struct sip_msg* msg, char *src_ip, int proto)
 {
 	int result;
 	db1_res_t* res = NULL;
-	
+
 	db_key_t keys[1];
 	db_val_t vals[1];
 	db_key_t cols[4];
 
 	if (db_mode == DISABLE_CACHE) {
 		db_key_t order = &priority_col;
-	
-	        if (db_handle == 0) {
-		    LM_ERR("no connection to database\n");
-		    return -1;
-	        }
+
+		if (db_handle == 0) {
+			LM_ERR("no connection to database\n");
+			return -1;
+		}
 
 		keys[0] = &source_col;
 		cols[0] = &proto_col;
@@ -497,13 +497,13 @@ int allow_trusted(struct sip_msg* msg, char *src_ip, int proto)
 			LM_ERR("failed to use trusted table\n");
 			return -1;
 		}
-		
+
 		VAL_TYPE(vals) = DB1_STRING;
 		VAL_NULL(vals) = 0;
 		VAL_STRING(vals) = src_ip;
 
 		if (perm_dbf.query(db_handle, keys, 0, vals, cols, 1, 4, order,
-				   &res) < 0){
+					&res) < 0){
 			LM_ERR("failed to query database\n");
 			return -1;
 		}
@@ -512,7 +512,7 @@ int allow_trusted(struct sip_msg* msg, char *src_ip, int proto)
 			perm_dbf.free_result(db_handle, res);
 			return -1;
 		}
-		
+
 		result = match_res(msg, proto, res);
 		perm_dbf.free_result(db_handle, res);
 		return result;
@@ -526,10 +526,10 @@ int allow_trusted(struct sip_msg* msg, char *src_ip, int proto)
  * Checks based on request's source address, protocol, and From URI
  * if request can be trusted without authentication.
  */
-int allow_trusted_0(struct sip_msg* _msg, char* str1, char* str2) 
+int allow_trusted_0(struct sip_msg* _msg, char* str1, char* str2)
 {
-    return allow_trusted(_msg, ip_addr2a(&(_msg->rcv.src_ip)),
-			 _msg->rcv.proto);
+	return allow_trusted(_msg, ip_addr2a(&(_msg->rcv.src_ip)),
+			_msg->rcv.proto);
 }
 
 
@@ -537,64 +537,64 @@ int allow_trusted_0(struct sip_msg* _msg, char* str1, char* str2)
  * Checks based on source address and protocol given in pvar arguments and
  * and requests's From URI, if request can be trusted without authentication.
  */
-int allow_trusted_2(struct sip_msg* _msg, char* _src_ip_sp, char* _proto_sp) 
+int allow_trusted_2(struct sip_msg* _msg, char* _src_ip_sp, char* _proto_sp)
 {
-    str src_ip, proto;
-    int proto_int;
+	str src_ip, proto;
+	int proto_int;
 
-    if (_src_ip_sp==NULL
-	|| (fixup_get_svalue(_msg, (gparam_p)_src_ip_sp, &src_ip) != 0)) {
-	LM_ERR("src_ip param does not exist or has no value\n");
-	return -1;
-    }
-    
-    if (_proto_sp==NULL
-	|| (fixup_get_svalue(_msg, (gparam_p)_proto_sp, &proto) != 0)) {
-	LM_ERR("proto param does not exist or has no value\n");
-	return -1;
-    }
-
-    if(proto.len<2 || proto.len>4)
-	goto error;
-
-    switch(proto.s[0]) {
-    case 'a': case 'A':
-	if (proto.len==3 && strncasecmp(proto.s, "any", 3) == 0) {
-	    proto_int = PROTO_NONE;
-	} else goto error;
-	break;
-    case 'u': case 'U':
-	if (proto.len==3 && strncasecmp(proto.s, "udp", 3) == 0) {
-	    proto_int = PROTO_UDP;
-	} else goto error;
-	break;
-    case 't': case 'T':
-	if (proto.len==3 && strncasecmp(proto.s, "tcp", 3) == 0) {
-	    proto_int = PROTO_TCP;
-	} else if (proto.len==3 && strncasecmp(proto.s, "tls", 3) == 0) {
-	    proto_int = PROTO_TLS;
-	} else goto error;
-	break;
-    case 's': case 'S':
-	if (proto.len==4 && strncasecmp(proto.s, "sctp", 4) == 0) {
-	    proto_int = PROTO_SCTP;
-	} else goto error;
-	break;
-    case 'w': case 'W':
-	if (proto.len==2 && strncasecmp(proto.s, "ws", 2) == 0) {
-	    proto_int = PROTO_WS;
-	} else if (proto.len==3 && strncasecmp(proto.s, "wss", 3) == 0) {
-	    proto_int = PROTO_WSS;
-	} else goto error;
-        break;
-    default:
-	goto error;
-    }
-
-    return allow_trusted(_msg, src_ip.s, proto_int);
+	if (_src_ip_sp==NULL
+			|| (fixup_get_svalue(_msg, (gparam_p)_src_ip_sp, &src_ip) != 0)) {
+		LM_ERR("src_ip param does not exist or has no value\n");
+		return -1;
+	}
+
+	if (_proto_sp==NULL
+			|| (fixup_get_svalue(_msg, (gparam_p)_proto_sp, &proto) != 0)) {
+		LM_ERR("proto param does not exist or has no value\n");
+		return -1;
+	}
+
+	if(proto.len<2 || proto.len>4)
+		goto error;
+
+	switch(proto.s[0]) {
+		case 'a': case 'A':
+			if (proto.len==3 && strncasecmp(proto.s, "any", 3) == 0) {
+				proto_int = PROTO_NONE;
+			} else goto error;
+			break;
+		case 'u': case 'U':
+			if (proto.len==3 && strncasecmp(proto.s, "udp", 3) == 0) {
+				proto_int = PROTO_UDP;
+			} else goto error;
+			break;
+		case 't': case 'T':
+			if (proto.len==3 && strncasecmp(proto.s, "tcp", 3) == 0) {
+				proto_int = PROTO_TCP;
+			} else if (proto.len==3 && strncasecmp(proto.s, "tls", 3) == 0) {
+				proto_int = PROTO_TLS;
+			} else goto error;
+			break;
+		case 's': case 'S':
+			if (proto.len==4 && strncasecmp(proto.s, "sctp", 4) == 0) {
+				proto_int = PROTO_SCTP;
+			} else goto error;
+			break;
+		case 'w': case 'W':
+			if (proto.len==2 && strncasecmp(proto.s, "ws", 2) == 0) {
+				proto_int = PROTO_WS;
+			} else if (proto.len==3 && strncasecmp(proto.s, "wss", 3) == 0) {
+				proto_int = PROTO_WSS;
+			} else goto error;
+			break;
+		default:
+			goto error;
+	}
+
+	return allow_trusted(_msg, src_ip.s, proto_int);
 error:
-    LM_ERR("unknown protocol %.*s\n", proto.len, proto.s);
-    return -1;
+	LM_ERR("unknown protocol %.*s\n", proto.len, proto.s);
+	return -1;
 }
 
 

+ 3 - 3
modules/permissions/trusted.h

@@ -15,14 +15,14 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License 
- * along with this program; if not, write to the Free Software 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
 #ifndef TRUSTED_H
 #define TRUSTED_H
-		
+
 #include "../../parser/msg_parser.h"