[asterisk-commits] murf: branch murf/fast-ast3 r88006 - in /team/murf/fast-ast3: apps/ include/a...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Oct 31 23:56:28 CDT 2007


Author: murf
Date: Wed Oct 31 23:56:27 2007
New Revision: 88006

URL: http://svn.digium.com/view/asterisk?view=rev&rev=88006
Log:
Two optimizations here: first, one to compress the ast_exists_extension() ... ast_spawn_extension() pair into a single call to ast_spawn_exention(), which has an added arg, a ptr to an int to hold the found boolean. Next optimization: adjust the substitute_variables_helper_full function, so there is no longer a requirement that the result buffer be nulled out first. This results in the pips count going from 76k to 97k, which is nice.

Modified:
    team/murf/fast-ast3/apps/app_dial.c
    team/murf/fast-ast3/apps/app_macro.c
    team/murf/fast-ast3/include/asterisk/pbx.h
    team/murf/fast-ast3/main/pbx.c
    team/murf/fast-ast3/pbx/pbx_loopback.c

Modified: team/murf/fast-ast3/apps/app_dial.c
URL: http://svn.digium.com/view/asterisk/team/murf/fast-ast3/apps/app_dial.c?view=diff&rev=88006&r1=88005&r2=88006
==============================================================================
--- team/murf/fast-ast3/apps/app_dial.c (original)
+++ team/murf/fast-ast3/apps/app_dial.c Wed Oct 31 23:56:27 2007
@@ -1791,19 +1791,19 @@
 
 		if (ast_test_flag64(&opts, OPT_PEER_H) && ast_exists_extension(peer, peer->context, "h", 1, peer->cid.cid_num)) {
 			int autoloopflag;
+			int found;
 			strcpy(peer->exten, "h");
 			peer->priority = 1;
 			autoloopflag = ast_test_flag(peer, AST_FLAG_IN_AUTOLOOP);	/* save value to restore at the end */
 			ast_set_flag(peer, AST_FLAG_IN_AUTOLOOP);
 			
-			while (ast_exists_extension(peer, peer->context, peer->exten, peer->priority, peer->cid.cid_num)) {
-				if ((res = ast_spawn_extension(peer, peer->context, peer->exten, peer->priority, peer->cid.cid_num))) {
-					/* Something bad happened, or a hangup has been requested. */
-					ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", peer->context, peer->exten, peer->priority, peer->name);
-					ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", peer->context, peer->exten, peer->priority, peer->name);
-					break;
-				}
+			while ((res = ast_spawn_extension(peer, peer->context, peer->exten, peer->priority, peer->cid.cid_num, &found))) {
 				peer->priority++;
+			}
+			if (found && res) {
+				/* Something bad happened, or a hangup has been requested. */
+				ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", peer->context, peer->exten, peer->priority, peer->name);
+				ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", peer->context, peer->exten, peer->priority, peer->name);
 			}
 			ast_set2_flag(peer, autoloopflag, AST_FLAG_IN_AUTOLOOP);  /* set it back the way it was */
 		}

Modified: team/murf/fast-ast3/apps/app_macro.c
URL: http://svn.digium.com/view/asterisk/team/murf/fast-ast3/apps/app_macro.c?view=diff&rev=88006&r1=88005&r2=88006
==============================================================================
--- team/murf/fast-ast3/apps/app_macro.c (original)
+++ team/murf/fast-ast3/apps/app_macro.c Wed Oct 31 23:56:27 2007
@@ -271,6 +271,7 @@
 	while(ast_exists_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num)) {
 		struct ast_context *c;
 		struct ast_exten *e;
+		int foundx;
 		runningapp[0] = '\0';
 		runningdata[0] = '\0';
 
@@ -299,7 +300,7 @@
 		/* Reset the macro depth, if it was changed in the last iteration */
 		pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc);
 
