[sr-dev] git:master:073f25f8: function for node index calculation added

Savolainen Dmitri savolainen at erinaco.ru
Mon Jun 15 11:35:20 CEST 2015


Module: kamailio
Branch: master
Commit: 073f25f8d9181fe1d64e6a418bfee5889e4280ac
URL: https://github.com/kamailio/kamailio/commit/073f25f8d9181fe1d64e6a418bfee5889e4280ac

Author: Savolainen Dmitri <savolainen at erinaco.ru>
Committer: Savolainen Dmitri <savolainen at erinaco.ru>
Date: 2015-06-11T20:14:58+03:00

function for node index calculation added

---

Modified: modules/drouting/prefix_tree.c
Modified: modules/drouting/prefix_tree.h

---

Diff:  https://github.com/kamailio/kamailio/commit/073f25f8d9181fe1d64e6a418bfee5889e4280ac.diff
Patch: https://github.com/kamailio/kamailio/commit/073f25f8d9181fe1d64e6a418bfee5889e4280ac.patch

---

diff --git a/modules/drouting/prefix_tree.c b/modules/drouting/prefix_tree.c
index 2229144..b601d7a 100644
--- a/modules/drouting/prefix_tree.c
+++ b/modules/drouting/prefix_tree.c
@@ -119,7 +119,6 @@ get_prefix(
 {
 	rt_info_t *rt = NULL;
 	char *tmp=NULL;
-	char local=0;
 	int idx=0;
 
 	if(NULL == ptree)
@@ -132,24 +131,10 @@ get_prefix(
 	while(tmp< (prefix->s+prefix->len)) {
 		if(NULL == tmp)
 			goto err_exit;
-		local=*tmp;
-			
-		if( IS_DECIMAL_DIGIT(local) ) {
-			idx = local -'0';
-		}
-		else if (local == '*'){
-			idx = 10;
-		}
-		else if (local == '#'){
-			idx = 11;
-		}
-		else if (local == '+'){
-			idx = 12;
-		}
-		else{
+		idx = get_node_index(*tmp);
+		if (idx == -1){
 			/* unknown character in the prefix string */
 			goto err_exit;
-
 		}
 		if( tmp == (prefix->s+prefix->len-1) ) {
 			/* last digit in the prefix string */
@@ -168,13 +153,7 @@ get_prefix(
 		if(NULL == tmp)
 			goto err_exit;
 		/* is it a real node or an intermediate one */
-		idx = *tmp-'0';
-		if (*tmp == '*')
-			idx = 10;
-		else if (*tmp == '#')
-			idx = 11;
-		else if (*tmp == '+')
-			idx = 12;
+		idx = get_node_index(*tmp);
 		if(NULL != ptree->ptnode[idx].rg) {
 			/* real node; check the constraints on the routing info*/
 			if( NULL != (rt = internal_check_rt( &(ptree->ptnode[idx]), rgid)))
@@ -225,22 +204,8 @@ add_prefix(
 	while(tmp < (prefix->s+prefix->len)) {
 		if(NULL == tmp)
 			goto err_exit;
-		int insert_index = -1;
-		if( IS_DECIMAL_DIGIT(*tmp)  ) {
-			/* unknown character in the prefix string */
-			insert_index = *tmp - '0';
-		}
-		else if (*tmp=='*'){
-			insert_index = 10;
-		}
-		else if (*tmp=='#'){
-			insert_index = 11;
-		}
-		else if (*tmp=='+'){
-			insert_index = 12;
-		}
-
-		else{
+		int insert_index = get_node_index(*tmp);
+		if (insert_index == -1){
 			/* unknown character in the prefix string */
 			goto err_exit;
 		}
@@ -353,3 +318,32 @@ print_rt(
 				rt->pgwl[i].pgw->pri.len, rt->pgwl[i].pgw->pri.s,
 				rt->pgwl[i].pgw->ip.len, rt->pgwl[i].pgw->ip.s);
 }
+
+
+int
+get_node_index(
+		char ch
+		)
+{
+	switch (ch)
+	{
+		case '0':
+		case '1':
+		case '2':
+		case '3':
+		case '4':
+		case '5':
+		case '6':
+		case '7':
+		case '8':
+		case '9':
+			return ch - '0';
+		case '*':
+			return 10;
+		case '#':
+			return 11;
+		case '+':
+			return 12;
+	}
+	return -1;
+}
diff --git a/modules/drouting/prefix_tree.h b/modules/drouting/prefix_tree.h
index 4ebc8f7..41065e3 100644
--- a/modules/drouting/prefix_tree.h
+++ b/modules/drouting/prefix_tree.h
@@ -35,8 +35,6 @@
 #include "dr_time.h"
 
 #define PTREE_CHILDREN 13  //decimal digits, '*', '#',  '+'
-#define IS_DECIMAL_DIGIT(d) \
-	(((d)>='0') && ((d)<= '9'))
 
 extern int tree_size;
 
@@ -176,4 +174,9 @@ check_rt(
 	unsigned int rgid
 	);
 
+int
+get_node_index(
+	char ch
+	);
+
 #endif




More information about the sr-dev mailing list