aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2008-03-19 16:54:12 +0000
committerfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2008-03-19 16:54:12 +0000
commitab44bf670074a2c0dbe9595c0162ed872434d227 (patch)
treeb3662a3a9f1b1ec9c300f89c9ae0cb8f9ccca831
parent2ed0ae46f5747fee537a209eee168338e4f154d4 (diff)
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) git-svn-id: http://svn.digium.com/svn/asterisk/trunk@109970 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--CHANGES6
-rw-r--r--main/pbx.c50
2 files changed, 47 insertions, 9 deletions
diff --git a/CHANGES b/CHANGES
index f7bf3fc90..1468e19db 100644
--- a/CHANGES
+++ b/CHANGES
@@ -12,6 +12,12 @@ Zaptel channel driver (chan_zap) Changes
* 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 -------------
------------------------------------------------------------------------------
diff --git a/main/pbx.c b/main/pbx.c
index 650b0d9d9..5b880e30d 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -2836,7 +2836,7 @@ static struct ast_exten *ast_hint_extension(struct ast_channel *c, const char *c
/*! \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 @@ int ast_extension_state_add(const char *context, const char *exten,
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 @@ void ast_merge_contexts_and_delete(struct ast_context **extcontexts, struct ast_
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 @@ int ast_add_extension2(struct ast_context *con,
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;
+ /* 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);
}
- ast_rwlock_unlock(&globalslock);
length = sizeof(struct ast_exten);
length += strlen(extension) + 1;