-		if ((res = ast_spawn_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num))) {
+		if ((res = ast_spawn_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num, &foundx))) {
 			/* Something bad happened, or a hangup has been requested. */
 			if (((res >= '0') && (res <= '9')) || ((res >= 'A') && (res <= 'F')) ||
 		    	(res == '*') || (res == '#')) {

Modified: team/murf/fast-ast3/include/asterisk/pbx.h
URL: http://svn.digium.com/view/asterisk/team/murf/fast-ast3/include/asterisk/pbx.h?view=diff&rev=88006&r1=88005&r2=88006
==============================================================================
--- team/murf/fast-ast3/include/asterisk/pbx.h (original)
+++ team/murf/fast-ast3/include/asterisk/pbx.h Wed Oct 31 23:56:27 2007
@@ -522,7 +522,7 @@
  * \retval -1 on failure.
  */
 int ast_spawn_extension(struct ast_channel *c, const char *context, 
-	const char *exten, int priority, const char *callerid);
+      const char *exten, int priority, const char *callerid, int *found);
 
 /*! 
  * \brief Add a context include

Modified: team/murf/fast-ast3/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/murf/fast-ast3/main/pbx.c?view=diff&rev=88006&r1=88005&r2=88006
==============================================================================
--- team/murf/fast-ast3/main/pbx.c (original)
+++ team/murf/fast-ast3/main/pbx.c Wed Oct 31 23:56:27 2007
@@ -1662,6 +1662,7 @@
 			count -= pos;
 			cp2 += pos;
 			whereweare += pos;
+			*cp2 = 0;
 		}
 
 		if (nextvar) {
@@ -1702,7 +1703,7 @@
 				if (!ltmp)
 					ltmp = alloca(VAR_BUF_SIZE);
 
-				memset(ltmp, 0, VAR_BUF_SIZE);
+				/* memset(ltmp, 0, VAR_BUF_SIZE); */
 				pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1);
 				vars = ltmp;
 			} else {
@@ -1746,6 +1747,7 @@
 				memcpy(cp2, cp4, length);
 				count -= length;
 				cp2 += length;
+				*cp2 = 0;
 			}
 		} else if (nextexp) {
 			/* We have an expression.  Find the start and end, and determine
@@ -1789,7 +1791,7 @@
 				if (!ltmp)
 					ltmp = alloca(VAR_BUF_SIZE);
 
-				memset(ltmp, 0, VAR_BUF_SIZE);
+				/* memset(ltmp, 0, VAR_BUF_SIZE); */
 				pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1);
 				vars = ltmp;
 			} else {
@@ -1802,6 +1804,7 @@
 				ast_debug(1, "Expression result is '%s'\n", cp2);
 				count -= length;
 				cp2 += length;
+				*cp2 = 0;
 			}
 		}
 	}
@@ -1820,7 +1823,7 @@
 static void pbx_substitute_variables(char *passdata, int datalen, struct ast_channel *c, struct ast_exten *e)
 {
 	const char *tmp;
-	memset(passdata, 0, datalen);
+	/* memset(passdata, 0, datalen); */
 
 	/* Nothing more to do */
 	if (!e->data)
@@ -1847,8 +1850,8 @@
  * \retval  -1 on failure.
  */
 static int pbx_extension_helper(struct ast_channel *c, struct ast_context *con,
-	const char *context, const char *exten, int priority,
-	const char *label, const char *callerid, enum ext_match_t action)
+  const char *context, const char *exten, int priority,
+  const char *label, const char *callerid, enum ext_match_t action, int *found)
 {
 	struct ast_exten *e;
 	struct ast_app *app;
@@ -1857,10 +1860,14 @@
 	char passdata[EXT_DATA_SIZE];
 
 	int matching_action = (action == E_MATCH || action == E_CANMATCH || action == E_MATCHMORE);
-
+	
 	ast_rdlock_contexts();
+	if (found)
+		*found = 0;
 	e = pbx_find_extension(c, con, &q, context, exten, priority, label, callerid, action);
 	if (e) {
+		if (found)
+			*found = 1;
 		if (matching_action) {
 			ast_unlock_contexts();
 			return -1;	/* success, we found it */
@@ -2376,32 +2383,32 @@
 
 int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
 {
-	return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCH);
+	return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCH, 0);
 }
 
 int ast_findlabel_extension(struct ast_channel *c, const char *context, const char *exten, const char *label, const char *callerid)
 {
-	return pbx_extension_helper(c, NULL, context, exten, 0, label, callerid, E_FINDLABEL);
+	return pbx_extension_helper(c, NULL, context, exten, 0, label, callerid, E_FINDLABEL, 0);
 }
 
 int ast_findlabel_extension2(struct ast_channel *c, struct ast_context *con, const char *exten, const char *label, const char *callerid)
 {
-	return pbx_extension_helper(c, con, NULL, exten, 0, label, callerid, E_FINDLABEL);
+	return pbx_extension_helper(c, con, NULL, exten, 0, label, callerid, E_FINDLABEL, 0);
 }
 
 int ast_canmatch_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
 {
-	return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_CANMATCH);
+	return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_CANMATCH, 0);
 }
 
 int ast_matchmore_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
 {
-	return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCHMORE);
-}
-
-int ast_spawn_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
-{
-	return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_SPAWN);
+	return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCHMORE, 0);
+}
+
+int ast_spawn_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid, int *found)
+{
+	return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_SPAWN, found);
 }
 
 /*! helper function to set extension and priority */
@@ -2498,50 +2505,7 @@
 		int digit = 0;
 
 		/* loop on priorities in this context/exten */
