[asterisk-commits] tilghman: trunk r181027 - /trunk/main/pbx.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Mar 10 19:28:31 CDT 2009


Author: tilghman
Date: Tue Mar 10 19:28:28 2009
New Revision: 181027

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=181027
Log:
Spacing changes only

Modified:
    trunk/main/pbx.c

Modified: trunk/main/pbx.c
URL: http://svn.digium.com/svn-view/asterisk/trunk/main/pbx.c?view=diff&rev=181027&r1=181026&r2=181027
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Tue Mar 10 19:28:28 2009
@@ -76,13 +76,13 @@
  *
  * A new algorithm to do searching based on a 'compiled' pattern tree is introduced
  * here, and shows a fairly flat (constant) search time, even for over
- * 10000 patterns. 
+ * 10000 patterns.
  *
  * Also, using a hash table for context/priority name lookup can help prevent
- * the find_extension routines from absorbing exponential cpu cycles as the number 
- * of contexts/priorities grow. I've previously tested find_extension with red-black trees, 
- * which have O(log2(n)) speed. Right now, I'm using hash tables, which do 
- * searches (ideally) in O(1) time. While these techniques do not yield much 
+ * the find_extension routines from absorbing exponential cpu cycles as the number
+ * of contexts/priorities grow. I've previously tested find_extension with red-black trees,
+ * which have O(log2(n)) speed. Right now, I'm using hash tables, which do
+ * searches (ideally) in O(1) time. While these techniques do not yield much
  * speed in small dialplans, they are worth the trouble in large dialplans.
  *
  */
@@ -142,7 +142,7 @@
 			<parameter name="context">
 				<para>This is the dialplan context that this application will use when exiting
 				to a dialed extension.</para>
-			</parameter>	
+			</parameter>
 		</syntax>
 		<description>
 			<para>This application will play the given list of files <emphasis>(do not put extension)</emphasis>
@@ -773,7 +773,7 @@
 	int priority;			/*!< Priority */
 	const char *label;		/*!< Label */
 	struct ast_context *parent;	/*!< The context this extension belongs to  */
-	const char *app; 		/*!< Application to execute */
+	const char *app;		/*!< Application to execute */
 	struct ast_app *cached_app;     /*!< Cached location of application */
 	void *data;			/*!< Data to use (arguments) */
 	void (*datad)(void *);		/*!< Data destructor */
