[asterisk-commits] murf: trunk r89272 - /trunk/main/pbx.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Nov 14 12:05:51 CST 2007


Author: murf
Date: Wed Nov 14 12:05:50 2007
New Revision: 89272

URL: http://svn.digium.com/view/asterisk?view=rev&rev=89272
Log:
Rescaled the weights of the patterns to give something more independent of pattern length; and make . less likely to win. Question: which should win for 14102241145-- _1xxxxxxx.   or  _XXXXXXXXXXX  -- right now, the pure X pattern will win.

Modified:
    trunk/main/pbx.c

Modified: trunk/main/pbx.c
URL: http://svn.digium.com/view/asterisk/trunk/main/pbx.c?view=diff&rev=89272&r1=89271&r2=89272
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Wed Nov 14 12:05:50 2007
@@ -892,7 +892,7 @@
 	for (p=tree; p; p=p->alt_char) {
 		if (p->x[0] == 'N' && p->x[1] == 0 && *str >= '2' && *str <= '9' ) {
 			if (p->exten) /* if a shorter pattern matches along the way, might as well report it */
-				update_scoreboard(score, length+1, spec+8, p->exten,0,callerid);
+				update_scoreboard(score, length+1, spec+p->specificity, p->exten,0,callerid);
 
 			if (p->next_char && ( *(str+1) || (p->next_char->x[0] == '/' && p->next_char->x[1] == 0))) {
 				if (*(str+1))
@@ -907,7 +907,7 @@
 			}
 		} else if (p->x[0] == 'Z' && p->x[1] == 0 && *str >= '1' && *str <= '9' ) {
 			if (p->exten) /* if a shorter pattern matches along the way, might as well report it */
-				update_scoreboard(score, length+1, spec+8, p->exten,0,callerid);
+				update_scoreboard(score, length+1, spec+p->specificity, p->exten,0,callerid);
 
 			if (p->next_char && ( *(str+1) || (p->next_char->x[0] == '/' && p->next_char->x[1] == 0))) {
 				if (*(str+1))
@@ -922,7 +922,7 @@
 			}
 		} else if (p->x[0] == 'X' && p->x[1] == 0 && *str >= '0' && *str <= '9' ) {
 			if (p->exten) /* if a shorter pattern matches along the way, might as well report it */
-				update_scoreboard(score, length+1, spec+8, p->exten,0,callerid);
+				update_scoreboard(score, length+1, spec+p->specificity, p->exten,0,callerid);
 
 			if (p->next_char && ( *(str+1) || (p->next_char->x[0] == '/' && p->next_char->x[1] == 0))) {
 				if (*(str+1))
@@ -936,15 +936,27 @@
 				return;
 			}
 		} else if (p->x[0] == '.' && p->x[1] == 0) {
-			update_scoreboard(score, length+1, spec+11, p->exten, '.', callerid);
+			/* how many chars will the . match against? */
+			int i = 0;
+			while (*str++) {
+				i++;
+			}
+			if (p->exten)
+				update_scoreboard(score, length+i, spec+(i*p->specificity), p->exten, '.', callerid);
 			if (p->next_char && p->next_char->x[0] == '/' && p->next_char->x[1] == 0) {
-				new_find_extension("/", score, p->next_char, length+1, spec+p->specificity, callerid);
+				new_find_extension("/", score, p->next_char, length+i, spec+(p->specificity*i), callerid);
 			}
 			return;
 		} else if (p->x[0] == '!' && p->x[1] == 0) {
-			update_scoreboard(score, length+1, spec+11, p->exten, '!', callerid);
+			/* how many chars will the . match against? */
+			int i = 0;
+			while (*str++) {
+				i++;
+			}
+			if (p->exten)
+				update_scoreboard(score, length+1, spec+(p->specificity*i), p->exten, '!', callerid);
 			if (p->next_char && p->next_char->x[0] == '/' && p->next_char->x[1] == 0) {
-				new_find_extension("/", score, p->next_char, length+1, spec+p->specificity, callerid);
+				new_find_extension("/", score, p->next_char, length+i, spec+(p->specificity*i), callerid);
 			}
 			return;
 		} else if (p->x[0] == '/' && p->x[1] == 0) {
@@ -954,7 +966,7 @@
 			}
 		} else if (index(p->x, *str)) {
 			if (p->exten) /* if a shorter pattern matches along the way, might as well report it */
-				update_scoreboard(score, length+1, spec+8, p->exten,0,callerid);
+				update_scoreboard(score, length+1, spec+p->specificity, p->exten,0,callerid);
 
 
 			if (p->next_char && ( *(str+1) || (p->next_char->x[0] == '/' && p->next_char->x[1] == 0))) {
@@ -1006,15 +1018,15 @@
 	m->x = strdup(pattern);
 	m->is_pattern = is_pattern;
 	if (specificity == 1 && is_pattern && pattern[0] == 'N')
-		m->specificity = 8;
+		m->specificity = 98;
 	else if (specificity == 1 && is_pattern && pattern[0] == 'Z')
-		m->specificity = 9;
+		m->specificity = 99;
 	else if (specificity == 1 && is_pattern && pattern[0] == 'X')
-		m->specificity = 10;
+		m->specificity = 100;
 	else if (specificity == 1 && is_pattern && pattern[0] == '.')
-		m->specificity = 11;
+		m->specificity = 200;
 	else if (specificity == 1 && is_pattern && pattern[0] == '!')
-		m->specificity = 11;
+		m->specificity = 200;
 	else
 		m->specificity = specificity;
 	
@@ -4260,9 +4272,16 @@
 		if (option_debug && c->pattern_tree)
 		{
 			ast_cli(fd,"\r\n     In-mem exten Trie for Fast Extension Pattern Matching:\r\n\r\n");
+
+			ast_cli(fd,"\r\n           Explanation: Node Contents Format = <char(s) to match>:<pattern?>:<specif>:[matched extension]\r\n");
+			ast_cli(fd,    "                        Where <char(s) to match> is a set of chars, any one of which should match the current character\r\n");
+			ast_cli(fd,    "                              <pattern?>: Y if this a pattern match (eg. _XZN[5-7]), N otherwise\r\n");
+			ast_cli(fd,    "                              <specif>: an assigned 'exactness' number for this matching char. The lower the number, the more exact the match\r\n");
+			ast_cli(fd,    "                              [matched exten]: If all chars matched to this point, which extension this matches. In form: EXTEN:<exten string> \r\n");
+			ast_cli(fd,    "                        In general, you match a trie node to a string character, from left to right. All possible matching chars\r\n");
+			ast_cli(fd,    "                        are in a string vertically, separated by an unbroken string of '+' characters.\r\n\r\n");
 			cli_match_char_tree(c->pattern_tree, " ", fd);
 		}
-		
 
 		ast_unlock_context(c);
 




More information about the asterisk-commits mailing list