[svn-commits] murf: branch murf/fast-ast2 r88451 - in /team/murf/fast-ast2: ./ main/ pbx/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sat Nov 3 11:10:03 CDT 2007


Author: murf
Date: Sat Nov  3 11:10:02 2007
New Revision: 88451

URL: http://svn.digium.com/view/asterisk?view=rev&rev=88451
Log:
Cleanup: incremental add of extens to exten trie. reload issues to handle.

Modified:
    team/murf/fast-ast2/Makefile
    team/murf/fast-ast2/main/pbx.c
    team/murf/fast-ast2/pbx/pbx_ael.c

Modified: team/murf/fast-ast2/Makefile
URL: http://svn.digium.com/view/asterisk/team/murf/fast-ast2/Makefile?view=diff&rev=88451&r1=88450&r2=88451
==============================================================================
--- team/murf/fast-ast2/Makefile (original)
+++ team/murf/fast-ast2/Makefile Sat Nov  3 11:10:02 2007
@@ -24,7 +24,6 @@
 # Default values fo ASTCFLAGS and ASTLDFLAGS can be specified in the
 # environment when running make, as follows:
 #
-# $ ASTCFLAGS="-Werror" make
 
 export ASTTOPDIR
 export ASTERISKVERSION
@@ -78,8 +77,8 @@
 
 # Some build systems, such as the one in openwrt, like to pass custom target
 # CFLAGS and LDFLAGS in the COPTS and LDOPTS variables.
-ASTCFLAGS+=$(COPTS)
-ASTLDFLAGS+=$(LDOPTS)
+ASTCFLAGS+=$(COPTS) -pg
+ASTLDFLAGS+=$(LDOPTS) -pg
 
 #Uncomment this to see all build commands instead of 'quiet' output
 #NOISY_BUILD=yes