-		while (ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {
-			found = 1;
-			if ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num))) {
-				/* Something bad happened, or a hangup has been requested. */
-				if (strchr("0123456789ABCDEF*#", res)) {
-					ast_debug(1, "Oooh, got something to jump out with ('%c')!\n", res);
-					pos = 0;
-					dst_exten[pos++] = digit = res;
-					dst_exten[pos] = '\0';
-					break;
-				}
-				if (res == AST_PBX_KEEPALIVE) {
-					ast_debug(1, "Spawn extension (%s,%s,%d) exited KEEPALIVE on '%s'\n", c->context, c->exten, c->priority, c->name);
-					ast_verb(2, "Spawn extension (%s, %s, %d) exited KEEPALIVE on '%s'\n", c->context, c->exten, c->priority, c->name);
-					error = 1;
-					break;
-				}
-				ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
-				ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
-
- 				if ((res == AST_PBX_ERROR) && ast_exists_extension(c, c->context, "e", 1, c->cid.cid_num)) {
- 					/* if we are already on the 'e' exten, don't jump to it again */
- 					if (!strcmp(c->exten, "e")) {
- 						if (option_verbose > 1)
- 							ast_verbose(VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited ERROR while already on 'e' exten on '%s'\n", c->context, c->exten, c->priority, c->name);
- 						error = 1;
-						break;
- 					} else {
-						pbx_builtin_raise_exception(c, "ERROR");
- 						continue;
- 					}
- 				}
-
-				if (c->_softhangup == AST_SOFTHANGUP_ASYNCGOTO) {
-					c->_softhangup = 0;
-				} else if (c->_softhangup == AST_SOFTHANGUP_TIMEOUT) {
-					/* atimeout, nothing bad */
-				} else {
-					if (c->cdr)
-						ast_cdr_update(c);
-					error = 1;
-					break;
-				}
-			}
+		while ( !(res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num, &found))) {
 			if (c->_softhangup == AST_SOFTHANGUP_TIMEOUT && ast_exists_extension(c, c->context, "T", 1, c->cid.cid_num)) {
 				set_ext_pri(c, "T", 0); /* 0 will become 1 with the c->priority++; at the end */
 				/* If the AbsoluteTimeout is not reset to 0, we'll get an infinite loop */
@@ -2560,6 +2524,45 @@
 			}
 			c->priority++;
 		} /* end while  - from here on we can use 'break' to go out */
+		if (found && res) {
+			/* Something bad happened, or a hangup has been requested. */
+			if (strchr("0123456789ABCDEF*#", res)) {
+				ast_debug(1, "Oooh, got something to jump out with ('%c')!\n", res);
+				pos = 0;
+				dst_exten[pos++] = digit = res;
+				dst_exten[pos] = '\0';
+			}
+			if (res == AST_PBX_KEEPALIVE) {
+				ast_debug(1, "Spawn extension (%s,%s,%d) exited KEEPALIVE on '%s'\n", c->context, c->exten, c->priority, c->name);
+				ast_verb(2, "Spawn extension (%s, %s, %d) exited KEEPALIVE on '%s'\n", c->context, c->exten, c->priority, c->name);
+				error = 1;
+			}
+			ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
+			ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
+			
+			if ((res == AST_PBX_ERROR) && ast_exists_extension(c, c->context, "e", 1, c->cid.cid_num)) {
+				/* if we are already on the 'e' exten, don't jump to it again */
+				if (!strcmp(c->exten, "e")) {
+					if (option_verbose > 1)
+						ast_verbose(VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited ERROR while already on 'e' exten on '%s'\n", c->context, c->exten, c->priority, c->name);
+					error = 1;
+				} else {
+					pbx_builtin_raise_exception(c, "ERROR");
+					continue;
+				}
+			}
+			
+			if (c->_softhangup == AST_SOFTHANGUP_ASYNCGOTO) {
+				c->_softhangup = 0;
+			} else if (c->_softhangup == AST_SOFTHANGUP_TIMEOUT) {
+				/* atimeout, nothing bad */
+			} else {
+				if (c->cdr)
+					ast_cdr_update(c);
+				error = 1;
+				break;
+			}
+		}
 		if (error)
 			break;
 
@@ -2657,14 +2660,13 @@
 		if (c->cdr && ast_opt_end_cdr_before_h_exten)
 			ast_cdr_end(c->cdr);
 		set_ext_pri(c, "h", 1);
-		while (ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {
-			if ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num))) {
-				/* Something bad happened, or a hangup has been requested. */
-				ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
-				ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
-				break;
-			}
+		while ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num, &found))) {
 			c->priority++;
+		}
+		if (found && res) {
+			/* Something bad happened, or a hangup has been requested. */
+			ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
+			ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
 		}
 	}
 	ast_set2_flag(c, autoloopflag, AST_FLAG_IN_AUTOLOOP);

Modified: team/murf/fast-ast3/pbx/pbx_loopback.c
URL: http://svn.digium.com/view/asterisk/team/murf/fast-ast3/pbx/pbx_loopback.c?view=diff&rev=88006&r1=88005&r2=88006
==============================================================================
--- team/murf/fast-ast3/pbx/pbx_loopback.c (original)
+++ team/murf/fast-ast3/pbx/pbx_loopback.c Wed Oct 31 23:56:27 2007
@@ -141,8 +141,9 @@
 
 static int loopback_exec(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
 {
+	int found;
 	LOOPBACK_COMMON;
-	res = ast_spawn_extension(chan, newcontext, newexten, newpriority, callerid);
+	res = ast_spawn_extension(chan, newcontext, newexten, newpriority, callerid, &found);
 	/* XXX hmmm... res is overridden ? */
 	if (newpattern && !ast_extension_match(newpattern, exten))
 		res = -1;




More information about the asterisk-commits mailing list