@@ -838,10 +838,10 @@
 
 /*! \brief ast_context: An extension context */
 struct ast_context {
-	ast_rwlock_t lock; 			/*!< A lock to prevent multiple threads from clobbering the 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_table;            /*!< 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 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 */
 	struct ast_ignorepat *ignorepats;	/*!< Patterns for which to continue playing dialtone */
@@ -879,12 +879,12 @@
 /*! \brief Structure for dial plan hints
 
   \note Hints are pointers from an extension in the dialplan to one or
-  more devices (tech/name) 
+  more devices (tech/name)
 	- See \ref AstExtState
 */
 struct ast_hint {
 	struct ast_exten *exten;	/*!< Extension */
-	int laststate; 			/*!< Last known state */
+	int laststate;			/*!< Last known state */
 	AST_LIST_HEAD_NOLOCK(, ast_state_cb) callbacks; /*!< Callback list for this extension */
 	AST_RWLIST_ENTRY(ast_hint) list;/*!< Pointer to next hint in list */
 };
@@ -945,15 +945,15 @@
 void log_match_char_tree(struct match_char *node, char *prefix); /* for use anywhere */
 int pbx_builtin_setvar_multiple(struct ast_channel *, void *);
 static int pbx_builtin_importvar(struct ast_channel *, void *);
-static void set_ext_pri(struct ast_channel *c, const char *exten, int pri); 
-static void new_find_extension(const char *str, struct scoreboard *score, 
-		struct match_char *tree, int length, int spec, const char *callerid, 
+static void set_ext_pri(struct ast_channel *c, const char *exten, int pri);
+static void new_find_extension(const char *str, struct scoreboard *score,
+		struct match_char *tree, int length, int spec, const char *callerid,
 		const char *label, enum ext_match_t action);
 static struct match_char *already_in_tree(struct match_char *current, char *pat);
-static struct match_char *add_exten_to_pattern_tree(struct ast_context *con, 
+static struct match_char *add_exten_to_pattern_tree(struct ast_context *con,
 		struct ast_exten *e1, int findonly);
-static struct match_char *add_pattern_node(struct ast_context *con, 
-		struct match_char *current, char *pattern, int is_pattern, 
+static 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 **parent);
 static void create_match_char_tree(struct ast_context *con);
 static struct ast_exten *get_canmatch_exten(struct match_char *node);
@@ -1009,7 +1009,7 @@
 	if (x) { /* if exten names are diff, then return */
 		return x;
 	}
-	
+
 	/* but if they are the same, do the cidmatch values match? */
 	if (ac->matchcid && bc->matchcid) {
 		return strcmp(ac->cidmatch,bc->cidmatch);
@@ -1119,7 +1119,7 @@
 static struct ast_context *contexts;
 static struct ast_hashtab *contexts_table = NULL;
 
-AST_RWLOCK_DEFINE_STATIC(conlock); 		/*!< Lock for the ast_context list */
+AST_RWLOCK_DEFINE_STATIC(conlock);		/*!< Lock for the ast_context list */
 
 static AST_RWLIST_HEAD_STATIC(apps, ast_app);
 
@@ -1169,10 +1169,10 @@
 	int found = 0;
 	struct ast_exten *e1, *e2, *e3;
 	struct ast_exten ex;
-	
+
 	/* try to find inconsistencies */
 	/* is every context in the context table in the context list and vice-versa ? */
-	
+
 	if (!contexts_table) {
 		ast_log(LOG_NOTICE,"Called from: %s:%d: No contexts_table!\n", file, line);
 		usleep(500000);
@@ -1228,7 +1228,7 @@
 					check_contexts_trouble();
 				}
 			}
-			
+
 			/* is every entry in the root_table also in the root list? */ 
 			if (!c2->root_table) {
 				if (c2->root) {
@@ -1248,40 +1248,40 @@
 						ast_log(LOG_NOTICE,"Called from: %s:%d: The %s context records the exten %s but it is not in its root_table\n", file, line, c2->name, e2->exten);
 						check_contexts_trouble();
 					}
-					
+
 				}
 				ast_hashtab_end_traversal(t1);
 			}
 		}
 		/* is every priority reflected in the peer_table at the head of the list? */
-		
+
 		/* is every entry in the root list also in the root_table? */
 		/* are the per-extension peer_tables in the right place? */
 
 		for(e1 = c2->root; e1; e1 = e1->next) {
-			
+
 			for(e2=e1;e2;e2=e2->peer) {
 				ex.priority = e2->priority;
 				if (e2 != e1 && e2->peer_table) {
 					ast_log(LOG_NOTICE,"Called from: %s:%d: The %s context, %s exten, %d priority has a peer_table entry, and shouldn't!\n", file, line, c2->name, e1->exten, e2->priority );
 					check_contexts_trouble();
 				}
-				
+
 				if (e2 != e1 && e2->peer_label_table) {
 					ast_log(LOG_NOTICE,"Called from: %s:%d: The %s context, %s exten, %d priority has a peer_label_table entry, and shouldn't!\n", file, line, c2->name, e1->exten, e2->priority );
 					check_contexts_trouble();
 				}
-				
+
 				if (e2 == e1 && !e2->peer_table){
 					ast_log(LOG_NOTICE,"Called from: %s:%d: The %s context, %s exten, %d priority doesn't have a peer_table!\n", file, line, c2->name, e1->exten, e2->priority );
 					check_contexts_trouble();
 				}
-				
+
 				if (e2 == e1 && !e2->peer_label_table) {
 					ast_log(LOG_NOTICE,"Called from: %s:%d: The %s context, %s exten, %d priority doesn't have a peer_label_table!\n", file, line, c2->name, e1->exten, e2->priority );
 					check_contexts_trouble();
 				}
-				
+
 
 				e3 = ast_hashtab_lookup(e1->peer_table, &ex);
 				if (!e3) {
@@ -1289,13 +1289,13 @@
 					check_contexts_trouble();
 				}
 			}
-			
+
 			if (!e1->peer_table){
 				ast_log(LOG_NOTICE,"Called from: %s:%d: No e1->peer_table!\n", file, line);
 				usleep(500000);
 			}
-			
-			/* is every entry in the peer_table also in the peer list? */ 
+
+			/* is every entry in the peer_table also in the peer list? */
 			t1 = ast_hashtab_start_traversal(e1->peer_table);
 			while( (e2 = ast_hashtab_next(t1)) ) {
 				for(e3=e1;e3;e3=e3->peer) {
@@ -1319,9 +1319,9 @@
 /*
    \note This function is special. It saves the stack so that no matter
    how many times it is called, it returns to the same place */
-int pbx_exec(struct ast_channel *c, 		/*!< Channel */
-	     struct ast_app *app,		/*!< Application */
-	     void *data)			/*!< Data for execution */
+int pbx_exec(struct ast_channel *c, /*!< Channel */
+	     struct ast_app *app,       /*!< Application */
+	     void *data)                /*!< Data for execution */
 {
 	int res;
 	struct ast_module_user *u = NULL;
@@ -1395,30 +1395,30 @@
 	ast_free(p);
 }
 
-/* form a tree that fully describes all the patterns in a context's extensions 
+/* form a tree that fully describes all the patterns in a context's extensions
  * in this tree, a "node" represents an individual character or character set
- * meant to match the corresponding character in a dial string. The tree 
+ * meant to match the corresponding character in a dial string. The tree
  * consists of a series of match_char structs linked in a chain
- * via the alt_char pointers. More than one pattern can share the same parts of the 
- * tree as other extensions with the same pattern to that point. 
+ * via the alt_char pointers. More than one pattern can share the same parts of the
+ * tree as other extensions with the same pattern to that point.
  * My first attempt to duplicate the finding of the 'best' pattern was flawed in that
  * I misunderstood the general algorithm. I thought that the 'best' pattern
  * was the one with lowest total score. This was not true. Thus, if you have
  * patterns "1XXXXX" and "X11111", you would be tempted to say that "X11111" is
- * the "best" match because it has fewer X's, and is therefore more specific, 
+ * the "best" match because it has fewer X's, and is therefore more specific,
  * but this is not how the old algorithm works. It sorts matching patterns
- * in a similar collating sequence as sorting alphabetic strings, from left to 
+ * in a similar collating sequence as sorting alphabetic strings, from left to
  * right. Thus, "1XXXXX" comes before "X11111", and would be the "better" match,
  * because "1" is more specific than "X".
  * So, to accomodate this philosophy, I sort the tree branches along the alt_char
  * line so they are lowest to highest in specificity numbers. This way, as soon
- * as we encounter our first complete match, we automatically have the "best" 
+ * as we encounter our first complete match, we automatically have the "best"
  * match and can stop the traversal immediately. Same for CANMATCH/MATCHMORE.
  * If anyone would like to resurrect the "wrong" pattern trie searching algorithm,
  * they are welcome to revert pbx to before 1 Apr 2008.
  * As an example, consider these 4 extensions:
  * (a) NXXNXXXXXX
- * (b) 307754XXXX 
+ * (b) 307754XXXX
  * (c) fax
  * (d) NXXXXXXXXX
  *
@@ -1450,7 +1450,7 @@
  *   the previous. The same goes for "CANMATCH" or "MATCHMORE"; the first such match ends the traversal. In both
  *   these cases, the reason we can stop immediately, is because the first pattern match found will be the "best"
  *   according to the sort criteria.
- *   Hope the limit on stack depth won't be a problem... this routine should 
+ *   Hope the limit on stack depth won't be a problem... this routine should
  *   be pretty lean as far a stack usage goes. Any non-match terminates the recursion down a branch.
  *
  *   In the above example, with the number "3077549999" as the pattern, the traversor could match extensions a, b and d.  All are
@@ -1488,20 +1488,20 @@
 void log_match_char_tree(struct match_char *node, char *prefix)
 {
 	char extenstr[40];
-	struct ast_str *my_prefix = ast_str_alloca(1024); 
+	struct ast_str *my_prefix = ast_str_alloca(1024);
 
 	extenstr[0] = '\0';
 
 	if (node && node->exten && node->exten)
 		snprintf(extenstr, sizeof(extenstr), "(%p)", node->exten);
-	
+
 	if (strlen(node->x) > 1) {
-		ast_debug(1, "%s[%s]:%c:%c:%d:%s%s%s\n", prefix, node->x, node->is_pattern ? 'Y':'N', 
-			node->deleted? 'D':'-', node->specificity, node->exten? "EXTEN:":"", 
+		ast_debug(1, "%s[%s]:%c:%c:%d:%s%s%s\n", prefix, node->x, node->is_pattern ? 'Y':'N',
+			node->deleted? 'D':'-', node->specificity, node->exten? "EXTEN:":"",
 			node->exten ? node->exten->exten : "", extenstr);
 	} else {
-		ast_debug(1, "%s%s:%c:%c:%d:%s%s%s\n", prefix, node->x, node->is_pattern ? 'Y':'N', 
-			node->deleted? 'D':'-', node->specificity, node->exten? "EXTEN:":"", 
+		ast_debug(1, "%s%s:%c:%c:%d:%s%s%s\n", prefix, node->x, node->is_pattern ? 'Y':'N',
+			node->deleted? 'D':'-', node->specificity, node->exten? "EXTEN:":"",
 			node->exten ? node->exten->exten : "", extenstr);
 	}
 
@@ -1518,19 +1518,19 @@
 {
 	char extenstr[40];
 	struct ast_str *my_prefix = ast_str_alloca(1024);
-	
+
 	extenstr[0] = '\0';
 
 	if (node && node->exten && node->exten)
 		snprintf(extenstr, sizeof(extenstr), "(%p)", node->exten);
-	
+
 	if (strlen(node->x) > 1) {
-		ast_cli(fd, "%s[%s]:%c:%c:%d:%s%s%s\n", prefix, node->x, node->is_pattern ? 'Y' : 'N', 
-			node->deleted ? 'D' : '-', node->specificity, node->exten? "EXTEN:" : "", 
+		ast_cli(fd, "%s[%s]:%c:%c:%d:%s%s%s\n", prefix, node->x, node->is_pattern ? 'Y' : 'N',
+			node->deleted ? 'D' : '-', node->specificity, node->exten? "EXTEN:" : "",
 			node->exten ? node->exten->exten : "", extenstr);
 	} else {
-		ast_cli(fd, "%s%s:%c:%c:%d:%s%s%s\n", prefix, node->x, node->is_pattern ? 'Y' : 'N', 
-			node->deleted ? 'D' : '-', node->specificity, node->exten? "EXTEN:" : "", 
+		ast_cli(fd, "%s%s:%c:%c:%d:%s%s%s\n", prefix, node->x, node->is_pattern ? 'Y' : 'N',
+			node->deleted ? 'D' : '-', node->specificity, node->exten? "EXTEN:" : "",
 			node->exten ? node->exten->exten : "", extenstr);
 	}
 
@@ -1567,28 +1567,34 @@
 	struct match_char *m3;
 	struct match_char *m4;
 	struct ast_exten *e3;
-	
-	if (node && node->x[0] == '.' && !node->x[1]) /* dot and ! will ALWAYS be next match in a matchmore */
+
+	if (node && node->x[0] == '.' && !node->x[1]) { /* dot and ! will ALWAYS be next match in a matchmore */
 		return node->exten;
-	
-	if (node && node->x[0] == '!' && !node->x[1])
+	}
+
+	if (node && node->x[0] == '!' && !node->x[1]) {
 		return node->exten;
-	
-	if (!node || !node->next_char)
+	}
+
+	if (!node || !node->next_char) {
 		return NULL;
-	
+	}
+
 	m3 = node->next_char;
 
-	if (m3->exten)
+	if (m3->exten) {
 		return m3->exten;
-	for(m4=m3->alt_char; m4; m4 = m4->alt_char) {
-		if (m4->exten)
+	}
+	for (m4 = m3->alt_char; m4; m4 = m4->alt_char) {
+		if (m4->exten) {
 			return m4->exten;
-	}
-	for(m4=m3; m4; m4 = m4->alt_char) {
+		}
+	}
+	for (m4 = m3; m4; m4 = m4->alt_char) {
 		e3 = trie_find_next_match(m3);
-		if (e3)
+		if (e3) {
 			return e3;
+		}
 	}
 	return NULL;
 }
@@ -1596,8 +1602,7 @@
 #ifdef DEBUG_THIS
 static char *action2str(enum ext_match_t action)
 {
-	switch(action)
-	{
+	switch (action) {
 	case E_MATCH:
 		return "MATCH";
 	case E_CANMATCH:
@@ -1625,13 +1630,13 @@
 	else
 		ast_log(LOG_NOTICE,"new_find_extension called with %s on (sub)tree NULL action=%s\n", str, action2str(action));
 #endif
-	for (p=tree; p; p=p->alt_char) {
+	for (p = tree; p; p = p->alt_char) {
 		if (p->x[0] == 'N') {
 			if (p->x[1] == 0 && *str >= '2' && *str <= '9' ) {
 #define NEW_MATCHER_CHK_MATCH	       \
-				if (p->exten && !(*(str+1))) { /* if a shorter pattern matches along the way, might as well report it */             \
+				if (p->exten && !(*(str + 1))) { /* if a shorter pattern matches along the way, might as well report it */           \
 					if (action == E_MATCH || action == E_SPAWN || action == E_FINDLABEL) { /* if in CANMATCH/MATCHMORE, don't let matches get in the way */   \
-						update_scoreboard(score, length+1, spec+p->specificity, p->exten,0,callerid, p->deleted, p);                 \
+						update_scoreboard(score, length + 1, spec + p->specificity, p->exten, 0, callerid, p->deleted, p);           \
 						if (!p->deleted) {                                                                                           \
 							if (action == E_FINDLABEL) {                                                                             \
 								if (ast_hashtab_lookup(score->exten->peer_label_table, &pattern)) {                                  \
@@ -1645,33 +1650,33 @@
 						}                                                                                                            \
 					}                                                                                                                \
 				}
-				
+
 #define NEW_MATCHER_RECURSE	           \
-				if (p->next_char && ( *(str+1) || (p->next_char->x[0] == '/' && p->next_char->x[1] == 0)                 \
-                                               || p->next_char->x[0] == '!')) {                                          \
-					if (*(str+1) || p->next_char->x[0] == '!') {                                                         \
-						new_find_extension(str+1, score, p->next_char, length+1, spec+p->specificity, callerid, label, action); \
+				if (p->next_char && ( *(str + 1) || (p->next_char->x[0] == '/' && p->next_char->x[1] == 0)               \
+                                                 || p->next_char->x[0] == '!')) {                                        \
+					if (*(str + 1) || p->next_char->x[0] == '!') {                                                       \
+						new_find_extension(str + 1, score, p->next_char, length + 1, spec+p->specificity, callerid, label, action); \
 						if (score->exten)  {                                                                             \
-					        ast_debug(4,"returning an exact match-- %s\n", score->exten->exten);                         \
+					        ast_debug(4, "returning an exact match-- %s\n", score->exten->exten);                        \
 							return; /* the first match is all we need */                                                 \
 						}												                                                 \
 					} else {                                                                                             \
-						new_find_extension("/", score, p->next_char, length+1, spec+p->specificity, callerid, label, action);	 \
+						new_find_extension("/", score, p->next_char, length + 1, spec+p->specificity, callerid, label, action);	 \
 						if (score->exten || ((action == E_CANMATCH || action == E_MATCHMORE) && score->canmatch)) {      \
 					        ast_debug(4,"returning a (can/more) match--- %s\n", score->exten ? score->exten->exten :     \
-                                       "NULL");                                                                        \
+                                       "NULL");                                                                          \
 							return; /* the first match is all we need */                                                 \
 						}												                                                 \
 					}                                                                                                    \
-				} else if (p->next_char && !*(str+1)) {                                                                  \
+				} else if (p->next_char && !*(str + 1)) {                                                                \
 					score->canmatch = 1;                                                                                 \
 					score->canmatch_exten = get_canmatch_exten(p);                                                       \
 					if (action == E_CANMATCH || action == E_MATCHMORE) {                                                 \
-				        ast_debug(4,"returning a canmatch/matchmore--- str=%s\n", str);                                  \
+				        ast_debug(4, "returning a canmatch/matchmore--- str=%s\n", str);                                 \
 						return;                                                                                          \
 					}												                                                     \
 				}
-				
+
 				NEW_MATCHER_CHK_MATCH;
 				NEW_MATCHER_RECURSE;
 			}
@@ -1680,7 +1685,7 @@
 				NEW_MATCHER_CHK_MATCH;
 				NEW_MATCHER_RECURSE;
 			}
-		} else if (p->x[0] == 'X') { 
+		} else if (p->x[0] == 'X') {
 			if (p->x[1] == 0 && *str >= '0' && *str <= '9' ) {
 				NEW_MATCHER_CHK_MATCH;
 				NEW_MATCHER_RECURSE;
@@ -1703,7 +1708,7 @@
 			if (p->next_char && p->next_char->x[0] == '/' && p->next_char->x[1] == 0) {
 				new_find_extension("/", score, p->next_char, length+i, spec+(p->specificity*i), callerid, label, action);
 				if (score->exten || ((action == E_CANMATCH || action == E_MATCHMORE) && score->canmatch)) {
-					ast_debug(4,"return because scoreboard has exact match OR CANMATCH/MATCHMORE & canmatch set--- %s\n", score->exten ? score->exten->exten : "NULL");
+					ast_debug(4, "return because scoreboard has exact match OR CANMATCH/MATCHMORE & canmatch set--- %s\n", score->exten ? score->exten->exten : "NULL");
 					return; /* the first match is all we need */
 				}
 			}
@@ -1716,14 +1721,14 @@
 				i++;
 			}
 			if (p->exten && *str2 != '/') {
-				update_scoreboard(score, length+1, spec+(p->specificity*i), p->exten, '!', callerid, p->deleted, p);
+				update_scoreboard(score, length + 1, spec+(p->specificity * i), p->exten, '!', callerid, p->deleted, p);
 				if (score->exten) {
-					ast_debug(4,"return because scoreboard has a '!' match--- %s\n", score->exten->exten);
+					ast_debug(4, "return because scoreboard has a '!' match--- %s\n", score->exten->exten);
 					return; /* the first match is all we need */
 				}
 			}
 			if (p->next_char && p->next_char->x[0] == '/' && p->next_char->x[1] == 0) {
-				new_find_extension("/", score, p->next_char, length+i, spec+(p->specificity*i), callerid, label, action);
+				new_find_extension("/", score, p->next_char, length + i, spec + (p->specificity * i), callerid, label, action);
 				if (score->exten || ((action == E_CANMATCH || action == E_MATCHMORE) && score->canmatch)) {
 					ast_debug(4,"return because scoreboard has exact match OR CANMATCH/MATCHMORE & canmatch set with '/' and '!'--- %s\n", score->exten ? score->exten->exten : "NULL");
 					return; /* the first match is all we need */
@@ -1734,7 +1739,7 @@
 			if (p->next_char && callerid && *callerid) {
 				new_find_extension(callerid, score, p->next_char, length+1, spec, callerid, label, action);
 				if (score->exten || ((action == E_CANMATCH || action == E_MATCHMORE) && score->canmatch)) {
-					ast_debug(4,"return because scoreboard has exact match OR CANMATCH/MATCHMORE & canmatch set with '/'--- %s\n", score->exten ? score->exten->exten : "NULL");
+					ast_debug(4, "return because scoreboard has exact match OR CANMATCH/MATCHMORE & canmatch set with '/'--- %s\n", score->exten ? score->exten->exten : "NULL");
 					return; /* the first match is all we need */
 				}
 			}
@@ -1744,16 +1749,16 @@
 			NEW_MATCHER_RECURSE;
 		}
 	}
-	ast_debug(4,"return at end of func\n");
-}
-
-/* the algorithm for forming the extension pattern tree is also a bit simple; you 
+	ast_debug(4, "return at end of func\n");
+}
+
+/* the algorithm for forming the extension pattern tree is also a bit simple; you
  * traverse all the extensions in a context, and for each char of the extension,
  * you see if it exists in the tree; if it doesn't, you add it at the appropriate
  * spot. What more can I say? At the end of each exten, you cap it off by adding the
  * address of the extension involved. Duplicate patterns will be complained about.
  *
- * Ideally, this would be done for each context after it is created and fully 
+ * Ideally, this would be done for each context after it is created and fully
  * filled. It could be done as a finishing step after extensions.conf or .ael is
  * loaded, or it could be done when the first search is encountered. It should only
  * have to be done once, until the next unload or reload.
@@ -1768,37 +1773,39 @@
 {
 	struct match_char *t;
 
-	if (!current)
+	if (!current) {
 		return 0;
+	}
 
 	for (t = current; t; t = t->alt_char) {
-		if (!strcmp(pat, t->x)) /* uh, we may want to sort exploded [] contents to make matching easy */
+		if (!strcmp(pat, t->x)) { /* uh, we may want to sort exploded [] contents to make matching easy */
 			return t;
+		}
 	}
 
 	return 0;
 }
 
-/* The first arg is the location of the tree ptr, or the 
+/* The first arg is the location of the tree ptr, or the
    address of the next_char ptr in the node, so we can mess
    with it, if we need to insert at the beginning of the list */
 
 static void insert_in_next_chars_alt_char_list(struct match_char **parent_ptr, struct match_char *node)
 {
 	struct match_char *curr, *lcurr;
-	
+
 	/* insert node into the tree at "current", so the alt_char list from current is
 	   sorted in increasing value as you go to the leaves */
 	if (!(*parent_ptr)) {
 		*parent_ptr = node;
 	} else {
-		if ((*parent_ptr)->specificity > node->specificity){
+		if ((*parent_ptr)->specificity > node->specificity) {
 			/* insert at head */
 			node->alt_char = (*parent_ptr);
 			*parent_ptr = node;
 		} else {
 			lcurr = *parent_ptr;
-			for (curr=(*parent_ptr)->alt_char; curr; curr = curr->alt_char) {
+			for (curr = (*parent_ptr)->alt_char; curr; curr = curr->alt_char) {
 				if (curr->specificity > node->specificity) {
 					node->alt_char = curr;
 					lcurr->alt_char = node;
@@ -1818,9 +1825,10 @@
 static 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 **nextcharptr)
 {
 	struct match_char *m;
-	
-	if (!(m = ast_calloc(1, sizeof(*m))))
+
+	if (!(m = ast_calloc(1, sizeof(*m)))) {
 		return NULL;
+	}
 
 	if (!(m->x = ast_strdup(pattern))) {
 		ast_free(m);
@@ -1842,7 +1850,7 @@
 		m->specificity = 0x20000;
 	else
 		m->specificity = specificity;
-	
+
 	if (!con->pattern_tree) {
 		insert_in_next_chars_alt_char_list(&con->pattern_tree, m);
 	} else {
@@ -1866,19 +1874,19 @@
 	char extenbuf[512];
 	char *s1 = extenbuf;
 	int l1 = strlen(e1->exten) + strlen(e1->cidmatch) + 2;
-	
+
 
 	ast_copy_string(extenbuf, e1->exten, sizeof(extenbuf));
 
 	if (e1->matchcid &&  l1 <= sizeof(extenbuf)) {
-		strcat(extenbuf,"/");
-		strcat(extenbuf,e1->cidmatch);
+		strcat(extenbuf, "/");
+		strcat(extenbuf, e1->cidmatch);
 	} else if (l1 > sizeof(extenbuf)) {
-		ast_log(LOG_ERROR,"The pattern %s/%s is too big to deal with: it will be ignored! Disaster!\n", e1->exten, e1->cidmatch);
+		ast_log(LOG_ERROR, "The pattern %s/%s is too big to deal with: it will be ignored! Disaster!\n", e1->exten, e1->cidmatch);
 		return 0;
 	}
 #ifdef NEED_DEBUG
-	ast_log(LOG_DEBUG,"Adding exten %s%c%s to tree\n", s1, e1->matchcid? '/':' ', e1->matchcid? e1->cidmatch : "");
+	ast_log(LOG_DEBUG, "Adding exten %s%c%s to tree\n", s1, e1->matchcid ? '/' : ' ', e1->matchcid ? e1->cidmatch : "");
 #endif
 	m1 = con->pattern_tree; /* each pattern starts over at the root of the pattern tree */
 	m0 = &con->pattern_tree;
@@ -1893,24 +1901,24 @@
 			char *s2 = buf;
 			buf[0] = 0;
 			s1++; /* get past the '[' */
-			while (*s1 != ']' && *(s1-1) != '\\' ) {
+			while (*s1 != ']' && *(s1 - 1) != '\\' ) {
 				if (*s1 == '\\') {
-					if (*(s1+1) == ']') {
+					if (*(s1 + 1) == ']') {
 						*s2++ = ']';
-						s1++;s1++;
-					} else if (*(s1+1) == '\\') {
+						s1++; s1++;
+					} else if (*(s1 + 1) == '\\') {
 						*s2++ = '\\';
-						s1++;s1++;
-					} else if (*(s1+1) == '-') {
+						s1++; s1++;
+					} else if (*(s1 + 1) == '-') {
 						*s2++ = '-';
 						s1++; s1++;
-					} else if (*(s1+1) == '[') {
+					} 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);
+					char s3 = *(s1 - 1);
+					char s4 = *(s1 + 1);
 					for (s3++; s3 <= s4; s3++) {
 						*s2++ = s3;
 					}
@@ -1930,7 +1938,7 @@
 			specif <<= 8;
 			specif += buf[0];
 		} else {
-			
+
 			if (*s1 == '\\') {
 				s1++;
 				buf[0] = *s1;
@@ -1949,9 +1957,9 @@
 			specif = 1;
 		}
 		m2 = 0;
-		if (already && (m2=already_in_tree(m1,buf)) && m2->next_char) {
-			if (!(*(s1+1))) {  /* if this is the end of the pattern, but not the end of the tree, then mark this node with the exten...
-								a shorter pattern might win if the longer one doesn't match */
+		if (already && (m2 = already_in_tree(m1,buf)) && m2->next_char) {
+			if (!(*(s1 + 1))) {  /* if this is the end of the pattern, but not the end of the tree, then mark this node with the exten...
+								  * a shorter pattern might win if the longer one doesn't match */
 				m2->exten = e1;
 				m2->deleted = 0;
 			}
@@ -1959,21 +1967,23 @@
 			m0 = &m2->next_char; /* m0 points to the ptr that points to m1 */
 		} else { /* not already OR not m2 OR nor m2->next_char */
 			if (m2) {
-				if (findonly)
+				if (findonly) {
 					return m2;
+				}
 				m1 = m2; /* while m0 stays the same */
 			} else {
-				if (findonly)
+				if (findonly) {
 					return m1;
+				}
 				m1 = add_pattern_node(con, m1, buf, pattern, already,specif, m0); /* m1 is the node just added */
 				m0 = &m1->next_char;
 			}
-			
-			if (!(*(s1+1))) {
+
+			if (!(*(s1 + 1))) {
 				m1->deleted = 0;
 				m1->exten = e1;
 			}
-			
+
 			already = 0;
 		}
 		s1++; /* advance to next char */
@@ -1987,18 +1997,19 @@
 	struct ast_exten *e1;
 #ifdef NEED_DEBUG
 	int biggest_bucket, resizes, numobjs, numbucks;
-	
+
 	ast_log(LOG_DEBUG,"Creating Extension Trie for context %s\n", con->name);
 	ast_hashtab_get_stats(con->root_table, &biggest_bucket, &resizes, &numobjs, &numbucks);
 	ast_log(LOG_DEBUG,"This tree has %d objects in %d bucket lists, longest list=%d objects, and has resized %d times\n",
 			numobjs, numbucks, biggest_bucket, resizes);
 #endif
 	t1 = ast_hashtab_start_traversal(con->root_table);
-	while( (e1 = ast_hashtab_next(t1)) ) {
-		if (e1->exten)
+	while ((e1 = ast_hashtab_next(t1))) {
+		if (e1->exten) {
 			add_exten_to_pattern_tree(con, e1, 0);
-		else
-			ast_log(LOG_ERROR,"Attempt to create extension with no extension name.\n");
+		} else {
+			ast_log(LOG_ERROR, "Attempt to create extension with no extension name.\n");
+		}
 	}
 	ast_hashtab_end_traversal(t1);
 }
@@ -2016,8 +2027,9 @@
 		pattern_tree->next_char = 0;
 	}
 	pattern_tree->exten = 0; /* never hurts to make sure there's no pointers laying around */
-	if (pattern_tree->x)
+	if (pattern_tree->x) {
 		free(pattern_tree->x);
+	}
 	free(pattern_tree);
 }
 
@@ -2062,12 +2074,12 @@
  * This way more specific patterns (smaller cardinality) appear first.
  * Wildcards have a special value, so that we can directly compare them to
  * sets by subtracting the two values. In particular:
- * 	0x000xx		one character, xx
- * 	0x0yyxx		yy character set starting with xx
- * 	0x10000		'.' (one or more of anything)
- * 	0x20000		'!' (zero or more of anything)
- * 	0x30000		NUL (end of string)
- * 	0x40000		error in set.
+ *  0x000xx		one character, xx
+ *  0x0yyxx		yy character set starting with xx
+ *  0x10000		'.' (one or more of anything)
+ *  0x20000		'!' (zero or more of anything)
+ *  0x30000		NUL (end of string)
+ *  0x40000		error in set.
  * The pointer to the string is advanced according to needs.
  * NOTES:
  *	1. the empty set is equivalent to NUL.
@@ -2114,7 +2126,7 @@
 		break;
 	}
 	/* locate end of set */
-	end = strchr(*p, ']');	
+	end = strchr(*p, ']');
 
 	if (end == NULL) {
 		ast_log(LOG_WARNING, "Wrong usage of [] in the extension\n");
@@ -2192,11 +2204,11 @@
 static int _extension_match_core(const char *pattern, const char *data, enum ext_match_t mode)
 {
 	mode &= E_MATCH_MASK;	/* only consider the relevant bits */
-	
+
 #ifdef NEED_DEBUG_HERE
 	ast_log(LOG_NOTICE,"match core: pat: '%s', dat: '%s', mode=%d\n", pattern, data, (int)mode);
 #endif
-	
+
 	if ( (mode == E_MATCH) && (pattern[0] == '_') && (!strcasecmp(pattern,data)) ) { /* note: if this test is left out, then _x. will not match _x. !!! */
 #ifdef NEED_DEBUG_HERE
 		ast_log(LOG_NOTICE,"return (1) - pattern matches pattern\n");
@@ -2206,7 +2218,7 @@
 
 	if (pattern[0] != '_') { /* not a pattern, try exact or partial match */
 		int ld = strlen(data), lp = strlen(pattern);
-		
+
 		if (lp < ld) {		/* pattern too short, cannot match */
 #ifdef NEED_DEBUG_HERE
 			ast_log(LOG_NOTICE,"return (0) - pattern too short, cannot match\n");
@@ -2219,7 +2231,7 @@
 			ast_log(LOG_NOTICE,"return (!strcmp(%s,%s) when mode== E_MATCH)\n", pattern, data);
 #endif
 			return !strcmp(pattern, data); /* 1 on match, 0 on fail */
-		} 
+		}
 		if (ld == 0 || !strncasecmp(pattern, data, ld)) { /* partial or full match */
 #ifdef NEED_DEBUG_HERE
 			ast_log(LOG_NOTICE,"return (mode(%d) == E_MATCHMORE ? lp(%d) > ld(%d) : 1)\n", mode, lp, ld);
@@ -2296,12 +2308,12 @@
 			break;
 		case '.':	/* Must match, even with more digits */
 #ifdef NEED_DEBUG_HERE
-			ast_log(LOG_NOTICE,"return (1) when '.' is matched\n");
+			ast_log(LOG_NOTICE, "return (1) when '.' is matched\n");
 #endif
 			return 1;
 		case '!':	/* Early match */
 #ifdef NEED_DEBUG_HERE
-			ast_log(LOG_NOTICE,"return (2) when '!' is matched\n");
+			ast_log(LOG_NOTICE, "return (2) when '!' is matched\n");
 #endif
 			return 2;
 		case ' ':
@@ -2311,39 +2323,38 @@
 		default:
 			if (*data != *pattern) {
 #ifdef NEED_DEBUG_HERE
-				ast_log(LOG_NOTICE,"return (0) when *data(%c) != *pattern(%c)\n", *data, *pattern);
+				ast_log(LOG_NOTICE, "return (0) when *data(%c) != *pattern(%c)\n", *data, *pattern);
 #endif
 				return 0;
 			}
-			
 		}
 		data++;
 		pattern++;
 	}
 	if (*data)			/* data longer than pattern, no match */ {
 #ifdef NEED_DEBUG_HERE
-		ast_log(LOG_NOTICE,"return (0) when data longer than pattern\n");
+		ast_log(LOG_NOTICE, "return (0) when data longer than pattern\n");
 #endif
 		return 0;
 	}
-	
+
 	/*
 	 * match so far, but ran off the end of the data.
 	 * Depending on what is next, determine match or not.
 	 */
 	if (*pattern == '\0' || *pattern == '/') {	/* exact match */
 #ifdef NEED_DEBUG_HERE
-		ast_log(LOG_NOTICE,"at end, return (%d) in 'exact match'\n", (mode==E_MATCHMORE) ? 0 : 1);
+		ast_log(LOG_NOTICE, "at end, return (%d) in 'exact match'\n", (mode==E_MATCHMORE) ? 0 : 1);
 #endif
 		return (mode == E_MATCHMORE) ? 0 : 1;	/* this is a failure for E_MATCHMORE */
 	} else if (*pattern == '!')	{		/* early match */
 #ifdef NEED_DEBUG_HERE
-		ast_log(LOG_NOTICE,"at end, return (2) when '!' is matched\n");
+		ast_log(LOG_NOTICE, "at end, return (2) when '!' is matched\n");
 #endif
 		return 2;
 	} else {						/* partial match */
 #ifdef NEED_DEBUG_HERE
-		ast_log(LOG_NOTICE,"at end, return (%d) which deps on E_MATCH\n", (mode == E_MATCH) ? 0 : 1);
+		ast_log(LOG_NOTICE, "at end, return (%d) which deps on E_MATCH\n", (mode == E_MATCH) ? 0 : 1);
 #endif
 		return (mode == E_MATCH) ? 0 : 1;	/* this is a failure for E_MATCH */
 	}
@@ -2357,8 +2368,9 @@
 {
 	int i;
 	static int prof_id = -2;	/* marker for 'unallocated' id */
-	if (prof_id == -2)
+	if (prof_id == -2) {
 		prof_id = ast_add_profile("ext_match", 0);
+	}
 	ast_mark(prof_id, 1);
 	i = _extension_match_core(pattern, data, mode);
 	ast_mark(prof_id, 0);
@@ -2379,18 +2391,18 @@
 
 struct fake_context /* this struct is purely for matching in the hashtab */
 {
-	ast_rwlock_t lock; 			
-	struct ast_exten *root;		
-	struct ast_hashtab *root_table;            
-	struct match_char *pattern_tree;       
-	struct ast_context *next;	
-	struct ast_include *includes;		
-	struct ast_ignorepat *ignorepats;	
+	ast_rwlock_t lock;
+	struct ast_exten *root;
+	struct ast_hashtab *root_table;
+	struct match_char *pattern_tree;
+	struct ast_context *next;
+	struct ast_include *includes;
+	struct ast_ignorepat *ignorepats;
 	const char *registrar;
 	int refcount;
-	AST_LIST_HEAD_NOLOCK(, ast_sw) alts;	
-	ast_mutex_t macrolock;		
-	char name[256];		
+	AST_LIST_HEAD_NOLOCK(, ast_sw) alts;
+	ast_mutex_t macrolock;
+	char name[256];
 };
 
 struct ast_context *ast_context_find(const char *name)
@@ -2405,8 +2417,9 @@
 		tmp = ast_hashtab_lookup(contexts_table,&item);
 	} else {
 		while ( (tmp = ast_walk_contexts(tmp)) ) {
-			if (!name || !strcasecmp(name, tmp->name))
+			if (!name || !strcasecmp(name, tmp->name)) {
 				break;
+			}
 		}
 	}
 	ast_unlock_contexts();
@@ -2424,8 +2437,9 @@
 	/* If the Caller*ID pattern is empty, then we're matching NO Caller*ID, so
 	   failing to get a number should count as a match, otherwise not */
 
-	if (ast_strlen_zero(callerid))
+	if (ast_strlen_zero(callerid)) {
 		return ast_strlen_zero(cidpattern) ? 1 : 0;
+	}
 
 	return ast_extension_match(cidpattern, callerid);
 }
@@ -2447,7 +2461,7 @@
 	pattern.label = label;
 	pattern.priority = priority;
 #ifdef NEED_DEBUG_HERE
-	ast_log(LOG_NOTICE,"Looking for cont/ext/prio/label/action = %s/%s/%d/%s/%d\n", context, exten, priority, label, (int)action);
+	ast_log(LOG_NOTICE, "Looking for cont/ext/prio/label/action = %s/%s/%d/%s/%d\n", context, exten, priority, label, (int) action);
 #endif
 
 	/* Initialize status if appropriate */
@@ -2467,9 +2481,9 @@
 			return NULL;
 	}
 
-	if (bypass)	/* bypass means we only look there */
+	if (bypass) { /* bypass means we only look there */
 		tmp = bypass;
-	else {	/* look in contexts */
+	} else {      /* look in contexts */
 		struct fake_context item;
 
 		ast_copy_string(item.name, context, sizeof(item.name));
@@ -2478,34 +2492,34 @@
 #ifdef NOTNOW
 		tmp = NULL;
 		while ((tmp = ast_walk_contexts(tmp)) ) {
-			if (!strcmp(tmp->name, context))
+			if (!strcmp(tmp->name, context)) {
 				break;
+			}
 		}
 #endif
-		if (!tmp)
+		if (!tmp) {
 			return NULL;
-		
+		}
 	}
 
 	if (q->status < STATUS_NO_EXTENSION)
 		q->status = STATUS_NO_EXTENSION;
-	
+
 	/* Do a search for matching extension */
 
 	eroot = NULL;
 	score.total_specificity = 0;
 	score.exten = 0;
 	score.total_length = 0;
-	if (!tmp->pattern_tree && tmp->root_table)
-	{
+	if (!tmp->pattern_tree && tmp->root_table) {
 		create_match_char_tree(tmp);
 #ifdef NEED_DEBUG
-		ast_log(LOG_DEBUG,"Tree Created in context %s:\n", context);
+		ast_log(LOG_DEBUG, "Tree Created in context %s:\n", context);
 		log_match_char_tree(tmp->pattern_tree," ");
 #endif
 	}
 #ifdef NEED_DEBUG
-	ast_log(LOG_NOTICE,"The Trie we are searching in:\n");
+	ast_log(LOG_NOTICE, "The Trie we are searching in:\n");
 	log_match_char_tree(tmp->pattern_tree, "::  ");
 #endif
 
@@ -2571,7 +2585,7 @@
 	if (extenpatternmatchnew) {
 		new_find_extension(exten, &score, tmp->pattern_tree, 0, 0, callerid, label, action);
 		eroot = score.exten;
-		
+
 		if (score.last_char == '!' && action == E_MATCHMORE) {
 			/* We match an extension ending in '!'.
 			 * The decision in this case is final and is NULL (no match).
@@ -2581,7 +2595,7 @@
 #endif
 			return NULL;
 		}
-		
+
 		if (!eroot && (action == E_CANMATCH || action == E_MATCHMORE) && score.canmatch_exten) {
 			q->status = STATUS_SUCCESS;
 #ifdef NEED_DEBUG_HERE
@@ -2589,7 +2603,7 @@
 #endif
 			return score.canmatch_exten;
 		}
-		
+
 		if ((action == E_MATCHMORE || action == E_CANMATCH)  && eroot) {
 			if (score.node) {
 				struct ast_exten *z = trie_find_next_match(score.node);
@@ -2612,11 +2626,11 @@
 				return z;
 			}
 #ifdef NEED_DEBUG_HERE
-			ast_log(LOG_NOTICE,"Returning CANMATCH/MATCHMORE NULL (no next_match)\n");

[... 1106 lines stripped ...]



More information about the asterisk-commits mailing list