[svn-commits] file: trunk r109970 - in /trunk: CHANGES main/pbx.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Mar 19 11:54:13 CDT 2008


Author: file
Date: Wed Mar 19 11:54:12 2008
New Revision: 109970

URL: http://svn.digium.com/view/asterisk?view=rev&rev=109970
Log:
Add the ability to use a pattern match for a hint.
(closes issue #7767)
Reported by: Corydon76
Patches:
      20070314__simple_hint_lookup.diff.txt uploaded by Corydon76
      pbx-trunk-98436.diff uploaded by plack (license 365)

Modified:
    trunk/CHANGES
    trunk/main/pbx.c

Modified: trunk/CHANGES
URL: http://svn.digium.com/view/asterisk/trunk/CHANGES?view=diff&rev=109970&r1=109969&r2=109970
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Wed Mar 19 11:54:12 2008
@@ -11,6 +11,12 @@
 ----------------------------------------
  * Channels can now be configured using named sections in zapata.conf, just
    like other channel drivers, including the use of templates.
+
+PBX Changes
+-----------
+ * It is now possible to specify a pattern match as a hint. Once a phone subscribes
+   to something that matches the pattern a hint will be created using the contents
+   and variables evaluated.
 
 ------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 1.4.X to Asterisk 1.6.0  -------------

Modified: trunk/main/pbx.c
URL: http://svn.digium.com/view/asterisk/trunk/main/pbx.c?view=diff&rev=109970&r1=109969&r2=109970
==============================================================================
--- trunk/main/pbx.c (original)
+++ trunk/main/pbx.c Wed Mar 19 11:54:12 2008
@@ -2836,7 +2836,7 @@
 /*! \brief Check state of extension by using hints */
 static int ast_extension_state2(struct ast_exten *e)
 {
-	char hint[AST_MAX_EXTENSION];
+	char hint[AST_MAX_EXTENSION] = "";
 	char *cur, *rest;
 	int allunavailable = 1, allbusy = 1, allfree = 1, allonhold = 1;
 	int busy = 0, inuse = 0, ring = 0;
@@ -3073,6 +3073,20 @@
 		return -1;
 	}
 
+	/* If this is a pattern, dynamically create a new extension for this
+	 * particular match.  Note that this will only happen once for each
+	 * individual extension, because the pattern will no longer match first.
+	 */
+	if (e->exten[0] == '_') {
+		ast_add_extension(e->parent->name, 0, exten, e->priority, e->label,
+			e->cidmatch, e->app, strdup(e->data), free,
+			e->registrar);
+		e = ast_hint_extension(NULL, context, exten);
+		if (!e || e->exten[0] == '_') {
+			return -1;
+		}
+	}
+
 	/* Find the hint in the list of hints */
 	AST_RWLIST_WRLOCK(&hints);
 
@@ -5498,6 +5512,16 @@
 	while ((this = AST_LIST_REMOVE_HEAD(&store, list))) {
 		struct pbx_find_info q = { .stacklen = 0 };
 		exten = pbx_find_extension(NULL, NULL, &q, this->context, this->exten, PRIORITY_HINT, NULL, "", E_MATCH);
+		/* If this is a pattern, dynamically create a new extension for this
+		 * particular match.  Note that this will only happen once for each
+		 * individual extension, because the pattern will no longer match first.
+		 */
+		if (exten && exten->exten[0] == '_') {
+			ast_add_extension(exten->parent->name, 0, this->exten, PRIORITY_HINT, NULL,
+				0, exten->app, strdup(exten->data), free, registrar);
+			exten = ast_hint_extension(NULL, this->context, this->exten);
+		}
+
 		/* Find the hint in the list of hints */
 		AST_RWLIST_TRAVERSE(&hints, hint, list) {
 			if (hint->exten == exten)
@@ -6360,15 +6384,23 @@
 	struct ast_exten dummy_exten = {0};
 	char dummy_name[1024];
 
-	/* if we are adding a hint, and there are global variables, and the hint
-	   contains variable references, then expand them
-	*/
-	ast_rwlock_rdlock(&globalslock);
-	if (priority == PRIORITY_HINT && AST_LIST_FIRST(&globals) && strstr(application, "${")) {
-		pbx_substitute_variables_varshead(&globals, application, expand_buf, sizeof(expand_buf));
-		application = expand_buf;
-	}
-	ast_rwlock_unlock(&globalslock);
+	/* If we are adding a hint evalulate in variables and global variables */
+	if (priority == PRIORITY_HINT && strstr(application, "${") && !strstr(extension, "_")) {
+		struct ast_channel c = {0, };
+
+		/* Start out with regular variables */
+		ast_copy_string(c.exten, extension, sizeof(c.exten));
+		ast_copy_string(c.context, con->name, sizeof(c.context));
+		pbx_substitute_variables_helper(&c, application, expand_buf, sizeof(expand_buf));
+
+		/* Move on to global variables if they exist */
+		ast_rwlock_rdlock(&globalslock);
+		if (AST_LIST_FIRST(&globals)) {
+			pbx_substitute_variables_varshead(&globals, application, expand_buf, sizeof(expand_buf));
+			application = expand_buf;
+		}
+		ast_rwlock_unlock(&globalslock);
+	}
 
 	length = sizeof(struct ast_exten);
 	length += strlen(extension) + 1;




More information about the svn-commits mailing list