Modified: team/murf/fast-ast2/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/murf/fast-ast2/main/pbx.c?view=diff&rev=88451&r1=88450&r2=88451
==============================================================================
--- team/murf/fast-ast2/main/pbx.c (original)
+++ team/murf/fast-ast2/main/pbx.c Sat Nov  3 11:10:02 2007
@@ -187,7 +187,8 @@
 struct match_char
 {
 	int is_pattern; /* the pattern started with '_' */
-	char *x;
+	int deleted;    /* if this is set, then... don't return it */
+	char *x;       /* the pattern itself-- matches a single char */
 	int specificity; /* simply the strlen of x, or 10 for X, 9 for Z, and 8 for N; and '.' and '!' will add 11 ? */
 	struct match_char *alt_char;
 	struct match_char *next_char;
@@ -208,7 +209,7 @@
 struct ast_context {
 	ast_rwlock_t lock; 			/*!< A lock to prevent multiple threads from clobbering the context */
 	struct ast_exten *root;			/*!< The root of the list of extensions */
-	struct ast_hashtab *root_tree;            /*!< The root of the list of extensions in threaded red-black tree form */
+	struct ast_hashtab *root_tree;            /*!< For exact matches on the extensions in the pattern tree, and for traversals of the pattern_tree  */
  	struct match_char *pattern_tree;        /*!< A tree to speed up extension pattern matching */
 	struct ast_context *next;		/*!< Link them together */
 	struct ast_include *includes;		/*!< Include other contexts */
@@ -325,9 +326,11 @@
 static void set_ext_pri(struct ast_channel *c, const char *exten, int pri);
 void new_find_extension(const char *str, struct scoreboard *score, struct match_char *tree, int length, int spec, const char *callerid);
 struct match_char *already_in_tree(struct match_char *current, char *pat);
+struct match_char *add_exten_to_pattern_tree(struct ast_context *con, struct ast_exten *e1);
 struct match_char *add_pattern_node(struct ast_context *con, struct match_char *current, char *pattern, int is_pattern, int already, int specificity);
-struct match_char *create_match_char_tree(struct ast_context *con);
+void create_match_char_tree(struct ast_context *con);
 struct ast_exten *get_canmatch_exten(struct match_char *node);
+void destroy_pattern_tree(struct match_char *pattern_tree);
 static int matchcid(const char *cidpattern, const char *callerid);
 static int hashtab_compare_contexts(const void *ah_a, const void *ah_b);
 static int hashtab_compare_extens(const void *ha_a, const void *ah_b);
@@ -865,8 +868,7 @@
 void new_find_extension(const char *str, struct scoreboard *score, struct match_char *tree, int length, int spec, const char *callerid)
 {
 	struct match_char *p; /* note minimal stack storage requirements */
-	for (p=tree; p; p=p->alt_char)
-	{
+	for (p=tree; p; p=p->alt_char) {
 		if (p->x[0] == 'N' && p->x[1] == 0 && *str >= '2' && *str <= '9' ) {
 			if (p->next_char && *(str+1))
 				new_find_extension(str+1, score, p->next_char, length+1, spec+8, callerid);
@@ -921,7 +923,6 @@
 			} else {
 				return;
 			}
-
 		}
 	}
 }
@@ -989,14 +990,81 @@
 	return m;
 }
 
-struct match_char *create_match_char_tree(struct ast_context *con)
+struct match_char *add_exten_to_pattern_tree(struct ast_context *con, struct ast_exten *e1)
+{
+	struct match_char *m1=0,*m2=0;
+	int specif;
+	int already;
+	int pattern = 0;
+	char buf[256];
+	char *s1 = e1->exten;
+#ifdef NEED_DEBUG
+	ast_log(LOG_DEBUG,"Adding exten %s to tree\n", s1);
+#endif
+	m1 = con->pattern_tree; /* each pattern starts over at the root of the pattern tree */
+	already = 1;
+
+	if ( *s1 == '_') {
+		pattern = 1;
+		s1++;
+	}
+	while( *s1 ) {
+		if (pattern && *s1 == '[' && *(s1-1) != '\\') {
+			char *s2 = buf;
+			while (*s1 != ']' && *(s1-1) != '\\' ) {
+				if (*s1 == '\\') {
+					if (*(s1+1) == ']') {
+						*s2++ = ']';
+						s1++;s1++;
+					} else if (*(s1+1) == '\\') {
+						*s2++ = '\\';
+						s1++;s1++;
+					} else if (*(s1+1) == '-') {
+						*s2++ = '-';
+						s1++; s1++;
+					} else if (*(s1+1) == '[') {
+						*s2++ = '[';
+						s1++; s1++;
+					}
+				} else if (*s1 == '-') { /* remember to add some error checking to all this! */
+					char s3 = *(s1-1);
+					char s4 = *(s1+1);
+					for (s3++; s3 <= s4; s3++) {
+						*s2++ = s3;
+					}
+					s1++; s1++;
+				} else {
+					*s2++ = *s1++;
+				}
+			}
+			specif = strlen(buf);
+		} else {
+			if (*s1 == '\\') {
+				s1++;
+				buf[0] = *s1;
+			} else {
+				buf[0] = *s1;
+			}
+			buf[1] = 0;
+			specif = 1;
+		}
+		
+		if (already && (m2=already_in_tree(m1,buf))) {
+			m1 = m2->next_char; /* m1 points to the node to compare against */
+		} else {
+			m1 = add_pattern_node(con, m1, buf, pattern, already,specif); /* m1 is the node just added */
+			already = 0;
+		}
+		s1++; /* advance to next char */
+	}
+	m1->exten =  e1; /* that last node should have an exten pointer */
+	return m1;
+}
+
+void create_match_char_tree(struct ast_context *con)
 {
 	struct ast_hashtab_iter *t1;
 	struct ast_exten *e1;
-	struct match_char *m1=0,*m2=0;
-	char buf[256];
-	int already;
-	int specif;
 #ifdef NEED_DEBUG
 	int biggest_bucket, resizes, numobjs, numbucks;
 	
@@ -1007,72 +1075,27 @@
 #endif
 	t1 = ast_hashtab_start_traversal(con->root_tree);
 	while( (e1 = ast_hashtab_next(t1)) ) {
-		int pattern = 0;
-		char *s1 = e1->exten;
-#ifdef NEED_DEBUG
-		ast_log(LOG_DEBUG,"Adding exten %s to tree\n", s1);
-#endif
-		m1 = con->pattern_tree; /* each pattern starts over at the root of the pattern tree */
-		already = 1;
-
-		if ( *s1 == '_') {
-			pattern = 1;
-			s1++;
-		}
-		while( *s1 )
-		{
-			if (pattern && *s1 == '[' && *(s1-1) != '\\') {
-				char *s2 = buf;
-				while (*s1 != ']' && *(s1-1) != '\\' ) {
-					if (*s1 == '\\') {
-						if (*(s1+1) == ']') {
-							*s2++ = ']';
-							s1++;s1++;
-						} else if (*(s1+1) == '\\') {
-							*s2++ = '\\';
-							s1++;s1++;
-						} else if (*(s1+1) == '-') {
-							*s2++ = '-';
-							s1++; s1++;
-						} else if (*(s1+1) == '[') {
-							*s2++ = '[';
-							s1++; s1++;
-						}
-					} else if (*s1 == '-') { /* remember to add some error checking to all this! */
-						char s3 = *(s1-1);
-						char s4 = *(s1+1);
-						for (s3++; s3 <= s4; s3++) {
-							*s2++ = s3;
-						}
-						s1++; s1++;
-					} else {
-						*s2++ = *s1++;
-					}
-				}
-				specif = strlen(buf);
-			} else {
-				if (*s1 == '\\') {
-					s1++;
-					buf[0] = *s1;
-				} else {
-					buf[0] = *s1;
-				}
-				buf[1] = 0;
-				specif = 1;
-			}
-
-			if (already && (m2=already_in_tree(m1,buf))) {
-				m1 = m2->next_char; /* m1 points to the node to compare against */
-			} else {
-				m1 = add_pattern_node(con, m1, buf, pattern, already,specif); /* m1 is the node just added */
-				already = 0;
-			}
-			s1++; /* advance to next char */
-		}
-		m1->exten =  e1; /* that last node should have an exten pointer */
+		add_exten_to_pattern_tree(con, e1);
 	}
 	ast_hashtab_end_traversal(t1);
-	return m1; /* just in case you want to see how the pattern ended */
+}
+
+void destroy_pattern_tree(struct match_char *pattern_tree) /* pattern tree is a simple binary tree, sort of, so the proper way to destroy it is... recursively! */
+{
+	/* destroy all the alternates */
+	if (pattern_tree->alt_char) {
+		destroy_pattern_tree(pattern_tree->alt_char);
+		pattern_tree->alt_char = 0;
+	}
+	/* destroy all the nexts */
+	if (pattern_tree->next_char) {
+		destroy_pattern_tree(pattern_tree->next_char);
+		pattern_tree->next_char = 0;
+	}
+	pattern_tree->exten = 0; /* never hurts to make sure there's no pointers laying around */
+	if (pattern_tree->x)
+		free(pattern_tree->x);
+	free(pattern_tree);
 }
 
 /*
@@ -4713,6 +4736,11 @@
 			tmp = tmp->next;
 		}
 	}
+	tmp = *extcontexts;
+	while (tmp) {
+		ast_hashtab_insert_safe(contexts_tree, tmp); /*put this context into the tree */
+		tmp = tmp->next;
+	}
 	if (lasttmp) {
 		lasttmp->next = contexts;
 		contexts = *extcontexts;
@@ -5542,11 +5570,13 @@
 	 * All priorities for the same ext/pattern/cid are kept in a list,
 	 * using the 'peer' field  as a link field..
 	 */
-	struct ast_exten *tmp, *e, *el = NULL;
+	struct ast_exten *tmp, *tmp2, *e, *el = NULL;
 	int res;
 	int length;
 	char *p;
 	char expand_buf[VAR_BUF_SIZE];
+	struct ast_exten dummy_exten;
+	char dummy_name[1024];
 
 	/* if we are adding a hint, and there are global variables, and the hint
 	   contains variable references, then expand them
@@ -5598,6 +5628,17 @@
 	tmp->registrar = registrar;
 
 	ast_wrlock_context(con);
+	
+	if (con->pattern_tree) { /* usually, on initial load, the pattern_tree isn't formed until the first find_exten; so if we are adding
+								an extension, and the trie exists, then we need to incrementally add this pattern to it. */
+		strncpy(dummy_name,extension,sizeof(dummy_name));
+		dummy_exten.exten = dummy_name;
+		tmp2 = ast_hashtab_lookup(con->root_tree,&dummy_exten);
+		if (!tmp2) {
+			/* hmmm, not in the trie; */
+			add_exten_to_pattern_tree(con, tmp);
+		}
+	}
 	res = 0; /* some compilers will think it is uninitialized otherwise */
 	for (e = con->root; e; el = e, e = e->next) {   /* scan the extension list */
 		res = ext_cmp(e->exten, extension);
@@ -5686,7 +5727,7 @@
 	}
 
 	if (tmp->matchcid) {
-		ast_verb(3, "Added extension '%s' priority %d (CID match '%s')to %s\n",
+		ast_verb(3, "Added extension '%s' priority %d (CID matcvih '%s')to %s\n",
 			tmp->exten, tmp->priority, tmp->cidmatch, con->name);
 	} else {
 		ast_verb(3, "Added extension '%s' priority %d to %s\n",
@@ -6125,6 +6166,14 @@
 			ipi = ipi->next;
 			ast_free(ipl);
 		}
+		/* destroy the hash tabs */
+		if (tmp->root_tree) {
+			ast_hashtab_destroy(tmp->root_tree, 0);
+		}
+		/* and destroy the pattern tree */
+		if (tmp->pattern_tree)
+			destroy_pattern_tree(tmp->pattern_tree);
+		
 		while ((sw = AST_LIST_REMOVE_HEAD(&tmp->alts, list)))
 			ast_free(sw);
 		for (e = tmp->root; e;) {

Modified: team/murf/fast-ast2/pbx/pbx_ael.c
URL: http://svn.digium.com/view/asterisk/team/murf/fast-ast2/pbx/pbx_ael.c?view=diff&rev=88451&r1=88450&r2=88451
==============================================================================
--- team/murf/fast-ast2/pbx/pbx_ael.c (original)
+++ team/murf/fast-ast2/pbx/pbx_ael.c Sat Nov  3 11:10:02 2007
@@ -123,8 +123,6 @@
 		rfilename = alloca(strlen(config) + strlen(ast_config_AST_CONFIG_DIR) + 2);
 		sprintf(rfilename, "%s/%s", ast_config_AST_CONFIG_DIR, config);
 	}
-	ast_log(LOG_NOTICE, "AEL load process: calculated config file name '%s'.\n", rfilename);
-
 	if (access(rfilename,R_OK) != 0) {
 		ast_log(LOG_NOTICE, "File %s not found; AEL declining load\n", rfilename);
 		return AST_MODULE_LOAD_DECLINE;




More information about the svn-commits mailing list